From 07a23c4e3b5c16c60ac6a5a89c9330bbd513cb49 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sun, 15 Apr 2018 15:44:38 +0200 Subject: [PATCH] Allways remove infs/nans (#3706) When exporting a project lmms performs extra tests for bad data. The tests are for infs and nans. Switching these tests on for all occasions as the extra performance hit would be in the order of only ~2% and the problems, when it hits the end user, are hard to debug and/or work around. After testing for inf/nan we clamp the sound to +/-4.0f as sometimes you will get large transients passing through (an issue that is currently only present when exporting). Fixes: #1048 --- src/core/EffectChain.cpp | 12 +++--------- src/core/FxMixer.cpp | 13 ++++--------- src/core/MixHelpers.cpp | 4 ++++ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/core/EffectChain.cpp b/src/core/EffectChain.cpp index a1aea9d3a74..efadca525b6 100644 --- a/src/core/EffectChain.cpp +++ b/src/core/EffectChain.cpp @@ -202,11 +202,8 @@ 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 ); - } + + MixHelpers::sanitize( _buf, _frames ); bool moreEffects = false; for( EffectList::Iterator it = m_effects.begin(); it != m_effects.end(); ++it ) @@ -214,10 +211,7 @@ 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 ); - } + MixHelpers::sanitize( _buf, _frames ); } } diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 5ac23639a5c..62b68b7a3bc 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -117,7 +117,6 @@ void FxChannel::unmuteForSolo() void FxChannel::doProcessing() { const fpp_t fpp = Engine::mixer()->framesPerPeriod(); - const bool exporting = Engine::getSong()->isExporting(); if( m_muted == false ) { @@ -140,25 +139,21 @@ void FxChannel::doProcessing() if( ! volBuf && ! sendBuf ) // neither volume nor send has sample-exact data... { const float v = sender->m_volumeModel.value() * sendModel->value(); - if( exporting ) { MixHelpers::addSanitizedMultiplied( m_buffer, ch_buf, v, fpp ); } - else { MixHelpers::addMultiplied( m_buffer, ch_buf, v, fpp ); } + MixHelpers::addSanitizedMultiplied( m_buffer, ch_buf, v, fpp ); } else if( volBuf && sendBuf ) // both volume and send have sample-exact data { - if( exporting ) { MixHelpers::addSanitizedMultipliedByBuffers( m_buffer, ch_buf, volBuf, sendBuf, fpp ); } - else { MixHelpers::addMultipliedByBuffers( m_buffer, ch_buf, volBuf, sendBuf, fpp ); } + MixHelpers::addSanitizedMultipliedByBuffers( m_buffer, ch_buf, volBuf, sendBuf, fpp ); } else if( volBuf ) // volume has sample-exact data but send does not { const float v = sendModel->value(); - if( exporting ) { MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, volBuf, fpp ); } - else { MixHelpers::addMultipliedByBuffer( m_buffer, ch_buf, v, volBuf, fpp ); } + MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, volBuf, fpp ); } else // vice versa { const float v = sender->m_volumeModel.value(); - if( exporting ) { MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, sendBuf, fpp ); } - else { MixHelpers::addMultipliedByBuffer( m_buffer, ch_buf, v, sendBuf, fpp ); } + MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, sendBuf, fpp ); } m_hasInput = true; } diff --git a/src/core/MixHelpers.cpp b/src/core/MixHelpers.cpp index 001aa05ccae..60fa778afa8 100644 --- a/src/core/MixHelpers.cpp +++ b/src/core/MixHelpers.cpp @@ -82,6 +82,10 @@ bool sanitize( sampleFrame * src, int frames ) src[f][c] = 0.0f; found = true; } + else + { + src[f][c] = qBound( -4.0f, src[f][c], 4.0f ); + } } } return found;