Mercurial > hg > multitrack-audio-matcher
changeset 47:689704aa55d5
Added square and better scrolling through the matrix, better loading of files
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 09 May 2012 12:38:00 +0100 |
parents | ba36a1721538 |
children | 5359e2c0b0fb |
files | annotationCalculatorSrc/Histogram.cpp annotationCalculatorSrc/Histogram.h annotationCalculatorSrc/testApp.cpp annotationCalculatorSrc/testApp.h src/RecordedMultitrackAudio.cpp |
diffstat | 5 files changed, 184 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/annotationCalculatorSrc/Histogram.cpp Tue May 08 23:16:00 2012 +0100 +++ b/annotationCalculatorSrc/Histogram.cpp Wed May 09 12:38:00 2012 +0100 @@ -13,14 +13,39 @@ screenHeight = ofGetHeight(); } -void Histogram::createHistogram(const int& binWidthIn, const int& numberofBinsIn, DoubleVector& data){ +void Histogram::createHistogram(const int& binWidthIn, const int& numberofBinsIn){ numberofBins = numberofBinsIn; binWidth = binWidthIn; + minimumBinValue = -1.0 * binWidth * ((double)numberofBins/2); histogram.clear(); histogram.assign(numberofBins, 0); maximum = 0; + numberOutsideRange = 0; + + setBinPoints(); + +} + +void Histogram::setBinPoints(){ + binPoints.clear(); + binPoints.push_back(minimumBinValue); + while (binPoints.size() < numberofBins){ + binPoints.push_back(binPoints[binPoints.size()-1] + binWidth); + } + maximumBinValue = binPoints[binPoints.size()-1]+binWidth; + + for (int k = 0; k < binPoints.size();k++){ + printf("Bin pts [%i] : %f\n", k, binPoints[k]); + } + +} + +void Histogram::processDataIntoHistogram(const DoubleVector& data){ + double binPoint; int bin = 0; + numberOutsideRange = 0; + for (int i = 0;i < data.size();i++){ //find which bin it falls into. //5 bins, width is 10 @@ -28,20 +53,29 @@ //zero is the 5/2 th pt bin = 0; - binPoint = -1.0 * binWidth * ((double)numberofBins/2); + binPoint = binPoints[0];//i.e. minimumBinValue; if (data[i] >= binPoint){//i.e. falls inside - while (data[i] > (binPoint + binWidth) && bin < numberofBins) { + // while (data[i] > (binPoint + binWidth) && bin < numberofBins) { + while (bin < numberofBins && data[i] > binPoints[bin+1]) { //printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); - binPoint += binWidth; - bin++; + bin++; + binPoint = binPoints[bin]; +// binPoint += binWidth; +// bin++; } // printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); - if (data[i] <= binPoint + binWidth){//in case outside range + if (data[i] <= maximumBinValue){//in case outside range histogram[bin]++; + } else{ + //then it's greater than maximum + numberOutsideRange++; } + } else{ + //then it's less than minimum + numberOutsideRange++; } } @@ -52,6 +86,7 @@ printf("HISTO[%i] = %i\n", k, histogram[k]); } + printf("Number outside %i\n", numberOutsideRange); }
--- a/annotationCalculatorSrc/Histogram.h Tue May 08 23:16:00 2012 +0100 +++ b/annotationCalculatorSrc/Histogram.h Wed May 09 12:38:00 2012 +0100 @@ -21,14 +21,20 @@ typedef std::vector<int> IntVector; IntVector histogram; - void createHistogram(const int& binWidth, const int& numberofBins, DoubleVector& data); + void createHistogram(const int& binWidth, const int& numberofBins); + void processDataIntoHistogram(const DoubleVector& data); void plotHistogram(); void plotHistogram(const double& maxHeight); + void setBinPoints(); int numberofBins; int binWidth; + double minimumBinValue, maximumBinValue; + + DoubleVector binPoints; double maximum; + int numberOutsideRange; int getY(const int& y); int screenHeight;
--- a/annotationCalculatorSrc/testApp.cpp Tue May 08 23:16:00 2012 +0100 +++ b/annotationCalculatorSrc/testApp.cpp Wed May 09 12:38:00 2012 +0100 @@ -5,50 +5,10 @@ ofBackground(255); histogramWidth = 10; histogramBinNumber = 25; - - std::string path = "../../../data/marbleArch_4_beats.txt"; -// path = "../../../data/marbleArchKick_take4.txt"; - - beatReader.readInBeatsFile(path); - GroundTruth.push_back(beatReader.beatTimes);//so we have our first file list of beats - - //now get the second file beat list - path = "../../../data/marbleArch_6_beats.txt";//just the same one for the mo... -// path = "../../../data/marbleArchKick_take6.txt";//annotated kick tracks - beatReader.readInBeatsFile(path); - GroundTruth.push_back(beatReader.beatTimes);//so we have our first file list of beats - - //so GroundTruth[0] is the DoubleVector of file 1 beats - //this is the Live file - i.e. played along - //i.e. GT[0][0] - first, GT[0][1] second and so on - -// path = "../../../data/marbleArchloaded6_live4.txt"; - path = "../../../data/MarbleArch_live4_reh6_output.txt"; - path = "../../../data/marbleArch_take4_to_take6_new_output.txt"; - path = "../../../data/MarbleArch_live4_reh6_newOutput.txt"; - //Then we need to know where our alignment path has gone and projected these positions to be - //this is the rehearsal file that was analysed - //so we need to load an alignment path - //then calculate the error histogram etc - beatReader.readInMultiAlignmentFile(path); - printf("\n\nMultitrack Alignment\n"); - beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], beatReader.alignmentTimes[0], beatReader.alignmentTimes[1]); - multiHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); - - printf("\n\nMATCH BACKWARDS\n"); - - matchPath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OB.out"; - matchBackwardsNotations.readInMatchFile(matchPath); - beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchBackwardsNotations.matchLiveTimes, matchBackwardsNotations.matchRehearsalTimes); - matchBackwardsHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); - - printf("\n\nMATCH FORWARDS\n"); - matchPath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OF.out"; - matchForwardNotations.readInMatchFile(matchPath); - matchForwardNotations.reverseAnnotations(); - beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchForwardNotations.matchLiveTimes, matchForwardNotations.matchRehearsalTimes); - matchForwardHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); + setFilePaths(1); + readInFiles(); + processResults(); screenToDraw = 1; @@ -59,6 +19,83 @@ yPlotMax = 40; } + +void testApp::setFilePaths(int fileToLoad){ + + switch (fileToLoad) { + case 0: + liveGroundTruthPath = "../../../data/marbleArch_4_beats.txt"; + rehearsalGroundTruthPath = "../../../data/marbleArch_6_beats.txt"; + liveToRehMultitrackAlignmentPath = "../../../data/MarbleArch_live4_reh6_newOutput.txt"; + liveToRehMatchOFpath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OF.out"; + liveToRehMatchOBpath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OB.out"; + break; + case 1: + liveGroundTruthPath = "../../../data/Lewes/LewesTake14_beatsSV.txt"; + rehearsalGroundTruthPath = "../../../data/Lewes/Take13_proper_beatsSV.txt"; + liveToRehMultitrackAlignmentPath = "../../../data/Lewes/LewesLiveTake14_rehTake13proper_output.txt"; + liveToRehMatchOFpath = "../../../data/Lewes/LewesLive14_reh13p_match_OF.out"; + liveToRehMatchOBpath = "../../../data/Lewes/LewesLive14_reh13p_match_OB.out"; + break; + + default: + /*liveGroundTruthPath = NULL; + rehearsalGroundTruthPath = NULL; + liveToRehMultitrackAlignmentPath = NULL; + liveToRehMatchOFpath = NULL; + liveToRehMatchOBpath = NULL; + */ + break; + } + + + +} + + +void testApp::readInFiles(){ + //so we have our first file list of ground truth beats + beatReader.readInBeatsFile(liveGroundTruthPath); + GroundTruth.push_back(beatReader.beatTimes); + //then the second i.e. analysed list of beats + beatReader.readInBeatsFile(rehearsalGroundTruthPath); + GroundTruth.push_back(beatReader.beatTimes); + //so GroundTruth[0] is the DoubleVector of file 1 beats + //this is the Live file - i.e. played along + //i.e. GT[0][0] - first, GT[0][1] second and so on + + //Then we need to know where our alignment path has projected these positions to be + beatReader.readInMultiAlignmentFile(liveToRehMultitrackAlignmentPath); + + //read in the alignments from Match algorithm - first backwards, non-causal, path + matchBackwardsNotations.readInMatchFile(liveToRehMatchOBpath); + + //and forwards + matchForwardNotations.readInMatchFile(liveToRehMatchOFpath); + matchForwardNotations.reverseAnnotations();//which needs reversing + +} + + +void testApp::processResults(){ + + printf("\n\nMultitrack Alignment\n"); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], beatReader.alignmentTimes[0], beatReader.alignmentTimes[1]); + multiHistogram.createHistogram(histogramWidth, histogramBinNumber); + multiHistogram.processDataIntoHistogram(beatReader.errors); + + printf("\n\nMATCH BACKWARDS\n"); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchBackwardsNotations.matchLiveTimes, matchBackwardsNotations.matchRehearsalTimes); + matchBackwardsHistogram.createHistogram(histogramWidth, histogramBinNumber); + matchBackwardsHistogram.processDataIntoHistogram(beatReader.errors); + + printf("\n\nMATCH FORWARDS\n"); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchForwardNotations.matchLiveTimes, matchForwardNotations.matchRehearsalTimes); + matchForwardHistogram.createHistogram(histogramWidth, histogramBinNumber); + matchForwardHistogram.processDataIntoHistogram(beatReader.errors); + +} + //-------------------------------------------------------------- void testApp::update(){ @@ -84,9 +121,17 @@ break; } + + if (squareBeingDragged) + drawSquare(); } +void testApp::drawSquare(){ + ofSetColor(100,100,100); + ofRect(squareX, squareY, squareWidth, squareHeight); +} + void testApp::drawAlignmentVectors(){ ofSetColor(0,0,0); @@ -113,18 +158,29 @@ } + +void testApp::setCoordinatesToSquare(){ + xPlotMin += (xPlotMax - xPlotMin)*squareX / ofGetWidth(); + xPlotMax = xPlotMin + ((xPlotMax - xPlotMin)*(squareX + squareWidth)/ ofGetWidth()); + double screenHeight = (double)ofGetHeight(); + yPlotMax -= (yPlotMax - yPlotMin) * (squareY)/screenHeight ; + yPlotMin += (yPlotMax - yPlotMin) * (screenHeight - squareY - squareHeight)/screenHeight; +} + //-------------------------------------------------------------- void testApp::keyPressed(int key){ if (key == OF_KEY_RIGHT){ - xPlotMax += 20; - xPlotMin += 20; + double tmp = 0.5*(xPlotMax - xPlotMin); + xPlotMax += tmp; + xPlotMin += tmp; getYvalues(); } if (key == OF_KEY_LEFT){ - xPlotMin -= 20; - xPlotMax -= 20; + double tmp = 0.5*(xPlotMax - xPlotMin); + xPlotMin -= tmp; + xPlotMax -= tmp; getYvalues(); } @@ -137,6 +193,13 @@ xPlotMax = -1*xPlotMin + 2*xPlotMax ; yPlotMax = -1*xPlotMin + 2*yPlotMax; } + + if (key == OF_KEY_RETURN){ + xPlotMin = 0; + xPlotMax = beatReader.alignmentTimes[0][beatReader.alignmentTimes[0].size()-1]; + yPlotMin = 0; + yPlotMax = beatReader.alignmentTimes[1][beatReader.alignmentTimes[1].size()-1];; + } if (key == 's'){ screenToDraw++; @@ -187,17 +250,21 @@ //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ - + squareWidth = x - squareX; + squareHeight = y - squareY; + squareBeingDragged = true; } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ - + squareX = x; + squareY = y; } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ - + squareBeingDragged = false; + setCoordinatesToSquare(); } //--------------------------------------------------------------
--- a/annotationCalculatorSrc/testApp.h Tue May 08 23:16:00 2012 +0100 +++ b/annotationCalculatorSrc/testApp.h Wed May 09 12:38:00 2012 +0100 @@ -30,6 +30,10 @@ BeatAnnotationReader beatReader; + void setFilePaths(int fileToLoad); + void readInFiles(); + void processResults(); + void drawAlignmentVectors(); PlotTools plotter; @@ -49,4 +53,14 @@ int screenToDraw; int histogramWidth, histogramBinNumber; + + std::string liveGroundTruthPath, rehearsalGroundTruthPath; + std::string liveToRehMultitrackAlignmentPath; + std::string liveToRehMatchOFpath, liveToRehMatchOBpath; + + int squareX, squareY, squareWidth, squareHeight; + bool squareBeingDragged; + void drawSquare(); + void setCoordinatesToSquare(); + };
--- a/src/RecordedMultitrackAudio.cpp Tue May 08 23:16:00 2012 +0100 +++ b/src/RecordedMultitrackAudio.cpp Wed May 09 12:38:00 2012 +0100 @@ -16,7 +16,7 @@ printf("loaded max val is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue); - int multitrackToLoad = 13; + int multitrackToLoad = 19; setDifferentMultitracks(multitrackToLoad);//command to load this set of audio files - see below //number 7 is problematic with memory @@ -164,10 +164,10 @@ break; case 19: - bassfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesStudioTake13/bass di_bip.wav"; - kickfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesStudioTake13/kick_bip.wav"; - snarefilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesStudioTake13/snare_bip.wav"; - guitarfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesStudioTake13/guitar di_bip.wav"; + bassfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesTake13_ProperStructure/bass di_bip_1.wav"; + kickfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesTake13_ProperStructure/kick_bip_1.wav"; + snarefilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesTake13_ProperStructure/snare_bip_1.wav"; + guitarfilename = "/Volumes/Supersaurus/TractorsAlbum/tractorsDemo/Bounces/LewesMultitracks/LewesTake13_ProperStructure/guitar di_bip_1.wav"; break; case 20: