From 8310a672b01763c5c783f6afb638bcd23b07005d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 18 Sep 2017 23:40:06 +0200 Subject: [PATCH] DSP: Fix the predscale update logic When the current address is xxxxxxxf, after doing the standard ADPCM decoding and incrementing the current address as usual to get the next address, the DSP will update the predscale register by reading 2 bytes from memory, and add two to get the next address. This means xxxxxx10 cannot be a current address, as the DSP goes from 0f to 12 directly. A more serious issue with the old code is that if the start address is 16-byte aligned, some samples will always be skipped, even when that should not be the case. An easy way to test whether this behaviour is correct is to check the current address register and the predscale after each read. Old code: ... ACCA=00000002, predscale= ACCA=00000003, predscale= ... ACCA=0000000f, predscale= ACCA=00000010, predscale= ACCA=00000013, predscale= ACCA=00000014, predscale= ... New code (and console): ... ACCA=00000002, predscale= ACCA=00000003, predscale= ... ACCA=0000000f, predscale= ACCA=00000012, predscale= ACCA=00000013, predscale= ... --- Source/Core/Core/DSP/DSPAccelerator.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/DSP/DSPAccelerator.cpp b/Source/Core/Core/DSP/DSPAccelerator.cpp index c82b62530a..a6a2695364 100644 --- a/Source/Core/Core/DSP/DSPAccelerator.cpp +++ b/Source/Core/Core/DSP/DSPAccelerator.cpp @@ -73,13 +73,6 @@ u16 Accelerator::Read(s16* coefs) { case 0x00: // ADPCM audio { - // ADPCM decoding, not much to explain here. - if ((m_current_address & 15) == 0) - { - m_pred_scale = ReadMemory((m_current_address & ~15) >> 1); - m_current_address += 2; - } - switch (m_end_address & 15) { case 0: // Tom and Jerry @@ -111,6 +104,13 @@ u16 Accelerator::Read(s16* coefs) m_yn2 = m_yn1; m_yn1 = val; m_current_address += 1; + + if ((m_current_address & 15) == 0) + { + m_pred_scale = ReadMemory((m_current_address & ~15) >> 1); + m_current_address += 2; + step_size_bytes += 2; + } break; } case 0x0A: // 16-bit PCM audio