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(Filter::Parameters parameters) :
25 m_ord = m_filter.getOrder();
32 void FiltFilt::process(double *src, double *dst, unsigned int length)
36 if (length == 0) return;
39 for( i = 0; i < length; i++ ) {
45 unsigned int nFilt = m_ord + 1;
46 unsigned int nFact = 3 * ( nFilt - 1);
47 unsigned int nExt = length + 2 * nFact;
49 double *filtScratchIn = new double[ nExt ];
50 double *filtScratchOut = new double[ nExt ];
52 for( i = 0; i< nExt; i++ )
54 filtScratchIn[ i ] = 0.0;
55 filtScratchOut[ i ] = 0.0;
58 // Edge transients reflection
59 double sample0 = 2 * src[ 0 ];
60 double sampleN = 2 * src[ length - 1 ];
62 unsigned int index = 0;
63 for( i = nFact; i > 0; i-- )
65 filtScratchIn[ index++ ] = sample0 - src[ i ];
68 for( i = 0; i < nFact && i + 2 < length; i++ )
70 filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
73 for(; i < nFact; i++ )
75 filtScratchIn[ (nExt - nFact) + index++ ] = 0;
79 for( i = 0; i < length; i++ )
81 filtScratchIn[ i + nFact ] = src[ i ];
84 ////////////////////////////////
86 m_filter.process( filtScratchIn, filtScratchOut, nExt);
88 // reverse the series for FILTFILT
89 for ( i = 0; i < nExt; i++)
91 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1];
95 m_filter.process( filtScratchIn, filtScratchOut, nExt);
97 // reverse the series back
98 for ( i = 0; i < nExt; i++)
100 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ];
102 for ( i = 0;i < nExt; i++)
104 filtScratchOut[ i ] = filtScratchIn[ i ];
108 for( i = 0; i < length; i++ )
110 dst[ index++ ] = filtScratchOut[ i + nFact ];
113 delete [] filtScratchIn;
114 delete [] filtScratchOut;
118 void FiltFilt::reset()