From 0aa35b8e12263af8ed229caaf5c81b9203436e07 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 7 Aug 2020 18:27:24 -0700 Subject: [PATCH] 3DS: Redo video sync to be more precise --- CHANGES | 1 + src/platform/3ds/main.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 2be8d1ebd..0601388eb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 0.8.4: (Future) Other fixes: + - 3DS: Redo video sync to be more precise - Qt: Add dummy English translation file (fixes mgba.io/i/1469) - VFS: Fix directory node listing on some filesystems diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 52779bfc2..a43753ea1 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -94,7 +94,7 @@ static int activeOutputTexture = 0; static ndspWaveBuf dspBuffer[DSP_BUFFERS]; static int bufferId = 0; static bool frameLimiter = true; -static u64 tickCounter; +static u32 frameCounter; static C3D_RenderTarget* topScreen[2]; static C3D_RenderTarget* bottomScreen[2]; @@ -207,11 +207,17 @@ static void _drawStart(void) { return; } frameStarted = true; + + int screen = screenMode >= SM_PA_TOP ? GSP_SCREEN_TOP : GSP_SCREEN_BOTTOM; if (frameLimiter) { - if (tickCounter + 4481000 > svcGetSystemTick()) { - C3D_FrameSync(); + u32 oldFrame = frameCounter; + frameCounter = C3D_FrameCounter(screen); + while (oldFrame == frameCounter) { + gspWaitForAnyEvent(); + frameCounter = C3D_FrameCounter(screen); } - tickCounter = svcGetSystemTick(); + } else { + frameCounter = C3D_FrameCounter(screen); } C3D_FrameBegin(0); ctrStartFrame(); @@ -344,7 +350,7 @@ static void _gameLoaded(struct mGUIRunner* runner) { } osSetSpeedupEnable(true); - double ratio = GBAAudioCalculateRatio(1, 59.8260982880808, 1); + double ratio = GBAAudioCalculateRatio(1, 268111856.f / 4481136.f, 1); blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 32768 * ratio); blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 32768 * ratio); if (hasSound != NO_SOUND) { @@ -658,7 +664,6 @@ static void _setFrameLimiter(struct mGUIRunner* runner, bool limit) { return; } frameLimiter = limit; - tickCounter = svcGetSystemTick(); } static bool _running(struct mGUIRunner* runner) {