Merge pull request #4982 from vvanelslande/mic-device
service/mic: actually use the specified device
This commit is contained in:
commit
866df2644b
@ -2,6 +2,7 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cubeb/cubeb.h>
|
#include <cubeb/cubeb.h>
|
||||||
#include "audio_core/cubeb_input.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);
|
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) {
|
if (cubeb_init(&impl->ctx, "Citra Input", nullptr) != CUBEB_OK) {
|
||||||
LOG_ERROR(Audio, "cubeb_init failed! Mic will not work properly");
|
LOG_ERROR(Audio, "cubeb_init failed! Mic will not work properly");
|
||||||
return;
|
return;
|
||||||
@ -56,6 +58,23 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) {
|
|||||||
is_sampling = true;
|
is_sampling = true;
|
||||||
|
|
||||||
cubeb_devid input_device = nullptr;
|
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;
|
cubeb_stream_params input_params;
|
||||||
input_params.channels = 1;
|
input_params.channels = 1;
|
||||||
input_params.layout = CUBEB_LAYOUT_UNDEFINED;
|
input_params.layout = CUBEB_LAYOUT_UNDEFINED;
|
||||||
|
@ -12,7 +12,7 @@ namespace AudioCore {
|
|||||||
|
|
||||||
class CubebInput final : public Frontend::Mic::Interface {
|
class CubebInput final : public Frontend::Mic::Interface {
|
||||||
public:
|
public:
|
||||||
CubebInput();
|
explicit CubebInput(std::string device_id);
|
||||||
~CubebInput() override;
|
~CubebInput() override;
|
||||||
|
|
||||||
void StartSampling(const Frontend::Mic::Parameters& params) override;
|
void StartSampling(const Frontend::Mic::Parameters& params) override;
|
||||||
@ -26,6 +26,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
std::unique_ptr<Impl> impl;
|
std::unique_ptr<Impl> impl;
|
||||||
|
std::string device_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::string> ListCubebInputDevices();
|
std::vector<std::string> ListCubebInputDevices();
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
|
#include "core/frontend/mic.h"
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "input_common/main.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.audio_device_id = sdl2_config->GetString("Audio", "output_device", "auto");
|
||||||
Settings::values.volume = static_cast<float>(sdl2_config->GetReal("Audio", "volume", 1));
|
Settings::values.volume = static_cast<float>(sdl2_config->GetReal("Audio", "volume", 1));
|
||||||
Settings::values.mic_input_device =
|
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 =
|
Settings::values.mic_input_type =
|
||||||
static_cast<Settings::MicInputType>(sdl2_config->GetInteger("Audio", "mic_input_type", 0));
|
static_cast<Settings::MicInputType>(sdl2_config->GetInteger("Audio", "mic_input_type", 0));
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "citra_qt/configuration/config.h"
|
#include "citra_qt/configuration/config.h"
|
||||||
#include "citra_qt/uisettings.h"
|
#include "citra_qt/uisettings.h"
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
|
#include "core/frontend/mic.h"
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
#include "input_common/main.h"
|
#include "input_common/main.h"
|
||||||
#include "input_common/udp/client.h"
|
#include "input_common/udp/client.h"
|
||||||
@ -114,7 +115,7 @@ void Config::ReadAudioValues() {
|
|||||||
Settings::values.mic_input_type = static_cast<Settings::MicInputType>(
|
Settings::values.mic_input_type = static_cast<Settings::MicInputType>(
|
||||||
ReadSetting(QStringLiteral("mic_input_type"), 0).toInt());
|
ReadSetting(QStringLiteral("mic_input_type"), 0).toInt());
|
||||||
Settings::values.mic_input_device =
|
Settings::values.mic_input_device =
|
||||||
ReadSetting(QStringLiteral("mic_input_device"), QStringLiteral("Default"))
|
ReadSetting(QStringLiteral("mic_input_device"), Frontend::Mic::default_device_name)
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString();
|
.toStdString();
|
||||||
|
|
||||||
@ -628,7 +629,7 @@ void Config::SaveAudioValues() {
|
|||||||
WriteSetting(QStringLiteral("volume"), Settings::values.volume, 1.0f);
|
WriteSetting(QStringLiteral("volume"), Settings::values.volume, 1.0f);
|
||||||
WriteSetting(QStringLiteral("mic_input_device"),
|
WriteSetting(QStringLiteral("mic_input_device"),
|
||||||
QString::fromStdString(Settings::values.mic_input_device),
|
QString::fromStdString(Settings::values.mic_input_device),
|
||||||
QStringLiteral("Default"));
|
Frontend::Mic::default_device_name);
|
||||||
WriteSetting(QStringLiteral("mic_input_type"),
|
WriteSetting(QStringLiteral("mic_input_type"),
|
||||||
static_cast<int>(Settings::values.mic_input_type), 0);
|
static_cast<int>(Settings::values.mic_input_type), 0);
|
||||||
|
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
#include "audio_core/sink_details.h"
|
#include "audio_core/sink_details.h"
|
||||||
#include "citra_qt/configuration/configure_audio.h"
|
#include "citra_qt/configuration/configure_audio.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#include "core/frontend/mic.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "ui_configure_audio.h"
|
#include "ui_configure_audio.h"
|
||||||
|
|
||||||
|
constexpr int DEFAULT_INPUT_DEVICE_INDEX = 0;
|
||||||
|
|
||||||
ConfigureAudio::ConfigureAudio(QWidget* parent)
|
ConfigureAudio::ConfigureAudio(QWidget* parent)
|
||||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureAudio>()) {
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureAudio>()) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -75,8 +78,7 @@ void ConfigureAudio::SetConfiguration() {
|
|||||||
|
|
||||||
int index = static_cast<int>(Settings::values.mic_input_type);
|
int index = static_cast<int>(Settings::values.mic_input_type);
|
||||||
ui->input_type_combo_box->setCurrentIndex(index);
|
ui->input_type_combo_box->setCurrentIndex(index);
|
||||||
ui->input_device_combo_box->setCurrentText(
|
|
||||||
QString::fromStdString(Settings::values.mic_input_device));
|
|
||||||
UpdateAudioInputDevices(index);
|
UpdateAudioInputDevices(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,12 @@ void ConfigureAudio::ApplyConfiguration() {
|
|||||||
Settings::values.enable_dsp_lle_multithread = ui->emulation_combo_box->currentIndex() == 2;
|
Settings::values.enable_dsp_lle_multithread = ui->emulation_combo_box->currentIndex() == 2;
|
||||||
Settings::values.mic_input_type =
|
Settings::values.mic_input_type =
|
||||||
static_cast<Settings::MicInputType>(ui->input_type_combo_box->currentIndex());
|
static_cast<Settings::MicInputType>(ui->input_type_combo_box->currentIndex());
|
||||||
|
|
||||||
|
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();
|
Settings::values.mic_input_device = ui->input_device_combo_box->currentText().toStdString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) {
|
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() {
|
void ConfigureAudio::RetranslateUI() {
|
||||||
ui->retranslateUi(this);
|
ui->retranslateUi(this);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Frontend::Mic {
|
namespace Frontend::Mic {
|
||||||
|
|
||||||
|
constexpr char default_device_name[] = "Default";
|
||||||
|
|
||||||
enum class Signedness : u8 {
|
enum class Signedness : u8 {
|
||||||
Signed,
|
Signed,
|
||||||
Unsigned,
|
Unsigned,
|
||||||
|
@ -326,7 +326,7 @@ struct MIC_U::Impl {
|
|||||||
break;
|
break;
|
||||||
case Settings::MicInputType::Real:
|
case Settings::MicInputType::Real:
|
||||||
#if HAVE_CUBEB
|
#if HAVE_CUBEB
|
||||||
new_mic = std::make_unique<AudioCore::CubebInput>();
|
new_mic = std::make_unique<AudioCore::CubebInput>(Settings::values.mic_input_device);
|
||||||
#else
|
#else
|
||||||
new_mic = std::make_unique<Frontend::Mic::NullMic>();
|
new_mic = std::make_unique<Frontend::Mic::NullMic>();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user