Mercurial > hg > aubio-onset-detector
comparison Source/AubioOnsetDetector.cpp @ 3:979125db34ab
added OF visualiser src code. Added a long term median trigger threshold. New method is working very well on onsets
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Mon, 21 Nov 2011 23:22:40 +0000 |
parents | b4c899822b4e |
children | eba88b84b5ca |
comparison
equal
deleted
inserted
replaced
2:b4c899822b4e | 3:979125db34ab |
---|---|
24 resetValues(); | 24 resetValues(); |
25 thresholdRelativeToMedian = 1.3; | 25 thresholdRelativeToMedian = 1.3; |
26 cutoffForRepeatOnsetsMillis = 100; | 26 cutoffForRepeatOnsetsMillis = 100; |
27 medianSpeed = 10; | 27 medianSpeed = 10; |
28 pos = 0; | 28 pos = 0; |
29 | |
30 detectionTriggerRatio = 0.5f; | |
31 detectionTriggerThreshold = 10; | |
29 } | 32 } |
30 | 33 |
31 AubioOnsetDetector :: ~AubioOnsetDetector(){ | 34 AubioOnsetDetector :: ~AubioOnsetDetector(){ |
32 aubio_onsetdetection_free (o); | 35 aubio_onsetdetection_free (o); |
33 | 36 |
190 bool AubioOnsetDetector :: checkForSlopeOnset(float bestValue){ | 193 bool AubioOnsetDetector :: checkForSlopeOnset(float bestValue){ |
191 bool onsetDetected = false; | 194 bool onsetDetected = false; |
192 //check for onset relative to our processed slope function | 195 //check for onset relative to our processed slope function |
193 //a mix between increase in value and the gradient of that increase | 196 //a mix between increase in value and the gradient of that increase |
194 | 197 |
195 if (bestValue > bestSlopeMedian * thresholdRelativeToMedian && | 198 if (bestValue > bestSlopeMedian * thresholdRelativeToMedian && //better than recent average |
196 1000*framesToSeconds(currentFrame - lastSlopeOnsetFrame) > cutoffForRepeatOnsetsMillis | 199 1000*framesToSeconds(currentFrame - lastSlopeOnsetFrame) > cutoffForRepeatOnsetsMillis //after cutoff time |
197 && slopeFallenBelowMedian | 200 && slopeFallenBelowMedian // has had onset and fall away again |
201 && bestValue > detectionTriggerThreshold * detectionTriggerRatio //longer term ratio of winning onsets | |
198 ){ | 202 ){ |
199 printf("frame diff between onsets %6.1f", (1000*framesToSeconds(currentFrame - lastMedianOnsetFrame)) ); | 203 printf("frame diff between onsets %6.1f", (1000*framesToSeconds(currentFrame - lastMedianOnsetFrame)) ); |
200 onsetDetected = true; | 204 onsetDetected = true; |
201 lastSlopeOnsetFrame = currentFrame; | 205 lastSlopeOnsetFrame = currentFrame; |
202 slopeFallenBelowMedian = false; | 206 slopeFallenBelowMedian = false; |
207 | |
208 updateDetectionTriggerThreshold(bestValue); | |
203 } | 209 } |
204 | 210 |
205 | 211 |
206 if (bestValue > bestSlopeMedian) | 212 if (bestValue > bestSlopeMedian) |
207 bestSlopeMedian += (bestValue - bestSlopeMedian)*0.1; | 213 bestSlopeMedian += (bestValue - bestSlopeMedian)*0.02;//was 1.1 |
208 else{ | 214 else{ |
209 bestSlopeMedian *= 0.995; | 215 bestSlopeMedian *= 0.99; |
210 slopeFallenBelowMedian = true;; | 216 slopeFallenBelowMedian = true;; |
211 } | 217 } |
212 return onsetDetected; | 218 return onsetDetected; |
219 } | |
220 | |
221 | |
222 void AubioOnsetDetector::updateDetectionTriggerThreshold(const float& val){ | |
223 float detectionAdaptSpeed = 0.05;//moving average, roughly last twenty onsets | |
224 detectionTriggerThreshold *= 1- detectionAdaptSpeed; | |
225 detectionTriggerThreshold += (val * detectionAdaptSpeed); | |
213 } | 226 } |
214 | 227 |
215 double AubioOnsetDetector::framesToSeconds(float frames){ | 228 double AubioOnsetDetector::framesToSeconds(float frames){ |
216 double seconds = frames * buffersize / 44100.; | 229 double seconds = frames * buffersize / 44100.; |
217 return seconds; | 230 return seconds; |