annotate dsp/signalconditioning/FiltFilt.cpp @ 96:88f3cfcff55f

A threshold (delta) is added in the peak picking parameters structure (PPickParams). It is used as an offset when computing the smoothed detection function. A constructor for the structure PPickParams is also added to set the parameters to 0 when a structure instance is created. Hence programmes using the peak picking parameter structure and which do not set the delta parameter (e.g. QM Vamp note onset detector) won't be affected by the modifications. Functions modified: - dsp/onsets/PeakPicking.cpp - dsp/onsets/PeakPicking.h - dsp/signalconditioning/DFProcess.cpp - dsp/signalconditioning/DFProcess.h
author mathieub <mathieu.barthet@eecs.qmul.ac.uk>
date Mon, 20 Jun 2011 19:01:48 +0100
parents e5907ae6de17
children 715f779d0b4f
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 QM DSP Library
cannam@0 5
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@84 7 This file 2005-2006 Christian Landone.
Chris@84 8
Chris@84 9 This program is free software; you can redistribute it and/or
Chris@84 10 modify it under the terms of the GNU General Public License as
Chris@84 11 published by the Free Software Foundation; either version 2 of the
Chris@84 12 License, or (at your option) any later version. See the file
Chris@84 13 COPYING included with this distribution for more information.
cannam@0 14 */
cannam@0 15
cannam@0 16 #include "FiltFilt.h"
cannam@0 17
cannam@0 18 //////////////////////////////////////////////////////////////////////
cannam@0 19 // Construction/Destruction
cannam@0 20 //////////////////////////////////////////////////////////////////////
cannam@0 21
cannam@0 22 FiltFilt::FiltFilt( FiltFiltConfig Config )
cannam@0 23 {
cannam@0 24 m_filtScratchIn = NULL;
cannam@0 25 m_filtScratchOut = NULL;
cannam@0 26 m_ord = 0;
cannam@0 27
cannam@0 28 initialise( Config );
cannam@0 29 }
cannam@0 30
cannam@0 31 FiltFilt::~FiltFilt()
cannam@0 32 {
cannam@0 33 deInitialise();
cannam@0 34 }
cannam@0 35
cannam@0 36 void FiltFilt::initialise( FiltFiltConfig Config )
cannam@0 37 {
cannam@0 38 m_ord = Config.ord;
cannam@0 39 m_filterConfig.ord = Config.ord;
cannam@0 40 m_filterConfig.ACoeffs = Config.ACoeffs;
cannam@0 41 m_filterConfig.BCoeffs = Config.BCoeffs;
cannam@0 42
cannam@0 43 m_filter = new Filter( m_filterConfig );
cannam@0 44 }
cannam@0 45
cannam@0 46 void FiltFilt::deInitialise()
cannam@0 47 {
cannam@0 48 delete m_filter;
cannam@0 49 }
cannam@0 50
cannam@0 51
cannam@0 52 void FiltFilt::process(double *src, double *dst, unsigned int length)
cannam@0 53 {
cannam@0 54 unsigned int i;
cannam@0 55
cannam@58 56 if (length == 0) return;
cannam@58 57
cannam@0 58 unsigned int nFilt = m_ord + 1;
cannam@0 59 unsigned int nFact = 3 * ( nFilt - 1);
cannam@0 60 unsigned int nExt = length + 2 * nFact;
cannam@0 61
cannam@0 62 m_filtScratchIn = new double[ nExt ];
cannam@0 63 m_filtScratchOut = new double[ nExt ];
cannam@0 64
cannam@0 65
cannam@0 66 for( i = 0; i< nExt; i++ )
cannam@0 67 {
cannam@0 68 m_filtScratchIn[ i ] = 0.0;
cannam@0 69 m_filtScratchOut[ i ] = 0.0;
cannam@0 70 }
cannam@0 71
cannam@0 72 // Edge transients reflection
cannam@0 73 double sample0 = 2 * src[ 0 ];
cannam@0 74 double sampleN = 2 * src[ length - 1 ];
cannam@0 75
cannam@0 76 unsigned int index = 0;
cannam@0 77 for( i = nFact; i > 0; i-- )
cannam@0 78 {
cannam@0 79 m_filtScratchIn[ index++ ] = sample0 - src[ i ];
cannam@0 80 }
cannam@0 81 index = 0;
cannam@0 82 for( i = 0; i < nFact; i++ )
cannam@0 83 {
cannam@0 84 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
cannam@0 85 }
cannam@0 86
cannam@0 87 index = 0;
cannam@0 88 for( i = 0; i < length; i++ )
cannam@0 89 {
cannam@0 90 m_filtScratchIn[ i + nFact ] = src[ i ];
cannam@0 91 }
cannam@0 92
cannam@0 93 ////////////////////////////////
cannam@0 94 // Do 0Ph filtering
cannam@0 95 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
cannam@0 96
cannam@0 97 // reverse the series for FILTFILT
cannam@0 98 for ( i = 0; i < nExt; i++)
cannam@0 99 {
cannam@0 100 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
cannam@0 101 }
cannam@0 102
cannam@0 103 // do FILTER again
cannam@0 104 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
cannam@0 105
cannam@0 106 // reverse the series back
cannam@0 107 for ( i = 0; i < nExt; i++)
cannam@0 108 {
cannam@0 109 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
cannam@0 110 }
cannam@0 111 for ( i = 0;i < nExt; i++)
cannam@0 112 {
cannam@0 113 m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
cannam@0 114 }
cannam@0 115
cannam@0 116 index = 0;
cannam@0 117 for( i = 0; i < length; i++ )
cannam@0 118 {
cannam@0 119 dst[ index++ ] = m_filtScratchOut[ i + nFact ];
cannam@0 120 }
cannam@0 121
cannam@0 122 delete [] m_filtScratchIn;
cannam@0 123 delete [] m_filtScratchOut;
cannam@0 124
cannam@0 125 }
cannam@0 126
cannam@0 127 void FiltFilt::reset()
cannam@0 128 {
cannam@0 129
cannam@0 130 }