Qt: Hook up audio settings (buffer size/count, volume, mute)

This commit is contained in:
Connor McLaughlin 2020-05-10 00:44:56 +10:00
parent c329f58afe
commit 5aacfa7be3
3 changed files with 100 additions and 7 deletions

View file

@ -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<u32>(m_ui.bufferSize->value());
const u32 buffer_count = static_cast<u32>(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()));
}

View file

@ -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;

View file

@ -51,12 +51,30 @@
</item>
<item row="1" column="1">
<widget class="QSlider" name="bufferSize">
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>16384</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="pageStep">
<number>1024</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>1024</number>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -69,30 +87,59 @@
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QLabel" name="bufferSizeLabel">
<item row="3" column="1">
<widget class="QLabel" name="bufferingLabel">
<property name="text">
<string>2048 samples</string>
<string>2048 samples, 4 buffers (min 0.00ms, max 0.00ms))</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="syncToOutput">
<property name="text">
<string>Sync To Output</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="startDumpingOnBoot">
<property name="text">
<string>Start Dumping On Boot</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Buffer Count:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSlider" name="bufferCount">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>8</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -111,13 +158,25 @@
</item>
<item row="0" column="1">
<widget class="QSlider" name="volume">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="muted">
<property name="text">
<string>Mute</string>
</property>