From a5e021a41410d18e07920989c6c47d93118db65a Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:18:33 +0300 Subject: [PATCH] Add busy loop to audio thread. --- UnleashedRecomp/apu/driver/sdl2_driver.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/apu/driver/sdl2_driver.cpp b/UnleashedRecomp/apu/driver/sdl2_driver.cpp index be0acd94..e06e8a86 100644 --- a/UnleashedRecomp/apu/driver/sdl2_driver.cpp +++ b/UnleashedRecomp/apu/driver/sdl2_driver.cpp @@ -59,7 +59,12 @@ static void AudioThread() auto now = std::chrono::steady_clock::now(); if ((next - now) < 1s) - std::this_thread::sleep_until(next); + { + std::this_thread::sleep_for(std::chrono::floor(next - now)); + + while ((now = std::chrono::steady_clock::now()) < next) + std::this_thread::yield(); + } int64_t elapsed = std::chrono::nanoseconds(std::chrono::steady_clock::now() - start).count(); iteration = ((elapsed * XAUDIO_SAMPLES_HZ) / (XAUDIO_NUM_SAMPLES * 1000000000ll)) + 1;