aboutsummaryrefslogtreecommitdiff
path: root/src/audio_core/sdl2_sink.cpp
diff options
context:
space:
mode:
authorKloen Lansfiel <kloen@outlawkiwi.com>2017-01-26 04:33:26 +0100
committerSebastian Valle <subv2112@gmail.com>2017-01-25 22:33:26 -0500
commitf8523699864b6000572affaa0e36d9a4d89ffce6 (patch)
tree952a96e11d4efe860272ea7a47ebbee896fb5d61 /src/audio_core/sdl2_sink.cpp
parent3feb3ce283b53be644bc4ca884817aba9cf63a81 (diff)
SDL: Select audio device (#2403)
* Initial Commit Added Device logic to Sinks Started on UI for selecting devices Removed redundant import * 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. Worked with the Sink abstraction and tuned the "Device Selection" configuration so that the Device List is automatically populated when the Sink is changed. This hopefully addresses the concerns and recommendations mentioned in the comments of the PR. * Clean original implementation. * Refactor GetSinkDetails
Diffstat (limited to 'src/audio_core/sdl2_sink.cpp')
-rw-r--r--src/audio_core/sdl2_sink.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/audio_core/sdl2_sink.cpp b/src/audio_core/sdl2_sink.cpp
index 4b66cd8266..933c5f16d1 100644
--- a/src/audio_core/sdl2_sink.cpp
+++ b/src/audio_core/sdl2_sink.cpp
@@ -4,12 +4,12 @@
#include <list>
#include <numeric>
-#include <vector>
#include <SDL.h>
#include "audio_core/audio_core.h"
#include "audio_core/sdl2_sink.h"
#include "common/assert.h"
#include "common/logging/log.h"
+#include "core/settings.h"
namespace AudioCore {
@@ -42,10 +42,24 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
SDL_AudioSpec obtained_audiospec;
SDL_zero(obtained_audiospec);
- impl->audio_device_id =
- SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, 0);
+ int device_count = SDL_GetNumAudioDevices(0);
+ device_list.clear();
+ for (int i = 0; i < device_count; ++i) {
+ device_list.push_back(SDL_GetAudioDeviceName(i, 0));
+ }
+
+ const char* device = nullptr;
+
+ if (device_count >= 1 && Settings::values.audio_device_id != "auto" &&
+ !Settings::values.audio_device_id.empty()) {
+ device = Settings::values.audio_device_id.c_str();
+ }
+
+ impl->audio_device_id = SDL_OpenAudioDevice(device, false, &desired_audiospec,
+ &obtained_audiospec, SDL_AUDIO_ALLOW_ANY_CHANGE);
if (impl->audio_device_id <= 0) {
- LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with: %s", SDL_GetError());
+ 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;
}
@@ -69,6 +83,10 @@ unsigned int SDL2Sink::GetNativeSampleRate() const {
return impl->sample_rate;
}
+std::vector<std::string> SDL2Sink::GetDeviceList() const {
+ return device_list;
+}
+
void SDL2Sink::EnqueueSamples(const s16* samples, size_t sample_count) {
if (impl->audio_device_id <= 0)
return;
@@ -96,6 +114,10 @@ size_t SDL2Sink::SamplesInQueue() const {
return total_size;
}
+void SDL2Sink::SetDevice(int device_id) {
+ this->device_id = device_id;
+}
+
void SDL2Sink::Impl::Callback(void* impl_, u8* buffer, int buffer_size_in_bytes) {
Impl* impl = reinterpret_cast<Impl*>(impl_);