summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar FearlessTobi2020-02-24 18:34:00 +0100
committerGravatar bunnei2020-03-08 03:16:06 -0400
commit59d0d34dce3fa3be6374f6a2740d69c1f622547a (patch)
tree45823c7c598d93a37b2b334edae5fef0c6c6bca3
parentMerge pull request #3452 from Morph1984/anisotropic-filtering (diff)
downloadyuzu-59d0d34dce3fa3be6374f6a2740d69c1f622547a.tar.gz
yuzu-59d0d34dce3fa3be6374f6a2740d69c1f622547a.tar.xz
yuzu-59d0d34dce3fa3be6374f6a2740d69c1f622547a.zip
cubeb_sink: Don't discard other channels when performing downmixing
Previously, when performing downmixing, we would discard all channels except the left and right one. This implementation respects them when mixing down to Stereo. It is taken from this document: http://www.atsc.org/wp-content/uploads/2015/03/A52-201212-17.pdf. Fixes Luigis Mansion 3 cutscene and Bayonetta audio.
-rw-r--r--src/audio_core/cubeb_sink.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index 7047ed9cf..c4e0e30fe 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -8,6 +8,7 @@
8#include "audio_core/cubeb_sink.h" 8#include "audio_core/cubeb_sink.h"
9#include "audio_core/stream.h" 9#include "audio_core/stream.h"
10#include "audio_core/time_stretch.h" 10#include "audio_core/time_stretch.h"
11#include "common/assert.h"
11#include "common/logging/log.h" 12#include "common/logging/log.h"
12#include "common/ring_buffer.h" 13#include "common/ring_buffer.h"
13#include "core/settings.h" 14#include "core/settings.h"
@@ -65,12 +66,25 @@ public:
65 void EnqueueSamples(u32 source_num_channels, const std::vector<s16>& samples) override { 66 void EnqueueSamples(u32 source_num_channels, const std::vector<s16>& samples) override {
66 if (source_num_channels > num_channels) { 67 if (source_num_channels > num_channels) {
67 // Downsample 6 channels to 2 68 // Downsample 6 channels to 2
69 ASSERT_MSG(source_num_channels == 6, "Channel count must be 6");
70
68 std::vector<s16> buf; 71 std::vector<s16> buf;
69 buf.reserve(samples.size() * num_channels / source_num_channels); 72 buf.reserve(samples.size() * num_channels / source_num_channels);
70 for (std::size_t i = 0; i < samples.size(); i += source_num_channels) { 73 for (std::size_t i = 0; i < samples.size(); i += source_num_channels) {
71 for (std::size_t ch = 0; ch < num_channels; ch++) { 74 // Downmixing implementation taken from the ATSC standard
72 buf.push_back(samples[i + ch]); 75 const s16 left{samples[i + 0]};
73 } 76 const s16 right{samples[i + 1]};
77 const s16 center{samples[i + 2]};
78 const s16 surround_left{samples[i + 4]};
79 const s16 surround_right{samples[i + 5]};
80 // Not used in the ATSC reference implementation
81 [[maybe_unused]] const s16 low_frequency_effects { samples[i + 3] };
82
83 constexpr s32 clev{707}; // center mixing level coefficient
84 constexpr s32 slev{707}; // surround mixing level coefficient
85
86 buf.push_back(left + (clev * center / 1000) + (slev * surround_left / 1000));
87 buf.push_back(right + (clev * center / 1000) + (slev * surround_right / 1000));
74 } 88 }
75 queue.Push(buf); 89 queue.Push(buf);
76 return; 90 return;