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 
67  OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
68 
71 
78  void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
79 
84  double calculateOnsetDetectionFunctionSample(double *buffer);
85 
89  void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
90 
91 private:
92 
94  void performFFT();
95 
96  //=======================================================================
98  double energyEnvelope();
99 
101  double energyDifference();
102 
104  double spectralDifference();
105 
107  double spectralDifferenceHWR();
108 
110  double phaseDeviation();
111 
113  double complexSpectralDifference();
114 
116  double complexSpectralDifferenceHWR();
117 
119  double highFrequencyContent();
120 
122  double highFrequencySpectralDifference();
123 
125  double highFrequencySpectralDifferenceHWR();
126 
127  //=======================================================================
129  void calculateRectangularWindow();
130 
132  void calculateHanningWindow();
133 
135  void calclulateHammingWindow();
136 
138  void calculateBlackmanWindow();
139 
141  void calculateTukeyWindow();
142 
143  //=======================================================================
148  double princarg(double phaseVal);
149 
150 
151  double pi;
153  int frameSize;
154  int hopSize;
155  int onsetDetectionFunctionType;
157  fftw_plan p;
158  fftw_complex *complexIn;
159  fftw_complex *complexOut;
161  bool initialised;
163  std::vector<double> frame;
164  std::vector<double> window;
166  double prevEnergySum;
168  std::vector<double> magSpec;
169  std::vector<double> prevMagSpec;
171  std::vector<double> phase;
172  std::vector<double> prevPhase;
173  std::vector<double> prevPhase2;
175 };
176 
177 
178 #endif