Mercurial > hg > multitrack-audio-matcher
comparison 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 |
comparison
equal
deleted
inserted
replaced
34:0d52ba6844b9 | 35:6fb77b20413c |
---|---|
13 const int matchWindowWidth = 6000; | 13 const int matchWindowWidth = 6000; |
14 const float pitchCutOff = 16;//within which pitches are even considered | 14 const float pitchCutOff = 16;//within which pitches are even considered |
15 | 15 |
16 AudioEventMatcher::AudioEventMatcher(){ | 16 AudioEventMatcher::AudioEventMatcher(){ |
17 | 17 |
18 useChromaDotProduct = false; | |
18 | 19 |
19 pitchLikelihoodToNoise = 0.6;//more noise | 20 pitchLikelihoodToNoise = 0.6;//more noise |
20 chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events | 21 chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events |
21 chromaLikelihoodWidth = 50;//ms round onset event | 22 chromaLikelihoodWidth = 50;//ms round onset event |
22 | 23 |
28 usingRealTime = false; | 29 usingRealTime = false; |
29 bayesianStruct.realTimeMode = &usingRealTime; | 30 bayesianStruct.realTimeMode = &usingRealTime; |
30 recentPitch = 0; | 31 recentPitch = 0; |
31 currentAlignmentPosition = 0; | 32 currentAlignmentPosition = 0; |
32 | 33 |
33 | |
34 | |
35 followingLiveInput = true; | 34 followingLiveInput = true; |
36 startedPlaying = false; | 35 startedPlaying = false; |
37 recordedTempoIndex = 0; | 36 recordedTempoIndex = 0; |
38 // temporal.setUpEventTimeMatrix(); | 37 // temporal.setUpEventTimeMatrix(); |
39 // recordedTempoData.setUpEventTimeMatrix(); | 38 // recordedTempoData.setUpEventTimeMatrix(); |
628 | 627 |
629 for (int i = checkIndex;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size() && millisTime <= endMatchingTime;i++){ | 628 for (int i = checkIndex;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size() && millisTime <= endMatchingTime;i++){ |
630 millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; | 629 millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; |
631 | 630 |
632 if (millisTime >= startMatchingTime && millisTime <= endMatchingTime){ | 631 if (millisTime >= startMatchingTime && millisTime <= endMatchingTime){ |
633 quantity = getChromaDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); | 632 |
633 if (useChromaDotProduct) | |
634 quantity = getChromaDotProductDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); | |
635 else | |
636 quantity = getChromaEuclideanDistance(chromaIn, &recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].chromaValues[0]); | |
637 | |
638 | |
634 bayesianStruct.likelihood.addGaussianShapeFromRealTime(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime, chromaLikelihoodWidth, quantity); | 639 bayesianStruct.likelihood.addGaussianShapeFromRealTime(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime, chromaLikelihoodWidth, quantity); |
635 | 640 |
636 // bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, onsetLikelihoodWidth, quantity); | 641 // bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, onsetLikelihoodWidth, quantity); |
637 numberOfMatches++; | 642 numberOfMatches++; |
638 totalLikelihoodAdded += quantity; | 643 totalLikelihoodAdded += quantity; |
661 } | 666 } |
662 | 667 |
663 } | 668 } |
664 | 669 |
665 | 670 |
666 double AudioEventMatcher::getChromaDistance(float* chromaOne, float* chromaTwo){ | 671 double AudioEventMatcher::getChromaDotProductDistance(float* chromaOne, float* chromaTwo){ |
667 double distance = 0; | 672 double distance = 0; |
668 double total = 0; | 673 double total = 0; |
669 for (int i = 0;i < 12;i++){ | 674 for (int i = 0;i < 12;i++){ |
670 distance += chromaOne[i]*chromaTwo[i]; | 675 distance += chromaOne[i]*chromaTwo[i]; |
671 total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); | 676 total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); |
672 } | 677 } |
673 | 678 |
674 distance /= sqrt(total); | 679 if (total > 0) |
680 distance /= sqrt(total); | |
681 | |
682 return distance; | |
683 } | |
684 | |
685 double AudioEventMatcher::getChromaEuclideanDistance(float* chromaOne, float* chromaTwo){ | |
686 double distance = 0; | |
687 double total = 0; | |
688 // printf("\n"); | |
689 for (int i = 0;i < 12;i++){ | |
690 total += (chromaOne[i] - chromaTwo[i])*(chromaOne[i] - chromaTwo[i]); | |
691 // printf("chroma1: %.2f; chroma2: %.2f\n", chromaOne[i], chromaTwo[i]); | |
692 // total += chromaOne[i]*chromaOne[i] + (chromaTwo[i]*chromaTwo[i]); | |
693 } | |
694 | |
695 if (total > 0) | |
696 distance = 1.0/sqrt(total); | |
697 // printf("DISTANCE : %.3f\n", distance); | |
675 return distance; | 698 return distance; |
676 } | 699 } |
677 | 700 |
678 void AudioEventMatcher::windowResized(const int& w, const int& h){ | 701 void AudioEventMatcher::windowResized(const int& w, const int& h){ |
679 recordedTracks.windowResized(w,h); | 702 recordedTracks.windowResized(w,h); |