From 32d4a6d002297f6978b6e76907a279c5f8c203fe Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Sun, 3 Jun 2018 22:29:19 +0200 Subject: clamp the outputs of 16bit adding generators --- src/chips/nuked_opl3_v174.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/chips/nuked_opl3_v174.cpp') diff --git a/src/chips/nuked_opl3_v174.cpp b/src/chips/nuked_opl3_v174.cpp index 675e104..d8e8ef8 100644 --- a/src/chips/nuked_opl3_v174.cpp +++ b/src/chips/nuked_opl3_v174.cpp @@ -73,10 +73,14 @@ int NukedOPL3v174::generateAndMix(int16_t *output, size_t frames) #if defined(ADLMIDI_ENABLE_HQ_RESAMPLER) for(size_t i = 0; i < frames; ++i) { - int16_t frame[2]; - generateResampledHq(frame); - output[0] += (int32_t)frame[0]; - output[1] += (int32_t)frame[1]; + int32_t frame[2]; + generateResampledHq32(frame); + for (unsigned c = 0; c < 2; ++c) { + int32_t temp = (int32_t)output[c] + frame[c]; + temp = (temp > -32768) ? temp : -32768; + temp = (temp < 32767) ? temp : 32767; + output[c] = temp; + } output += 2; } #else -- cgit v1.2.3