Mercurial > hg > multitrack-audio-matcher
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:780def3a1f36 | 16:680ba08e9925 |
---|---|
1 /* | |
2 * AccompanimentSynchroniser.cpp | |
3 * MultipleAudioMathcher | |
4 * | |
5 * Created by Andrew on 06/02/2012. | |
6 * Copyright 2012 QMUL. All rights reserved. | |
7 * | |
8 */ | |
9 | |
10 #include "AccompanimentSynchroniser.h" | |
11 | |
12 AccompanimentSynchroniser::AccompanimentSynchroniser(){ | |
13 sender.setup(HOST, SENDER_PORT); | |
14 } | |
15 | |
16 void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){ | |
17 playingPositionRatio = ratio; | |
18 playingPositionSamples = ratio * fileLengthSamples; | |
19 playingPositionMillis = playingPositionSamples * 1000.0/44100.0; | |
20 playingPositionTimeSent = timePlayed; | |
21 } | |
22 | |
23 | |
24 void AccompanimentSynchroniser::updateRecordedPosition(const double& currentAlignmentPosition){ | |
25 recordedPositionMillis = currentAlignmentPosition; | |
26 } | |
27 | |
28 | |
29 void AccompanimentSynchroniser::updateOutputSpeed(){ | |
30 //we want the playing position to more closely align with the recordedPosition | |
31 | |
32 double difference = recordedPositionMillis - playingPositionMillis; | |
33 | |
34 //suppose we project that we will align in two seconds time | |
35 double projectedAlignmentTime = 2000; | |
36 | |
37 //then our current speed projects forward | |
38 double predictedPlayingTimeIncrease = projectedAlignmentTime*speed; | |
39 | |
40 difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); | |
41 | |
42 speed += difference/projectedAlignmentTime; | |
43 | |
44 sendSpeed(speed); | |
45 | |
46 } | |
47 | |
48 void AccompanimentSynchroniser::sendSpeed(double const& val){ | |
49 ofxOscMessage m; | |
50 m.setAddress( "/setSpeed" ); | |
51 m.addFloatArg( val ); | |
52 sender.sendMessage( m ); | |
53 } |