Mercurial > hg > multitrack-audio-matcher
changeset 37:9806a4f22fd0
Fixed bugs in the likelohoods that caused some to zero when no events found.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 24 Apr 2012 14:16:01 +0100 |
parents | eb43b2a007ea |
children | 9c803369b229 |
files | bayesianArraySrc/BayesianArrayStructure.cpp src/AudioEventMatcher.cpp src/AudioEventMatcher.h src/LiveAudioInput.cpp src/TempoFollower.cpp src/testApp.cpp |
diffstat | 6 files changed, 79 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/bayesianArraySrc/BayesianArrayStructure.cpp Tue Apr 24 01:19:24 2012 +0100 +++ b/bayesianArraySrc/BayesianArrayStructure.cpp Tue Apr 24 14:16:01 2012 +0100 @@ -31,7 +31,7 @@ tmpBestEstimate = 0; crossUpdateTimeThreshold = 60; - priorWidth = 12; + priorWidth = 20; @@ -106,7 +106,9 @@ speedPriorValue = f; int index = relativeSpeedPosterior.getRealTermsAsIndex(speedPriorValue); relativeSpeedPosterior.zero(); - relativeSpeedPosterior.addGaussianShape(index, priorWidth, 0.9); + + //changed these a bit - still need to figure tempo process out properly + relativeSpeedPosterior.addGaussianShape(index, priorWidth, 1.9); relativeSpeedPosterior.addGaussianShape(relativeSpeedPosterior.getRealTermsAsIndex(1), 4, 1); printf("speed adding to index for 1 = %f\n", relativeSpeedPosterior.getRealTermsAsIndex(1));
--- a/src/AudioEventMatcher.cpp Tue Apr 24 01:19:24 2012 +0100 +++ b/src/AudioEventMatcher.cpp Tue Apr 24 14:16:01 2012 +0100 @@ -17,6 +17,8 @@ useChromaDotProduct = false; + printingData = false; + pitchLikelihoodToNoise = 0.6;//more noise chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events chromaLikelihoodWidth = 50;//ms round onset event @@ -146,6 +148,9 @@ //SET TEMPO PRIOR for Speed Ratio //the update this setSpeedRatioDistribution(currentSpeedRatio); + + euclideanMaximumDistance = 0; + //bayesianStruct.posterior.printArray(); } @@ -158,7 +163,7 @@ void AudioEventMatcher::stopPlaying(){ startedPlaying = false; - temporal.printEventTimes(); + //temporal.printEventTimes(); } void AudioEventMatcher::rescue(){ @@ -186,6 +191,7 @@ void AudioEventMatcher::updateRecordedTempo(){ //tempo of equivalent recorded position is updated + if (recordedTempoIndex < recordedTempoData.globalTempoTimes.size()){//if for debug while(currentAlignmentPosition > recordedTempoData.globalTempoTimes[recordedTempoIndex]){ recordedTempoIndex++; } @@ -194,6 +200,8 @@ currentSpeedRatio = temporal.playingTempo / recordedTempo; if (currentSpeedRatio != tmpRatio) setSpeedRatioDistribution(currentSpeedRatio); + + }//end if to prevent debug crash } void AudioEventMatcher::updateBestAlignmentPosition(){ @@ -343,10 +351,18 @@ ofSetColor(255,0,0);//projected prior in red projectedPrior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow); + //draw pitch + ofSetColor(0,100,255); + int index = getScreenWidthIndexOfEventTime(recentPitchEventTime); + //this window would be used (recordedTracks.loadedAudioFiles[1].fileLoader.onsetDetect.window); } +int AudioEventMatcher::getScreenWidthIndexOfEventTime(const double& time){ + return (time - screenStartTimeMillis)*ofGetWidth()/screenWidthMillis; +} + void AudioEventMatcher::drawTrackLikelihoods(){ //draw track by track likelihoods for (int i = 0; i <recordedTracks.numberOfAudioTracks;i++){ @@ -376,7 +392,7 @@ tmpStr = "pitch "+ofToString(recentPitch, 2); tmpStr += " Nearest "+ofToString(pitchOfNearestMatch,2); tmpStr += " dist "+ofToString(distanceOfNearestMatch, 2); - tmpStr += ", Time "+ofToString(recentTime, 0); + tmpStr += ", Time "+ofToString(recentPitchEventTime, 0); ofDrawBitmapString(tmpStr, 20, 20); string alignString = " align "+ofToString(currentAlignmentPosition, 2); @@ -400,7 +416,7 @@ likelihoodVisualisation[1] = bayesianStruct.likelihood; recentPitch = pitchIn;//for drawing - recentTime = timeIn; + recentPitchEventTime = timeIn; } } @@ -408,9 +424,11 @@ void AudioEventMatcher::newChromaEvent(const int& channel, float* chromaIn, const double& timeIn){ // could add event to the liveInput list? as in pitch event - printf("match chroma channel %i\n", channel); - for (int i = 0;i < 12;i++){ + if (printingData){ + printf("match chroma channel %i\n", channel); + for (int i = 0;i < 12;i++){ printf("chroma in[%i] = %f\n", i, chromaIn[i]); + } } matchNewChromaEvent(channel, chromaIn, timeIn);//main pitch matching fn @@ -544,9 +562,11 @@ - if (numberOfMatches > 0){//no point updating unless there is a match + if (numberOfMatches > 0 && totalLikelihoodAdded > 0){//no point updating unless there is a match //replacing numberOfMatches with totalLike below... - bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length)); + //bug here was that if totaladded = 0, we add then zero likelihood + bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-pitchLikelihoodToNoise)/(bayesianStruct.likelihood.length)); + // bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length)); //tmp set likelihood constant and calculate using that //bayesianStruct.likelihood.zero(); @@ -622,7 +642,8 @@ double millisTime = -1*INFINITY;//or 0 is fine int checkIndex = 0; - if (channel <= recordedTracks.numberOfAudioTracks){ + if (channel <= recordedTracks.numberOfAudioTracks && checkIndex < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size()){ + while (millisTime < startMatchingTime) { millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[checkIndex].millisTime; checkIndex++; @@ -644,19 +665,22 @@ // bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, onsetLikelihoodWidth, quantity); numberOfMatches++; totalLikelihoodAdded += quantity; - printf("Adding CHROMA Gaussian for onset at time %.1f dist %.3f\n", millisTime, quantity); + + //printf("Adding CHROMA Gaussian for onset at time %.1f dist %.3f\n", millisTime, quantity); }//end if within limits (changed so it now is 4 sure) } } - if (numberOfMatches > 0){//no point updating unless there is a match + if (numberOfMatches > 0 && totalLikelihoodAdded > 0){//no point updating unless there is a match //replacing numberOfMatches with totalLike below... printf("CHROMA HAS %i MATCHES\n", numberOfMatches); - bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-chromaLikelihoodToNoise)/(chromaLikelihoodToNoise*bayesianStruct.likelihood.length)); + bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-chromaLikelihoodToNoise)/(bayesianStruct.likelihood.length)); + //previous way + // bayesianStruct.likelihood.addConstant(totalLikelihoodAdded*(1-chromaLikelihoodToNoise)/(chromaLikelihoodToNoise*bayesianStruct.likelihood.length)); bayesianStruct.calculatePosterior(); lastAlignmentTime = timeIn;//has to use the STAMPED time @@ -688,6 +712,7 @@ double AudioEventMatcher::getChromaEuclideanDistance(float* chromaOne, float* chromaTwo){ double distance = 0; double total = 0; + // printf("\n"); for (int i = 0;i < 12;i++){ total += (chromaOne[i] - chromaTwo[i])*(chromaOne[i] - chromaTwo[i]); @@ -695,8 +720,15 @@ // total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); } - if (total > 0) - distance = 1.0/sqrt(total); + if (total > euclideanMaximumDistance) + euclideanMaximumDistance = total; + + distance = ((euclideanMaximumDistance - total)/ euclideanMaximumDistance);//i.e. 1 is + +// if (total > 0) + + +// distance = 1.0/sqrt(total); // printf("DISTANCE : %.3f\n", distance); return distance; }
--- a/src/AudioEventMatcher.h Tue Apr 24 01:19:24 2012 +0100 +++ b/src/AudioEventMatcher.h Tue Apr 24 14:16:01 2012 +0100 @@ -43,6 +43,7 @@ void drawInfo(); void setWindowDimensions(); + int getScreenWidthIndexOfEventTime(const double& time); void newPitchEvent(const int& channel, const double& pitchIn, const double& timeIn); void newKickEvent(const double& timeIn); @@ -82,7 +83,7 @@ bool startedPlaying; bool usingRealTime; - double recentPitch, recentTime; + double recentPitch, recentPitchEventTime; DynamicVector likelihoodVisualisation[numberOfChannels]; DynamicVector recentPriors[numberOfChannels]; @@ -126,5 +127,8 @@ double currentSpeedRatio; void drawPlayingTempo(); void setSpeedRatioDistribution(const double& speedRatio); + + double euclideanMaximumDistance; + bool printingData; }; #endif
--- a/src/LiveAudioInput.cpp Tue Apr 24 01:19:24 2012 +0100 +++ b/src/LiveAudioInput.cpp Tue Apr 24 14:16:01 2012 +0100 @@ -9,6 +9,10 @@ #include "LiveAudioInput.h" +//Keeping track of incoming events +//more useful as data than anything else. But in fact, not particularly useful it seems at present + + const double hopsize = 512;//check to see it agrees with ofxAubioOnsetDetector LiveAudioInput::LiveAudioInput(){ @@ -16,9 +20,6 @@ } - - - void LiveAudioInput::addPitchEvent(const double& pitch, const double& time){ AudioEvent e; @@ -32,22 +33,6 @@ } - -/* - //any point in this?? -void LiveAudioInput::addChromaEvent(const double& time){ - - AudioEvent e; - e.millisTime = time; - e.frameTime = millisToFrames(time); - - liveEvents.push_back(e); - //printf("live input pitch %f time %f ms == %f frames\n", pitch, time, e.frameTime); - numberOfEvents++; - -} -*/ - double LiveAudioInput::framesToMillis(const double& frameCount){ return ((frameCount*hopsize*1000.0)/44100.0); } @@ -55,4 +40,21 @@ double LiveAudioInput::millisToFrames(const double& millis){ return ((millis*44100.0)/(hopsize*1000.0)); -} \ No newline at end of file +} + + + +/* + //any point in this?? + void LiveAudioInput::addChromaEvent(const double& time){ + + AudioEvent e; + e.millisTime = time; + e.frameTime = millisToFrames(time); + + liveEvents.push_back(e); + //printf("live input pitch %f time %f ms == %f frames\n", pitch, time, e.frameTime); + numberOfEvents++; + + } + */ \ No newline at end of file
--- a/src/TempoFollower.cpp Tue Apr 24 01:19:24 2012 +0100 +++ b/src/TempoFollower.cpp Tue Apr 24 14:16:01 2012 +0100 @@ -117,7 +117,7 @@ double divisionInEighthNotes = intervalsToTest[k]; double testInterval = interval / divisionInEighthNotes; if (testTempoInterval(channel, testInterval, d)){ - printf("channel %i interval %i at division %.0f == tempo update %f\n", channel, interval, divisionInEighthNotes, testInterval); + //printf("channel %i interval %i at division %.0f == tempo update %f\n", channel, interval, divisionInEighthNotes, testInterval); div.push_back((int)divisionInEighthNotes); } }
--- a/src/testApp.cpp Tue Apr 24 01:19:24 2012 +0100 +++ b/src/testApp.cpp Tue Apr 24 14:16:01 2012 +0100 @@ -83,10 +83,11 @@ int testChannel = m.getArgAsInt32(0); double timeIn = m.getArgAsFloat(1); float chromaIn[12]; + printf("CHROMA received at time %f\n", timeIn); for (int i = 0;i < 12;i++){ chromaIn[i] = m.getArgAsFloat(i+2); - printf("chroma[%i]: %f\n", i, chromaIn[i]); + // printf("chroma[%i]: %f\n", i, chromaIn[i]); } eventMatcher.newChromaEvent(testChannel, chromaIn, timeIn); }