Changeset 6f1727f
 Timestamp:
 Sep 13, 2009, 11:54:23 PM (11 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 7bf3dcb
 Parents:
 3b2d32c
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/tempo/beattracking.c
r3b2d32c r6f1727f 23 23 #include "tempo/beattracking.h" 24 24 25 uint_t fvec_gettimesig( smpl_t * acf, uint_t acflen, uint_t gp);25 uint_t fvec_gettimesig(fvec_t * acf, uint_t acflen, uint_t gp); 26 26 void aubio_beattracking_checkstate(aubio_beattracking_t * bt); 27 27 28 28 struct _aubio_beattracking_t { 29 fvec_t * rwv; /** rayleigh weight vector  rayleigh distribution function */ 30 fvec_t * gwv; /** rayleigh weight vector  rayleigh distribution function */ 31 fvec_t * dfwv; /** detection function weighting  exponential curve */ 29 fvec_t * rwv; /** rayleigh weighting for beat period in general model */ 30 fvec_t * dfwv; /** exponential weighting for beat alignment in general model */ 31 fvec_t * gwv; /** gaussian weighting for beat period in context dependant model */ 32 fvec_t * phwv; /** gaussian weighting for beat alignment in context dependant model */ 32 33 fvec_t * dfrev; /** reversed onset detection function */ 33 34 fvec_t * acf; /** vector for autocorrelation function (of current detection function frame) */ 34 35 fvec_t * acfout; /** store result of passing acf through s.i.c.f.b. */ 35 fvec_t * phwv; /** beat expectation alignment weighting */36 36 fvec_t * phout; 37 37 uint_t timesig; /** time signature of input, set to zero until context dependent model activated */ … … 73 73 p>rayparam = rayparam; 74 74 p>step = step; 75 p>rwv = new_fvec(laglen, channels);76 p>gwv = new_fvec(laglen, channels);77 p>dfwv = new_fvec(winlen, channels);75 p>rwv = new_fvec(laglen,1); 76 p>gwv = new_fvec(laglen,1); 77 p>dfwv = new_fvec(winlen,1); 78 78 p>dfrev = new_fvec(winlen,channels); 79 79 p>acf = new_fvec(winlen,channels); 80 80 p>acfout = new_fvec(laglen,channels); 81 p>phwv = new_fvec(2*laglen, channels);81 p>phwv = new_fvec(2*laglen,1); 82 82 p>phout = new_fvec(winlen,channels); 83 83 … … 118 118 uint_t laglen = bt>rwv>length; 119 119 uint_t winlen = bt>dfwv>length; 120 smpl_t * phout = bt>phout>data[0];121 smpl_t * phwv = bt>phwv>data[0];122 smpl_t * dfrev = bt>dfrev>data[0];123 smpl_t * dfwv = bt>dfwv>data[0];124 smpl_t * rwv = bt>rwv>data[0];125 smpl_t * acfout = bt>acfout>data[0];126 smpl_t * acf = bt>acf>data[0];127 120 uint_t maxindex = 0; 128 121 //number of harmonics in shift invariant comb filterbank … … 135 128 uint_t kmax; // number of elements used to find beat phase 136 129 137 for (i = 0; i < winlen; i++){138 dfrev[winlen1i] = 0.;139 dfrev[winlen1i] = dfframe>data[0][i]*dfwv[i];140 }141 142 /* findautocorrelation function */130 /* copy dfframe, apply detection function weighting, and revert */ 131 fvec_copy(dfframe, bt>dfrev); 132 fvec_weight(bt>dfrev, bt>dfwv); 133 fvec_rev(bt>dfrev); 134 135 /* compute autocorrelation function */ 143 136 aubio_autocorr(dfframe,bt>acf); 144 137 … … 151 144 152 145 /* first and last output values are left intentionally as zero */ 153 for (i=0; i < bt>acfout>length; i++) 154 acfout[i] = 0.; 155 156 /* get acfout  assume Rayleigh weightvector only */ 146 fvec_zeros(bt>acfout); 147 148 /* compute shift invariant comb filterbank */ 157 149 for(i=1;i<laglen1;i++){ 158 150 for (a=1; a<=numelem; a++){ 159 151 for(b=(1a); b<a; b++){ 160 acfout[i] += acf[a*(i+1)+b1]161 * 1./(2.*a1.) *rwv[i];152 bt>acfout>data[0][i] += bt>acf>data[0][a*(i+1)+b1] 153 * 1./(2.*a1.); 162 154 } 163 155 } 164 156 } 157 /* apply Rayleigh weight */ 158 fvec_weight(bt>acfout, bt>rwv); 165 159 166 160 /* find nonzero Rayleigh period */ … … 178 172 /* end of biased filterbank */ 179 173 180 /* initialize output */181 for(i=0;i<bt>phout>length;i++) {phout[i] = 0.;}182 174 183 175 /* deliberate integer operation, could be set to 3 max eventually */ 184 176 kmax = FLOOR(winlen/bp); 185 177 178 /* initialize output */ 179 fvec_zeros(bt>phout); 186 180 for(i=0;i<bp;i++){ 187 phout[i] = 0.;188 181 for(k=0;k<kmax;k++){ 189 phout[i] += dfrev[i+(uint_t)ROUND(bp*k)] * phwv[i]; 190 } 191 } 182 bt>phout>data[0][i] += bt>dfrev>data[0][i+(uint_t)ROUND(bp*k)]; 183 } 184 } 185 fvec_weight(bt>phout, bt>phwv); 192 186 193 187 /* find Rayleigh period */ … … 200 194 201 195 /* reset output */ 202 for (i = 0; i < laglen; i++) 203 output>data[0][i] = 0.; 196 fvec_zeros(output); 204 197 205 198 i = 1; 206 199 beat = bp  phase; 207 200 /* start counting the beats */ 208 if(beat >= 0) 209 { 201 if(beat >= 0) { 210 202 output>data[0][i] = beat; 211 203 i++; 212 204 } 213 205 214 while( beat + bp <= step) 215 { 206 while( beat + bp <= step) { 216 207 beat += bp; 217 208 output>data[0][i] = beat; … … 224 215 } 225 216 226 uint_t fvec_gettimesig( smpl_t * acf, uint_t acflen, uint_t gp){217 uint_t fvec_gettimesig(fvec_t * acf, uint_t acflen, uint_t gp){ 227 218 sint_t k = 0; 228 219 smpl_t three_energy = 0., four_energy = 0.; 229 220 if( acflen > 6 * gp + 2 ){ 230 221 for(k=2;k<2;k++){ 231 three_energy += acf [3*gp+k];232 four_energy += acf [4*gp+k];222 three_energy += acf>data[0][3*gp+k]; 223 four_energy += acf>data[0][4*gp+k]; 233 224 } 234 225 } 235 226 else{ /*Expanded to be more accurate in time sig estimation*/ 236 227 for(k=2;k<2;k++){ 237 three_energy += acf [3*gp+k]+acf[6*gp+k];238 four_energy += acf [4*gp+k]+acf[2*gp+k];228 three_energy += acf>data[0][3*gp+k]+acf>data[0][6*gp+k]; 229 four_energy += acf>data[0][4*gp+k]+acf>data[0][2*gp+k]; 239 230 } 240 231 } … … 255 246 uint_t acflen = bt>acf>length; 256 247 uint_t step = bt>step; 257 smpl_t * acf = bt>acf>data[0]; 258 smpl_t * acfout = bt>acfout>data[0]; 259 smpl_t * gwv = bt>gwv>data[0]; 260 smpl_t * phwv = bt>phwv>data[0]; 248 fvec_t * acf = bt>acf; 249 fvec_t * acfout = bt>acfout; 261 250 262 251 if (gp) { … … 266 255 // gwv is, in first loop, definitely all zeros, but will have 267 256 // proper values when context dependent model is activated 268 for (i=0; i < bt>acfout>length; i++) 269 acfout[i] = 0.; 257 fvec_zeros(acfout); 270 258 for(i=1;i<laglen1;i++){ 271 259 for (a=1;a<=bt>timesig;a++){ 272 260 for(b=(1a);b<a;b++){ 273 acfout[i] += acf[a*(i+1)+b1] 274 * 1. * gwv[i]; 261 acfout>data[0][i] += acf>data[0][a*(i+1)+b1]; 275 262 } 276 263 } 277 264 } 278 gp = vec_quadint(bt>acfout, vec_max_elem(bt>acfout), 1); 265 fvec_weight(acfout, bt>gwv); 266 gp = vec_quadint(acfout, vec_max_elem(acfout), 1); 279 267 /* 280 268 while(gp<32) gp =gp*2; … … 321 309 bt>timesig = fvec_gettimesig(acf,acflen, gp); 322 310 for(j=0;j<laglen;j++) 323 gwv[j] = EXP(.5*SQR((smpl_t)(j+1.gp))/SQR(bt>g_var));311 bt>gwv>data[0][j] = EXP(.5*SQR((smpl_t)(j+1.gp))/SQR(bt>g_var)); 324 312 flagconst = 0; 325 313 bp = gp; 326 314 /* flat phase weighting */ 327 f or(j=0;j<2*laglen;j++) {phwv[j] = 1.;}315 fvec_ones(bt>phwv); 328 316 } else if (bt>timesig) { 329 317 /* context dependant model */ … … 332 320 if (step > bt>lastbeat) { 333 321 for(j=0;j<2*laglen;j++) { 334 phwv[j] = EXP(.5*SQR((smpl_t)(1.+jstep+bt>lastbeat))/(bp/8.));322 bt>phwv>data[0][j] = EXP(.5*SQR((smpl_t)(1.+jstep+bt>lastbeat))/(bp/8.)); 335 323 } 336 324 } else { 337 325 //AUBIO_DBG("NOT using phase weighting as step is %d and lastbeat %d \n", 338 326 // step,bt>lastbeat); 339 f or(j=0;j<2*laglen;j++) {phwv[j] = 1.;}327 fvec_ones(bt>phwv); 340 328 } 341 329 } else { … … 343 331 bp = rp; 344 332 /* flat phase weighting */ 345 f or(j=0;j<2*laglen;j++) {phwv[j] = 1.;}333 fvec_ones(bt>phwv); 346 334 } 347 335
Note: See TracChangeset
for help on using the changeset viewer.