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 #ifndef QM_DSP_PEAKPICKING_H 25 #define QM_DSP_PEAKPICKING_H 26 27 #include "maths/MathUtilities.h" 28 #include "maths/MathAliases.h" 29 #include "dsp/signalconditioning/DFProcess.h" 30 31 32 struct PPWinThresh 33 { 34 int pre; 35 int post; 36 PPWinThreshPPWinThresh37 PPWinThresh(int x, int y) : 38 pre(x), 39 post(y) 40 { 41 } 42 }; 43 44 struct QFitThresh 45 { 46 double a; 47 double b; 48 double c; 49 QFitThreshQFitThresh50 QFitThresh(double x, double y, double z) : 51 a(x), 52 b(y), 53 c(z) 54 { 55 } 56 }; 57 58 struct PPickParams 59 { 60 int length; // detection function length 61 double tau; // time resolution of the detection function 62 int alpha; // alpha-norm parameter 63 double cutoff;// low-pass filter cutoff freq 64 int LPOrd; // low-pass filter order 65 double* LPACoeffs; // low-pass filter denominator coefficients 66 double* LPBCoeffs; // low-pass filter numerator coefficients 67 PPWinThresh WinT;// window size in frames for adaptive thresholding [pre post]: 68 QFitThresh QuadThresh; 69 float delta; // delta threshold used as an offset when computing the smoothed detection function 70 PPickParamsPPickParams71 PPickParams() : 72 length(0), 73 tau(0), 74 alpha(0), 75 cutoff(0), 76 LPOrd(0), 77 LPACoeffs(NULL), 78 LPBCoeffs(NULL), 79 WinT(0,0), 80 QuadThresh(0,0,0), 81 delta(0) 82 { 83 } 84 }; 85 86 class PeakPicking 87 { 88 public: 89 PeakPicking( PPickParams Config ); 90 virtual ~PeakPicking(); 91 92 void process( double* src, int len, std::vector<int> &onsets ); 93 94 private: 95 void initialise( PPickParams Config ); 96 void deInitialise(); 97 int quadEval( std::vector<double> &src, std::vector<int> &idx ); 98 99 DFProcConfig m_DFProcessingParams; 100 101 int m_DFLength ; 102 double Qfilta ; 103 double Qfiltb; 104 double Qfiltc; 105 106 double* m_workBuffer; 107 108 DFProcess* m_DFSmoothing; 109 }; 110 111 #endif 112