diff 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
line wrap: on
line diff
--- a/src/RecordedMultitrackAudio.cpp	Tue Jan 31 17:35:30 2012 +0000
+++ b/src/RecordedMultitrackAudio.cpp	Tue Jan 31 21:34:19 2012 +0000
@@ -13,7 +13,7 @@
 void RecordedMultitrackAudio::loadTestAudio(){
 	
 	
-	const char	*infilename = "../../../data/sound/bach4_short1.wav";	
+	const char	*infilename = "../../../data/sound/basicClavScale.wav";	
 	
 	//LoadedAudioHolder lah;
 	//	lah.loadAudioFile(infilename);
@@ -23,12 +23,13 @@
 	//but not then delete the instance before the vector of all audio tracks has been used
 	//the above code using lah has problem that it deletes objects once out of the scope of testApp.setup()
 	//when lah is in theory no longer used - something like that possible? - at least pointers to onset detection seem deleted
-	loadedAudioPtr = new LoadedAudioHolder;
+	loadedAudioPtr = new LoadedAudioHolder();
 	loadedAudioPtr->loadAudioFile(infilename);
 	//	loadedAudioFiles.push_back(*loadedAudioPtr);
 	loadedAudioFiles[0] = *loadedAudioPtr;
 	
 	loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25);
+	loadedAudioFiles[0].setTrackType(0);//	fileLoader.onsetDetect.trackType = 0;
 	
 	//	printf("Loaded audio %i\n", (int)numberOfAudioTracks);
 	printf("loaded max val  is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue);
@@ -36,11 +37,15 @@
 	printf("BEFORE LOADING 1\n");
 	printInfo();
 	
+	infilename = "../../../data/sound/basicClavScale2.wav";	
+	
 	loadedAudioPtr = new LoadedAudioHolder;
 	loadedAudioPtr->loadAudioFile(infilename);
 	//	loadedAudioFiles.push_back(*loadedAudioPtr);
 	loadedAudioFiles[1] = *loadedAudioPtr;
 	loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25);
+	loadedAudioFiles[1].setTrackType(1);
+//	loadedAudioFiles[1].fileLoader.onsetDetect.trackType = 0;
 	
 	printf("AFTER LOADING 1\n");
 	printInfo();
@@ -57,6 +62,8 @@
 	for (int i = 0;i < numberOfAudioTracks;i++){		
 		loadedAudioFiles[i].draw();
 	}
+	
+	ofDrawBitmapString("pitch "+ofToString(recentPitch, 2), 20, 20);
 }
 
 
@@ -66,6 +73,33 @@
 }
 
 
+void RecordedMultitrackAudio::matchNewPitchEvent(const int& channel, const double& pitchIn, const double& timeIn){
+	//start at beginning but OPTIMISE later
+	
+	if (channel <= numberOfAudioTracks){
+		for (int i = 0;i < loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){
+			
+			if (checkMatch(loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].aubioPitch, pitchIn)) {
+				 loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = true;
+			 } 
+			 else{
+				 loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].matched = false;
+			 }
+			
+		 }
+	}
+	
+	recentPitch = pitchIn;
+}
+
+bool RecordedMultitrackAudio::checkMatch(const double& recordedPitch, const double& livePitch){
+	if (abs(recordedPitch - livePitch) < 40)
+		return true;
+	else
+		return false;
+}
+
+
 void RecordedMultitrackAudio::switchScreens(){
 	for (int i = 0;i < numberOfAudioTracks;i++)
 		loadedAudioFiles[i].switchScreens();