diff options
| author | 2023-12-13 06:26:20 +0000 | |
|---|---|---|
| committer | 2023-12-16 12:49:28 -0500 | |
| commit | ffbba74c91e2200868047f76ab5c452bb9aa338d (patch) | |
| tree | bf3477ac30013763ea12486272b4aaf42a94cef3 | |
| parent | Merge pull request #12184 from Kelebek1/system_settings (diff) | |
| download | yuzu-ffbba74c91e2200868047f76ab5c452bb9aa338d.tar.gz yuzu-ffbba74c91e2200868047f76ab5c452bb9aa338d.tar.xz yuzu-ffbba74c91e2200868047f76ab5c452bb9aa338d.zip | |
Have GetActiveChannelCount return the system channels instead of host device channels
| -rw-r--r-- | src/audio_core/sink/cubeb_sink.cpp | 3 | ||||
| -rw-r--r-- | src/audio_core/sink/sdl2_sink.cpp | 3 | ||||
| -rw-r--r-- | src/audio_core/sink/sink.h | 12 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.cpp | 43 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audren_u.cpp | 2 |
5 files changed, 43 insertions, 20 deletions
diff --git a/src/audio_core/sink/cubeb_sink.cpp b/src/audio_core/sink/cubeb_sink.cpp index 51a23fe15..d97ca2a40 100644 --- a/src/audio_core/sink/cubeb_sink.cpp +++ b/src/audio_core/sink/cubeb_sink.cpp | |||
| @@ -253,8 +253,9 @@ CubebSink::~CubebSink() { | |||
| 253 | #endif | 253 | #endif |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels, | 256 | SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels_, |
| 257 | const std::string& name, StreamType type) { | 257 | const std::string& name, StreamType type) { |
| 258 | system_channels = system_channels_; | ||
| 258 | SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<CubebSinkStream>( | 259 | SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<CubebSinkStream>( |
| 259 | ctx, device_channels, system_channels, output_device, input_device, name, type, system)); | 260 | ctx, device_channels, system_channels, output_device, input_device, name, type, system)); |
| 260 | 261 | ||
diff --git a/src/audio_core/sink/sdl2_sink.cpp b/src/audio_core/sink/sdl2_sink.cpp index 96e0efce2..7dd155ff0 100644 --- a/src/audio_core/sink/sdl2_sink.cpp +++ b/src/audio_core/sink/sdl2_sink.cpp | |||
| @@ -168,8 +168,9 @@ SDLSink::SDLSink(std::string_view target_device_name) { | |||
| 168 | 168 | ||
| 169 | SDLSink::~SDLSink() = default; | 169 | SDLSink::~SDLSink() = default; |
| 170 | 170 | ||
| 171 | SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels, | 171 | SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels_, |
| 172 | const std::string&, StreamType type) { | 172 | const std::string&, StreamType type) { |
| 173 | system_channels = system_channels_; | ||
| 173 | SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<SDLSinkStream>( | 174 | SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<SDLSinkStream>( |
| 174 | device_channels, system_channels, output_device, input_device, type, system)); | 175 | device_channels, system_channels, output_device, input_device, type, system)); |
| 175 | return stream.get(); | 176 | return stream.get(); |
diff --git a/src/audio_core/sink/sink.h b/src/audio_core/sink/sink.h index f28c6d126..e22e8c3e5 100644 --- a/src/audio_core/sink/sink.h +++ b/src/audio_core/sink/sink.h | |||
| @@ -85,9 +85,21 @@ public: | |||
| 85 | */ | 85 | */ |
| 86 | virtual void SetSystemVolume(f32 volume) = 0; | 86 | virtual void SetSystemVolume(f32 volume) = 0; |
| 87 | 87 | ||
| 88 | /** | ||
| 89 | * Get the number of channels the game has set, can be different to the host hardware's support. | ||
| 90 | * Either 2 or 6. | ||
| 91 | * | ||
| 92 | * @return Number of device channels. | ||
| 93 | */ | ||
| 94 | u32 GetSystemChannels() const { | ||
| 95 | return system_channels; | ||
| 96 | } | ||
| 97 | |||
| 88 | protected: | 98 | protected: |
| 89 | /// Number of device channels supported by the hardware | 99 | /// Number of device channels supported by the hardware |
| 90 | u32 device_channels{2}; | 100 | u32 device_channels{2}; |
| 101 | /// Number of channels the game is sending | ||
| 102 | u32 system_channels{2}; | ||
| 91 | }; | 103 | }; |
| 92 | 104 | ||
| 93 | using SinkPtr = std::unique_ptr<Sink>; | 105 | using SinkPtr = std::unique_ptr<Sink>; |
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<s16> samples) { | |||
| 40 | 40 | ||
| 41 | if (system_channels == 6 && device_channels == 2) { | 41 | if (system_channels == 6 && device_channels == 2) { |
| 42 | // We're given 6 channels, but our device only outputs 2, so downmix. | 42 | // We're given 6 channels, but our device only outputs 2, so downmix. |
| 43 | static constexpr std::array<f32, 4> down_mix_coeff{1.0f, 0.707f, 0.251f, 0.707f}; | 43 | // Front = 1.0 |
| 44 | // Center = 0.596 | ||
| 45 | // Back = 0.707 | ||
| 46 | // LFE = 0.354 | ||
| 47 | // 1.0 + 0.596 + 0.707 + 0.354 = 2.657, 1/2.657 = 0.37636f downscale coefficient | ||
| 48 | static constexpr std::array<f32, 4> down_mix_coeff{0.37636f, 0.22431056f, 0.13323144f, | ||
| 49 | 0.26608652f}; | ||
| 44 | 50 | ||
| 45 | for (u32 read_index = 0, write_index = 0; read_index < samples.size(); | 51 | for (u32 read_index = 0, write_index = 0; read_index < samples.size(); |
| 46 | read_index += system_channels, write_index += device_channels) { | 52 | read_index += system_channels, write_index += device_channels) { |
| 53 | const auto fl = | ||
| 54 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontLeft)]); | ||
| 55 | const auto fr = | ||
| 56 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontRight)]); | ||
| 57 | const auto c = | ||
| 58 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::Center)]); | ||
| 59 | const auto lfe = | ||
| 60 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::LFE)]); | ||
| 61 | const auto bl = | ||
| 62 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackLeft)]); | ||
| 63 | const auto br = | ||
| 64 | static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackRight)]); | ||
| 65 | |||
| 47 | const auto left_sample{ | 66 | const auto left_sample{ |
| 48 | ((Common::FixedPoint<49, 15>( | 67 | static_cast<s32>((fl * down_mix_coeff[0] + c * down_mix_coeff[1] + |
| 49 | samples[read_index + static_cast<u32>(Channels::FrontLeft)]) * | 68 | lfe * down_mix_coeff[2] + bl * down_mix_coeff[3]) * |
| 50 | down_mix_coeff[0] + | 69 | volume)}; |
| 51 | samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] + | ||
| 52 | samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] + | ||
| 53 | samples[read_index + static_cast<u32>(Channels::BackLeft)] * down_mix_coeff[3]) * | ||
| 54 | volume) | ||
| 55 | .to_int()}; | ||
| 56 | 70 | ||
| 57 | const auto right_sample{ | 71 | const auto right_sample{ |
| 58 | ((Common::FixedPoint<49, 15>( | 72 | static_cast<s32>((fr * down_mix_coeff[0] + c * down_mix_coeff[1] + |
| 59 | samples[read_index + static_cast<u32>(Channels::FrontRight)]) * | 73 | lfe * down_mix_coeff[2] + br * down_mix_coeff[3]) * |
| 60 | down_mix_coeff[0] + | 74 | volume)}; |
| 61 | samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] + | ||
| 62 | samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] + | ||
| 63 | samples[read_index + static_cast<u32>(Channels::BackRight)] * down_mix_coeff[3]) * | ||
| 64 | volume) | ||
| 65 | .to_int()}; | ||
| 66 | 75 | ||
| 67 | samples[write_index + static_cast<u32>(Channels::FrontLeft)] = | 76 | samples[write_index + static_cast<u32>(Channels::FrontLeft)] = |
| 68 | static_cast<s16>(std::clamp(left_sample, min, max)); | 77 | static_cast<s16>(std::clamp(left_sample, min, max)); |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 2f09cade5..23e56c77a 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -359,7 +359,7 @@ private: | |||
| 359 | 359 | ||
| 360 | void GetActiveChannelCount(HLERequestContext& ctx) { | 360 | void GetActiveChannelCount(HLERequestContext& ctx) { |
| 361 | const auto& sink{system.AudioCore().GetOutputSink()}; | 361 | const auto& sink{system.AudioCore().GetOutputSink()}; |
| 362 | u32 channel_count{sink.GetDeviceChannels()}; | 362 | u32 channel_count{sink.GetSystemChannels()}; |
| 363 | 363 | ||
| 364 | LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count); | 364 | LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count); |
| 365 | 365 | ||