changeset 18:c7107e5c8f03

added in a mode to use either integrated estimate or MAP estimate in tempo process. Decreased nooise param from 0.02 to 0.03 so observations given more weight
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 18 Nov 2011 11:56:32 +0000
parents d75d16c57eac
children 2e17f0fdeaef
files maxPatchToPlayFiles/playMidiTranscription3.maxpat src/BayesianArrayStructure.cpp src/BayesianArrayStructure.h src/DynamicBayesianArray.h src/midiEventHolder.cpp
diffstat 5 files changed, 76 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/maxPatchToPlayFiles/playMidiTranscription3.maxpat	Tue Nov 15 20:06:55 2011 +0000
+++ b/maxPatchToPlayFiles/playMidiTranscription3.maxpat	Fri Nov 18 11:56:32 2011 +0000
@@ -1,9 +1,9 @@
 {
 	"patcher" : 	{
 		"fileversion" : 1,
-		"rect" : [ 391.0, 59.0, 1089.0, 872.0 ],
+		"rect" : [ 826.0, 100.0, 1089.0, 872.0 ],
 		"bglocked" : 0,
-		"defrect" : [ 391.0, 59.0, 1089.0, 872.0 ],
+		"defrect" : [ 826.0, 100.0, 1089.0, 872.0 ],
 		"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
 		"openinpresentation" : 1,
 		"default_fontsize" : 10.0,
@@ -20,6 +20,21 @@
 		"devicewidth" : 0.0,
 		"boxes" : [ 			{
 				"box" : 				{
+					"maxclass" : "flonum",
+					"fontsize" : 12.0,
+					"presentation_rect" : [ 282.0, 62.0, 57.0, 21.0 ],
+					"numinlets" : 1,
+					"patching_rect" : [ 511.0, 249.0, 57.0, 21.0 ],
+					"numoutlets" : 2,
+					"presentation" : 1,
+					"id" : "obj-99",
+					"fontname" : "Verdana",
+					"outlettype" : [ "float", "bang" ]
+				}
+
+			}
+, 			{
+				"box" : 				{
 					"maxclass" : "message",
 					"text" : "/offline",
 					"fontsize" : 10.0,
@@ -80,17 +95,17 @@
 					"maxclass" : "newobj",
 					"text" : "p ftmPlayer",
 					"fontsize" : 10.0,
-					"numinlets" : 1,
-					"patching_rect" : [ -26.0, 314.0, 476.0, 19.0 ],
+					"numinlets" : 2,
+					"patching_rect" : [ 45.0, 316.0, 476.0, 19.0 ],
 					"numoutlets" : 2,
 					"id" : "obj-60",
 					"fontname" : "Verdana",
 					"outlettype" : [ "", "" ],
 					"patcher" : 					{
 						"fileversion" : 1,
-						"rect" : [ 0.0, 0.0, 640.0, 480.0 ],
+						"rect" : [ 25.0, 69.0, 640.0, 480.0 ],
 						"bglocked" : 0,
-						"defrect" : [ 0.0, 0.0, 640.0, 480.0 ],
+						"defrect" : [ 25.0, 69.0, 640.0, 480.0 ],
 						"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
 						"openinpresentation" : 0,
 						"default_fontsize" : 12.0,
@@ -107,6 +122,18 @@
 						"devicewidth" : 0.0,
 						"boxes" : [ 							{
 								"box" : 								{
+									"maxclass" : "inlet",
+									"numinlets" : 0,
+									"patching_rect" : [ 336.0, 56.0, 25.0, 25.0 ],
+									"numoutlets" : 1,
+									"id" : "obj-1",
+									"outlettype" : [ "float" ],
+									"comment" : ""
+								}
+
+							}
+, 							{
+								"box" : 								{
 									"maxclass" : "comment",
 									"text" : "midi",
 									"fontsize" : 10.0,
@@ -788,21 +815,6 @@
 							}
 , 							{
 								"box" : 								{
-									"maxclass" : "flonum",
-									"fontsize" : 12.0,
-									"presentation_rect" : [ 184.0, 62.0, 57.0, 21.0 ],
-									"numinlets" : 1,
-									"patching_rect" : [ 337.0, 137.0, 57.0, 21.0 ],
-									"numoutlets" : 2,
-									"presentation" : 1,
-									"id" : "obj-99",
-									"fontname" : "Verdana",
-									"outlettype" : [ "float", "bang" ]
-								}
-
-							}
-, 							{
-								"box" : 								{
 									"maxclass" : "comment",
 									"text" : "syntax:",
 									"fontsize" : 10.0,
@@ -1079,8 +1091,8 @@
  ],
 						"lines" : [ 							{
 								"patchline" : 								{
-									"source" : [ "obj-115", 0 ],
-									"destination" : [ "obj-53", 0 ],
+									"source" : [ "obj-1", 0 ],
+									"destination" : [ "obj-53", 3 ],
 									"hidden" : 0,
 									"midpoints" : [  ]
 								}
@@ -1088,8 +1100,8 @@
 							}
 , 							{
 								"patchline" : 								{
-									"source" : [ "obj-99", 0 ],
-									"destination" : [ "obj-53", 3 ],
+									"source" : [ "obj-115", 0 ],
+									"destination" : [ "obj-53", 0 ],
 									"hidden" : 0,
 									"midpoints" : [  ]
 								}
@@ -1253,7 +1265,7 @@
 					"fontsize" : 10.0,
 					"presentation_rect" : [ 62.0, 86.0, 51.0, 17.0 ],
 					"numinlets" : 2,
-					"patching_rect" : [ 155.0, 267.0, 40.0, 17.0 ],
+					"patching_rect" : [ 226.0, 269.0, 40.0, 17.0 ],
 					"numoutlets" : 1,
 					"presentation" : 1,
 					"id" : "obj-55",
@@ -1268,7 +1280,7 @@
 					"text" : "hear MIDI playing",
 					"fontsize" : 10.0,
 					"numinlets" : 1,
-					"patching_rect" : [ -147.0, 346.0, 150.0, 19.0 ],
+					"patching_rect" : [ -10.0, 351.0, 150.0, 19.0 ],
 					"numoutlets" : 0,
 					"id" : "obj-54",
 					"fontname" : "Verdana"
@@ -1288,9 +1300,9 @@
 					"outlettype" : [ "bang" ],
 					"patcher" : 					{
 						"fileversion" : 1,
-						"rect" : [ 0.0, 0.0, 640.0, 480.0 ],
+						"rect" : [ 25.0, 69.0, 640.0, 480.0 ],
 						"bglocked" : 0,
-						"defrect" : [ 0.0, 0.0, 640.0, 480.0 ],
+						"defrect" : [ 25.0, 69.0, 640.0, 480.0 ],
 						"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
 						"openinpresentation" : 0,
 						"default_fontsize" : 12.0,
@@ -1578,9 +1590,9 @@
 , 			{
 				"box" : 				{
 					"maxclass" : "message",
-					"text" : "78 100 2750.",
+					"text" : "48 0 95275.25",
 					"fontsize" : 10.0,
-					"presentation_rect" : [ 422.0, 937.0, 201.0, 17.0 ],
+					"presentation_rect" : [ 32.0, 199.0, 201.0, 17.0 ],
 					"numinlets" : 2,
 					"patching_rect" : [ 422.0, 937.0, 201.0, 17.0 ],
 					"numoutlets" : 1,
@@ -1626,7 +1638,7 @@
 					"fontsize" : 10.0,
 					"presentation_rect" : [ 23.0, 86.0, 33.0, 17.0 ],
 					"numinlets" : 2,
-					"patching_rect" : [ 111.0, 266.0, 33.0, 17.0 ],
+					"patching_rect" : [ 182.0, 268.0, 33.0, 17.0 ],
 					"numoutlets" : 1,
 					"presentation" : 1,
 					"id" : "obj-25",
@@ -1747,7 +1759,7 @@
 					"maxclass" : "toggle",
 					"presentation_rect" : [ 188.0, 84.0, 20.0, 20.0 ],
 					"numinlets" : 1,
-					"patching_rect" : [ -170.0, 351.0, 20.0, 20.0 ],
+					"patching_rect" : [ -33.0, 356.0, 20.0, 20.0 ],
 					"numoutlets" : 1,
 					"presentation" : 1,
 					"id" : "obj-4",
@@ -1761,7 +1773,7 @@
 					"text" : "gate",
 					"fontsize" : 10.0,
 					"numinlets" : 2,
-					"patching_rect" : [ -152.0, 368.0, 33.0, 19.0 ],
+					"patching_rect" : [ -15.0, 373.0, 33.0, 19.0 ],
 					"numoutlets" : 1,
 					"id" : "obj-1",
 					"fontname" : "Verdana",
@@ -2031,7 +2043,7 @@
 					"text" : "/stopplaying",
 					"fontsize" : 10.0,
 					"numinlets" : 2,
-					"patching_rect" : [ 283.0, 569.0, 73.0, 17.0 ],
+					"patching_rect" : [ 339.0, 568.0, 73.0, 17.0 ],
 					"numoutlets" : 1,
 					"id" : "obj-72",
 					"fontname" : "Verdana",
@@ -2094,7 +2106,7 @@
 , 			{
 				"box" : 				{
 					"maxclass" : "message",
-					"text" : "78 100",
+					"text" : "48 0",
 					"fontsize" : 10.0,
 					"numinlets" : 2,
 					"patching_rect" : [ 58.0, 637.0, 50.0, 17.0 ],
@@ -2214,7 +2226,7 @@
 					"text" : "midiout",
 					"fontsize" : 10.0,
 					"numinlets" : 1,
-					"patching_rect" : [ -146.0, 396.0, 48.0, 19.0 ],
+					"patching_rect" : [ -9.0, 401.0, 48.0, 19.0 ],
 					"numoutlets" : 0,
 					"id" : "obj-44",
 					"fontname" : "Verdana"
@@ -2285,6 +2297,15 @@
  ],
 		"lines" : [ 			{
 				"patchline" : 				{
+					"source" : [ "obj-99", 0 ],
+					"destination" : [ "obj-60", 1 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
 					"source" : [ "obj-31", 0 ],
 					"destination" : [ "obj-69", 0 ],
 					"hidden" : 0,
--- a/src/BayesianArrayStructure.cpp	Tue Nov 15 20:06:55 2011 +0000
+++ b/src/BayesianArrayStructure.cpp	Fri Nov 18 11:56:32 2011 +0000
@@ -24,15 +24,9 @@
 	
 	lastEventTime = 0;//ofGetElapsedTimeMillis();
 
-	/*
-	 tmpPrior.createVector(240);
-	 tmpPrior.addGaussianShape(100, 40, 1);
-	 tmpPrior.addGaussianShape(200, 10, 0.2);
-	 tmpPrior.translateDistribution(20);
-	 */
 	tmpBestEstimate = 0;
 	crossUpdateTimeThreshold = 100;
-	priorWidth = 30;
+	priorWidth = 50;
 }
 
 BayesianArrayStructure::BayesianArrayStructure(int length){
@@ -43,6 +37,7 @@
 	posterior.createVector(length);
 	
 	lastEventTime = 0;
+	usingIntegratedTempoEstimate = false;//use max index
 
 }
 
@@ -67,13 +62,8 @@
 	relativeSpeedPosterior.zero();
 	relativeSpeedLikelihood.zero();
 	
-	//relativeSpeedPosterior.addGaussianShape(40, 5, 0.6);
 	
 	relativeSpeedPosterior.addGaussianShape(100, 20, 0.8);
-//	relativeSpeedPosterior.addGaussianShape(50, 1, 0.8);
-	
-//	relativeSpeedPosterior.addToIndex(100, 1);
-	//relativeSpeedPosterior.addToIndex(50, 1);
 	relativeSpeedPosterior.renormalise();
 	relativeSpeedPosterior.getMaximum();
 	
@@ -82,8 +72,7 @@
 	
 	prior.zero();
 	posterior.zero();
-//	posterior.offset = - 200;
-//	posterior.addGaussianShape(200, 40, 1);
+
 	posterior.addToIndex(0, 1);
 	posterior.renormalise();
 	
@@ -130,21 +119,6 @@
 }
 
 void BayesianArrayStructure::simpleExample(){
-	//simple example
-	
-//	 prior.addGaussianShape(50, 10, 1);
-//	prior.addGaussianShape(150, 30, 0.3);
-//	prior.addGaussianShape(250, 30, 0.2);
-	
-//	likelihood.addGaussianShape(90, 20, 0.6);
-//	likelihood.addConstant(0.02);
-//	posterior.doProduct(prior, likelihood);
-	
-//	relativeSpeedPosterior.addToIndex(100, 1);
-//	relativeSpeedPosterior.addToIndex(40, 0.7);	
-	
-//	relativeSpeedPosterior.addGaussianShape(100, 2, 1);
-//	relativeSpeedPosterior.addGaussianShape(40, 2, 0.5);
 	relativeSpeedPosterior.getMaximum();
 	relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior);
 }
@@ -228,7 +202,13 @@
 	//if (*realTimeMode)
 		timeDiff = ofGetElapsedTimeMillis() - lastBestEstimateUpdateTime;
 	
-	double speedEstimate = relativeSpeedPosterior.getIntegratedEstimate();
+	double speedEstimate;
+	if (usingIntegratedTempoEstimate)
+		speedEstimate = relativeSpeedPosterior.getIntegratedEstimate();
+	else
+		speedEstimate = relativeSpeedPosterior.MAPestimate;
+	
+	
 	speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimate);
 	//relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate)
 	bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate;
@@ -505,6 +485,11 @@
 	ofSetColor(155,255, 0);
 	double fractionOfScreen = ((double)relativeSpeedPosterior.integratedEstimate / relativeSpeedPosterior.length);
 	ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight());
+	
+	ofSetColor(0,255, 255);
+	fractionOfScreen = ((double)relativeSpeedPosterior.MAPestimate / relativeSpeedPosterior.length);
+	ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight());
+	
 }
 
 
--- a/src/BayesianArrayStructure.h	Tue Nov 15 20:06:55 2011 +0000
+++ b/src/BayesianArrayStructure.h	Fri Nov 18 11:56:32 2011 +0000
@@ -92,6 +92,7 @@
 	double speedPriorValue;
 	int priorWidth;
 	bool* realTimeMode;
+	bool usingIntegratedTempoEstimate;
 	
 };
 #endif
--- a/src/DynamicBayesianArray.h	Tue Nov 15 20:06:55 2011 +0000
+++ b/src/DynamicBayesianArray.h	Fri Nov 18 11:56:32 2011 +0000
@@ -63,6 +63,7 @@
 	void resetPrior();
 	void decayPosterior();
 	float* getMaximumEstimate(float *ptr, int length);
+	double getMaximumIndex();//return the index where the probability is maximal
 	double getIntegratedEstimateIndex();
 	
 //	void drawArray(const int& minIndex, const int& maxIndex);
--- a/src/midiEventHolder.cpp	Tue Nov 15 20:06:55 2011 +0000
+++ b/src/midiEventHolder.cpp	Fri Nov 18 11:56:32 2011 +0000
@@ -28,7 +28,7 @@
 	maximumMatchSpeed = 2.0;
 
 	likelihoodWidth = 100;
-	likelihoodToNoiseRatio = 0.02;
+	likelihoodToNoiseRatio = 0.03;//was 0.02 on 18/11/11, changing to give more weight to observations
 	
 	bayesStruct.speedLikelihoodNoise = 0.1;//was 0.05
 	bayesStruct.speedDecayWidth = 20;