diff dsp/onsets/PeakPicking.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 d7116e3183f8
children 2e3f5d2d62c1
line wrap: on
line diff
--- 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;