Merge pull request #6372 from spycrab/wasapi

AudioCommon: Implement WASAPI (Exclusive Mode)
This commit is contained in:
spycrab
2018-05-26 20:04:55 +02:00
committed by GitHub
10 changed files with 600 additions and 7 deletions

View File

@ -17,6 +17,7 @@
#include <QVBoxLayout>
#include "AudioCommon/AudioCommon.h"
#include "AudioCommon/WASAPIStream.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt2/Config/SettingsWindow.h"
@ -88,6 +89,14 @@ void AudioPane::CreateWidgets()
backend_layout->addRow(m_backend_label, m_backend_combo);
if (m_latency_control_supported)
backend_layout->addRow(m_latency_label, m_latency_spin);
#ifdef _WIN32
m_wasapi_device_label = new QLabel(tr("Device:"));
m_wasapi_device_combo = new QComboBox;
backend_layout->addRow(m_wasapi_device_label, m_wasapi_device_combo);
#endif
backend_layout->addRow(m_dolby_pro_logic);
auto* stretching_box = new QGroupBox(tr("Audio Stretching Settings"));
@ -140,6 +149,12 @@ 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);
#ifdef _WIN32
connect(m_wasapi_device_combo,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AudioPane::SaveSettings);
#endif
}
void AudioPane::LoadSettings()
@ -183,6 +198,18 @@ void AudioPane::LoadSettings()
m_stretching_buffer_slider->setValue(SConfig::GetInstance().m_audio_stretch_max_latency);
m_stretching_buffer_slider->setEnabled(m_stretching_enable->isChecked());
m_stretching_buffer_indicator->setText(tr("%1 ms").arg(m_stretching_buffer_slider->value()));
#ifdef _WIN32
if (SConfig::GetInstance().sWASAPIDevice == "default")
{
m_wasapi_device_combo->setCurrentIndex(0);
}
else
{
m_wasapi_device_combo->setCurrentText(
QString::fromStdString(SConfig::GetInstance().sWASAPIDevice));
}
#endif
}
void AudioPane::SaveSettings()
@ -227,6 +254,15 @@ void AudioPane::SaveSettings()
m_stretching_buffer_indicator->setText(
tr("%1 ms").arg(SConfig::GetInstance().m_audio_stretch_max_latency));
#ifdef _WIN32
std::string device = "default";
if (m_wasapi_device_combo->currentIndex() != 0)
device = m_wasapi_device_combo->currentText().toStdString();
SConfig::GetInstance().sWASAPIDevice = device;
#endif
AudioCommon::UpdateSoundStream();
}
@ -240,6 +276,22 @@ void AudioPane::OnBackendChanged()
m_latency_label->setEnabled(AudioCommon::SupportsLatencyControl(backend));
m_latency_spin->setEnabled(AudioCommon::SupportsLatencyControl(backend));
}
#ifdef _WIN32
bool is_wasapi = backend == BACKEND_WASAPI;
m_wasapi_device_label->setHidden(!is_wasapi);
m_wasapi_device_combo->setHidden(!is_wasapi);
if (is_wasapi)
{
m_wasapi_device_combo->clear();
m_wasapi_device_combo->addItem(tr("Default Device"));
for (const auto device : WASAPIStream::GetAvailableDevices())
m_wasapi_device_combo->addItem(QString::fromStdString(device));
}
#endif
m_volume_slider->setEnabled(AudioCommon::SupportsVolumeChanges(backend));
m_volume_indicator->setEnabled(AudioCommon::SupportsVolumeChanges(backend));
}
@ -257,6 +309,10 @@ void AudioPane::OnEmulationStateChanged(bool running)
m_latency_label->setEnabled(!running);
m_latency_spin->setEnabled(!running);
}
#ifdef _WIN32
m_wasapi_device_combo->setEnabled(!running);
#endif
}
void AudioPane::OnVolumeChanged(int volume)

View File

@ -52,6 +52,10 @@ private:
QCheckBox* m_dolby_pro_logic;
QLabel* m_latency_label;
QSpinBox* m_latency_spin;
#ifdef _WIN32
QLabel* m_wasapi_device_label;
QComboBox* m_wasapi_device_combo;
#endif
// Audio Stretching
QCheckBox* m_stretching_enable;