Mercurial > hg > qm-dsp
comparison dsp/onsets/DetectionFunction.cpp @ 483:fdaa63607c15
Untabify, indent, tidy
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Fri, 31 May 2019 11:54:32 +0100 |
parents | c5e1b25d5177 |
children | af5b7ef02aa7 |
comparison
equal
deleted
inserted
replaced
482:cbe668c7d724 | 483:fdaa63607c15 |
---|---|
52 if (m_whitenRelaxCoeff < 0) m_whitenRelaxCoeff = 0.9997; | 52 if (m_whitenRelaxCoeff < 0) m_whitenRelaxCoeff = 0.9997; |
53 if (m_whitenFloor < 0) m_whitenFloor = 0.01; | 53 if (m_whitenFloor < 0) m_whitenFloor = 0.01; |
54 | 54 |
55 m_magHistory = new double[ m_halfLength ]; | 55 m_magHistory = new double[ m_halfLength ]; |
56 memset(m_magHistory,0, m_halfLength*sizeof(double)); | 56 memset(m_magHistory,0, m_halfLength*sizeof(double)); |
57 | 57 |
58 m_phaseHistory = new double[ m_halfLength ]; | 58 m_phaseHistory = new double[ m_halfLength ]; |
59 memset(m_phaseHistory,0, m_halfLength*sizeof(double)); | 59 memset(m_phaseHistory,0, m_halfLength*sizeof(double)); |
60 | 60 |
61 m_phaseHistoryOld = new double[ m_halfLength ]; | 61 m_phaseHistoryOld = new double[ m_halfLength ]; |
62 memset(m_phaseHistoryOld,0, m_halfLength*sizeof(double)); | 62 memset(m_phaseHistoryOld,0, m_halfLength*sizeof(double)); |
132 double retVal = 0; | 132 double retVal = 0; |
133 | 133 |
134 switch( m_DFType ) | 134 switch( m_DFType ) |
135 { | 135 { |
136 case DF_HFC: | 136 case DF_HFC: |
137 retVal = HFC( m_halfLength, m_magnitude); | 137 retVal = HFC( m_halfLength, m_magnitude); |
138 break; | 138 break; |
139 | 139 |
140 case DF_SPECDIFF: | 140 case DF_SPECDIFF: |
141 retVal = specDiff( m_halfLength, m_magnitude); | 141 retVal = specDiff( m_halfLength, m_magnitude); |
142 break; | 142 break; |
143 | 143 |
144 case DF_PHASEDEV: | 144 case DF_PHASEDEV: |
145 // Using the instantaneous phases here actually provides the | 145 // Using the instantaneous phases here actually provides the |
146 // same results (for these calculations) as if we had used | 146 // same results (for these calculations) as if we had used |
147 // unwrapped phases, but without the possible accumulation of | 147 // unwrapped phases, but without the possible accumulation of |
148 // phase error over time | 148 // phase error over time |
149 retVal = phaseDev( m_halfLength, m_thetaAngle); | 149 retVal = phaseDev( m_halfLength, m_thetaAngle); |
150 break; | 150 break; |
151 | 151 |
152 case DF_COMPLEXSD: | 152 case DF_COMPLEXSD: |
153 retVal = complexSD( m_halfLength, m_magnitude, m_thetaAngle); | 153 retVal = complexSD( m_halfLength, m_magnitude, m_thetaAngle); |
154 break; | 154 break; |
155 | 155 |
156 case DF_BROADBAND: | 156 case DF_BROADBAND: |
157 retVal = broadband( m_halfLength, m_magnitude); | 157 retVal = broadband( m_halfLength, m_magnitude); |
158 break; | 158 break; |
159 } | 159 } |
160 | 160 |
161 return retVal; | 161 return retVal; |
162 } | 162 } |
163 | 163 |
164 double DetectionFunction::HFC(unsigned int length, double *src) | 164 double DetectionFunction::HFC(unsigned int length, double *src) |
165 { | 165 { |
166 unsigned int i; | 166 unsigned int i; |
167 double val = 0; | 167 double val = 0; |
168 | 168 |
169 for( i = 0; i < length; i++) | 169 for( i = 0; i < length; i++) { |
170 { | 170 val += src[ i ] * ( i + 1); |
171 val += src[ i ] * ( i + 1); | |
172 } | 171 } |
173 return val; | 172 return val; |
174 } | 173 } |
175 | 174 |
176 double DetectionFunction::specDiff(unsigned int length, double *src) | 175 double DetectionFunction::specDiff(unsigned int length, double *src) |
178 unsigned int i; | 177 unsigned int i; |
179 double val = 0.0; | 178 double val = 0.0; |
180 double temp = 0.0; | 179 double temp = 0.0; |
181 double diff = 0.0; | 180 double diff = 0.0; |
182 | 181 |
183 for( i = 0; i < length; i++) | 182 for( i = 0; i < length; i++) { |
184 { | 183 |
185 temp = fabs( (src[ i ] * src[ i ]) - (m_magHistory[ i ] * m_magHistory[ i ]) ); | 184 temp = fabs( (src[ i ] * src[ i ]) - (m_magHistory[ i ] * m_magHistory[ i ]) ); |
186 | 185 |
187 diff= sqrt(temp); | 186 diff= sqrt(temp); |
188 | 187 |
189 // (See note in phaseDev below.) | 188 // (See note in phaseDev below.) |
190 | 189 |
191 val += diff; | 190 val += diff; |
192 | 191 |
193 m_magHistory[ i ] = src[ i ]; | 192 m_magHistory[ i ] = src[ i ]; |
194 } | 193 } |
195 | 194 |
196 return val; | 195 return val; |
197 } | 196 } |
198 | 197 |
204 double tmpVal = 0; | 203 double tmpVal = 0; |
205 double val = 0; | 204 double val = 0; |
206 | 205 |
207 double dev = 0; | 206 double dev = 0; |
208 | 207 |
209 for( i = 0; i < length; i++) | 208 for( i = 0; i < length; i++) { |
210 { | 209 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); |
211 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); | 210 dev = MathUtilities::princarg( tmpPhase ); |
212 dev = MathUtilities::princarg( tmpPhase ); | |
213 | 211 |
214 // A previous version of this code only counted the value here | 212 // A previous version of this code only counted the value here |
215 // if the magnitude exceeded 0.1. My impression is that | 213 // if the magnitude exceeded 0.1. My impression is that |
216 // doesn't greatly improve the results for "loud" music (so | 214 // doesn't greatly improve the results for "loud" music (so |
217 // long as the peak picker is reasonably sophisticated), but | 215 // long as the peak picker is reasonably sophisticated), but |
218 // does significantly damage its ability to work with quieter | 216 // does significantly damage its ability to work with quieter |
219 // music, so I'm removing it and counting the result always. | 217 // music, so I'm removing it and counting the result always. |
220 // Same goes for the spectral difference measure above. | 218 // Same goes for the spectral difference measure above. |
221 | 219 |
222 tmpVal = fabs(dev); | 220 tmpVal = fabs(dev); |
223 val += tmpVal ; | 221 val += tmpVal ; |
224 | 222 |
225 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; | 223 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; |
226 m_phaseHistory[ i ] = srcPhase[ i ]; | 224 m_phaseHistory[ i ] = srcPhase[ i ]; |
227 } | 225 } |
228 | 226 |
229 return val; | 227 return val; |
230 } | 228 } |
231 | 229 |
232 | 230 |
233 double DetectionFunction::complexSD(unsigned int length, double *srcMagnitude, double *srcPhase) | 231 double DetectionFunction::complexSD(unsigned int length, double *srcMagnitude, double *srcPhase) |
240 | 238 |
241 double dev = 0; | 239 double dev = 0; |
242 ComplexData meas = ComplexData( 0, 0 ); | 240 ComplexData meas = ComplexData( 0, 0 ); |
243 ComplexData j = ComplexData( 0, 1 ); | 241 ComplexData j = ComplexData( 0, 1 ); |
244 | 242 |
245 for( i = 0; i < length; i++) | 243 for( i = 0; i < length; i++) { |
246 { | 244 |
247 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); | 245 tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); |
248 dev= MathUtilities::princarg( tmpPhase ); | 246 dev= MathUtilities::princarg( tmpPhase ); |
249 | 247 |
250 meas = m_magHistory[i] - ( srcMagnitude[ i ] * exp( j * dev) ); | 248 meas = m_magHistory[i] - ( srcMagnitude[ i ] * exp( j * dev) ); |
251 | 249 |
252 tmpReal = real( meas ); | 250 tmpReal = real( meas ); |
253 tmpImag = imag( meas ); | 251 tmpImag = imag( meas ); |
254 | 252 |
255 val += sqrt( (tmpReal * tmpReal) + (tmpImag * tmpImag) ); | 253 val += sqrt( (tmpReal * tmpReal) + (tmpImag * tmpImag) ); |
256 | 254 |
257 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; | 255 m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; |
258 m_phaseHistory[ i ] = srcPhase[ i ]; | 256 m_phaseHistory[ i ] = srcPhase[ i ]; |
259 m_magHistory[ i ] = srcMagnitude[ i ]; | 257 m_magHistory[ i ] = srcMagnitude[ i ]; |
260 } | 258 } |
261 | 259 |
262 return val; | 260 return val; |
263 } | 261 } |
264 | 262 |