summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-03 14:50:53 -0400
committerGravatar bunnei2018-08-04 15:30:10 -0400
commit02fccc09408de59629ea408d825a8978882a6e06 (patch)
tree722448cd89bbbb42189fb0d28d19931c013c2942 /src
parentaudio_core: Sinks need unique names as well. (diff)
downloadyuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.gz
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.xz
yuzu-02fccc09408de59629ea408d825a8978882a6e06.zip
cubeb_sink: Support variable sample_rate and num_channels.
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/cubeb_sink.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index cf4839989..0b0e9a053 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -13,14 +13,24 @@ namespace AudioCore {
13 13
14class SinkStreamImpl final : public SinkStream { 14class SinkStreamImpl final : public SinkStream {
15public: 15public:
16 SinkStreamImpl(cubeb* ctx, cubeb_devid output_device, const std::string& name) : ctx{ctx} { 16 SinkStreamImpl(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device,
17 cubeb_stream_params params; 17 const std::string& name)
18 params.rate = 48000; 18 : ctx{ctx}, num_channels{num_channels_} {
19 params.channels = GetNumChannels(); 19
20 if (num_channels == 6) {
21 // 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2
22 // channel for now
23 is_6_channel = true;
24 num_channels = 2;
25 }
26
27 cubeb_stream_params params{};
28 params.rate = sample_rate;
29 params.channels = num_channels;
20 params.format = CUBEB_SAMPLE_S16NE; 30 params.format = CUBEB_SAMPLE_S16NE;
21 params.layout = CUBEB_LAYOUT_STEREO; 31 params.layout = num_channels == 1 ? CUBEB_LAYOUT_MONO : CUBEB_LAYOUT_STEREO;
22 32
23 u32 minimum_latency = 0; 33 u32 minimum_latency{};
24 if (cubeb_get_min_latency(ctx, &params, &minimum_latency) != CUBEB_OK) { 34 if (cubeb_get_min_latency(ctx, &params, &minimum_latency) != CUBEB_OK) {
25 LOG_CRITICAL(Audio_Sink, "Error getting minimum latency"); 35 LOG_CRITICAL(Audio_Sink, "Error getting minimum latency");
26 } 36 }
@@ -58,11 +68,7 @@ public:
58 68
59 queue.reserve(queue.size() + sample_count * GetNumChannels()); 69 queue.reserve(queue.size() + sample_count * GetNumChannels());
60 70
61 if (num_channels == 2) { 71 if (is_6_channel) {
62 // Copy as-is
63 std::copy(samples, samples + sample_count * GetNumChannels(),
64 std::back_inserter(queue));
65 } else if (num_channels == 6) {
66 // Downsample 6 channels to 2 72 // Downsample 6 channels to 2
67 const size_t sample_count_copy_size = sample_count * num_channels * 2; 73 const size_t sample_count_copy_size = sample_count * num_channels * 2;
68 queue.reserve(sample_count_copy_size); 74 queue.reserve(sample_count_copy_size);
@@ -71,13 +77,14 @@ public:
71 queue.push_back(samples[i + 1]); 77 queue.push_back(samples[i + 1]);
72 } 78 }
73 } else { 79 } else {
74 ASSERT_MSG(false, "Unimplemented"); 80 // Copy as-is
81 std::copy(samples, samples + sample_count * GetNumChannels(),
82 std::back_inserter(queue));
75 } 83 }
76 } 84 }
77 85
78 u32 GetNumChannels() const { 86 u32 GetNumChannels() const {
79 // Only support 2-channel stereo output for now 87 return num_channels;
80 return 2;
81 } 88 }
82 89
83private: 90private:
@@ -85,6 +92,8 @@ private:
85 92
86 cubeb* ctx{}; 93 cubeb* ctx{};
87 cubeb_stream* stream_backend{}; 94 cubeb_stream* stream_backend{};
95 u32 num_channels{};
96 bool is_6_channel{};
88 97
89 std::vector<s16> queue; 98 std::vector<s16> queue;
90 99
@@ -131,7 +140,8 @@ CubebSink::~CubebSink() {
131 140
132SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, 141SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels,
133 const std::string& name) { 142 const std::string& name) {
134 sink_streams.push_back(std::make_unique<SinkStreamImpl>(ctx, output_device, name)); 143 sink_streams.push_back(
144 std::make_unique<SinkStreamImpl>(ctx, sample_rate, num_channels, output_device, name));
135 return *sink_streams.back(); 145 return *sink_streams.back();
136} 146}
137 147