add queen mary DSP library
[ardour2.git] / libs / qm-dsp / dsp / signalconditioning / Filter.cpp
blobfcc12e590ae670099df1317839b296f7ba41d316
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 /*
4 QM DSP Library
6 Centre for Digital Music, Queen Mary, University of London.
7 This file 2005-2006 Christian Landone.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
16 #include "Filter.h"
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
22 Filter::Filter( FilterConfig Config )
24 m_ord = 0;
25 m_outBuffer = NULL;
26 m_inBuffer = NULL;
28 initialise( Config );
31 Filter::~Filter()
33 deInitialise();
36 void Filter::initialise( FilterConfig Config )
38 m_ord = Config.ord;
39 m_ACoeffs = Config.ACoeffs;
40 m_BCoeffs = Config.BCoeffs;
42 m_inBuffer = new double[ m_ord + 1 ];
43 m_outBuffer = new double[ m_ord + 1 ];
45 reset();
48 void Filter::deInitialise()
50 delete[] m_inBuffer;
51 delete[] m_outBuffer;
54 void Filter::reset()
56 for( unsigned int i = 0; i < m_ord+1; i++ ){ m_inBuffer[ i ] = 0.0; }
57 for(unsigned int i = 0; i < m_ord+1; i++ ){ m_outBuffer[ i ] = 0.0; }
60 void Filter::process( double *src, double *dst, unsigned int length )
62 unsigned int SP,i,j;
64 double xin,xout;
66 for (SP=0;SP<length;SP++)
68 xin=src[SP];
69 /* move buffer */
70 for ( i = 0; i < m_ord; i++) {m_inBuffer[ m_ord - i ]=m_inBuffer[ m_ord - i - 1 ];}
71 m_inBuffer[0]=xin;
73 xout=0.0;
74 for (j=0;j< m_ord + 1; j++)
75 xout = xout + m_BCoeffs[ j ] * m_inBuffer[ j ];
76 for (j = 0; j < m_ord; j++)
77 xout= xout - m_ACoeffs[ j + 1 ] * m_outBuffer[ j ];
79 dst[ SP ] = xout;
80 for ( i = 0; i < m_ord - 1; i++ ) { m_outBuffer[ m_ord - i - 1 ] = m_outBuffer[ m_ord - i - 2 ];}
81 m_outBuffer[0]=xout;
83 } /* end of SP loop */