annotate dsp/signalconditioning/FiltFilt.cpp @ 73:dcb555b90924

* Key detector: when returning key strengths, use the peak value of the three underlying chromagram correlations (from 36-bin chromagram) corresponding to each key, instead of the mean. Rationale: This is the same method as used when returning the key value, and it's nice to have the same results in both returned value and plot. The peak performed better than the sum with a simple test set of triads, so it seems reasonable to change the plot to match the key output rather than the other way around. * FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest rather than leaving them (perhaps dangerously) undefined. Fixes an uninitialised data error in chromagram that could cause garbage results from key detector. * Constant Q: remove precalculated values again, I reckon they're not proving such a good tradeoff.
author cannam
date Fri, 05 Jun 2009 15:12:39 +0000
parents d72fcd34d9a7
children e5907ae6de17
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.
cannam@0 7 This file copyright 2005-2006 Christian Landone.
cannam@0 8 All rights reserved.
cannam@0 9 */
cannam@0 10
cannam@0 11 #include "FiltFilt.h"
cannam@0 12
cannam@0 13 //////////////////////////////////////////////////////////////////////
cannam@0 14 // Construction/Destruction
cannam@0 15 //////////////////////////////////////////////////////////////////////
cannam@0 16
cannam@0 17 FiltFilt::FiltFilt( FiltFiltConfig Config )
cannam@0 18 {
cannam@0 19 m_filtScratchIn = NULL;
cannam@0 20 m_filtScratchOut = NULL;
cannam@0 21 m_ord = 0;
cannam@0 22
cannam@0 23 initialise( Config );
cannam@0 24 }
cannam@0 25
cannam@0 26 FiltFilt::~FiltFilt()
cannam@0 27 {
cannam@0 28 deInitialise();
cannam@0 29 }
cannam@0 30
cannam@0 31 void FiltFilt::initialise( FiltFiltConfig Config )
cannam@0 32 {
cannam@0 33 m_ord = Config.ord;
cannam@0 34 m_filterConfig.ord = Config.ord;
cannam@0 35 m_filterConfig.ACoeffs = Config.ACoeffs;
cannam@0 36 m_filterConfig.BCoeffs = Config.BCoeffs;
cannam@0 37
cannam@0 38 m_filter = new Filter( m_filterConfig );
cannam@0 39 }
cannam@0 40
cannam@0 41 void FiltFilt::deInitialise()
cannam@0 42 {
cannam@0 43 delete m_filter;
cannam@0 44 }
cannam@0 45
cannam@0 46
cannam@0 47 void FiltFilt::process(double *src, double *dst, unsigned int length)
cannam@0 48 {
cannam@0 49 unsigned int i;
cannam@0 50
cannam@58 51 if (length == 0) return;
cannam@58 52
cannam@0 53 unsigned int nFilt = m_ord + 1;
cannam@0 54 unsigned int nFact = 3 * ( nFilt - 1);
cannam@0 55 unsigned int nExt = length + 2 * nFact;
cannam@0 56
cannam@0 57 m_filtScratchIn = new double[ nExt ];
cannam@0 58 m_filtScratchOut = new double[ nExt ];
cannam@0 59
cannam@0 60
cannam@0 61 for( i = 0; i< nExt; i++ )
cannam@0 62 {
cannam@0 63 m_filtScratchIn[ i ] = 0.0;
cannam@0 64 m_filtScratchOut[ i ] = 0.0;
cannam@0 65 }
cannam@0 66
cannam@0 67 // Edge transients reflection
cannam@0 68 double sample0 = 2 * src[ 0 ];
cannam@0 69 double sampleN = 2 * src[ length - 1 ];
cannam@0 70
cannam@0 71 unsigned int index = 0;
cannam@0 72 for( i = nFact; i > 0; i-- )
cannam@0 73 {
cannam@0 74 m_filtScratchIn[ index++ ] = sample0 - src[ i ];
cannam@0 75 }
cannam@0 76 index = 0;
cannam@0 77 for( i = 0; i < nFact; i++ )
cannam@0 78 {
cannam@0 79 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
cannam@0 80 }
cannam@0 81
cannam@0 82 index = 0;
cannam@0 83 for( i = 0; i < length; i++ )
cannam@0 84 {
cannam@0 85 m_filtScratchIn[ i + nFact ] = src[ i ];
cannam@0 86 }
cannam@0 87
cannam@0 88 ////////////////////////////////
cannam@0 89 // Do 0Ph filtering
cannam@0 90 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
cannam@0 91
cannam@0 92 // reverse the series for FILTFILT
cannam@0 93 for ( i = 0; i < nExt; i++)
cannam@0 94 {
cannam@0 95 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
cannam@0 96 }
cannam@0 97
cannam@0 98 // do FILTER again
cannam@0 99 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
cannam@0 100
cannam@0 101 // reverse the series back
cannam@0 102 for ( i = 0; i < nExt; i++)
cannam@0 103 {
cannam@0 104 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
cannam@0 105 }
cannam@0 106 for ( i = 0;i < nExt; i++)
cannam@0 107 {
cannam@0 108 m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
cannam@0 109 }
cannam@0 110
cannam@0 111 index = 0;
cannam@0 112 for( i = 0; i < length; i++ )
cannam@0 113 {
cannam@0 114 dst[ index++ ] = m_filtScratchOut[ i + nFact ];
cannam@0 115 }
cannam@0 116
cannam@0 117 delete [] m_filtScratchIn;
cannam@0 118 delete [] m_filtScratchOut;
cannam@0 119
cannam@0 120 }
cannam@0 121
cannam@0 122 void FiltFilt::reset()
cannam@0 123 {
cannam@0 124
cannam@0 125 }