summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio_core/cubeb_sink.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index 552bcd051..3c129122f 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -89,6 +89,10 @@ public:
89 return num_channels; 89 return num_channels;
90 } 90 }
91 91
92 u32 GetNumChannelsInQueue() const {
93 return num_channels == 1 ? 1 : 2;
94 }
95
92private: 96private:
93 std::vector<std::string> device_list; 97 std::vector<std::string> device_list;
94 98
@@ -98,6 +102,7 @@ private:
98 bool is_6_channel{}; 102 bool is_6_channel{};
99 103
100 Common::RingBuffer<s16, 0x10000> queue; 104 Common::RingBuffer<s16, 0x10000> queue;
105 std::array<s16, 2> last_frame;
101 106
102 static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, 107 static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
103 void* output_buffer, long num_frames); 108 void* output_buffer, long num_frames);
@@ -156,13 +161,18 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const
156 return {}; 161 return {};
157 } 162 }
158 163
159 const size_t max_samples_to_write = impl->GetNumChannels() * num_frames; 164 const size_t num_channels = impl->GetNumChannelsInQueue();
165 const size_t max_samples_to_write = num_channels * num_frames;
160 const size_t samples_written = impl->queue.Pop(buffer, max_samples_to_write); 166 const size_t samples_written = impl->queue.Pop(buffer, max_samples_to_write);
161 167
162 if (samples_written < max_samples_to_write) { 168 if (samples_written >= num_channels) {
163 // Fill the rest of the frames with silence 169 std::memcpy(&impl->last_frame[0], buffer + (samples_written - num_channels) * sizeof(s16),
164 std::memset(buffer + samples_written * sizeof(s16), 0, 170 num_channels * sizeof(s16));
165 (max_samples_to_write - samples_written) * sizeof(s16)); 171 }
172
173 // Fill the rest of the frames with last_frame
174 for (size_t i = samples_written; i < max_samples_to_write; i += num_channels) {
175 std::memcpy(buffer + i * sizeof(s16), &impl->last_frame[0], num_channels * sizeof(s16));
166 } 176 }
167 177
168 return num_frames; 178 return num_frames;