From 7d5250b93aca57640beb31999d073d130ee05284 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 26 Apr 2014 06:16:51 +0300 Subject: [PATCH 1/2] FxMixer: turn off effects --- include/FxMixer.h | 2 ++ src/core/FxMixer.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/FxMixer.h b/include/FxMixer.h index 8ff396cc6..7cecb7803 100644 --- a/include/FxMixer.h +++ b/include/FxMixer.h @@ -42,6 +42,8 @@ class FxChannel : public ThreadableJob EffectChain m_fxChain; + // set to true when input fed from mixToChannel or child channel + bool m_hasInput; // set to true if any effect in the channel is enabled and running bool m_stillRunning; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 669a2de4e..52781099e 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -36,6 +36,7 @@ FxChannel::FxChannel( int idx, Model * _parent ) : m_fxChain( NULL ), + m_hasInput( false ), m_stillRunning( false ), m_peakLeft( 0.0f ), m_peakRight( 0.0f ), @@ -112,13 +113,23 @@ void FxChannel::doProcessing( sampleFrame * _buf ) _buf[f][0] += ch_buf[f][0] * v; _buf[f][1] += ch_buf[f][1] * v; } + + // if sender channel hasInput, then we hasInput too + if( sender->m_hasInput ) m_hasInput = true; } } const float v = m_volumeModel.value(); - m_fxChain.startRunning(); - m_stillRunning = m_fxChain.processAudioBuffer( _buf, fpp, true ); + if( m_hasInput ) + { + // only start fxchain when we have input... + m_fxChain.startRunning(); + } + if( m_hasInput || m_stillRunning ) + { + m_stillRunning = m_fxChain.processAudioBuffer( _buf, fpp, m_hasInput ); + } m_peakLeft = qMax( m_peakLeft, engine::mixer()->peakValueLeft( _buf, fpp ) * v ); m_peakRight = qMax( m_peakRight, engine::mixer()->peakValueRight( _buf, fpp ) * v ); } @@ -420,6 +431,7 @@ void FxMixer::mixToChannel( const sampleFrame * _buf, fx_ch_t _ch ) { m_fxChannels[_ch]->m_lock.lock(); MixHelpers::add( m_fxChannels[_ch]->m_buffer, _buf, engine::mixer()->framesPerPeriod() ); + m_fxChannels[_ch]->m_hasInput = true; m_fxChannels[_ch]->m_lock.unlock(); } } @@ -486,6 +498,8 @@ void FxMixer::masterMix( sampleFrame * _buf ) engine::mixer()->clearAudioBuffer( m_fxChannels[i]->m_buffer, engine::mixer()->framesPerPeriod() ); m_fxChannels[i]->reset(); m_fxChannels[i]->m_queued = false; + // also reset hasInput + m_fxChannels[i]->m_hasInput = false; } } From 0f37bd13eed37ee2ce9b0f860d3feae39dee4a54 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 26 Apr 2014 07:30:23 +0300 Subject: [PATCH 2/2] FxMixer - Further optimization: skip copying buffers if we know the sender has no meaningful input to copy --- src/core/FxMixer.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 52781099e..d2c79a972 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -101,17 +101,20 @@ void FxChannel::doProcessing( sampleFrame * _buf ) sender->process(); } - // get the send level... - const float amt = - fxm->channelSendModel( senderIndex, m_channelIndex )->value(); - - // mix it's output with this one's output - sampleFrame * ch_buf = sender->m_buffer; - const float v = sender->m_volumeModel.value() * amt; - for( f_cnt_t f = 0; f < fpp; ++f ) + if( sender->m_hasInput || sender->m_stillRunning ) { - _buf[f][0] += ch_buf[f][0] * v; - _buf[f][1] += ch_buf[f][1] * v; + // get the send level... + const float amt = + fxm->channelSendModel( senderIndex, m_channelIndex )->value(); + + // mix it's output with this one's output + sampleFrame * ch_buf = sender->m_buffer; + const float v = sender->m_volumeModel.value() * amt; + for( f_cnt_t f = 0; f < fpp; ++f ) + { + _buf[f][0] += ch_buf[f][0] * v; + _buf[f][1] += ch_buf[f][1] * v; + } } // if sender channel hasInput, then we hasInput too