Mercurial > hg > aubio-onset-detector
comparison Source/aubioOnsetDetect~.cpp @ 6:6a95d8b80393 tip
unknown changes
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Mon, 26 Nov 2012 23:17:34 +0000 |
parents | eba88b84b5ca |
children |
comparison
equal
deleted
inserted
replaced
5:eba88b84b5ca | 6:6a95d8b80393 |
---|---|
30 | 30 |
31 void *detectionFunctionOutlet; | 31 void *detectionFunctionOutlet; |
32 void *rawDetectionFunctionOutlet; | 32 void *rawDetectionFunctionOutlet; |
33 void *medianDetectionFunctionOutlet; | 33 void *medianDetectionFunctionOutlet; |
34 | 34 |
35 bool useMedianOnsetDetection;//(true) | 35 // bool useMedianOnsetDetection;//(true) |
36 //rather than Paul B's peak picking (false) | 36 //rather than Paul B's peak picking (false) |
37 | 37 |
38 } t_aubioOnsetDetect; | 38 } t_aubioOnsetDetect; |
39 | 39 |
40 ///////////////////////// function prototypes | 40 ///////////////////////// function prototypes |
104 x->hopsize = x->bufsize / 2; | 104 x->hopsize = x->bufsize / 2; |
105 object_post((t_object*)x, "Buffersize in aubioonset set to %i and hopsize to %i", x->bufsize, x->hopsize); | 105 object_post((t_object*)x, "Buffersize in aubioonset set to %i and hopsize to %i", x->bufsize, x->hopsize); |
106 | 106 |
107 //set this up in AubioOnsetDetector class instead | 107 //set this up in AubioOnsetDetector class instead |
108 //x->onsetDetector = new AubioOnsetDetector(); | 108 //x->onsetDetector = new AubioOnsetDetector(); |
109 | |
109 x->onsetDetector->buffersize = x->bufsize; | 110 x->onsetDetector->buffersize = x->bufsize; |
110 x->onsetDetector->hopsize = x->hopsize; | 111 x->onsetDetector->hopsize = x->hopsize; |
111 // x->onsetDetector->threshold = x->threshold; | 112 // x->onsetDetector->threshold = x->threshold; |
112 // x->onsetDetector->threshold2 = x->threshold2; | 113 // x->onsetDetector->threshold2 = x->threshold2; |
113 x->onsetDetector->initialise(); | 114 x->onsetDetector->initialise(); |
247 frame[j] = (float) inL[j];//must cast to float or is type t_float | 248 frame[j] = (float) inL[j];//must cast to float or is type t_float |
248 } | 249 } |
249 // aubio onset detector then processes current frame - returns bool true when new detection is output | 250 // aubio onset detector then processes current frame - returns bool true when new detection is output |
250 if (x->onsetDetector->processframe(frame, n)){ | 251 if (x->onsetDetector->processframe(frame, n)){ |
251 //if buffer full and new result is processed (buffer is 1024 with hopsize 512 - can be set to other values) | 252 //if buffer full and new result is processed (buffer is 1024 with hopsize 512 - can be set to other values) |
252 outlet_float(x->medianDetectionFunctionOutlet, x->onsetDetector->bestSlopeMedian);//medianDetectionValue | 253 |
254 outlet_float(x->medianDetectionFunctionOutlet, x->onsetDetector->bestSlopeMedian); | |
255 /* | |
256 //idea for getting processed value out | |
257 if (x->onsetDetector->rawDetectionValue > x->onsetDetector->medianDetectionValue) | |
258 outlet_float(x->medianDetectionFunctionOutlet, x->onsetDetector->rawDetectionValue - x->onsetDetector->medianDetectionValue); | |
259 else | |
260 outlet_float(x->medianDetectionFunctionOutlet, 0.0); | |
261 */ | |
262 | |
253 outlet_float(x->rawDetectionFunctionOutlet, x->onsetDetector->rawDetectionValue); | 263 outlet_float(x->rawDetectionFunctionOutlet, x->onsetDetector->rawDetectionValue); |
254 // outlet_float(x->detectionFunctionOutlet, x->onsetDetector->peakPickedDetectionValue); | 264 // outlet_float(x->detectionFunctionOutlet, x->onsetDetector->peakPickedDetectionValue); |
255 outlet_float(x->detectionFunctionOutlet, x->onsetDetector->bestSlopeValue); | 265 outlet_float(x->detectionFunctionOutlet, x->onsetDetector->bestSlopeValue); |
256 | 266 |
257 | 267 |
324 //then just change your external code to .cpp instead of c | 334 //then just change your external code to .cpp instead of c |
325 | 335 |
326 if (x = (t_aubioOnsetDetect *)object_alloc((t_class *) aubioOnsetDetect_class)) { | 336 if (x = (t_aubioOnsetDetect *)object_alloc((t_class *) aubioOnsetDetect_class)) { |
327 dsp_setup((t_pxobject *)x, 1); // MSP inlets: arg is # of inlets and is REQUIRED! | 337 dsp_setup((t_pxobject *)x, 1); // MSP inlets: arg is # of inlets and is REQUIRED! |
328 // use 0 if you don't need inlets | 338 // use 0 if you don't need inlets |
329 | 339 |
340 | |
341 object_post((t_object*)x, (char*) "Aubio Onset Detect Revamp found, created by Andrew Robertson from work by Paul Brossier, Queen Mary University"); | |
342 | |
343 | |
330 //set outlets, from right to left | 344 //set outlets, from right to left |
331 x->medianDetectionFunctionOutlet = floatout(x); | 345 x->medianDetectionFunctionOutlet = floatout(x); |
332 x->medianBangOutlet = bangout(x); | 346 x->medianBangOutlet = bangout(x); |
333 x->rawDetectionFunctionOutlet = floatout(x); | 347 x->rawDetectionFunctionOutlet = floatout(x); |
334 x->detectionFunctionOutlet = floatout(x); | 348 x->detectionFunctionOutlet = floatout(x); |
335 x->bangoutlet = bangout(x); | 349 x->bangoutlet = bangout(x); |
336 | 350 |
351 // outlet_new(x, "signal"); - no longer | |
352 | |
337 //aubio params | 353 //aubio params |
338 x->threshold = 1; | 354 x->threshold = 1; |
339 x->threshold2 = -70.; | 355 x->threshold2 = -70.; |
340 | 356 |
341 if (argc > 1){ | 357 //set this up in AubioOnsetDetector class instead |
342 t_atom my_atom = argv[1]; | 358 x->onsetDetector = new AubioOnsetDetector(); |
343 aubioOnsetDetect_setBuffersize(x, atom_getlong(&my_atom)); | 359 // x->onsetDetector->buffersize = x->bufsize; |
344 object_post((t_object*)x, (char*) "Buffersize set by user to %i ", atom_getfloat(&my_atom)); | 360 // x->onsetDetector->hopsize = x->hopsize; |
345 }else{ | 361 x->onsetDetector->threshold = x->threshold; |
346 x->bufsize = 1024;//using fixed buffer size here. | 362 x->onsetDetector->threshold2 = x->threshold2; |
347 x->hopsize = x->bufsize / 2; | 363 |
348 | 364 |
349 //set this up in AubioOnsetDetector class instead | |
350 x->onsetDetector = new AubioOnsetDetector(); | |
351 x->onsetDetector->buffersize = x->bufsize; | |
352 x->onsetDetector->hopsize = x->hopsize; | |
353 x->onsetDetector->threshold = x->threshold; | |
354 x->onsetDetector->threshold2 = x->threshold2; | |
355 x->onsetDetector->initialise(); | |
356 } | |
357 | |
358 | 365 |
359 if (argc > 0){//i.e. there is an argument on creation like [aubioOnsetDetect~ 0.3] | 366 if (argc > 0 && argv->a_type == A_FLOAT){//i.e. there is an argument on creation like [aubioOnsetDetect~ 0.3] |
360 t_atom my_atom = argv[0]; | 367 t_atom my_atom = argv[0]; |
361 object_post((t_object*)x, (char*) "Aubio Onset Detect found, created by Andrew Robertson from work by Paul Brossier, Queen Mary University"); | 368 object_post((t_object*)x, (char*) "Threshold argument: set to %f ", atom_getfloat(&my_atom)); |
362 object_post((t_object*)x, (char*) "Threshold set to %f ", atom_getfloat(&my_atom)); | |
363 x->threshold = atom_getfloat(&my_atom); | 369 x->threshold = atom_getfloat(&my_atom); |
364 | 370 |
365 if (x->threshold > 10) | 371 if (x->threshold > 10) |
366 x->threshold = 10; | 372 x->threshold = 10; |
367 | 373 |
369 x->threshold = 0.1; | 375 x->threshold = 0.1; |
370 | 376 |
371 x->onsetDetector->threshold = x->threshold; | 377 x->onsetDetector->threshold = x->threshold; |
372 } | 378 } |
373 | 379 |
374 x->useMedianOnsetDetection = true; | 380 if (argc > 1 && (argv+1)->a_type == A_LONG){ |
381 t_atom my_atom = argv[1]; | |
382 aubioOnsetDetect_setBuffersize(x, atom_getlong(&my_atom)); | |
383 object_post((t_object*)x, (char*) "Buffersize argument: set to %ld ", atom_getlong(&my_atom)); | |
384 } else { | |
385 x->bufsize = 1024;//using fixed buffer size here. | |
386 x->hopsize = x->bufsize / 2; | |
387 } | |
388 | |
389 x->onsetDetector->initialise(); | |
390 | |
391 // x->useMedianOnsetDetection = true; | |
375 } | 392 } |
376 return (x); | 393 return (x); |
377 } | 394 } |