Mercurial > hg > multitrack-audio-matcher
annotate src/AccompanimentSynchroniser.cpp @ 16:680ba08e9925
Auto synchroniser added using the elastique~ object in max
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Mon, 06 Feb 2012 12:18:40 +0000 |
parents | |
children | c96b18dd0f48 |
rev | line source |
---|---|
andrew@16 | 1 /* |
andrew@16 | 2 * AccompanimentSynchroniser.cpp |
andrew@16 | 3 * MultipleAudioMathcher |
andrew@16 | 4 * |
andrew@16 | 5 * Created by Andrew on 06/02/2012. |
andrew@16 | 6 * Copyright 2012 QMUL. All rights reserved. |
andrew@16 | 7 * |
andrew@16 | 8 */ |
andrew@16 | 9 |
andrew@16 | 10 #include "AccompanimentSynchroniser.h" |
andrew@16 | 11 |
andrew@16 | 12 AccompanimentSynchroniser::AccompanimentSynchroniser(){ |
andrew@16 | 13 sender.setup(HOST, SENDER_PORT); |
andrew@16 | 14 } |
andrew@16 | 15 |
andrew@16 | 16 void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){ |
andrew@16 | 17 playingPositionRatio = ratio; |
andrew@16 | 18 playingPositionSamples = ratio * fileLengthSamples; |
andrew@16 | 19 playingPositionMillis = playingPositionSamples * 1000.0/44100.0; |
andrew@16 | 20 playingPositionTimeSent = timePlayed; |
andrew@16 | 21 } |
andrew@16 | 22 |
andrew@16 | 23 |
andrew@16 | 24 void AccompanimentSynchroniser::updateRecordedPosition(const double& currentAlignmentPosition){ |
andrew@16 | 25 recordedPositionMillis = currentAlignmentPosition; |
andrew@16 | 26 } |
andrew@16 | 27 |
andrew@16 | 28 |
andrew@16 | 29 void AccompanimentSynchroniser::updateOutputSpeed(){ |
andrew@16 | 30 //we want the playing position to more closely align with the recordedPosition |
andrew@16 | 31 |
andrew@16 | 32 double difference = recordedPositionMillis - playingPositionMillis; |
andrew@16 | 33 |
andrew@16 | 34 //suppose we project that we will align in two seconds time |
andrew@16 | 35 double projectedAlignmentTime = 2000; |
andrew@16 | 36 |
andrew@16 | 37 //then our current speed projects forward |
andrew@16 | 38 double predictedPlayingTimeIncrease = projectedAlignmentTime*speed; |
andrew@16 | 39 |
andrew@16 | 40 difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); |
andrew@16 | 41 |
andrew@16 | 42 speed += difference/projectedAlignmentTime; |
andrew@16 | 43 |
andrew@16 | 44 sendSpeed(speed); |
andrew@16 | 45 |
andrew@16 | 46 } |
andrew@16 | 47 |
andrew@16 | 48 void AccompanimentSynchroniser::sendSpeed(double const& val){ |
andrew@16 | 49 ofxOscMessage m; |
andrew@16 | 50 m.setAddress( "/setSpeed" ); |
andrew@16 | 51 m.addFloatArg( val ); |
andrew@16 | 52 sender.sendMessage( m ); |
andrew@16 | 53 } |