Mercurial > hg > qm-dsp
changeset 237:343915d55ec5
* Some fixes to peak picker
* Add broadband energy rise detection function (same as the percussive
onset detector in the Vamp example plugins)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 18 May 2007 16:43:17 +0000 |
parents | ac95b396c8c3 |
children | e8e5f9130b49 |
files | dsp/onsets/DetectionFunction.cpp dsp/onsets/DetectionFunction.h dsp/onsets/PeakPicking.cpp dsp/onsets/PeakPicking.h dsp/signalconditioning/DFProcess.h |
diffstat | 5 files changed, 36 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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;
--- 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 <iostream> ////////////////////////////////////////////////////////////////////// // 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;
--- 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;
--- 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 {