Mercurial > hg > multitrack-audio-matcher
diff src/AudioEventMatcher.cpp @ 8:572564b7cb85
added calculation posterior into both onset and pitch processes
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Fri, 03 Feb 2012 13:28:59 +0000 |
parents | 33dedfe32893 |
children | bc62266af280 |
line wrap: on
line diff
--- a/src/AudioEventMatcher.cpp Thu Feb 02 21:55:51 2012 +0000 +++ b/src/AudioEventMatcher.cpp Fri Feb 03 13:28:59 2012 +0000 @@ -19,6 +19,7 @@ usingRealTime = false; bayesianStruct.realTimeMode = &usingRealTime; recentPitch = 0; + currentAlignmentPosition = 0; } void AudioEventMatcher::setWindowDimensions(){ @@ -46,9 +47,16 @@ void AudioEventMatcher::startPlaying(){ bayesianStruct.setStartPlaying(); + currentAlignmentPosition = 0; + startTime = ofGetElapsedTimeMillis(); //bayesianStruct.posterior.printArray(); } +void AudioEventMatcher::updateBestAlignmentPosition(){ + currentAlignmentPosition = bayesianStruct.posterior.offset + bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate); + currentAlignmentPosition += (ofGetElapsedTimeMillis() - lastAlignmentTime) * bayesianStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesianStruct.relativeSpeedPosterior.MAPestimate); +} + void AudioEventMatcher::draw(){ //draw some outlines in blue ofSetColor(20,200,200); @@ -64,6 +72,7 @@ // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); drawBayesianDistributions(); + // bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); //bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); @@ -88,14 +97,9 @@ string tmpString = "start "+ofToString(screenStartTimeMillis)+" (index "+ofToString(startIndex)+"), end "+ofToString(screenEndTimeMillis); ofDrawBitmapString(tmpString, bayesPositionWindow.x+20, bayesPositionWindow.y+20); - +// bayesianStruct.likelihood.drawConstrainedVector(startIndex, endIndex, 0, ofGetWidth(), bayesLikelihoodWindow); - bayesianStruct.likelihood.drawConstrainedVector(startIndex, endIndex, 0, ofGetWidth(), bayesLikelihoodWindow); - - - //bayesianStruct.likelihood.drawVector(bayesianStruct.likelihood.getRealTermsAsIndex(0), bayesianStruct.likelihood.getRealTermsAsIndex(screenWidthMillis), bayesLikelihoodWindow); - bayesianStruct.relativeSpeedPosterior.drawConstrainedVector(0, bayesianStruct.relativeSpeedPosterior.arraySize, 0, ofGetWidth(), bayesTempoWindow); string tmpStr = "zero is "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(0)); @@ -105,15 +109,28 @@ tmpStr = "best est "+ofToString(bayesianStruct.bestEstimate); ofDrawBitmapString(tmpStr, 20, 180); - ofDrawBitmapString("screenamp "+ofToString(screenWidthMillis), 20, 100); + ofDrawBitmapString("screenwidth "+ofToString(screenWidthMillis), 20, 800); - + ofSetColor(0,255,0); + double currentEstimateIndex = (currentAlignmentPosition - screenStartTimeMillis)*ofGetWidth()/screenWidthMillis; + ofLine(currentEstimateIndex, bayesPositionWindow.y, currentEstimateIndex, bayesPositionWindow.y + bayesPositionWindow.height); //draw track by track likelihoods for (int i = 0; i <recordedTracks.numberOfAudioTracks;i++){ ofSetColor(200,255,50); - likelihoodVisualisation[i].drawConstrainedVector(startIndex, endIndex, 0, ofGetWidth(), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window); + likelihoodVisualisation[i].drawConstrainedVector(likelihoodVisualisation[i].getRealTermsAsIndex(screenStartTimeMillis), likelihoodVisualisation[i].getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window); + ofSetColor(255); + ofDrawBitmapString("recent event "+ofToString(recentEventTime[i]), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.x + 20, recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.y + recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.height - 10); } + + int priorStartIndex = recentPrior.getRealTermsAsIndex(screenStartTimeMillis); + int priorEndIndex = recentPrior.getRealTermsAsIndex(screenEndTimeMillis); + ofSetColor(0,200,200); + recentPrior.drawConstrainedVector(priorStartIndex, priorEndIndex, 0, ofGetWidth(), bayesPositionWindow); + +// bayesianStruct.prior.addTriangularShape(100, 20, 0.4); + ofSetColor(255,0,100); + bayesianStruct.prior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesLikelihoodWindow); } @@ -133,6 +150,8 @@ recentPitch = pitchIn;//for drawing recentTime = timeIn; } + + } void AudioEventMatcher::newKickEvent(const double& timeIn){ @@ -166,7 +185,7 @@ bayesianStruct.updateBayesianDistributions(timeIn);//moves the posterior up into prior given the time interval and calculates new offsets //start at beginning but OPTIMISE later - double onsetLikelihoodToNoise = 0.3; + double onsetLikelihoodToNoise = 0.5; double likelihoodWidth = 40; @@ -194,10 +213,12 @@ // bayesianStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesianStruct.likelihood.length); bayesianStruct.likelihood.addConstant(numberOfMatchesFound*(1-onsetLikelihoodToNoise)/(onsetLikelihoodToNoise*bayesianStruct.likelihood.length)); - bayesianStruct.likelihood.renormalise(); - + bayesianStruct.calculatePosterior(); + + lastAlignmentTime = ofGetElapsedTimeMillis(); + recentEventTime[channel] = ofGetElapsedTimeMillis() - startTime; } @@ -208,10 +229,10 @@ bayesianStruct.updateBayesianDistributions(timeIn);//moves the posterior up into prior given the time interval and calculates new offsets - + //set the lielihoods by matching the pitched note - double pitchLikelihoodToNoise = 0.6;//more noise + double pitchLikelihoodToNoise = 0.5;//more noise int numberOfMatches = 0; bayesianStruct.likelihood.zero();//set to zero @@ -232,6 +253,9 @@ } } + recentPrior = bayesianStruct.prior; + + if (numberOfMatches > 0){//no point updating unless there is a match bayesianStruct.likelihood.addConstant(numberOfMatches*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length)); @@ -243,6 +267,8 @@ bayesianStruct.calculatePosterior(); } + lastAlignmentTime = ofGetElapsedTimeMillis(); + recentEventTime[channel] = ofGetElapsedTimeMillis() - startTime; } double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){