Separate BiQuad, OnePole filters as their own classes in BasicFilters.h

Might do the same for other filter types, but these two are kind of "basic building blocks" for many effects so it makes most sense for them
This commit is contained in:
Vesa
2014-11-30 14:33:04 +02:00
parent 920064fef9
commit be04040ae8
3 changed files with 125 additions and 74 deletions

View File

@@ -53,7 +53,7 @@ MultitapEchoEffect::MultitapEchoEffect( Model* parent, const Descriptor::SubPlug
m_sampleRate( Engine::mixer()->processingSampleRate() ),
m_sampleRatio( 1.0f / m_sampleRate )
{
m_work = new sampleFrame[ Engine::mixer()->framesPerPeriod() ];
m_work = MM_ALLOC( sampleFrame, Engine::mixer()->framesPerPeriod() );
m_buffer.reset();
updateFilters( 0, 19 );
}
@@ -61,16 +61,15 @@ MultitapEchoEffect::MultitapEchoEffect( Model* parent, const Descriptor::SubPlug
MultitapEchoEffect::~MultitapEchoEffect()
{
delete m_work;
MM_FREE( m_work );
}
void MultitapEchoEffect::updateFilters( int begin, int end )
{
for( int i = begin; i <= end; ++i )
{
m_filter[i][0].setFc( m_lpFreq[i] * m_sampleRatio );
m_filter[i][1].setFc( m_lpFreq[i] * m_sampleRatio );
{
setFilterFreq( m_lpFreq[i] * m_sampleRatio, m_filter[i] );
}
}
@@ -79,8 +78,8 @@ void MultitapEchoEffect::runFilter( sampleFrame * dst, sampleFrame * src, Stereo
{
for( int f = 0; f < frames; ++f )
{
dst[f][0] = filter[0].update( src[f][0] );
dst[f][1] = filter[1].update( src[f][1] );
dst[f][0] = filter.update( src[f][0], 0 );
dst[f][1] = filter.update( src[f][1], 1 );
}
}
@@ -119,7 +118,7 @@ bool MultitapEchoEffect::processAudioBuffer( sampleFrame * buf, const fpp_t fram
else
{
float offset = stepLength;
for( int i = 0; i < steps; ++i ) // add all steps swapped
for( int i = 0; i < steps; ++i ) // add all steps
{
runFilter( m_work, buf, m_filter[i], frames );
m_buffer.writeAddingMultiplied( m_work, offset, frames, m_amp[i] );

View File

@@ -31,34 +31,7 @@
#include "ValueBuffer.h"
#include "RingBuffer.h"
#include "lmms_math.h"
class OnePole
{
public:
OnePole()
{
m_a0 = 1.0;
m_b1 = 0.0;
m_z1 = 0.0;
}
virtual ~OnePole() {}
inline void setFc( float fc )
{
m_b1 = expf( -2.0f * F_PI * fc );
m_a0 = 1.0f - m_b1;
}
inline float update( float s )
{
return m_z1 = s * m_a0 + m_z1 * m_b1;
}
private:
float m_a0, m_b1, m_z1;
};
typedef OnePole StereoOnePole [2];
#include "BasicFilters.h"
class MultitapEchoEffect : public Effect
{
@@ -76,6 +49,12 @@ private:
void updateFilters( int begin, int end );
void runFilter( sampleFrame * dst, sampleFrame * src, StereoOnePole & filter, const fpp_t frames );
inline void setFilterFreq( float fc, StereoOnePole & f )
{
const float b1 = expf( -2.0f * F_PI * fc );
f.setCoeffs( 1.0f - b1, b1 );
}
MultitapEchoControls m_controls;
float m_amp [20];