# HG changeset patch # User Andrew N Robertson # Date 1328530720 0 # Node ID 680ba08e99257af854d0cf164df781f00b4fca25 # Parent 780def3a1f3625104fbb4f8d743fc6356001c87a Auto synchroniser added using the elastique~ object in max diff -r 780def3a1f36 -r 680ba08e9925 src/AccompanimentSynchroniser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/AccompanimentSynchroniser.cpp Mon Feb 06 12:18:40 2012 +0000 @@ -0,0 +1,53 @@ +/* + * AccompanimentSynchroniser.cpp + * MultipleAudioMathcher + * + * Created by Andrew on 06/02/2012. + * Copyright 2012 QMUL. All rights reserved. + * + */ + +#include "AccompanimentSynchroniser.h" + +AccompanimentSynchroniser::AccompanimentSynchroniser(){ + sender.setup(HOST, SENDER_PORT); +} + +void AccompanimentSynchroniser::setPlayingRatio(const double& ratio, const double& timePlayed){ + playingPositionRatio = ratio; + playingPositionSamples = ratio * fileLengthSamples; + playingPositionMillis = playingPositionSamples * 1000.0/44100.0; + playingPositionTimeSent = timePlayed; +} + + +void AccompanimentSynchroniser::updateRecordedPosition(const double& currentAlignmentPosition){ + recordedPositionMillis = currentAlignmentPosition; +} + + +void AccompanimentSynchroniser::updateOutputSpeed(){ + //we want the playing position to more closely align with the recordedPosition + + double difference = recordedPositionMillis - playingPositionMillis; + + //suppose we project that we will align in two seconds time + double projectedAlignmentTime = 2000; + + //then our current speed projects forward + double predictedPlayingTimeIncrease = projectedAlignmentTime*speed; + + difference += (projectedAlignmentTime - predictedPlayingTimeIncrease); + + speed += difference/projectedAlignmentTime; + + sendSpeed(speed); + +} + +void AccompanimentSynchroniser::sendSpeed(double const& val){ + ofxOscMessage m; + m.setAddress( "/setSpeed" ); + m.addFloatArg( val ); + sender.sendMessage( m ); +} \ No newline at end of file diff -r 780def3a1f36 -r 680ba08e9925 src/AccompanimentSynchroniser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/AccompanimentSynchroniser.h Mon Feb 06 12:18:40 2012 +0000 @@ -0,0 +1,51 @@ +/* + * AccompanimentSynchroniser.h + * MultipleAudioMathcher + * + * Created by Andrew on 06/02/2012. + * Copyright 2012 QMUL. All rights reserved. + * + */ + + +#ifndef ACCOMPANIMENT_SYNCHRONISER_H +#define ACCOMPANIMENT_SYNCHRONISER_H + +#include "ofxOsc.h" +#define HOST "localhost" +#define SENDER_PORT 10875 + +#include "ofMain.h" + + +class AccompanimentSynchroniser{ + +public: + AccompanimentSynchroniser(); + + void setPlayingRatio(const double& ratio, const double& timePlayed); + void setRecordedPosition(); + void updateRecordedPosition(const double& currentAlignmentPosition); + + void updateOutputSpeed(); + + double fileLengthSamples; + + + + double playingPositionRatio; + double playingPositionSamples; + double playingPositionMillis; + double playingPositionTimeSent; + +private: + + double recordedPositionMillis; + + double speed; + + ofxOscSender sender; + void sendSpeed(double const& val); + +}; +#endif diff -r 780def3a1f36 -r 680ba08e9925 src/AudioEventMatcher.cpp --- a/src/AudioEventMatcher.cpp Sun Feb 05 22:08:50 2012 +0000 +++ b/src/AudioEventMatcher.cpp Mon Feb 06 12:18:40 2012 +0000 @@ -15,8 +15,9 @@ AudioEventMatcher::AudioEventMatcher(){ - pitchLikelihoodToNoise = 0.4;//more noise - onsetLikelihoodToNoise = 0.3; + pitchLikelihoodToNoise = 0.9;//more noise + + onsetLikelihoodToNoise = 0.4; onsetLikelihoodWidth = 20;//in ms setArraySizes(); @@ -56,6 +57,12 @@ } +void AudioEventMatcher::loadAudioFiles(){ + recordedTracks.loadTestAudio(); + synchroniser.fileLengthSamples = recordedTracks.loadedAudioFiles[0].fileLoader.totalNumberOfSamples; + printf("synchroniser has %f samples\n", synchroniser.fileLengthSamples); +} + void AudioEventMatcher::startPlaying(){ bayesianStruct.setStartPlaying(); currentAlignmentPosition = 0; @@ -92,6 +99,11 @@ currentAlignmentPosition = bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate); currentAlignmentPosition += (newTime - lastAlignmentTime) * bayesianStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesianStruct.relativeSpeedPosterior.MAPestimate); + + synchroniser.updateRecordedPosition(currentAlignmentPosition); + + synchroniser.updateOutputSpeed(); + bayesianStruct.projectDistribution(newTime, currentAlignmentPosition, projectedPrior);//prior gets updated to where we are now // printf("ALIGN pos %f time diff %f (now %f , last %f)speed %f :: ALIGN BEST %f\n", tmp, timetmp, (double)ofGetElapsedTimeMillis(), lastAlignmentTime, speedtmp, currentAlignmentPosition); @@ -118,6 +130,11 @@ ofDrawBitmapString("pitch "+ofToString(recentPitch, 2)+", Time "+ofToString(recentTime, 0), 20, 20); + string alignString = " align "+ofToString(currentAlignmentPosition, 2); + alignString += " playing "+ofToString(synchroniser.playingPositionRatio, 5); + alignString += " "+ofToString(synchroniser.playingPositionMillis)+" ms"; + ofDrawBitmapString(alignString, 20, 50); + ofDrawBitmapString("pos "+ofToString(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.playPosition), 200,600); } @@ -167,6 +184,13 @@ double currentEstimateIndex = (currentAlignmentPosition - screenStartTimeMillis)*ofGetWidth()/screenWidthMillis; ofLine(currentEstimateIndex, bayesPositionWindow.y, currentEstimateIndex, bayesPositionWindow.y + bayesPositionWindow.height); + + ofSetColor(0,255,255);//synchroniser position + currentEstimateIndex = (synchroniser.playingPositionMillis - screenStartTimeMillis)*ofGetWidth()/screenWidthMillis; + ofLine(currentEstimateIndex, bayesLikelihoodWindow.y, currentEstimateIndex, bayesLikelihoodWindow.y + bayesPositionWindow.height); + + + //draw track by track likelihoods for (int i = 0; i