From d8fc3f403b62e2b3d67ec08791fdc66847ddb4ac Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 18 Mar 2023 20:52:02 +0000 Subject: audio: Interpolate system manager sample count using host sink sample info This avoids the need to stall if the host sink sporadically misses the deadline, in such a case the previous implementation would report them samples as being played on-time, causing the guest to send more samples and leading to a gradual buildup. --- src/audio_core/sink/sink_stream.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/audio_core/sink/sink_stream.h') diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index 5fea72ab7..2340c936c 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include "common/common_types.h" #include "common/reader_writer_queue.h" #include "common/ring_buffer.h" +#include "common/thread.h" namespace Core { class System; @@ -210,6 +212,13 @@ public: */ void Unstall(); + /** + * Get the total number of samples expected to have been played by this stream. + * + * @return The number of samples. + */ + u64 GetExpectedPlayedSampleCount(); + protected: /// Core system Core::System& system; @@ -237,6 +246,14 @@ private: std::atomic queued_buffers{}; /// The ring size for audio out buffers (usually 4, rarely 2 or 8) u32 max_queue_size{}; + /// Locks access to sample count tracking info + std::mutex sample_count_lock; + /// Minimum number of total samples that have been played since the last callback + u64 min_played_sample_count{}; + /// Maximum number of total samples that can be played since the last callback + u64 max_played_sample_count{}; + /// The time the two above tracking variables were last written to + std::chrono::microseconds last_sample_count_update_time{}; /// Set by the audio render/in/out system which uses this stream f32 system_volume{1.0f}; /// Set via IAudioDevice service calls -- cgit v1.2.3