Mercurial > hg > multitrack-audio-matcher
comparison src/AudioEventMatcher.cpp @ 2:179c09199b3c
bayesian vector now adding gaussians for kick onsets
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 31 Jan 2012 21:34:19 +0000 |
parents | 852173ca8365 |
children | 5e188c0035b6 |
comparison
equal
deleted
inserted
replaced
1:852173ca8365 | 2:179c09199b3c |
---|---|
8 */ | 8 */ |
9 | 9 |
10 #include "AudioEventMatcher.h" | 10 #include "AudioEventMatcher.h" |
11 | 11 |
12 | 12 |
13 const int matchWindowWidth = 1200; | 13 const int matchWindowWidth = 6000; |
14 | 14 |
15 AudioEventMatcher::AudioEventMatcher(){ | 15 AudioEventMatcher::AudioEventMatcher(){ |
16 | 16 |
17 bayesTempoWindow.setToRelativeSize(0, 0.6, 1, 0.2); | 17 bayesTempoWindow.setToRelativeSize(0, 0.6, 1, 0.2); |
18 bayesPositionWindow.setToRelativeSize(0, 0.8, 1, 0.2); | 18 bayesPositionWindow.setToRelativeSize(0, 0.8, 1, 0.2); |
34 | 34 |
35 void AudioEventMatcher::draw(){ | 35 void AudioEventMatcher::draw(){ |
36 //ofRect(20, 20, 300, 200); | 36 //ofRect(20, 20, 300, 200); |
37 | 37 |
38 recordedTracks.drawTracks(); | 38 recordedTracks.drawTracks(); |
39 bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); | 39 |
40 ofSetColor(255); | |
41 // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); | |
42 | |
43 double screenWidthMillis = recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.framesToMillis(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.amplitudeNumber); | |
44 | |
45 | |
46 bayesianStruct.likelihood.drawVector(0, screenWidthMillis, bayesTempoWindow); | |
40 | 47 |
41 } | 48 } |
42 | 49 |
43 | 50 |
44 void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){ | 51 void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){ |
45 liveInput.addPitchEvent(pitchIn, timeIn); | 52 liveInput.addPitchEvent(pitchIn, timeIn); |
46 //matchNewPitchEvent(); | 53 recordedTracks.matchNewPitchEvent(0, pitchIn, timeIn); |
54 } | |
55 | |
56 void AudioEventMatcher::newKickEvent(const double& timeIn){ | |
57 matchNewOnsetEvent(0, timeIn); | |
58 } | |
59 | |
60 | |
61 void AudioEventMatcher::newSnareEvent(const double& timeIn){ | |
62 matchNewOnsetEvent(0, timeIn); | |
63 } | |
64 | |
65 //Needs just to set bounds for the matching process, not have TimeIn | |
66 void AudioEventMatcher::matchNewOnsetEvent(const int& channel, const double& timeIn){ | |
67 //start at beginning but OPTIMISE later | |
68 double likelihoodToNoise = 0.5; | |
69 | |
70 double likelihoodWidth = 40; | |
71 | |
72 bayesianStruct.likelihood.offset = bayesianStruct.prior.offset; | |
73 bayesianStruct.likelihood.zero();//set to zero | |
74 | |
75 double quantity = 1;//likelihoodToNoiseRatio / numberOfMatches; | |
76 int numberOfMatchesFound = 0; | |
77 | |
78 | |
79 double startTime = bayesianStruct.likelihood.offset; | |
80 double endTime = bayesianStruct.likelihood.offset + matchWindowWidth; | |
81 | |
82 if (channel <= recordedTracks.numberOfAudioTracks){ | |
83 for (int i = 0;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){ | |
84 double millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; | |
85 if (millisTime >= startTime && millisTime <= endTime){ | |
86 bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, likelihoodWidth, quantity); | |
87 numberOfMatchesFound++; | |
88 printf("Adding Gaussian for onset at time %f offset %f\n", millisTime, bayesianStruct.likelihood.offset); | |
89 | |
90 } | |
91 } | |
92 } | |
93 | |
94 bayesianStruct.likelihood.renormalise(); | |
95 | |
96 //bayesStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesStruct.likelihood.length); | |
97 | |
98 | |
47 } | 99 } |
48 | 100 |
49 | 101 |
50 void AudioEventMatcher::windowResized(const int& w, const int& h){ | 102 void AudioEventMatcher::windowResized(const int& w, const int& h){ |
51 recordedTracks.windowResized(w,h); | 103 recordedTracks.windowResized(w,h); |