BTrack - A Real-Time Beat Tracker
 All Classes Files Functions Enumerations Pages
OnsetDetectionFunction.h
Go to the documentation of this file.
1 //=======================================================================
20 //=======================================================================
21 
22 #ifndef __ONSETDETECTIONFUNCTION_H
23 #define __ONSETDETECTIONFUNCTION_H
24 
25 #include "fftw3.h"
26 
27 //=======================================================================
30 {
31  EnergyEnvelope,
32  EnergyDifference,
33  SpectralDifference,
34  SpectralDifferenceHWR,
35  PhaseDeviation,
36  ComplexSpectralDifference,
37  ComplexSpectralDifferenceHWR,
38  HighFrequencyContent,
39  HighFrequencySpectralDifference,
40  HighFrequencySpectralDifferenceHWR
41 };
42 
43 //=======================================================================
46 {
47  RectangularWindow,
48  HanningWindow,
49  HammingWindow,
50  BlackmanWindow,
51  TukeyWindow
52 };
53 
54 //=======================================================================
57 {
58 public:
59 
66  OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
67 
70 
77  void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
78 
83  double calculateOnsetDetectionFunctionSample(double *buffer);
84 
88  void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
89 
90 private:
91 
93  void performFFT();
94 
95  //=======================================================================
97  double energyEnvelope();
98 
100  double energyDifference();
101 
103  double spectralDifference();
104 
106  double spectralDifferenceHWR();
107 
109  double phaseDeviation();
110 
112  double complexSpectralDifference();
113 
115  double complexSpectralDifferenceHWR();
116 
118  double highFrequencyContent();
119 
121  double highFrequencySpectralDifference();
122 
124  double highFrequencySpectralDifferenceHWR();
125 
126  //=======================================================================
128  void calculateRectangularWindow();
129 
131  void calculateHanningWindow();
132 
134  void calclulateHammingWindow();
135 
137  void calculateBlackmanWindow();
138 
140  void calculateTukeyWindow();
141 
142  //=======================================================================
147  double princarg(double phaseVal);
148 
149 
150  double pi;
152  int frameSize;
153  int hopSize;
154  int onsetDetectionFunctionType;
156  fftw_plan p;
157  fftw_complex *complexIn;
158  fftw_complex *complexOut;
160  int initialised;
162  double *frame;
163  double *window;
165  double prevEnergySum;
167  double *magSpec;
168  double *prevMagSpec;
170  double *phase;
171  double *prevPhase;
172  double *prevPhase2;
174 };
175 
176 
177 #endif