summaryrefslogtreecommitdiff
path: root/src/audio_core/audio_renderer.cpp
diff options
context:
space:
mode:
authorGravatar Morph2021-07-08 12:09:21 -0400
committerGravatar GitHub2021-07-08 12:09:21 -0400
commit91a4a924b13b50f5b86fac732575c22e40d21891 (patch)
tree6511301bcbebc5b9ed6c9a1c64b19b3a8b2179dd /src/audio_core/audio_renderer.cpp
parentMerge pull request #6567 from Kelebek1/Audio2 (diff)
parentaudio_core: Preserve front channel volume after 6 to 2 downmix (diff)
downloadyuzu-91a4a924b13b50f5b86fac732575c22e40d21891.tar.gz
yuzu-91a4a924b13b50f5b86fac732575c22e40d21891.tar.xz
yuzu-91a4a924b13b50f5b86fac732575c22e40d21891.zip
Merge pull request #6569 from Kelebek1/Vol
audio_core: Preserve front channel volume after 6 to 2 downmix
Diffstat (limited to 'src/audio_core/audio_renderer.cpp')
-rw-r--r--src/audio_core/audio_renderer.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp
index ccd5ca6cc..7dba739b4 100644
--- a/src/audio_core/audio_renderer.cpp
+++ b/src/audio_core/audio_renderer.cpp
@@ -29,10 +29,9 @@ namespace {
29 (static_cast<float>(r_channel) * r_mix_amount))); 29 (static_cast<float>(r_channel) * r_mix_amount)));
30} 30}
31 31
32[[nodiscard]] static constexpr std::tuple<s16, s16> Mix6To2(s16 fl_channel, s16 fr_channel, 32[[maybe_unused, nodiscard]] static constexpr std::tuple<s16, s16> Mix6To2(
33 s16 fc_channel, 33 s16 fl_channel, s16 fr_channel, s16 fc_channel, [[maybe_unused]] s16 lf_channel, s16 bl_channel,
34 [[maybe_unused]] s16 lf_channel, 34 s16 br_channel) {
35 s16 bl_channel, s16 br_channel) {
36 // Front channels are mixed 36.94%, Center channels are mixed to be 26.12% & the back channels 35 // Front channels are mixed 36.94%, Center channels are mixed to be 26.12% & the back channels
37 // are mixed to be 36.94% 36 // are mixed to be 36.94%
38 37
@@ -57,11 +56,11 @@ namespace {
57 const std::array<float_le, 4>& coeff) { 56 const std::array<float_le, 4>& coeff) {
58 const auto left = 57 const auto left =
59 static_cast<float>(fl_channel) * coeff[0] + static_cast<float>(fc_channel) * coeff[1] + 58 static_cast<float>(fl_channel) * coeff[0] + static_cast<float>(fc_channel) * coeff[1] +
60 static_cast<float>(lf_channel) * coeff[2] + static_cast<float>(bl_channel) * coeff[0]; 59 static_cast<float>(lf_channel) * coeff[2] + static_cast<float>(bl_channel) * coeff[3];
61 60
62 const auto right = 61 const auto right =
63 static_cast<float>(fr_channel) * coeff[0] + static_cast<float>(fc_channel) * coeff[1] + 62 static_cast<float>(fr_channel) * coeff[0] + static_cast<float>(fc_channel) * coeff[1] +
64 static_cast<float>(lf_channel) * coeff[2] + static_cast<float>(br_channel) * coeff[0]; 63 static_cast<float>(lf_channel) * coeff[2] + static_cast<float>(br_channel) * coeff[3];
65 64
66 return {ClampToS16(static_cast<s32>(left)), ClampToS16(static_cast<s32>(right))}; 65 return {ClampToS16(static_cast<s32>(left)), ClampToS16(static_cast<s32>(right))};
67} 66}
@@ -241,7 +240,7 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
241 const auto channel_count = buffer_offsets.size(); 240 const auto channel_count = buffer_offsets.size();
242 const auto& final_mix = mix_context.GetFinalMixInfo(); 241 const auto& final_mix = mix_context.GetFinalMixInfo();
243 const auto& in_params = final_mix.GetInParams(); 242 const auto& in_params = final_mix.GetInParams();
244 std::vector<s32*> mix_buffers(channel_count); 243 std::vector<std::span<s32>> mix_buffers(channel_count);
245 for (std::size_t i = 0; i < channel_count; i++) { 244 for (std::size_t i = 0; i < channel_count; i++) {
246 mix_buffers[i] = 245 mix_buffers[i] =
247 command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]); 246 command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]);
@@ -294,18 +293,11 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
294 buffer[i * stream_channel_count + 0] = Mix2To1(fl_sample, fr_sample); 293 buffer[i * stream_channel_count + 0] = Mix2To1(fl_sample, fr_sample);
295 } else if (stream_channel_count == 2) { 294 } else if (stream_channel_count == 2) {
296 // Mix all channels into 2 channels 295 // Mix all channels into 2 channels
297 if (sink_context.HasDownMixingCoefficients()) { 296 const auto [left, right] = Mix6To2WithCoefficients(
298 const auto [left, right] = Mix6To2WithCoefficients( 297 fl_sample, fr_sample, fc_sample, lf_sample, bl_sample, br_sample,
299 fl_sample, fr_sample, fc_sample, lf_sample, bl_sample, br_sample, 298 sink_context.GetDownmixCoefficients());
300 sink_context.GetDownmixCoefficients()); 299 buffer[i * stream_channel_count + 0] = left;
301 buffer[i * stream_channel_count + 0] = left; 300 buffer[i * stream_channel_count + 1] = right;
302 buffer[i * stream_channel_count + 1] = right;
303 } else {
304 const auto [left, right] = Mix6To2(fl_sample, fr_sample, fc_sample,
305 lf_sample, bl_sample, br_sample);
306 buffer[i * stream_channel_count + 0] = left;
307 buffer[i * stream_channel_count + 1] = right;
308 }
309 } else if (stream_channel_count == 6) { 301 } else if (stream_channel_count == 6) {
310 // Pass through 302 // Pass through
311 buffer[i * stream_channel_count + 0] = fl_sample; 303 buffer[i * stream_channel_count + 0] = fl_sample;