summaryrefslogtreecommitdiff
path: root/src/audio_core/sdl2_sink.cpp
diff options
context:
space:
mode:
authorGravatar Kloen Lansfiel2017-01-26 04:33:26 +0100
committerGravatar Sebastian Valle2017-01-25 22:33:26 -0500
commitf8523699864b6000572affaa0e36d9a4d89ffce6 (patch)
tree952a96e11d4efe860272ea7a47ebbee896fb5d61 /src/audio_core/sdl2_sink.cpp
parentMerge pull request #2434 from mailwl/nfc-amiibo (diff)
downloadyuzu-f8523699864b6000572affaa0e36d9a4d89ffce6.tar.gz
yuzu-f8523699864b6000572affaa0e36d9a4d89ffce6.tar.xz
yuzu-f8523699864b6000572affaa0e36d9a4d89ffce6.zip
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 4b66cd826..933c5f16d 100644
--- a/src/audio_core/sdl2_sink.cpp
+++ b/src/audio_core/sdl2_sink.cpp
@@ -4,12 +4,12 @@
4 4
5#include <list> 5#include <list>
6#include <numeric> 6#include <numeric>
7#include <vector>
8#include <SDL.h> 7#include <SDL.h>
9#include "audio_core/audio_core.h" 8#include "audio_core/audio_core.h"
10#include "audio_core/sdl2_sink.h" 9#include "audio_core/sdl2_sink.h"
11#include "common/assert.h" 10#include "common/assert.h"
12#include "common/logging/log.h" 11#include "common/logging/log.h"
12#include "core/settings.h"
13 13
14namespace AudioCore { 14namespace AudioCore {
15 15
@@ -42,10 +42,24 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
42 SDL_AudioSpec obtained_audiospec; 42 SDL_AudioSpec obtained_audiospec;
43 SDL_zero(obtained_audiospec); 43 SDL_zero(obtained_audiospec);
44 44
45 impl->audio_device_id = 45 int device_count = SDL_GetNumAudioDevices(0);
46 SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, 0); 46 device_list.clear();
47 for (int i = 0; i < device_count; ++i) {
48 device_list.push_back(SDL_GetAudioDeviceName(i, 0));
49 }
50
51 const char* device = nullptr;
52
53 if (device_count >= 1 && Settings::values.audio_device_id != "auto" &&
54 !Settings::values.audio_device_id.empty()) {
55 device = Settings::values.audio_device_id.c_str();
56 }
57
58 impl->audio_device_id = SDL_OpenAudioDevice(device, false, &desired_audiospec,
59 &obtained_audiospec, SDL_AUDIO_ALLOW_ANY_CHANGE);
47 if (impl->audio_device_id <= 0) { 60 if (impl->audio_device_id <= 0) {
48 LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with: %s", SDL_GetError()); 61 LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with code %d for device \"%s\"",
62 impl->audio_device_id, Settings::values.audio_device_id.c_str());
49 return; 63 return;
50 } 64 }
51 65
@@ -69,6 +83,10 @@ unsigned int SDL2Sink::GetNativeSampleRate() const {
69 return impl->sample_rate; 83 return impl->sample_rate;
70} 84}
71 85
86std::vector<std::string> SDL2Sink::GetDeviceList() const {
87 return device_list;
88}
89
72void SDL2Sink::EnqueueSamples(const s16* samples, size_t sample_count) { 90void SDL2Sink::EnqueueSamples(const s16* samples, size_t sample_count) {
73 if (impl->audio_device_id <= 0) 91 if (impl->audio_device_id <= 0)
74 return; 92 return;
@@ -96,6 +114,10 @@ size_t SDL2Sink::SamplesInQueue() const {
96 return total_size; 114 return total_size;
97} 115}
98 116
117void SDL2Sink::SetDevice(int device_id) {
118 this->device_id = device_id;
119}
120
99void SDL2Sink::Impl::Callback(void* impl_, u8* buffer, int buffer_size_in_bytes) { 121void SDL2Sink::Impl::Callback(void* impl_, u8* buffer, int buffer_size_in_bytes) {
100 Impl* impl = reinterpret_cast<Impl*>(impl_); 122 Impl* impl = reinterpret_cast<Impl*>(impl_);
101 123