Mercurial > hg > multitrack-audio-matcher
diff src/AudioEventMatcher.cpp @ 35:6fb77b20413c
updating multimatcher for euclidean distance in chroma too
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 08 Apr 2012 18:59:30 +0100 |
parents | 0d52ba6844b9 |
children | eb43b2a007ea |
line wrap: on
line diff
--- a/src/AudioEventMatcher.cpp Tue Apr 03 13:13:38 2012 +0100 +++ b/src/AudioEventMatcher.cpp Sun Apr 08 18:59:30 2012 +0100 @@ -15,6 +15,7 @@ AudioEventMatcher::AudioEventMatcher(){ + useChromaDotProduct = false; pitchLikelihoodToNoise = 0.6;//more noise chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events @@ -30,8 +31,6 @@ recentPitch = 0; currentAlignmentPosition = 0; - - followingLiveInput = true; startedPlaying = false; recordedTempoIndex = 0; @@ -630,7 +629,13 @@ millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; if (millisTime >= startMatchingTime && millisTime <= endMatchingTime){ - quantity = getChromaDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); + + if (useChromaDotProduct) + quantity = getChromaDotProductDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); + else + quantity = getChromaEuclideanDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); + + bayesianStruct.likelihood.addGaussianShapeFromRealTime(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime, chromaLikelihoodWidth, quantity); // bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, onsetLikelihoodWidth, quantity); @@ -663,7 +668,7 @@ } -double AudioEventMatcher::getChromaDistance(float* chromaOne, float* chromaTwo){ +double AudioEventMatcher::getChromaDotProductDistance(float* chromaOne, float* chromaTwo){ double distance = 0; double total = 0; for (int i = 0;i < 12;i++){ @@ -671,7 +676,25 @@ total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); } - distance /= sqrt(total); + if (total > 0) + distance /= sqrt(total); + + return distance; +} + +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]); +// printf("chroma1: %.2f; chroma2: %.2f\n", chromaOne[i], chromaTwo[i]); + // total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); + } + + if (total > 0) + distance = 1.0/sqrt(total); +// printf("DISTANCE : %.3f\n", distance); return distance; }