comparison src/AudioEventMatcher.cpp @ 19:1a62561bd72d

Added in tempo follower class that models the tempo of played events
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 09 Feb 2012 18:09:34 +0000
parents 4ded82fe318d
children 4f6006cac9de
comparison
equal deleted inserted replaced
18:4ded82fe318d 19:1a62561bd72d
29 29
30 30
31 31
32 followingLiveInput = true; 32 followingLiveInput = true;
33 startedPlaying = false; 33 startedPlaying = false;
34 } 34
35 temporal.setUpEventTimeMatrix();
36 }
37
38
35 39
36 40
37 void AudioEventMatcher::setWindowDimensions(){ 41 void AudioEventMatcher::setWindowDimensions(){
38 double startHeight = recordedTracks.numberOfAudioTracks * recordedTracks.trackScreenHeight; 42 double startHeight = recordedTracks.numberOfAudioTracks * recordedTracks.trackScreenHeight;
39 double heightAvailable = 1 - startHeight; 43 double heightAvailable = 1 - startHeight;
40 heightAvailable /= 3.0; 44 heightAvailable /= NUMBER_OF_CHANNELS;
41 45
42 bayesPositionWindow.setToRelativeSize(0, startHeight, 1, heightAvailable); 46 bayesPositionWindow.setToRelativeSize(0, startHeight, 1, heightAvailable);
43 bayesLikelihoodWindow.setToRelativeSize(0, startHeight + 1*heightAvailable, 1, heightAvailable); 47 bayesLikelihoodWindow.setToRelativeSize(0, startHeight + 1*heightAvailable, 1, heightAvailable);
44 bayesTempoWindow.setToRelativeSize(0, startHeight + 2*heightAvailable, 1, heightAvailable); 48 bayesTempoWindow.setToRelativeSize(0, startHeight + 2*heightAvailable, 1, heightAvailable);
45 49
69 startTime = ofGetElapsedTimeMillis(); 73 startTime = ofGetElapsedTimeMillis();
70 74
71 projectedPrior = bayesianStruct.prior; 75 projectedPrior = bayesianStruct.prior;
72 startedPlaying = true; 76 startedPlaying = true;
73 synchroniser.reset(); 77 synchroniser.reset();
78 temporal.reset();
74 79
75 //bayesianStruct.posterior.printArray(); 80 //bayesianStruct.posterior.printArray();
76 } 81 }
77 82
78 83
79 void AudioEventMatcher::stopPlaying(){ 84 void AudioEventMatcher::stopPlaying(){
80 startedPlaying = false; 85 startedPlaying = false;
86 temporal.printEventTimes();
81 } 87 }
82 88
83 void AudioEventMatcher::updatePosition(){ 89 void AudioEventMatcher::updatePosition(){
90
91 if (startedPlaying){
84 if (!followingLiveInput) 92 if (!followingLiveInput)
85 recordedTracks.updatePosition(); 93 recordedTracks.updatePosition();
86 else if (startedPlaying) 94 else
87 recordedTracks.updatePositionToMillis(currentAlignmentPosition); 95 recordedTracks.updatePositionToMillis(currentAlignmentPosition);
88 96
89 updateBestAlignmentPosition(); 97 updateBestAlignmentPosition();
98 }
99
100 temporal.tempoPosterior.addGaussianShape(temporal.tempoPosterior.MAPestimate, temporal.tempoArraySize / 4, 0.5 );
90 } 101 }
91 102
92 void AudioEventMatcher::updateBestAlignmentPosition(){ 103 void AudioEventMatcher::updateBestAlignmentPosition(){
93 //THIS DEALS WITH WHERE WE ARE NOW! ON THE SCREEN 104 //THIS DEALS WITH WHERE WE ARE NOW! ON THE SCREEN
94 //DIFFERENT TO WHEN EVENTS COME IN AS THEY ARE TIMESTAMPED - SO EG A PITCH EVENT MAY ARRIVE 16 CHROMA FRAMES LATER - BIG DIFFERENCE 105 //DIFFERENT TO WHEN EVENTS COME IN AS THEY ARE TIMESTAMPED - SO EG A PITCH EVENT MAY ARRIVE 16 CHROMA FRAMES LATER - BIG DIFFERENCE
221 bayesianStruct.prior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow); 232 bayesianStruct.prior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow);
222 233
223 ofSetColor(255,0,0); 234 ofSetColor(255,0,0);
224 projectedPrior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow); 235 projectedPrior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow);
225 236
237 temporal.drawTempoArray(bayesLikelihoodWindow);
238
226 } 239 }
227 240
228 void AudioEventMatcher::newPitchEvent(const int& channel, const double& pitchIn, const double& timeIn){ 241 void AudioEventMatcher::newPitchEvent(const int& channel, const double& pitchIn, const double& timeIn){
229 if (pitchIn > 0){ 242 if (pitchIn > 0){
230 liveInput.addPitchEvent(pitchIn, timeIn); 243 liveInput.addPitchEvent(pitchIn, timeIn);
304 lastAlignmentTime = timeIn;//use TIMESTAMP 317 lastAlignmentTime = timeIn;//use TIMESTAMP
305 recentEventTime[channel] = timeIn;//ofGetElapsedTimeMillis() - startTime; 318 recentEventTime[channel] = timeIn;//ofGetElapsedTimeMillis() - startTime;
306 319
307 recentPriors[channel] = bayesianStruct.prior; 320 recentPriors[channel] = bayesianStruct.prior;
308 projectedPrior = bayesianStruct.prior; 321 projectedPrior = bayesianStruct.prior;
322
323
324 temporal.updateTempo(channel, timeIn);
309 } 325 }
310 326
311 327
312 328
313 } 329 }
370 lastAlignmentTime = timeIn;//has to use the STAMPED time 386 lastAlignmentTime = timeIn;//has to use the STAMPED time
371 recentEventTime[channel] = timeIn; 387 recentEventTime[channel] = timeIn;
372 388
373 recentPriors[channel] = bayesianStruct.prior; 389 recentPriors[channel] = bayesianStruct.prior;
374 projectedPrior = bayesianStruct.prior; 390 projectedPrior = bayesianStruct.prior;
391
392 temporal.eventTimes[channel].push_back(timeIn);
375 } 393 }
376 394
377 395
378 } 396 }
379 397