Mercurial > hg > multitrack-audio-matcher
diff src/AudioEventMatcher.cpp @ 4:45b5cf9be377
checking through Bayesian update procedure - working without cross update method.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 02 Feb 2012 12:13:44 +0000 |
parents | 5e188c0035b6 |
children | 5ef00d1dfe68 |
line wrap: on
line diff
--- a/src/AudioEventMatcher.cpp Wed Feb 01 16:05:26 2012 +0000 +++ b/src/AudioEventMatcher.cpp Thu Feb 02 12:13:44 2012 +0000 @@ -52,12 +52,16 @@ double screenWidthMillis = recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.framesToMillis(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.amplitudeNumber); + bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); + +// bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); + + bayesianStruct.likelihood.drawVector(bayesianStruct.likelihood.getRealTermsAsIndex(0), bayesianStruct.likelihood.getRealTermsAsIndex(screenWidthMillis), bayesLikelihoodWindow); bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); - bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); - + string tmpStr = "zero is "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(0)); tmpStr += " offsetis "+ofToString(bayesianStruct.posterior.offset); tmpStr += " screenWidth = "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis)); @@ -73,6 +77,12 @@ void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){ liveInput.addPitchEvent(pitchIn, timeIn); + + //tmp print stuff + printf("New pitch MAP post estimate now %i, ", bayesianStruct.posterior.MAPestimate); + double tmp = bayesianStruct.posterior.getMAPestimate(); + printf(" getting it %f and offset %f == %f ms\n", tmp, bayesianStruct.posterior.offset, bayesianStruct.posterior.getIndexInRealTerms(tmp)); + matchNewPitchEvent(0, pitchIn, timeIn); } @@ -159,6 +169,18 @@ bayesianStruct.likelihood.addConstant(numberOfMatches*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length)); recordedTracks.recentPitch = pitchIn; + + + //tmp set likelihood constant and calculate using that + bayesianStruct.likelihood.zero(); + bayesianStruct.likelihood.addConstant(1); + + bayesianStruct.calculatePosterior(); + + //tmp print stuff + printf("After CALC"); + printPostOffset(); + } double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){ @@ -195,34 +217,49 @@ void AudioEventMatcher::updateBayesianDistributions(const double& newEventTime){ //MOVE INTO bayesianStruct?? XX - - //NEED TO CHECK HERE THAT THEY HAVE THE SAME OFFSETS bayesianStruct.prior.copyFromDynamicVector(bayesianStruct.posterior);//try the otehr way //bayesianStruct.copyPriorToPosterior(); //need to get new MAP position and set the offset of the arrays //currently bestEstimate is the approx for the new MAP position - + int tmpMap = bayesianStruct.posterior.getMAPestimate(); + double timeDifference = newEventTime - bayesianStruct.lastEventTime; - printf("updating distributions at time %f diff %f\n", newEventTime, timeDifference); + printf("updating distributions at time %f diff %f offset %f tmpmap est %i\n", newEventTime, timeDifference, bayesianStruct.posterior.offset, tmpMap); //addnoise to the tempo distribution //bayesianStruct.decaySpeedDistribution(timeDifference); - + if (timeDifference > 50){ bayesianStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.); } bayesianStruct.updateBestEstimate(timeDifference); - bayesianStruct.lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); +// printf("set new distrb max 0 or %f\n", bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2)); + + //tmp print stuff + + printf("HALFWAY BEST "); + printPostOffset(); + bayesianStruct.setNewDistributionOffsets(max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2))); - bayesianStruct.crossUpdateArrays(bayesianStruct.posterior, bayesianStruct.relativeSpeedPosterior, timeDifference); - bayesianStruct.posterior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));// bayesianStruct.prior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2)); - + //i.e. using the same offset as prior + bayesianStruct.posterior.offset = bayesianStruct.prior.offset;// + +// float tmpPrior = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));// bayesianStruct.prior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2)); +// printf("Using prior offset of %f not %f\n", tmpPrior, bayesianStruct.prior.offset); + bayesianStruct.lastEventTime = newEventTime;//bayesianStruct.lastEventTime = ofGetElapsedTimeMillis(); + + } + +void AudioEventMatcher::printPostOffset(){ + double tmp = bayesianStruct.posterior.getMAPestimate(); + printf(" MAP index %i post offset %f == %f ms\n", bayesianStruct.posterior.MAPestimate, bayesianStruct.posterior.offset, bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate)); +} \ No newline at end of file