Changeset 2cdae81 for src


Ignore:
Timestamp:
May 23, 2005, 12:31:46 AM (19 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:
71f98f1
Parents:
b78805a
Message:

update beattracking.c
update beattracking.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/beattracking.c

    rb78805a r2cdae81  
    3030uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp);
    3131void aubio_beattracking_checkstate(aubio_beattracking_t * bt);
     32smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp);
    3233
    3334/* could move to struct */
    34 uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0;
     35uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0, bp2 = 0;
    3536smpl_t g_mu =0.;
    3637smpl_t g_var = 3.901;
     
    4546//number of harmonics in shift invariant comb filterbank
    4647uint_t numelem   = 4;
     48smpl_t myperiod = 0.;
     49
     50
     51// FIXME
     52uint_t maxnumelem = 4;
     53uint_t len = 512;
     54smpl_t inds[4]; //vector for max index outputs for each harmonic
     55smpl_t local_acf[512]; //vector to store harmonics of filterbank of acf
     56
    4757
    4858struct _aubio_beattracking_t {
     
    160170        for (i=0; i < bt->acfout->length; i++)
    161171                acfout[i] = 0.;
     172
    162173        for(i=1;i<laglen-1;i++){
    163                 for (a=1;a<=numelem;a++){
    164                         for(b=(1-a);b<a;b++){
     174                for (a=1; a<=numelem; a++){
     175                        for(b=(1-a); b<a; b++){
    165176                                acfout[i] += acf[a*(i+1)+b-1]
    166177                                        * 1./(2.*a-1.)*rwv[i];
     
    174185        rp = (maxindex==127) ? 43 : maxindex; //rayparam
    175186
     187        // get float period
     188        myperiod = fvec_getperiod(acf,timesig,rp);
     189        //AUBIO_DBG("\nrp =  %d myperiod = %f\n",rp,myperiod);
     190        //AUBIO_DBG("accurate tempo is %f bpm\n",5168./myperiod);
     191       
     192
    176193        /* activate biased filterbank */
    177194        aubio_beattracking_checkstate(bt);
     
    192209        }
    193210
    194 
    195211        /* find Rayleigh period */
    196212        maxindex = vec_max_elem(bt->phout);
     
    209225        beat =  bp - phase;
    210226        /* start counting the beats */
    211         if(beat)
     227        if(beat >= 0)
    212228        {
    213229                output->data[0][i] = (smpl_t)beat;
     
    245261        return (three_energy > four_energy) ? 3 : 4;
    246262}
     263
     264smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp){
     265        /*function to make a more accurate beat period measurement.*/
     266
     267        smpl_t period = 0.;
     268        smpl_t maxval = 0.;
     269       
     270
     271
     272        int a,b;
     273        uint_t i,j;     
     274        uint_t acfmi = rp; //acfout max index
     275        uint_t maxind = 0;
     276
     277        if(!timesig)
     278                numelem = 4;
     279        else
     280                numelem = timesig;
     281
     282        for (i=0;i<numelem;i++) // initialize
     283        inds[i] = 0.;
     284
     285        for (i=0;i<len;i++) // initialize
     286        local_acf[i] = 0.;
     287       
     288        // get appropriate acf elements from acf and store in local_acf
     289        for (a=1;a<=4;a++){
     290                for(b=(1-a);b<a;b++){           
     291                        local_acf[a*(acfmi)+b-1] = acf[a*(acfmi)+b-1];                                               
     292                            }
     293                        }
     294
     295        for(i=0;i<numelem;i++){
     296
     297                maxindex = 0;
     298                maxval = 0.0;
     299       
     300                for (j=0;j<(acfmi*(i+1)+(i)); j++){
     301                        if(local_acf[j]>maxval){
     302                                maxval = local_acf[j];
     303                                maxind = j;
     304                                }
     305                                local_acf[maxind] = 0.;
     306                }
     307                //printf("\n\n");
     308                //AUBIO_DBG("\n maxind is  %d\n",maxind);
     309                inds[i] = maxind;
     310
     311        }
     312
     313        for (i=0;i<numelem;i++){
     314                period += inds[i]/(i+1.);}
     315
     316        period = period/numelem;
     317
     318        return (period);
     319}
     320
    247321
    248322void aubio_beattracking_checkstate(aubio_beattracking_t * bt) {
     
    273347                }
    274348                gp = vec_max_elem(bt->acfout);
     349                /*
     350                while(gp<32) gp =gp*2;
     351                while(gp>64) gp = gp/2;
     352                */
    275353        } else {
    276354                //still only using general model
     
    339417        }
    340418
    341 
    342419        /* do some further checks on the final bp value */
     420
    343421        /* if tempo is > 206 bpm, half it */
    344422        while (bp < 25) {
     423                AUBIO_DBG("warning, halving the tempo from %f\n", 5168./bp);
    345424                bp = bp*2;
    346                 AUBIO_DBG("warning, halving the tempo to %f\n", 5168./bp);
    347425        }
    348426       
    349         AUBIO_DBG("tempo:\t%3.5f bpm | time signature: %d \n", 5168./bp, timesig);
    350 
    351 }
     427        AUBIO_DBG("tempo:\t%3.5f bpm | ", 5168./bp);
     428
     429        /* smoothing */
     430        //bp = (uint_t) (0.8 * (smpl_t)bp + 0.2 * (smpl_t)bp2);
     431        //AUBIO_DBG("tempo:\t%3.5f bpm smoothed | bp2 %d | bp %d | ", 5168./bp, bp2, bp);
     432        //bp2 = bp;
     433        AUBIO_DBG("time signature: %d \n", timesig);
     434
     435}
Note: See TracChangeset for help on using the changeset viewer.