diff options
| author | 2018-09-12 18:07:16 +0100 | |
|---|---|---|
| committer | 2018-09-12 18:09:14 +0100 | |
| commit | 957ddab6796cb6f644c60993c3035d8bd9c0a398 (patch) | |
| tree | 17c3d0a96f47959a9c26d4f202003e5c2858fde3 /src/audio_core/cubeb_sink.cpp | |
| parent | cubeb_sink: Downsample arbitrary number of channels (diff) | |
| download | yuzu-957ddab6796cb6f644c60993c3035d8bd9c0a398.tar.gz yuzu-957ddab6796cb6f644c60993c3035d8bd9c0a398.tar.xz yuzu-957ddab6796cb6f644c60993c3035d8bd9c0a398.zip | |
audio_core: Flush stream when not playing anything
Diffstat (limited to 'src/audio_core/cubeb_sink.cpp')
| -rw-r--r-- | src/audio_core/cubeb_sink.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 067dc98d2..79155a7a0 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <atomic> | ||
| 6 | #include <cstring> | 7 | #include <cstring> |
| 7 | #include "audio_core/cubeb_sink.h" | 8 | #include "audio_core/cubeb_sink.h" |
| 8 | #include "audio_core/stream.h" | 9 | #include "audio_core/stream.h" |
| @@ -81,6 +82,10 @@ public: | |||
| 81 | return queue.Size() / num_channels; | 82 | return queue.Size() / num_channels; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 85 | void Flush() override { | ||
| 86 | should_flush = true; | ||
| 87 | } | ||
| 88 | |||
| 84 | u32 GetNumChannels() const { | 89 | u32 GetNumChannels() const { |
| 85 | return num_channels; | 90 | return num_channels; |
| 86 | } | 91 | } |
| @@ -94,6 +99,7 @@ private: | |||
| 94 | 99 | ||
| 95 | Common::RingBuffer<s16, 0x10000> queue; | 100 | Common::RingBuffer<s16, 0x10000> queue; |
| 96 | std::array<s16, 2> last_frame; | 101 | std::array<s16, 2> last_frame; |
| 102 | std::atomic<bool> should_flush{}; | ||
| 97 | TimeStretcher time_stretch; | 103 | TimeStretcher time_stretch; |
| 98 | 104 | ||
| 99 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, | 105 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, |
| @@ -163,6 +169,11 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const | |||
| 163 | s16* const out{reinterpret_cast<s16*>(buffer)}; | 169 | s16* const out{reinterpret_cast<s16*>(buffer)}; |
| 164 | const size_t out_frames = impl->time_stretch.Process(in.data(), num_in, out, num_frames); | 170 | const size_t out_frames = impl->time_stretch.Process(in.data(), num_in, out, num_frames); |
| 165 | samples_written = out_frames * num_channels; | 171 | samples_written = out_frames * num_channels; |
| 172 | |||
| 173 | if (impl->should_flush) { | ||
| 174 | impl->time_stretch.Flush(); | ||
| 175 | impl->should_flush = false; | ||
| 176 | } | ||
| 166 | } else { | 177 | } else { |
| 167 | samples_written = impl->queue.Pop(buffer, samples_to_write); | 178 | samples_written = impl->queue.Pop(buffer, samples_to_write); |
| 168 | } | 179 | } |