From e2fd4e46f765acf702dac38a17fcbd6c57c40243 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 6 Jul 2020 17:38:40 +0200 Subject: [PATCH] Only reboot audio if a relevant setting changed --- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 48 ++++++++++++++++++++++------ rpcs3/Emu/Cell/Modules/cellAudio.h | 14 ++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index e4ee2016e9..21ef35919b 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -44,6 +44,7 @@ void fmt_class_string::format(std::string& out, u64 arg) cell_audio_config::cell_audio_config() { + raw = audio::get_raw_config(); reset(); } @@ -59,11 +60,9 @@ void cell_audio_config::reset() audio_buffer_length = AUDIO_BUFFER_SAMPLES * audio_channels; audio_buffer_size = audio_buffer_length * backend->get_sample_size(); - desired_buffer_duration = g_cfg.audio.desired_buffer_duration * 1000llu; + desired_buffer_duration = raw.desired_buffer_duration * 1000llu; - const bool raw_buffering_enabled = static_cast(g_cfg.audio.enable_buffering); - - buffering_enabled = raw_buffering_enabled && backend->has_capability(AudioBackend::PLAY_PAUSE_FLUSH | AudioBackend::IS_PLAYING);; + buffering_enabled = raw.buffering_enabled && backend->has_capability(AudioBackend::PLAY_PAUSE_FLUSH | AudioBackend::IS_PLAYING);; minimum_block_period = audio_block_period / 2; maximum_block_period = (6 * audio_block_period) / 5; @@ -74,15 +73,14 @@ void cell_audio_config::reset() fully_untouched_timeout = static_cast(audio_block_period) * 2; partially_untouched_timeout = static_cast(audio_block_period) * 4; - const s64 raw_time_stretching_threshold = g_cfg.audio.time_stretching_threshold; - const bool raw_time_stretching_enabled = buffering_enabled && g_cfg.audio.enable_time_stretching && (raw_time_stretching_threshold > 0); + const bool raw_time_stretching_enabled = buffering_enabled && raw.enable_time_stretching && (raw.time_stretching_threshold > 0); time_stretching_enabled = raw_time_stretching_enabled && backend->has_capability(AudioBackend::SET_FREQUENCY_RATIO); - time_stretching_threshold = raw_time_stretching_threshold / 100.0f; + time_stretching_threshold = raw.time_stretching_threshold / 100.0f; // Warn if audio backend does not support all requested features - if (raw_buffering_enabled && !buffering_enabled) + if (raw.buffering_enabled && !buffering_enabled) { cellAudio.error("Audio backend %s does not support buffering, this option will be ignored.", backend->GetName()); } @@ -539,11 +537,43 @@ void cell_audio_thread::advance(u64 timestamp, bool reset) namespace audio { + cell_audio_config::raw_config get_raw_config() + { + return + { + .buffering_enabled = static_cast(g_cfg.audio.enable_buffering), + .desired_buffer_duration = g_cfg.audio.desired_buffer_duration, + .enable_time_stretching = static_cast(g_cfg.audio.enable_time_stretching), + .time_stretching_threshold = g_cfg.audio.time_stretching_threshold, + .convert_to_u16 = static_cast(g_cfg.audio.convert_to_u16), + .start_threshold = static_cast(g_cfg.audio.start_threshold), + .sampling_period_multiplier = static_cast(g_cfg.audio.sampling_period_multiplier), + .channels = g_cfg.audio.audio_channel_downmix, + .renderer = g_cfg.audio.renderer + }; + } + void configure_audio() { if (const auto g_audio = g_fxo->get()) { - g_audio->m_update_configuration = true; + // Only reboot the audio renderer if a relevant setting changed + const auto new_raw = get_raw_config(); + + if (const auto raw = g_audio->cfg.raw; + raw.desired_buffer_duration != new_raw.desired_buffer_duration || + raw.buffering_enabled != new_raw.buffering_enabled || + raw.time_stretching_threshold != new_raw.time_stretching_threshold || + raw.enable_time_stretching != new_raw.enable_time_stretching || + raw.convert_to_u16 != new_raw.convert_to_u16 || + raw.start_threshold != new_raw.start_threshold || + raw.sampling_period_multiplier != new_raw.sampling_period_multiplier || + raw.channels != new_raw.channels || + raw.renderer != new_raw.renderer) + { + g_audio->cfg.raw = new_raw; + g_audio->m_update_configuration = true; + } } } } diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.h b/rpcs3/Emu/Cell/Modules/cellAudio.h index 9323c4d6dd..e7c412e6ea 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.h +++ b/rpcs3/Emu/Cell/Modules/cellAudio.h @@ -187,6 +187,19 @@ struct audio_port struct cell_audio_config { + struct raw_config + { + bool buffering_enabled = false; + s64 desired_buffer_duration = 0; + bool enable_time_stretching = false; + s64 time_stretching_threshold = 0; + bool convert_to_u16 = false; + u32 start_threshold = 0; + u32 sampling_period_multiplier = 0; + audio_channels channels = audio_channels::downmix_to_stereo; + audio_renderer renderer = audio_renderer::null; + } raw; + std::shared_ptr backend = nullptr; u32 audio_channels = 0; @@ -414,5 +427,6 @@ using cell_audio = named_thread; namespace audio { + cell_audio_config::raw_config get_raw_config(); void configure_audio(); }