changeset 1:ba2a17cf81bf

first working version of audio file loder. Loads bach clip from the apps->audio-file-loader->bin->data->sounds foler. Three classes: SoundFileLoader does the loading and parsing of thefile with libSndFile. audio samples are kept in AudioFile and analysis of features are kept in AudioAnalysis, at this stage just chromagramm and basic energy
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Sun, 04 Sep 2011 22:45:35 +0100
parents bcb0d40158f4
children fa2af670b5c5
files SoundFileLoader.cpp SoundFileLoader.h src/AudioAnalysis.cpp src/AudioAnalysis.h src/AudioFile.cpp src/AudioFile.h src/testApp.cpp src/testApp.h
diffstat 8 files changed, 295 insertions(+), 229 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoundFileLoader.cpp	Sun Sep 04 22:45:35 2011 +0100
@@ -0,0 +1,11 @@
+/*
+ *  SoundFileLoader.cpp
+ *  audioFileLoaderSVN1
+ *
+ *  Created by Andrew on 04/09/2011.
+ *  Copyright 2011 QMUL. All rights reserved.
+ *
+ */
+
+#include "SoundFileLoader.h"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoundFileLoader.h	Sun Sep 04 22:45:35 2011 +0100
@@ -0,0 +1,35 @@
+/*
+ *  SoundFileLoader.h
+ *  audioFileLoaderSVN1
+ *
+ *  Created by Andrew on 04/09/2011.
+ *  Copyright 2011 QMUL. All rights reserved.
+ *
+ */
+
+#ifndef SOUND_FILE_LOADER_H
+#define SOUND_FILE_LOADER_H
+
+
+#include "fftw3.h"
+#include "ofMain.h"
+#include "sndfile.h"
+#include "AudioFile.h"
+
+#define FRAMESIZE 512
+#define ENERGY_LENGTH 80000
+#define CHROMA_LENGTH 12000
+#define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
+
+
+//this does a chromagram analysis and aubio onset analysis
+//held in double matrix and doubleVector respectively
+//these are dynamic vectors, so size set by what's needed for the file
+
+class SoundFileLoader{
+	
+public:
+
+
+};
+#endif
--- a/src/AudioAnalysis.cpp	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/AudioAnalysis.cpp	Sun Sep 04 22:45:35 2011 +0100
@@ -10,6 +10,80 @@
 #include "AudioAnalysis.h"
 
 
+AudioAnalysis::AudioAnalysis(){
+	chromoGramm.initialise(FRAMESIZE,2048);
+
+	scrollWidth = 1600;
+	
+}
+
+
+
+void AudioAnalysis::drawEnergyVectorFromPointer(){
+	DoubleVector* energyVec;
+	energyVec = &energyVector;
+	//xxx above
+	
+	ofSetColor(0xFF0066);
+	float screenHeight = ofGetHeight() ;
+	float screenWidth = ofGetWidth();  
+	float heightFactor = 8;
+	int i, j, startingFrame;
+	startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
+	startingFrame *= scrollWidth;
+	
+	for (i = 0; i < scrollWidth - 1; i++){
+		j = i + startingFrame;
+		if (j < (*energyVec).size())
+			ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
+				   screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
+		
+	}
+}
+
+void AudioAnalysis::drawSpectralDifference(){
+	DoubleMatrix* dMatrix;
+	dMatrix = &chromaMatrix;
+	//get rid of these!
+	
+	int matrixSize = (*dMatrix).size();
+	if (matrixSize > 0){
+		
+		float screenHeight = ofGetHeight() ;
+		float screenWidth = ofGetWidth();
+		float heightFactor = 8;
+		double difference;
+		int i, j, startingFrame;
+		startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
+		startingFrame *= scrollWidth;//starting frame in terms of energy frames
+		startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
+		
+		float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
+		for (i = 1; i < chromoLength; i++){//changed to add 1
+			j = i + startingFrame;
+			for (int y = 0;y < 12;y++){			
+				
+				if (j < matrixSize)
+					difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
+				else 
+					difference = 0;
+				
+				if (difference < 0)
+					difference = 0;//half wave rectify
+				
+				ofSetColor(0,0,255 * difference);//, 0;
+				ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
+			}//end y
+		}//end i
+		
+	}///end if matrix has content
+	else{
+		printf("Error - please load audio first");
+	}
+	
+}
+
+
 /*
 void testApp::initialiseVariables(){
 	
@@ -147,109 +221,6 @@
 
 
 
-void testApp::processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){
-	
-	myDoubleMatrix->clear();
-	energyVector->clear();
-	
-	audioHolder.audioVector.clear();
-	audioHolder.audioMatrix.clear();
-	
-	energyIndex = 0;
-
-	chromaG->initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 
-	chromaG->maximumChromaValue = 0;
-	
-	
-	// HERE IS THE CLASSIC LOADING FILE CODE
-	//DEALS WITH MORE THAN MONO
-	int channels = sfinfo.channels;
-	int blocksize = FRAMESIZE;
-	
-	float buf [channels * blocksize] ;
-	int k, m, readcount ;
-	
-	DoubleVector d;
-	while ((readcount = sf_readf_float (infile, buf, blocksize)) > 0){
-		for (k = 0 ; k < readcount ; k++){	
-			d.clear();
-			for (m = 0 ; m < channels ; m++){
-				d.push_back(buf [k * channels + m]);
-				//		 fprintf (outfile, " % 12.10f", buf [k * channels + m]) ;
-				//		 fprintf (outfile, "\n") ;
-				if (m == 0){
-					//makes the vector hold the mono file
-					//this is the one we use for chromagram analysis etc
-					audioHolder.audioVector.push_back(buf[k * channels + 0]);
-					frame[k] = buf[k*channels + 0];
-				}
-				
-			} 
-			audioHolder.audioMatrix.push_back(d);
-			//storing the full soundfile in multiple channels in the audioMatrix
-		}
-		
-		
-		chromaG->processframe(frame);
-		
-		if (chromaG->chromaready)
-		{
-			DoubleVector d;
-			
-			for (int i = 0;i<12;i++){
-				//chromoGramVector[chromaIndex][i] = chromoGramm.rawChroma[i] / chromoGramm.maximumChromaValue;
-				d.push_back(chromaG->rawChroma[i]);// / chromaG->maximumChromaValue);	
-				
-			}	
-			
-			myDoubleMatrix->push_back(d);
-			
-			//There was a method to detect chord but deleted
-			//	chord.C_Detect(chromoGramm.chroma,chromoGramm.chroma_low);
-			//	rootChord[chromaIndex] = chord.root;
-			
-			
-		}//end if chromagRamm ready
-		
-		//	frameIndex++;
-		
-		//get energy of the current frame and wait
-		double energyValue = getEnergyOfFrame();
-		energyVector->push_back(energyValue);
-		
-		
-		
-	}//end readcount
-	
-	
-	
-	printf("Max chroma value is %f \n", chromaG->maximumChromaValue);
-	
-	
-	
-	//normalise
-	int length = myDoubleMatrix->size();
-	printf("length of chromagram is %d frames\n", length);
-	length = ((*myDoubleMatrix)[0]).size();
-	printf("height of dmatrix is %d\n", length);
-	
-	for (int i = 0; i < myDoubleMatrix->size();i++){
-		for (int j = 0; j < ((*myDoubleMatrix)[0]).size();j++){
-			(*myDoubleMatrix)[i][j] /= chromaG->maximumChromaValue;	
-		}
-	}
-	
-	
-	printf("size of energy vector is %d \n", (int) energyVector->size());
-	
-	totalNumberOfFrames = (int) energyVector->size();//frameIndex;//used to use this - but switch to energy vector's size instead
-	
-	//	printf("Total frames %i energy index %i and Chroma index %i \n", frameIndex, energyIndex, chromaIndex);
-	
-	printf("audio vector size is %i\n", (int) audioHolder.audioVector.size());
-	audioHolder.length = (int) audioHolder.audioVector.size();
-}
-
 */
 
 
--- a/src/AudioAnalysis.h	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/AudioAnalysis.h	Sun Sep 04 22:45:35 2011 +0100
@@ -19,6 +19,12 @@
 #include "ofxFileDialogOSX.h"
 #include "AudioFile.h"
 
+#define FRAMESIZE 512
+#define ENERGY_LENGTH 80000
+#define CHROMA_LENGTH 12000
+#define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
+
+
 //this does a chromagram analysis and aubio onset analysis
 //held in double matrix and doubleVector respectively
 //these are dynamic vectors, so size set by what's needed for the file
@@ -26,16 +32,55 @@
 class AudioAnalysis{
 
 public:
+	
+	AudioAnalysis();
+	
+	typedef std::vector<double> DoubleVector;
+	typedef std::vector<DoubleVector> DoubleMatrix;
+	
+	DoubleMatrix chromaMatrix;
+//	DoubleMatrix* matrixPtr;
+	DoubleVector energyVector;
+	
+	AudioFile* audioHolder;
+	void loadNewAudio(string soundFileName);//??
+	
+	Chromagram chromoGramm;
+	int currentPlayingFrame;
+	
+	ChordDetect chord;
+	
+	double getEnergyOfFrame();
+	int scrollWidth;
+	//int totalFrames;
+	void drawEnergyVectorFromPointer();
+	void drawSpectralDifference();
+	
 	/*
 	 double getEnergyOfFrame();
-	 //	void putEnergyInFrame();
+	
 	 
 	 void initialiseVariables();
 	 
+	 	 
+	 void initialiseVariables();
 	 
-	 typedef std::vector<double> DoubleVector;
-	 typedef std::vector<DoubleVector> DoubleMatrix;
+	 
+		 AudioFile audioHolder;
+	 
+	 void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET
 	
+	 
+	 DoubleVector firstEnergyVector;
+	 
+	 void drawEnergyVectorFromPointer(DoubleVector* energyVec);
+	 
+	 void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
+	 
+	 void loadNewAudio(string soundFileName);
+	 
+	 
+	 
 	 */
 	
 	
--- a/src/AudioFile.cpp	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/AudioFile.cpp	Sun Sep 04 22:45:35 2011 +0100
@@ -67,7 +67,7 @@
 		
 	}
 	*/
-	double firstXpos = 0;
+	double firstXpos = halfHeight;
 	double firstYpos = getPosition(startTimeSample);//screenHeight - ((1-audioVector[startTimeSample])*screenHeight/2.0);
 	
 	int stepSize = 1;//(int) samplesPerPixel); optimize !! XXX
--- a/src/AudioFile.h	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/AudioFile.h	Sun Sep 04 22:45:35 2011 +0100
@@ -16,6 +16,9 @@
 
 #include "ofMain.h"
 
+
+//fix bug where drawn before the start high up
+
 class AudioFile
 {
 public:		
@@ -24,9 +27,8 @@
 	
 	
 	
-		void drawAudioVectorMillis(double startTimeMillis, double endTimeMillis);
+	void drawAudioVectorMillis(double startTimeMillis, double endTimeMillis);
 	void drawAudioVectorSamples(double startTimeSample, double endTimeSample);
-	
 	double getPosition(int index);
 	
 	typedef std::vector<double> DoubleVector;
@@ -34,6 +36,7 @@
 	DoubleVector audioVector;
 	DoubleMatrix audioMatrix;
 	
+	
 	double screenHeight;
 	int length;
 	double audioScaleSamples;
--- a/src/testApp.cpp	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/testApp.cpp	Sun Sep 04 22:45:35 2011 +0100
@@ -14,6 +14,7 @@
 
 	ofBackground(255,255,255);
 
+	
 	// 2 output channels,
 	// 0 input channels
 	// 22050 samples per second
@@ -40,19 +41,19 @@
 	
 	ofSetFrameRate(60);
 	
-	fvec_t * my_fvec_t;
-	aubio_onset_t* my_aubio_result;
-	aubio_onsetdetection_t * my_onset_detection;
+//	fvec_t * my_fvec_t;
+//	aubio_onset_t* my_aubio_result;
+//	aubio_onsetdetection_t * my_onset_detection;
 	
 	audioScale = 1000.0;
 	
-	scrollWidth = 1600;
+
 	
 	//int readcount = 0; // counts number of samples read from sound file
 
 	//string inputFilename = "sound/GetIntoTheGroove.wav";// input file name placed in bin
 
-	sfinfo.format = 0;
+
 	
 	moveOn = true;
 
@@ -73,22 +74,19 @@
 
 void testApp::initialiseVariables(){
 	
-//	energyIndex = 0;
-//	frameIndex = 0;
-//	chromaIndex = 0;
-	chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048
+//	chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048
 }
 
 
 //--------------------------------------------------------------
 void testApp::update(){
 
-	audioPosition = loadedAudio.getPosition() * totalNumberOfFrames;//frameIndex;//the position in number of frames
-	currentPlayingFrame = audioPosition;
-	audioPosition = (int) audioPosition % scrollWidth ;
-	audioPosition /= scrollWidth;
+	audioPosition = loadedAudio.getPosition() * fileLoader.totalNumberOfFrames;//frameIndex;//the position in number of frames
+	fileLoader.chromaAnalysis.currentPlayingFrame = audioPosition;
+	audioPosition = (int) audioPosition % fileLoader.chromaAnalysis.scrollWidth ;
+	audioPosition /= fileLoader.chromaAnalysis.scrollWidth;
 	
-	audioHolder.playPosition = loadedAudio.getPosition() * audioHolder.audioVector.size();
+	fileLoader.audioHolder.playPosition = loadedAudio.getPosition() * fileLoader.audioHolder.audioVector.size();
 }
 
 //--------------------------------------------------------------
@@ -96,17 +94,18 @@
 	switch (screenToDraw){
 		case 0:
 			if (drawSpectralDifferenceFunction)
-				drawSpectralDifference(&chromaMatrix);
+				fileLoader.chromaAnalysis.drawSpectralDifference();
 			else
-				drawDoubleMatrix(&chromaMatrix);
+				drawDoubleMatrix(&fileLoader.chromaAnalysis.chromaMatrix);
 			
-			drawEnergyVectorFromPointer(&firstEnergyVector);
+			fileLoader.chromaAnalysis.drawEnergyVectorFromPointer();
+			
 			ofSetColor(0xFFFFFF);
 			ofLine(audioPosition*width, 0, audioPosition*width, height);
 			break;
 			case 1:
 		//	audioHolder.drawAudioVectorMillis(1000, 1000+audioScale);
-			audioHolder.drawAudioVectorSamples(audioHolder.playPosition - audioHolder.audioScaleSamples*0.5, audioHolder.playPosition+audioHolder.audioScaleSamples*0.5);
+			fileLoader.audioHolder.drawAudioVectorSamples(fileLoader.audioHolder.playPosition - fileLoader.audioHolder.audioScaleSamples*0.5, fileLoader.audioHolder.playPosition+fileLoader.audioHolder.audioScaleSamples*0.5);
 			ofSetColor(100,100,100);
 			ofLine(width/2, 0, width/2, height);
 			break;
@@ -124,63 +123,6 @@
 }
 
 
-void testApp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
-	
-	ofSetColor(0xFF0066);
-	float screenHeight = ofGetHeight() ;
-	float screenWidth = ofGetWidth();  
-	float heightFactor = 8;
-	int i, j, startingFrame;
-	startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
-	startingFrame *= scrollWidth;
-	
-	for (i = 0; i < scrollWidth - 1; i++){
-		j = i + startingFrame;
-		if (j < (*energyVec).size())
-		ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
-			   screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
-		
-	}
-}
-
-void testApp::drawSpectralDifference(DoubleMatrix* dMatrix){
-	int matrixSize = (*dMatrix).size();
-	if (matrixSize > 0){
-		
-	float screenHeight = ofGetHeight() ;
-	float screenWidth = ofGetWidth();
-	float heightFactor = 8;
-	double difference;
-	int i, j, startingFrame;
-	startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
-	startingFrame *= scrollWidth;//starting frame in terms of energy frames
-	startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
-	
-	float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
-	for (i = 1; i < chromoLength; i++){//changed to add 1
-		j = i + startingFrame;
-		for (int y = 0;y < 12;y++){			
-
-			if (j < matrixSize)
-				difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
-			else 
-				difference = 0;
-			
-			if (difference < 0)
-				difference = 0;//half wave rectify
-			
-			ofSetColor(0,0,255 * difference);//, 0;
-			ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
-		}//end y
-	}//end i
-		
-	}///end if matrix has content
-	else{
-		printf("Error - please load audio first");
-	}
-	
-}
-
 
 void testApp::drawDoubleMatrix(DoubleMatrix* dMatrix){
 	//used to draw the chromagram matrix
@@ -191,11 +133,11 @@
 	float screenWidth = ofGetWidth();
 	float heightFactor = 8;
 	int i, j, startingFrame;
-	startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
-	startingFrame *= scrollWidth;//starting frame in terms of energy frames
+	startingFrame = fileLoader.chromaAnalysis.currentPlayingFrame / fileLoader.chromaAnalysis.scrollWidth;//i.e. number of scroll widths in
+	startingFrame *= fileLoader.chromaAnalysis.scrollWidth;//starting frame in terms of energy frames
 	startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
 	
-	float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
+	float chromoLength = fileLoader.chromaAnalysis.scrollWidth/CHROMA_CONVERSION_FACTOR;
 	for (i = 0; i < chromoLength; i++){
 		j = i + startingFrame;
 		for (int y = 0;y < 12;y++){
@@ -219,7 +161,7 @@
 
 
 
-
+/*
 void testApp::loadLibSndFile(const char *infilename){
 	
 	if (!sf_close(infile)){
@@ -241,8 +183,8 @@
 	};
 	
 }
-
-
+*/
+/*
 void testApp::processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){
 
 	myDoubleMatrix->clear();
@@ -349,7 +291,7 @@
 	audioHolder.length = (int) audioHolder.audioVector.size();
 }
 
-
+*/
 //--------------------------------------------------------------
 void testApp::keyPressed  (int key){
 	if (key == '-'){
@@ -364,28 +306,28 @@
 		screenToDraw = 1 - screenToDraw;
 	
 	if (key == OF_KEY_DOWN){
-		if (scrollWidth > 600)
-		scrollWidth += 400;
+		if (fileLoader.chromaAnalysis.scrollWidth > 600)
+		fileLoader.chromaAnalysis.scrollWidth += 400;
 		else
-		scrollWidth *= 2;
+		fileLoader.chromaAnalysis.scrollWidth *= 2;
 	}
 	
 	if (key == OF_KEY_RIGHT){
-		loadedAudio.setPosition(min(1.0, loadedAudio.getPosition() + (audioHolder.audioScaleSamples/(4.0*audioHolder.audioVector.size()))) );
+		loadedAudio.setPosition(min(1.0, loadedAudio.getPosition() + (fileLoader.audioHolder.audioScaleSamples/(4.0*fileLoader.audioHolder.audioVector.size()))) );
 //	audioHolder.playPosition = loadedAudio.getPosition() * audioHolder.audioVector.size();
 	}
 	
 	if (key == OF_KEY_LEFT){
-		loadedAudio.setPosition(max(0.0, loadedAudio.getPosition() - (audioHolder.audioScaleSamples/(4.0*audioHolder.audioVector.size()))));
+		loadedAudio.setPosition(max(0.0, loadedAudio.getPosition() - (fileLoader.audioHolder.audioScaleSamples/(4.0*fileLoader.audioHolder.audioVector.size()))));
 		//	audioHolder.playPosition = loadedAudio.getPosition() * audioHolder.audioVector.size();
 	}
 	
 	
 	if (key == OF_KEY_UP){
-		if (scrollWidth > 600)
-		scrollWidth -= 400;
+		if (fileLoader.chromaAnalysis.scrollWidth > 600)
+		fileLoader.chromaAnalysis.scrollWidth -= 400;
 		else
-		scrollWidth /= 2;
+		fileLoader.chromaAnalysis.scrollWidth /= 2;
 	}
 		
 		if (key == ' '){
@@ -420,12 +362,12 @@
 	
 	if (key == 'u'){
 		audioScale *= 2.;
-	audioHolder.audioScaleSamples *= 2.;
+	fileLoader.audioHolder.audioScaleSamples *= 2.;
 	}
 	
 	if (key == 'j'){
 		audioScale /= 2.;	
-		audioHolder.audioScaleSamples /= 2.;
+		fileLoader.audioHolder.audioScaleSamples /= 2.;
 	}
 }
 
@@ -454,7 +396,7 @@
 	pan = (float)x / (float)width;
 	float height = (float)ofGetHeight();
 	float heightPct = ((height-y) / height);
-	xIndex = (int)(pan*firstEnergyVector.size());
+	xIndex = (int)(pan*fileLoader.chromaAnalysis.energyVector.size());
 }
 
 //--------------------------------------------------------------
@@ -540,9 +482,9 @@
 	
 	//snd file method
 	const char	*infilename = soundFileName.c_str() ;
-	loadLibSndFile(infilename);
+	fileLoader.loadLibSndFile(infilename);
 
-	processAudioToDoubleMatrix(&chromoGramm, &chromaMatrix, &firstEnergyVector);
+	
 	
 	audioPlaying = false;
 }
@@ -551,7 +493,8 @@
 
 
 
-
+/*
+ 
 double testApp::getEnergyOfFrame(){
 	
 	float totalEnergyInFrame = 0;
@@ -566,7 +509,7 @@
 	return totalEnergyInFrame;
 }
 
-
+*/
 
 
 //JUNK METHODS BEFORE SWITCHING TO VECTORS TO HOLD ENERGY AND CHROMA
@@ -672,4 +615,61 @@
  }//end while readcount
  
  
+ void testApp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
+ 
+ ofSetColor(0xFF0066);
+ float screenHeight = ofGetHeight() ;
+ float screenWidth = ofGetWidth();  
+ float heightFactor = 8;
+ int i, j, startingFrame;
+ startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
+ startingFrame *= scrollWidth;
+ 
+ for (i = 0; i < scrollWidth - 1; i++){
+ j = i + startingFrame;
+ if (j < (*energyVec).size())
+ ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
+ screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
+ 
+ }
+ }
+ 
+ void testApp::drawSpectralDifference(DoubleMatrix* dMatrix){
+ int matrixSize = (*dMatrix).size();
+ if (matrixSize > 0){
+ 
+ float screenHeight = ofGetHeight() ;
+ float screenWidth = ofGetWidth();
+ float heightFactor = 8;
+ double difference;
+ int i, j, startingFrame;
+ startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
+ startingFrame *= scrollWidth;//starting frame in terms of energy frames
+ startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
+ 
+ float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
+ for (i = 1; i < chromoLength; i++){//changed to add 1
+ j = i + startingFrame;
+ for (int y = 0;y < 12;y++){			
+ 
+ if (j < matrixSize)
+ difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
+ else 
+ difference = 0;
+ 
+ if (difference < 0)
+ difference = 0;//half wave rectify
+ 
+ ofSetColor(0,0,255 * difference);//, 0;
+ ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
+ }//end y
+ }//end i
+ 
+ }///end if matrix has content
+ else{
+ printf("Error - please load audio first");
+ }
+ 
+ }
+ 
  */
--- a/src/testApp.h	Tue Aug 30 20:18:34 2011 +0100
+++ b/src/testApp.h	Sun Sep 04 22:45:35 2011 +0100
@@ -3,11 +3,11 @@
 
 
 #include "ofMain.h"
-#include "chromaGram.h"
-#include "ChordDetect.h"
 #include "sndfile.h"
 #include "ofxFileDialogOSX.h"
 #include "AudioFile.h"
+#include "AudioAnalysis.h"
+#include "SoundFileLoader.h"
 
 //note the dependency on sndfile (libsndfile library needs to be accessible)
 //also the file dialogue addon
@@ -21,10 +21,8 @@
 //see the key pressed function for other bits - e.g. can view spectral difference
 
 
-#define FRAMESIZE 512
-#define ENERGY_LENGTH 80000
-#define CHROMA_LENGTH 12000
-#define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
+//#define FRAMESIZE 512
+
 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds
 
 class testApp : public ofBaseApp{
@@ -56,19 +54,19 @@
 	typedef std::vector<double> DoubleVector;
 	typedef std::vector<DoubleVector> DoubleMatrix;
 
-	DoubleMatrix chromaMatrix;
-	DoubleMatrix* matrixPtr;
+//	DoubleMatrix chromaMatrix;
+//	DoubleMatrix* matrixPtr;
 	
-	AudioFile audioHolder;
+
 	
-	void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET
-	void drawSpectralDifference(DoubleMatrix* dMatrix);
+	void drawDoubleMatrix(DoubleMatrix* dMatrix);
+//	void drawSpectralDifference(DoubleMatrix* dMatrix);
 	
-	DoubleVector firstEnergyVector;
+//	DoubleVector firstEnergyVector;
 	
-	void drawEnergyVectorFromPointer(DoubleVector* energyVec);
+//	void drawEnergyVectorFromPointer(DoubleVector* energyVec);
 	
-		void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
+	//	void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
 	
 		void loadNewAudio(string soundFileName);
 		
@@ -91,7 +89,7 @@
 
 		bool moveOn;
 		bool drawSpectralDifferenceFunction;
-		float frame[FRAMESIZE]; 
+		
 	//	int frameIndex;
 	//	float energy[ENERGY_LENGTH];
 	
@@ -99,7 +97,8 @@
 	//	int rootChord[CHROMA_LENGTH];
 		
 	//	int energyIndex;
-		int totalFrames;
+	
+	//	int totalFrames;
 		int screenToDraw;
 		
 		int scrollWidth;// 1600
@@ -117,21 +116,23 @@
 */		
 		string sndfileInfoString, textString;
 		int xIndex;
-		
+	
+		SoundFileLoader fileLoader;
+	
 		ofSoundPlayer  loadedAudio;
 		float audioPosition;
 		float width, height;
 	//	int chromaIndex;	
 		int totalNumberOfFrames;
-		int currentPlayingFrame;
+	
 		string chordString;
 	
-		Chromagram chromoGramm;
+	//	Chromagram chromoGramm;
 			
-		ChordDetect chord;
-	
-		SNDFILE *infile; // define input and output sound files
-		SF_INFO sfinfo ; // struct to hold info about sound file
+	//	ChordDetect chord;
+
+//		SNDFILE *infile; // define input and output sound files
+//		SF_INFO sfinfo ; // struct to hold info about sound file
 
 		
 };