Mercurial > hg > audio-time-warp
changeset 1:6842ff391568
getting rid of pointer use in processAudio - not many changes
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 18 May 2011 16:47:12 +0100 |
parents | 572c856e38ac |
children | 9ce18f24b266 |
files | chromagramm/Chromagram.cpp src/testApp.cpp src/testApp.h src/timeWarp.cpp src/timeWarp.h |
diffstat | 5 files changed, 50 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/chromagramm/Chromagram.cpp Tue May 17 08:48:58 2011 +0100 +++ b/chromagramm/Chromagram.cpp Wed May 18 16:47:12 2011 +0100 @@ -8,7 +8,7 @@ Chromagram :: Chromagram() { pi = 3.14159265; - bsize = 8192; + bsize = 8192;//buffersize - ie main framesize at 11025Hz // array init buffer = new float[8192]; // make audio buffer
--- a/src/testApp.cpp Tue May 17 08:48:58 2011 +0100 +++ b/src/testApp.cpp Wed May 18 16:47:12 2011 +0100 @@ -74,9 +74,12 @@ backwardsAlignmentIndex = 0;//remember that this goes backwards! tw.initialiseVariables(); + + //here is the main timewarp similarity matrix calc, the minimum alignment matrix via dtw and then the backwards path estimate tw.calculateSimilarityMatrix(); tw.calculateAlignmentMatrix(); tw.calculateMinimumAlignmentPath(); + printf("\n gettem hereafter!"); //set not to play audioPlaying = false; @@ -92,6 +95,8 @@ initialiseVariables(); + chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE); + } @@ -150,6 +155,8 @@ } void testApp::updateAlignmentPathIndex(int identifier){ + + //this is the alignment where we are currently playing - i.e. switching between files int chromaPosition = audioPosition/CHROMA_CONVERSION_FACTOR; @@ -537,15 +544,16 @@ } -void testApp::processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){ +void testApp::processAudioToDoubleMatrix(DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){ //wendy myDoubleMatrix->clear(); energyVector->clear(); + frameIndex = 0; -// chromaIndex = 0;// WHY NEED THIS? - chromaG->initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 - chromaG->maximumChromaValue = 0; + + chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE);//framesize 512 and hopsize 2048 - already done + chromaG.maximumChromaValue = 1; int readcount = 1; // counts number of samples read from sound file printf("processing audio from doublematrix \n"); @@ -556,41 +564,34 @@ // read FRAMESIZE samples from 'infile' and save in 'data' readcount = sf_read_float(infile, frame, FRAMESIZE); - //printf("readcount %i", readcount); + //8192 samples per chroma frame //processing frame - downsampled to 11025Hz + chromaG.processframe(frame); - //processing frame - downsampled to 11025Hz - //8192 samples per chroma frame - chromaG->processframe(frame); - - if (chromaG->chromaready) + if (chromaG.chromaready) { DoubleVector d; for (int i = 0;i<12;i++){ - d.push_back(chromaG->rawChroma[i]);// / chromaG->maximumChromaValue); + d.push_back(chromaG.rawChroma[i]);// / chromaG->maximumChromaValue); } //this would do chord detection myDoubleMatrix->push_back(d); - + //so now is storing at d[i][current_index] }//end if chromagRamm ready //printf("calling drawSndFile %i", frameIndex); frameIndex++; - - // putEnergyInFrame(); - //get energy of the current frame and wait - double energyValue = getEnergyOfFrame(); energyVector->push_back(energyValue); }//end while readcount - printf("Max chroma value is %f \n", chromaG->maximumChromaValue); + printf("Max chroma value is %f \n", chromaG.maximumChromaValue); //normalise int length = myDoubleMatrix->size(); @@ -600,7 +601,8 @@ for (int i = 0; i < myDoubleMatrix->size();i++){ for (int j = 0; j < ((*myDoubleMatrix)[0]).size();j++){ - (*myDoubleMatrix)[i][j] /= chromaG->maximumChromaValue; + //non-causal normalisation + (*myDoubleMatrix)[i][j] /= chromaG.maximumChromaValue; } } @@ -608,13 +610,13 @@ size = energyVector->size(); printf("size of energy vector is %d \n", size); - totalNumberOfFrames = frameIndex;//used to use this - but switch to energy vector's size instead -// totalNumberOfFrames = size; +// totalNumberOfFrames = frameIndex;//used to use this - but switch to energy vector's size instead + totalNumberOfFrames = size; // int size = myDoubleMatrix->size() * CHROMA_CONVERSION_FACTOR; // printf("size of double matrix is %d and frame index %d", size, frameIndex); - printf("Total frames %i and Chroma index %i \n", frameIndex, chromaIndex); + printf("Total frames %i \n", frameIndex); } @@ -867,15 +869,16 @@ void testApp::loadFirstAudioFile(){ - Chromagram* cptr; +/* + Chromagram* cptr; DoubleMatrix* dptr; DoubleVector* eptr; cptr = &(tw.chromoGramm); dptr = &(tw.chromaMatrix); eptr = &(tw.firstEnergyVector); - - processAudioToDoubleMatrix(cptr, dptr, eptr); + */ + processAudioToDoubleMatrix(&tw.chromaMatrix, &tw.firstEnergyVector); } @@ -893,7 +896,7 @@ dptr = &(tw.secondMatrix); eptr = &(tw.secondEnergyVector); - processAudioToDoubleMatrix(cptr, dptr, eptr);//chromaMatrix); + processAudioToDoubleMatrix(dptr, eptr);//chromaMatrix); }
--- a/src/testApp.h Tue May 17 08:48:58 2011 +0100 +++ b/src/testApp.h Wed May 18 16:47:12 2011 +0100 @@ -17,6 +17,9 @@ #define ENERGY_LENGTH 80000 #define CHROMA_LENGTH 12000 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma +#define CHROMAGRAM_FRAMESIZE 2048 + + //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds class testApp : public ofBaseApp{ @@ -109,7 +112,7 @@ void drawEnergyVectorFromPointer(DoubleVector* energyVec); - void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector); + void processAudioToDoubleMatrix(DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector); void loadNewAudio(string soundFileName); void loadSecondAudio(string soundFileName); @@ -188,7 +191,7 @@ timeWarp tw; - + Chromagram chromaG; };
--- a/src/timeWarp.cpp Tue May 17 08:48:58 2011 +0100 +++ b/src/timeWarp.cpp Wed May 18 16:47:12 2011 +0100 @@ -37,7 +37,7 @@ void timeWarp::initialiseVariables(){ diagonalPenalty = 2;//penalises diagonal so all path gradients equal weighting - chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 + //chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 } @@ -71,8 +71,6 @@ DoubleVector d; for (int y = 0;y < secondMatrix.size();y++){ - //d.push_back( drand48() ); - distance = 0; firstSum = 0; secondSum = 0; @@ -97,7 +95,7 @@ }//end for x // userInfoString += "; size ="; // userInfoString += ofToString(similarityMatrix.size() , 0); - printf("..sim size: %i, height: %i \n", similarityMatrix.size(), (chromaMatrix[0]).size()); + printf("..sim size: %i, height: %i \n", (int) similarityMatrix.size(), (int) (chromaMatrix[0]).size()); }//end self sim @@ -111,11 +109,9 @@ d.push_back(getDistance(0,0)); alignmentMeasureMatrix.push_back(d); - bool chromaCalculated = false; bool secondCalculated = false; - while (!chromaCalculated || !secondCalculated) { if (!chromaCalculated) @@ -126,20 +122,18 @@ } - - } bool timeWarp::extendAlignmentUp(){ DoubleVector d; - d = alignmentMeasureMatrix[0]; + d = alignmentMeasureMatrix[0];//alignmentMatrix[0];// int heightSize = d.size(); if (heightSize < secondMatrix.size()){ //then we haven't finished yet for (int i = 0;i < alignmentMeasureMatrix.size();i++){ double value = getDistance(i, heightSize); value += getMinimum(i, heightSize, value); - alignmentMeasureMatrix[i].push_back(value); + alignmentMeasureMatrix[i].push_back(value);// } } if (alignmentMeasureMatrix[0].size() == secondMatrix.size()) @@ -167,7 +161,6 @@ alignmentMeasureMatrix[widthSize].push_back(value); } - //alignmentMeasureMatrix.push_back(d); } if (alignmentMeasureMatrix.size() == chromaMatrix.size()) @@ -181,7 +174,7 @@ void timeWarp::calculateMinimumAlignmentPath(){ //this requires one pass of the DTW algorithm and then works backwards from (N,M) //to find the optimal path to (0,0), where N and M are the lengths of the two chromoVectors respectively - //minimumAlignmentPath.clear(); + backwardsAlignmentPath.clear(); printf("Finding minimum Path \n"); @@ -201,7 +194,7 @@ printf("backwards path %i : %i \n", backwardsAlignmentPath[0][indexOfBackwardsPath], backwardsAlignmentPath[1][indexOfBackwardsPath]); } - printf("final index of backwards path is %i and i is %i \n", backwardsAlignmentPath[0].size()-1, indexOfBackwardsPath); + printf("final index of backwards path is %i and i is %i \n", (int) backwardsAlignmentPath[0].size()-1, indexOfBackwardsPath); // backwardsAlignmentIndex = backwardsAlignmentPath[0].size()-1;//remember that this goes backwards!
--- a/src/timeWarp.h Tue May 17 08:48:58 2011 +0100 +++ b/src/timeWarp.h Wed May 18 16:47:12 2011 +0100 @@ -74,9 +74,17 @@ // void drawSimilarityMatrix(); // void printSimilarityMatrix(int sizeToPrint); - DoubleMatrix alignmentMeasureMatrix; + Chromagram chromoGramm; + Chromagram secondChromoGramm; + + + DoubleMatrix alignmentMeasureMatrix;//just the choma alignment DoubleVector minimumAlignmentPath; + //new addition + DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment + DoubleVector superMinimumAlignmentPath; + // void drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame); int findStartWidthFrame(); @@ -99,7 +107,7 @@ void calculateAlignmentMatrix(); double getDistance(int i, int j); - void printAlignmentMatrix(); +// void printAlignmentMatrix(); double getMinimum(int i, int j, float newValue); bool extendAlignmentUp(); bool extendAlignmentAlong(); @@ -115,8 +123,6 @@ - Chromagram chromoGramm; - Chromagram secondChromoGramm;