From cbc14ee0df4eec9187e25c7b16a1ca862aa7ad26 Mon Sep 17 00:00:00 2001 From: BearOso Date: Sun, 30 Apr 2023 15:51:14 -0500 Subject: [PATCH] sdsp: Check for invalid scale in defined way. --- apu/bapu/dsp/SPC_DSP.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apu/bapu/dsp/SPC_DSP.cpp b/apu/bapu/dsp/SPC_DSP.cpp index 06de2451..02dfa6ac 100644 --- a/apu/bapu/dsp/SPC_DSP.cpp +++ b/apu/bapu/dsp/SPC_DSP.cpp @@ -672,9 +672,10 @@ inline void SPC_DSP::decode_brr( voice_t* v ) // Shift sample based on header int const shift = header >> 4; - s = (s << shift) >> 1; - if ( shift >= 0xD ) // handle invalid range - s = (s >> 25) << 11; // same as: s = (s < 0 ? -0x800 : 0) + if (shift <= 12) + s = (s << shift) >> 1; + else + s &= 0x7ff; // Apply IIR filter (8 is the most commonly used) int const filter = header & 0x0C;