# HG changeset patch # User Adam # Date 1390869077 0 # Node ID 7af87d3f2ce219f5779c5ab653a11f2f426d9b95 # Parent 98f7a54faa0c58d97efc0d297113ecf830f38b9d Added a function to allow updates to the hop and frame size of the beat tracker diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_b_track_8cpp.html --- a/doc/html/_b_track_8cpp.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_b_track_8cpp.html Tue Jan 28 00:31:17 2014 +0000 @@ -103,7 +103,7 @@ diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_b_track_8h.html --- a/doc/html/_b_track_8h.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_b_track_8h.html Tue Jan 28 00:31:17 2014 +0000 @@ -92,6 +92,7 @@

BTrack - a real-time beat tracker. More...

#include "OnsetDetectionFunction.h"
+#include <vector>

Go to the source code of this file.

@@ -110,7 +111,7 @@ diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_b_track_8h_source.html --- a/doc/html/_b_track_8h_source.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_b_track_8h_source.html Tue Jan 28 00:31:17 2014 +0000 @@ -93,111 +93,116 @@
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 
-
75  double getLatestCumulativeScoreValue();
-
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();
+
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 
+
83  double getLatestCumulativeScoreValue();
+
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 updateCumulativeScore(double odfSample);
+
131  void setHopSize(int hopSize_);
132 
-
134  void predictBeat();
+
134  void resampleOnsetDetectionFunction();
135 
-
137  void calculateTempo();
-
138 
-
144  void adaptiveThreshold(double *x,int N);
-
145 
-
152  double calculateMeanOfArray(double *array,int startIndex,int endIndex);
+
139  void updateCumulativeScore(double odfSample);
+
140 
+
142  void predictBeat();
+
143 
+
145  void calculateTempo();
+
146 
+
152  void adaptiveThreshold(double *x,int N);
153 
-
158  void normaliseArray(double *array,int N);
-
159 
-
163  void calculateBalancedACF(double *onsetDetectionFunction);
-
164 
-
166  void calculateOutputOfCombFilterBank();
+
160  double calculateMeanOfArray(double *array,int startIndex,int endIndex);
+
161 
+
166  void normaliseArray(double *array,int N);
167 
-
168  //=======================================================================
-
169 
-
171  OnsetDetectionFunction odf;
+
171  void calculateBalancedACF(double *onsetDetectionFunction);
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
+
174  void calculateOutputOfCombFilterBank();
+
175 
+
176  //=======================================================================
+
177 
+
179  OnsetDetectionFunction odf;
+
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
diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_onset_detection_function_8cpp.html --- a/doc/html/_onset_detection_function_8cpp.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_onset_detection_function_8cpp.html Tue Jan 28 00:31:17 2014 +0000 @@ -101,7 +101,7 @@ diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_onset_detection_function_8h.html --- a/doc/html/_onset_detection_function_8h.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_onset_detection_function_8h.html Tue Jan 28 00:31:17 2014 +0000 @@ -93,6 +93,7 @@

A class for calculating onset detection functions. More...

#include "fftw3.h"
+#include <vector>

Go to the source code of this file.

@@ -167,7 +168,7 @@ diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/_onset_detection_function_8h_source.html --- a/doc/html/_onset_detection_function_8h_source.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/_onset_detection_function_8h_source.html Tue Jan 28 00:31:17 2014 +0000 @@ -93,111 +93,112 @@
23 #define __ONSETDETECTIONFUNCTION_H
24 
25 #include "fftw3.h"
-
26 
-
27 //=======================================================================
-
29 enum OnsetDetectionFunctionType
-
30 {
-
31  EnergyEnvelope,
-
32  EnergyDifference,
-
33  SpectralDifference,
-
34  SpectralDifferenceHWR,
-
35  PhaseDeviation,
-
36  ComplexSpectralDifference,
-
37  ComplexSpectralDifferenceHWR,
-
38  HighFrequencyContent,
-
39  HighFrequencySpectralDifference,
-
40  HighFrequencySpectralDifferenceHWR
-
41 };
-
42 
-
43 //=======================================================================
-
45 enum WindowType
-
46 {
-
47  RectangularWindow,
-
48  HanningWindow,
-
49  HammingWindow,
-
50  BlackmanWindow,
-
51  TukeyWindow
-
52 };
-
53 
-
54 //=======================================================================
-
56 class OnsetDetectionFunction
-
57 {
-
58 public:
-
59 
-
66  OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
-
67 
-
69  ~OnsetDetectionFunction();
-
70 
-
77  void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
-
78 
-
83  double calculateOnsetDetectionFunctionSample(double *buffer);
-
84 
-
88  void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
-
89 
-
90 private:
-
91 
-
93  void performFFT();
-
94 
-
95  //=======================================================================
-
97  double energyEnvelope();
-
98 
-
100  double energyDifference();
-
101 
-
103  double spectralDifference();
-
104 
-
106  double spectralDifferenceHWR();
-
107 
-
109  double phaseDeviation();
-
110 
-
112  double complexSpectralDifference();
-
113 
-
115  double complexSpectralDifferenceHWR();
-
116 
-
118  double highFrequencyContent();
-
119 
-
121  double highFrequencySpectralDifference();
-
122 
-
124  double highFrequencySpectralDifferenceHWR();
-
125 
-
126  //=======================================================================
-
128  void calculateRectangularWindow();
-
129 
-
131  void calculateHanningWindow();
-
132 
-
134  void calclulateHammingWindow();
-
135 
-
137  void calculateBlackmanWindow();
-
138 
-
140  void calculateTukeyWindow();
-
141 
-
142  //=======================================================================
-
147  double princarg(double phaseVal);
-
148 
+
26 #include <vector>
+
27 
+
28 //=======================================================================
+
30 enum OnsetDetectionFunctionType
+
31 {
+
32  EnergyEnvelope,
+
33  EnergyDifference,
+
34  SpectralDifference,
+
35  SpectralDifferenceHWR,
+
36  PhaseDeviation,
+
37  ComplexSpectralDifference,
+
38  ComplexSpectralDifferenceHWR,
+
39  HighFrequencyContent,
+
40  HighFrequencySpectralDifference,
+
41  HighFrequencySpectralDifferenceHWR
+
42 };
+
43 
+
44 //=======================================================================
+
46 enum WindowType
+
47 {
+
48  RectangularWindow,
+
49  HanningWindow,
+
50  HammingWindow,
+
51  BlackmanWindow,
+
52  TukeyWindow
+
53 };
+
54 
+
55 //=======================================================================
+
57 class OnsetDetectionFunction
+
58 {
+
59 public:
+
60 
+
67  OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
+
68 
+
70  ~OnsetDetectionFunction();
+
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  double pi;
-
152  int frameSize;
-
153  int hopSize;
-
154  int onsetDetectionFunctionType;
-
156  fftw_plan p;
-
157  fftw_complex *complexIn;
-
158  fftw_complex *complexOut;
-
160  int initialised;
-
162  double *frame;
-
163  double *window;
-
165  double prevEnergySum;
-
167  double *magSpec;
-
168  double *prevMagSpec;
-
170  double *phase;
-
171  double *prevPhase;
-
172  double *prevPhase2;
-
174 };
-
175 
+
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 #endif
+
177 
+
178 #endif
diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/annotated.html --- a/doc/html/annotated.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/annotated.html Tue Jan 28 00:31:17 2014 +0000 @@ -92,7 +92,7 @@ diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/class_b_track-members.html --- a/doc/html/class_b_track-members.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/class_b_track-members.html Tue Jan 28 00:31:17 2014 +0000 @@ -100,10 +100,11 @@ +
processAudioFrame(double *frame)BTrack
processOnsetDetectionFunctionSample(double sample)BTrack
setTempo(double tempo)BTrack
updateHopAndFrameSize(int hopSize_, int frameSize_)BTrack
diff -r 98f7a54faa0c -r 7af87d3f2ce2 doc/html/class_b_track.html --- a/doc/html/class_b_track.html Tue Jan 28 00:19:21 2014 +0000 +++ b/doc/html/class_b_track.html Tue Jan 28 00:31:17 2014 +0000 @@ -98,6 +98,8 @@    BTrack (int hopSize_, int frameSize_)   +void updateHopAndFrameSize (int hopSize_, int frameSize_) +  void processAudioFrame (double *frame)   void processOnsetDetectionFunctionSample (double sample) @@ -139,7 +141,7 @@
-

constructor assuming hop size of 512 and frame size of 1024

+

Constructor assuming hop size of 512 and frame size of 1024

@@ -156,7 +158,7 @@
-

constructor assuming frame size will be double the hopSize

+

Constructor assuming frame size will be double the hopSize

Parameters
@@ -189,7 +191,7 @@
hopSizethe hop size in audio samples
-

constructor taking both hopSize and frameSize

+

Constructor taking both hopSize and frameSize

Parameters
@@ -229,7 +231,7 @@
hopSizethe hop size in audio samples
-

tell the algorithm to not fix the tempo anymore

+

Tell the algorithm to not fix the tempo anymore

@@ -246,7 +248,7 @@
-

fix tempo to roughly around some value, so that the algorithm will only try to track tempi around the given tempo

+

Fix tempo to roughly around some value, so that the algorithm will only try to track tempi around the given tempo

Parameters
@@ -293,7 +295,7 @@
tempothe tempo in beats per minute (bpm)
-

calculates a beat time in seconds, given the frame number, hop size and sampling frequency. This version uses a long to represent the frame number

+

Calculates a beat time in seconds, given the frame number, hop size and sampling frequency. This version uses a long to represent the frame number

Parameters
@@ -343,7 +345,7 @@
frameNumberthe index of the current frame
-

calculates a beat time in seconds, given the frame number, hop size and sampling frequency. This version uses an int to represent the frame number

+

Calculates a beat time in seconds, given the frame number, hop size and sampling frequency. This version uses an int to represent the frame number

Parameters
@@ -473,6 +475,40 @@ + +
+
+
frameNumberthe index of the current frame
+ + + + + + + + + + + + + + + + + +
void BTrack::updateHopAndFrameSize (int hopSize_,
int frameSize_ 
)
+
+

Updates the hop and frame size used by the beat tracker

+
Parameters
+ + + +
hopSizethe hop size in audio samples
frameSizethe frame size in audio samples
+
+
+ +
+
The documentation for this class was generated from the following files: