From 8a596b0898bdc12568c8b3670b52ba93bdb93e4e Mon Sep 17 00:00:00 2001 From: Vesa Date: Tue, 21 Oct 2014 00:09:42 +0300 Subject: [PATCH] Sanitize output of all effects when exporting --- include/MixHelpers.h | 2 ++ src/core/EffectChain.cpp | 12 +++++++++++- src/core/MixHelpers.cpp | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/MixHelpers.h b/include/MixHelpers.h index 376b0bd61..4a2f510ee 100644 --- a/include/MixHelpers.h +++ b/include/MixHelpers.h @@ -33,6 +33,8 @@ namespace MixHelpers bool isSilent( const sampleFrame* src, int frames ); +bool sanitize( sampleFrame * src, int frames ); + /*! \brief Add samples from src to dst */ void add( sampleFrame* dst, const sampleFrame* src, int frames ); diff --git a/src/core/EffectChain.cpp b/src/core/EffectChain.cpp index 1d57de940..708cd9698 100644 --- a/src/core/EffectChain.cpp +++ b/src/core/EffectChain.cpp @@ -31,7 +31,8 @@ #include "engine.h" #include "debug.h" #include "DummyEffect.h" - +#include "MixHelpers.h" +#include "song.h" EffectChain::EffectChain( Model * _parent ) : @@ -194,6 +195,11 @@ bool EffectChain::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames, b { return false; } + const bool exporting = engine::getSong()->isExporting(); + if( exporting ) // strip infs/nans if exporting + { + MixHelpers::sanitize( _buf, _frames ); + } bool moreEffects = false; for( EffectList::Iterator it = m_effects.begin(); it != m_effects.end(); ++it ) @@ -201,6 +207,10 @@ bool EffectChain::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames, b if( hasInputNoise || ( *it )->isRunning() ) { moreEffects |= ( *it )->processAudioBuffer( _buf, _frames ); + if( exporting ) // strip infs/nans if exporting + { + MixHelpers::sanitize( _buf, _frames ); + } } #ifdef LMMS_DEBUG diff --git a/src/core/MixHelpers.cpp b/src/core/MixHelpers.cpp index da5f34c55..a6e43e05a 100644 --- a/src/core/MixHelpers.cpp +++ b/src/core/MixHelpers.cpp @@ -69,6 +69,25 @@ bool isSilent( const sampleFrame* src, int frames ) } +/*! \brief Function for sanitizing a buffer of infs/nans - returns true if those are found */ +bool sanitize( sampleFrame * src, int frames ) +{ + bool found = false; + for( int f = 0; f < frames; ++f ) + { + for( int c = 0; c < 2; ++c ) + { + if( isinff( src[f][c] ) || isnanf( src[f][c] ) ) + { + src[f][c] = 0.0f; + found = true; + } + } + } + return found; +} + + struct AddOp { void operator()( sampleFrame& dst, const sampleFrame& src ) const