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 
27 //=======================================================================
33 class BTrack {
34 
35 public:
36 
37  //=======================================================================
39  BTrack();
40 
44  BTrack(int hopSize_);
45 
50  BTrack(int hopSize_,int frameSize_);
51 
52  //=======================================================================
57  void processAudioFrame(double *frame);
58 
62  void processOnsetDetectionFunctionSample(double sample);
63 
64  //=======================================================================
66  int getHopSize();
67 
69  bool beatDueInCurrentFrame();
70 
72  double getCurrentTempoEstimate();
73 
76 
77  //=======================================================================
81  void setTempo(double tempo);
82 
87  void fixTempo(double tempo);
88 
90  void doNotFixTempo();
91 
92  //=======================================================================
100  static double getBeatTimeInSeconds(long frameNumber,int hopSize,int fs);
101 
109  static double getBeatTimeInSeconds(int frameNumber,int hopSize,int fs);
110 
111 
112 private:
113 
118  void initialise(int hopSize_,int frameSize_);
119 
123  void setHopSize(int hopSize_);
124 
126  void resampleOnsetDetectionFunction();
127 
131  void updateCumulativeScore(double odfSample);
132 
134  void predictBeat();
135 
137  void calculateTempo();
138 
144  void adaptiveThreshold(double *x,int N);
145 
152  double calculateMeanOfArray(double *array,int startIndex,int endIndex);
153 
158  void normaliseArray(double *array,int N);
159 
163  void calculateBalancedACF(double *onsetDetectionFunction);
164 
166  void calculateOutputOfCombFilterBank();
167 
168  //=======================================================================
169 
172 
173  //=======================================================================
174  // buffers
175  double *onsetDF;
176  double resampledOnsetDF[512];
177  double *cumulativeScore;
179  double acf[512];
181  double weightingVector[128];
183  double combFilterBankOutput[128];
184  double tempoObservationVector[41];
186  double delta[41];
187  double prevDelta[41];
188  double prevDeltaFixed[41];
190  double tempoTransitionMatrix[41][41];
193  //=======================================================================
194  // parameters
195 
196 
197  double tightness;
199  double alpha;
201  double beatPeriod;
203  double tempo;
205  double estimatedTempo;
207  double latestCumulativeScoreValue;
209  double tempoToLagFactor;
211  int m0;
213  int beatCounter;
215  int hopSize;
217  int onsetDFBufferSize;
219  bool tempoFixed;
221  bool beatDueInFrame;
223 };
224 
225 #endif