add 176.4kHz to export sample possibilities
[ardour.git] / libs / qm-dsp / dsp / signalconditioning / Filter.cpp
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     QM DSP Library
5
6     Centre for Digital Music, Queen Mary, University of London.
7     This file 2005-2006 Christian Landone.
8
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.
14 */
15
16 #include "Filter.h"
17
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
21
22 Filter::Filter( FilterConfig Config )
23 {
24     m_ord = 0;
25     m_outBuffer = NULL;
26     m_inBuffer = NULL;
27
28     initialise( Config );
29 }
30
31 Filter::~Filter()
32 {
33     deInitialise();
34 }
35
36 void Filter::initialise( FilterConfig Config )
37 {
38     m_ord = Config.ord;
39     m_ACoeffs = Config.ACoeffs;
40     m_BCoeffs = Config.BCoeffs;
41
42     m_inBuffer = new double[ m_ord + 1 ];
43     m_outBuffer = new double[ m_ord + 1 ];
44
45     reset();
46 }
47
48 void Filter::deInitialise()
49 {
50     delete[] m_inBuffer;
51     delete[] m_outBuffer;
52 }
53
54 void Filter::reset()
55 {
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; }
58 }
59
60 void Filter::process( double *src, double *dst, unsigned int length )
61 {
62     unsigned int SP,i,j;
63
64     double xin,xout;
65
66     for (SP=0;SP<length;SP++)
67     {
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;
72
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 ];
78
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;
82
83     } /* end of SP loop */
84 }
85
86
87