Mercurial > hg > multitrack-audio-matcher
changeset 11:9a2b008c4706
Priors for each channel and scrolling projection for new prior is added
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 05 Feb 2012 00:00:58 +0000 |
parents | cbadb9d05d29 |
children | 446121327276 |
files | README.txt bayesianArraySrc/BayesianArrayStructure.cpp bayesianArraySrc/BayesianArrayStructure.h src/AudioEventMatcher.cpp src/AudioEventMatcher.h |
diffstat | 5 files changed, 88 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/README.txt Sat Feb 04 19:59:27 2012 +0000 +++ b/README.txt Sun Feb 05 00:00:58 2012 +0000 @@ -33,6 +33,8 @@ OPTIMISE the starting point for the update routine when new`Pitch or onset is found. goes all the way through chromaOnsets +check: Should the offset potion be the alignment position or the actual time in - i guess the former but are we using the latter? +
--- a/bayesianArraySrc/BayesianArrayStructure.cpp Sat Feb 04 19:59:27 2012 +0000 +++ b/bayesianArraySrc/BayesianArrayStructure.cpp Sun Feb 05 00:00:58 2012 +0000 @@ -107,10 +107,19 @@ printf("speed adding to index for 1 = %f\n", relativeSpeedPosterior.getRealTermsAsIndex(1)); relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1), 0.1); relativeSpeedPosterior.addGaussianShapeFromRealTime(1, 3, 0.5); + + + //tmp debug test + //relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1.8), 0.15); relativeSpeedPosterior.renormalise(); relativeSpeedPosterior.getMaximum(); + + relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); + + + printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); } @@ -662,8 +671,8 @@ } //PROJECT PRIOR CODE -/* -void BayesianArrayStructure::projectDistribution(const double& newEventTime, DynamicVector& projectedPrior){ + +void BayesianArrayStructure::projectDistribution(const double& newEventTime, const double& newAlignmentPosition, DynamicVector& projectedPrior){ projectedPrior.copyFromDynamicVector(posterior); @@ -674,89 +683,71 @@ // } - updateBestEstimate(timeDifference); - lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); +// updateBestEstimate(timeDifference); +// lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); //set TARGETS - commented tenmporarily - setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); - - crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference); - + + //setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); + projectedPrior.offset = posterior.offset;//max(0., newAlignmentPosition - (projectedPrior.scalar*projectedPrior.arraySize/2)); + +// int timeDifference = newEventTime - lastEventTime; + + double timeDifferenceInPositionVectorUnits = timeDifference / projectedPrior.scalar; + + // printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); + projectedPrior.zero();//kill prior + + // calculateNewPriorOffset(timeDifference);//dioesnt do anything + + // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); + + if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) + complexCrossUpdateProjection(projectedPrior, timeDifferenceInPositionVectorUnits); + else + translatePosteriorByMaximumSpeed(projectedPrior, timeDifferenceInPositionVectorUnits); + + + // updateCounter++; + projectedPrior.renormalise();//not strictly necessary?? + + //i.e. using the same offset as prior - posterior.offset = prior.offset;// +// posterior.offset = prior.offset;// // float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));// prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2)); // printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset); - lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis(); +// lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis(); } - -void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ - - //set the cutoff for offset of position first! XXX - - double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; - - printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); - prior.zero();//kill prior - - // calculateNewPriorOffset(timeDifference);//dioesnt do anything - - // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); - - if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) - complexCrossUpdate(timeDifferenceInPositionVectorUnits); - else - translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); - - - updateCounter++; - prior.renormalise();//not strictly necessary?? - -} - -void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ - - - printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits); +void BayesianArrayStructure::complexCrossUpdateProjection(DynamicVector& projectedPrior, const double& timeDifferenceInPositionVectorUnits){ int distanceMoved, newPriorIndex; - + double speedValue = relativeSpeedPosterior.offset; for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ - // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 - - //so we have moved distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value - // printf("Speed value %f time %f gives distance %i\n", speedValue, timeDifferenceInPositionVectorUnits, distanceMoved); if (relativeSpeedPosterior.array[i] != 0){ double speedContribution = relativeSpeedPosterior.array[i]; - // printf("speed [%i](val[%f]) gives %f moved %i in %f units \n", i, relativeSpeedPosterior.array[i], speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); - - //1/2/12 deleted line - newPriorIndex = posterior.offset - prior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed + newPriorIndex = posterior.offset - projectedPrior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed int postIndex = 0;//index of posterior that will contribute - while (postIndex < posterior.arraySize && newPriorIndex < prior.arraySize){ - - //did use a for loop - // for (postIndex = 0;postIndex < posterior.arraySize;postIndex++){ - //old posterior contributing to new prior - + while (postIndex < posterior.arraySize && newPriorIndex < projectedPrior.arraySize){ + //would use this method //newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; if (newPriorIndex >= 0){ - prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); + projectedPrior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); // printf("speed index %i new prior index %i post val %f speed contrib %f dist %i\n", i, newPriorIndex, posterior.array[postIndex], speedContribution, distanceMoved); } //but we actually do this for simplicity @@ -772,14 +763,12 @@ // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 }//end speed - - - printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate())); + } -void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ +void BayesianArrayStructure::translatePosteriorByMaximumSpeed(DynamicVector& translatedPosterior, const double& timeDifferenceInPositionVectorUnits){ int distanceMoved, newPriorIndex; @@ -799,17 +788,18 @@ //old posterior contributing to new prior newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ - prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); + translatedPosterior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); } } } - */ + //END PROJECT PRIOR CODE + /* void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){
--- a/bayesianArraySrc/BayesianArrayStructure.h Sat Feb 04 19:59:27 2012 +0000 +++ b/bayesianArraySrc/BayesianArrayStructure.h Sun Feb 05 00:00:58 2012 +0000 @@ -98,6 +98,10 @@ bool usingIntegratedTempoEstimate; double relativeSpeedLikelihoodStdDev; + void projectDistribution(const double& newEventTime, const double& newAlignmentPosition, DynamicVector& projectedPrior); + void complexCrossUpdateProjection(DynamicVector& projectedPrior, const double& timeDifferenceInPositionVectorUnits); + void translatePosteriorByMaximumSpeed(DynamicVector& translatedPosterior, const double& timeDifferenceInPositionVectorUnits); + void printPostOffset(); bool updatingSpeedDistribution;//false for testing
--- a/src/AudioEventMatcher.cpp Sat Feb 04 19:59:27 2012 +0000 +++ b/src/AudioEventMatcher.cpp Sun Feb 05 00:00:58 2012 +0000 @@ -51,6 +51,8 @@ bayesianStruct.setStartPlaying(); currentAlignmentPosition = 0; startTime = ofGetElapsedTimeMillis(); + + projectedPrior = bayesianStruct.prior; //bayesianStruct.posterior.printArray(); } @@ -72,10 +74,12 @@ // double tmp = bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate);; // double timetmp = (newTime - lastAlignmentTime); // double speedtmp = bayesianStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesianStruct.relativeSpeedPosterior.MAPestimate); - +// currentAlignmentTime = newTime; currentAlignmentPosition = bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate); currentAlignmentPosition += (newTime - lastAlignmentTime) * bayesianStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesianStruct.relativeSpeedPosterior.MAPestimate); + bayesianStruct.projectDistribution(newTime, currentAlignmentPosition, projectedPrior);//prior gets updated to where we are now + // printf("ALIGN pos %f time diff %f (now %f , last %f)speed %f :: ALIGN BEST %f\n", tmp, timetmp, (double)ofGetElapsedTimeMillis(), lastAlignmentTime, speedtmp, currentAlignmentPosition); } @@ -88,19 +92,15 @@ //draw the scrolling audio tracks recordedTracks.drawTracks(); - - ofSetColor(255); // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); setScreenDisplayTimes(); drawBayesianDistributions(); - // bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); - + //bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); //bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); - - // bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); + //bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); ofDrawBitmapString("pitch "+ofToString(recentPitch, 2)+", Time "+ofToString(recentTime, 0), 20, 20); @@ -157,6 +157,11 @@ for (int i = 0; i <recordedTracks.numberOfAudioTracks;i++){ ofSetColor(200,255,50); likelihoodVisualisation[i].drawConstrainedVector(likelihoodVisualisation[i].getRealTermsAsIndex(screenStartTimeMillis), likelihoodVisualisation[i].getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window); + + ofSetColor(0,255,150); + recentPriors[i].drawConstrainedVector(recentPriors[i].getRealTermsAsIndex(screenStartTimeMillis), recentPriors[i].getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window); + + ofSetColor(255); ofDrawBitmapString("recent event "+ofToString(recentEventTime[i]), recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.x + 20, recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.y + recordedTracks.loadedAudioFiles[i].fileLoader.onsetDetect.window.height - 10); } @@ -167,7 +172,10 @@ recentPrior.drawConstrainedVector(priorStartIndex, priorEndIndex, 0, ofGetWidth(), bayesPositionWindow); ofSetColor(255,0,100);//purple prior - bayesianStruct.prior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesLikelihoodWindow); + bayesianStruct.prior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesPositionWindow); + + ofSetColor(255,0,0); + projectedPrior.drawConstrainedVector(bayesianStruct.prior.getRealTermsAsIndex(screenStartTimeMillis), bayesianStruct.prior.getRealTermsAsIndex(screenEndTimeMillis), 0, ofGetWidth(), bayesLikelihoodWindow); } @@ -176,7 +184,7 @@ liveInput.addPitchEvent(pitchIn, timeIn); //printPosteriorMAPinfo(); - + matchNewPitchEvent(channel, pitchIn, timeIn);//main pitch matching fn likelihoodVisualisation[1] = bayesianStruct.likelihood; @@ -243,14 +251,20 @@ } } + if (numberOfMatchesFound > 0){ // bayesianStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesianStruct.likelihood.length); bayesianStruct.likelihood.addConstant(numberOfMatchesFound*(1-onsetLikelihoodToNoise)/(onsetLikelihoodToNoise*bayesianStruct.likelihood.length)); bayesianStruct.likelihood.renormalise(); bayesianStruct.calculatePosterior(); - lastAlignmentTime = timeIn;//use TIMESTAMP recentEventTime[channel] = timeIn;//ofGetElapsedTimeMillis() - startTime; + + recentPriors[channel] = bayesianStruct.prior; + + } + + } @@ -300,10 +314,13 @@ //bayesianStruct.likelihood.addConstant(1); bayesianStruct.calculatePosterior(); + lastAlignmentTime = timeIn;//has to use the STAMPED time + recentEventTime[channel] = timeIn; + + recentPriors[channel] = bayesianStruct.prior; } - lastAlignmentTime = timeIn;//has to use the STAMPED time - recentEventTime[channel] = timeIn; + } double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){
--- a/src/AudioEventMatcher.h Sat Feb 04 19:59:27 2012 +0000 +++ b/src/AudioEventMatcher.h Sun Feb 05 00:00:58 2012 +0000 @@ -64,6 +64,7 @@ double recentPitch, recentTime; DynamicVector likelihoodVisualisation[3]; + DynamicVector recentPriors[3]; DynamicVector recentPrior; DynamicVector projectedPrior; @@ -72,6 +73,7 @@ double recentEventTime[3]; int startTime; + int currentAlignmentTime; double screenStartTimeMillis, screenEndTimeMillis, screenWidthMillis; bool followingLiveInput;