From bc37d78a5501ea520ad215af76ee5862a8fd12e0 Mon Sep 17 00:00:00 2001 From: patchzyy <64382339+patchzyy@users.noreply.github.com> Date: Sun, 25 Oct 2026 13:19:12 +0100 Subject: [PATCH] keep audio poll time remainder --- runtime/src/hle/audio/audio.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/runtime/src/hle/audio/audio.cpp b/runtime/src/hle/audio/audio.cpp index fd19215..f2166d4 100644 --- a/runtime/src/hle/audio/audio.cpp +++ b/runtime/src/hle/audio/audio.cpp @@ -503,19 +503,20 @@ int64_t ConsumeAudioPollDeltaMicros() using Clock = std::chrono::steady_clock; static thread_local Clock::time_point lastPoll = Clock::now(); - const Clock::time_point now = Clock::now(); - auto elapsed = std::chrono::duration_cast(now - lastPoll).count(); - lastPoll = now; - - if (elapsed < 0) { - elapsed = 0; - } - // Cap the catch-up interval after a debugger pause or host stall; backlog drains via // kMaxBlocksPerTick per pass. Never return early on a zero delta: two scheduler passes // can land in the same microsecond and the backlog still needs servicing. - constexpr int64_t kMaxPollDeltaMicros = 100'000; - return std::min(elapsed, kMaxPollDeltaMicros); + constexpr std::chrono::microseconds kMaxPollDelta{100'000}; + + const Clock::time_point now = Clock::now(); + const auto elapsed = std::chrono::duration_cast(now - lastPoll); + if (elapsed.count() < 0 || elapsed > kMaxPollDelta) { + lastPoll = now; + return elapsed.count() < 0 ? 0 : kMaxPollDelta.count(); + } + // Keep the sub-microsecond remainder for the next poll. + lastPoll += elapsed; + return elapsed.count(); } } // namespace