1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     QM DSP Library
5 
6     Centre for Digital Music, Queen Mary, University of London.
7     This file 2005-2006 Christian Landone.
8 
9     Modifications:
10 
11     - delta threshold
12     Description: add delta threshold used as offset in the smoothed
13     detection function
14     Author: Mathieu Barthet
15     Date: June 2010
16 
17     This program is free software; you can redistribute it and/or
18     modify it under the terms of the GNU General Public License as
19     published by the Free Software Foundation; either version 2 of the
20     License, or (at your option) any later version.  See the file
21     COPYING included with this distribution for more information.
22 */
23 
24 // PeakPicking.h: interface for the PeakPicking class.
25 //
26 //////////////////////////////////////////////////////////////////////
27 
28 #ifndef PEAKPICKING_H
29 #define PEAKPICKING_H
30 
31 #include "maths/MathUtilities.h"
32 #include "maths/MathAliases.h"
33 #include "dsp/signalconditioning/DFProcess.h"
34 
35 
36 struct PPWinThresh
37 {
38     unsigned int pre;
39     unsigned int  post;
40 
PPWinThreshPPWinThresh41     PPWinThresh(unsigned int x, unsigned int y) :
42         pre(x),
43         post(y)
44     {
45     }
46 };
47 
48 struct QFitThresh
49 {
50     double a;
51     double b;
52     double c;
53 
QFitThreshQFitThresh54     QFitThresh(double x, double y, double z) :
55         a(x),
56         b(y),
57         c(z)
58     {
59     }
60 };
61 
62 struct PPickParams
63 {
64     unsigned int length; //Detection FunctionLength
65     double tau; // time resolution of the detection function
66     unsigned int alpha; //alpha-norm parameter
67     double cutoff;//low-pass Filter cutoff freq
68     unsigned int LPOrd; // low-pass Filter order
69     double* LPACoeffs; //low pass Filter den coefficients
70     double* LPBCoeffs; //low pass Filter num coefficients
71     PPWinThresh WinT;//window size in frames for adaptive thresholding [pre post]:
72     QFitThresh QuadThresh;
73     float delta; //delta threshold used as an offset when computing the smoothed detection function
74 
PPickParamsPPickParams75     PPickParams() :
76         length(0),
77         tau(0),
78         alpha(0),
79         cutoff(0),
80         LPOrd(0),
81         LPACoeffs(NULL),
82         LPBCoeffs(NULL),
83         WinT(0,0),
84         QuadThresh(0,0,0),
85         delta(0)
86     {
87     }
88 };
89 
90 class PeakPicking
91 {
92 public:
93     PeakPicking( PPickParams Config );
94     virtual ~PeakPicking();
95 
96     void process( double* src, unsigned int len, vector<int> &onsets  );
97 
98 
99 private:
100     void initialise( PPickParams Config  );
101     void deInitialise();
102     int  quadEval( vector<double> &src, vector<int> &idx );
103 
104     DFProcConfig m_DFProcessingParams;
105 
106     unsigned int m_DFLength ;
107     double Qfilta ;
108     double Qfiltb;
109     double Qfiltc;
110 
111 
112     double* m_workBuffer;
113 
114     DFProcess*	m_DFSmoothing;
115 };
116 
117 #endif
118