From 18d0f1588589417a63e399caaf3e83ecc971304b Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 14 Aug 2015 11:32:24 +0200 Subject: [PATCH] ZeldaHLE: Fix the AFC remaining samples logic on looping. --- Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp index ace118b2f9..6e5e93c25d 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp @@ -1579,8 +1579,19 @@ void ZeldaAudioRenderer::DownloadAFCSamplesFromARAM( DecodeAFC(vpb, dst, requested_blocks_count); - for (size_t i = 0; i < 0x10; ++i) - vpb->afc_remaining_samples[i] = dst[decoded_samples_count - 0x10 + i]; + if (vpb->afc_remaining_decoded_samples) + { + for (size_t i = 0; i < 0x10; ++i) + vpb->afc_remaining_samples[i] = dst[decoded_samples_count - 0x10 + i]; + + if (!vpb->GetRemainingLength() && vpb->GetLoopStartPosition()) + { + // Adjust remaining samples to account for the future loop iteration. + base = vpb->afc_remaining_samples + ((vpb->GetLoopStartPosition() + 0xF) & 0xF); + for (size_t i = 0; i < vpb->afc_remaining_decoded_samples; ++i) + vpb->afc_remaining_samples[0x10 - i - 1] = *base--; + } + } return; }