BTrack - A Real-Time Beat Tracker
Loading...
Searching...
No Matches
OnsetDetectionFunction.h
Go to the documentation of this file.
1//=======================================================================
20//=======================================================================
21
22#ifndef __ONSETDETECTIONFUNCTION_H
23#define __ONSETDETECTIONFUNCTION_H
24
25#ifdef USE_FFTW
26#include "fftw3.h"
27#endif
28
29#ifdef USE_KISS_FFT
30#include "kiss_fft.h"
31#endif
32
33#include <vector>
34
35//=======================================================================
38{
39 EnergyEnvelope,
40 EnergyDifference,
41 SpectralDifference,
42 SpectralDifferenceHWR,
43 PhaseDeviation,
44 ComplexSpectralDifference,
45 ComplexSpectralDifferenceHWR,
46 HighFrequencyContent,
47 HighFrequencySpectralDifference,
48 HighFrequencySpectralDifferenceHWR
49};
50
51//=======================================================================
54{
55 RectangularWindow,
56 HanningWindow,
57 HammingWindow,
58 BlackmanWindow,
59 TukeyWindow
60};
61
62//=======================================================================
65{
66public:
67
73 OnsetDetectionFunction (int hopSize, int frameSize);
74
75
82 OnsetDetectionFunction (int hopSize, int frameSize, int onsetDetectionFunctionType, int windowType);
83
86
92 void initialise (int hopSize, int frameSize);
93
100 void initialise (int hopSize, int frameSize, int onsetDetectionFunctionType, int windowType);
101
106 double calculateOnsetDetectionFunctionSample (double* buffer);
107
111 void setOnsetDetectionFunctionType (int onsetDetectionFunctionType);
112
113private:
114
116 void performFFT();
117
118 //=======================================================================
120 double energyEnvelope();
121
123 double energyDifference();
124
126 double spectralDifference();
127
129 double spectralDifferenceHWR();
130
132 double phaseDeviation();
133
135 double complexSpectralDifference();
136
138 double complexSpectralDifferenceHWR();
139
141 double highFrequencyContent();
142
144 double highFrequencySpectralDifference();
145
147 double highFrequencySpectralDifferenceHWR();
148
149 //=======================================================================
151 void calculateRectangularWindow();
152
154 void calculateHanningWindow();
155
157 void calclulateHammingWindow();
158
160 void calculateBlackmanWindow();
161
163 void calculateTukeyWindow();
164
165 //=======================================================================
170 double princarg(double phaseVal);
171
172 void initialiseFFT();
173 void freeFFT();
174
175 double pi;
177 int frameSize;
178 int hopSize;
179 int onsetDetectionFunctionType;
180 int windowType;
182 //=======================================================================
183#ifdef USE_FFTW
184 fftw_plan p;
185 fftw_complex* complexIn;
186 fftw_complex* complexOut;
187#endif
188
189#ifdef USE_KISS_FFT
190 kiss_fft_cfg cfg;
191 kiss_fft_cpx* fftIn;
192 kiss_fft_cpx* fftOut;
193 std::vector<std::vector<double> > complexOut;
194#endif
195
196 //=======================================================================
197 bool initialised;
199 std::vector<double> frame;
200 std::vector<double> window;
202 double prevEnergySum;
204 std::vector<double> magSpec;
205 std::vector<double> prevMagSpec;
207 std::vector<double> phase;
208 std::vector<double> prevPhase;
209 std::vector<double> prevPhase2;
210};
211
212
213#endif
OnsetDetectionFunctionType
Definition OnsetDetectionFunction.h:38
WindowType
Definition OnsetDetectionFunction.h:54
Definition OnsetDetectionFunction.h:65
void initialise(int hopSize, int frameSize)
Definition OnsetDetectionFunction.cpp:64
double calculateOnsetDetectionFunctionSample(double *buffer)
Definition OnsetDetectionFunction.cpp:179
~OnsetDetectionFunction()
Definition OnsetDetectionFunction.cpp:55
void setOnsetDetectionFunctionType(int onsetDetectionFunctionType)
Definition OnsetDetectionFunction.cpp:173