Mercurial > hg > audio-time-warp
changeset 2:9ce18f24b266
bringin onset detection function into the code
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 19 May 2011 11:45:26 +0100 |
parents | 6842ff391568 |
children | d0242d0a48e8 |
files | .DS_Store src/testApp.cpp src/testApp.h |
diffstat | 3 files changed, 40 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testApp.cpp Wed May 18 16:47:12 2011 +0100 +++ b/src/testApp.cpp Thu May 19 11:45:26 2011 +0100 @@ -6,6 +6,8 @@ #include <string> #include <cstdlib> + + //FIX CHORDS IN THE NEW POINTER VERSION OF THE PROCESS AUDIO FN //BUG IN WHETHER SECOND SONG LOADED OR NOT @@ -61,7 +63,11 @@ sfinfo.format = 0; moveOn = true; - + + + chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE); + onset = new OnsetDetectionFunction(512,1024,6,1); + //loading audio files loadSoundFiles(); @@ -95,15 +101,12 @@ initialiseVariables(); - chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE); - } void testApp::initialiseVariables(){ - frameIndex = 0; chromaIndex = 0; // chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 audioPosition = 0; @@ -183,13 +186,13 @@ float screenHeight = ofGetHeight() ; float screenWidth = ofGetWidth(); - float heightFactor = 8; + float heightFactor = 1; 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; + j = min(i + startingFrame, (int)energyVec->size()-1); ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor), screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor)); @@ -210,7 +213,7 @@ for (i = 1; i < chromoLength; i++){//changed to add 1 - j = i + startingFrame; + j = min(i + startingFrame, (int) dMatrix->size()-1 );//in case out of range for (int y = 0;y < 12;y++){ difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y]; if (difference < 0) @@ -287,7 +290,7 @@ float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR; for (i = 0; i < chromoLength; i++){ - j = i + startingFrame; + j = min(i + startingFrame, (int) dMatrix->size()-1 ) ; for (int y = 0;y < 12;y++){ ofSetColor(0,0,255 * (*dMatrix)[j][11-y]);//, 0; ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12); @@ -550,10 +553,10 @@ energyVector->clear(); - frameIndex = 0; chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE);//framesize 512 and hopsize 2048 - already done chromaG.maximumChromaValue = 1; + double maximumEnergyValue = 1; int readcount = 1; // counts number of samples read from sound file printf("processing audio from doublematrix \n"); @@ -564,6 +567,13 @@ // read FRAMESIZE samples from 'infile' and save in 'data' readcount = sf_read_float(infile, frame, FRAMESIZE); + double doubleFrame[FRAMESIZE]; + for (int k = 0;k< FRAMESIZE;k++){ + doubleFrame[k] = frame[k]; + } + + + //8192 samples per chroma frame //processing frame - downsampled to 11025Hz chromaG.processframe(frame); @@ -582,11 +592,12 @@ }//end if chromagRamm ready - //printf("calling drawSndFile %i", frameIndex); - frameIndex++; - double energyValue = getEnergyOfFrame(); + // double energyValue = getEnergyOfFrame(); + double energyValue = onset->getDFsample(doubleFrame); energyVector->push_back(energyValue); + if (energyValue > maximumEnergyValue) + maximumEnergyValue = energyValue; }//end while readcount @@ -594,10 +605,10 @@ 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); + //int length = myDoubleMatrix->size(); + printf("length of chromagram is %d frames\n", (int)myDoubleMatrix->size()); + //length = (*myDoubleMatrix)[0].size(); + printf("height of dmatrix is %d\n", (int)(*myDoubleMatrix)[0].size()); for (int i = 0; i < myDoubleMatrix->size();i++){ for (int j = 0; j < ((*myDoubleMatrix)[0]).size();j++){ @@ -606,18 +617,17 @@ } } - int size; - size = energyVector->size(); - printf("size of energy vector is %d \n", size); + printf("size of energy vector is %d \n", (int)energyVector->size()); -// totalNumberOfFrames = frameIndex;//used to use this - but switch to energy vector's size instead - totalNumberOfFrames = size; + for (int i = 0; i < energyVector->size();i++){ + (*energyVector)[i] /= maximumEnergyValue; + } + + totalNumberOfFrames = (int)energyVector->size(); + + chromaConversionRatio = myDoubleMatrix->size() / totalNumberOfFrames; // int size = myDoubleMatrix->size() * CHROMA_CONVERSION_FACTOR; -// printf("size of double matrix is %d and frame index %d", size, frameIndex); - - printf("Total frames %i \n", frameIndex); - } @@ -652,13 +662,13 @@ if (key == OF_KEY_LEFT){ - (*playingAudio).setSpeed(-2); + (*playingAudio).setSpeed(-4); backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1; } if (key == OF_KEY_RIGHT){ - (*playingAudio).setSpeed(2); + (*playingAudio).setSpeed(4); } if (key == OF_KEY_RETURN){
--- a/src/testApp.h Wed May 18 16:47:12 2011 +0100 +++ b/src/testApp.h Thu May 19 11:45:26 2011 +0100 @@ -8,6 +8,7 @@ #include "sndfile.h" #include "ofxFileDialogOSX.h" #include "timeWarp.h" +#include "OnsetDetectionFunction.h" //#include <vector> //#include <cstdlib> @@ -189,10 +190,10 @@ SNDFILE *infile; // define input and output sound files SF_INFO sfinfo ; // struct to hold info about sound file - + int chromaConversionRatio;//not needed but could be useful timeWarp tw; Chromagram chromaG; - + OnsetDetectionFunction* onset; }; #endif