annotate dsp/signalconditioning/DFProcess.cpp @ 298:255e431ae3d4

* 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 Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 05 Jun 2009 15:12:39 +0000
parents 5e125f030287
children 769da847732b
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 "DFProcess.h"
c@241 12 #include "maths/MathUtilities.h"
c@225 13
c@272 14 #include <cstring>
c@272 15
c@225 16 //////////////////////////////////////////////////////////////////////
c@225 17 // Construction/Destruction
c@225 18 //////////////////////////////////////////////////////////////////////
c@225 19
c@225 20 DFProcess::DFProcess( DFProcConfig Config )
c@225 21 {
c@225 22 filtSrc = NULL;
c@225 23 filtDst = NULL;
c@225 24 m_filtScratchIn = NULL;
c@225 25 m_filtScratchOut = NULL;
c@225 26
c@225 27 m_FFOrd = 0;
c@225 28
c@225 29 initialise( Config );
c@225 30 }
c@225 31
c@225 32 DFProcess::~DFProcess()
c@225 33 {
c@225 34 deInitialise();
c@225 35 }
c@225 36
c@225 37 void DFProcess::initialise( DFProcConfig Config )
c@225 38 {
c@225 39 m_length = Config.length;
c@225 40 m_winPre = Config.winPre;
c@225 41 m_winPost = Config.winPost;
c@225 42 m_alphaNormParam = Config.AlphaNormParam;
c@225 43
c@225 44 m_isMedianPositive = Config.isMedianPositive;
c@225 45
c@225 46 filtSrc = new double[ m_length ];
c@225 47 filtDst = new double[ m_length ];
c@225 48
c@225 49
c@225 50 //Low Pass Smoothing Filter Config
c@225 51 m_FilterConfigParams.ord = Config.LPOrd;
c@225 52 m_FilterConfigParams.ACoeffs = Config.LPACoeffs;
c@225 53 m_FilterConfigParams.BCoeffs = Config.LPBCoeffs;
c@225 54
c@225 55 m_FiltFilt = new FiltFilt( m_FilterConfigParams );
c@225 56 }
c@225 57
c@225 58 void DFProcess::deInitialise()
c@225 59 {
c@225 60 delete [] filtSrc;
c@225 61
c@225 62 delete [] filtDst;
c@225 63
c@225 64 delete [] m_filtScratchIn;
c@225 65
c@225 66 delete [] m_filtScratchOut;
c@225 67
c@225 68 delete m_FiltFilt;
c@225 69 }
c@225 70
c@225 71 void DFProcess::process(double *src, double* dst)
c@225 72 {
c@283 73 if (m_length == 0) return;
c@283 74
c@225 75 removeDCNormalize( src, filtSrc );
c@225 76
c@225 77 m_FiltFilt->process( filtSrc, filtDst, m_length );
c@225 78
c@225 79 medianFilter( filtDst, dst );
c@225 80 }
c@225 81
c@225 82
c@225 83 void DFProcess::medianFilter(double *src, double *dst)
c@225 84 {
c@225 85 unsigned int i,k,j,l;
c@225 86 unsigned int index = 0;
c@225 87
c@225 88 double val = 0;
c@225 89
c@225 90 double* y = new double[ m_winPost + m_winPre + 1];
c@225 91 memset( y, 0, sizeof( double ) * ( m_winPost + m_winPre + 1) );
c@225 92
c@225 93 double* scratch = new double[ m_length ];
c@225 94
c@225 95 for( i = 0; i < m_winPre; i++)
c@225 96 {
c@225 97 k = i + m_winPost + 1;
c@225 98
c@225 99 for( j = 0; j < k; j++)
c@225 100 {
c@225 101 y[ j ] = src[ j ];
c@225 102 }
c@225 103 scratch[ index ] = MathUtilities::median( y, k );
c@225 104 index++;
c@225 105 }
c@225 106
c@225 107 for( i = 0; i < ( m_length - ( m_winPost + m_winPre ) ); i ++)
c@225 108 {
c@225 109
c@225 110 l = 0;
c@225 111 for( j = i; j < ( i + m_winPost + m_winPre + 1); j++)
c@225 112 {
c@225 113 y[ l ] = src[ j ];
c@225 114 l++;
c@225 115 }
c@225 116
c@225 117 scratch[ index++ ] = MathUtilities::median( y, (m_winPost + m_winPre + 1 ));
c@225 118 }
c@225 119
c@225 120 for( i = std::max( m_length - m_winPost, (unsigned)1); i < m_length; i++)
c@225 121 {
c@225 122 k = std::max( i - m_winPre, (unsigned)1);
c@225 123
c@225 124 l = 0;
c@225 125 for( j = k; j < m_length; j++)
c@225 126 {
c@225 127 y[ l ] = src[ j ];
c@225 128
c@225 129 l++;
c@225 130 }
c@225 131
c@225 132 scratch[ index++ ] = MathUtilities::median( y, l);
c@225 133 }
c@225 134
c@225 135
c@225 136 for( i = 0; i < m_length; i++ )
c@225 137 {
c@225 138 val = src[ i ] - scratch[ i ];// - 0.033;
c@225 139
c@225 140 if( m_isMedianPositive )
c@225 141 {
c@225 142 if( val > 0 )
c@225 143 {
c@225 144 dst[ i ] = val;
c@225 145 }
c@225 146 else
c@225 147 {
c@225 148 dst[ i ] = 0;
c@225 149 }
c@225 150 }
c@225 151 else
c@225 152 {
c@225 153 dst[ i ] = val;
c@225 154 }
c@225 155 }
c@225 156
c@225 157 delete [] y;
c@225 158 delete [] scratch;
c@225 159 }
c@225 160
c@225 161
c@225 162 void DFProcess::removeDCNormalize( double *src, double*dst )
c@225 163 {
c@225 164 double DFmax = 0;
c@225 165 double DFMin = 0;
c@225 166 double DFAlphaNorm = 0;
c@225 167
c@225 168 MathUtilities::getFrameMinMax( src, m_length, &DFMin, &DFmax );
c@225 169
c@225 170 MathUtilities::getAlphaNorm( src, m_length, m_alphaNormParam, &DFAlphaNorm );
c@225 171
c@225 172 for( unsigned int i = 0; i< m_length; i++)
c@225 173 {
c@225 174 dst[ i ] = ( src[ i ] - DFMin ) / DFAlphaNorm;
c@225 175 }
c@225 176 }