summaryrefslogtreecommitdiffstats
path: root/src/audio_core/renderer/effect/delay.cpp
blob: d9853efd920192a14673d2a0a9c2f4d9af021b2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "audio_core/renderer/effect/delay.h"

namespace AudioCore::AudioRenderer {

void DelayInfo::Update(BehaviorInfo::ErrorInfo& error_info, const InParameterVersion1& in_params,
                       const PoolMapper& pool_mapper) {
    auto in_specific{reinterpret_cast<const ParameterVersion1*>(in_params.specific.data())};
    auto params{reinterpret_cast<ParameterVersion1*>(parameter.data())};

    if (IsChannelCountValid(in_specific->channel_count_max)) {
        const auto old_state{params->state};
        std::memcpy(params, in_specific, sizeof(ParameterVersion1));
        mix_id = in_params.mix_id;
        process_order = in_params.process_order;
        enabled = in_params.enabled;

        if (!IsChannelCountValid(in_specific->channel_count)) {
            params->channel_count = params->channel_count_max;
        }

        if (!IsChannelCountValid(in_specific->channel_count) ||
            old_state != ParameterState::Updated) {
            params->state = old_state;
        }

        if (buffer_unmapped || in_params.is_new) {
            usage_state = UsageState::New;
            params->state = ParameterState::Initialized;
            buffer_unmapped = !pool_mapper.TryAttachBuffer(
                error_info, workbuffers[0], in_params.workbuffer, in_params.workbuffer_size);
            return;
        }
    }
    error_info.error_code = ResultSuccess;
    error_info.address = CpuAddr(0);
}

void DelayInfo::Update(BehaviorInfo::ErrorInfo& error_info, const InParameterVersion2& in_params,
                       const PoolMapper& pool_mapper) {
    auto in_specific{reinterpret_cast<const ParameterVersion1*>(in_params.specific.data())};
    auto params{reinterpret_cast<ParameterVersion1*>(parameter.data())};

    if (IsChannelCountValid(in_specific->channel_count_max)) {
        const auto old_state{params->state};
        std::memcpy(params, in_specific, sizeof(ParameterVersion1));
        mix_id = in_params.mix_id;
        process_order = in_params.process_order;
        enabled = in_params.enabled;

        if (!IsChannelCountValid(in_specific->channel_count)) {
            params->channel_count = params->channel_count_max;
        }

        if (!IsChannelCountValid(in_specific->channel_count) ||
            old_state != ParameterState::Updated) {
            params->state = old_state;
        }

        if (buffer_unmapped || in_params.is_new) {
            usage_state = UsageState::New;
            params->state = ParameterState::Initialized;
            buffer_unmapped = !pool_mapper.TryAttachBuffer(
                error_info, workbuffers[0], in_params.workbuffer, in_params.workbuffer_size);
            return;
        }
    }
    error_info.error_code = ResultSuccess;
    error_info.address = CpuAddr(0);
}

void DelayInfo::UpdateForCommandGeneration() {
    if (enabled) {
        usage_state = UsageState::Enabled;
    } else {
        usage_state = UsageState::Disabled;
    }

    auto params{reinterpret_cast<ParameterVersion1*>(parameter.data())};
    params->state = ParameterState::Updated;
}

void DelayInfo::InitializeResultState(EffectResultState& result_state) {}

void DelayInfo::UpdateResultState(EffectResultState& cpu_state, EffectResultState& dsp_state) {}

CpuAddr DelayInfo::GetWorkbuffer(s32 index) {
    return GetSingleBuffer(index);
}

} // namespace AudioCore::AudioRenderer