From 5acd7ddd7125042b1202847f52c22d4a7da982c7 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Fri, 27 Dec 2019 15:28:06 +0200 Subject: [PATCH] Solve the sound clicking issue in Kirby! The symptom of the problem was in the form of a rythmic click sound popping in the left channel. Diving deep into Kirby's binary, I found out that channel B and channel A are playing too different pcm buffers simultationsly: A is enabled for the right channel and B is enabled for the left. I found out that the game's sound driver was using VCOUNT in order to syncornize the audio, but in some occassions the fifo DMA was not disabled in time, causing the DMA to fill the fifo in additional 16 bytes of garbage residing next to channel B's pcmBuffer. After a thorough check-up of the GPU state machine, I find out that I stay in VBLANK for 1 line too long, and that's what caused the audio buffer to de-sync with the gpu emulation. This commit fixes this issue. Former-commit-id: e0f20bd01b8abf62da486e2501cff197a9a22763 --- src/core/gpu/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/gpu/mod.rs b/src/core/gpu/mod.rs index ad37cb8..5a9d140 100644 --- a/src/core/gpu/mod.rs +++ b/src/core/gpu/mod.rs @@ -513,7 +513,7 @@ impl Gpu { if self.cycles > CYCLES_SCANLINE { self.cycles -= CYCLES_SCANLINE; - if self.current_scanline < DISPLAY_HEIGHT + VBLANK_LINES { + if self.current_scanline < DISPLAY_HEIGHT + VBLANK_LINES - 1 { self.update_vcount(self.current_scanline + 1, irqs); return None; } else {