Mercurial > hg > qm-dsp
diff dsp/onsets/DetectionFunction.cpp @ 12:da277e8b5244
* Some fixes to peak picker
* Add broadband energy rise detection function (same as the percussive
onset detector in the Vamp example plugins)
author | cannam |
---|---|
date | Fri, 18 May 2007 16:43:17 +0000 |
parents | c539af5259da |
children | f2b5c4251bf3 |
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;