From 64c526ede27cb9cafc7a9f7308b42a4ab80f9464 Mon Sep 17 00:00:00 2001 From: Ziemas Date: Wed, 17 Feb 2021 23:32:28 +0100 Subject: [PATCH] SPU2: Optimize reverb upsampling Skip the 0 coefs here as well. --- pcsx2/SPU2/Reverb.cpp | 24 ++++++++++++++++-------- pcsx2/SPU2/defs.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pcsx2/SPU2/Reverb.cpp b/pcsx2/SPU2/Reverb.cpp index 7181d61dd9..d93cf0914a 100644 --- a/pcsx2/SPU2/Reverb.cpp +++ b/pcsx2/SPU2/Reverb.cpp @@ -112,17 +112,26 @@ s32 __forceinline V_Core::ReverbDownsample(bool right) } -StereoOut32 __forceinline V_Core::ReverbUpsample() +StereoOut32 __forceinline V_Core::ReverbUpsample(bool phase) { s32 ls = 0, rs = 0; - for (u32 i = 0; i < NUM_TAPS; i++) + if (phase) { - ls += RevbUpBuf[0][((RevbSampleBufPos - NUM_TAPS) + i) & 63] * filter_coefs[i]; + ls += RevbUpBuf[0][(((RevbSampleBufPos - NUM_TAPS) >> 1) + 9) & 63] * filter_coefs[19]; + rs += RevbUpBuf[1][(((RevbSampleBufPos - NUM_TAPS) >> 1) + 9) & 63] * filter_coefs[19]; } - for (u32 i = 0; i < NUM_TAPS; i++) + else { - rs += RevbUpBuf[1][((RevbSampleBufPos - NUM_TAPS) + i) & 63] * filter_coefs[i]; + + for (u32 i = 0; i < (NUM_TAPS >> 1) + 1; i++) + { + ls += RevbUpBuf[0][(((RevbSampleBufPos - NUM_TAPS) >> 1) + i) & 63] * filter_coefs[i * 2]; + } + for (u32 i = 0; i < (NUM_TAPS >> 1) + 1; i++) + { + rs += RevbUpBuf[1][(((RevbSampleBufPos - NUM_TAPS) >> 1) + i) & 63] * filter_coefs[i * 2]; + } } ls >>= 14; @@ -223,10 +232,9 @@ StereoOut32 V_Core::DoReverb(const StereoOut32& Input) _spu2mem[apf2_dst] = clamp_mix(apf2); } - RevbUpBuf[0][RevbSampleBufPos & 63] = R ? 0 : clamp_mix(out); - RevbUpBuf[1][RevbSampleBufPos & 63] = R ? clamp_mix(out) : 0; + RevbUpBuf[R][(RevbSampleBufPos >> 1) & 63] = clamp_mix(out); RevbSampleBufPos++; - return ReverbUpsample(); + return ReverbUpsample(RevbSampleBufPos & 1); } diff --git a/pcsx2/SPU2/defs.h b/pcsx2/SPU2/defs.h index dfdc19b993..4fd5a161ac 100644 --- a/pcsx2/SPU2/defs.h +++ b/pcsx2/SPU2/defs.h @@ -497,7 +497,7 @@ struct V_Core s32 RevbGetIndexer(s32 offset); s32 ReverbDownsample(bool right); - StereoOut32 ReverbUpsample(); + StereoOut32 ReverbUpsample(bool phase); StereoOut32 ReadInput(); StereoOut32 ReadInput_HiFi();