Mercurial > hg > multitrack-audio-matcher
comparison src/AudioEventMatcher.cpp @ 18:4ded82fe318d
added pitch info at top of page
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 07 Feb 2012 02:37:04 +0000 |
parents | c96b18dd0f48 |
children | 1a62561bd72d |
comparison
equal
deleted
inserted
replaced
17:c96b18dd0f48 | 18:4ded82fe318d |
---|---|
127 drawBayesianDistributions(); | 127 drawBayesianDistributions(); |
128 | 128 |
129 //bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); | 129 //bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); |
130 //bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); | 130 //bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); |
131 //bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); | 131 //bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); |
132 | 132 string tmpStr = "pitch "+ofToString(recentPitch, 2); |
133 ofDrawBitmapString("pitch "+ofToString(recentPitch, 2)+", Time "+ofToString(recentTime, 0), 20, 20); | 133 tmpStr += " Nearest "+ofToString(pitchOfNearestMatch,2); |
134 tmpStr += " dist "+ofToString(distanceOfNearestMatch, 2); | |
135 tmpStr += ", Time "+ofToString(recentTime, 0); | |
136 ofDrawBitmapString(tmpStr, 20, 20); | |
137 | |
138 | |
134 | 139 |
135 string alignString = " align "+ofToString(currentAlignmentPosition, 2); | 140 string alignString = " align "+ofToString(currentAlignmentPosition, 2); |
136 alignString += " playing "+ofToString(synchroniser.playingPositionRatio, 5); | 141 alignString += " playing "+ofToString(synchroniser.playingPositionRatio, 5); |
137 alignString += " pos "+ofToString(synchroniser.playingPositionMillis,0)+" ms"; | 142 alignString += " pos "+ofToString(synchroniser.playingPositionMillis,0)+" ms"; |
138 alignString += " rec pos "+ofToString(synchroniser.recordedPositionMillis,0)+" ms"; | 143 alignString += " rec pos "+ofToString(synchroniser.recordedPositionMillis,0)+" ms"; |
321 //set the lielihoods by matching the pitched note | 326 //set the lielihoods by matching the pitched note |
322 | 327 |
323 | 328 |
324 int numberOfMatches = 0; | 329 int numberOfMatches = 0; |
325 bayesianStruct.likelihood.zero();//set to zero | 330 bayesianStruct.likelihood.zero();//set to zero |
331 double newOnsetTime; | |
332 double closestDistance = INFINITY; | |
326 | 333 |
327 double quantity = 0; | 334 double quantity = 0; |
328 if (channel <= recordedTracks.numberOfAudioTracks){ | 335 if (channel <= recordedTracks.numberOfAudioTracks){ |
329 for (int i = 0;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){ | 336 for (int i = 0;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){ |
330 | 337 |
331 if (checkMatch(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn)) { | 338 if (checkMatch(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn)) { |
332 quantity = getPitchDistance(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn, 16); | 339 quantity = getPitchDistance(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn, 8); |
340 | |
333 bayesianStruct.likelihood.addGaussianShapeFromRealTime(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime, 30, quantity); | 341 bayesianStruct.likelihood.addGaussianShapeFromRealTime(recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime, 30, quantity); |
334 recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = true; | 342 recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = true; |
335 numberOfMatches++; | 343 numberOfMatches++; |
336 } | 344 } |
337 else{ | 345 else{ |
338 recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = false; | 346 recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = false; |
339 } | 347 } |
348 //checking nearest pitch | |
349 newOnsetTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; | |
350 if (abs(newOnsetTime - currentAlignmentPosition) < closestDistance){ | |
351 closestDistance = abs(newOnsetTime - currentAlignmentPosition); | |
352 pitchOfNearestMatch = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch; | |
353 distanceOfNearestMatch = quantity; | |
354 } | |
340 | 355 |
341 } | 356 } |
342 } | 357 } |
343 | 358 |
344 | 359 |
362 | 377 |
363 } | 378 } |
364 | 379 |
365 double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){ | 380 double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){ |
366 | 381 |
367 double scaleFactor = scale ;//* pitchOne / 110.0; | 382 double scaleFactor = scale * pitchOne / 110.0; |
368 | 383 |
369 | 384 int multiplicationFactor = 1; |
370 double distance = abs(pitchOne - pitchTwo); | 385 if (pitchTwo > 0){ |
386 int multiplicationFactor = round(pitchOne/pitchTwo); | |
387 } | |
388 | |
389 double distance = abs(pitchOne - pitchTwo*multiplicationFactor); | |
371 if (distance < scaleFactor) | 390 if (distance < scaleFactor) |
372 distance = 1 - (distance/scaleFactor); | 391 distance = 1 - (distance/scaleFactor); |
373 else | 392 else |
374 distance = 0; | 393 distance = 0; |
375 | 394 |
378 | 397 |
379 } | 398 } |
380 | 399 |
381 | 400 |
382 bool AudioEventMatcher::checkMatch(const double& recordedPitch, const double& livePitch){ | 401 bool AudioEventMatcher::checkMatch(const double& recordedPitch, const double& livePitch){ |
383 if (abs(recordedPitch - livePitch) < 16) | 402 |
403 if (livePitch > 0){ | |
404 int multiplicationFactor = (int)(round(recordedPitch/livePitch)); | |
405 | |
406 if (abs(recordedPitch - livePitch * multiplicationFactor) < 16) | |
384 return true; | 407 return true; |
385 else | 408 else |
386 return false; | 409 return false; |
410 }else { | |
411 return false; | |
412 } | |
413 | |
387 } | 414 } |
388 | 415 |
389 | 416 |
390 | 417 |
391 void AudioEventMatcher::windowResized(const int& w, const int& h){ | 418 void AudioEventMatcher::windowResized(const int& w, const int& h){ |