From 8f47454c034bcda188f4ee62885401ab18024b8e Mon Sep 17 00:00:00 2001 From: Ribbit Date: Sat, 25 Oct 2025 20:47:35 -0700 Subject: [PATCH] [Experiment] Audio Test --- src/audio_core/sink/sink_stream.cpp | 12 +++++++++--- src/audio_core/sink/sink_stream.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 88e2dfa3d3..d591fe1345 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp @@ -237,9 +237,15 @@ u64 SinkStream::GetExpectedPlayedSampleCount() { void SinkStream::WaitFreeSpace(std::stop_token stop_token) { std::unique_lock lk{release_mutex}; - release_cv.wait_for(lk, std::chrono::milliseconds(5), [this]() { return paused || queued_buffers < max_queue_size; }); - if (queued_buffers > max_queue_size + 3) { - release_cv.wait(lk, stop_token, [this] { return paused || queued_buffers < max_queue_size; }); + + const auto has_space = [this]() { + const u32 current_size = queued_buffers.load(std::memory_order_relaxed); + return paused || max_queue_size == 0 || current_size < max_queue_size; + }; + + if (!has_space()) { + // Wait until the queue falls below the configured limit or the stream is paused/stopped. + release_cv.wait(lk, stop_token, has_space); } } diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index cc34c3db45..4ffccef332 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h @@ -240,7 +240,7 @@ private: /// Ring buffer of the samples waiting to be played or consumed Common::RingBuffer samples_buffer; /// Audio buffers queued and waiting to play - Common::SPSCQueue queue; + Common::SPSCQueue queue; /// The currently-playing audio buffer SinkBuffer playing_buffer{}; /// The last played (or received) frame of audio, used when the callback underruns