From 9bc8a230b7edcb23b079c24024066543f95f3691 Mon Sep 17 00:00:00 2001 From: Andy Tran Date: Thu, 14 Jul 2016 10:24:55 +1000 Subject: [PATCH] Audio Core: Complete Device Switching Complete the device switching implementation by allowing the output device to be loaded, changed and saved through the configurations menu. --- src/audio_core/sdl2_sink.cpp | 8 ++++---- src/audio_core/sdl2_sink.h | 2 +- src/audio_core/sink_details.cpp | 7 +++++++ src/audio_core/sink_details.h | 2 ++ src/citra/default_ini.h | 4 ++++ src/citra_qt/config.cpp | 2 ++ src/citra_qt/configure_audio.cpp | 8 ++++---- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/audio_core/sdl2_sink.cpp b/src/audio_core/sdl2_sink.cpp index 74bb1f212..6426d20f3 100644 --- a/src/audio_core/sdl2_sink.cpp +++ b/src/audio_core/sdl2_sink.cpp @@ -56,17 +56,17 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique()) { if (device_count < 1 || Settings::values.audio_device_id == "auto" || Settings::values.audio_device_id == "") { - impl->audio_device_id = SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, 0); + impl->audio_device_id = SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, SDL_AUDIO_ALLOW_ANY_CHANGE); if (impl->audio_device_id <= 0) { - LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed"); + LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with code %d for device \"auto\"", impl->audio_device_id); return; } } else { - impl->audio_device_id = SDL_OpenAudioDevice(device_map[device_id].c_str(), false, &desired_audiospec, &obtained_audiospec, 0); + impl->audio_device_id = SDL_OpenAudioDevice(Settings::values.audio_device_id.c_str(), false, &desired_audiospec, &obtained_audiospec, SDL_AUDIO_ALLOW_ANY_CHANGE); if (impl->audio_device_id <= 0) { - LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed"); + LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with code %d for device \"%s\"", impl->audio_device_id, Settings::values.audio_device_id.c_str()); return; } } diff --git a/src/audio_core/sdl2_sink.h b/src/audio_core/sdl2_sink.h index 5199529fe..6552c088e 100644 --- a/src/audio_core/sdl2_sink.h +++ b/src/audio_core/sdl2_sink.h @@ -26,6 +26,7 @@ public: std::map* GetDeviceMap(); void SetDevice(int _device_id); + private: struct Impl; std::unique_ptr impl; @@ -33,6 +34,5 @@ private: std::map device_map; }; -extern const std::map g_device_map; } // namespace AudioCore diff --git a/src/audio_core/sink_details.cpp b/src/audio_core/sink_details.cpp index ba5e83d17..9ee92ac0e 100644 --- a/src/audio_core/sink_details.cpp +++ b/src/audio_core/sink_details.cpp @@ -22,4 +22,11 @@ const std::vector g_sink_details = { { "null", []() { return std::make_unique(); } }, }; +#ifdef HAVE_SDL2 +SDL2Sink sink; +const std::map g_device_map = *sink.GetDeviceMap(); +#else +const std::map g_device_map = { {0, "null"} }; +#endif + } // namespace AudioCore diff --git a/src/audio_core/sink_details.h b/src/audio_core/sink_details.h index 4b30cf835..783a314a5 100644 --- a/src/audio_core/sink_details.h +++ b/src/audio_core/sink_details.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace AudioCore { @@ -23,5 +24,6 @@ struct SinkDetails { }; extern const std::vector g_sink_details; +extern const std::map g_device_map; } // namespace AudioCore diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index 4e63f3206..5545dc41d 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -66,6 +66,10 @@ bg_green = # auto (default): Auto-select, null: No audio output, sdl2: SDL2 (if available) output_engine = +# Which audio device to use. +# auto (default): Auto-select +output_device = + [Data Storage] # Whether to create a virtual SD card. # 1 (default): Yes, 0: No diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index ba7edaff9..eebf97c38 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -59,6 +59,7 @@ void Config::ReadValues() { qt_config->beginGroup("Audio"); Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); + Settings::values.audio_device_id = qt_config->value("output_device", "auto").toString().toStdString(); qt_config->endGroup(); qt_config->beginGroup("Data Storage"); @@ -151,6 +152,7 @@ void Config::SaveValues() { qt_config->beginGroup("Audio"); qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); + qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); qt_config->endGroup(); qt_config->beginGroup("Data Storage"); diff --git a/src/citra_qt/configure_audio.cpp b/src/citra_qt/configure_audio.cpp index 25e13a051..5db2077ea 100644 --- a/src/citra_qt/configure_audio.cpp +++ b/src/citra_qt/configure_audio.cpp @@ -23,9 +23,9 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) : ui->audio_device_combo_box->clear(); ui->audio_device_combo_box->addItem("auto"); - //for (const auto& device : AudioCore:) { - // ui->audio_device_combo_box->addItem(device.second.c_str()); - //} + for (const auto& device : AudioCore::g_device_map) { + ui->audio_device_combo_box->addItem(device.second.c_str()); + } this->setConfiguration(); } @@ -51,7 +51,7 @@ void ConfigureAudio::setConfiguration() { break; } } - ui->audio_device_combo_box->setCurrentIndex(new_sink_index); + ui->audio_device_combo_box->setCurrentIndex(new_device_index); } void ConfigureAudio::applyConfiguration() {