From 257638f77aa1e3445527f36422e4fcd233c5a6c7 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Tue, 12 Mar 2019 16:31:44 -0500 Subject: [PATCH] Clamp MSU1+S-DSP mixing. --- apu/apu.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index 941b2eca..d3fde6ce 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -90,7 +90,10 @@ bool8 S9xMixSamples(uint8 *dest, int sample_count) msu::resampler->read((short *)msu::resample_buffer.data(), sample_count); for (int i = 0; i < sample_count; ++i) - out[i] += msu::resample_buffer[i]; + { + int32 mixed = (int32)out[i] + msu::resample_buffer[i]; + out[i] = ((int16)mixed != mixed) ? (mixed >> 31) ^ 0x7fff : mixed; + } } else // should never occur assert(0);