Mercurial > hg > precise-onset-detection
diff src/PeakProcessor.cpp @ 8:184a7c232049 tip
changed files since updating computer
author | Venetian |
---|---|
date | Thu, 14 Aug 2014 17:53:57 +0100 |
parents | 93b9a9471011 |
children |
line wrap: on
line diff
--- a/src/PeakProcessor.cpp Thu Aug 14 16:27:52 2014 +0100 +++ b/src/PeakProcessor.cpp Thu Aug 14 17:53:57 2014 +0100 @@ -9,23 +9,35 @@ #include "PeakProcessor.h" -const bool printingOn = false;//true;//false; +const bool printingOn = false;//true;//false;//true;//false; + + +/* +how it works +detectionTriggerThreshold is a fairly fdast moving average (every twenty frames) + tend to require newValue > detectionTriggerRatio * detectionTriggerThreshold +*/ PeakProcessor::PeakProcessor(){ recentDFsamples.assign(vectorSize, 0.0); recentDFonsetFound.assign(vectorSize, false); recentDFslopeValues.assign(vectorSize, 0.0); - + /* + //all in reset numberOfDetectionValuesToTest = 10; currentFrame = 0; - cutoffForRepeatOnsetsFrames = 4; + cutoffForRepeatOnsetsFrames = 8; detectionTriggerRatio = 0.34f;//was 0.5 - detectionTriggerThreshold = 1.5;//0.1; + detectionTriggerThreshold = 0.2;//was 1.5 is trigger? bestSlopeMedian = 3; thresholdRelativeToMedian = 1.1; slopeFallenBelowMedian = true; lastSlopeOnsetFrame = 0; + */ + initialise(); + reset(); + minimumThreshold = 15.; } PeakProcessor::~PeakProcessor(){ @@ -36,6 +48,37 @@ } +void PeakProcessor::initialise(){ + numberOfDetectionValuesToTest = 10; + cutoffForRepeatOnsetsFrames = 8; + detectionTriggerRatio = 0.234f;//was 0.5 + thresholdRelativeToMedian = 1.01;//need to be this multiple above median value + //median tends to move relatively slowly + reset(); +/* slopeFallenBelowMedian = true; + lastSlopeOnsetFrame = 0; + currentFrame = 0; + */ +} + +void PeakProcessor::reset(){ + /* + numberOfDetectionValuesToTest = 10; + + cutoffForRepeatOnsetsFrames = 8; + detectionTriggerRatio = 0.234f;//was 0.5 + detectionTriggerThreshold = 0.2; + bestSlopeMedian = 3; + thresholdRelativeToMedian = 1.01;//need to be this multiple above median value + */ + //median tends to move relatively slowly + slopeFallenBelowMedian = true; + lastSlopeOnsetFrame = 0; + currentFrame = 0; + detectionTriggerThreshold = 0.4; + bestSlopeMedian = 16; +} + bool PeakProcessor::peakProcessing(const double& newDFval){ recentDFsamples.erase (recentDFsamples.begin(), recentDFsamples.begin()+1);//erase first val recentDFsamples.push_back(newDFval); @@ -72,6 +115,7 @@ //the idea is we want a high slope double bestValue = 0; + double bestCosAngle = 0; for (int i = 1;i < min(numberOfDetectionValuesToTest, (int)recentDFsamples.size() - 1);i++){ double angle = 0; @@ -85,10 +129,14 @@ testValue = (dfvalue - recentDFsamples[otherIndex]) * cos(angle); } - if (testValue > bestValue) + if (testValue > bestValue){ bestValue = testValue; + bestCosAngle = cos(angle); + } } - + if (printingOn) + printf("best value %f dfValue %f cosAngle %f\n", bestValue, dfvalue, bestCosAngle); + return bestValue; } @@ -106,6 +154,7 @@ (currentFrame - lastSlopeOnsetFrame) > cutoffForRepeatOnsetsFrames //after cutoff time && slopeFallenBelowMedian // has had onset and fall away again && bestValue > detectionTriggerThreshold * detectionTriggerRatio //longer term ratio of winning onsets + && bestValue > minimumThreshold//fixed minimum requirement ){ // printf("frame diff between onsets %6.1f", (1000*framesToSeconds(currentFrame - lastMedianOnsetFrame)) ); onsetDetected = true; @@ -113,6 +162,9 @@ slopeFallenBelowMedian = false; updateDetectionTriggerThreshold(bestValue); + + if (printingOn) + printf("ONSET, best value %f, min %f\n", bestValue, minimumThreshold); }