comparison src/BTrack.h @ 24:deb49a2590f3 develop

Updated README, commented more code, added a Vamp plug-in
author Adam <adamstark.uk@gmail.com>
date Mon, 27 Jan 2014 23:11:31 +0000
parents 92ee4ace9d46
children e4d5f045064d
comparison
equal deleted inserted replaced
23:92ee4ace9d46 24:deb49a2590f3
33 class BTrack { 33 class BTrack {
34 34
35 public: 35 public:
36 36
37 //======================================================================= 37 //=======================================================================
38 /** constructor assuming hop size of 512 and frame size of 1024 */ 38 /** Constructor assuming hop size of 512 and frame size of 1024 */
39 BTrack(); 39 BTrack();
40 40
41 /** constructor assuming frame size will be double the hopSize 41 /** Constructor assuming frame size will be double the hopSize
42 * @param hopSize the hop size in audio samples 42 * @param hopSize the hop size in audio samples
43 */ 43 */
44 BTrack(int hopSize_); 44 BTrack(int hopSize_);
45 45
46 /** constructor taking both hopSize and frameSize 46 /** Constructor taking both hopSize and frameSize
47 * @param hopSize the hop size in audio samples 47 * @param hopSize the hop size in audio samples
48 * @param frameSize the frame size in audio samples 48 * @param frameSize the frame size in audio samples
49 */ 49 */
50 BTrack(int hopSize_,int frameSize_); 50 BTrack(int hopSize_,int frameSize_);
51 51
78 /** Set the tempo of the beat tracker 78 /** Set the tempo of the beat tracker
79 * @param tempo the tempo in beats per minute (bpm) 79 * @param tempo the tempo in beats per minute (bpm)
80 */ 80 */
81 void setTempo(double tempo); 81 void setTempo(double tempo);
82 82
83 /** fix tempo to roughly around some value, so that the algorithm will only try to track 83 /** Fix tempo to roughly around some value, so that the algorithm will only try to track
84 * tempi around the given tempo 84 * tempi around the given tempo
85 * @param tempo the tempo in beats per minute (bpm) 85 * @param tempo the tempo in beats per minute (bpm)
86 */ 86 */
87 void fixTempo(double tempo); 87 void fixTempo(double tempo);
88 88
89 /** tell the algorithm to not fix the tempo anymore */ 89 /** Tell the algorithm to not fix the tempo anymore */
90 void doNotFixTempo(); 90 void doNotFixTempo();
91 91
92 //======================================================================= 92 //=======================================================================
93 /** calculates a beat time in seconds, given the frame number, hop size and sampling frequency. 93 /** Calculates a beat time in seconds, given the frame number, hop size and sampling frequency.
94 * This version uses a long to represent the frame number 94 * This version uses a long to represent the frame number
95 * @param frameNumber the index of the current frame 95 * @param frameNumber the index of the current frame
96 * @param hopSize the hop size in audio samples 96 * @param hopSize the hop size in audio samples
97 * @param fs the sampling frequency in Hz 97 * @param fs the sampling frequency in Hz
98 * @returns a beat time in seconds 98 * @returns a beat time in seconds
99 */ 99 */
100 static double getBeatTimeInSeconds(long frameNumber,int hopSize,int fs); 100 static double getBeatTimeInSeconds(long frameNumber,int hopSize,int fs);
101 101
102 /** calculates a beat time in seconds, given the frame number, hop size and sampling frequency. 102 /** Calculates a beat time in seconds, given the frame number, hop size and sampling frequency.
103 * This version uses an int to represent the frame number 103 * This version uses an int to represent the frame number
104 * @param frameNumber the index of the current frame 104 * @param frameNumber the index of the current frame
105 * @param hopSize the hop size in audio samples 105 * @param hopSize the hop size in audio samples
106 * @param fs the sampling frequency in Hz 106 * @param fs the sampling frequency in Hz
107 * @returns a beat time in seconds 107 * @returns a beat time in seconds
128 /** Updates the cumulative score function with a new onset detection function sample 128 /** Updates the cumulative score function with a new onset detection function sample
129 * @param odfSample an onset detection function sample 129 * @param odfSample an onset detection function sample
130 */ 130 */
131 void updateCumulativeScore(double odfSample); 131 void updateCumulativeScore(double odfSample);
132 132
133 /** predicts the next beat, based upon the internal program state */ 133 /** Predicts the next beat, based upon the internal program state */
134 void predictBeat(); 134 void predictBeat();
135 135
136 /** Calculates the current tempo expressed as the beat period in detection function samples */ 136 /** Calculates the current tempo expressed as the beat period in detection function samples */
137 void calculateTempo(); 137 void calculateTempo();
138 138
139 /** calculates an adaptive threshold which is used to remove low level energy from detection 139 /** Calculates an adaptive threshold which is used to remove low level energy from detection
140 * function and emphasise peaks 140 * function and emphasise peaks
141 * @param x a pointer to an array containing onset detection function samples 141 * @param x a pointer to an array containing onset detection function samples
142 * @param N the length of the array, x 142 * @param N the length of the array, x
143 */ 143 */
144 void adaptiveThreshold(double *x,int N); 144 void adaptiveThreshold(double *x,int N);
145 145
146 /** calculates the mean of values in an array between index locations [startIndex,endIndex] 146 /** Calculates the mean of values in an array between index locations [startIndex,endIndex]
147 * @param array a pointer to an array that contains the values we wish to find the mean from 147 * @param array a pointer to an array that contains the values we wish to find the mean from
148 * @param startIndex the start index from which we would like to calculate the mean 148 * @param startIndex the start index from which we would like to calculate the mean
149 * @param endIndex the final index to which we would like to calculate the mean 149 * @param endIndex the final index to which we would like to calculate the mean
150 * @returns the mean of the sub-section of the array 150 * @returns the mean of the sub-section of the array
151 */ 151 */
152 double calculateMeanOfArray(double *array,int startIndex,int endIndex); 152 double calculateMeanOfArray(double *array,int startIndex,int endIndex);
153 153
154 /** normalises a given array 154 /** Normalises a given array
155 * @param array a pointer to the array we wish to normalise 155 * @param array a pointer to the array we wish to normalise
156 * @param N the length of the array 156 * @param N the length of the array
157 */ 157 */
158 void normaliseArray(double *array,int N); 158 void normaliseArray(double *array,int N);
159 159
160 /** calculates the balanced autocorrelation of the smoothed onset detection function 160 /** Calculates the balanced autocorrelation of the smoothed onset detection function
161 * @param onsetDetectionFunction a pointer to an array containing the onset detection function 161 * @param onsetDetectionFunction a pointer to an array containing the onset detection function
162 */ 162 */
163 void calculateBalancedACF(double *onsetDetectionFunction); 163 void calculateBalancedACF(double *onsetDetectionFunction);
164 164
165 /** calculates the output of the comb filter bank */ 165 /** Calculates the output of the comb filter bank */
166 void calculateOutputOfCombFilterBank(); 166 void calculateOutputOfCombFilterBank();
167 167
168 //======================================================================= 168 //=======================================================================
169 169
170 /** an OnsetDetectionFunction instance for calculating onset detection functions */ 170 /** An OnsetDetectionFunction instance for calculating onset detection functions */
171 OnsetDetectionFunction odf; 171 OnsetDetectionFunction odf;
172 172
173 //======================================================================= 173 //=======================================================================
174 // buffers 174 // buffers
175 double *onsetDF; /**< to hold onset detection function */ 175 double *onsetDF; /**< to hold onset detection function */