diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index f8034b04b..8d7a82dc9 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -86,6 +86,16 @@ static void VolumeAdjustSamples(std::vector& samples, float game_volume) { } void Stream::PlayNextBuffer(std::chrono::nanoseconds ns_late) { +#ifndef _WIN32 + auto now = std::chrono::steady_clock::now(); + auto duration = now.time_since_epoch(); + auto nanoseconds = std::chrono::duration_cast(duration); + + if (nanoseconds > expected_cb_time) { + ns_late = nanoseconds - expected_cb_time; + } +#endif + if (!IsPlaying()) { // Ensure we are in playing state before playing the next buffer sink_stream.Flush(); @@ -120,6 +130,9 @@ void Stream::PlayNextBuffer(std::chrono::nanoseconds ns_late) { ns_late = {}; } +#ifndef _WIN32 + expected_cb_time = nanoseconds + (buffer_release_ns - ns_late); +#endif core_timing.ScheduleEvent(buffer_release_ns - ns_late, release_event, {}); } diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index f5de70396..fdf7ad6ca 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h @@ -123,6 +123,9 @@ private: SinkStream& sink_stream; ///< Output sink for the stream Core::Timing::CoreTiming& core_timing; ///< Core timing instance. std::string name; ///< Name of the stream, must be unique +#ifndef _WIN32 + std::chrono::nanoseconds expected_cb_time = {}; ///< Estimated time of next callback +#endif }; using StreamPtr = std::shared_ptr;