changeset 1:852173ca8365

Added class to hold recorded mulitracks
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 31 Jan 2012 17:35:30 +0000
parents c4f9e49226eb
children 179c09199b3c
files src/AudioEventMatcher.cpp src/AudioEventMatcher.h src/LiveAudioInput.cpp src/LiveAudioInput.h src/RecordedMultitrackAudio.cpp src/RecordedMultitrackAudio.h src/testApp.cpp src/testApp.h
diffstat 8 files changed, 252 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/AudioEventMatcher.cpp	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/AudioEventMatcher.cpp	Tue Jan 31 17:35:30 2012 +0000
@@ -35,6 +35,18 @@
 void AudioEventMatcher::draw(){
 	//ofRect(20, 20, 300, 200);
 	
+	recordedTracks.drawTracks();
 	bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow);
 	
+}
+
+
+void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){
+	liveInput.addPitchEvent(pitchIn, timeIn);
+	//matchNewPitchEvent();
+}
+
+
+void AudioEventMatcher::windowResized(const int& w, const int& h){
+	recordedTracks.windowResized(w,h);
 }
\ No newline at end of file
--- a/src/AudioEventMatcher.h	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/AudioEventMatcher.h	Tue Jan 31 17:35:30 2012 +0000
@@ -18,6 +18,7 @@
 #include "LiveAudioInput.h"
 #include "ofxWindowRegion.h"
 #include "BayesianArrayStructure.h"
+#include "RecordedMultitrackAudio.h"
 
 class AudioEventMatcher{
 	
@@ -28,9 +29,14 @@
 	
 	void draw();
 	
+	void newPitchEvent(const double& pitchIn, const double& timeIn);
+	
 	BayesianArrayStructure bayesianStruct;//hold the probability distriubtions
 	
 	LiveAudioInput liveInput;//hold the new events that come in
+	RecordedMultitrackAudio recordedTracks;
+	
+	void windowResized(const int& w, const int& h);
 	
 	ofxWindowRegion bayesTempoWindow;
 	ofxWindowRegion bayesPositionWindow;	
--- a/src/LiveAudioInput.cpp	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/LiveAudioInput.cpp	Tue Jan 31 17:35:30 2012 +0000
@@ -9,6 +9,35 @@
 
 #include "LiveAudioInput.h"
 
+const double hopsize = 512;//check to see it agrees with ofxAubioOnsetDetector
+
 LiveAudioInput::LiveAudioInput(){
+	numberOfEvents = 0;
+	
+}
 
+
+
+
+void LiveAudioInput::addPitchEvent(const double& pitch, const double& time){
+
+	AudioEvent e;
+	e.millisTime = time;
+	e.frameTime = millisToFrames(time);
+	e.pitch = pitch;
+	liveEvents.push_back(e);
+	printf("live input pitch %f time %f ms == %f frames\n", pitch, time, e.frameTime);
+	numberOfEvents++;
+	
+}
+
+
+
+double LiveAudioInput::framesToMillis(const double& frameCount){
+	return ((frameCount*hopsize*1000.0)/44100.0);
+}
+
+
+double LiveAudioInput::millisToFrames(const double& millis){
+	return ((millis*44100.0)/(hopsize*1000.0));
 }
\ No newline at end of file
--- a/src/LiveAudioInput.h	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/LiveAudioInput.h	Tue Jan 31 17:35:30 2012 +0000
@@ -24,14 +24,20 @@
 
 class LiveAudioInput{
 	
+	int numberOfEvents;
 public:
 	
+	
 	LiveAudioInput();
 	
 	typedef std::vector<AudioEvent> EventVector; 
 	
+	EventVector liveEvents;
 	
-
+	void addPitchEvent(const double& pitch, const double& time);
+	
+	double framesToMillis(const double& frameCount);
+	double millisToFrames(const double& millis);
 	
 };
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/RecordedMultitrackAudio.cpp	Tue Jan 31 17:35:30 2012 +0000
@@ -0,0 +1,106 @@
+/*
+ *  RecordedMultitrackAudio.cpp
+ *  MultipleAudioMathcher
+ *
+ *  Created by Andrew on 31/01/2012.
+ *  Copyright 2012 QMUL. All rights reserved.
+ *
+ */
+
+#include "RecordedMultitrackAudio.h"
+
+
+void RecordedMultitrackAudio::loadTestAudio(){
+	
+	
+	const char	*infilename = "../../../data/sound/bach4_short1.wav";	
+	
+	//LoadedAudioHolder lah;
+	//	lah.loadAudioFile(infilename);
+	//	loadedAudioFiles.push_back(lah);
+	
+	//Take care here - we need a pointer to create new instance
+	//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->loadAudioFile(infilename);
+	//	loadedAudioFiles.push_back(*loadedAudioPtr);
+	loadedAudioFiles[0] = *loadedAudioPtr;
+	
+	loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25);
+	
+	//	printf("Loaded audio %i\n", (int)numberOfAudioTracks);
+	printf("loaded max val  is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue);
+	
+	printf("BEFORE LOADING 1\n");
+	printInfo();
+	
+	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);
+	
+	printf("AFTER LOADING 1\n");
+	printInfo();
+	
+	numberOfAudioTracks = 2;
+	
+	
+}
+
+
+
+void RecordedMultitrackAudio::drawTracks(){
+	
+	for (int i = 0;i < numberOfAudioTracks;i++){		
+		loadedAudioFiles[i].draw();
+	}
+}
+
+
+void RecordedMultitrackAudio::updatePosition(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].updateToPlayPosition();
+}
+
+
+void RecordedMultitrackAudio::switchScreens(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].switchScreens();
+}
+
+
+void RecordedMultitrackAudio::togglePlay(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].togglePlay();
+}
+
+void RecordedMultitrackAudio::stop(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].stop();
+}
+
+
+void RecordedMultitrackAudio::printInfo(){
+	loadedAudioFiles[0].fileLoader.onsetDetect.printChromaInfo();
+	loadedAudioFiles[0].printEvents();
+}
+
+void RecordedMultitrackAudio::windowResized(const int& w, const int& h){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].windowResized(w, h);
+}
+
+void RecordedMultitrackAudio::zoomIn(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].fileLoader.zoomIn();
+}
+
+void RecordedMultitrackAudio::zoomOut(){
+	for (int i = 0;i < numberOfAudioTracks;i++)
+		loadedAudioFiles[i].fileLoader.zoomOut();
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/RecordedMultitrackAudio.h	Tue Jan 31 17:35:30 2012 +0000
@@ -0,0 +1,51 @@
+/*
+ *  RecordedMultitrackAudio.h
+ *  MultipleAudioMathcher
+ *
+ *  Created by Andrew on 31/01/2012.
+ *  Copyright 2012 QMUL. All rights reserved.
+ *
+ */
+
+
+#ifndef RECORDED_MULTITRACK_AUDIO_H
+#define RECORDED_MULTITRACK_AUDIO_H
+
+
+#include "ofMain.h"
+#include "ChromaOnset.h"
+#include "LoadedAudioHolder.h"
+
+/*
+ struct AudioEvent {
+	double millisTime;
+	double frameTime;
+	double pitch;
+	int type;
+};
+*/
+
+class RecordedMultitrackAudio{
+	
+	public:
+
+	
+	void loadTestAudio();
+	void updatePosition();
+	void drawTracks();
+	void switchScreens();
+	void togglePlay();
+	
+	void stop();
+	void printInfo();
+	void windowResized(const int& w, const int& h);
+	void zoomIn();
+	void zoomOut();
+	
+	
+	//variables
+	int numberOfAudioTracks;
+	LoadedAudioHolder* loadedAudioPtr;
+	LoadedAudioHolder loadedAudioFiles[5];
+};
+#endif
\ No newline at end of file
--- a/src/testApp.cpp	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/testApp.cpp	Tue Jan 31 17:35:30 2012 +0000
@@ -27,25 +27,35 @@
 
 	ofSetFrameRate(30);
 
-	LoadedAudioHolder lah;
+	
+	
+	eventMatcher.recordedTracks.loadTestAudio();
+	
+	
+	//audioFilePlayer.loadAudioFile(infilename);
+}
+/*
+void testApp::loadTestAudio(){
+	
+
 	const char	*infilename = "../../../data/sound/bach4_short1.wav";	
 	
+	//LoadedAudioHolder lah;
+	//	lah.loadAudioFile(infilename);
+	//	loadedAudioFiles.push_back(lah);
 	
-//	lah.loadAudioFile(infilename);
-//	loadedAudioFiles.push_back(lah);
-
 	//Take care here - we need a pointer to create new instance
 	//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->loadAudioFile(infilename);
-//	loadedAudioFiles.push_back(*loadedAudioPtr);
+	//	loadedAudioFiles.push_back(*loadedAudioPtr);
 	loadedAudioFiles[0] = *loadedAudioPtr;
 	
 	loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25);
 	
-//	printf("Loaded audio %i\n", (int)numberOfAudioTracks);
+	//	printf("Loaded audio %i\n", (int)numberOfAudioTracks);
 	printf("loaded max val  is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue);
 	
 	printf("BEFORE LOADING 1\n");
@@ -53,26 +63,21 @@
 	
 	loadedAudioPtr = new LoadedAudioHolder;
 	loadedAudioPtr->loadAudioFile(infilename);
-//	loadedAudioFiles.push_back(*loadedAudioPtr);
+	//	loadedAudioFiles.push_back(*loadedAudioPtr);
 	loadedAudioFiles[1] = *loadedAudioPtr;
 	loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25);
-	
-		printf("AFTER LOADING 1\n");
+
+	printf("AFTER LOADING 1\n");
 	keyPressed('p');
 	
-	numberOfAudioTracks = 2;
-	
-	
-	//audioFilePlayer.loadAudioFile(infilename);
 }
-
-
+ */
 
 //--------------------------------------------------------------
 void testApp::update(){
 
-	for (int i = 0;i < numberOfAudioTracks;i++)
-		loadedAudioFiles[i].updateToPlayPosition();
+	eventMatcher.recordedTracks.updatePosition();
+	
 //	audioFilePlayer.updateToPlayPosition();
 	
 	checkForOSCmessages();
@@ -88,11 +93,11 @@
 		receiver.getNextMessage( &m );
 		
 		// check for mouse moved message
-		if ( m.getAddress() == "/aubioPitch" )
-		{
+		if ( m.getAddress() == "/aubioPitch" ){
 			float pitchIn = m.getArgAsFloat(0); 
 			int timeIn = m.getArgAsInt32(1); 
 			printf("AUBIO PITCH RECEIVED %f at time %i\n", pitchIn, timeIn);
+			eventMatcher.newPitchEvent(pitchIn, timeIn);
 		}
 	}
 }
@@ -100,11 +105,6 @@
 //--------------------------------------------------------------
 void testApp::draw(){
 	
-	for (int i = 0;i < numberOfAudioTracks;i++){		
-		loadedAudioFiles[i].draw();
-	}
-		
-	
 	eventMatcher.draw();
 	
 //	audioFilePlayer.draw();
@@ -124,9 +124,7 @@
 	}
 
 	if (key == 'q'){
-		for (int i = 0;i < numberOfAudioTracks;i++)
-			loadedAudioFiles[i].switchScreens();
-//		audioFilePlayer.switchScreens();
+		eventMatcher.recordedTracks.switchScreens();
 	}
 	
 	if (key == OF_KEY_RIGHT){
@@ -141,16 +139,14 @@
 	
 	
 	if (key == ' '){
-		for (int i = 0;i < numberOfAudioTracks;i++)
-		loadedAudioFiles[i].togglePlay();
-//		audioFilePlayer.togglePlay();
+
+		eventMatcher.recordedTracks.togglePlay();
 	}
 
 	if (key == OF_KEY_RETURN){
-		for (int i = 0;i < numberOfAudioTracks;i++)
-		loadedAudioFiles[i].stop();
+		
 			
-//		audioFilePlayer.stop();
+		eventMatcher.recordedTracks.stop();
 	}
 	
 	
@@ -160,23 +156,17 @@
 	}
 
 	if (key == 'p'){
-		loadedAudioFiles[0].fileLoader.onsetDetect.printChromaInfo();
-		loadedAudioFiles[0].printEvents();
+
 	}
 
 	
 	if (key == OF_KEY_UP){
-		for (int i = 0;i < numberOfAudioTracks;i++)
-			loadedAudioFiles[i].fileLoader.zoomOut();
-//		audioFilePlayer.fileLoader.zoomOut();
+		eventMatcher.recordedTracks.zoomOut();
+	
 	}
 	
 	if (key == OF_KEY_DOWN){
-		for (int i = 0;i < numberOfAudioTracks;i++)
-			loadedAudioFiles[i].fileLoader.zoomIn();
-			
-	//	audioFilePlayer.fileLoader.zoomIn();
-
+		eventMatcher.recordedTracks.zoomIn();
 	}
 	
 }
@@ -211,9 +201,8 @@
 
 //--------------------------------------------------------------
 void testApp::windowResized(int w, int h){
-	for (int i = 0;i < numberOfAudioTracks;i++)
-	loadedAudioFiles[i].windowResized(w, h);
-	//audioFilePlayer.windowResized(w, h);
+	
+	eventMatcher.windowResized(w, h);
 	
 	
 }
@@ -238,7 +227,7 @@
 
 void testApp::loadNewAudio(string soundFileName){
 	
-	loadedAudioFiles[0].loadAudioFile(soundFileName);
+	eventMatcher.recordedTracks.loadedAudioFiles[0].loadAudioFile(soundFileName);
 	
 //	for (int i = 0;i < numberOfAudioTracks;i++)
 //		loadedAudioFiles[i].loadAudioFile(soundFileName);
--- a/src/testApp.h	Tue Jan 31 13:54:17 2012 +0000
+++ b/src/testApp.h	Tue Jan 31 17:35:30 2012 +0000
@@ -47,25 +47,18 @@
 
 		void audioRequested 	(float * input, int bufferSize, int nChannels);
 
+	//void loadTestAudio();
+	
 	void checkForOSCmessages();
 	
 	bool getFilenameFromDialogBox(string* fileNameToSave);
 	void openNewAudioFileWithdialogBox();		
 	void loadNewAudio(string soundFileName);
-	
-	typedef vector<LoadedAudioHolder> AudioFileVector;
-//	AudioFileVector loadedAudioFiles;
+
 
 	AudioEventMatcher eventMatcher;
-	
-	LoadedAudioHolder* loadedAudioPtr;
-	int numberOfAudioTracks;
-	
-	LoadedAudioHolder loadedAudioFiles[5];
-	
-//	LoadedAudioHolder audioFilePlayer;
-	
-//	LoadedAudioHolder bassFilePlayer;
+
+
 	
 	ofxOscReceiver	receiver;