diff --git a/rpcs3/Emu/Audio/AudioBackend.cpp b/rpcs3/Emu/Audio/AudioBackend.cpp index 84627eaaac..2ca44d1dc5 100644 --- a/rpcs3/Emu/Audio/AudioBackend.cpp +++ b/rpcs3/Emu/Audio/AudioBackend.cpp @@ -100,12 +100,12 @@ void AudioBackend::normalize(u32 sample_cnt, const f32* src, f32* dst) } } -AudioChannelCnt AudioBackend::get_channel_count() +AudioChannelCnt AudioBackend::get_channel_count(u32 device_index) { - audio_out_configuration& audio_out = g_fxo->get(); - std::lock_guard lock(audio_out.mtx); - ensure(!audio_out.out.empty()); - audio_out_configuration::audio_out& out = audio_out.out.at(CELL_AUDIO_OUT_PRIMARY); + 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); switch (out.downmixer) { diff --git a/rpcs3/Emu/Audio/AudioBackend.h b/rpcs3/Emu/Audio/AudioBackend.h index 6e09f36b52..5d681c8d89 100644 --- a/rpcs3/Emu/Audio/AudioBackend.h +++ b/rpcs3/Emu/Audio/AudioBackend.h @@ -138,7 +138,7 @@ public: /* * Returns the channel count based on the downmix mode. */ - static AudioChannelCnt get_channel_count(); + static AudioChannelCnt get_channel_count(u32 device_index); /* * Downmix audio stream. diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index c63cbb8d3d..04684b98d6 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -66,7 +66,7 @@ void cell_audio_config::reset(bool backend_changed) const AudioFreq freq = AudioFreq::FREQ_48K; const AudioSampleSize sample_size = raw.convert_to_s16 ? AudioSampleSize::S16 : AudioSampleSize::FLOAT; - const AudioChannelCnt ch_cnt = AudioBackend::get_channel_count(); + const AudioChannelCnt ch_cnt = AudioBackend::get_channel_count(0); // CELL_AUDIO_OUT_PRIMARY const f64 cb_frame_len = backend->Open(freq, sample_size, ch_cnt) ? backend->GetCallbackFrameLen() : 0.0; audio_channels = static_cast(ch_cnt); diff --git a/rpcs3/Emu/Cell/Modules/cellAudioOut.cpp b/rpcs3/Emu/Cell/Modules/cellAudioOut.cpp index 9f70a3d41f..4d6bda4bda 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudioOut.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudioOut.cpp @@ -240,6 +240,7 @@ error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32 switch (audioOut) { case CELL_AUDIO_OUT_PRIMARY: break; + // case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output default: return not_an_error(0); } @@ -248,7 +249,7 @@ error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32 // Check if the requested audio parameters are available and find the max supported channel count audio_out_configuration& cfg = g_fxo->get(); std::lock_guard lock(cfg.mtx); - audio_out_configuration::audio_out& out = cfg.out.at(audioOut); + const audio_out_configuration::audio_out& out = cfg.out.at(audioOut); for (const CellAudioOutSoundMode& mode : out.sound_modes) { @@ -268,13 +269,14 @@ error_code cellAudioOutGetSoundAvailability2(u32 audioOut, u32 type, u32 fs, u32 switch (audioOut) { case CELL_AUDIO_OUT_PRIMARY: break; + // case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output default: return not_an_error(0); } // Check if the requested audio parameters are available audio_out_configuration& cfg = g_fxo->get(); std::lock_guard lock(cfg.mtx); - audio_out_configuration::audio_out& out = cfg.out.at(audioOut); + const audio_out_configuration::audio_out& out = cfg.out.at(audioOut); for (const CellAudioOutSoundMode& mode : out.sound_modes) { @@ -327,11 +329,11 @@ error_code cellAudioOutGetState(u32 audioOut, u32 deviceIndex, vm::ptrget(); std::lock_guard lock(cfg.mtx); - audio_out_configuration::audio_out& out = cfg.out.at(audioOut); + const audio_out_configuration::audio_out& out = cfg.out.at(audioOut); const auto it = std::find_if(out.sound_modes.cbegin(), out.sound_modes.cend(), [&channels, &out](const CellAudioOutSoundMode& mode) { @@ -368,13 +370,12 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptrget(); { @@ -390,16 +391,17 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptrchannel || out.encoder != config->encoder || out.downmixer != config->downMixer) + { + out.channels = config->channel; + out.encoder = config->encoder; + out.downmixer = config->downMixer; - out.channels = config->channel; - out.encoder = config->encoder; - out.downmixer = config->downMixer; - - out_new = out; + needs_reset = true; + } } - if (std::memcmp(&out_old, &out_new, sizeof(audio_out_configuration::audio_out)) != 0) + if (needs_reset) { const auto reset_audio = [audioOut]() -> void { @@ -447,7 +449,7 @@ error_code cellAudioOutGetConfiguration(u32 audioOut, vm::ptrget(); std::lock_guard lock(cfg.mtx); ensure(audioOut < cfg.out.size()); - audio_out_configuration::audio_out& out = cfg.out.at(audioOut); + const audio_out_configuration::audio_out& out = cfg.out.at(audioOut); ensure(out.sound_modes.size() <= 16); CellAudioOutDeviceInfo _info{}; @@ -547,7 +549,7 @@ error_code cellAudioOutSetCopyControl(u32 audioOut, u32 control) case CELL_AUDIO_OUT_PRIMARY: break; case CELL_AUDIO_OUT_SECONDARY: - return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; + return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // TODO: enable if we ever actually support peripheral output default: return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER; } diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index b2a872aa73..b6c32628d0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -1322,7 +1322,7 @@ void rsxaudio_backend_thread::update_emu_cfg() rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg() { - const AudioChannelCnt out_ch_cnt = AudioBackend::get_channel_count(); + const AudioChannelCnt out_ch_cnt = AudioBackend::get_channel_count(0); // CELL_AUDIO_OUT_PRIMARY emu_audio_cfg cfg = {