Dual Filter fix: make more efficient - don't calculate coefficients unnecessarily

This commit is contained in:
Vesa
2014-03-19 03:19:02 +02:00
parent 547e6dcc95
commit 0b46aa4506
4 changed files with 49 additions and 20 deletions

View File

@@ -55,6 +55,10 @@ DualFilterEffect::DualFilterEffect( Model* parent, const Descriptor::SubPluginFe
{
m_filter1 = new basicFilters<2>( engine::mixer()->processingSampleRate() );
m_filter2 = new basicFilters<2>( engine::mixer()->processingSampleRate() );
// ensure filters get updated
m_filter1changed = true;
m_filter2changed = true;
}
@@ -82,10 +86,23 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
m_filter1->setFilterType( m_dfControls.m_filter1Model.value() );
m_filter2->setFilterType( m_dfControls.m_filter2Model.value() );
const bool enabled1 = m_dfControls.m_enabled1Model.value();
const bool enabled2 = m_dfControls.m_enabled2Model.value();
if( m_dfControls.m_enabled1Model.value() ) m_filter1->calcFilterCoeffs( m_dfControls.m_cut1Model.value(), m_dfControls.m_res1Model.value() );
if( m_dfControls.m_enabled2Model.value() ) m_filter2->calcFilterCoeffs( m_dfControls.m_cut2Model.value(), m_dfControls.m_res2Model.value() );
// recalculate only when necessary
if( enabled1 && m_filter1changed )
{
m_filter1->calcFilterCoeffs( m_dfControls.m_cut1Model.value(), m_dfControls.m_res1Model.value() );
m_filter1changed = false;
}
if( enabled2 && m_filter2changed )
{
m_filter2->calcFilterCoeffs( m_dfControls.m_cut2Model.value(), m_dfControls.m_res2Model.value() );
m_filter2changed = false;
}
// buffer processing loop
for( fpp_t f = 0; f < frames; ++f )
{
@@ -98,7 +115,7 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
const float mix2 = ( ( m_dfControls.m_mixModel.value( f ) + 1.0f ) / 2.0f );
// update filter 1
if( m_dfControls.m_enabled1Model.value() )
if( enabled1 )
{
s1[0] = m_filter1->update( s1[0], 0 );
s1[1] = m_filter1->update( s1[1], 1 );
@@ -113,7 +130,7 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
}
// update filter 2
if( m_dfControls.m_enabled2Model.value() )
if( enabled2 )
{
s2[0] = m_filter2->update( s2[0], 0 );
s2[1] = m_filter2->update( s2[1], 1 );
@@ -140,6 +157,8 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
extern "C"
{

View File

@@ -43,11 +43,15 @@ public:
return &m_dfControls;
}
private:
DualFilterControls m_dfControls;
basicFilters<2> * m_filter1;
basicFilters<2> * m_filter2;
bool m_filter1changed;
bool m_filter2changed;
friend class DualFilterControls;

View File

@@ -51,19 +51,13 @@ DualFilterControls::DualFilterControls( DualFilterEffect* effect ) :
m_res2Model( 0.5, basicFilters<0>::minQ(), 10.0, 0.01, this, tr( "Q/Resonance 2" ) ),
m_gain2Model( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Gain 2" ) )
{
connect( &m_enabled1Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_filter1Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_cut1Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_res1Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_gain1Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_filter1Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter1() ) );
connect( &m_cut1Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter1() ) );
connect( &m_res1Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter1() ) );
connect( &m_mixModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_enabled2Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_filter2Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_cut2Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_res2Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_gain2Model, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_filter2Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter2() ) );
connect( &m_cut2Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter2() ) );
connect( &m_res2Model, SIGNAL( dataChanged() ), this, SLOT( updateFilter2() ) );
m_filter1Model.addItem( tr( "LowPass" ), new PixmapLoader( "filter_lp" ) );
m_filter1Model.addItem( tr( "HiPass" ), new PixmapLoader( "filter_hp" ) );
@@ -102,19 +96,30 @@ DualFilterControls::DualFilterControls( DualFilterEffect* effect ) :
void DualFilterControls::changeControl()
void DualFilterControls::updateFilter1()
{
engine::getSong()->setModified();
m_effect->m_filter1changed = true;
}
void DualFilterControls::updateFilter2()
{
m_effect->m_filter2changed = true;
}
void DualFilterControls::updateFilters()
{
// swap filters to new ones
delete m_effect->m_filter1;
delete m_effect->m_filter2;
m_effect->m_filter1 = new basicFilters<2>( engine::mixer()->processingSampleRate() );
m_effect->m_filter2 = new basicFilters<2>( engine::mixer()->processingSampleRate() );
// flag filters as needing recalculation
updateFilter1();
updateFilter2();
}

View File

@@ -62,7 +62,8 @@ public:
private slots:
void changeControl();
void updateFilter1();
void updateFilter2();
void updateFilters();
private: