BTrack - A Real-Time Beat Tracker
Loading...
Searching...
No Matches
BTrack.h
Go to the documentation of this file.
1//=======================================================================
20//=======================================================================
21
22#ifndef __BTRACK_H
23#define __BTRACK_H
24
26#include "CircularBuffer.h"
27#include <vector>
28
29//=======================================================================
35class BTrack {
36
37public:
38
39 //=======================================================================
41 BTrack();
42
46 BTrack (int hopSize);
47
52 BTrack (int hopSize, int frameSize);
53
55 ~BTrack();
56
57 //=======================================================================
62 void updateHopAndFrameSize (int hopSize, int frameSize);
63
64 //=======================================================================
69 void processAudioFrame (double* frame);
70
74 void processOnsetDetectionFunctionSample (double sample);
75
76 //=======================================================================
78 int getHopSize();
79
82
85
88
89 //=======================================================================
93 void setTempo (double tempo);
94
99 void fixTempo (double tempo);
100
102 void doNotFixTempo();
103
104 //=======================================================================
112 static double getBeatTimeInSeconds (long frameNumber, int hopSize, int fs);
113
114private:
115
119 void initialise (int hopSize);
120
124 void setHopSize (int hopSize);
125
127 void resampleOnsetDetectionFunction();
128
132 void updateCumulativeScore (double onsetDetectionFunctionSample);
133
135 void predictBeat();
136
138 void calculateTempo();
139
144 void adaptiveThreshold (std::vector<double>& x);
145
152 double calculateMeanOfVector (std::vector<double>& vector, int startIndex, int endIndex);
153
157 void normaliseVector (std::vector<double>& vector);
158
162 void calculateBalancedACF (std::vector<double>& onsetDetectionFunction);
163
165 void calculateOutputOfCombFilterBank();
166
168 void createLogGaussianTransitionWeighting (double* weightingArray, int numSamples, double beatPeriod);
169
171 template <typename T>
172 double calculateNewCumulativeScoreValue (T cumulativeScoreArray, double* logGaussianTransitionWeighting, int startIndex, int endIndex, double onsetDetectionFunctionSample, double alphaWeightingFactor);
173
174 //=======================================================================
175
178
179 //=======================================================================
180 // buffers
181
182 CircularBuffer onsetDF;
183 CircularBuffer cumulativeScore;
185 std::vector<double> resampledOnsetDF;
186 std::vector<double> acf;
187 std::vector<double> weightingVector;
188 std::vector<double> combFilterBankOutput;
189 std::vector<double> tempoObservationVector;
190 std::vector<double> delta;
191 std::vector<double> prevDelta;
192 std::vector<double> prevDeltaFixed;
193 double tempoTransitionMatrix[41][41];
195 //=======================================================================
196 // parameters
197
198 double tightness;
199 double alpha;
200 double beatPeriod;
201 double estimatedTempo;
202 int timeToNextPrediction;
203 int timeToNextBeat;
204 int hopSize;
205 int onsetDFBufferSize;
206 bool tempoFixed;
207 bool beatDueInFrame;
208 int FFTLengthForACFCalculation;
210#ifdef USE_FFTW
211 fftw_plan acfForwardFFT;
212 fftw_plan acfBackwardFFT;
213 fftw_complex* complexIn;
214 fftw_complex* complexOut;
215#endif
216
217#ifdef USE_KISS_FFT
218 kiss_fft_cfg cfgForwards;
219 kiss_fft_cfg cfgBackwards;
220 kiss_fft_cpx* fftIn;
221 kiss_fft_cpx* fftOut;
222#endif
223
224};
225
226#endif
A circular buffer.
A class for calculating onset detection functions.
Definition BTrack.h:35
double getCurrentTempoEstimate()
Definition BTrack.cpp:192
void doNotFixTempo()
Definition BTrack.cpp:340
BTrack()
Definition BTrack.cpp:30
~BTrack()
Definition BTrack.cpp:51
void fixTempo(double tempo)
Definition BTrack.cpp:314
void processOnsetDetectionFunctionSample(double sample)
Definition BTrack.cpp:220
double getLatestCumulativeScoreValue()
Definition BTrack.cpp:204
void setTempo(double tempo)
Definition BTrack.cpp:256
static double getBeatTimeInSeconds(long frameNumber, int hopSize, int fs)
Definition BTrack.cpp:70
void processAudioFrame(double *frame)
Definition BTrack.cpp:210
int getHopSize()
Definition BTrack.cpp:198
bool beatDueInCurrentFrame()
Definition BTrack.cpp:186
void updateHopAndFrameSize(int hopSize, int frameSize)
Definition BTrack.cpp:176
Definition CircularBuffer.h:34
Definition OnsetDetectionFunction.h:65