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@5
|
25 class BTrack {
|
adamstark@5
|
26
|
adamstark@5
|
27 public:
|
adamstark@14
|
28
|
adamstark@14
|
29 /** constructor */
|
adamstark@14
|
30 BTrack();
|
adamstark@14
|
31
|
adamstark@14
|
32 /** destructor */
|
adamstark@14
|
33 ~BTrack();
|
adamstark@5
|
34
|
adamstark@14
|
35 /** Initialise with frame size and set all frame sizes accordingly */
|
adamstark@5
|
36 void initialise(int fsize);
|
adamstark@14
|
37
|
adamstark@14
|
38 /** Add new sample to buffer and apply beat tracking */
|
adamstark@17
|
39 void process(double df_sample);
|
adamstark@14
|
40
|
adamstark@14
|
41 /** Set the tempo of the beat tracker */
|
adamstark@17
|
42 void settempo(double tempo);
|
adamstark@14
|
43
|
adamstark@14
|
44 /** fix tempo to roughly around some value */
|
adamstark@17
|
45 void fixtempo(double tempo);
|
adamstark@14
|
46
|
adamstark@14
|
47 /** do not fix the tempo anymore */
|
adamstark@5
|
48 void unfixtempo();
|
adamstark@5
|
49
|
adamstark@5
|
50 int playbeat;
|
adamstark@17
|
51 double cscoreval;
|
adamstark@17
|
52 double est_tempo;
|
adamstark@5
|
53
|
adamstark@5
|
54 private:
|
adamstark@14
|
55
|
adamstark@14
|
56 /** Convert detection function from N samples to 512 */
|
adamstark@14
|
57 void dfconvert();
|
adamstark@14
|
58
|
adamstark@14
|
59 /** update the cumulative score */
|
adamstark@17
|
60 void updatecumscore(double df_sample);
|
adamstark@14
|
61
|
adamstark@14
|
62 /** predicts the next beat */
|
adamstark@14
|
63 void predictbeat();
|
adamstark@14
|
64
|
adamstark@14
|
65 /** Calculates the current tempo expressed as the beat period in detection function samples */
|
adamstark@14
|
66 void calcTempo();
|
adamstark@14
|
67
|
adamstark@14
|
68 /** calculates an adaptive threshold which is used to remove low level energy from detection
|
adamstark@14
|
69 * function and emphasise peaks
|
adamstark@14
|
70 */
|
adamstark@17
|
71 void adapt_thresh(double *x,int N);
|
adamstark@14
|
72
|
adamstark@14
|
73 /** calculates the mean of values in an array from index locations [start,end] */
|
adamstark@17
|
74 double mean_array(double *array,int start,int end);
|
adamstark@14
|
75
|
adamstark@14
|
76 /** normalises a given array */
|
adamstark@17
|
77 void normalise(double *array,int N);
|
adamstark@14
|
78
|
adamstark@14
|
79 /** calculates the balanced autocorrelation of the smoothed detection function */
|
adamstark@17
|
80 void acf_bal(double *df_thresh);
|
adamstark@14
|
81
|
adamstark@14
|
82 /** returns the output of the comb filter */
|
adamstark@14
|
83 void getrcfoutput();
|
adamstark@5
|
84
|
adamstark@5
|
85 // buffers
|
adamstark@17
|
86 double *dfbuffer; /**< to hold detection function */
|
adamstark@17
|
87 double df512[512]; /**< to hold resampled detection function */
|
adamstark@17
|
88 double *cumscore; /**< to hold cumulative score */
|
adamstark@5
|
89
|
adamstark@17
|
90 double acf[512]; /**< to hold autocorrelation function */
|
adamstark@5
|
91
|
adamstark@17
|
92 double wv[128]; /**< to hold weighting vector */
|
adamstark@5
|
93
|
adamstark@17
|
94 double rcf[128]; /**< to hold comb filter output */
|
adamstark@17
|
95 double t_obs[41]; /**< to hold tempo version of comb filter output */
|
adamstark@5
|
96
|
adamstark@17
|
97 double delta[41]; /**< to hold final tempo candidate array */
|
adamstark@17
|
98 double prev_delta[41]; /**< previous delta */
|
adamstark@17
|
99 double prev_delta_fix[41]; /**< fixed tempo version of previous delta */
|
adamstark@5
|
100
|
adamstark@17
|
101 double t_tmat[41][41]; /**< transition matrix */
|
adamstark@5
|
102
|
adamstark@5
|
103
|
adamstark@5
|
104 // parameters
|
adamstark@17
|
105 double tightness;
|
adamstark@17
|
106 double alpha;
|
adamstark@17
|
107 double bperiod;
|
adamstark@17
|
108 double tempo;
|
adamstark@5
|
109
|
adamstark@5
|
110
|
adamstark@17
|
111 double p_fact;
|
adamstark@5
|
112
|
adamstark@5
|
113
|
adamstark@5
|
114 //
|
adamstark@5
|
115 int m0; // indicates when the next point to predict the next beat is
|
adamstark@5
|
116 int beat;
|
adamstark@5
|
117
|
adamstark@5
|
118 int dfbuffer_size;
|
adamstark@5
|
119
|
adamstark@5
|
120
|
adamstark@5
|
121 int framesize;
|
adamstark@5
|
122
|
adamstark@5
|
123
|
adamstark@5
|
124 int tempofix;
|
adamstark@5
|
125
|
adamstark@5
|
126
|
adamstark@5
|
127 };
|
adamstark@5
|
128
|
adamstark@5
|
129 #endif
|