changeset 4:fb106f14e0a4

Streamlined the object, getting rid of sigmal outlet, adding in buffer and hopsize changes - needs to be fixed for slope onset - but median working, added the max external
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 18 Oct 2012 17:12:05 +0100
parents 979125db34ab
children eba88b84b5ca
files Source/aubioOnsetDetect~.cpp aubioOnsetDetectorOFvisualiser/src/testApp.cpp
diffstat 2 files changed, 76 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Source/aubioOnsetDetect~.cpp	Mon Nov 21 23:22:40 2011 +0000
+++ b/Source/aubioOnsetDetect~.cpp	Thu Oct 18 17:12:05 2012 +0100
@@ -44,7 +44,8 @@
 void aubioOnsetDetect_assist(t_aubioOnsetDetect *x, void *b, long m, long a, char *s);
 
 void aubioOnsetDetect_float(t_aubioOnsetDetect *x, double f);
-
+void aubioOnsetDetect_setBuffersize(t_aubioOnsetDetect *x, int i);
+void aubioOnsetDetect_setHopsize(t_aubioOnsetDetect *x, int i);
 void aubioOnsetDetect_energy(t_aubioOnsetDetect *x);
 void aubioOnsetDetect_hfc(t_aubioOnsetDetect *x);
 void aubioOnsetDetect_complex(t_aubioOnsetDetect *x);
@@ -70,7 +71,9 @@
 	t_class *c;
 	
 	c = class_new("aubioOnsetDetect~", (method)aubioOnsetDetect_new, (method)dsp_free, (long)sizeof(t_aubioOnsetDetect), 0L, A_GIMME, 0);
-	
+	class_addmethod(c, (method)aubioOnsetDetect_setBuffersize,	(char*)"setBuffersize",	A_LONG, 0);	
+	class_addmethod(c, (method)aubioOnsetDetect_setHopsize,	(char*)"setHopsize",	A_LONG, 0);	
+
 	class_addmethod(c, (method)aubioOnsetDetect_float,	(char*)"float",	A_FLOAT, 0);
 	class_addmethod(c, (method)aubioOnsetDetect_dsp,	(char*)	"dsp",		A_CANT, 0);
 	class_addmethod(c, (method)aubioOnsetDetect_assist,	(char*)"assist",	A_CANT, 0);
@@ -95,6 +98,37 @@
 	return 0;
 }
 
+
+void aubioOnsetDetect_setBuffersize(t_aubioOnsetDetect *x, int i){
+	x->bufsize   = i;//using fixed buffer size here.
+	x->hopsize   = x->bufsize / 2;
+	object_post((t_object*)x, "Buffersize in aubioonset set to %i and hopsize to %i", x->bufsize, x->hopsize);
+	
+	//set this up in AubioOnsetDetector class instead
+	//x->onsetDetector = new AubioOnsetDetector();
+	x->onsetDetector->buffersize = x->bufsize;
+	x->onsetDetector->hopsize = x->hopsize;
+	x->onsetDetector->threshold = x->threshold;
+	x->onsetDetector->threshold2 = x->threshold2;
+	x->onsetDetector->initialise();
+}
+
+void aubioOnsetDetect_setHopsize(t_aubioOnsetDetect *x, int i){
+	if (i < x->bufsize && x->hopsize > 0){
+		x->hopsize   = i;
+	object_post((t_object*)x, "Hopsize now set to %i and Buffersize set to %i", x->hopsize, x->bufsize);
+	
+	//set this up in AubioOnsetDetector class instead
+//	x->onsetDetector = new AubioOnsetDetector();
+	x->onsetDetector->buffersize = x->bufsize;
+	x->onsetDetector->hopsize = x->hopsize;
+	x->onsetDetector->threshold = x->threshold;
+	x->onsetDetector->threshold2 = x->threshold2;
+	x->onsetDetector->initialise();
+	}
+}
+
+
 void aubioOnsetDetect_float(t_aubioOnsetDetect *x, double f)
 {
 			if (f < 10 || f > 0.1){
@@ -253,17 +287,21 @@
 				
 		switch (a){
 			case 0:
-				sprintf(s, "Outlet %ld is the original signal.", a); 	
+				sprintf(s, "Bang out when onset is detected according to best slope.");
 				break;
 			case 1:
-				sprintf(s, "Bang out when onset is detected.");
+				sprintf(s, "best slope detection function.");
 				break;
 			case 2:
-				sprintf(s, "Peak Picked detection function.");
+				sprintf(s, "Raw aubio detection function result.");
 				break;
 			case 3:
-				sprintf(s, "Raw aubio detection function result.");
-				break;
+				sprintf(s, "Bang outlet according to median threshold.");
+				break;	
+			case 4:
+				sprintf(s, "Median function");
+				break;		
+				
 			}
 	}
 }
@@ -280,6 +318,10 @@
 
 	
 	// NEW VERSION
+	
+	//note for C++ programmers:
+	//adding (t_class *) in the line below lets you use .cpp files instead 
+	//then just change your external code to .cpp instead of c
 	if (x = (t_aubioOnsetDetect *)object_alloc((t_class *) aubioOnsetDetect_class)) {
 		dsp_setup((t_pxobject *)x, 1);	// MSP inlets: arg is # of inlets and is REQUIRED! 
 										// use 0 if you don't need inlets
@@ -290,28 +332,36 @@
 		x->detectionFunctionOutlet = floatout(x);
 		x->bangoutlet  = bangout(x);
 
-		outlet_new(x, "signal"); // signal outlet (note "signal" rather than NULL)
+	//	outlet_new(x, "signal"); // signal outlet (note "signal" rather than NULL)
 
 		x->threshold = 1;
 		x->threshold2 = -70.;
-		x->bufsize   = 1024;//using fixed buffer size here.
-		x->hopsize   = x->bufsize / 2;
+
+		//
 		
-		//set this up in AubioOnsetDetector class instead
-		x->onsetDetector = new AubioOnsetDetector();
-		x->onsetDetector->buffersize = x->bufsize;
-		x->onsetDetector->hopsize = x->hopsize;
-		x->onsetDetector->threshold = x->threshold;
-		x->onsetDetector->threshold2 = x->threshold2;
-		x->onsetDetector->initialise();
-		//
+		if (argc > 1){
+			t_atom my_atom = argv[1];
+			aubioOnsetDetect_setBuffersize(x, atom_getlong(&my_atom));
+			object_post((t_object*)x, (char*) "Buffersize set by user to %i ", atom_getfloat(&my_atom));
+		}else{
+			x->bufsize   = 1024;//using fixed buffer size here.
+			x->hopsize   = x->bufsize / 2;
+			
+			//set this up in AubioOnsetDetector class instead
+			x->onsetDetector = new AubioOnsetDetector();
+			x->onsetDetector->buffersize = x->bufsize;
+			x->onsetDetector->hopsize = x->hopsize;
+			x->onsetDetector->threshold = x->threshold;
+			x->onsetDetector->threshold2 = x->threshold2;
+			x->onsetDetector->initialise();
+		}
+		
 						
-		if (argc == 1){//i.e. there is an argument on creation like [aubioOnsetDetect~ 0.3]
-		t_atom my_atom = argv[0];
-		
+		if (argc > 0){//i.e. there is an argument on creation like [aubioOnsetDetect~ 0.3]
+			t_atom my_atom = argv[0];
 			object_post((t_object*)x, (char*) "Aubio Onset Detect found, created by Andrew Robertson from work by Paul Brossier, Queen Mary University");
-		object_post((t_object*)x, (char*) "Threshold set to %f ", atom_getfloat(&my_atom));
-		x->threshold = atom_getfloat(&my_atom);
+			object_post((t_object*)x, (char*) "Threshold set to %f ", atom_getfloat(&my_atom));
+			x->threshold = atom_getfloat(&my_atom);
 		
 			if (x->threshold > 10)
 			x->threshold = 10;
--- a/aubioOnsetDetectorOFvisualiser/src/testApp.cpp	Mon Nov 21 23:22:40 2011 +0000
+++ b/aubioOnsetDetectorOFvisualiser/src/testApp.cpp	Thu Oct 18 17:12:05 2012 +0100
@@ -291,6 +291,7 @@
 	int Xindex = (onsetIndex-Xvalue) ;
 	int previousIndex = (Xindex-1);
 	
+	//below - Paule's processed onsets	
 	ofSetColor(55,100,255);
 
 	ofLine((int) (width*(amplitudeNumber - Xvalue - 1)), screenHeight - (scale_factor*(onsetFunction[previousIndex]- minimumValue)), 
@@ -318,12 +319,13 @@
 			   (int) (width*(amplitudeNumber - Xvalue)),  screenHeight - (scale_factor*(medianOnsetFunction[Xindex]- minimumValue)) );
 		
 		
-
+		
 	if (rawOnsetRecorded[Xindex] == true){
 		ofSetColor(255,100,0);
 		ofCircle(width*(amplitudeNumber - Xvalue), screenHeight - (scale_factor*(rawOnsetFunction[Xindex]- minimumValue)) , 3);
 	}
 		
+		//median onsets in red
 		if (medianOnsetRecorded[Xindex] == true){
 			ofSetColor(255,0,0);
 			ofCircle(width*(amplitudeNumber - Xvalue), screenHeight - (scale_factor*(medianOnsetFunction[Xindex]- minimumValue)) , 3);