update qm-dsp library
[ardour.git] / libs / qm-dsp / dsp / onsets / PeakPicking.cpp
index be98a82a345711004a7b5b6588973b482e5ad7b9..e30e71568f9981ba9e65d7427884aa5fa27982b7 100644 (file)
@@ -6,11 +6,19 @@
     Centre for Digital Music, Queen Mary, University of London.
     This file 2005-2006 Christian Landone.
 
+    Modifications:
+
+    - delta threshold
+    Description: add delta threshold used as offset in the smoothed
+    detection function
+    Author: Mathieu Barthet
+    Date: June 2010
+
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
     published by the Free Software Foundation; either version 2 of the
     License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
+    COPYING included with this distribution for more information.    
 */
 
 #include "PeakPicking.h"
@@ -41,15 +49,16 @@ void PeakPicking::initialise( PPickParams Config )
     Qfilta = Config.QuadThresh.a ;
     Qfiltb = Config.QuadThresh.b ;
     Qfiltc = Config.QuadThresh.c ;
-
-    m_DFProcessingParams.length = m_DFLength;
-    m_DFProcessingParams.LPOrd = Config.LPOrd;
-    m_DFProcessingParams.LPACoeffs = Config.LPACoeffs;
-    m_DFProcessingParams.LPBCoeffs = Config.LPBCoeffs;
+       
+    m_DFProcessingParams.length = m_DFLength; 
+    m_DFProcessingParams.LPOrd = Config.LPOrd; 
+    m_DFProcessingParams.LPACoeffs = Config.LPACoeffs; 
+    m_DFProcessingParams.LPBCoeffs = Config.LPBCoeffs; 
     m_DFProcessingParams.winPre  = Config.WinT.pre;
-    m_DFProcessingParams.winPost = Config.WinT.post;
+    m_DFProcessingParams.winPost = Config.WinT.post; 
     m_DFProcessingParams.AlphaNormParam = Config.alpha;
     m_DFProcessingParams.isMedianPositive = false;
+    m_DFProcessingParams.delta = Config.delta; //add the delta threshold as an adjustable parameter
 
     m_DFSmoothing = new DFProcess( m_DFProcessingParams );
 
@@ -68,19 +77,19 @@ void PeakPicking::process( double* src, unsigned int len, vector<int> &onsets )
 {
     if (len < 4) return;
 
-    vector <double> m_maxima;
+    vector <double> m_maxima;  
 
-    // Signal conditioning
+    // Signal conditioning 
     m_DFSmoothing->process( src, m_workBuffer );
-
+       
     for( unsigned int u = 0; u < len; u++)
     {
-       m_maxima.push_back( m_workBuffer[ u ] );
+       m_maxima.push_back( m_workBuffer[ u ] );                
     }
-
+       
     quadEval( m_maxima, onsets );
 
-    for(unsigned int b = 0; b <  m_maxima.size(); b++)
+    for( int b = 0; b <  (int)m_maxima.size(); b++)
     {
        src[ b ] = m_maxima[ b ];
     }
@@ -92,7 +101,7 @@ int PeakPicking::quadEval( vector<double> &src, vector<int> &idx )
 
     vector <int> m_maxIndex;
     vector <int> m_onsetPosition;
-
+       
     vector <double> m_maxFit;
     vector <double> m_poly;
     vector <double> m_err;
@@ -123,7 +132,7 @@ int PeakPicking::quadEval( vector<double> &src, vector<int> &idx )
         for (int k = -2; k <= 2; ++k)
        {
            selMax = src[ m_maxIndex[j] + k ] ;
-           m_maxFit.push_back(selMax);
+           m_maxFit.push_back(selMax);                 
        }
 
        TPolyFit::PolyFit2(m_err, m_maxFit, m_poly);
@@ -135,7 +144,7 @@ int PeakPicking::quadEval( vector<double> &src, vector<int> &idx )
        {
            idx.push_back(m_maxIndex[j]);
        }
-
+               
        m_maxFit.clear();
     }