diff --git a/include/MixHelpers.h b/include/MixHelpers.h index 7f919aba1f3..872319f82df 100644 --- a/include/MixHelpers.h +++ b/include/MixHelpers.h @@ -33,6 +33,10 @@ namespace MixHelpers bool isSilent( const sampleFrame* src, int frames ); +bool useNaNHandler(); + +void setNaNHandler( bool use ); + bool sanitize( sampleFrame * src, int frames ); /*! \brief Add samples from src to dst */ diff --git a/include/SetupDialog.h b/include/SetupDialog.h index ebaa90f0151..338ea93dd77 100644 --- a/include/SetupDialog.h +++ b/include/SetupDialog.h @@ -142,6 +142,7 @@ private slots: bool m_MMPZ; bool m_disableBackup; bool m_openLastProject; + bool m_NaNHandler; bool m_hqAudioDev; QString m_lang; QStringList m_languages; diff --git a/src/core/MixHelpers.cpp b/src/core/MixHelpers.cpp index a1fcd155def..2addb48b593 100644 --- a/src/core/MixHelpers.cpp +++ b/src/core/MixHelpers.cpp @@ -27,6 +27,9 @@ #include "ValueBuffer.h" +static bool s_NaNHandler; + + namespace MixHelpers { @@ -68,10 +71,24 @@ bool isSilent( const sampleFrame* src, int frames ) return true; } +bool useNaNHandler() +{ + return s_NaNHandler; +} + +void setNaNHandler( bool use ) +{ + s_NaNHandler = use; +} /*! \brief Function for sanitizing a buffer of infs/nans - returns true if those are found */ bool sanitize( sampleFrame * src, int frames ) { + if( !useNaNHandler() ) + { + return false; + } + bool found = false; for( int f = 0; f < frames; ++f ) { @@ -179,6 +196,13 @@ void addMultipliedByBuffers( sampleFrame* dst, const sampleFrame* src, ValueBuff void addSanitizedMultipliedByBuffer( sampleFrame* dst, const sampleFrame* src, float coeffSrc, ValueBuffer * coeffSrcBuf, int frames ) { + if ( !useNaNHandler() ) + { + addMultipliedByBuffer( dst, src, coeffSrc, coeffSrcBuf, + frames ); + return; + } + for( int f = 0; f < frames; ++f ) { dst[f][0] += ( isinff( src[f][0] ) || isnanf( src[f][0] ) ) ? 0.0f : src[f][0] * coeffSrc * coeffSrcBuf->values()[f]; @@ -188,6 +212,13 @@ void addSanitizedMultipliedByBuffer( sampleFrame* dst, const sampleFrame* src, f void addSanitizedMultipliedByBuffers( sampleFrame* dst, const sampleFrame* src, ValueBuffer * coeffSrcBuf1, ValueBuffer * coeffSrcBuf2, int frames ) { + if ( !useNaNHandler() ) + { + addMultipliedByBuffers( dst, src, coeffSrcBuf1, coeffSrcBuf2, + frames ); + return; + } + for( int f = 0; f < frames; ++f ) { dst[f][0] += ( isinff( src[f][0] ) || isnanf( src[f][0] ) ) @@ -216,6 +247,12 @@ struct AddSanitizedMultipliedOp void addSanitizedMultiplied( sampleFrame* dst, const sampleFrame* src, float coeffSrc, int frames ) { + if ( !useNaNHandler() ) + { + addMultiplied( dst, src, coeffSrc, frames ); + return; + } + run<>( dst, src, frames, AddSanitizedMultipliedOp(coeffSrc) ); } diff --git a/src/core/main.cpp b/src/core/main.cpp index 4a6654a5d8f..45f2bb66be0 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -64,6 +64,7 @@ #include "GuiApplication.h" #include "ImportFilter.h" #include "MainWindow.h" +#include "MixHelpers.h" #include "OutputSettings.h" #include "ProjectRenderer.h" #include "RenderManager.h" @@ -633,6 +634,10 @@ int main( int argc, char * * argv ) ConfigManager::inst()->loadConfigFile(configFile); + // Hidden settings + MixHelpers::setNaNHandler( ConfigManager::inst()->value( "app", + "nanhandler", "1" ).toInt() ); + // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) diff --git a/src/gui/SetupDialog.cpp b/src/gui/SetupDialog.cpp index 1e5c7aa5f5e..4c261f58124 100644 --- a/src/gui/SetupDialog.cpp +++ b/src/gui/SetupDialog.cpp @@ -99,6 +99,8 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) : "disablebackup" ).toInt() ), m_openLastProject( ConfigManager::inst()->value( "app", "openlastproject" ).toInt() ), + m_NaNHandler( ConfigManager::inst()->value( "app", + "nanhandler", "1" ).toInt() ), m_hqAudioDev( ConfigManager::inst()->value( "mixer", "hqaudio" ).toInt() ), m_lang( ConfigManager::inst()->value( "app", @@ -334,6 +336,15 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) : misc_tw->setFixedHeight( YDelta*labelNumber + HeaderSize ); + // Advanced setting, hidden for now + if( false ) + { + LedCheckBox * useNaNHandler = new LedCheckBox( + tr( "Use built-in NaN handler" ), + misc_tw ); + useNaNHandler->setChecked( m_NaNHandler ); + } + TabWidget* embed_tw = new TabWidget( tr( "PLUGIN EMBEDDING" ), general); embed_tw->setFixedHeight( 48 ); m_vstEmbedComboBox = new QComboBox( embed_tw ); @@ -1055,6 +1066,8 @@ void SetupDialog::accept() QString::number( !m_disableBackup ) ); ConfigManager::inst()->setValue( "app", "openlastproject", QString::number( m_openLastProject ) ); + ConfigManager::inst()->setValue( "app", "nanhandler", + QString::number( m_NaNHandler ) ); ConfigManager::inst()->setValue( "mixer", "hqaudio", QString::number( m_hqAudioDev ) ); ConfigManager::inst()->setValue( "ui", "smoothscroll",