annotate src/BTrack.h @ 51:68d01fea1e8d

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