changeset 17:c96b18dd0f48

adjusting sync parameters
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 06 Feb 2012 13:38:19 +0000
parents 680ba08e9925
children 4ded82fe318d
files bayesianArraySrc/BayesianArrayStructure.cpp src/AccompanimentSynchroniser.cpp src/AccompanimentSynchroniser.h src/AudioEventMatcher.cpp
diffstat 4 files changed, 62 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/bayesianArraySrc/BayesianArrayStructure.cpp	Mon Feb 06 12:18:40 2012 +0000
+++ b/bayesianArraySrc/BayesianArrayStructure.cpp	Mon Feb 06 13:38:19 2012 +0000
@@ -243,7 +243,8 @@
 	
 //	printf("best estimate update from %f to %f; time diff %f MAP %i = %f ms speed index %f est %f SpeedxTime %f\n", tmp, bestEstimate, timeDiff,
 //		   posterior.MAPestimate, posterior.getIndexInRealTerms(posterior.MAPestimate), speedEstimateIndex, speedEstimate, timeDiff*speedEstimate);
-	printf("BEST ESTIMATE %f\n", bestEstimate);
+
+		printf("BEST ESTIMATE %f\n", bestEstimate);
 }
 
 
@@ -258,9 +259,8 @@
 	
 	posterior.renormalise();
 	
-	//tmp print stuff
-	printf("After CALC");
-	printPostOffset();	
+	//	printf("After CALC");
+	//	printPostOffset();	
 	
 }
 
@@ -295,7 +295,7 @@
 //	int tmpMap = bayesianStruct.posterior.getMAPestimate();
 	
 	double timeDifference = newEventTime - lastEventTime; 
-	printf("updating distributions at time %f diff %f offset %f\n", newEventTime, timeDifference, posterior.offset);
+//	printf("updating distributions at time %f diff %f offset %f\n", newEventTime, timeDifference, posterior.offset);
 	
 	//addnoise to the tempo distribution
 	//bayesianStruct.decaySpeedDistribution(timeDifference);
@@ -333,7 +333,7 @@
 	
 	double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar;
 	
-	printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits);
+	//printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits);
 	prior.zero();//kill prior
 	
 //	calculateNewPriorOffset(timeDifference);//dioesnt do anything
@@ -354,7 +354,7 @@
 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){
 
 	
-	printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits);
+//	printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits);
 	
 	int distanceMoved, newPriorIndex;
 	
@@ -406,7 +406,7 @@
 	}//end speed
 	
 	
-	printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate()));
+//	printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate()));
 }
 
 
--- a/src/AccompanimentSynchroniser.cpp	Mon Feb 06 12:18:40 2012 +0000
+++ b/src/AccompanimentSynchroniser.cpp	Mon Feb 06 13:38:19 2012 +0000
@@ -11,6 +11,24 @@
 
 AccompanimentSynchroniser::AccompanimentSynchroniser(){
 	sender.setup(HOST,  SENDER_PORT);
+	counter = 0;
+	reset();
+}
+
+void AccompanimentSynchroniser::reset(){
+	
+	
+	playingPositionRatio = 0;
+	playingPositionSamples = 0;
+	playingPositionMillis = 0;
+	playingPositionTimeSent = 0;
+	
+	recordedPositionMillis = 0;
+	recordedPositionTimeSent = 0;
+	
+	speed = 1;
+	
+	
 }
 
 void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){
@@ -21,33 +39,44 @@
 }
 
 
-void AccompanimentSynchroniser::updateRecordedPosition(const double& currentAlignmentPosition){
+void AccompanimentSynchroniser::updateRecordedPosition(const double& currentAlignmentPosition, const double& timeSent){
 	recordedPositionMillis = currentAlignmentPosition;
+	recordedPositionTimeSent = timeSent;
 }
 
 
 void AccompanimentSynchroniser::updateOutputSpeed(){
 	//we want the playing position to more closely align with the recordedPosition
+
 	
 	double difference = recordedPositionMillis - playingPositionMillis;
+//	difference -=  (recordedPositionTimeSent - playingPositionTimeSent);
 	
-	//suppose we project that we will align in two seconds time
-	double projectedAlignmentTime = 2000;
+	//suppose we project that we will align in 1 seconds time
+	double projectedAlignmentTime = 1000;
 	
 	//then our current speed projects forward
 	double predictedPlayingTimeIncrease = projectedAlignmentTime*speed;
-	
 	difference += (projectedAlignmentTime - predictedPlayingTimeIncrease);
-	
+	double tmpSpeed = speed;
 	speed += difference/projectedAlignmentTime;
 	
 	sendSpeed(speed);
+	
+	if (counter % 10 == 0){
+		printf("SYNC: rec pos %f play pos %f, diff %f\n", recordedPositionMillis, playingPositionMillis, recordedPositionMillis - playingPositionMillis);
+		printf("projected align diff %f at speed %f\n", (projectedAlignmentTime - predictedPlayingTimeIncrease), tmpSpeed);
+		printf("Final difference %f and speed output %f\n\n", difference, speed);
+	}
+		counter++;
 
 }
 
 void AccompanimentSynchroniser::sendSpeed(double const& val){
-	ofxOscMessage m;
-	m.setAddress( "/setSpeed" );
-	m.addFloatArg( val );
-	sender.sendMessage( m );
+	if (val > -3 && val < 4){
+		ofxOscMessage m;
+		m.setAddress( "/setSpeed" );
+		m.addFloatArg( val );
+		sender.sendMessage( m );
+	}
 }
\ No newline at end of file
--- a/src/AccompanimentSynchroniser.h	Mon Feb 06 12:18:40 2012 +0000
+++ b/src/AccompanimentSynchroniser.h	Mon Feb 06 13:38:19 2012 +0000
@@ -23,12 +23,16 @@
 public:
 	AccompanimentSynchroniser();
 	
+	void reset();
+	
 	void setPlayingRatio(const double& ratio, const double& timePlayed);
 	void setRecordedPosition();
-	void updateRecordedPosition(const double& currentAlignmentPosition);
+	void updateRecordedPosition(const double& currentAlignmentPosition, const double& timeSent);
 	
 	void updateOutputSpeed();
 	
+	int counter ;
+	
 	double fileLengthSamples;
 	
 
@@ -38,9 +42,11 @@
 	double playingPositionMillis;
 	double playingPositionTimeSent;
 	
+	double recordedPositionMillis;
 private:
 	
-	double recordedPositionMillis;
+	
+	double recordedPositionTimeSent;
 	
 	double speed;
 	
--- a/src/AudioEventMatcher.cpp	Mon Feb 06 12:18:40 2012 +0000
+++ b/src/AudioEventMatcher.cpp	Mon Feb 06 13:38:19 2012 +0000
@@ -15,10 +15,10 @@
 AudioEventMatcher::AudioEventMatcher(){
 
 	
-	pitchLikelihoodToNoise = 0.9;//more noise
+	pitchLikelihoodToNoise = 0.7;//more noise
 	
-	onsetLikelihoodToNoise = 0.4;
-	onsetLikelihoodWidth = 20;//in ms
+	onsetLikelihoodToNoise = 0.5;
+	onsetLikelihoodWidth = 10;//in ms
 	
 	setArraySizes();
 	
@@ -70,6 +70,8 @@
 	
 	projectedPrior = bayesianStruct.prior;
 	startedPlaying = true;
+	synchroniser.reset();
+	
 	//bayesianStruct.posterior.printArray();
 }
 
@@ -100,7 +102,7 @@
 	currentAlignmentPosition += (newTime - lastAlignmentTime) * bayesianStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesianStruct.relativeSpeedPosterior.MAPestimate);
 
 	
-	synchroniser.updateRecordedPosition(currentAlignmentPosition);
+	synchroniser.updateRecordedPosition(currentAlignmentPosition, newTime);
 	
 	synchroniser.updateOutputSpeed();
 	
@@ -132,7 +134,8 @@
 	
 	string alignString = " align "+ofToString(currentAlignmentPosition, 2);
 	alignString += " playing "+ofToString(synchroniser.playingPositionRatio, 5);
-	alignString += "  "+ofToString(synchroniser.playingPositionMillis)+" ms";
+	alignString += "  pos "+ofToString(synchroniser.playingPositionMillis,0)+" ms";
+	alignString +=  "  rec pos "+ofToString(synchroniser.recordedPositionMillis,0)+" ms";
 	ofDrawBitmapString(alignString, 20, 50);
 	
 	ofDrawBitmapString("pos "+ofToString(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.playPosition), 200,600);