From 2a1e3b2b774231424ecd32f30599a338772ec515 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 7 Jun 2022 17:53:13 +0200 Subject: [PATCH] sys_rsxaudio: use max channel count from configured sound_modes --- rpcs3/Emu/Audio/AudioBackend.cpp | 26 ++++++++++++++++++++++++++ rpcs3/Emu/Audio/AudioBackend.h | 5 +++++ rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp | 6 ++---- rpcs3/Emu/Cell/lv2/sys_rsxaudio.h | 1 - 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/Audio/AudioBackend.cpp b/rpcs3/Emu/Audio/AudioBackend.cpp index 382c1abc5f..792ab77a31 100644 --- a/rpcs3/Emu/Audio/AudioBackend.cpp +++ b/rpcs3/Emu/Audio/AudioBackend.cpp @@ -144,3 +144,29 @@ std::pair AudioBackend::get_channel_count_and_ fmt::throw_exception("Unknown downmixer in cellAudioOut config: %d", out.downmixer); } } + +AudioChannelCnt AudioBackend::get_max_channel_count(u32 device_index) +{ + audio_out_configuration& audio_out_cfg = g_fxo->get(); + std::lock_guard lock(audio_out_cfg.mtx); + ensure(device_index < audio_out_cfg.out.size()); + const audio_out_configuration::audio_out& out = audio_out_cfg.out.at(device_index); + + AudioChannelCnt count = AudioChannelCnt::STEREO; + + for (const CellAudioOutSoundMode& mode : out.sound_modes) + { + switch (mode.channel) + { + case 6: + count = AudioChannelCnt::SURROUND_5_1; + break; + case 8: + return AudioChannelCnt::SURROUND_7_1; // Max possible count. So let's return immediately. + default: + break; + } + } + + return count; +} diff --git a/rpcs3/Emu/Audio/AudioBackend.h b/rpcs3/Emu/Audio/AudioBackend.h index 19cfbcd1fc..f3eb6dfc84 100644 --- a/rpcs3/Emu/Audio/AudioBackend.h +++ b/rpcs3/Emu/Audio/AudioBackend.h @@ -140,6 +140,11 @@ public: */ static std::pair get_channel_count_and_downmixer(u32 device_index); + /* + * Returns the max supported channel count. + */ + static AudioChannelCnt get_max_channel_count(u32 device_index); + /* * Downmix audio stream. */ diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index 7125aa633b..a670c72d71 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -1322,7 +1322,8 @@ void rsxaudio_backend_thread::update_emu_cfg() rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg() { - const auto [out_ch_cnt, out_downmix] = AudioBackend::get_channel_count_and_downmixer(0); // CELL_AUDIO_OUT_PRIMARY + // Get max supported channel count + AudioChannelCnt out_ch_cnt = AudioBackend::get_max_channel_count(0); // CELL_AUDIO_OUT_PRIMARY emu_audio_cfg cfg = { @@ -1333,7 +1334,6 @@ rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg() .enable_time_stretching = static_cast(g_cfg.audio.enable_time_stretching), .dump_to_file = static_cast(g_cfg.audio.dump_to_file), .channels = out_ch_cnt, - .downmix = out_downmix, .renderer = g_cfg.audio.renderer, .provider = g_cfg.audio.provider, .avport = convert_avport(g_cfg.audio.rsxaudio_port) @@ -1672,8 +1672,6 @@ void rsxaudio_backend_thread::backend_init(const rsxaudio_state& ra_state, const backend->SetErrorCallback(std::bind(&rsxaudio_backend_thread::error_callback, this)); } - // TODO: properly handle dowmnix - const port_config& port_cfg = ra_state.port[static_cast(emu_cfg.avport)]; const AudioSampleSize sample_size = emu_cfg.convert_to_s16 ? AudioSampleSize::S16 : AudioSampleSize::FLOAT; const AudioChannelCnt ch_cnt = static_cast(std::min(static_cast(port_cfg.ch_cnt), static_cast(emu_cfg.channels))); diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h index 362dcac60b..08e88c7ef5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h @@ -475,7 +475,6 @@ private: bool enable_time_stretching = false; bool dump_to_file = false; AudioChannelCnt channels = AudioChannelCnt::STEREO; - AudioChannelCnt downmix = AudioChannelCnt::SURROUND_7_1; audio_renderer renderer = audio_renderer::null; audio_provider provider = audio_provider::none; RsxaudioAvportIdx avport = RsxaudioAvportIdx::HDMI_0;