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 #include <vector>
27 
28 //=======================================================================
31 {
32  EnergyEnvelope,
33  EnergyDifference,
34  SpectralDifference,
35  SpectralDifferenceHWR,
36  PhaseDeviation,
37  ComplexSpectralDifference,
38  ComplexSpectralDifferenceHWR,
39  HighFrequencyContent,
40  HighFrequencySpectralDifference,
41  HighFrequencySpectralDifferenceHWR
42 };
43 
44 //=======================================================================
47 {
48  RectangularWindow,
49  HanningWindow,
50  HammingWindow,
51  BlackmanWindow,
52  TukeyWindow
53 };
54 
55 //=======================================================================
58 {
59 public:
60 
66  OnsetDetectionFunction(int hopSize_,int frameSize_);
67 
68 
75  OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_);
76 
79 
85  void initialise(int hopSize_,int frameSize_);
86 
93  void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_);
94 
99  double calculateOnsetDetectionFunctionSample(double *buffer);
100 
104  void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
105 
106 private:
107 
109  void performFFT();
110 
111  //=======================================================================
113  double energyEnvelope();
114 
116  double energyDifference();
117 
119  double spectralDifference();
120 
122  double spectralDifferenceHWR();
123 
125  double phaseDeviation();
126 
128  double complexSpectralDifference();
129 
131  double complexSpectralDifferenceHWR();
132 
134  double highFrequencyContent();
135 
137  double highFrequencySpectralDifference();
138 
140  double highFrequencySpectralDifferenceHWR();
141 
142  //=======================================================================
144  void calculateRectangularWindow();
145 
147  void calculateHanningWindow();
148 
150  void calclulateHammingWindow();
151 
153  void calculateBlackmanWindow();
154 
156  void calculateTukeyWindow();
157 
158  //=======================================================================
163  double princarg(double phaseVal);
164 
165 
166  double pi;
168  int frameSize;
169  int hopSize;
170  int onsetDetectionFunctionType;
171  int windowType;
173  fftw_plan p;
174  fftw_complex *complexIn;
175  fftw_complex *complexOut;
177  bool initialised;
179  std::vector<double> frame;
180  std::vector<double> window;
182  double prevEnergySum;
184  std::vector<double> magSpec;
185  std::vector<double> prevMagSpec;
187  std::vector<double> phase;
188  std::vector<double> prevPhase;
189  std::vector<double> prevPhase2;
191 };
192 
193 
194 #endif