2020-01-24 04:51:13 +00:00
|
|
|
#include "audiosettingswidget.h"
|
2020-05-09 14:44:56 +00:00
|
|
|
#include "common/audio_stream.h"
|
2020-06-06 15:30:05 +00:00
|
|
|
#include "settingsdialog.h"
|
2020-01-24 04:51:13 +00:00
|
|
|
#include "settingwidgetbinder.h"
|
2020-10-28 15:58:08 +00:00
|
|
|
#include <cmath>
|
2020-01-24 04:51:13 +00:00
|
|
|
|
2020-06-06 15:30:05 +00:00
|
|
|
AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog)
|
2020-01-24 04:51:13 +00:00
|
|
|
: QWidget(parent), m_host_interface(host_interface)
|
|
|
|
{
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
2020-02-25 13:40:42 +00:00
|
|
|
for (u32 i = 0; i < static_cast<u32>(AudioBackend::Count); i++)
|
2020-08-22 03:01:52 +00:00
|
|
|
{
|
|
|
|
m_ui.audioBackend->addItem(
|
|
|
|
qApp->translate("AudioBackend", Settings::GetAudioBackendDisplayName(static_cast<AudioBackend>(i))));
|
|
|
|
}
|
2020-02-25 13:40:42 +00:00
|
|
|
|
2020-07-21 09:49:04 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.audioBackend, "Audio", "Backend",
|
|
|
|
&Settings::ParseAudioBackend, &Settings::GetAudioBackendName,
|
|
|
|
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::BindWidgetToBoolSetting(m_host_interface, m_ui.startDumpingOnBoot, "Audio", "DumpOnBoot");
|
2020-10-03 02:24:03 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.muteCDAudio, "CDROM", "MuteCDAudio");
|
2021-01-10 16:26:49 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.resampling, "Audio", "Resampling", true);
|
2020-05-09 14:44:56 +00:00
|
|
|
|
2020-12-08 14:48:00 +00:00
|
|
|
m_ui.volume->setValue(m_host_interface->GetIntSettingValue("Audio", "OutputVolume", 100));
|
|
|
|
m_ui.fastForwardVolume->setValue(m_host_interface->GetIntSettingValue("Audio", "FastForwardVolume", 100));
|
|
|
|
m_ui.muted->setChecked(m_host_interface->GetBoolSettingValue("Audio", "OutputMuted", false));
|
2020-07-21 10:04:43 +00:00
|
|
|
|
2020-05-09 14:44:56 +00:00
|
|
|
connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel);
|
2020-07-21 10:04:43 +00:00
|
|
|
connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::onOutputVolumeChanged);
|
2020-12-08 14:48:00 +00:00
|
|
|
connect(m_ui.fastForwardVolume, &QSlider::valueChanged, this, &AudioSettingsWidget::onFastForwardVolumeChanged);
|
2020-07-21 10:04:43 +00:00
|
|
|
connect(m_ui.muted, &QCheckBox::stateChanged, this, &AudioSettingsWidget::onOutputMutedChanged);
|
2020-05-09 14:44:56 +00:00
|
|
|
|
|
|
|
updateBufferingLabel();
|
|
|
|
updateVolumeLabel();
|
2020-06-06 15:30:05 +00:00
|
|
|
|
|
|
|
dialog->registerWidgetHelp(
|
2020-07-28 09:42:14 +00:00
|
|
|
m_ui.audioBackend, tr("Audio Backend"), QStringLiteral("Cubeb"),
|
|
|
|
tr("The audio backend determines how frames produced by the emulator are submitted to the host. Cubeb provides the "
|
|
|
|
"lowest latency, if you encounter issues, try the SDL backend. The null backend disables all host audio "
|
|
|
|
"output."));
|
2020-06-06 15:30:05 +00:00
|
|
|
dialog->registerWidgetHelp(
|
2020-07-28 09:42:14 +00:00
|
|
|
m_ui.bufferSize, tr("Buffer Size"), QStringLiteral("2048"),
|
|
|
|
tr("The buffer size determines the size of the chunks of audio which will be pulled by the "
|
|
|
|
"host. Smaller values reduce the output latency, but may cause hitches if the emulation "
|
|
|
|
"speed is inconsistent. Note that the Cubeb backend uses smaller chunks regardless of "
|
|
|
|
"this value, so using a low value here may not significantly change latency."));
|
2020-08-22 04:38:57 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.syncToOutput, tr("Sync To Output"), tr("Checked"),
|
|
|
|
tr("Throttles the emulation speed based on the audio backend pulling audio frames. This "
|
|
|
|
"helps to remove noises or crackling if emulation is too fast. Sync will "
|
|
|
|
"automatically be disabled if not running at 100% speed."));
|
2020-07-28 09:42:14 +00:00
|
|
|
dialog->registerWidgetHelp(
|
2020-08-22 04:38:57 +00:00
|
|
|
m_ui.startDumpingOnBoot, tr("Start Dumping On Boot"), tr("Unchecked"),
|
2020-07-28 09:42:14 +00:00
|
|
|
tr("Start dumping audio to file as soon as the emulator is started. Mainly useful as a debug option."));
|
2021-01-11 04:49:25 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.volume, tr("Output Volume"), "100%",
|
|
|
|
tr("Controls the volume of the audio played on the host."));
|
|
|
|
dialog->registerWidgetHelp(m_ui.fastForwardVolume, tr("Fast Forward Volume"), "100%",
|
|
|
|
tr("Controls the volume of the audio played on the host when fast forwarding."));
|
2020-10-03 02:24:03 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.muted, tr("Mute All Sound"), tr("Unchecked"),
|
2020-07-28 09:42:14 +00:00
|
|
|
tr("Prevents the emulator from producing any audible sound."));
|
2020-10-03 02:24:03 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.muteCDAudio, tr("Mute CD Audio"), tr("Unchecked"),
|
|
|
|
tr("Forcibly mutes both CD-DA and XA audio from the CD-ROM. Can be used to disable "
|
|
|
|
"background music in some games."));
|
2021-01-10 16:26:49 +00:00
|
|
|
dialog->registerWidgetHelp(
|
2021-01-11 04:49:25 +00:00
|
|
|
m_ui.resampling, tr("Resampling"), tr("Checked"),
|
2021-01-10 16:26:49 +00:00
|
|
|
tr("When running outside of 100% speed, resamples audio from the target speed instead of dropping frames. Produces "
|
|
|
|
"much nicer fast forward/slowdown audio at a small cost to performance."));
|
2020-01-24 04:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioSettingsWidget::~AudioSettingsWidget() = default;
|
2020-05-09 14:44:56 +00:00
|
|
|
|
|
|
|
void AudioSettingsWidget::updateBufferingLabel()
|
|
|
|
{
|
2020-10-28 07:32:01 +00:00
|
|
|
constexpr float step = 128;
|
2020-10-28 15:58:08 +00:00
|
|
|
const u32 actual_buffer_size =
|
|
|
|
static_cast<u32>(std::round(static_cast<float>(m_ui.bufferSize->value()) / step) * step);
|
2020-10-28 07:32:01 +00:00
|
|
|
if (static_cast<u32>(m_ui.bufferSize->value()) != actual_buffer_size)
|
|
|
|
{
|
|
|
|
m_ui.bufferSize->setValue(static_cast<int>(actual_buffer_size));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float max_latency = AudioStream::GetMaxLatency(HostInterface::AUDIO_SAMPLE_RATE, actual_buffer_size);
|
2021-03-02 19:11:40 +00:00
|
|
|
m_ui.bufferingLabel->setText(tr("Maximum Latency: %n frames (%1ms)", "", actual_buffer_size)
|
2021-01-11 04:49:25 +00:00
|
|
|
.arg(static_cast<double>(max_latency) * 1000.0, 0, 'f', 2));
|
2020-05-09 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSettingsWidget::updateVolumeLabel()
|
|
|
|
{
|
|
|
|
m_ui.volumeLabel->setText(tr("%1%").arg(m_ui.volume->value()));
|
2020-12-08 14:48:00 +00:00
|
|
|
m_ui.fastForwardVolumeLabel->setText(tr("%1%").arg(m_ui.fastForwardVolume->value()));
|
2020-05-09 14:44:56 +00:00
|
|
|
}
|
2020-07-21 10:04:43 +00:00
|
|
|
|
|
|
|
void AudioSettingsWidget::onOutputVolumeChanged(int new_value)
|
|
|
|
{
|
|
|
|
m_host_interface->SetIntSettingValue("Audio", "OutputVolume", new_value);
|
2021-01-12 16:36:11 +00:00
|
|
|
m_host_interface->setAudioOutputVolume(new_value, m_ui.fastForwardVolume->value());
|
2020-12-08 14:48:00 +00:00
|
|
|
|
|
|
|
updateVolumeLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSettingsWidget::onFastForwardVolumeChanged(int new_value)
|
|
|
|
{
|
|
|
|
m_host_interface->SetIntSettingValue("Audio", "FastForwardVolume", new_value);
|
2021-01-12 16:36:11 +00:00
|
|
|
m_host_interface->setAudioOutputVolume(m_ui.volume->value(), new_value);
|
2020-07-21 10:04:43 +00:00
|
|
|
|
|
|
|
updateVolumeLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSettingsWidget::onOutputMutedChanged(int new_state)
|
|
|
|
{
|
|
|
|
const bool muted = (new_state != 0);
|
|
|
|
m_host_interface->SetBoolSettingValue("Audio", "OutputMuted", muted);
|
2020-07-23 16:55:00 +00:00
|
|
|
m_host_interface->setAudioOutputMuted(muted);
|
2020-08-15 11:14:14 +00:00
|
|
|
}
|