add queen mary DSP library
[ardour2.git] / libs / qm-dsp / dsp / onsets / DetectionFunction.h
blob7dc1c7b8b68b034be08faf5614ee5574b4944762
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 /*
4 QM DSP Library
6 Centre for Digital Music, Queen Mary, University of London.
7 This file 2005-2006 Christian Landone.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
16 #ifndef DETECTIONFUNCTION_H
17 #define DETECTIONFUNCTION_H
19 #include "maths/MathUtilities.h"
20 #include "maths/MathAliases.h"
21 #include "dsp/phasevocoder/PhaseVocoder.h"
22 #include "base/Window.h"
24 #define DF_HFC (1)
25 #define DF_SPECDIFF (2)
26 #define DF_PHASEDEV (3)
27 #define DF_COMPLEXSD (4)
28 #define DF_BROADBAND (5)
30 struct DFConfig{
31 unsigned int stepSize; // DF step in samples
32 unsigned int frameLength; // DF analysis window - usually 2*step
33 int DFType; // type of detection function ( see defines )
34 double dbRise; // only used for broadband df (and required for it)
35 bool adaptiveWhitening; // perform adaptive whitening
36 double whiteningRelaxCoeff; // if < 0, a sensible default will be used
37 double whiteningFloor; // if < 0, a sensible default will be used
40 class DetectionFunction
42 public:
43 double* getSpectrumMagnitude();
44 DetectionFunction( DFConfig Config );
45 virtual ~DetectionFunction();
46 double process( const double* TDomain );
47 double process( const double* magnitudes, const double* phases );
49 private:
50 void whiten();
51 double runDF();
53 double HFC( unsigned int length, double* src);
54 double specDiff( unsigned int length, double* src);
55 double phaseDev(unsigned int length, double *srcPhase);
56 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
57 double broadband(unsigned int length, double *srcMagnitude);
59 private:
60 void initialise( DFConfig Config );
61 void deInitialise();
63 int m_DFType;
64 unsigned int m_dataLength;
65 unsigned int m_halfLength;
66 unsigned int m_stepSize;
67 double m_dbRise;
68 bool m_whiten;
69 double m_whitenRelaxCoeff;
70 double m_whitenFloor;
72 double* m_magHistory;
73 double* m_phaseHistory;
74 double* m_phaseHistoryOld;
75 double* m_magPeaks;
77 double* m_DFWindowedFrame; // Array for windowed analysis frame
78 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
79 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
81 Window<double> *m_window;
82 PhaseVocoder* m_phaseVoc; // Phase Vocoder
85 #endif