c@225
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@225
|
2
|
c@225
|
3 /*
|
c@225
|
4 QM DSP Library
|
c@225
|
5
|
c@225
|
6 Centre for Digital Music, Queen Mary, University of London.
|
c@309
|
7 This file 2005-2006 Christian Landone.
|
c@309
|
8
|
c@309
|
9 This program is free software; you can redistribute it and/or
|
c@309
|
10 modify it under the terms of the GNU General Public License as
|
c@309
|
11 published by the Free Software Foundation; either version 2 of the
|
c@309
|
12 License, or (at your option) any later version. See the file
|
c@309
|
13 COPYING included with this distribution for more information.
|
c@225
|
14 */
|
c@225
|
15
|
c@225
|
16 #include "Filter.h"
|
c@225
|
17
|
c@225
|
18 //////////////////////////////////////////////////////////////////////
|
c@225
|
19 // Construction/Destruction
|
c@225
|
20 //////////////////////////////////////////////////////////////////////
|
c@225
|
21
|
c@225
|
22 Filter::Filter( FilterConfig Config )
|
c@225
|
23 {
|
c@225
|
24 m_ord = 0;
|
c@225
|
25 m_outBuffer = NULL;
|
c@225
|
26 m_inBuffer = NULL;
|
c@225
|
27
|
c@225
|
28 initialise( Config );
|
c@225
|
29 }
|
c@225
|
30
|
c@225
|
31 Filter::~Filter()
|
c@225
|
32 {
|
c@225
|
33 deInitialise();
|
c@225
|
34 }
|
c@225
|
35
|
c@225
|
36 void Filter::initialise( FilterConfig Config )
|
c@225
|
37 {
|
c@225
|
38 m_ord = Config.ord;
|
c@225
|
39 m_ACoeffs = Config.ACoeffs;
|
c@225
|
40 m_BCoeffs = Config.BCoeffs;
|
c@225
|
41
|
c@225
|
42 m_inBuffer = new double[ m_ord + 1 ];
|
c@225
|
43 m_outBuffer = new double[ m_ord + 1 ];
|
c@225
|
44
|
c@225
|
45 reset();
|
c@225
|
46 }
|
c@225
|
47
|
c@225
|
48 void Filter::deInitialise()
|
c@225
|
49 {
|
c@225
|
50 delete[] m_inBuffer;
|
c@225
|
51 delete[] m_outBuffer;
|
c@225
|
52 }
|
c@225
|
53
|
c@225
|
54 void Filter::reset()
|
c@225
|
55 {
|
c@225
|
56 for( unsigned int i = 0; i < m_ord+1; i++ ){ m_inBuffer[ i ] = 0.0; }
|
c@225
|
57 for(unsigned int i = 0; i < m_ord+1; i++ ){ m_outBuffer[ i ] = 0.0; }
|
c@225
|
58 }
|
c@225
|
59
|
c@225
|
60 void Filter::process( double *src, double *dst, unsigned int length )
|
c@225
|
61 {
|
c@225
|
62 unsigned int SP,i,j;
|
c@225
|
63
|
c@225
|
64 double xin,xout;
|
c@225
|
65
|
c@225
|
66 for (SP=0;SP<length;SP++)
|
c@225
|
67 {
|
c@225
|
68 xin=src[SP];
|
c@225
|
69 /* move buffer */
|
c@225
|
70 for ( i = 0; i < m_ord; i++) {m_inBuffer[ m_ord - i ]=m_inBuffer[ m_ord - i - 1 ];}
|
c@225
|
71 m_inBuffer[0]=xin;
|
c@225
|
72
|
c@225
|
73 xout=0.0;
|
c@225
|
74 for (j=0;j< m_ord + 1; j++)
|
c@225
|
75 xout = xout + m_BCoeffs[ j ] * m_inBuffer[ j ];
|
c@225
|
76 for (j = 0; j < m_ord; j++)
|
c@225
|
77 xout= xout - m_ACoeffs[ j + 1 ] * m_outBuffer[ j ];
|
c@225
|
78
|
c@225
|
79 dst[ SP ] = xout;
|
c@225
|
80 for ( i = 0; i < m_ord - 1; i++ ) { m_outBuffer[ m_ord - i - 1 ] = m_outBuffer[ m_ord - i - 2 ];}
|
c@225
|
81 m_outBuffer[0]=xout;
|
c@225
|
82
|
c@225
|
83 } /* end of SP loop */
|
c@225
|
84 }
|
c@225
|
85
|
c@225
|
86
|
c@225
|
87
|