Mercurial > hg > multitrack-audio-matcher
comparison 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 |
comparison
equal
deleted
inserted
replaced
52:e359b9bad811 | 53:5274e3b5479d |
---|---|
13 //time sent is the live time since start of play | 13 //time sent is the live time since start of play |
14 | 14 |
15 AccompanimentSynchroniser::AccompanimentSynchroniser(){ | 15 AccompanimentSynchroniser::AccompanimentSynchroniser(){ |
16 sender.setup(HOST, SENDER_PORT); | 16 sender.setup(HOST, SENDER_PORT); |
17 counter = 0; | 17 counter = 0; |
18 movingAverageWeighting = 0.4; | |
18 reset(); | 19 reset(); |
19 } | 20 } |
20 | 21 |
21 void AccompanimentSynchroniser::reset(){ | 22 void AccompanimentSynchroniser::reset(){ |
22 | 23 |
28 | 29 |
29 recordedPositionMillis = 0; | 30 recordedPositionMillis = 0; |
30 recordedPositionTimeSent = 0; | 31 recordedPositionTimeSent = 0; |
31 | 32 |
32 speed = 1; | 33 speed = 1; |
33 | 34 smoothedSpeedOutput = 1; |
35 difference = 0; | |
34 | 36 |
35 } | 37 } |
36 | 38 |
37 void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){ | 39 void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){ |
38 playingPositionRatio = ratio; | 40 playingPositionRatio = ratio; |
49 | 51 |
50 | 52 |
51 void AccompanimentSynchroniser::updateOutputSpeed(){ | 53 void AccompanimentSynchroniser::updateOutputSpeed(){ |
52 //we want the playing position to more closely align with the recordedPosition | 54 //we want the playing position to more closely align with the recordedPosition |
53 | 55 |
54 | 56 |
55 double difference = recordedPositionMillis - playingPositionMillis; | 57 difference += 0.5*((recordedPositionMillis - playingPositionMillis)-difference); |
56 // difference -= (recordedPositionTimeSent - playingPositionTimeSent); | 58 // difference -= (recordedPositionTimeSent - playingPositionTimeSent); |
57 | 59 |
58 //suppose we project that we will align in 1 seconds time | 60 //suppose we project that we will align in 1 seconds time |
59 double projectedAlignmentTime = 1000; | 61 double projectedAlignmentTime = 1000; |
60 | 62 |
61 //then our current speed projects forward | 63 //then our current speed projects forward |
62 double predictedPlayingTimeIncrease = projectedAlignmentTime*speed; | 64 double predictedPlayingTimeIncrease = projectedAlignmentTime * smoothedSpeedOutput;//speed; |
63 difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); | 65 difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); |
64 double tmpSpeed = speed; | 66 double tmpSpeed = smoothedSpeedOutput; |
65 speed += difference/projectedAlignmentTime; | 67 speed = smoothedSpeedOutput + (difference/projectedAlignmentTime); |
66 | 68 |
67 sendSpeed(speed); | 69 smoothedSpeedOutput = movingAverageWeighting*speed + (1- movingAverageWeighting)*tmpSpeed; |
70 | |
71 sendSpeed(smoothedSpeedOutput); | |
68 | 72 |
69 if (counter % 10 == 0){ | 73 if (counter % 10 == 0){ |
70 printf("SYNC: rec pos %f play pos %f, diff %f\n", recordedPositionMillis, playingPositionMillis, recordedPositionMillis - playingPositionMillis); | 74 printf("SYNC: rec pos %f play pos %f, diff %f\n", recordedPositionMillis, playingPositionMillis, recordedPositionMillis - playingPositionMillis); |
71 printf("projected align diff %f at speed %f\n", (projectedAlignmentTime - predictedPlayingTimeIncrease), tmpSpeed); | 75 printf("projected align diff %f at speed %f\n", (projectedAlignmentTime - predictedPlayingTimeIncrease), tmpSpeed); |
72 printf("Final difference %f and speed output %f\n\n", difference, speed); | 76 printf("Final difference %f and speed output %f\n\n", difference, speed); |
79 if (val > -3 && val < 4){ | 83 if (val > -3 && val < 4){ |
80 ofxOscMessage m; | 84 ofxOscMessage m; |
81 m.setAddress( "/setSpeed" ); | 85 m.setAddress( "/setSpeed" ); |
82 m.addFloatArg( val ); | 86 m.addFloatArg( val ); |
83 sender.sendMessage( m ); | 87 sender.sendMessage( m ); |
88 | |
89 ofxOscMessage z; | |
90 z.setAddress( "/syncDifference" ); | |
91 z.addFloatArg( difference ); | |
92 sender.sendMessage( z ); | |
84 } | 93 } |
85 } | 94 } |