diff --git a/src/duckstation-qt/audiosettingswidget.cpp b/src/duckstation-qt/audiosettingswidget.cpp index 1a86a190b..e4c1ef1da 100644 --- a/src/duckstation-qt/audiosettingswidget.cpp +++ b/src/duckstation-qt/audiosettingswidget.cpp @@ -1,7 +1,9 @@ #include "audiosettingswidget.h" #include "common/audio_stream.h" +#include "common/log.h" #include "settingsdialog.h" #include "settingwidgetbinder.h" +Log_SetChannel(AudioSettingsWidget); AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog) : QWidget(parent), m_host_interface(host_interface) @@ -16,12 +18,14 @@ AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidge Settings::DEFAULT_AUDIO_BACKEND); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.syncToOutput, "Audio", "Sync"); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.bufferSize, "Audio", "BufferSize"); - SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.volume, "Audio", "OutputVolume"); - SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.muted, "Audio", "OutputMuted"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startDumpingOnBoot, "Audio", "DumpOnBoot"); + m_ui.volume->setValue(m_host_interface->GetIntSettingValue("Audio", "OutputVolume")); + m_ui.muted->setChecked(m_host_interface->GetBoolSettingValue("Audio", "OutputMuted")); + connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel); - connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::updateVolumeLabel); + connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::onOutputVolumeChanged); + connect(m_ui.muted, &QCheckBox::stateChanged, this, &AudioSettingsWidget::onOutputMutedChanged); updateBufferingLabel(); updateVolumeLabel(); @@ -61,3 +65,19 @@ void AudioSettingsWidget::updateVolumeLabel() { m_ui.volumeLabel->setText(tr("%1%").arg(m_ui.volume->value())); } + +void AudioSettingsWidget::onOutputVolumeChanged(int new_value) +{ + m_host_interface->SetIntSettingValue("Audio", "OutputVolume", new_value); + if (!m_ui.muted->isChecked()) + m_host_interface->setAudioOutputVolume(new_value); + + updateVolumeLabel(); +} + +void AudioSettingsWidget::onOutputMutedChanged(int new_state) +{ + const bool muted = (new_state != 0); + m_host_interface->SetBoolSettingValue("Audio", "OutputMuted", muted); + m_host_interface->setAudioOutputVolume(muted ? 0 : m_ui.volume->value()); +} \ No newline at end of file diff --git a/src/duckstation-qt/audiosettingswidget.h b/src/duckstation-qt/audiosettingswidget.h index b8e054483..e285f85bc 100644 --- a/src/duckstation-qt/audiosettingswidget.h +++ b/src/duckstation-qt/audiosettingswidget.h @@ -18,6 +18,8 @@ public: private Q_SLOTS: void updateBufferingLabel(); void updateVolumeLabel(); + void onOutputVolumeChanged(int new_value); + void onOutputMutedChanged(int new_state); private: Ui::AudioSettingsWidget m_ui; diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 74b784616..1778008a1 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -884,6 +884,18 @@ void QtHostInterface::saveState(bool global, qint32 slot, bool block_until_done SaveState(global, slot); } +void QtHostInterface::setAudioOutputVolume(int value) +{ + if (!isOnWorkerThread()) + { + QMetaObject::invokeMethod(this, "setAudioOutputVolume", Q_ARG(int, value)); + return; + } + + if (m_audio_stream) + m_audio_stream->SetOutputVolume(value); +} + void QtHostInterface::startDumpingAudio() { if (!isOnWorkerThread()) diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index ee7bd6edc..8a77f296a 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -135,6 +135,7 @@ public Q_SLOTS: void loadState(const QString& filename); void loadState(bool global, qint32 slot); void saveState(bool global, qint32 slot, bool block_until_done = false); + void setAudioOutputVolume(int value); void startDumpingAudio(); void stopDumpingAudio(); void saveScreenshot();