comparison src/AudioEventMatcher.cpp @ 36:eb43b2a007ea

changed newMatchOnset to have different way to calculate onsets vs noise, using the onsetLikelihoodNoise factor
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 24 Apr 2012 01:19:24 +0100
parents 6fb77b20413c
children 9806a4f22fd0
comparison
equal deleted inserted replaced
35:6fb77b20413c 36:eb43b2a007ea
8 */ 8 */
9 9
10 #include "AudioEventMatcher.h" 10 #include "AudioEventMatcher.h"
11 11
12 12
13 const int matchWindowWidth = 6000; 13 const int matchWindowWidth = 8000;
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 useChromaDotProduct = false;
19 19
20 pitchLikelihoodToNoise = 0.6;//more noise 20 pitchLikelihoodToNoise = 0.6;//more noise
21 chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events 21 chromaLikelihoodToNoise = 0.5;//lower => more noise, higher more weight for events
22 chromaLikelihoodWidth = 50;//ms round onset event 22 chromaLikelihoodWidth = 50;//ms round onset event
23 23
24 onsetLikelihoodToNoise = 0.4; 24 onsetLikelihoodToNoise = 0.1;
25 onsetLikelihoodWidth = 10;//in ms 25 onsetLikelihoodWidth = 10;//in ms
26 26
27 setArraySizes(); 27 setArraySizes();
28 28
29 usingRealTime = false; 29 usingRealTime = false;
57 bayesianStruct.resetSpeedSize(200); 57 bayesianStruct.resetSpeedSize(200);
58 bayesianStruct.setRelativeSpeedScalar(0.01); 58 bayesianStruct.setRelativeSpeedScalar(0.01);
59 bayesianStruct.setSpeedPrior(1.0); 59 bayesianStruct.setSpeedPrior(1.0);
60 bayesianStruct.relativeSpeedPrior.getMaximum(); 60 bayesianStruct.relativeSpeedPrior.getMaximum();
61 61
62 bayesianStruct.resetSize(matchWindowWidth); 62 float scalarForBayesianDistribution = 2;
63 bayesianStruct.setPositionDistributionScalar(1); 63
64 bayesianStruct.resetSize(matchWindowWidth / scalarForBayesianDistribution);
65 bayesianStruct.setPositionDistributionScalar(2);
64 66
65 } 67 }
66 68
67 void AudioEventMatcher::loadAudioFiles(){ 69 void AudioEventMatcher::loadAudioFiles(){
68 recordedTracks.loadTestAudio(); 70 recordedTracks.loadTestAudio();
137 recordedTempo = recordedTempoData.globalTempo[recordedTempoIndex]; 139 recordedTempo = recordedTempoData.globalTempo[recordedTempoIndex];
138 140
139 currentSpeedRatio = 1; 141 currentSpeedRatio = 1;
140 142
141 temporal.tempoPosterior.zero(); 143 temporal.tempoPosterior.zero();
142 temporal.tempoPosterior.addGaussianShapeFromRealTime(recordedTempo, 10, 1); 144 temporal.tempoPosterior.addGaussianShapeFromRealTime(recordedTempo, 2000, 1);
143 145
144 //SET TEMPO PRIOR for Speed Ratio 146 //SET TEMPO PRIOR for Speed Ratio
145 //the update this 147 //the update this
146 setSpeedRatioDistribution(currentSpeedRatio); 148 setSpeedRatioDistribution(currentSpeedRatio);
147 //bayesianStruct.posterior.printArray(); 149 //bayesianStruct.posterior.printArray();
449 bayesianStruct.updateBayesianDistributions(timeIn);//moves the posterior up into prior given the time interval and calculates new offsets 451 bayesianStruct.updateBayesianDistributions(timeIn);//moves the posterior up into prior given the time interval and calculates new offsets
450 452
451 //start at beginning but OPTIMISE later 453 //start at beginning but OPTIMISE later
452 bayesianStruct.likelihood.offset = bayesianStruct.prior.offset; 454 bayesianStruct.likelihood.offset = bayesianStruct.prior.offset;
453 bayesianStruct.likelihood.zero();//set to zero 455 bayesianStruct.likelihood.zero();//set to zero
454 456 //double quantity = 1;//
455 double quantity = 1;//likelihoodToNoiseRatio / numberOfMatches; 457 double quantity = 1*onsetLikelihoodToNoise;//BETTER CHANGE THIS BACK TOO..see below//likelihoodToNoiseRatio / numberOfMatches;
456 int numberOfMatchesFound = 0; 458 int numberOfMatchesFound = 0;
457 459
458 double startMatchingTime = bayesianStruct.likelihood.offset; 460 double startMatchingTime = bayesianStruct.likelihood.offset;
459 double endMatchingTime = bayesianStruct.likelihood.offset + matchWindowWidth; 461 double endMatchingTime = bayesianStruct.likelihood.offset + matchWindowWidth;
460 double millisTime = -1*INFINITY;//or 0 is fine 462 double millisTime = -1*INFINITY;//or 0 is fine
461 int checkIndex = 0; 463 int checkIndex = 0;
462 if (channel <= recordedTracks.numberOfAudioTracks){ 464 if (channel <= recordedTracks.numberOfAudioTracks && checkIndex < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size()){
463 while (millisTime < startMatchingTime) { 465 while (millisTime < startMatchingTime) {
464 millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[checkIndex].millisTime; 466 millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[checkIndex].millisTime;
465 checkIndex++; 467 checkIndex++;
466 } 468 }
467 for (int i = checkIndex;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size() && millisTime <= endMatchingTime;i++){ 469 for (int i = checkIndex;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size() && millisTime <= endMatchingTime;i++){
475 } 477 }
476 } 478 }
477 479
478 if (numberOfMatchesFound > 0){ 480 if (numberOfMatchesFound > 0){
479 // bayesianStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesianStruct.likelihood.length); 481 // bayesianStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesianStruct.likelihood.length);
480 bayesianStruct.likelihood.addConstant(numberOfMatchesFound*(1-onsetLikelihoodToNoise)/(onsetLikelihoodToNoise*bayesianStruct.likelihood.length)); 482 // bayesianStruct.likelihood.addConstant(numberOfMatchesFound*(1-onsetLikelihoodToNoise)/(onsetLikelihoodToNoise*bayesianStruct.likelihood.length));
483 bayesianStruct.likelihood.addConstant(numberOfMatchesFound*(1-onsetLikelihoodToNoise)/(bayesianStruct.likelihood.length));//BETTER CHANGE THIS BACK...
481 bayesianStruct.likelihood.renormalise(); 484 bayesianStruct.likelihood.renormalise();
482 485
483 bayesianStruct.calculatePosterior(); 486 bayesianStruct.calculatePosterior();
484 lastAlignmentTime = timeIn;//use TIMESTAMP 487 lastAlignmentTime = timeIn;//use TIMESTAMP
485 recentEventTime[channel] = timeIn;//ofGetElapsedTimeMillis() - startTime; 488 recentEventTime[channel] = timeIn;//ofGetElapsedTimeMillis() - startTime;