Merge pull request #1 from extramaster/audio

Audio Core: Complete Device Switching
This commit is contained in:
Zach Toogood 2016-07-14 19:27:13 +01:00 committed by GitHub
commit 0d0d8eceb4
7 changed files with 24 additions and 9 deletions

View File

@ -56,17 +56,17 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
if (device_count < 1 || if (device_count < 1 ||
Settings::values.audio_device_id == "auto" || Settings::values.audio_device_id == "auto" ||
Settings::values.audio_device_id == "") { 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) { 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; return;
} }
} }
else 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) { 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; return;
} }
} }

View File

@ -26,6 +26,7 @@ public:
std::map<int, std::string>* GetDeviceMap(); std::map<int, std::string>* GetDeviceMap();
void SetDevice(int _device_id); void SetDevice(int _device_id);
private: private:
struct Impl; struct Impl;
std::unique_ptr<Impl> impl; std::unique_ptr<Impl> impl;
@ -33,6 +34,5 @@ private:
std::map<int, std::string> device_map; std::map<int, std::string> device_map;
}; };
extern const std::map<int, std::string> g_device_map;
} // namespace AudioCore } // namespace AudioCore

View File

@ -22,4 +22,11 @@ const std::vector<SinkDetails> g_sink_details = {
{ "null", []() { return std::make_unique<NullSink>(); } }, { "null", []() { return std::make_unique<NullSink>(); } },
}; };
#ifdef HAVE_SDL2
SDL2Sink sink;
const std::map<int, std::string> g_device_map = *sink.GetDeviceMap();
#else
const std::map<int, std::string> g_device_map = { {0, "null"} };
#endif
} // namespace AudioCore } // namespace AudioCore

View File

@ -7,6 +7,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <map>
namespace AudioCore { namespace AudioCore {
@ -23,5 +24,6 @@ struct SinkDetails {
}; };
extern const std::vector<SinkDetails> g_sink_details; extern const std::vector<SinkDetails> g_sink_details;
extern const std::map<int, std::string> g_device_map;
} // namespace AudioCore } // namespace AudioCore

View File

@ -66,6 +66,10 @@ bg_green =
# auto (default): Auto-select, null: No audio output, sdl2: SDL2 (if available) # auto (default): Auto-select, null: No audio output, sdl2: SDL2 (if available)
output_engine = output_engine =
# Which audio device to use.
# auto (default): Auto-select
output_device =
[Data Storage] [Data Storage]
# Whether to create a virtual SD card. # Whether to create a virtual SD card.
# 1 (default): Yes, 0: No # 1 (default): Yes, 0: No

View File

@ -59,6 +59,7 @@ void Config::ReadValues() {
qt_config->beginGroup("Audio"); qt_config->beginGroup("Audio");
Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); 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->endGroup();
qt_config->beginGroup("Data Storage"); qt_config->beginGroup("Data Storage");
@ -151,6 +152,7 @@ void Config::SaveValues() {
qt_config->beginGroup("Audio"); qt_config->beginGroup("Audio");
qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); 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->endGroup();
qt_config->beginGroup("Data Storage"); qt_config->beginGroup("Data Storage");

View File

@ -23,9 +23,9 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) :
ui->audio_device_combo_box->clear(); ui->audio_device_combo_box->clear();
ui->audio_device_combo_box->addItem("auto"); ui->audio_device_combo_box->addItem("auto");
//for (const auto& device : AudioCore:) { for (const auto& device : AudioCore::g_device_map) {
// ui->audio_device_combo_box->addItem(device.second.c_str()); ui->audio_device_combo_box->addItem(device.second.c_str());
//} }
this->setConfiguration(); this->setConfiguration();
} }
@ -51,7 +51,7 @@ void ConfigureAudio::setConfiguration() {
break; break;
} }
} }
ui->audio_device_combo_box->setCurrentIndex(new_sink_index); ui->audio_device_combo_box->setCurrentIndex(new_device_index);
} }
void ConfigureAudio::applyConfiguration() { void ConfigureAudio::applyConfiguration() {