Mercurial > hg > btrack
comparison src/BTrack.h @ 17:a31841af2bbc develop
Before this commit, the OnsetDetectionFunction class used double precision, and the BTrack class used floats. I have now made BTrack use double precision also. This works fine and the only cost of doing this is that we have to perform one array copy into floating point format so that sample rate conversion (which has to be in floating point format) can take place.
author | Adam <adamstark.uk@gmail.com> |
---|---|
date | Wed, 22 Jan 2014 02:49:29 +0000 |
parents | 73c64ca0ed23 |
children | 450c53430540 |
comparison
equal
deleted
inserted
replaced
16:73c64ca0ed23 | 17:a31841af2bbc |
---|---|
34 | 34 |
35 /** Initialise with frame size and set all frame sizes accordingly */ | 35 /** Initialise with frame size and set all frame sizes accordingly */ |
36 void initialise(int fsize); | 36 void initialise(int fsize); |
37 | 37 |
38 /** Add new sample to buffer and apply beat tracking */ | 38 /** Add new sample to buffer and apply beat tracking */ |
39 void process(float df_sample); | 39 void process(double df_sample); |
40 | 40 |
41 /** Set the tempo of the beat tracker */ | 41 /** Set the tempo of the beat tracker */ |
42 void settempo(float tempo); | 42 void settempo(double tempo); |
43 | 43 |
44 /** fix tempo to roughly around some value */ | 44 /** fix tempo to roughly around some value */ |
45 void fixtempo(float tempo); | 45 void fixtempo(double tempo); |
46 | 46 |
47 /** do not fix the tempo anymore */ | 47 /** do not fix the tempo anymore */ |
48 void unfixtempo(); | 48 void unfixtempo(); |
49 | 49 |
50 int playbeat; | 50 int playbeat; |
51 float cscoreval; | 51 double cscoreval; |
52 float est_tempo; | 52 double est_tempo; |
53 | 53 |
54 private: | 54 private: |
55 | 55 |
56 /** Convert detection function from N samples to 512 */ | 56 /** Convert detection function from N samples to 512 */ |
57 void dfconvert(); | 57 void dfconvert(); |
58 | 58 |
59 /** update the cumulative score */ | 59 /** update the cumulative score */ |
60 void updatecumscore(float df_sample); | 60 void updatecumscore(double df_sample); |
61 | 61 |
62 /** predicts the next beat */ | 62 /** predicts the next beat */ |
63 void predictbeat(); | 63 void predictbeat(); |
64 | 64 |
65 /** Calculates the current tempo expressed as the beat period in detection function samples */ | 65 /** Calculates the current tempo expressed as the beat period in detection function samples */ |
66 void calcTempo(); | 66 void calcTempo(); |
67 | 67 |
68 /** calculates an adaptive threshold which is used to remove low level energy from detection | 68 /** calculates an adaptive threshold which is used to remove low level energy from detection |
69 * function and emphasise peaks | 69 * function and emphasise peaks |
70 */ | 70 */ |
71 void adapt_thresh(float *x,int N); | 71 void adapt_thresh(double *x,int N); |
72 | 72 |
73 /** calculates the mean of values in an array from index locations [start,end] */ | 73 /** calculates the mean of values in an array from index locations [start,end] */ |
74 float mean_array(float *array,int start,int end); | 74 double mean_array(double *array,int start,int end); |
75 | 75 |
76 /** normalises a given array */ | 76 /** normalises a given array */ |
77 void normalise(float *array,int N); | 77 void normalise(double *array,int N); |
78 | 78 |
79 /** calculates the balanced autocorrelation of the smoothed detection function */ | 79 /** calculates the balanced autocorrelation of the smoothed detection function */ |
80 void acf_bal(float *df_thresh); | 80 void acf_bal(double *df_thresh); |
81 | 81 |
82 /** returns the output of the comb filter */ | 82 /** returns the output of the comb filter */ |
83 void getrcfoutput(); | 83 void getrcfoutput(); |
84 | 84 |
85 // buffers | 85 // buffers |
86 float *dfbuffer; /**< to hold detection function */ | 86 double *dfbuffer; /**< to hold detection function */ |
87 float df512[512]; /**< to hold resampled detection function */ | 87 double df512[512]; /**< to hold resampled detection function */ |
88 float *cumscore; /**< to hold cumulative score */ | 88 double *cumscore; /**< to hold cumulative score */ |
89 | 89 |
90 float acf[512]; /**< to hold autocorrelation function */ | 90 double acf[512]; /**< to hold autocorrelation function */ |
91 | 91 |
92 float wv[128]; /**< to hold weighting vector */ | 92 double wv[128]; /**< to hold weighting vector */ |
93 | 93 |
94 float rcf[128]; /**< to hold comb filter output */ | 94 double rcf[128]; /**< to hold comb filter output */ |
95 float t_obs[41]; /**< to hold tempo version of comb filter output */ | 95 double t_obs[41]; /**< to hold tempo version of comb filter output */ |
96 | 96 |
97 float delta[41]; /**< to hold final tempo candidate array */ | 97 double delta[41]; /**< to hold final tempo candidate array */ |
98 float prev_delta[41]; /**< previous delta */ | 98 double prev_delta[41]; /**< previous delta */ |
99 float prev_delta_fix[41]; /**< fixed tempo version of previous delta */ | 99 double prev_delta_fix[41]; /**< fixed tempo version of previous delta */ |
100 | 100 |
101 float t_tmat[41][41]; /**< transition matrix */ | 101 double t_tmat[41][41]; /**< transition matrix */ |
102 | 102 |
103 | 103 |
104 // parameters | 104 // parameters |
105 float tightness; | 105 double tightness; |
106 float alpha; | 106 double alpha; |
107 float bperiod; | 107 double bperiod; |
108 float tempo; | 108 double tempo; |
109 | 109 |
110 | 110 |
111 float p_fact; | 111 double p_fact; |
112 | 112 |
113 | 113 |
114 // | 114 // |
115 int m0; // indicates when the next point to predict the next beat is | 115 int m0; // indicates when the next point to predict the next beat is |
116 int beat; | 116 int beat; |