Mercurial > hg > midi-score-follower
changeset 44:6c8a048720c3
improving functions in dynamic vector - to copy with changing offset in copyvector and the drawvector routine
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 Feb 2012 16:07:09 +0000 |
parents | 732ce4711159 |
children | 90ad1817ca56 |
files | .DS_Store jnmr/DynamicVector.cpp jnmr/DynamicVector.h jnmr/midiEventHolder.cpp jnmr/testApp.cpp |
diffstat | 5 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/jnmr/DynamicVector.cpp Tue Jan 24 17:11:11 2012 +0000 +++ b/jnmr/DynamicVector.cpp Wed Feb 01 16:07:09 2012 +0000 @@ -30,6 +30,7 @@ void DynamicVector::copyFromDynamicVector(const DynamicVector& dynamicVec){ if (dynamicVec.length == length){ + offset = dynamicVec.offset; for (int i = 0;i < length;i++) array[i] = dynamicVec.array[i]; } @@ -172,6 +173,25 @@ // addGaussianShapeByLookupTable(mean, StdDev, factor); } + +void DynamicVector::addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor){ + + double mean = getRealTermsAsIndex(actualTime); + printf("Gaussian realtime %f at index %f\n", actualTime, mean); + int i; + double std_dev_factor = (2*StdDev*StdDev); + factor *= (1/(StdDev*sqrt(2*PI))); + int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); + int minVal = max(0, (int)(mean - 4.8*StdDev)); + + for (i=minVal;i < maxVal;i++){ + array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); + } + + // addGaussianShapeByLookupTable(mean, StdDev, factor); +} + + void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double factor){ int i; int lookupIndex ; @@ -257,7 +277,8 @@ int newHeightPixel; for (int i = startInt;i < endInt;i++){ newHeightPixel = (int) heightConstant * (maxVal - array[i]); - ofLine (stepSize*(i-1), lastHeightPixel, stepSize*i, newHeightPixel); + int xPos = i - startInt; + ofLine (stepSize*(xPos-1), lastHeightPixel, stepSize*xPos, newHeightPixel); lastHeightPixel = newHeightPixel; }
--- a/jnmr/DynamicVector.h Tue Jan 24 17:11:11 2012 +0000 +++ b/jnmr/DynamicVector.h Wed Feb 01 16:07:09 2012 +0000 @@ -40,6 +40,8 @@ void addConstant(const double& value); void addGaussianShape(const double& mean, const double& stddev, double factor); + void addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor); + void addTriangularShape(double mean, double width, double factor); void addToIndex(const int& index, const double& constant);
--- a/jnmr/midiEventHolder.cpp Tue Jan 24 17:11:11 2012 +0000 +++ b/jnmr/midiEventHolder.cpp Wed Feb 01 16:07:09 2012 +0000 @@ -346,8 +346,9 @@ // double confidenceMeasure = 0; // if (totalConfidence > 0) // confidenceMeasure = bayesStruct.posterior.getValueAtMillis(recordedEventTimes[matchesFound[i]])/totalConfidence; - - bayesStruct.likelihood.addGaussianShape(recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset, likelihoodWidth, quantity);//* confidenceMeasure + + //bayesStruct.likelihood.addGaussianShape(recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset, likelihoodWidth, quantity);//* confidenceMeasure + bayesStruct.likelihood.addGaussianShapeFromRealTime(recordedEventTimes[matchesFound[i]], likelihoodWidth, quantity);//* confidenceMeasure }//end if } bayesStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesStruct.likelihood.length); @@ -850,7 +851,7 @@ } - printf("assert rec tick time %i vs %i midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", + printf("annotaions: rec tick time %i vs %i midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", recordedNoteOnMatrix[smoothIndex][0], annotationTick, recordedNoteOnMatrix[smoothIndex][1], beatPositions[smoothIndex], playingTime, annotationNote, annotationLocation, annotationTime, difference);
--- a/jnmr/testApp.cpp Tue Jan 24 17:11:11 2012 +0000 +++ b/jnmr/testApp.cpp Wed Feb 01 16:07:09 2012 +0000 @@ -117,7 +117,7 @@ } // printf("MIDI NOTE %i \n", newMidiOnPitch); midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); - noteInStream.newNoteCounted(newMidiOnPitch); + noteInStream.newNoteCounted(newMidiOnPitch);//counts notes for an overall score } } @@ -713,7 +713,7 @@ std::string filename = midiFileName;//argv[1]; printf("Loading'%s'\n", midiFileName.c_str()); -// fileLoader.chopBeginning = true; + fileLoader.loadFile(filename, midiEvents); }//new end of load function