From a56a27a219c3e29a36751a1c671505b1b51b6f63 Mon Sep 17 00:00:00 2001 From: TryTwo Date: Wed, 9 Oct 2024 17:39:18 -0700 Subject: [PATCH] Audio: Add option to AudioPane to temporarily mute audio when emulation speed limit is disabled. --- Source/Core/Core/Config/MainSettings.cpp | 2 ++ Source/Core/Core/Config/MainSettings.h | 1 + Source/Core/DolphinQt/HotkeyScheduler.cpp | 16 +++++++++++++++- Source/Core/DolphinQt/Settings/AudioPane.cpp | 20 ++++++++++++++++++++ Source/Core/DolphinQt/Settings/AudioPane.h | 3 +++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index a45c014262..7f4e9989b7 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -280,6 +280,8 @@ const Info MAIN_AUDIO_BACKEND{{System::Main, "DSP", "Backend"}, AudioCommon::GetDefaultSoundBackend()}; const Info MAIN_AUDIO_VOLUME{{System::Main, "DSP", "Volume"}, 100}; const Info MAIN_AUDIO_MUTED{{System::Main, "DSP", "Muted"}, false}; +const Info MAIN_AUDIO_MUTE_ON_DISABLED_SPEED_LIMIT{ + {System::Main, "DSP", "MuteOnDisabledSpeedLimit"}, false}; #ifdef _WIN32 const Info MAIN_WASAPI_DEVICE{{System::Main, "DSP", "WASAPIDevice"}, "Default"}; #endif diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index d7e78bf6e9..b6e8f966c7 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -167,6 +167,7 @@ extern const Info MAIN_DUMP_UCODE; extern const Info MAIN_AUDIO_BACKEND; extern const Info MAIN_AUDIO_VOLUME; extern const Info MAIN_AUDIO_MUTED; +extern const Info MAIN_AUDIO_MUTE_ON_DISABLED_SPEED_LIMIT; #ifdef _WIN32 extern const Info MAIN_WASAPI_DEVICE; #endif diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index 95d7b95a4e..7f2c454e71 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -360,7 +360,7 @@ void HotkeyScheduler::Run() if (IsHotkey(HK_VOLUME_TOGGLE_MUTE)) { - AudioCommon::ToggleMuteVolume(Core::System::GetInstance()); + AudioCommon::ToggleMuteVolume(system); ShowVolume(); } @@ -483,6 +483,20 @@ void HotkeyScheduler::Run() Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true)); + if (IsHotkey(HK_TOGGLE_THROTTLE, true) && !Config::Get(Config::MAIN_AUDIO_MUTED) && + Config::Get(Config::MAIN_AUDIO_MUTE_ON_DISABLED_SPEED_LIMIT)) + { + Config::SetCurrent(Config::MAIN_AUDIO_MUTED, true); + AudioCommon::UpdateSoundStream(system); + } + else if (!IsHotkey(HK_TOGGLE_THROTTLE, true) && Config::Get(Config::MAIN_AUDIO_MUTED) && + Config::GetActiveLayerForConfig(Config::MAIN_AUDIO_MUTED) == + Config::LayerType::CurrentRun) + { + Config::DeleteKey(Config::LayerType::CurrentRun, Config::MAIN_AUDIO_MUTED); + AudioCommon::UpdateSoundStream(system); + } + auto ShowEmulationSpeed = []() { const float emulation_speed = Config::Get(Config::MAIN_EMULATION_SPEED); if (!AchievementManager::GetInstance().IsHardcoreModeActive() || diff --git a/Source/Core/DolphinQt/Settings/AudioPane.cpp b/Source/Core/DolphinQt/Settings/AudioPane.cpp index 289dc28e7d..9be2fcd0e7 100644 --- a/Source/Core/DolphinQt/Settings/AudioPane.cpp +++ b/Source/Core/DolphinQt/Settings/AudioPane.cpp @@ -160,10 +160,22 @@ void AudioPane::CreateWidgets() dsp_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + auto* misc_box = new QGroupBox(tr("Miscellaneous Settings")); + auto* misc_layout = new QGridLayout; + misc_box->setLayout(misc_layout); + + m_speed_up_mute_enable = new QCheckBox(tr("Mute When Disabling Speed Limit.")); + m_speed_up_mute_enable->setToolTip( + tr("Mutes the audio when overriding the emulation speed limit (default hotkey: Tab).")); + + misc_layout->addWidget(m_speed_up_mute_enable, 0, 0, 1, 1); + auto* const main_vbox_layout = new QVBoxLayout; + main_vbox_layout->addWidget(dsp_box); main_vbox_layout->addWidget(backend_box); main_vbox_layout->addWidget(stretching_box); + main_vbox_layout->addWidget(misc_box); m_main_layout = new QHBoxLayout; m_main_layout->addLayout(main_vbox_layout); @@ -188,6 +200,7 @@ void AudioPane::ConnectWidgets() connect(m_dsp_hle, &QRadioButton::toggled, this, &AudioPane::SaveSettings); connect(m_dsp_lle, &QRadioButton::toggled, this, &AudioPane::SaveSettings); connect(m_dsp_interpreter, &QRadioButton::toggled, this, &AudioPane::SaveSettings); + connect(m_speed_up_mute_enable, &QCheckBox::toggled, this, &AudioPane::SaveSettings); #ifdef _WIN32 connect(m_wasapi_device_combo, &QComboBox::currentIndexChanged, this, &AudioPane::SaveSettings); @@ -251,6 +264,9 @@ void AudioPane::LoadSettings() m_stretching_buffer_indicator->setEnabled(m_stretching_enable->isChecked()); m_stretching_buffer_indicator->setText(tr("%1 ms").arg(m_stretching_buffer_slider->value())); + // Misc + m_speed_up_mute_enable->setChecked(Config::Get(Config::MAIN_AUDIO_MUTE_ON_DISABLED_SPEED_LIMIT)); + #ifdef _WIN32 if (Config::Get(Config::MAIN_WASAPI_DEVICE) == "default") { @@ -320,6 +336,10 @@ void AudioPane::SaveSettings() m_stretching_buffer_indicator->setText( tr("%1 ms").arg(Config::Get(Config::MAIN_AUDIO_STRETCH_LATENCY))); + // Misc + Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTE_ON_DISABLED_SPEED_LIMIT, + m_speed_up_mute_enable->isChecked()); + #ifdef _WIN32 std::string device = "default"; diff --git a/Source/Core/DolphinQt/Settings/AudioPane.h b/Source/Core/DolphinQt/Settings/AudioPane.h index 50fa27717b..493b067939 100644 --- a/Source/Core/DolphinQt/Settings/AudioPane.h +++ b/Source/Core/DolphinQt/Settings/AudioPane.h @@ -76,4 +76,7 @@ private: QLabel* m_stretching_buffer_label; QSlider* m_stretching_buffer_slider; QLabel* m_stretching_buffer_indicator; + + // Misc Settings + QCheckBox* m_speed_up_mute_enable; };