From 0dc75ca08944433051a138e2d750ac8694633df6 Mon Sep 17 00:00:00 2001 From: Ruben <40356555+Aikku93@users.noreply.github.com> Date: Mon, 28 Oct 2019 15:28:09 +1100 Subject: [PATCH] add interpolation at loop boundary Fixes crackling in small streams and correctly interpolates chip-style samples --- desmume/src/SPU.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/desmume/src/SPU.cpp b/desmume/src/SPU.cpp index 75bdc4457..e2d3d2bf9 100644 --- a/desmume/src/SPU.cpp +++ b/desmume/src/SPU.cpp @@ -1058,12 +1058,12 @@ template static FORCEINLINE void Fetch8Bi u32 loc = sputrunc(chan->sampcnt); if(INTERPOLATE_MODE != SPUInterpolation_None) { - s32 a = (s32)(read_s8(chan->addr + loc) << 8); - if(loc < (chan->totlength << 2) - 1) { - s32 b = (s32)(read_s8(chan->addr + loc + 1) << 8); - a = Interpolate(a, b, chan->sampcnt); - } - *data = a; + s32 a = (s32)(read_s8(chan->addr + loc) << 8), b = a; + if(loc < (chan->totlength << 2) - 1) + b = (s32)(read_s8(chan->addr + loc + 1) << 8); + else if(chan->repeat == 1) + b = (s32)(read_s8(chan->addr + chan->loopstart*4) << 8); + *data = Interpolate(a, b, chan->sampcnt); } else *data = (s32)read_s8(chan->addr + loc)<< 8; @@ -1077,20 +1077,18 @@ template static FORCEINLINE void Fetch16B return; } + u32 loc = sputrunc(chan->sampcnt); if(INTERPOLATE_MODE != SPUInterpolation_None) { - u32 loc = sputrunc(chan->sampcnt); - - s32 a = (s32)read16(loc*2 + chan->addr), b; + s32 a = (s32)read16(loc*2 + chan->addr), b = a; if(loc < (chan->totlength << 1) - 1) - { - b = (s32)read16(loc*2 + chan->addr + 2); - a = Interpolate(a, b, chan->sampcnt); - } - *data = a; + b = (s32)read16(chan->addr + loc*2 + 2); + else if(chan->repeat == 1) + b = (s32)read16(chan->addr + chan->loopstart*2); + *data = Interpolate(a, b, chan->sampcnt); } else - *data = read16(chan->addr + sputrunc(chan->sampcnt)*2); + *data = read16(chan->addr + loc*2); } template static FORCEINLINE void FetchADPCMData(channel_struct * const chan, s32 * const data)