1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
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.
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
22 FiltFilt::FiltFilt( FiltFiltConfig Config )
24 m_filtScratchIn = NULL;
25 m_filtScratchOut = NULL;
36 void FiltFilt::initialise( FiltFiltConfig Config )
39 m_filterConfig.ord = Config.ord;
40 m_filterConfig.ACoeffs = Config.ACoeffs;
41 m_filterConfig.BCoeffs = Config.BCoeffs;
43 m_filter = new Filter( m_filterConfig );
46 void FiltFilt::deInitialise()
52 void FiltFilt::process(double *src, double *dst, unsigned int length)
56 if (length == 0) return;
58 unsigned int nFilt = m_ord + 1;
59 unsigned int nFact = 3 * ( nFilt - 1);
60 unsigned int nExt = length + 2 * nFact;
62 m_filtScratchIn = new double[ nExt ];
63 m_filtScratchOut = new double[ nExt ];
66 for( i = 0; i< nExt; i++ )
68 m_filtScratchIn[ i ] = 0.0;
69 m_filtScratchOut[ i ] = 0.0;
72 // Edge transients reflection
73 double sample0 = 2 * src[ 0 ];
74 double sampleN = 2 * src[ length - 1 ];
76 unsigned int index = 0;
77 for( i = nFact; i > 0; i-- )
79 m_filtScratchIn[ index++ ] = sample0 - src[ i ];
82 for( i = 0; i < nFact; i++ )
84 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
88 for( i = 0; i < length; i++ )
90 m_filtScratchIn[ i + nFact ] = src[ i ];
93 ////////////////////////////////
95 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
97 // reverse the series for FILTFILT
98 for ( i = 0; i < nExt; i++)
100 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
104 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
106 // reverse the series back
107 for ( i = 0; i < nExt; i++)
109 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
111 for ( i = 0;i < nExt; i++)
113 m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
117 for( i = 0; i < length; i++ )
119 dst[ index++ ] = m_filtScratchOut[ i + nFact ];
122 delete [] m_filtScratchIn;
123 delete [] m_filtScratchOut;
127 void FiltFilt::reset()