Skip to content

Commit

Permalink
Allways remove infs/nans (LMMS#3706)
Browse files Browse the repository at this point in the history
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: LMMS#1048
  • Loading branch information
zonkmachine authored Apr 15, 2018
1 parent e554a4c commit 07a23c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
12 changes: 3 additions & 9 deletions src/core/EffectChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,16 @@ 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 )
{
if( hasInputNoise || ( *it )->isRunning() )
{
moreEffects |= ( *it )->processAudioBuffer( _buf, _frames );
if( exporting ) // strip infs/nans if exporting
{
MixHelpers::sanitize( _buf, _frames );
}
MixHelpers::sanitize( _buf, _frames );
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/core/FxMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/MixHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 07a23c4

Please sign in to comment.