Mercurial > hg > audio-time-warp
changeset 13:a3d797046ea8
neatened causal align code for forwards path, working well now
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 22 Nov 2011 17:54:48 +0000 |
parents | 13c19fe83301 |
children | 0ded10fd754c |
files | src/testApp.cpp src/testApp.h |
diffstat | 2 files changed, 79 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testApp.cpp Tue Nov 22 17:37:45 2011 +0000 +++ b/src/testApp.cpp Tue Nov 22 17:54:48 2011 +0000 @@ -151,86 +151,42 @@ printf("CHROMA SIMILARITY ONLY TAKES %2.2f seconds\n", elapsedTime); dontDoJunkAlignment(); + + calculateForwardsAlignment(); - tw.forwardsAlignmentPath.clear(); - //causal part - int hopsize = 200; - int frameSize = 600; - int startFrameY = 0; - int startFrameX = 0; - tw.anchorPoints.clear(); - for (int startFrameX = 0;startFrameX < tw.firstEnergyVector.size(); startFrameX += hopsize){//tw.firstChromaEnergyMatrix.size() - //replace this with a while startFrame < end of file - tw.addAnchorPoints(startFrameX, startFrameY); - - //NEED TO ASSUME WE DON'T HAVE - timeBefore = ofGetElapsedTimef(); - printf("PART SIM: startFrameX %i, startFrameY: %i\n", startFrameX, startFrameY); - // tw.calculatePartSimilarityMatrix(&tw.firstChromaEnergyMatrix, &tw.secondChromaEnergyMatrix, &tw.tmpSimilarityMatrix, startFrameX, startFrameY, startFrameX+frameSize); - - //NEW FUNCTION - calls only the energy and uses the stored chromagram - tw.calculatePartJointSimilarityMatrix(&tw.firstEnergyVector, &tw.secondEnergyVector, &tw.chromaSimilarityMatrix, &tw.tmpSimilarityMatrix, - startFrameX, startFrameY, startFrameX+frameSize, startFrameY + 3*frameSize); - - - - - printf("TMP size of tmp sim is %i\n", (int)tw.tmpSimilarityMatrix.size()); - elapsedTime = ofGetElapsedTimef() - timeBefore; - printf("PART SIM MATRIX CAL TAKES %f\n", elapsedTime); - - //change part sim to have a y limit too - - - //check if we can not calculate alignment matrix for chunks of the sim matrix where it is off diagonal - - tw.calculatePartAlignmentMatrix(tw.tmpSimilarityMatrix.size()-1, tw.tmpSimilarityMatrix[0].size()-1, &tw.tmpAlignmentMeasureMatrix, &tw.tmpSimilarityMatrix); - - //get alignment measure minimum - //find minimum path between only the section we are interested in - //write new function to find minimum backwards path from the index we choose (not the final corner) -// int myIndex = tw.findMinimumOfMatrixColumn(tw.tmpAlignmentMeasureMatrix, tw.tmpSimilarityMatrix.size()-1); -/* printf("my index is %i\n", myIndex); - for (int i = 0;i< tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1].size() - 1;i++){ - printf("Alignment[%i] : %f\n", i, tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1][i]); - } -*/ - printf("\n CALC PART ALIGNMENT MIN PATH\n"); - tw.calculateMinimumAlignmentPath(&tw.tmpAlignmentMeasureMatrix, &tw.tmpBackwardsPath, true);//true is for greedy calculation - printf("\n PART ALIGNMENT GENERATES THIS BACKWARDS PATH:: \n"); - tw.extendForwardAlignmentPath(hopsize, &tw.tmpBackwardsPath, startFrameX, startFrameY); - - startFrameY = tw.forwardsAlignmentPath[1][(tw.forwardsAlignmentPath[0].size()-1)]; - - //printf("forwards path printed\n"); - // tw.printBackwardsPath(0, tw.forwardsAlignmentPath[0].size(), &tw.forwardsAlignmentPath); - //pushSimCode()? - - }//end for startFrameX + tw.copyForwardsPathToBackwardsPath(); + backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1; // tw.calculateAlignmentMatrix(tw.firstChromaEnergyMatrix, tw.secondChromaEnergyMatrix, &tw.alignmentMeasureMatrix); // tw.calculateMinimumAlignmentPath(&tw.alignmentMeasureMatrix, &tw.backwardsAlignmentPath, false); - // tw.calculatePartMinimumAlignmentPath(0, 0, 100, 100, &tw.partAlignmentMeasureMatrix); + setConversionRatio(); -// conversionFactor = (int)round((tw.firstEnergyVector.size() / tw.similarityMatrix.size())); - printf("large SIM SIZE%i, chrom size %ix%i\n", tw.similarityMatrix.size(), tw.chromaMatrix.size(), tw.chromaMatrix[0].size()); + printVariousMatrixInfo(); +} + + + +void testApp::setConversionRatio(){ conversionFactor = (int) round(tw.firstEnergyVector.size() / tw.chromaMatrix.size()); chromaConversionRatio = (int) round(tw.firstEnergyVector.size() / tw.chromaMatrix.size()); - //conversionFactor = 1.0;//since we are using onset level matching chromoLength = scrollWidth / (float)conversionFactor;// CHROMA_CONVERSION_FACTOR; printf("scrollwidth %i, conversion factor %i, chromo length %i\n", scrollWidth, (int)conversionFactor, (int)chromoLength); +} + +void testApp::printVariousMatrixInfo(){ + printf("large SIM SIZE%i, chrom size %ix%i\n", (int)tw.similarityMatrix.size(), (int)tw.chromaMatrix.size(), (int)tw.chromaMatrix[0].size()); if (tw.similarityMatrix.size() > 0 && tw.chromaSimilarityMatrix.size() > 0){ - printf("SIM SIZE %i, and %i \n",(int) tw.similarityMatrix.size(), (int) tw.similarityMatrix[0].size()); - printf("chomra sim size %i, and %i\n", (int) tw.chromaSimilarityMatrix.size(), tw.chromaSimilarityMatrix[0].size()); + printf("SIM SIZE %i, and %i \n",(int) tw.similarityMatrix.size(), (int) tw.similarityMatrix[0].size()); + printf("chomra sim size %i, and %i\n", (int) tw.chromaSimilarityMatrix.size(), (int)tw.chromaSimilarityMatrix[0].size()); } - tw.copyForwardsPathToBackwardsPath(); - + + //tw.printBackwardsPath(0, tw.forwardsAlignmentPath[0].size()-1, &tw.forwardsAlignmentPath); - backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1; + printf("backwards path size is [0]:%i, [1]%i, \n", (int)tw.backwardsAlignmentPath[0].size(), (int)tw.backwardsAlignmentPath[1].size()); printf("backwards path size is %i, FORWARDS SIZE IS %i\n", (int)tw.backwardsAlignmentPath[0].size(), (int)tw.forwardsAlignmentPath[0].size()); @@ -258,6 +214,62 @@ } +void testApp::calculateForwardsAlignment(){ + + tw.forwardsAlignmentPath.clear(); + //causal part + int hopsize = 200; + int frameSize = 600; + int startFrameY = 0; + int startFrameX = 0; + tw.anchorPoints.clear(); + for (int startFrameX = 0;startFrameX < tw.firstEnergyVector.size(); startFrameX += hopsize){//tw.firstChromaEnergyMatrix.size() + //replace this with a while startFrame < end of file + tw.addAnchorPoints(startFrameX, startFrameY); + + //NEED TO ASSUME WE DON'T HAVE + double timeBefore = ofGetElapsedTimef(); + printf("PART SIM: startFrameX %i, startFrameY: %i\n", startFrameX, startFrameY); + // tw.calculatePartSimilarityMatrix(&tw.firstChromaEnergyMatrix, &tw.secondChromaEnergyMatrix, &tw.tmpSimilarityMatrix, startFrameX, startFrameY, startFrameX+frameSize); + + //NEW FUNCTION - calls only the energy and uses the stored chromagram + tw.calculatePartJointSimilarityMatrix(&tw.firstEnergyVector, &tw.secondEnergyVector, &tw.chromaSimilarityMatrix, &tw.tmpSimilarityMatrix, + startFrameX, startFrameY, startFrameX+frameSize, startFrameY + 3*frameSize); + + + + + printf("TMP size of tmp sim is %i\n", (int)tw.tmpSimilarityMatrix.size()); + double elapsedTime = ofGetElapsedTimef() - timeBefore; + printf("PART SIM MATRIX CAL TAKES %f\n", elapsedTime); + + //change part sim to have a y limit too + + + //check if we can not calculate alignment matrix for chunks of the sim matrix where it is off diagonal + + tw.calculatePartAlignmentMatrix(tw.tmpSimilarityMatrix.size()-1, tw.tmpSimilarityMatrix[0].size()-1, &tw.tmpAlignmentMeasureMatrix, &tw.tmpSimilarityMatrix); + + //get alignment measure minimum + //find minimum path between only the section we are interested in + //write new function to find minimum backwards path from the index we choose (not the final corner) + // int myIndex = tw.findMinimumOfMatrixColumn(tw.tmpAlignmentMeasureMatrix, tw.tmpSimilarityMatrix.size()-1); + /* printf("my index is %i\n", myIndex); + for (int i = 0;i< tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1].size() - 1;i++){ + printf("Alignment[%i] : %f\n", i, tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1][i]); + } + */ + printf("\n CALC PART ALIGNMENT MIN PATH\n"); + tw.calculateMinimumAlignmentPath(&tw.tmpAlignmentMeasureMatrix, &tw.tmpBackwardsPath, true);//true is for greedy calculation + printf("\n PART ALIGNMENT GENERATES THIS BACKWARDS PATH:: \n"); + tw.extendForwardAlignmentPath(hopsize, &tw.tmpBackwardsPath, startFrameX, startFrameY); + + startFrameY = tw.forwardsAlignmentPath[1][(tw.forwardsAlignmentPath[0].size()-1)]; + + }//end for startFrameX + +} + //-------------------------------------------------------------- void testApp::update(){ textString = "energy index [";
--- a/src/testApp.h Tue Nov 22 17:37:45 2011 +0000 +++ b/src/testApp.h Tue Nov 22 17:54:48 2011 +0000 @@ -71,11 +71,13 @@ // DoubleMatrix similarityMatrix; void calculateSimilarityMatrix(); + void calculateForwardsAlignment();//forwards causal alignment version bool drawSimilarity; void drawSimilarityMatrix(); void printSimilarityMatrix(int sizeToPrint); - + void setConversionRatio(); + void printVariousMatrixInfo(); void drawChromaSimilarityMatrix();