diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio_core/behavior_info.cpp | 2 | ||||
| -rw-r--r-- | src/audio_core/command_generator.cpp | 155 | ||||
| -rw-r--r-- | src/audio_core/command_generator.h | 2 | ||||
| -rw-r--r-- | src/audio_core/effect_context.cpp | 11 | ||||
| -rw-r--r-- | src/audio_core/effect_context.h | 1 | ||||
| -rw-r--r-- | src/audio_core/mix_context.cpp | 1 | ||||
| -rw-r--r-- | src/audio_core/splitter_context.cpp | 10 | ||||
| -rw-r--r-- | src/audio_core/voice_context.cpp | 23 |
8 files changed, 104 insertions, 101 deletions
diff --git a/src/audio_core/behavior_info.cpp b/src/audio_core/behavior_info.cpp index b7cd8f17d..5d62adb0b 100644 --- a/src/audio_core/behavior_info.cpp +++ b/src/audio_core/behavior_info.cpp | |||
| @@ -99,7 +99,7 @@ bool BehaviorInfo::IsSplitterBugFixed() const { | |||
| 99 | 99 | ||
| 100 | void BehaviorInfo::CopyErrorInfo(BehaviorInfo::OutParams& dst) { | 100 | void BehaviorInfo::CopyErrorInfo(BehaviorInfo::OutParams& dst) { |
| 101 | dst.error_count = static_cast<u32>(error_count); | 101 | dst.error_count = static_cast<u32>(error_count); |
| 102 | std::memcpy(dst.errors.data(), errors.data(), sizeof(ErrorInfo) * dst.errors.size()); | 102 | std::copy(errors.begin(), errors.begin() + error_count, dst.errors.begin()); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | } // namespace AudioCore | 105 | } // namespace AudioCore |
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index 722f9b6c5..440bfc140 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp | |||
| @@ -10,12 +10,12 @@ | |||
| 10 | 10 | ||
| 11 | namespace AudioCore { | 11 | namespace AudioCore { |
| 12 | namespace { | 12 | namespace { |
| 13 | static constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00; | 13 | constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00; |
| 14 | static constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; | 14 | constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; |
| 15 | 15 | ||
| 16 | template <std::size_t N> | 16 | template <std::size_t N> |
| 17 | void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { | 17 | void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { |
| 18 | for (s32 i = 0; i < sample_count; i += N) { | 18 | for (std::size_t i = 0; i < static_cast<std::size_t>(sample_count); i += N) { |
| 19 | for (std::size_t j = 0; j < N; j++) { | 19 | for (std::size_t j = 0; j < N; j++) { |
| 20 | output[i + j] += | 20 | output[i + j] += |
| 21 | static_cast<s32>((static_cast<s64>(input[i + j]) * gain + 0x4000) >> 15); | 21 | static_cast<s32>((static_cast<s64>(input[i + j]) * gain + 0x4000) >> 15); |
| @@ -59,13 +59,13 @@ CommandGenerator::CommandGenerator(AudioCommon::AudioRendererParameter& worker_p | |||
| 59 | CommandGenerator::~CommandGenerator() = default; | 59 | CommandGenerator::~CommandGenerator() = default; |
| 60 | 60 | ||
| 61 | void CommandGenerator::ClearMixBuffers() { | 61 | void CommandGenerator::ClearMixBuffers() { |
| 62 | std::memset(mix_buffer.data(), 0, mix_buffer.size() * sizeof(s32)); | 62 | std::fill(mix_buffer.begin(), mix_buffer.end(), 0); |
| 63 | std::memset(sample_buffer.data(), 0, sample_buffer.size() * sizeof(s32)); | 63 | std::fill(sample_buffer.begin(), sample_buffer.end(), 0); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void CommandGenerator::GenerateVoiceCommands() { | 66 | void CommandGenerator::GenerateVoiceCommands() { |
| 67 | if (dumping_frame) { | 67 | if (dumping_frame) { |
| 68 | LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateVoiceCommands"); | 68 | LOG_DEBUG(Audio, "(DSP_TRACE) GenerateVoiceCommands"); |
| 69 | } | 69 | } |
| 70 | // Grab all our voices | 70 | // Grab all our voices |
| 71 | const auto voice_count = voice_context.GetVoiceCount(); | 71 | const auto voice_count = voice_context.GetVoiceCount(); |
| @@ -168,24 +168,26 @@ void CommandGenerator::GenerateFinalMixCommands() { | |||
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | void CommandGenerator::PreCommand() { | 170 | void CommandGenerator::PreCommand() { |
| 171 | if (dumping_frame) { | 171 | if (!dumping_frame) { |
| 172 | for (std::size_t i = 0; i < splitter_context.GetInfoCount(); i++) { | 172 | return; |
| 173 | const auto& base = splitter_context.GetInfo(i); | 173 | } |
| 174 | std::string graph = fmt::format("b[{}]", i); | 174 | for (std::size_t i = 0; i < splitter_context.GetInfoCount(); i++) { |
| 175 | auto* head = base.GetHead(); | 175 | const auto& base = splitter_context.GetInfo(i); |
| 176 | while (head != nullptr) { | 176 | std::string graph = fmt::format("b[{}]", i); |
| 177 | graph += fmt::format("->{}", head->GetMixId()); | 177 | auto* head = base.GetHead(); |
| 178 | head = head->GetNextDestination(); | 178 | while (head != nullptr) { |
| 179 | } | 179 | graph += fmt::format("->{}", head->GetMixId()); |
| 180 | LOG_CRITICAL(Audio, "(DSP_TRACE) SplitterGraph splitter_info={}, {}", i, graph); | 180 | head = head->GetNextDestination(); |
| 181 | } | 181 | } |
| 182 | LOG_DEBUG(Audio, "(DSP_TRACE) SplitterGraph splitter_info={}, {}", i, graph); | ||
| 182 | } | 183 | } |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 185 | void CommandGenerator::PostCommand() { | 186 | void CommandGenerator::PostCommand() { |
| 186 | if (dumping_frame) { | 187 | if (!dumping_frame) { |
| 187 | dumping_frame = false; | 188 | return; |
| 188 | } | 189 | } |
| 190 | dumping_frame = false; | ||
| 189 | } | 191 | } |
| 190 | 192 | ||
| 191 | void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, | 193 | void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, |
| @@ -194,29 +196,31 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo | |||
| 194 | const auto depop = in_params.should_depop; | 196 | const auto depop = in_params.should_depop; |
| 195 | 197 | ||
| 196 | if (in_params.mix_id != AudioCommon::NO_MIX) { | 198 | if (in_params.mix_id != AudioCommon::NO_MIX) { |
| 197 | auto& mix_info = mix_context.GetInfo(in_params.mix_id); | 199 | [[maybe_unused]] auto& mix_info = mix_context.GetInfo(in_params.mix_id); |
| 198 | // mix_info. | 200 | // mix_info. |
| 199 | // TODO(ogniK): Depop to destination mix | 201 | // TODO(ogniK): Depop to destination mix |
| 200 | } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) { | 202 | } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) { |
| 201 | // TODO(ogniK): Depop to splitter | 203 | // TODO(ogniK): Depop to splitter |
| 202 | } | 204 | } |
| 203 | 205 | ||
| 204 | if (!depop) { | 206 | if (depop) { |
| 205 | switch (in_params.sample_format) { | 207 | return; |
| 206 | case SampleFormat::Pcm16: | 208 | } |
| 207 | DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, | 209 | |
| 208 | worker_params.sample_rate, worker_params.sample_count, | 210 | switch (in_params.sample_format) { |
| 209 | in_params.node_id); | 211 | case SampleFormat::Pcm16: |
| 210 | break; | 212 | DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, |
| 211 | case SampleFormat::Adpcm: | 213 | worker_params.sample_rate, worker_params.sample_count, |
| 212 | ASSERT(channel == 0 && in_params.channel_count == 1); | 214 | in_params.node_id); |
| 213 | DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0, | 215 | break; |
| 214 | worker_params.sample_rate, worker_params.sample_count, | 216 | case SampleFormat::Adpcm: |
| 215 | in_params.node_id); | 217 | ASSERT(channel == 0 && in_params.channel_count == 1); |
| 216 | break; | 218 | DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0, |
| 217 | default: | 219 | worker_params.sample_rate, worker_params.sample_count, |
| 218 | UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); | 220 | in_params.node_id); |
| 219 | } | 221 | break; |
| 222 | default: | ||
| 223 | UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); | ||
| 220 | } | 224 | } |
| 221 | } | 225 | } |
| 222 | 226 | ||
| @@ -233,8 +237,7 @@ void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voic | |||
| 233 | 237 | ||
| 234 | // Reinitialize our biquad filter state if it was enabled previously | 238 | // Reinitialize our biquad filter state if it was enabled previously |
| 235 | if (!in_params.was_biquad_filter_enabled[i]) { | 239 | if (!in_params.was_biquad_filter_enabled[i]) { |
| 236 | std::memset(dsp_state.biquad_filter_state.data(), 0, | 240 | dsp_state.biquad_filter_state.fill(0); |
| 237 | dsp_state.biquad_filter_state.size() * sizeof(s64)); | ||
| 238 | } | 241 | } |
| 239 | 242 | ||
| 240 | // Generate biquad filter | 243 | // Generate biquad filter |
| @@ -248,39 +251,34 @@ void AudioCore::CommandGenerator::GenerateBiquadFilterCommand( | |||
| 248 | s32 mix_buffer, const BiquadFilterParameter& params, std::array<s64, 2>& state, | 251 | s32 mix_buffer, const BiquadFilterParameter& params, std::array<s64, 2>& state, |
| 249 | std::size_t input_offset, std::size_t output_offset, s32 sample_count, s32 node_id) { | 252 | std::size_t input_offset, std::size_t output_offset, s32 sample_count, s32 node_id) { |
| 250 | if (dumping_frame) { | 253 | if (dumping_frame) { |
| 251 | LOG_CRITICAL(Audio, | 254 | LOG_DEBUG(Audio, |
| 252 | "(DSP_TRACE) GenerateBiquadFilterCommand node_id={}, " | 255 | "(DSP_TRACE) GenerateBiquadFilterCommand node_id={}, " |
| 253 | "input_mix_buffer={}, output_mix_buffer={}", | 256 | "input_mix_buffer={}, output_mix_buffer={}", |
| 254 | node_id, input_offset, output_offset); | 257 | node_id, input_offset, output_offset); |
| 255 | } | 258 | } |
| 256 | const auto* input = GetMixBuffer(input_offset); | 259 | const auto* input = GetMixBuffer(input_offset); |
| 257 | auto* output = GetMixBuffer(output_offset); | 260 | auto* output = GetMixBuffer(output_offset); |
| 258 | 261 | ||
| 259 | // Biquad filter parameters | 262 | // Biquad filter parameters |
| 260 | const auto n0 = params.numerator[0]; | 263 | const auto [n0, n1, n2] = params.numerator; |
| 261 | const auto n1 = params.numerator[1]; | 264 | const auto [d0, d1] = params.denominator; |
| 262 | const auto n2 = params.numerator[2]; | ||
| 263 | const auto d0 = params.denominator[0]; | ||
| 264 | const auto d1 = params.denominator[1]; | ||
| 265 | 265 | ||
| 266 | // Biquad filter states | 266 | // Biquad filter states |
| 267 | auto s0 = state[0]; | 267 | auto [s0, s1] = state; |
| 268 | auto s1 = state[1]; | ||
| 269 | 268 | ||
| 270 | constexpr s64 MIN = std::numeric_limits<int32_t>::min(); | 269 | constexpr s64 int32_min = std::numeric_limits<s32>::min(); |
| 271 | constexpr s64 MAX = std::numeric_limits<int32_t>::max(); | 270 | constexpr s64 int32_max = std::numeric_limits<s32>::max(); |
| 272 | 271 | ||
| 273 | for (int i = 0; i < sample_count; ++i) { | 272 | for (int i = 0; i < sample_count; ++i) { |
| 274 | const auto sample = static_cast<int64_t>(input[i]); | 273 | const auto sample = static_cast<s64>(input[i]); |
| 275 | const auto f = (sample * n0 + s0 + 0x4000) >> 15; | 274 | const auto f = (sample * n0 + s0 + 0x4000) >> 15; |
| 276 | const auto y = std::clamp(f, MIN, MAX); | 275 | const auto y = std::clamp(f, int32_min, int32_max); |
| 277 | s0 = sample * n1 + y * d0 + s1; | 276 | s0 = sample * n1 + y * d0 + s1; |
| 278 | s1 = sample * n2 + y * d1; | 277 | s1 = sample * n2 + y * d1; |
| 279 | output[i] = static_cast<s32>(y); | 278 | output[i] = static_cast<s32>(y); |
| 280 | } | 279 | } |
| 281 | 280 | ||
| 282 | state[0] = s0; | 281 | state = {s0, s1}; |
| 283 | state[1] = s1; | ||
| 284 | } | 282 | } |
| 285 | 283 | ||
| 286 | ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter_id, s32 index) { | 284 | ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter_id, s32 index) { |
| @@ -298,11 +296,11 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren | |||
| 298 | static_cast<float>(worker_params.sample_count)); | 296 | static_cast<float>(worker_params.sample_count)); |
| 299 | 297 | ||
| 300 | if (dumping_frame) { | 298 | if (dumping_frame) { |
| 301 | LOG_CRITICAL(Audio, | 299 | LOG_DEBUG(Audio, |
| 302 | "(DSP_TRACE) GenerateVolumeRampCommand node_id={}, input={}, output={}, " | 300 | "(DSP_TRACE) GenerateVolumeRampCommand node_id={}, input={}, output={}, " |
| 303 | "last_volume={}, current_volume={}", | 301 | "last_volume={}, current_volume={}", |
| 304 | node_id, GetMixChannelBufferOffset(channel), | 302 | node_id, GetMixChannelBufferOffset(channel), GetMixChannelBufferOffset(channel), |
| 305 | GetMixChannelBufferOffset(channel), last_volume, current_volume); | 303 | last_volume, current_volume); |
| 306 | } | 304 | } |
| 307 | // Apply generic gain on samples | 305 | // Apply generic gain on samples |
| 308 | ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta, | 306 | ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta, |
| @@ -320,11 +318,11 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume | |||
| 320 | static_cast<float>(worker_params.sample_count); | 318 | static_cast<float>(worker_params.sample_count); |
| 321 | 319 | ||
| 322 | if (dumping_frame) { | 320 | if (dumping_frame) { |
| 323 | LOG_CRITICAL(Audio, | 321 | LOG_DEBUG(Audio, |
| 324 | "(DSP_TRACE) GenerateVoiceMixCommand node_id={}, input={}, " | 322 | "(DSP_TRACE) GenerateVoiceMixCommand node_id={}, input={}, " |
| 325 | "output={}, last_volume={}, current_volume={}", | 323 | "output={}, last_volume={}, current_volume={}", |
| 326 | node_id, voice_index, mix_buffer_offset + i, last_mix_volumes[i], | 324 | node_id, voice_index, mix_buffer_offset + i, last_mix_volumes[i], |
| 327 | mix_volumes[i]); | 325 | mix_volumes[i]); |
| 328 | } | 326 | } |
| 329 | 327 | ||
| 330 | dsp_state.previous_samples[i] = | 328 | dsp_state.previous_samples[i] = |
| @@ -338,7 +336,7 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume | |||
| 338 | 336 | ||
| 339 | void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) { | 337 | void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) { |
| 340 | if (dumping_frame) { | 338 | if (dumping_frame) { |
| 341 | LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateSubMixCommand"); | 339 | LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand"); |
| 342 | } | 340 | } |
| 343 | // TODO(ogniK): Depop | 341 | // TODO(ogniK): Depop |
| 344 | // TODO(ogniK): Effects | 342 | // TODO(ogniK): Effects |
| @@ -391,9 +389,9 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t | |||
| 391 | float volume, s32 node_id) { | 389 | float volume, s32 node_id) { |
| 392 | 390 | ||
| 393 | if (dumping_frame) { | 391 | if (dumping_frame) { |
| 394 | LOG_CRITICAL(Audio, | 392 | LOG_DEBUG(Audio, |
| 395 | "(DSP_TRACE) GenerateMixCommand node_id={}, input={}, output={}, volume={}", | 393 | "(DSP_TRACE) GenerateMixCommand node_id={}, input={}, output={}, volume={}", |
| 396 | node_id, input_offset, output_offset, volume); | 394 | node_id, input_offset, output_offset, volume); |
| 397 | } | 395 | } |
| 398 | 396 | ||
| 399 | auto* output = GetMixBuffer(output_offset); | 397 | auto* output = GetMixBuffer(output_offset); |
| @@ -412,7 +410,7 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t | |||
| 412 | 410 | ||
| 413 | void CommandGenerator::GenerateFinalMixCommand() { | 411 | void CommandGenerator::GenerateFinalMixCommand() { |
| 414 | if (dumping_frame) { | 412 | if (dumping_frame) { |
| 415 | LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateFinalMixCommand"); | 413 | LOG_DEBUG(Audio, "(DSP_TRACE) GenerateFinalMixCommand"); |
| 416 | } | 414 | } |
| 417 | // TODO(ogniK): Depop | 415 | // TODO(ogniK): Depop |
| 418 | // TODO(ogniK): Effects | 416 | // TODO(ogniK): Effects |
| @@ -421,7 +419,7 @@ void CommandGenerator::GenerateFinalMixCommand() { | |||
| 421 | for (s32 i = 0; i < in_params.buffer_count; i++) { | 419 | for (s32 i = 0; i < in_params.buffer_count; i++) { |
| 422 | const s32 gain = static_cast<s32>(in_params.volume * 32768.0f); | 420 | const s32 gain = static_cast<s32>(in_params.volume * 32768.0f); |
| 423 | if (dumping_frame) { | 421 | if (dumping_frame) { |
| 424 | LOG_CRITICAL( | 422 | LOG_DEBUG( |
| 425 | Audio, | 423 | Audio, |
| 426 | "(DSP_TRACE) ApplyGainWithoutDelta node_id={}, input={}, output={}, volume={}", | 424 | "(DSP_TRACE) ApplyGainWithoutDelta node_id={}, input={}, output={}, volume={}", |
| 427 | in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i, | 425 | in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i, |
| @@ -544,11 +542,11 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o | |||
| 544 | s32 node_id) { | 542 | s32 node_id) { |
| 545 | auto& in_params = voice_info.GetInParams(); | 543 | auto& in_params = voice_info.GetInParams(); |
| 546 | if (dumping_frame) { | 544 | if (dumping_frame) { |
| 547 | LOG_CRITICAL(Audio, | 545 | LOG_DEBUG(Audio, |
| 548 | "(DSP_TRACE) DecodeFromWaveBuffers, node_id={}, channel={}, " | 546 | "(DSP_TRACE) DecodeFromWaveBuffers, node_id={}, channel={}, " |
| 549 | "format={}, sample_count={}, sample_rate={}, mix_id={}, splitter_id={}", | 547 | "format={}, sample_count={}, sample_rate={}, mix_id={}, splitter_id={}", |
| 550 | node_id, channel, in_params.sample_format, sample_count, in_params.sample_rate, | 548 | node_id, channel, in_params.sample_format, sample_count, in_params.sample_rate, |
| 551 | in_params.mix_id, in_params.splitter_info_id); | 549 | in_params.mix_id, in_params.splitter_info_id); |
| 552 | } | 550 | } |
| 553 | ASSERT_OR_EXECUTE(output != nullptr, { return; }); | 551 | ASSERT_OR_EXECUTE(output != nullptr, { return; }); |
| 554 | 552 | ||
| @@ -649,10 +647,11 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o | |||
| 649 | 647 | ||
| 650 | if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) { | 648 | if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) { |
| 651 | // No need to resample | 649 | // No need to resample |
| 652 | memcpy(output, sample_buffer.data(), samples_read * sizeof(s32)); | 650 | std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32)); |
| 653 | } else { | 651 | } else { |
| 654 | std::memset(sample_buffer.data() + temp_mix_offset, 0, | 652 | std::fill(sample_buffer.begin() + temp_mix_offset, |
| 655 | sizeof(s32) * (samples_to_read - samples_read)); | 653 | sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read), |
| 654 | 0); | ||
| 656 | AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction, | 655 | AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction, |
| 657 | samples_to_output); | 656 | samples_to_output); |
| 658 | // Resample | 657 | // Resample |
diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index e0d7510fc..3ad8973b5 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h | |||
| @@ -19,7 +19,9 @@ class MixContext; | |||
| 19 | class SplitterContext; | 19 | class SplitterContext; |
| 20 | class ServerSplitterDestinationData; | 20 | class ServerSplitterDestinationData; |
| 21 | class ServerMixInfo; | 21 | class ServerMixInfo; |
| 22 | |||
| 22 | using MixVolumeBuffer = std::array<float, AudioCommon::MAX_MIX_BUFFERS>; | 23 | using MixVolumeBuffer = std::array<float, AudioCommon::MAX_MIX_BUFFERS>; |
| 24 | |||
| 23 | class CommandGenerator { | 25 | class CommandGenerator { |
| 24 | public: | 26 | public: |
| 25 | explicit CommandGenerator(AudioCommon::AudioRendererParameter& worker_params, | 27 | explicit CommandGenerator(AudioCommon::AudioRendererParameter& worker_params, |
diff --git a/src/audio_core/effect_context.cpp b/src/audio_core/effect_context.cpp index c42e71c1c..2497d2f32 100644 --- a/src/audio_core/effect_context.cpp +++ b/src/audio_core/effect_context.cpp | |||
| @@ -2,13 +2,14 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include "audio_core/effect_context.h" | 6 | #include "audio_core/effect_context.h" |
| 6 | 7 | ||
| 7 | namespace AudioCore { | 8 | namespace AudioCore { |
| 8 | EffectContext::EffectContext(std::size_t effect_count) : effect_count(effect_count) { | 9 | EffectContext::EffectContext(std::size_t effect_count) : effect_count(effect_count) { |
| 9 | for (std::size_t i = 0; i < effect_count; i++) { | 10 | effects.reserve(effect_count); |
| 10 | effects.push_back(std::make_unique<EffectStubbed>()); | 11 | std::generate_n(std::back_inserter(effects), effect_count, |
| 11 | } | 12 | [] { return std::make_unique<EffectStubbed>(); }); |
| 12 | } | 13 | } |
| 13 | EffectContext::~EffectContext() = default; | 14 | EffectContext::~EffectContext() = default; |
| 14 | 15 | ||
| @@ -20,6 +21,10 @@ EffectBase* EffectContext::GetInfo(std::size_t i) { | |||
| 20 | return effects.at(i).get(); | 21 | return effects.at(i).get(); |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 24 | const EffectBase* EffectContext::GetInfo(std::size_t i) const { | ||
| 25 | return effects.at(i).get(); | ||
| 26 | } | ||
| 27 | |||
| 23 | EffectStubbed::EffectStubbed() : EffectBase::EffectBase() {} | 28 | EffectStubbed::EffectStubbed() : EffectBase::EffectBase() {} |
| 24 | EffectStubbed::~EffectStubbed() = default; | 29 | EffectStubbed::~EffectStubbed() = default; |
| 25 | 30 | ||
diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index 09aedf385..e3c367296 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h | |||
| @@ -106,6 +106,7 @@ public: | |||
| 106 | 106 | ||
| 107 | std::size_t GetCount() const; | 107 | std::size_t GetCount() const; |
| 108 | EffectBase* GetInfo(std::size_t i); | 108 | EffectBase* GetInfo(std::size_t i); |
| 109 | const EffectBase* GetInfo(std::size_t i) const; | ||
| 109 | 110 | ||
| 110 | private: | 111 | private: |
| 111 | std::size_t effect_count{}; | 112 | std::size_t effect_count{}; |
diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp index 8e150db03..f6f119a11 100644 --- a/src/audio_core/mix_context.cpp +++ b/src/audio_core/mix_context.cpp | |||
| @@ -16,6 +16,7 @@ void MixContext::Initialize(const BehaviorInfo& behavior_info, std::size_t mix_c | |||
| 16 | infos.resize(info_count); | 16 | infos.resize(info_count); |
| 17 | auto& final_mix = GetInfo(AudioCommon::FINAL_MIX); | 17 | auto& final_mix = GetInfo(AudioCommon::FINAL_MIX); |
| 18 | final_mix.GetInParams().mix_id = AudioCommon::FINAL_MIX; | 18 | final_mix.GetInParams().mix_id = AudioCommon::FINAL_MIX; |
| 19 | sorted_info.reserve(infos.size()); | ||
| 19 | for (auto& info : infos) { | 20 | for (auto& info : infos) { |
| 20 | sorted_info.push_back(&info); | 21 | sorted_info.push_back(&info); |
| 21 | } | 22 | } |
diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index c0be26be1..79bb2f516 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp | |||
| @@ -173,7 +173,7 @@ void SplitterContext::Initialize(BehaviorInfo& behavior_info, std::size_t _info_ | |||
| 173 | 173 | ||
| 174 | bool SplitterContext::Update(const std::vector<u8>& input, std::size_t& input_offset, | 174 | bool SplitterContext::Update(const std::vector<u8>& input, std::size_t& input_offset, |
| 175 | std::size_t& bytes_read) { | 175 | std::size_t& bytes_read) { |
| 176 | auto UpdateOffsets = [&](std::size_t read) { | 176 | const auto UpdateOffsets = [&](std::size_t read) { |
| 177 | input_offset += read; | 177 | input_offset += read; |
| 178 | bytes_read += read; | 178 | bytes_read += read; |
| 179 | }; | 179 | }; |
| @@ -286,7 +286,7 @@ void SplitterContext::Setup(std::size_t _info_count, std::size_t _data_count, | |||
| 286 | 286 | ||
| 287 | bool SplitterContext::UpdateInfo(const std::vector<u8>& input, std::size_t& input_offset, | 287 | bool SplitterContext::UpdateInfo(const std::vector<u8>& input, std::size_t& input_offset, |
| 288 | std::size_t& bytes_read, s32 in_splitter_count) { | 288 | std::size_t& bytes_read, s32 in_splitter_count) { |
| 289 | auto UpdateOffsets = [&](std::size_t read) { | 289 | const auto UpdateOffsets = [&](std::size_t read) { |
| 290 | input_offset += read; | 290 | input_offset += read; |
| 291 | bytes_read += read; | 291 | bytes_read += read; |
| 292 | }; | 292 | }; |
| @@ -326,7 +326,7 @@ bool SplitterContext::UpdateInfo(const std::vector<u8>& input, std::size_t& inpu | |||
| 326 | 326 | ||
| 327 | bool SplitterContext::UpdateData(const std::vector<u8>& input, std::size_t& input_offset, | 327 | bool SplitterContext::UpdateData(const std::vector<u8>& input, std::size_t& input_offset, |
| 328 | std::size_t& bytes_read, s32 in_data_count) { | 328 | std::size_t& bytes_read, s32 in_data_count) { |
| 329 | auto UpdateOffsets = [&](std::size_t read) { | 329 | const auto UpdateOffsets = [&](std::size_t read) { |
| 330 | input_offset += read; | 330 | input_offset += read; |
| 331 | bytes_read += read; | 331 | bytes_read += read; |
| 332 | }; | 332 | }; |
| @@ -412,9 +412,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, | |||
| 412 | NodeStates::NodeStates() = default; | 412 | NodeStates::NodeStates() = default; |
| 413 | NodeStates::~NodeStates() = default; | 413 | NodeStates::~NodeStates() = default; |
| 414 | 414 | ||
| 415 | void NodeStates::Initialize(std::size_t _node_count) { | 415 | void NodeStates::Initialize(std::size_t node_count_) { |
| 416 | // Setup our work parameters | 416 | // Setup our work parameters |
| 417 | node_count = _node_count; | 417 | node_count = node_count_; |
| 418 | was_node_found.resize(node_count); | 418 | was_node_found.resize(node_count); |
| 419 | was_node_completed.resize(node_count); | 419 | was_node_completed.resize(node_count); |
| 420 | index_list.resize(node_count); | 420 | index_list.resize(node_count); |
diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index 038595ae0..1d8f69844 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp | |||
| @@ -29,12 +29,12 @@ void ServerVoiceChannelResource::Update(VoiceChannelResource::InParams& in_param | |||
| 29 | in_use = in_params.in_use; | 29 | in_use = in_params.in_use; |
| 30 | // Update our mix volumes only if it's in use | 30 | // Update our mix volumes only if it's in use |
| 31 | if (in_params.in_use) { | 31 | if (in_params.in_use) { |
| 32 | std::copy(in_params.mix_volume.begin(), in_params.mix_volume.end(), mix_volume.begin()); | 32 | mix_volume = in_params.mix_volume; |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | void ServerVoiceChannelResource::UpdateLastMixVolumes() { | 36 | void ServerVoiceChannelResource::UpdateLastMixVolumes() { |
| 37 | std::copy(mix_volume.begin(), mix_volume.end(), last_mix_volume.begin()); | 37 | last_mix_volume = mix_volume; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | const std::array<float, AudioCommon::MAX_MIX_BUFFERS>& | 40 | const std::array<float, AudioCommon::MAX_MIX_BUFFERS>& |
| @@ -64,8 +64,7 @@ void ServerVoiceInfo::Initialize() { | |||
| 64 | in_params.pitch = 0.0f; | 64 | in_params.pitch = 0.0f; |
| 65 | in_params.volume = 0.0f; | 65 | in_params.volume = 0.0f; |
| 66 | in_params.last_volume = 0.0f; | 66 | in_params.last_volume = 0.0f; |
| 67 | std::memset(in_params.biquad_filter.data(), 0, | 67 | in_params.biquad_filter.fill({}); |
| 68 | sizeof(BiquadFilterParameter) * in_params.biquad_filter.size()); | ||
| 69 | in_params.wave_buffer_count = 0; | 68 | in_params.wave_buffer_count = 0; |
| 70 | in_params.wave_bufffer_head = 0; | 69 | in_params.wave_bufffer_head = 0; |
| 71 | in_params.mix_id = AudioCommon::NO_MIX; | 70 | in_params.mix_id = AudioCommon::NO_MIX; |
| @@ -78,8 +77,7 @@ void ServerVoiceInfo::Initialize() { | |||
| 78 | in_params.voice_drop_flag = false; | 77 | in_params.voice_drop_flag = false; |
| 79 | in_params.buffer_mapped = false; | 78 | in_params.buffer_mapped = false; |
| 80 | in_params.wave_buffer_flush_request_count = 0; | 79 | in_params.wave_buffer_flush_request_count = 0; |
| 81 | std::fill(in_params.was_biquad_filter_enabled.begin(), | 80 | in_params.was_biquad_filter_enabled.fill(false); |
| 82 | in_params.was_biquad_filter_enabled.end(), false); | ||
| 83 | 81 | ||
| 84 | for (auto& wave_buffer : in_params.wave_buffer) { | 82 | for (auto& wave_buffer : in_params.wave_buffer) { |
| 85 | wave_buffer.start_sample_offset = 0; | 83 | wave_buffer.start_sample_offset = 0; |
| @@ -126,8 +124,7 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in, | |||
| 126 | in_params.channel_count = voice_in.channel_count; | 124 | in_params.channel_count = voice_in.channel_count; |
| 127 | in_params.pitch = voice_in.pitch; | 125 | in_params.pitch = voice_in.pitch; |
| 128 | in_params.volume = voice_in.volume; | 126 | in_params.volume = voice_in.volume; |
| 129 | std::memcpy(in_params.biquad_filter.data(), voice_in.biquad_filter.data(), | 127 | in_params.biquad_filter = voice_in.biquad_filter; |
| 130 | sizeof(BiquadFilterParameter) * voice_in.biquad_filter.size()); | ||
| 131 | in_params.wave_buffer_count = voice_in.wave_buffer_count; | 128 | in_params.wave_buffer_count = voice_in.wave_buffer_count; |
| 132 | in_params.wave_bufffer_head = voice_in.wave_buffer_head; | 129 | in_params.wave_bufffer_head = voice_in.wave_buffer_head; |
| 133 | if (behavior_info.IsFlushVoiceWaveBuffersSupported()) { | 130 | if (behavior_info.IsFlushVoiceWaveBuffersSupported()) { |
| @@ -308,7 +305,7 @@ void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) { | |||
| 308 | const auto channel_resource = in_params.voice_channel_resource_id[i]; | 305 | const auto channel_resource = in_params.voice_channel_resource_id[i]; |
| 309 | auto& dsp_state = | 306 | auto& dsp_state = |
| 310 | voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource)); | 307 | voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource)); |
| 311 | std::memset(&dsp_state, 0, sizeof(VoiceState)); | 308 | dsp_state = {}; |
| 312 | voice_context.GetChannelResource(static_cast<std::size_t>(channel_resource)) | 309 | voice_context.GetChannelResource(static_cast<std::size_t>(channel_resource)) |
| 313 | .UpdateLastMixVolumes(); | 310 | .UpdateLastMixVolumes(); |
| 314 | } | 311 | } |
| @@ -362,9 +359,8 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( | |||
| 362 | dsp_state->offset = 0; | 359 | dsp_state->offset = 0; |
| 363 | dsp_state->played_sample_count = 0; | 360 | dsp_state->played_sample_count = 0; |
| 364 | dsp_state->fraction = 0; | 361 | dsp_state->fraction = 0; |
| 365 | std::memset(dsp_state->sample_history.data(), 0, | 362 | dsp_state->sample_history.fill(0); |
| 366 | sizeof(s32) * dsp_state->sample_history.size()); | 363 | dsp_state->context = {}; |
| 367 | std::memset(&dsp_state->context, 0, sizeof(dsp_state->context)); | ||
| 368 | } | 364 | } |
| 369 | 365 | ||
| 370 | in_params.current_playstate = ServerPlayState::Stop; | 366 | in_params.current_playstate = ServerPlayState::Stop; |
| @@ -524,8 +520,7 @@ void VoiceContext::SortInfo() { | |||
| 524 | } | 520 | } |
| 525 | 521 | ||
| 526 | void VoiceContext::UpdateStateByDspShared() { | 522 | void VoiceContext::UpdateStateByDspShared() { |
| 527 | std::memcpy(voice_states.data(), dsp_voice_states.data(), | 523 | voice_states = dsp_voice_states; |
| 528 | sizeof(VoiceState) * dsp_voice_states.size()); | ||
| 529 | } | 524 | } |
| 530 | 525 | ||
| 531 | } // namespace AudioCore | 526 | } // namespace AudioCore |