Mercurial > hg > multitrack-audio-matcher
comparison src/RecordedMultitrackAudio.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 |
|---|---|
| 11 | 11 |
| 12 | 12 |
| 13 void RecordedMultitrackAudio::loadTestAudio(){ | 13 void RecordedMultitrackAudio::loadTestAudio(){ |
| 14 | 14 |
| 15 | 15 |
| 16 const char *infilename = "../../../data/sound/bach4_short1.wav"; | 16 const char *infilename = "../../../data/sound/basicClavScale.wav"; |
| 17 | 17 |
| 18 //LoadedAudioHolder lah; | 18 //LoadedAudioHolder lah; |
| 19 // lah.loadAudioFile(infilename); | 19 // lah.loadAudioFile(infilename); |
| 20 // loadedAudioFiles.push_back(lah); | 20 // loadedAudioFiles.push_back(lah); |
| 21 | 21 |
| 22 //Take care here - we need a pointer to create new instance | 22 //Take care here - we need a pointer to create new instance |
| 23 //but not then delete the instance before the vector of all audio tracks has been used | 23 //but not then delete the instance before the vector of all audio tracks has been used |
| 24 //the above code using lah has problem that it deletes objects once out of the scope of testApp.setup() | 24 //the above code using lah has problem that it deletes objects once out of the scope of testApp.setup() |
| 25 //when lah is in theory no longer used - something like that possible? - at least pointers to onset detection seem deleted | 25 //when lah is in theory no longer used - something like that possible? - at least pointers to onset detection seem deleted |
| 26 loadedAudioPtr = new LoadedAudioHolder; | 26 loadedAudioPtr = new LoadedAudioHolder(); |
| 27 loadedAudioPtr->loadAudioFile(infilename); | 27 loadedAudioPtr->loadAudioFile(infilename); |
| 28 // loadedAudioFiles.push_back(*loadedAudioPtr); | 28 // loadedAudioFiles.push_back(*loadedAudioPtr); |
| 29 loadedAudioFiles[0] = *loadedAudioPtr; | 29 loadedAudioFiles[0] = *loadedAudioPtr; |
| 30 | 30 |
| 31 loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25); | 31 loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25); |
| 32 loadedAudioFiles[0].setTrackType(0);// fileLoader.onsetDetect.trackType = 0; | |
| 32 | 33 |
| 33 // printf("Loaded audio %i\n", (int)numberOfAudioTracks); | 34 // printf("Loaded audio %i\n", (int)numberOfAudioTracks); |
| 34 printf("loaded max val is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue); | 35 printf("loaded max val is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue); |
| 35 | 36 |
| 36 printf("BEFORE LOADING 1\n"); | 37 printf("BEFORE LOADING 1\n"); |
| 37 printInfo(); | 38 printInfo(); |
| 38 | 39 |
| 40 infilename = "../../../data/sound/basicClavScale2.wav"; | |
| 41 | |
| 39 loadedAudioPtr = new LoadedAudioHolder; | 42 loadedAudioPtr = new LoadedAudioHolder; |
| 40 loadedAudioPtr->loadAudioFile(infilename); | 43 loadedAudioPtr->loadAudioFile(infilename); |
| 41 // loadedAudioFiles.push_back(*loadedAudioPtr); | 44 // loadedAudioFiles.push_back(*loadedAudioPtr); |
| 42 loadedAudioFiles[1] = *loadedAudioPtr; | 45 loadedAudioFiles[1] = *loadedAudioPtr; |
| 43 loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25); | 46 loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25); |
| 47 loadedAudioFiles[1].setTrackType(1); | |
| 48 // loadedAudioFiles[1].fileLoader.onsetDetect.trackType = 0; | |
| 44 | 49 |
| 45 printf("AFTER LOADING 1\n"); | 50 printf("AFTER LOADING 1\n"); |
| 46 printInfo(); | 51 printInfo(); |
| 47 | 52 |
| 48 numberOfAudioTracks = 2; | 53 numberOfAudioTracks = 2; |
| 55 void RecordedMultitrackAudio::drawTracks(){ | 60 void RecordedMultitrackAudio::drawTracks(){ |
| 56 | 61 |
| 57 for (int i = 0;i < numberOfAudioTracks;i++){ | 62 for (int i = 0;i < numberOfAudioTracks;i++){ |
| 58 loadedAudioFiles[i].draw(); | 63 loadedAudioFiles[i].draw(); |
| 59 } | 64 } |
| 65 | |
| 66 ofDrawBitmapString("pitch "+ofToString(recentPitch, 2), 20, 20); | |
| 60 } | 67 } |
| 61 | 68 |
| 62 | 69 |
| 63 void RecordedMultitrackAudio::updatePosition(){ | 70 void RecordedMultitrackAudio::updatePosition(){ |
| 64 for (int i = 0;i < numberOfAudioTracks;i++) | 71 for (int i = 0;i < numberOfAudioTracks;i++) |
| 65 loadedAudioFiles[i].updateToPlayPosition(); | 72 loadedAudioFiles[i].updateToPlayPosition(); |
| 73 } | |
| 74 | |
| 75 | |
| 76 void RecordedMultitrackAudio::matchNewPitchEvent(const int& channel, const double& pitchIn, const double& timeIn){ | |
| 77 //start at beginning but OPTIMISE later | |
| 78 | |
| 79 if (channel <= numberOfAudioTracks){ | |
| 80 for (int i = 0;i < loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){ | |
| 81 | |
| 82 if (checkMatch(loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn)) { | |
| 83 loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = true; | |
| 84 } | |
| 85 else{ | |
| 86 loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = false; | |
| 87 } | |
| 88 | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 recentPitch = pitchIn; | |
| 93 } | |
| 94 | |
| 95 bool RecordedMultitrackAudio::checkMatch(const double& recordedPitch, const double& livePitch){ | |
| 96 if (abs(recordedPitch - livePitch) < 40) | |
| 97 return true; | |
| 98 else | |
| 99 return false; | |
| 66 } | 100 } |
| 67 | 101 |
| 68 | 102 |
| 69 void RecordedMultitrackAudio::switchScreens(){ | 103 void RecordedMultitrackAudio::switchScreens(){ |
| 70 for (int i = 0;i < numberOfAudioTracks;i++) | 104 for (int i = 0;i < numberOfAudioTracks;i++) |
