# HG changeset patch # User cannam # Date 1179506597 0 # Node ID da277e8b5244d11b54861f4e4324baf0bacdf236 # Parent 8837aaa2a0e64774bac5687d076d14dfcc627c0f * Some fixes to peak picker * Add broadband energy rise detection function (same as the percussive onset detector in the Vamp example plugins) diff -r 8837aaa2a0e6 -r da277e8b5244 dsp/onsets/DetectionFunction.cpp --- a/dsp/onsets/DetectionFunction.cpp Mon Apr 02 13:20:30 2007 +0000 +++ b/dsp/onsets/DetectionFunction.cpp Fri May 18 16:43:17 2007 +0000 @@ -109,6 +109,9 @@ case DF_COMPLEXSD: retVal = complexSD( m_halfLength, m_magnitude, m_thetaAngle); break; + + case DF_BROADBAND: + retVal = broadband( m_halfLength, m_magnitude, m_thetaAngle); } return retVal; @@ -212,6 +215,20 @@ return val; } +double DetectionFunction::broadband(unsigned int length, double *srcMagnitude, double *srcPhase) +{ + double val = 0; + for (unsigned int i = 0; i < length; ++i) { + double sqrmag = srcMagnitude[i] * srcMagnitude[i]; + if (m_magHistory[i] > 0.0) { + double diff = 10.0 * log10(sqrmag / m_magHistory[i]); + if (diff > m_dbRise) val = val + 1; + } + m_magHistory[i] = sqrmag; + } + return val; +} + double* DetectionFunction::getSpectrumMagnitude() { return m_magnitude; diff -r 8837aaa2a0e6 -r da277e8b5244 dsp/onsets/DetectionFunction.h --- a/dsp/onsets/DetectionFunction.h Mon Apr 02 13:20:30 2007 +0000 +++ b/dsp/onsets/DetectionFunction.h Fri May 18 16:43:17 2007 +0000 @@ -20,12 +20,14 @@ #define DF_SPECDIFF (2) #define DF_PHASEDEV (3) #define DF_COMPLEXSD (4) +#define DF_BROADBAND (5) struct DFConfig{ double stepSecs; // DF step in seconds unsigned int stepSize; // DF step in samples unsigned int frameLength; // DF analysis window - usually 2*step int DFType; // type of detection function ( see defines ) + double dbRise; // only used for broadband df (and required for it) }; class DetectionFunction @@ -44,6 +46,7 @@ double specDiff( unsigned int length, double* src); double phaseDev(unsigned int length, double *srcMagnitude, double *srcPhase); double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase); + double broadband(unsigned int length, double *srcMagnitude, double *srcPhase); private: void initialise( DFConfig Config ); @@ -52,6 +55,7 @@ int m_DFType; unsigned int m_dataLength; unsigned int m_halfLength; + double m_dbRise; double* m_magHistory; double* m_phaseHistory; diff -r 8837aaa2a0e6 -r da277e8b5244 dsp/onsets/PeakPicking.cpp --- a/dsp/onsets/PeakPicking.cpp Mon Apr 02 13:20:30 2007 +0000 +++ b/dsp/onsets/PeakPicking.cpp Fri May 18 16:43:17 2007 +0000 @@ -11,6 +11,7 @@ #include "PeakPicking.h" #include "dsp/maths/Polyfit.h" +#include ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -99,9 +100,10 @@ } for( unsigned int i = 2; i < src.size() - 2; i++) { - if( (src[ i ] > src[ i - 1 ]) && (src[ i ] > src[ i + 1 ]) && (src[ i ] > 0) ) + if( (src[i] > src[i-1]) && (src[i] > src[i+1]) && (src[i] > 0) ) { - m_maxIndex.push_back( i + 1 ); +// m_maxIndex.push_back( i + 1 ); + m_maxIndex.push_back(i); } } @@ -111,7 +113,7 @@ for( unsigned int j = 0; j < maxLength ; j++) { - for( int k = -3; k < 2; k++) + for (int k = -2; k <= 2; ++k) { selMax = src[ m_maxIndex[j] + k ] ; m_maxFit.push_back(selMax); @@ -124,13 +126,13 @@ double h = m_poly[2]; int kk = m_poly.size(); + + if (h < -Qfilta || f > Qfiltc) + { + idx.push_back(m_maxIndex[j]); + } - if( h < -Qfilta || f > Qfiltc) - { - idx.push_back( m_maxIndex[j] ); - } - - m_maxFit.erase( m_maxFit.begin(), m_maxFit.end() ); + m_maxFit.clear(); } return 1; diff -r 8837aaa2a0e6 -r da277e8b5244 dsp/onsets/PeakPicking.h --- a/dsp/onsets/PeakPicking.h Mon Apr 02 13:20:30 2007 +0000 +++ b/dsp/onsets/PeakPicking.h Fri May 18 16:43:17 2007 +0000 @@ -20,7 +20,7 @@ #include "dsp/signalconditioning/DFProcess.h" -struct WinThresh +struct PPWinThresh { unsigned int pre; unsigned int post; @@ -42,7 +42,7 @@ unsigned int LPOrd; // low-pass Filter order double* LPACoeffs; //low pass Filter den coefficients double* LPBCoeffs; //low pass Filter num coefficients - WinThresh WinT;//window size in frames for adaptive thresholding [pre post]: + PPWinThresh WinT;//window size in frames for adaptive thresholding [pre post]: QFitThresh QuadThresh; }; @@ -63,7 +63,6 @@ DFProcConfig m_DFProcessingParams; unsigned int m_DFLength ; - double m_alphaNormParam ; double Qfilta ; double Qfiltb; double Qfiltc; diff -r 8837aaa2a0e6 -r da277e8b5244 dsp/signalconditioning/DFProcess.h --- a/dsp/signalconditioning/DFProcess.h Mon Apr 02 13:20:30 2007 +0000 +++ b/dsp/signalconditioning/DFProcess.h Fri May 18 16:43:17 2007 +0000 @@ -22,7 +22,8 @@ unsigned int winPre; unsigned int winPost; double AlphaNormParam; - bool isMedianPositive;}; + bool isMedianPositive; +}; class DFProcess {