BTrack - A Real-Time Beat Tracker
 All Classes Files Functions Enumerations Pages
BTrack.h
Go to the documentation of this file.
1 //=======================================================================
20 //=======================================================================
21 
22 #ifndef __BTRACK_H
23 #define __BTRACK_H
24 
25 #include "OnsetDetectionFunction.h"
26 #include <vector>
27 
28 //=======================================================================
34 class BTrack {
35 
36 public:
37 
38  //=======================================================================
40  BTrack();
41 
45  BTrack(int hopSize_);
46 
51  BTrack(int hopSize_,int frameSize_);
52 
53  //=======================================================================
58  void updateHopAndFrameSize(int hopSize_,int frameSize_);
59 
60  //=======================================================================
65  void processAudioFrame(double *frame);
66 
70  void processOnsetDetectionFunctionSample(double sample);
71 
72  //=======================================================================
74  int getHopSize();
75 
77  bool beatDueInCurrentFrame();
78 
80  double getCurrentTempoEstimate();
81 
84 
85  //=======================================================================
89  void setTempo(double tempo);
90 
95  void fixTempo(double tempo);
96 
98  void doNotFixTempo();
99 
100  //=======================================================================
108  static double getBeatTimeInSeconds(long frameNumber,int hopSize,int fs);
109 
117  static double getBeatTimeInSeconds(int frameNumber,int hopSize,int fs);
118 
119 
120 private:
121 
126  void initialise(int hopSize_,int frameSize_);
127 
131  void setHopSize(int hopSize_);
132 
134  void resampleOnsetDetectionFunction();
135 
139  void updateCumulativeScore(double odfSample);
140 
142  void predictBeat();
143 
145  void calculateTempo();
146 
152  void adaptiveThreshold(double *x,int N);
153 
160  double calculateMeanOfArray(double *array,int startIndex,int endIndex);
161 
166  void normaliseArray(double *array,int N);
167 
171  void calculateBalancedACF(double *onsetDetectionFunction);
172 
174  void calculateOutputOfCombFilterBank();
175 
176  //=======================================================================
177 
180 
181  //=======================================================================
182  // buffers
183 
184  std::vector<double> onsetDF;
185  std::vector<double> cumulativeScore;
187  double resampledOnsetDF[512];
189  double acf[512];
191  double weightingVector[128];
193  double combFilterBankOutput[128];
194  double tempoObservationVector[41];
196  double delta[41];
197  double prevDelta[41];
198  double prevDeltaFixed[41];
200  double tempoTransitionMatrix[41][41];
203  //=======================================================================
204  // parameters
205 
206 
207  double tightness;
209  double alpha;
211  double beatPeriod;
213  double tempo;
215  double estimatedTempo;
217  double latestCumulativeScoreValue;
219  double tempoToLagFactor;
221  int m0;
223  int beatCounter;
225  int hopSize;
227  int onsetDFBufferSize;
229  bool tempoFixed;
231  bool beatDueInFrame;
233 };
234 
235 #endif