diff options
author | Billy Laws <blaws05@gmail.com> | 2023-03-18 21:57:00 +0100 |
---|---|---|
committer | Billy Laws <blaws05@gmail.com> | 2023-03-27 22:34:28 +0200 |
commit | ea5dd02db9bdb9759a400907672ec6606bebb96b (patch) | |
tree | 9f6f4f4662eb48ad57fe713e29f6b98778f263bf /src/audio_core/sink | |
parent | audio: Interpolate system manager sample count using host sink sample info (diff) | |
download | yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar.gz yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar.bz2 yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar.lz yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar.xz yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.tar.zst yuzu-ea5dd02db9bdb9759a400907672ec6606bebb96b.zip |
Diffstat (limited to 'src/audio_core/sink')
-rw-r--r-- | src/audio_core/sink/sink_stream.cpp | 15 | ||||
-rw-r--r-- | src/audio_core/sink/sink_stream.h | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 1af96f793..a54c61845 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp @@ -205,6 +205,10 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz // If we're paused or going to shut down, we don't want to consume buffers as coretiming is // paused and we'll desync, so just play silence. if (system.IsPaused() || system.IsShuttingDown()) { + if (system.IsShuttingDown()) { + release_cv.notify_one(); + } + static constexpr std::array<s16, 6> silence{}; for (size_t i = frames_written; i < num_frames; i++) { std::memcpy(&output_buffer[i * frame_size], &silence[0], frame_size_bytes); @@ -240,6 +244,12 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz } // Successfully dequeued a new buffer. queued_buffers--; + + { + std::unique_lock lk{release_mutex}; + } + + release_cv.notify_one(); } // Get the minimum frames available between the currently playing buffer, and the @@ -303,4 +313,9 @@ u64 SinkStream::GetExpectedPlayedSampleCount() { return std::min<u64>(exp_played_sample_count, max_played_sample_count); } +void SinkStream::WaitFreeSpace() { + std::unique_lock lk{release_mutex}; + release_cv.wait(lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); }); +} + } // namespace AudioCore::Sink diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index 2340c936c..709f3b0ec 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h @@ -16,6 +16,7 @@ #include "common/reader_writer_queue.h" #include "common/ring_buffer.h" #include "common/thread.h" +#include "common/polyfill_thread.h" namespace Core { class System; @@ -219,6 +220,11 @@ public: */ u64 GetExpectedPlayedSampleCount(); + /** + * Waits for free space in the sample ring buffer + */ + void WaitFreeSpace(); + protected: /// Core system Core::System& system; @@ -258,6 +264,9 @@ private: f32 system_volume{1.0f}; /// Set via IAudioDevice service calls f32 device_volume{1.0f}; + /// Signalled when ring buffer entries are consumed + std::condition_variable release_cv; + std::mutex release_mutex; std::mutex stall_guard; std::unique_lock<std::mutex> stalled_lock; }; |