From 5a377103b5e0edca0d1908bd3c8f080c93bc431f Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 8 May 2024 21:04:07 +0200 Subject: [PATCH] small accuracy improvement (int)currentResult is a truncation, so we need to add 0.5 for proper rounding. also changed inefficient "constrain" into faster max(min( ...)) --- usermods/audioreactive/audio_reactive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 971c4b1c..f9effa2a 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -940,7 +940,7 @@ static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels) // p if (post_gain < 1.0f) post_gain = ((post_gain -1.0f) * 0.8f) +1.0f; currentResult *= post_gain; } - fftResult[i] = constrain((int)currentResult, 0, 255); + fftResult[i] = max(min((int)(currentResult+0.5f), 255), 0); // +0.5 for proper rounding } } ////////////////////