From: Paul Brossier Date: Sun, 22 May 2005 22:31:46 +0000 (+0000) Subject: update beattracking.c X-Git-Tag: bzr2git~913 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2cdae8125fac1e0d46450b8c910a60fb8f335f41;p=aubio.git update beattracking.c update beattracking.c --- diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index 4261e30e..772338e7 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -80,8 +80,8 @@ int aubio_process(float **input, float **output, int nframes) { /* end of second level loop */ istactus = 0; i=0; - for (i = 1; i <= btoutput[0]; i++ ) { - if (pos2 == btoutput[i] && btoutput[i] != 0.) { + for (i = 1; i < btoutput[0]; i++ ) { + if (pos2 == btoutput[i]) { //printf("pos2: %d\n", pos2); /* test for silence */ if (aubio_silence_detection(ibuf, threshold2)==1) { @@ -112,8 +112,8 @@ void process_print (void); void process_print (void) { if (output_filename == NULL) { if (istactus) - outmsg("%d\t%f",pos2,(frames)*overlap_size/(float)samplerate); - if (isonset) + outmsg("%f\n",(frames)*overlap_size/(float)samplerate); + if (isonset && verbose) outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate); } } diff --git a/src/beattracking.c b/src/beattracking.c index bfe77a05..bd0a4005 100644 --- a/src/beattracking.c +++ b/src/beattracking.c @@ -29,9 +29,10 @@ static smpl_t stepthresh = 2.*3.901; uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp); void aubio_beattracking_checkstate(aubio_beattracking_t * bt); +smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp); /* could move to struct */ -uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0; +uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0, bp2 = 0; smpl_t g_mu =0.; smpl_t g_var = 3.901; uint_t flagconst = 0; @@ -44,6 +45,15 @@ uint_t rp = 1; uint_t lastbeat = 0; //number of harmonics in shift invariant comb filterbank uint_t numelem = 4; +smpl_t myperiod = 0.; + + +// FIXME +uint_t maxnumelem = 4; +uint_t len = 512; +smpl_t inds[4]; //vector for max index outputs for each harmonic +smpl_t local_acf[512]; //vector to store harmonics of filterbank of acf + struct _aubio_beattracking_t { fvec_t * rwv; /* rayleigh weight vector - rayleigh distribution function */ @@ -159,9 +169,10 @@ void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframe, fvec_t * /* first and last output values are left intentionally as zero */ for (i=0; i < bt->acfout->length; i++) acfout[i] = 0.; + for(i=1;iphout); if (maxindex == winlen-1) maxindex = 0; @@ -208,7 +224,7 @@ void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframe, fvec_t * i = 1; beat = bp - phase; /* start counting the beats */ - if(beat) + if(beat >= 0) { output->data[0][i] = (smpl_t)beat; i++; @@ -245,6 +261,64 @@ uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp){ return (three_energy > four_energy) ? 3 : 4; } +smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp){ + /*function to make a more accurate beat period measurement.*/ + + smpl_t period = 0.; + smpl_t maxval = 0.; + + + + int a,b; + uint_t i,j; + uint_t acfmi = rp; //acfout max index + uint_t maxind = 0; + + if(!timesig) + numelem = 4; + else + numelem = timesig; + + for (i=0;imaxval){ + maxval = local_acf[j]; + maxind = j; + } + local_acf[maxind] = 0.; + } + //printf("\n\n"); + //AUBIO_DBG("\n maxind is %d\n",maxind); + inds[i] = maxind; + + } + + for (i=0;irwv->length; @@ -272,6 +346,10 @@ void aubio_beattracking_checkstate(aubio_beattracking_t * bt) { } } gp = vec_max_elem(bt->acfout); + /* + while(gp<32) gp =gp*2; + while(gp>64) gp = gp/2; + */ } else { //still only using general model gp = 0; @@ -338,14 +416,20 @@ void aubio_beattracking_checkstate(aubio_beattracking_t * bt) { for(j=0;j<2*laglen;j++) {phwv[j] = 1.;} } - /* do some further checks on the final bp value */ + /* if tempo is > 206 bpm, half it */ while (bp < 25) { + AUBIO_DBG("warning, halving the tempo from %f\n", 5168./bp); bp = bp*2; - AUBIO_DBG("warning, halving the tempo to %f\n", 5168./bp); } - AUBIO_DBG("tempo:\t%3.5f bpm | time signature: %d \n", 5168./bp, timesig); + AUBIO_DBG("tempo:\t%3.5f bpm | ", 5168./bp); + + /* smoothing */ + //bp = (uint_t) (0.8 * (smpl_t)bp + 0.2 * (smpl_t)bp2); + //AUBIO_DBG("tempo:\t%3.5f bpm smoothed | bp2 %d | bp %d | ", 5168./bp, bp2, bp); + //bp2 = bp; + AUBIO_DBG("time signature: %d \n", timesig); }