Mercurial > hg > multitrack-audio-matcher
diff src/AccompanimentSynchroniser.cpp @ 53:5274e3b5479d
Smoothed output, added tempo distribution variation to match the output
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 14 Aug 2012 21:45:12 +0100 |
parents | d23685b9e766 |
children | 2eca10a31ae2 |
line wrap: on
line diff
--- a/src/AccompanimentSynchroniser.cpp Tue Jul 17 22:12:20 2012 +0100 +++ b/src/AccompanimentSynchroniser.cpp Tue Aug 14 21:45:12 2012 +0100 @@ -15,6 +15,7 @@ AccompanimentSynchroniser::AccompanimentSynchroniser(){ sender.setup(HOST, SENDER_PORT); counter = 0; + movingAverageWeighting = 0.4; reset(); } @@ -30,7 +31,8 @@ recordedPositionTimeSent = 0; speed = 1; - + smoothedSpeedOutput = 1; + difference = 0; } @@ -51,20 +53,22 @@ void AccompanimentSynchroniser::updateOutputSpeed(){ //we want the playing position to more closely align with the recordedPosition - - double difference = recordedPositionMillis - playingPositionMillis; + + difference += 0.5*((recordedPositionMillis - playingPositionMillis)-difference); // difference -= (recordedPositionTimeSent - playingPositionTimeSent); //suppose we project that we will align in 1 seconds time double projectedAlignmentTime = 1000; //then our current speed projects forward - double predictedPlayingTimeIncrease = projectedAlignmentTime*speed; + double predictedPlayingTimeIncrease = projectedAlignmentTime * smoothedSpeedOutput;//speed; difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); - double tmpSpeed = speed; - speed += difference/projectedAlignmentTime; + double tmpSpeed = smoothedSpeedOutput; + speed = smoothedSpeedOutput + (difference/projectedAlignmentTime); - sendSpeed(speed); + smoothedSpeedOutput = movingAverageWeighting*speed + (1- movingAverageWeighting)*tmpSpeed; + + sendSpeed(smoothedSpeedOutput); if (counter % 10 == 0){ printf("SYNC: rec pos %f play pos %f, diff %f\n", recordedPositionMillis, playingPositionMillis, recordedPositionMillis - playingPositionMillis); @@ -81,5 +85,10 @@ m.setAddress( "/setSpeed" ); m.addFloatArg( val ); sender.sendMessage( m ); + + ofxOscMessage z; + z.setAddress( "/syncDifference" ); + z.addFloatArg( difference ); + sender.sendMessage( z ); } } \ No newline at end of file