From ffbba74c91e2200868047f76ab5c452bb9aa338d Mon Sep 17 00:00:00 2001 From: Kelebek1 Date: Wed, 13 Dec 2023 06:26:20 +0000 Subject: Have GetActiveChannelCount return the system channels instead of host device channels --- src/audio_core/sink/sink_stream.cpp | 43 ++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'src/audio_core/sink/sink_stream.cpp') diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 2a09db599..97866f417 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp @@ -40,29 +40,38 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span samples) { if (system_channels == 6 && device_channels == 2) { // We're given 6 channels, but our device only outputs 2, so downmix. - static constexpr std::array down_mix_coeff{1.0f, 0.707f, 0.251f, 0.707f}; + // Front = 1.0 + // Center = 0.596 + // Back = 0.707 + // LFE = 0.354 + // 1.0 + 0.596 + 0.707 + 0.354 = 2.657, 1/2.657 = 0.37636f downscale coefficient + static constexpr std::array down_mix_coeff{0.37636f, 0.22431056f, 0.13323144f, + 0.26608652f}; for (u32 read_index = 0, write_index = 0; read_index < samples.size(); read_index += system_channels, write_index += device_channels) { + const auto fl = + static_cast(samples[read_index + static_cast(Channels::FrontLeft)]); + const auto fr = + static_cast(samples[read_index + static_cast(Channels::FrontRight)]); + const auto c = + static_cast(samples[read_index + static_cast(Channels::Center)]); + const auto lfe = + static_cast(samples[read_index + static_cast(Channels::LFE)]); + const auto bl = + static_cast(samples[read_index + static_cast(Channels::BackLeft)]); + const auto br = + static_cast(samples[read_index + static_cast(Channels::BackRight)]); + const auto left_sample{ - ((Common::FixedPoint<49, 15>( - samples[read_index + static_cast(Channels::FrontLeft)]) * - down_mix_coeff[0] + - samples[read_index + static_cast(Channels::Center)] * down_mix_coeff[1] + - samples[read_index + static_cast(Channels::LFE)] * down_mix_coeff[2] + - samples[read_index + static_cast(Channels::BackLeft)] * down_mix_coeff[3]) * - volume) - .to_int()}; + static_cast((fl * down_mix_coeff[0] + c * down_mix_coeff[1] + + lfe * down_mix_coeff[2] + bl * down_mix_coeff[3]) * + volume)}; const auto right_sample{ - ((Common::FixedPoint<49, 15>( - samples[read_index + static_cast(Channels::FrontRight)]) * - down_mix_coeff[0] + - samples[read_index + static_cast(Channels::Center)] * down_mix_coeff[1] + - samples[read_index + static_cast(Channels::LFE)] * down_mix_coeff[2] + - samples[read_index + static_cast(Channels::BackRight)] * down_mix_coeff[3]) * - volume) - .to_int()}; + static_cast((fr * down_mix_coeff[0] + c * down_mix_coeff[1] + + lfe * down_mix_coeff[2] + br * down_mix_coeff[3]) * + volume)}; samples[write_index + static_cast(Channels::FrontLeft)] = static_cast(std::clamp(left_sample, min, max)); -- cgit v1.2.3