annotate dsp/signalconditioning/FiltFilt.cpp @ 283:5e125f030287

* Fixes to problems shown up by vamp-plugin-tester. Still not all plugins pass all tests, though
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 23 Mar 2009 16:28:53 +0000
parents 49844bc8a895
children e5907ae6de17
rev   line source
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@225 7 This file copyright 2005-2006 Christian Landone.
c@225 8 All rights reserved.
c@225 9 */
c@225 10
c@225 11 #include "FiltFilt.h"
c@225 12
c@225 13 //////////////////////////////////////////////////////////////////////
c@225 14 // Construction/Destruction
c@225 15 //////////////////////////////////////////////////////////////////////
c@225 16
c@225 17 FiltFilt::FiltFilt( FiltFiltConfig Config )
c@225 18 {
c@225 19 m_filtScratchIn = NULL;
c@225 20 m_filtScratchOut = NULL;
c@225 21 m_ord = 0;
c@225 22
c@225 23 initialise( Config );
c@225 24 }
c@225 25
c@225 26 FiltFilt::~FiltFilt()
c@225 27 {
c@225 28 deInitialise();
c@225 29 }
c@225 30
c@225 31 void FiltFilt::initialise( FiltFiltConfig Config )
c@225 32 {
c@225 33 m_ord = Config.ord;
c@225 34 m_filterConfig.ord = Config.ord;
c@225 35 m_filterConfig.ACoeffs = Config.ACoeffs;
c@225 36 m_filterConfig.BCoeffs = Config.BCoeffs;
c@225 37
c@225 38 m_filter = new Filter( m_filterConfig );
c@225 39 }
c@225 40
c@225 41 void FiltFilt::deInitialise()
c@225 42 {
c@225 43 delete m_filter;
c@225 44 }
c@225 45
c@225 46
c@225 47 void FiltFilt::process(double *src, double *dst, unsigned int length)
c@225 48 {
c@225 49 unsigned int i;
c@225 50
c@283 51 if (length == 0) return;
c@283 52
c@225 53 unsigned int nFilt = m_ord + 1;
c@225 54 unsigned int nFact = 3 * ( nFilt - 1);
c@225 55 unsigned int nExt = length + 2 * nFact;
c@225 56
c@225 57 m_filtScratchIn = new double[ nExt ];
c@225 58 m_filtScratchOut = new double[ nExt ];
c@225 59
c@225 60
c@225 61 for( i = 0; i< nExt; i++ )
c@225 62 {
c@225 63 m_filtScratchIn[ i ] = 0.0;
c@225 64 m_filtScratchOut[ i ] = 0.0;
c@225 65 }
c@225 66
c@225 67 // Edge transients reflection
c@225 68 double sample0 = 2 * src[ 0 ];
c@225 69 double sampleN = 2 * src[ length - 1 ];
c@225 70
c@225 71 unsigned int index = 0;
c@225 72 for( i = nFact; i > 0; i-- )
c@225 73 {
c@225 74 m_filtScratchIn[ index++ ] = sample0 - src[ i ];
c@225 75 }
c@225 76 index = 0;
c@225 77 for( i = 0; i < nFact; i++ )
c@225 78 {
c@225 79 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
c@225 80 }
c@225 81
c@225 82 index = 0;
c@225 83 for( i = 0; i < length; i++ )
c@225 84 {
c@225 85 m_filtScratchIn[ i + nFact ] = src[ i ];
c@225 86 }
c@225 87
c@225 88 ////////////////////////////////
c@225 89 // Do 0Ph filtering
c@225 90 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
c@225 91
c@225 92 // reverse the series for FILTFILT
c@225 93 for ( i = 0; i < nExt; i++)
c@225 94 {
c@225 95 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
c@225 96 }
c@225 97
c@225 98 // do FILTER again
c@225 99 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
c@225 100
c@225 101 // reverse the series back
c@225 102 for ( i = 0; i < nExt; i++)
c@225 103 {
c@225 104 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
c@225 105 }
c@225 106 for ( i = 0;i < nExt; i++)
c@225 107 {
c@225 108 m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
c@225 109 }
c@225 110
c@225 111 index = 0;
c@225 112 for( i = 0; i < length; i++ )
c@225 113 {
c@225 114 dst[ index++ ] = m_filtScratchOut[ i + nFact ];
c@225 115 }
c@225 116
c@225 117 delete [] m_filtScratchIn;
c@225 118 delete [] m_filtScratchOut;
c@225 119
c@225 120 }
c@225 121
c@225 122 void FiltFilt::reset()
c@225 123 {
c@225 124
c@225 125 }