Changeset e21208e


Ignore:
Timestamp:
Jul 21, 2006, 3:54:48 PM (18 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
b91fe6e
Parents:
f3f28b1
Message:

remove global variable in beattracking
remove global variable in beattracking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/beattracking.c

    rf3f28b1 re21208e  
    2323#include "beattracking.h"
    2424
    25 // 60*samplerate/winlen
    26 
    27 /* maximum length for rp */
    28 static smpl_t constthresh = 3.901; //empirically derived!
    29 
    3025uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp);
    3126void 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;
     27smpl_t fvec_getperiod(aubio_beattracking_t * bt);
    5128
    5229struct _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 */
    6037        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 */
    6239        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;
    6652};
    6753
     
    8167        uint_t step     = winlen/4; /* 1.5 seconds */
    8268
     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
    8377        p->rayparam = rayparam;
    8478        p->step    = step;
     
    9286        p->phout   = new_fvec(winlen,channels);
    9387
    94         //p->timesig = 0;
     88        p->timesig = 0;
    9589
    9690        p->inds    = new_fvec(maxnumelem,channels);
     
    141135        smpl_t * acfout = bt->acfout->data[0];
    142136        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.;
    143142        //smpl_t * out    = output->data[0];
    144143
     
    149148        uint_t kmax;
    150149        sint_t beat;
     150        uint_t bp;
    151151
    152152        for (i = 0; i < winlen; i++){
     
    166166        /* get acfout - assume Rayleigh weightvector only */
    167167        /* if timesig is unknown, use metrically unbiased version of filterbank */
    168         if(!timesig) 
     168        if(!bt->timesig) 
    169169                numelem = 4;
    170170        //        AUBIO_DBG("using unbiased filterbank, timesig: %d\n", timesig);
    171171        else
    172                 numelem = timesig;
     172                numelem = bt->timesig;
    173173        //        AUBIO_DBG("using biased filterbank, timesig: %d\n", timesig);
    174174
     
    188188        /* find non-zero Rayleigh period */
    189189        maxindex = vec_max_elem(bt->acfout);
    190         rp = maxindex ? maxindex : 1;
     190        bt->rp = maxindex ? maxindex : 1;
    191191        //rp = (maxindex==127) ? 43 : maxindex; //rayparam
    192         rp = (maxindex==bt->acfout->length-1) ? bt->rayparam : maxindex; //rayparam
     192        bt->rp = (maxindex==bt->acfout->length-1) ? bt->rayparam : maxindex; //rayparam
    193193
    194194        // 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);
    197197        //AUBIO_DBG("accurate tempo is %f bpm\n",5168./myperiod);
    198198
    199199        /* activate biased filterbank */
    200200        aubio_beattracking_checkstate(bt);
     201        bp = bt->bp;
    201202        /* end of biased filterbank */
    202203
     
    221222        /* debug */
    222223        //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);
    224225
    225226        /* reset output */
     
    243244        }
    244245
    245         lastbeat = beat;
     246        bt->lastbeat = beat;
    246247        /* store the number of beat found in this frame as the first element */
    247248        output->data[0][0] = i;
     
    266267}
    267268
    268 smpl_t fvec_getperiod(aubio_beattracking_t * bt, uint_t timesig, uint_t rp){
     269smpl_t fvec_getperiod(aubio_beattracking_t * bt){
    269270        /*function to make a more accurate beat period measurement.*/
    270271
    271272        smpl_t period = 0.;
    272273        smpl_t maxval = 0.;
     274        uint_t numelem    = 4;
    273275       
    274276        sint_t a,b;
    275277        uint_t i,j;     
    276         uint_t acfmi = rp; //acfout max index
     278        uint_t acfmi = bt->rp; //acfout max index
    277279        uint_t maxind = 0;
    278280
    279         if(!timesig)
     281        if(!bt->timesig)
    280282                numelem = 4;
    281283        else
    282                 numelem = timesig;
     284                numelem = bt->timesig;
    283285
    284286        for (i=0;i<numelem;i++) // initialize
     
    298300        for(i=0;i<numelem;i++){
    299301
    300                 maxindex = 0;
     302                maxind = 0;
    301303                maxval = 0.0;
    302304       
     
    325327void aubio_beattracking_checkstate(aubio_beattracking_t * bt) {
    326328        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;
    327337        uint_t laglen   = bt->rwv->length;
    328338        uint_t acflen   = bt->acf->length;
     
    342352                       acfout[i] = 0.;
    343353                for(i=1;i<laglen-1;i++){
    344                         for (a=1;a<=timesig;a++){
     354                        for (a=1;a<=bt->timesig;a++){
    345355                                for(b=(1-a);b<a;b++){
    346356                                        acfout[i] += acf[a*(i+1)+b-1]
     
    362372        // is greater than 2*constthresh - always true in first case, since gp = 0
    363373        if(counter == 0){
    364                 if(ABS(gp - rp) > 2.*constthresh) {
     374                if(ABS(gp - rp) > 2.*bt->g_var) {
    365375                        flagstep = 1; // have observed  step change.
    366376                        counter  = 3; // setup 3 frame counter
     
    373383        if (counter==1 && flagstep==1) {
    374384                //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) {
    376386                        //if true, can activate context dependent model
    377387                        flagconst = 1;
     
    392402                /* first run of new hypothesis */
    393403                gp = rp;
    394                 g_mu = gp;
    395                 timesig = fvec_gettimesig(acf,acflen, gp);
     404                bt->timesig = fvec_gettimesig(acf,acflen, gp);
    396405                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));
    398407                flagconst = 0;
    399408                bp = gp;
    400409                /* flat phase weighting */
    401410                for(j=0;j<2*laglen;j++)  {phwv[j] = 1.;}
    402         } else if (timesig) {
     411        } else if (bt->timesig) {
    403412                /* context dependant model */
    404413                bp = gp;
    405414                /* gaussian phase weighting */
    406                 if (step > lastbeat) {
     415                if (step > bt->lastbeat) {
    407416                        for(j=0;j<2*laglen;j++)  {
    408                                 phwv[j] = EXP(-.5*SQR((smpl_t)(1.+j-step+lastbeat))/(bp/8.));
     417                                phwv[j] = EXP(-.5*SQR((smpl_t)(1.+j-step+bt->lastbeat))/(bp/8.));
    409418                        }
    410419                } else {
    411420                        //AUBIO_DBG("NOT using phase weighting as step is %d and lastbeat %d \n",
    412                         //                step,lastbeat);
     421                        //                step,bt->lastbeat);
    413422                        for(j=0;j<2*laglen;j++)  {phwv[j] = 1.;}
    414423                }
     
    435444        //AUBIO_DBG("tempo:\t%3.5f bpm smoothed | bp2 %d | bp %d | ", 5168./bp, bp2, bp);
    436445        //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.