service/mic: actually use the specified device

This commit is contained in:
vvanelslande 2019-11-01 13:33:06 -05:00
parent 5fa71d425b
commit e1e136d72f
7 changed files with 46 additions and 10 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <utility>
#include <vector>
#include <cubeb/cubeb.h>
#include "audio_core/cubeb_input.h"
@ -23,7 +24,8 @@ struct CubebInput::Impl {
static void StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state);
};
CubebInput::CubebInput() : impl(std::make_unique<Impl>()) {
CubebInput::CubebInput(std::string device_id)
: impl(std::make_unique<Impl>()), device_id(std::move(device_id)) {
if (cubeb_init(&impl->ctx, "Citra Input", nullptr) != CUBEB_OK) {
LOG_ERROR(Audio, "cubeb_init failed! Mic will not work properly");
return;
@ -56,6 +58,23 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) {
is_sampling = true;
cubeb_devid input_device = nullptr;
if (device_id != Frontend::Mic::default_device_name && !device_id.empty()) {
cubeb_device_collection collection;
if (cubeb_enumerate_devices(impl->ctx, CUBEB_DEVICE_TYPE_INPUT, &collection) != CUBEB_OK) {
LOG_WARNING(Audio, "Audio input device enumeration not supported");
} else {
const auto collection_end = collection.device + collection.count;
const auto device = std::find_if(
collection.device, collection_end, [this](const cubeb_device_info& info) {
return info.friendly_name != nullptr && device_id == info.friendly_name;
});
if (device != collection_end) {
input_device = device->devid;
}
cubeb_device_collection_destroy(impl->ctx, &collection);
}
}
cubeb_stream_params input_params;
input_params.channels = 1;
input_params.layout = CUBEB_LAYOUT_UNDEFINED;

View File

@ -12,7 +12,7 @@ namespace AudioCore {
class CubebInput final : public Frontend::Mic::Interface {
public:
CubebInput();
explicit CubebInput(std::string device_id);
~CubebInput() override;
void StartSampling(const Frontend::Mic::Parameters& params) override;
@ -26,6 +26,7 @@ public:
private:
struct Impl;
std::unique_ptr<Impl> impl;
std::string device_id;
};
std::vector<std::string> ListCubebInputDevices();

View File

@ -13,6 +13,7 @@
#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/param_package.h"
#include "core/frontend/mic.h"
#include "core/hle/service/service.h"
#include "core/settings.h"
#include "input_common/main.h"
@ -178,7 +179,7 @@ void Config::ReadValues() {
Settings::values.audio_device_id = sdl2_config->GetString("Audio", "output_device", "auto");
Settings::values.volume = static_cast<float>(sdl2_config->GetReal("Audio", "volume", 1));
Settings::values.mic_input_device =
sdl2_config->GetString("Audio", "mic_input_device", "Default");
sdl2_config->GetString("Audio", "mic_input_device", Frontend::Mic::default_device_name);
Settings::values.mic_input_type =
static_cast<Settings::MicInputType>(sdl2_config->GetInteger("Audio", "mic_input_type", 0));

View File

@ -10,6 +10,7 @@
#include "citra_qt/configuration/config.h"
#include "citra_qt/uisettings.h"
#include "common/file_util.h"
#include "core/frontend/mic.h"
#include "core/hle/service/service.h"
#include "input_common/main.h"
#include "input_common/udp/client.h"
@ -114,7 +115,7 @@ void Config::ReadAudioValues() {
Settings::values.mic_input_type = static_cast<Settings::MicInputType>(
ReadSetting(QStringLiteral("mic_input_type"), 0).toInt());
Settings::values.mic_input_device =
ReadSetting(QStringLiteral("mic_input_device"), QStringLiteral("Default"))
ReadSetting(QStringLiteral("mic_input_device"), Frontend::Mic::default_device_name)
.toString()
.toStdString();
@ -628,7 +629,7 @@ void Config::SaveAudioValues() {
WriteSetting(QStringLiteral("volume"), Settings::values.volume, 1.0f);
WriteSetting(QStringLiteral("mic_input_device"),
QString::fromStdString(Settings::values.mic_input_device),
QStringLiteral("Default"));
Frontend::Mic::default_device_name);
WriteSetting(QStringLiteral("mic_input_type"),
static_cast<int>(Settings::values.mic_input_type), 0);

View File

@ -11,9 +11,12 @@
#include "audio_core/sink_details.h"
#include "citra_qt/configuration/configure_audio.h"
#include "core/core.h"
#include "core/frontend/mic.h"
#include "core/settings.h"
#include "ui_configure_audio.h"
constexpr int DEFAULT_INPUT_DEVICE_INDEX = 0;
ConfigureAudio::ConfigureAudio(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureAudio>()) {
ui->setupUi(this);
@ -75,8 +78,7 @@ void ConfigureAudio::SetConfiguration() {
int index = static_cast<int>(Settings::values.mic_input_type);
ui->input_type_combo_box->setCurrentIndex(index);
ui->input_device_combo_box->setCurrentText(
QString::fromStdString(Settings::values.mic_input_device));
UpdateAudioInputDevices(index);
}
@ -126,7 +128,12 @@ void ConfigureAudio::ApplyConfiguration() {
Settings::values.enable_dsp_lle_multithread = ui->emulation_combo_box->currentIndex() == 2;
Settings::values.mic_input_type =
static_cast<Settings::MicInputType>(ui->input_type_combo_box->currentIndex());
Settings::values.mic_input_device = ui->input_device_combo_box->currentText().toStdString();
if (ui->input_device_combo_box->currentIndex() == DEFAULT_INPUT_DEVICE_INDEX) {
Settings::values.mic_input_device = Frontend::Mic::default_device_name;
} else {
Settings::values.mic_input_device = ui->input_device_combo_box->currentText().toStdString();
}
}
void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) {
@ -139,7 +146,12 @@ void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) {
}
}
void ConfigureAudio::UpdateAudioInputDevices(int index) {}
void ConfigureAudio::UpdateAudioInputDevices(int index) {
if (Settings::values.mic_input_device != Frontend::Mic::default_device_name) {
ui->input_device_combo_box->setCurrentText(
QString::fromStdString(Settings::values.mic_input_device));
}
}
void ConfigureAudio::RetranslateUI() {
ui->retranslateUi(this);

View File

@ -11,6 +11,8 @@
namespace Frontend::Mic {
constexpr char default_device_name[] = "Default";
enum class Signedness : u8 {
Signed,
Unsigned,

View File

@ -326,7 +326,7 @@ struct MIC_U::Impl {
break;
case Settings::MicInputType::Real:
#if HAVE_CUBEB
new_mic = std::make_unique<AudioCore::CubebInput>();
new_mic = std::make_unique<AudioCore::CubebInput>(Settings::values.mic_input_device);
#else
new_mic = std::make_unique<Frontend::Mic::NullMic>();
#endif