From 6599a15524ad9c41966f14f7bbf2ff556b8fd36b Mon Sep 17 00:00:00 2001 From: Floogle <18466542+skyfloogle@users.noreply.github.com> Date: Thu, 16 Nov 2023 00:09:45 +0100 Subject: [PATCH] better timing --- source/common/vb_sound.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/common/vb_sound.c b/source/common/vb_sound.c index e947963..c260cd1 100644 --- a/source/common/vb_sound.c +++ b/source/common/vb_sound.c @@ -43,8 +43,13 @@ void sound_thread() { int shutoff_divider = 0; int clk1_divider = 0; int envelope_divider = 0; + u64 lastTime = svcGetSystemTick(); while (true) { - svcWaitSynchronization(nothingEvent, 960000); + u64 newTime = svcGetSystemTick(); + s64 waitNanos = 960000 - 2000 * (newTime - lastTime) / CPU_TICKS_PER_USEC; + if (waitNanos > 0) + svcSleepThread(waitNanos / 2); + lastTime = newTime; // do clk0 if (--shutoff_divider >= 0) continue; shutoff_divider += 4;