all repos — mgba @ 0aa35b8e12263af8ed229caaf5c81b9203436e07

mGBA Game Boy Advance Emulator

3DS: Redo video sync to be more precise
Vicki Pfau vi@endrift.com
Fri, 07 Aug 2020 18:27:24 -0700
commit

0aa35b8e12263af8ed229caaf5c81b9203436e07

parent

65e66feb598d774403a7d28487f49b277f20fd5b

2 files changed, 12 insertions(+), 6 deletions(-)

jump to
M CHANGESCHANGES

@@ -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
M src/platform/3ds/main.csrc/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 @@ if (frameStarted) {

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 @@ break;

} 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 @@ if (frameLimiter == limit) {

return; } frameLimiter = limit; - tickCounter = svcGetSystemTick(); } static bool _running(struct mGUIRunner* runner) {