diff options
| author | 2022-07-16 23:48:45 +0100 | |
|---|---|---|
| committer | 2022-07-22 01:11:32 +0100 | |
| commit | 458da8a94877677f086f06cdeecf959ec4283a33 (patch) | |
| tree | 583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/effect_context.cpp | |
| parent | Merge pull request #8598 from Link4565/recv-dontwait (diff) | |
| download | yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip | |
Project Andio
Diffstat (limited to 'src/audio_core/effect_context.cpp')
| -rw-r--r-- | src/audio_core/effect_context.cpp | 320 |
1 files changed, 0 insertions, 320 deletions
diff --git a/src/audio_core/effect_context.cpp b/src/audio_core/effect_context.cpp deleted file mode 100644 index 79bcd1192..000000000 --- a/src/audio_core/effect_context.cpp +++ /dev/null | |||
| @@ -1,320 +0,0 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <algorithm> | ||
| 5 | #include "audio_core/effect_context.h" | ||
| 6 | |||
| 7 | namespace AudioCore { | ||
| 8 | namespace { | ||
| 9 | bool ValidChannelCountForEffect(s32 channel_count) { | ||
| 10 | return channel_count == 1 || channel_count == 2 || channel_count == 4 || channel_count == 6; | ||
| 11 | } | ||
| 12 | } // namespace | ||
| 13 | |||
| 14 | EffectContext::EffectContext(std::size_t effect_count_) : effect_count(effect_count_) { | ||
| 15 | effects.reserve(effect_count); | ||
| 16 | std::generate_n(std::back_inserter(effects), effect_count, | ||
| 17 | [] { return std::make_unique<EffectStubbed>(); }); | ||
| 18 | } | ||
| 19 | EffectContext::~EffectContext() = default; | ||
| 20 | |||
| 21 | std::size_t EffectContext::GetCount() const { | ||
| 22 | return effect_count; | ||
| 23 | } | ||
| 24 | |||
| 25 | EffectBase* EffectContext::GetInfo(std::size_t i) { | ||
| 26 | return effects.at(i).get(); | ||
| 27 | } | ||
| 28 | |||
| 29 | EffectBase* EffectContext::RetargetEffect(std::size_t i, EffectType effect) { | ||
| 30 | switch (effect) { | ||
| 31 | case EffectType::Invalid: | ||
| 32 | effects[i] = std::make_unique<EffectStubbed>(); | ||
| 33 | break; | ||
| 34 | case EffectType::BufferMixer: | ||
| 35 | effects[i] = std::make_unique<EffectBufferMixer>(); | ||
| 36 | break; | ||
| 37 | case EffectType::Aux: | ||
| 38 | effects[i] = std::make_unique<EffectAuxInfo>(); | ||
| 39 | break; | ||
| 40 | case EffectType::Delay: | ||
| 41 | effects[i] = std::make_unique<EffectDelay>(); | ||
| 42 | break; | ||
| 43 | case EffectType::Reverb: | ||
| 44 | effects[i] = std::make_unique<EffectReverb>(); | ||
| 45 | break; | ||
| 46 | case EffectType::I3dl2Reverb: | ||
| 47 | effects[i] = std::make_unique<EffectI3dl2Reverb>(); | ||
| 48 | break; | ||
| 49 | case EffectType::BiquadFilter: | ||
| 50 | effects[i] = std::make_unique<EffectBiquadFilter>(); | ||
| 51 | break; | ||
| 52 | default: | ||
| 53 | ASSERT_MSG(false, "Unimplemented effect {}", effect); | ||
| 54 | effects[i] = std::make_unique<EffectStubbed>(); | ||
| 55 | } | ||
| 56 | return GetInfo(i); | ||
| 57 | } | ||
| 58 | |||
| 59 | const EffectBase* EffectContext::GetInfo(std::size_t i) const { | ||
| 60 | return effects.at(i).get(); | ||
| 61 | } | ||
| 62 | |||
| 63 | EffectStubbed::EffectStubbed() : EffectBase(EffectType::Invalid) {} | ||
| 64 | EffectStubbed::~EffectStubbed() = default; | ||
| 65 | |||
| 66 | void EffectStubbed::Update([[maybe_unused]] EffectInfo::InParams& in_params) {} | ||
| 67 | void EffectStubbed::UpdateForCommandGeneration() {} | ||
| 68 | |||
| 69 | EffectBase::EffectBase(EffectType effect_type_) : effect_type(effect_type_) {} | ||
| 70 | EffectBase::~EffectBase() = default; | ||
| 71 | |||
| 72 | UsageState EffectBase::GetUsage() const { | ||
| 73 | return usage; | ||
| 74 | } | ||
| 75 | |||
| 76 | EffectType EffectBase::GetType() const { | ||
| 77 | return effect_type; | ||
| 78 | } | ||
| 79 | |||
| 80 | bool EffectBase::IsEnabled() const { | ||
| 81 | return enabled; | ||
| 82 | } | ||
| 83 | |||
| 84 | s32 EffectBase::GetMixID() const { | ||
| 85 | return mix_id; | ||
| 86 | } | ||
| 87 | |||
| 88 | s32 EffectBase::GetProcessingOrder() const { | ||
| 89 | return processing_order; | ||
| 90 | } | ||
| 91 | |||
| 92 | std::vector<u8>& EffectBase::GetWorkBuffer() { | ||
| 93 | return work_buffer; | ||
| 94 | } | ||
| 95 | |||
| 96 | const std::vector<u8>& EffectBase::GetWorkBuffer() const { | ||
| 97 | return work_buffer; | ||
| 98 | } | ||
| 99 | |||
| 100 | EffectI3dl2Reverb::EffectI3dl2Reverb() : EffectGeneric(EffectType::I3dl2Reverb) {} | ||
| 101 | EffectI3dl2Reverb::~EffectI3dl2Reverb() = default; | ||
| 102 | |||
| 103 | void EffectI3dl2Reverb::Update(EffectInfo::InParams& in_params) { | ||
| 104 | auto& params = GetParams(); | ||
| 105 | const auto* reverb_params = reinterpret_cast<I3dl2ReverbParams*>(in_params.raw.data()); | ||
| 106 | if (!ValidChannelCountForEffect(reverb_params->max_channels)) { | ||
| 107 | ASSERT_MSG(false, "Invalid reverb max channel count {}", reverb_params->max_channels); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | |||
| 111 | const auto last_status = params.status; | ||
| 112 | mix_id = in_params.mix_id; | ||
| 113 | processing_order = in_params.processing_order; | ||
| 114 | params = *reverb_params; | ||
| 115 | if (!ValidChannelCountForEffect(reverb_params->channel_count)) { | ||
| 116 | params.channel_count = params.max_channels; | ||
| 117 | } | ||
| 118 | enabled = in_params.is_enabled; | ||
| 119 | if (last_status != ParameterStatus::Updated) { | ||
| 120 | params.status = last_status; | ||
| 121 | } | ||
| 122 | |||
| 123 | if (in_params.is_new || skipped) { | ||
| 124 | usage = UsageState::Initialized; | ||
| 125 | params.status = ParameterStatus::Initialized; | ||
| 126 | skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; | ||
| 127 | if (!skipped) { | ||
| 128 | auto& cur_work_buffer = GetWorkBuffer(); | ||
| 129 | // Has two buffers internally | ||
| 130 | cur_work_buffer.resize(in_params.buffer_size * 2); | ||
| 131 | std::fill(cur_work_buffer.begin(), cur_work_buffer.end(), 0); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | void EffectI3dl2Reverb::UpdateForCommandGeneration() { | ||
| 137 | if (enabled) { | ||
| 138 | usage = UsageState::Running; | ||
| 139 | } else { | ||
| 140 | usage = UsageState::Stopped; | ||
| 141 | } | ||
| 142 | GetParams().status = ParameterStatus::Updated; | ||
| 143 | } | ||
| 144 | |||
| 145 | I3dl2ReverbState& EffectI3dl2Reverb::GetState() { | ||
| 146 | return state; | ||
| 147 | } | ||
| 148 | |||
| 149 | const I3dl2ReverbState& EffectI3dl2Reverb::GetState() const { | ||
| 150 | return state; | ||
| 151 | } | ||
| 152 | |||
| 153 | EffectBiquadFilter::EffectBiquadFilter() : EffectGeneric(EffectType::BiquadFilter) {} | ||
| 154 | EffectBiquadFilter::~EffectBiquadFilter() = default; | ||
| 155 | |||
| 156 | void EffectBiquadFilter::Update(EffectInfo::InParams& in_params) { | ||
| 157 | auto& params = GetParams(); | ||
| 158 | const auto* biquad_params = reinterpret_cast<BiquadFilterParams*>(in_params.raw.data()); | ||
| 159 | mix_id = in_params.mix_id; | ||
| 160 | processing_order = in_params.processing_order; | ||
| 161 | params = *biquad_params; | ||
| 162 | enabled = in_params.is_enabled; | ||
| 163 | } | ||
| 164 | |||
| 165 | void EffectBiquadFilter::UpdateForCommandGeneration() { | ||
| 166 | if (enabled) { | ||
| 167 | usage = UsageState::Running; | ||
| 168 | } else { | ||
| 169 | usage = UsageState::Stopped; | ||
| 170 | } | ||
| 171 | GetParams().status = ParameterStatus::Updated; | ||
| 172 | } | ||
| 173 | |||
| 174 | EffectAuxInfo::EffectAuxInfo() : EffectGeneric(EffectType::Aux) {} | ||
| 175 | EffectAuxInfo::~EffectAuxInfo() = default; | ||
| 176 | |||
| 177 | void EffectAuxInfo::Update(EffectInfo::InParams& in_params) { | ||
| 178 | const auto* aux_params = reinterpret_cast<AuxInfo*>(in_params.raw.data()); | ||
| 179 | mix_id = in_params.mix_id; | ||
| 180 | processing_order = in_params.processing_order; | ||
| 181 | GetParams() = *aux_params; | ||
| 182 | enabled = in_params.is_enabled; | ||
| 183 | |||
| 184 | if (in_params.is_new || skipped) { | ||
| 185 | skipped = aux_params->send_buffer_info == 0 || aux_params->return_buffer_info == 0; | ||
| 186 | if (skipped) { | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | // There's two AuxInfos which are an identical size, the first one is managed by the cpu, | ||
| 191 | // the second is managed by the dsp. All we care about is managing the DSP one | ||
| 192 | send_info = aux_params->send_buffer_info + sizeof(AuxInfoDSP); | ||
| 193 | send_buffer = aux_params->send_buffer_info + (sizeof(AuxInfoDSP) * 2); | ||
| 194 | |||
| 195 | recv_info = aux_params->return_buffer_info + sizeof(AuxInfoDSP); | ||
| 196 | recv_buffer = aux_params->return_buffer_info + (sizeof(AuxInfoDSP) * 2); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | void EffectAuxInfo::UpdateForCommandGeneration() { | ||
| 201 | if (enabled) { | ||
| 202 | usage = UsageState::Running; | ||
| 203 | } else { | ||
| 204 | usage = UsageState::Stopped; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | VAddr EffectAuxInfo::GetSendInfo() const { | ||
| 209 | return send_info; | ||
| 210 | } | ||
| 211 | |||
| 212 | VAddr EffectAuxInfo::GetSendBuffer() const { | ||
| 213 | return send_buffer; | ||
| 214 | } | ||
| 215 | |||
| 216 | VAddr EffectAuxInfo::GetRecvInfo() const { | ||
| 217 | return recv_info; | ||
| 218 | } | ||
| 219 | |||
| 220 | VAddr EffectAuxInfo::GetRecvBuffer() const { | ||
| 221 | return recv_buffer; | ||
| 222 | } | ||
| 223 | |||
| 224 | EffectDelay::EffectDelay() : EffectGeneric(EffectType::Delay) {} | ||
| 225 | EffectDelay::~EffectDelay() = default; | ||
| 226 | |||
| 227 | void EffectDelay::Update(EffectInfo::InParams& in_params) { | ||
| 228 | const auto* delay_params = reinterpret_cast<DelayParams*>(in_params.raw.data()); | ||
| 229 | auto& params = GetParams(); | ||
| 230 | if (!ValidChannelCountForEffect(delay_params->max_channels)) { | ||
| 231 | return; | ||
| 232 | } | ||
| 233 | |||
| 234 | const auto last_status = params.status; | ||
| 235 | mix_id = in_params.mix_id; | ||
| 236 | processing_order = in_params.processing_order; | ||
| 237 | params = *delay_params; | ||
| 238 | if (!ValidChannelCountForEffect(delay_params->channels)) { | ||
| 239 | params.channels = params.max_channels; | ||
| 240 | } | ||
| 241 | enabled = in_params.is_enabled; | ||
| 242 | |||
| 243 | if (last_status != ParameterStatus::Updated) { | ||
| 244 | params.status = last_status; | ||
| 245 | } | ||
| 246 | |||
| 247 | if (in_params.is_new || skipped) { | ||
| 248 | usage = UsageState::Initialized; | ||
| 249 | params.status = ParameterStatus::Initialized; | ||
| 250 | skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | void EffectDelay::UpdateForCommandGeneration() { | ||
| 255 | if (enabled) { | ||
| 256 | usage = UsageState::Running; | ||
| 257 | } else { | ||
| 258 | usage = UsageState::Stopped; | ||
| 259 | } | ||
| 260 | GetParams().status = ParameterStatus::Updated; | ||
| 261 | } | ||
| 262 | |||
| 263 | EffectBufferMixer::EffectBufferMixer() : EffectGeneric(EffectType::BufferMixer) {} | ||
| 264 | EffectBufferMixer::~EffectBufferMixer() = default; | ||
| 265 | |||
| 266 | void EffectBufferMixer::Update(EffectInfo::InParams& in_params) { | ||
| 267 | mix_id = in_params.mix_id; | ||
| 268 | processing_order = in_params.processing_order; | ||
| 269 | GetParams() = *reinterpret_cast<BufferMixerParams*>(in_params.raw.data()); | ||
| 270 | enabled = in_params.is_enabled; | ||
| 271 | } | ||
| 272 | |||
| 273 | void EffectBufferMixer::UpdateForCommandGeneration() { | ||
| 274 | if (enabled) { | ||
| 275 | usage = UsageState::Running; | ||
| 276 | } else { | ||
| 277 | usage = UsageState::Stopped; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | |||
| 281 | EffectReverb::EffectReverb() : EffectGeneric(EffectType::Reverb) {} | ||
| 282 | EffectReverb::~EffectReverb() = default; | ||
| 283 | |||
| 284 | void EffectReverb::Update(EffectInfo::InParams& in_params) { | ||
| 285 | const auto* reverb_params = reinterpret_cast<ReverbParams*>(in_params.raw.data()); | ||
| 286 | auto& params = GetParams(); | ||
| 287 | if (!ValidChannelCountForEffect(reverb_params->max_channels)) { | ||
| 288 | return; | ||
| 289 | } | ||
| 290 | |||
| 291 | const auto last_status = params.status; | ||
| 292 | mix_id = in_params.mix_id; | ||
| 293 | processing_order = in_params.processing_order; | ||
| 294 | params = *reverb_params; | ||
| 295 | if (!ValidChannelCountForEffect(reverb_params->channels)) { | ||
| 296 | params.channels = params.max_channels; | ||
| 297 | } | ||
| 298 | enabled = in_params.is_enabled; | ||
| 299 | |||
| 300 | if (last_status != ParameterStatus::Updated) { | ||
| 301 | params.status = last_status; | ||
| 302 | } | ||
| 303 | |||
| 304 | if (in_params.is_new || skipped) { | ||
| 305 | usage = UsageState::Initialized; | ||
| 306 | params.status = ParameterStatus::Initialized; | ||
| 307 | skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | void EffectReverb::UpdateForCommandGeneration() { | ||
| 312 | if (enabled) { | ||
| 313 | usage = UsageState::Running; | ||
| 314 | } else { | ||
| 315 | usage = UsageState::Stopped; | ||
| 316 | } | ||
| 317 | GetParams().status = ParameterStatus::Updated; | ||
| 318 | } | ||
| 319 | |||
| 320 | } // namespace AudioCore | ||