From dd99f3a7c466e86e02a8a8811e4b41f471a8b15d Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sun, 20 Jan 2019 11:47:22 +0100 Subject: [PATCH] Improve handling of nan/inf (#4743) * If we find NaN/inf, we declare the whole buffer bad and set it to 0.0f. This is because the noise leading up to, or coming from, an infinite or NaN value is often very large and will create problems later in the sound chain. Especially if it hits a delay based fx with feedback. * We bump the clipping level to +/-10.0f. --- src/core/MixHelpers.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/MixHelpers.cpp b/src/core/MixHelpers.cpp index 60fa778af..a1fcd155d 100644 --- a/src/core/MixHelpers.cpp +++ b/src/core/MixHelpers.cpp @@ -79,12 +79,23 @@ bool sanitize( sampleFrame * src, int frames ) { if( isinff( src[f][c] ) || isnanf( src[f][c] ) ) { - src[f][c] = 0.0f; + #ifdef LMMS_DEBUG + printf("Bad data, clearing buffer. frame: "); + printf("%d: value %f\n", f, src[f][c]); + #endif + for( int f = 0; f < frames; ++f ) + { + for( int c = 0; c < 2; ++c ) + { + src[f][c] = 0.0f; + } + } found = true; + return found; } else { - src[f][c] = qBound( -4.0f, src[f][c], 4.0f ); + src[f][c] = qBound( -10.0f, src[f][c], 10.0f ); } } }