annotate src/BTrack.h @ 19:88c8d3862eee develop

Added some simple unit tests. Removed the destructor from the BTrack class as it was unnecessary.
author Adam <adamstark.uk@gmail.com>
date Thu, 23 Jan 2014 12:17:06 +0000
parents 450c53430540
children baf35f208814
rev   line source
adamstark@5 1 //=======================================================================
adamstark@5 2 /** @file BTrack.h
adamstark@6 3 * @brief BTrack - a real-time beat tracker
adamstark@5 4 * @author Adam Stark
adamstark@5 5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London
adamstark@5 6 *
adamstark@5 7 * This program is free software: you can redistribute it and/or modify
adamstark@5 8 * it under the terms of the GNU General Public License as published by
adamstark@5 9 * the Free Software Foundation, either version 3 of the License, or
adamstark@5 10 * (at your option) any later version.
adamstark@5 11 *
adamstark@5 12 * This program is distributed in the hope that it will be useful,
adamstark@5 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
adamstark@5 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adamstark@5 15 * GNU General Public License for more details.
adamstark@5 16 *
adamstark@5 17 * You should have received a copy of the GNU General Public License
adamstark@5 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
adamstark@5 19 */
adamstark@5 20 //=======================================================================
adamstark@5 21
adamstark@5 22 #ifndef __BTRACK_H
adamstark@5 23 #define __BTRACK_H
adamstark@5 24
adamstark@18 25 #include "OnsetDetectionFunction.h"
adamstark@18 26
adamstark@5 27 class BTrack {
adamstark@5 28
adamstark@5 29 public:
adamstark@14 30
adamstark@18 31 /** constructor assuming hop size of 512 and frame size of 1024 */
adamstark@19 32 BTrack();
adamstark@14 33
adamstark@18 34 /** constructor assuming frame size will be double hopSize
adamstark@18 35 * @param hopSize the step size in audio samples by which we will receive audio frames
adamstark@18 36 */
adamstark@18 37 BTrack(int hopSize);
adamstark@18 38
adamstark@18 39 /** constructor taking both hopSize and frameSize
adamstark@18 40 * @param hopSize the step size in audio samples by which we will receive audio frames
adamstark@18 41 * @param frameSize the audio frame size in audio samples
adamstark@18 42 */
adamstark@19 43 BTrack(int hopSize,int frameSize);
adamstark@18 44
adamstark@18 45 /** Process a single audio frame */
adamstark@19 46 void processAudioFrame(double *frame);
adamstark@18 47
adamstark@18 48 /** Add new onset detection function sample to buffer and apply beat tracking */
adamstark@19 49 void processOnsetDetectionFunctionSample(double sample);
adamstark@14 50
adamstark@14 51 /** Set the tempo of the beat tracker */
adamstark@19 52 void settempo(double tempo);
adamstark@14 53
adamstark@14 54 /** fix tempo to roughly around some value */
adamstark@19 55 void fixtempo(double tempo);
adamstark@14 56
adamstark@14 57 /** do not fix the tempo anymore */
adamstark@19 58 void unfixtempo();
adamstark@18 59
adamstark@18 60 static double getBeatTimeInSeconds(long frameNumber,int hopSize,int fs);
adamstark@18 61
adamstark@18 62 static double getBeatTimeInSeconds(int frameNumber,int hopSize,int fs);
adamstark@18 63
adamstark@19 64 int playbeat;
adamstark@19 65 double cscoreval;
adamstark@19 66 double est_tempo;
adamstark@5 67
adamstark@5 68 private:
adamstark@14 69
adamstark@19 70 void initialise(int hopSize,int frameSize);
adamstark@19 71
adamstark@19 72 /** Initialise with hop size and set all frame sizes accordingly */
adamstark@19 73 void setHopSize(int hopSize);
adamstark@19 74
adamstark@14 75 /** Convert detection function from N samples to 512 */
adamstark@19 76 void dfconvert();
adamstark@14 77
adamstark@14 78 /** update the cumulative score */
adamstark@19 79 void updatecumscore(double df_sample);
adamstark@14 80
adamstark@14 81 /** predicts the next beat */
adamstark@14 82 void predictbeat();
adamstark@14 83
adamstark@14 84 /** Calculates the current tempo expressed as the beat period in detection function samples */
adamstark@14 85 void calcTempo();
adamstark@14 86
adamstark@14 87 /** calculates an adaptive threshold which is used to remove low level energy from detection
adamstark@14 88 * function and emphasise peaks
adamstark@14 89 */
adamstark@19 90 void adapt_thresh(double *x,int N);
adamstark@14 91
adamstark@14 92 /** calculates the mean of values in an array from index locations [start,end] */
adamstark@19 93 double mean_array(double *array,int start,int end);
adamstark@14 94
adamstark@14 95 /** normalises a given array */
adamstark@19 96 void normalise(double *array,int N);
adamstark@14 97
adamstark@14 98 /** calculates the balanced autocorrelation of the smoothed detection function */
adamstark@19 99 void acf_bal(double *df_thresh);
adamstark@14 100
adamstark@14 101 /** returns the output of the comb filter */
adamstark@19 102 void getrcfoutput();
adamstark@5 103
adamstark@5 104 // buffers
adamstark@19 105 double *dfbuffer; /**< to hold detection function */
adamstark@19 106 double df512[512]; /**< to hold resampled detection function */
adamstark@19 107 double *cumscore; /**< to hold cumulative score */
adamstark@5 108
adamstark@19 109 double acf[512]; /**< to hold autocorrelation function */
adamstark@5 110
adamstark@19 111 double wv[128]; /**< to hold weighting vector */
adamstark@5 112
adamstark@19 113 double rcf[128]; /**< to hold comb filter output */
adamstark@19 114 double t_obs[41]; /**< to hold tempo version of comb filter output */
adamstark@5 115
adamstark@19 116 double delta[41]; /**< to hold final tempo candidate array */
adamstark@19 117 double prev_delta[41]; /**< previous delta */
adamstark@19 118 double prev_delta_fix[41]; /**< fixed tempo version of previous delta */
adamstark@5 119
adamstark@19 120 double t_tmat[41][41]; /**< transition matrix */
adamstark@5 121
adamstark@18 122 OnsetDetectionFunction odf;
adamstark@5 123
adamstark@19 124 // parameters
adamstark@19 125 double tightness;
adamstark@19 126 double alpha;
adamstark@19 127 double bperiod;
adamstark@19 128 double tempo;
adamstark@5 129
adamstark@5 130
adamstark@19 131 double p_fact;
adamstark@5 132
adamstark@5 133
adamstark@19 134 //
adamstark@19 135 int m0; // indicates when the next point to predict the next beat is
adamstark@19 136 int beat;
adamstark@5 137
adamstark@19 138 int dfbuffer_size;
adamstark@5 139
adamstark@5 140
adamstark@19 141 int framesize;
adamstark@5 142
adamstark@5 143
adamstark@19 144 int tempofix;
adamstark@5 145
adamstark@5 146
adamstark@5 147 };
adamstark@5 148
adamstark@5 149 #endif