comparison dsp/onsets/DetectionFunction.cpp @ 238:e8e5f9130b49

...
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 23 May 2007 15:22:10 +0000
parents 343915d55ec5
children 68801ecbab6a
comparison
equal deleted inserted replaced
237:343915d55ec5 238:e8e5f9130b49
33 void DetectionFunction::initialise( DFConfig Config ) 33 void DetectionFunction::initialise( DFConfig Config )
34 { 34 {
35 m_dataLength = Config.frameLength; 35 m_dataLength = Config.frameLength;
36 m_halfLength = m_dataLength/2; 36 m_halfLength = m_dataLength/2;
37 m_DFType = Config.DFType; 37 m_DFType = Config.DFType;
38 m_stepSecs = Config.stepSecs;
39 m_stepSize = Config.stepSize;
38 40
39 m_magHistory = new double[ m_halfLength ]; 41 m_magHistory = new double[ m_halfLength ];
40 memset(m_magHistory,0, m_halfLength*sizeof(double)); 42 memset(m_magHistory,0, m_halfLength*sizeof(double));
41 43
42 m_phaseHistory = new double[ m_halfLength ]; 44 m_phaseHistory = new double[ m_halfLength ];
96 { 98 {
97 case DF_HFC: 99 case DF_HFC:
98 retVal = HFC( m_halfLength, m_magnitude); 100 retVal = HFC( m_halfLength, m_magnitude);
99 break; 101 break;
100 102
101 case DF_SPECDIFF: 103 case DF_SPECDIFF:
102 retVal = specDiff( m_halfLength, m_magnitude); 104 retVal = specDiff( m_halfLength, m_magnitude);
103 break; 105 break;
104 106
105 case DF_PHASEDEV: 107 case DF_PHASEDEV:
106 retVal = phaseDev( m_halfLength, m_magnitude, m_thetaAngle); 108 retVal = phaseDev( m_halfLength, m_magnitude, m_thetaAngle);
140 { 142 {
141 temp = fabs( (src[ i ] * src[ i ]) - (m_magHistory[ i ] * m_magHistory[ i ]) ); 143 temp = fabs( (src[ i ] * src[ i ]) - (m_magHistory[ i ] * m_magHistory[ i ]) );
142 144
143 diff= sqrt(temp); 145 diff= sqrt(temp);
144 146
145 if( src[ i ] > 0.1) 147 // (See note in phaseDev below.)
146 { 148
147 val += diff; 149 val += diff;
148 }
149 150
150 m_magHistory[ i ] = src[ i ]; 151 m_magHistory[ i ] = src[ i ];
151 } 152 }
152 153
153 return val; 154 return val;
165 166
166 for( i = 0; i < length; i++) 167 for( i = 0; i < length; i++)
167 { 168 {
168 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); 169 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]);
169 dev = MathUtilities::princarg( tmpPhase ); 170 dev = MathUtilities::princarg( tmpPhase );
170 171
171 if( srcMagnitude[ i ] > 0.1) 172 // A previous version of this code only counted the value here
172 { 173 // if the magnitude exceeded 0.1. My impression is that
173 tmpVal = fabs( dev); 174 // doesn't greatly improve the results for "loud" music (so
174 val += tmpVal ; 175 // long as the peak picker is reasonably sophisticated), but
175 } 176 // does significantly damage its ability to work with quieter
177 // music, so I'm removing it and counting the result always.
178 // Same goes for the spectral difference measure above.
179
180 tmpVal = fabs(dev);
181 val += tmpVal ;
176 182
177 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; 183 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ;
178 m_phaseHistory[ i ] = srcPhase[ i ]; 184 m_phaseHistory[ i ] = srcPhase[ i ];
179 } 185 }
180 186