Changeset e21208e
 Timestamp:
 Jul 21, 2006, 3:54:48 PM (15 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 b91fe6e
 Parents:
 f3f28b1
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/beattracking.c
rf3f28b1 re21208e 23 23 #include "beattracking.h" 24 24 25 // 60*samplerate/winlen26 27 /* maximum length for rp */28 static smpl_t constthresh = 3.901; //empirically derived!29 30 25 uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp); 31 26 void aubio_beattracking_checkstate(aubio_beattracking_t * bt); 32 smpl_t fvec_getperiod(aubio_beattracking_t * bt, uint_t timesig, uint_t rp); 33 34 /* could move to struct */ 35 uint_t gp = 0, bp = 0, rp1 = 0, rp2 = 0, bp2 = 0; 36 smpl_t g_mu = 0.; 37 smpl_t g_var = 3.901; 38 uint_t flagconst = 0; 39 uint_t flagstep = 0; 40 // needs to be a signed ? 41 sint_t counter = 0; 42 uint_t maxindex = 0; 43 uint_t timesig = 0; 44 uint_t rp = 1; 45 uint_t lastbeat = 0; 46 //number of harmonics in shift invariant comb filterbank 47 uint_t numelem = 4; 48 smpl_t myperiod = 0.; 49 50 uint_t maxnumelem = 4; 27 smpl_t fvec_getperiod(aubio_beattracking_t * bt); 51 28 52 29 struct _aubio_beattracking_t { 53 fvec_t * rwv; /* rayleigh weight vector  rayleigh distribution function */54 fvec_t * gwv; /* rayleigh weight vector  rayleigh distribution function */55 fvec_t * dfwv; /* detection function weighting  exponential curve */56 fvec_t * dfrev; /* reversed onset detection function */57 fvec_t * acf; /* vector for autocorrelation function (of current detection function frame) */58 fvec_t * acfout; /* store result of passing acf through s.i.c.f.b. */59 fvec_t * phwv; /* beat expectation alignment weighting */30 fvec_t * rwv; /** rayleigh weight vector  rayleigh distribution function */ 31 fvec_t * gwv; /** rayleigh weight vector  rayleigh distribution function */ 32 fvec_t * dfwv; /** detection function weighting  exponential curve */ 33 fvec_t * dfrev; /** reversed onset detection function */ 34 fvec_t * acf; /** vector for autocorrelation function (of current detection function frame) */ 35 fvec_t * acfout; /** store result of passing acf through s.i.c.f.b. */ 36 fvec_t * phwv; /** beat expectation alignment weighting */ 60 37 fvec_t * phout; 61 //uint_t timesig; /* time signature of input, set to zero until context dependent model activated */38 uint_t timesig; /** time signature of input, set to zero until context dependent model activated */ 62 39 uint_t step; 63 fvec_t * locacf; /* vector to store harmonics of filterbank of acf */ 64 fvec_t * inds; /* vector for max index outputs for each harmonic */ 65 uint_t rayparam; /* Rayleigh parameter */ 40 fvec_t * locacf; /** vector to store harmonics of filterbank of acf */ 41 fvec_t * inds; /** vector for max index outputs for each harmonic */ 42 uint_t rayparam; /** Rayleigh parameter */ 43 uint_t lastbeat; 44 sint_t counter; 45 uint_t flagstep; 46 smpl_t g_var; 47 uint_t gp; 48 uint_t bp; 49 uint_t rp; 50 uint_t rp1; 51 uint_t rp2; 66 52 }; 67 53 … … 81 67 uint_t step = winlen/4; /* 1.5 seconds */ 82 68 69 uint_t maxnumelem = 4; /* max number of index output */ 70 p>lastbeat = 0; 71 p>counter = 0; 72 p>flagstep = 0; 73 p>g_var = 3.901; // constthresh empirically derived! 74 p>rp = 1; 75 p>gp = 0; 76 83 77 p>rayparam = rayparam; 84 78 p>step = step; … … 92 86 p>phout = new_fvec(winlen,channels); 93 87 94 //p>timesig = 0;88 p>timesig = 0; 95 89 96 90 p>inds = new_fvec(maxnumelem,channels); … … 141 135 smpl_t * acfout = bt>acfout>data[0]; 142 136 smpl_t * acf = bt>acf>data[0]; 137 uint_t maxindex = 0; 138 //number of harmonics in shift invariant comb filterbank 139 uint_t numelem = 4; 140 141 //smpl_t myperiod = 0.; 143 142 //smpl_t * out = output>data[0]; 144 143 … … 149 148 uint_t kmax; 150 149 sint_t beat; 150 uint_t bp; 151 151 152 152 for (i = 0; i < winlen; i++){ … … 166 166 /* get acfout  assume Rayleigh weightvector only */ 167 167 /* if timesig is unknown, use metrically unbiased version of filterbank */ 168 if(! timesig)168 if(!bt>timesig) 169 169 numelem = 4; 170 170 // AUBIO_DBG("using unbiased filterbank, timesig: %d\n", timesig); 171 171 else 172 numelem = timesig;172 numelem = bt>timesig; 173 173 // AUBIO_DBG("using biased filterbank, timesig: %d\n", timesig); 174 174 … … 188 188 /* find nonzero Rayleigh period */ 189 189 maxindex = vec_max_elem(bt>acfout); 190 rp = maxindex ? maxindex : 1;190 bt>rp = maxindex ? maxindex : 1; 191 191 //rp = (maxindex==127) ? 43 : maxindex; //rayparam 192 rp = (maxindex==bt>acfout>length1) ? bt>rayparam : maxindex; //rayparam192 bt>rp = (maxindex==bt>acfout>length1) ? bt>rayparam : maxindex; //rayparam 193 193 194 194 // get float period 195 myperiod = fvec_getperiod(bt,timesig,rp);196 //AUBIO_DBG("\nrp = %d myperiod = %f\n", rp,myperiod);195 //myperiod = fvec_getperiod(bt); 196 //AUBIO_DBG("\nrp = %d myperiod = %f\n",bt>rp,myperiod); 197 197 //AUBIO_DBG("accurate tempo is %f bpm\n",5168./myperiod); 198 198 199 199 /* activate biased filterbank */ 200 200 aubio_beattracking_checkstate(bt); 201 bp = bt>bp; 201 202 /* end of biased filterbank */ 202 203 … … 221 222 /* debug */ 222 223 //AUBIO_DBG("beat period = %d, rp1 = %d, rp2 = %d\n", bp, rp1, rp2); 223 //AUBIO_DBG("rp = %d, gp = %d, phase = %d\n", rp,gp, phase);224 //AUBIO_DBG("rp = %d, gp = %d, phase = %d\n", bt>rp, bt>gp, phase); 224 225 225 226 /* reset output */ … … 243 244 } 244 245 245 lastbeat = beat;246 bt>lastbeat = beat; 246 247 /* store the number of beat found in this frame as the first element */ 247 248 output>data[0][0] = i; … … 266 267 } 267 268 268 smpl_t fvec_getperiod(aubio_beattracking_t * bt , uint_t timesig, uint_t rp){269 smpl_t fvec_getperiod(aubio_beattracking_t * bt){ 269 270 /*function to make a more accurate beat period measurement.*/ 270 271 271 272 smpl_t period = 0.; 272 273 smpl_t maxval = 0.; 274 uint_t numelem = 4; 273 275 274 276 sint_t a,b; 275 277 uint_t i,j; 276 uint_t acfmi = rp; //acfout max index278 uint_t acfmi = bt>rp; //acfout max index 277 279 uint_t maxind = 0; 278 280 279 if(! timesig)281 if(!bt>timesig) 280 282 numelem = 4; 281 283 else 282 numelem = timesig;284 numelem = bt>timesig; 283 285 284 286 for (i=0;i<numelem;i++) // initialize … … 298 300 for(i=0;i<numelem;i++){ 299 301 300 maxind ex= 0;302 maxind = 0; 301 303 maxval = 0.0; 302 304 … … 325 327 void aubio_beattracking_checkstate(aubio_beattracking_t * bt) { 326 328 uint_t i,j,a,b; 329 uint_t flagconst = 0; 330 sint_t counter = bt>counter; 331 uint_t flagstep = bt>flagstep; 332 uint_t gp = bt>gp; 333 uint_t bp = bt>bp; 334 uint_t rp = bt>rp; 335 uint_t rp1 = bt>rp1; 336 uint_t rp2 = bt>rp2; 327 337 uint_t laglen = bt>rwv>length; 328 338 uint_t acflen = bt>acf>length; … … 342 352 acfout[i] = 0.; 343 353 for(i=1;i<laglen1;i++){ 344 for (a=1;a<= timesig;a++){354 for (a=1;a<=bt>timesig;a++){ 345 355 for(b=(1a);b<a;b++){ 346 356 acfout[i] += acf[a*(i+1)+b1] … … 362 372 // is greater than 2*constthresh  always true in first case, since gp = 0 363 373 if(counter == 0){ 364 if(ABS(gp  rp) > 2.* constthresh) {374 if(ABS(gp  rp) > 2.*bt>g_var) { 365 375 flagstep = 1; // have observed step change. 366 376 counter = 3; // setup 3 frame counter … … 373 383 if (counter==1 && flagstep==1) { 374 384 //check for consistency between previous beatperiod values 375 if(ABS(2.*rp  rp1 rp2) < constthresh) {385 if(ABS(2.*rp  rp1 rp2) < bt>g_var) { 376 386 //if true, can activate context dependent model 377 387 flagconst = 1; … … 392 402 /* first run of new hypothesis */ 393 403 gp = rp; 394 g_mu = gp; 395 timesig = fvec_gettimesig(acf,acflen, gp); 404 bt>timesig = fvec_gettimesig(acf,acflen, gp); 396 405 for(j=0;j<laglen;j++) 397 gwv[j] = EXP(.5*SQR((smpl_t)(j+1.g _mu))/SQR(g_var));406 gwv[j] = EXP(.5*SQR((smpl_t)(j+1.gp))/SQR(bt>g_var)); 398 407 flagconst = 0; 399 408 bp = gp; 400 409 /* flat phase weighting */ 401 410 for(j=0;j<2*laglen;j++) {phwv[j] = 1.;} 402 } else if ( timesig) {411 } else if (bt>timesig) { 403 412 /* context dependant model */ 404 413 bp = gp; 405 414 /* gaussian phase weighting */ 406 if (step > lastbeat) {415 if (step > bt>lastbeat) { 407 416 for(j=0;j<2*laglen;j++) { 408 phwv[j] = EXP(.5*SQR((smpl_t)(1.+jstep+ lastbeat))/(bp/8.));417 phwv[j] = EXP(.5*SQR((smpl_t)(1.+jstep+bt>lastbeat))/(bp/8.)); 409 418 } 410 419 } else { 411 420 //AUBIO_DBG("NOT using phase weighting as step is %d and lastbeat %d \n", 412 // step, lastbeat);421 // step,bt>lastbeat); 413 422 for(j=0;j<2*laglen;j++) {phwv[j] = 1.;} 414 423 } … … 435 444 //AUBIO_DBG("tempo:\t%3.5f bpm smoothed  bp2 %d  bp %d  ", 5168./bp, bp2, bp); 436 445 //bp2 = bp; 437 //AUBIO_DBG("time signature: %d \n", timesig); 438 439 } 446 //AUBIO_DBG("time signature: %d \n", bt>timesig); 447 bt>counter = counter; 448 bt>flagstep = flagstep; 449 bt>gp = gp; 450 bt>bp = bp; 451 bt>rp1 = rp1; 452 bt>rp2 = rp2; 453 454 }
Note: See TracChangeset
for help on using the changeset viewer.