From 5aacfa7be3aa64ecd630a0d7c20f6b41ddc296da Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 10 May 2020 00:44:56 +1000 Subject: [PATCH] Qt: Hook up audio settings (buffer size/count, volume, mute) --- src/duckstation-qt/audiosettingswidget.cpp | 30 +++++++++ src/duckstation-qt/audiosettingswidget.h | 4 ++ src/duckstation-qt/audiosettingswidget.ui | 73 +++++++++++++++++++--- 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/duckstation-qt/audiosettingswidget.cpp b/src/duckstation-qt/audiosettingswidget.cpp index 08c729853..6e687ffb5 100644 --- a/src/duckstation-qt/audiosettingswidget.cpp +++ b/src/duckstation-qt/audiosettingswidget.cpp @@ -1,4 +1,5 @@ #include "audiosettingswidget.h" +#include "common/audio_stream.h" #include "settingwidgetbinder.h" AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidget* parent /* = nullptr */) @@ -12,7 +13,36 @@ AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidge SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.audioBackend, "Audio/Backend", &Settings::ParseAudioBackend, &Settings::GetAudioBackendName); 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.bufferCount, "Audio/BufferCount"); + 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"); + + connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel); + connect(m_ui.bufferCount, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel); + connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::updateVolumeLabel); + + updateBufferingLabel(); + updateVolumeLabel(); } AudioSettingsWidget::~AudioSettingsWidget() = default; + +void AudioSettingsWidget::updateBufferingLabel() +{ + const u32 buffer_size = static_cast(m_ui.bufferSize->value()); + const u32 buffer_count = static_cast(m_ui.bufferCount->value()); + const float min_latency = AudioStream::GetMinLatency(HostInterface::AUDIO_SAMPLE_RATE, buffer_size, buffer_count); + const float max_latency = AudioStream::GetMaxLatency(HostInterface::AUDIO_SAMPLE_RATE, buffer_size, buffer_count); + m_ui.bufferingLabel->setText(tr("%1 samples, %2 buffers (min %3ms, max %4ms)") + .arg(buffer_size) + .arg(buffer_count) + .arg(min_latency * 1000.0f, 0, 'f', 2) + .arg(max_latency * 1000.0f, 0, 'f', 2)); +} + +void AudioSettingsWidget::updateVolumeLabel() +{ + m_ui.volumeLabel->setText(tr("%1%").arg(m_ui.volume->value())); +} diff --git a/src/duckstation-qt/audiosettingswidget.h b/src/duckstation-qt/audiosettingswidget.h index cb6967989..2d32797a5 100644 --- a/src/duckstation-qt/audiosettingswidget.h +++ b/src/duckstation-qt/audiosettingswidget.h @@ -14,6 +14,10 @@ public: explicit AudioSettingsWidget(QtHostInterface* host_interface, QWidget* parent = nullptr); ~AudioSettingsWidget(); +private Q_SLOTS: + void updateBufferingLabel(); + void updateVolumeLabel(); + private: Ui::AudioSettingsWidget m_ui; diff --git a/src/duckstation-qt/audiosettingswidget.ui b/src/duckstation-qt/audiosettingswidget.ui index f4f536df2..28e5ba082 100644 --- a/src/duckstation-qt/audiosettingswidget.ui +++ b/src/duckstation-qt/audiosettingswidget.ui @@ -51,12 +51,30 @@ + + 1024 + + + 16384 + + + 128 + + + 1024 + Qt::Horizontal + + QSlider::TicksBothSides + + + 1024 + - + Qt::Horizontal @@ -69,30 +87,59 @@ - - + + - 2048 samples + 2048 samples, 4 buffers (min 0.00ms, max 0.00ms)) Qt::AlignCenter - + Sync To Output - + Start Dumping On Boot + + + + Buffer Count: + + + + + + + 2 + + + 8 + + + 1 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + 1 + + + @@ -111,13 +158,25 @@ + + 100 + + + 100 + Qt::Horizontal + + QSlider::TicksBothSides + + + 10 + - + Mute