# HG changeset patch # User Venetian # Date 1408035237 -3600 # Node ID 184a7c23204956b17e57b8c7dcaf3db525e5d37a # Parent b1c13e8bec26eaf2194b1678e6245262aeb1d827 changed files since updating computer diff -r b1c13e8bec26 -r 184a7c232049 src/BeatWriter.cpp --- a/src/BeatWriter.cpp Thu Aug 14 16:27:52 2014 +0100 +++ b/src/BeatWriter.cpp Thu Aug 14 17:53:57 2014 +0100 @@ -49,7 +49,7 @@ void BeatWriter::openFile(){ if (!outputFile.is_open()){ outputFile.open(filepath.c_str()); - //printf("opening file %s\n", filepath.c_str()); + printf("opening file %s\n", filepath.c_str()); }else{ printf("file already open! %s\n", filepath.c_str()); } diff -r b1c13e8bec26 -r 184a7c232049 src/PeakProcessor.cpp --- 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); } diff -r b1c13e8bec26 -r 184a7c232049 src/PeakProcessor.h --- a/src/PeakProcessor.h Thu Aug 14 16:27:52 2014 +0100 +++ b/src/PeakProcessor.h Thu Aug 14 17:53:57 2014 +0100 @@ -18,6 +18,10 @@ PeakProcessor(); ~PeakProcessor(); + + void initialise(); + void reset(); + //peak processing requires static const int vectorSize = 512/6; vector recentDFsamples; @@ -34,7 +38,7 @@ float bestSlopeMedian, thresholdRelativeToMedian; bool newOnsetFound, slopeFallenBelowMedian; - + float minimumThreshold; }; #endif \ No newline at end of file diff -r b1c13e8bec26 -r 184a7c232049 src/PreciseOnsetLocator.cpp --- a/src/PreciseOnsetLocator.cpp Thu Aug 14 16:27:52 2014 +0100 +++ b/src/PreciseOnsetLocator.cpp Thu Aug 14 17:53:57 2014 +0100 @@ -38,13 +38,25 @@ } +int PreciseOnsetLocator::findExactOnset(float* frame){ + //store the samples - mainly for viewing actually + onsetSamples.clear(); + for (int i = 0; i < bufferSize;i++){ + onsetSamples.push_back(frame[i]); + } + return findExactOnset(); +} + int PreciseOnsetLocator::findExactOnset(double* frame){ //store the samples - mainly for viewing actually onsetSamples.clear(); for (int i = 0; i < bufferSize;i++){ onsetSamples.push_back(frame[i]); } - + return findExactOnset(); +} + +int PreciseOnsetLocator::findExactOnset(){ double energySum = 0; double lastEnergySum, hopsizeLastEnergySum; double energyDifference; diff -r b1c13e8bec26 -r 184a7c232049 src/PreciseOnsetLocator.h --- a/src/PreciseOnsetLocator.h Thu Aug 14 16:27:52 2014 +0100 +++ b/src/PreciseOnsetLocator.h Thu Aug 14 17:53:57 2014 +0100 @@ -25,6 +25,9 @@ vector recentBufferSamples; double getLastEnergySum(const int& startIndex, const int& vectorSize); + + int findExactOnset(); + int findExactOnset(float* frame); int findExactOnset(double* frame); int exactOnsetIndex; diff -r b1c13e8bec26 -r 184a7c232049 src/btrack_plus/OnsetDetectionFunction.cpp --- a/src/btrack_plus/OnsetDetectionFunction.cpp Thu Aug 14 16:27:52 2014 +0100 +++ b/src/btrack_plus/OnsetDetectionFunction.cpp Thu Aug 14 17:53:57 2014 +0100 @@ -52,7 +52,11 @@ //fftw_free(in); //fftw_free(out); - fft->~accFFT(); +// fft->~accFFT(); + + delete fft; + fft = NULL; + delete [] in; in = NULL; delete [] out; @@ -200,6 +204,67 @@ //-------------------------------------------------------------------------------------- // calculates a single detection function sample from a single audio frame. +double OnsetDetectionFunction :: getDFsample(float inputbuffer[]) +{ + double df_sample; + + // shift audio samples back in frame by hop size + for (int i = 0; i < (framesize-hopsize);i++) + { + frame[i] = frame[i+hopsize]; + } + + // add new samples to frame from input buffer + int j = 0; + for (int i = (framesize-hopsize);i < framesize;i++) + { + frame[i] = inputbuffer[j]; + j++; + } + + switch (df_type){ + case 0: + df_sample = energy_envelope(); // calculate energy envelope detection function sample + break; + case 1: + df_sample = energy_difference(); // calculate half-wave rectified energy difference detection function sample + break; + case 2: + df_sample = spectral_difference(); // calculate spectral difference detection function sample + break; + case 3: + df_sample = spectral_difference_hwr(); // calculate spectral difference detection function sample (half wave rectified) + break; + case 4: + df_sample = phase_deviation(); // calculate phase deviation detection function sample (half wave rectified) + break; + case 5: + df_sample = complex_spectral_difference(); // calcualte complex spectral difference detection function sample + break; + case 6: + df_sample = complex_spectral_difference_hwr(); // calcualte complex spectral difference detection function sample (half-wave rectified) + break; + case 7: + df_sample = high_frequency_content(); // calculate high frequency content detection function sample + break; + case 8: + df_sample = high_frequency_spectral_difference(); // calculate high frequency spectral difference detection function sample + break; + case 9: + df_sample = high_frequency_spectral_difference_hwr(); // calculate high frequency spectral difference detection function (half-wave rectified) + break; + default: + df_sample = 1.0; + } + + return df_sample; +} + + + + +//-------------------------------------------------------------------------------------- +// calculates a single detection function sample from a single audio frame. double OnsetDetectionFunction :: getDFsample(double inputbuffer[]) { double df_sample; diff -r b1c13e8bec26 -r 184a7c232049 src/btrack_plus/OnsetDetectionFunction.h --- a/src/btrack_plus/OnsetDetectionFunction.h Thu Aug 14 16:27:52 2014 +0100 +++ b/src/btrack_plus/OnsetDetectionFunction.h Thu Aug 14 17:53:57 2014 +0100 @@ -22,7 +22,8 @@ OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Constructor (with arguments) ~OnsetDetectionFunction(); // Destructor void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Initialisation Function - + + double getDFsample(float inputbuffer[]); double getDFsample(double inputbuffer[]); // process input buffer and calculate detection function sample void set_df_type(int arg_df_type); // set the detection function type