Changeset 0ce9acc3


Ignore:
Timestamp:
Jun 7, 2005, 6:56:39 PM (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:
b31f262
Parents:
97b8c3d
Message:

updated beattracking.c ad aubiotrack.c to support variable hopsize

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiotrack.c

    r97b8c3d r0ce9acc3  
    2727aubio_beattracking_t * bt = NULL;
    2828uint_t winlen             = 512;
    29 uint_t step               = 128;
    30 uint_t laglen             = 128;
    31 uint_t rayparam           = 43;
     29uint_t step               = 0;
    3230uint_t istactus           = 0;
    3331
     
    8482              if (pos2 == btoutput[i]) {
    8583                      //printf("pos2: %d\n", pos2);
     84                      //printf("tempo:\t%3.5f bpm \n",
     85                      //60.*44100./overlap_size/abs(btoutput[2]-btoutput[1]));
    8686                      /* test for silence */
    8787                      if (aubio_silence_detection(ibuf, threshold2)==1) {
     
    123123  /* override default settings */
    124124  examples_common_init(argc,argv);
     125  winlen = SQR(512)/overlap_size;
    125126
    126127  dfframe = new_fvec(winlen,channels);
     128  step = winlen/4;
    127129  out = new_fvec(step,channels);
     130
    128131  /* test input : impulses starting from 15, at intervals of 50 samples */
    129132  //for(i=0;i<16;i++){
     
    131134  //}
    132135
    133   bt = new_aubio_beattracking(winlen,step, laglen,
    134                   rayparam, channels);
     136  bt = new_aubio_beattracking(winlen,channels);
    135137
    136138  examples_common_process(aubio_process,process_print);
  • examples/utils.c

    r97b8c3d r0ce9acc3  
    9898
    9999int parse_args (int argc, char **argv) {
    100         const char *options = "hvjo:i:O:t:s:a";
     100        const char *options = "hvjo:i:O:t:s:H:a";
    101101        int next_option;
    102102        struct option long_options[] =
     
    111111                {"silence"  , 0, NULL, 's'},
    112112                {"averaging", 0, NULL, 'a'},
     113                {"hopsize",   0, NULL, 'H'},
    113114                {NULL       , 0, NULL, 0}
    114115        };
     
    169170                                averaging = 1;
    170171                                break;
     172                        case 'H':
     173                                overlap_size = atoi(optarg);
     174                                break;
    171175                        case '?':       /* unknown options */
    172176                                usage(stderr, 1);
  • src/beattracking.c

    r97b8c3d r0ce9acc3  
    2323#include "beattracking.h"
    2424
     25// 60*samplerate/winlen
     26
    2527/* maximum length for rp */
    26 static uint_t MAXRP = 512;
    2728static smpl_t constthresh = 3.901; //empirically derived!
    28 static smpl_t stepthresh = 2.*3.901;
    2929
    3030uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp);
    3131void aubio_beattracking_checkstate(aubio_beattracking_t * bt);
    32 smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp);
     32smpl_t fvec_getperiod(aubio_beattracking_t * bt, uint_t timesig, uint_t rp);
    3333
    3434/* 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;
     35uint_t gp         = 0, bp = 0, rp1 = 0, rp2 = 0, bp2 = 0;
     36smpl_t g_mu       = 0.;
     37smpl_t g_var      = 3.901;
     38uint_t flagconst  = 0;
     39uint_t flagstep   = 0;
    4040// 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;
     41sint_t counter    = 0;
     42uint_t maxindex   = 0;
     43uint_t timesig    = 0;
     44uint_t rp         = 1;
     45uint_t lastbeat   = 0;
    4646//number of harmonics in shift invariant comb filterbank
    47 uint_t numelem   = 4;
    48 smpl_t myperiod = 0.;
    49 
    50 
    51 // FIXME
     47uint_t numelem    = 4;
     48smpl_t myperiod   = 0.;
     49
    5250uint_t maxnumelem = 4;
    53 uint_t len = 512;
    54 smpl_t inds[4]; //vector for max index outputs for each harmonic
    55 smpl_t local_acf[512]; //vector to store harmonics of filterbank of acf
    56 
    5751
    5852struct _aubio_beattracking_t {
     
    6761        //uint_t timesig;  /* time signature of input, set to zero until context dependent model activated */
    6862        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 */
    6966};
    7067
    7168aubio_beattracking_t * new_aubio_beattracking(uint_t winlen,
    72                 uint_t step,
    73                 uint_t laglen,
    74                 uint_t rayparam,
    7569                uint_t channels) {
    7670
    7771        aubio_beattracking_t * p = AUBIO_NEW(aubio_beattracking_t);
    78 
    7972        uint_t i        = 0;
     73        smpl_t rayparam = 48./512. * winlen;
    8074        smpl_t dfwvnorm = EXP((LOG(2.0)/rayparam)*(winlen+2));
    81 
     75        uint_t laglen   = winlen/4;
     76        uint_t step     = winlen/4; /* 1.5 seconds */
     77
     78        p->rayparam = rayparam;
    8279        p->step    = step;
    8380        p->rwv     = new_fvec(laglen,channels);
     
    8885        p->acfout  = new_fvec(laglen,channels);
    8986        p->phwv    = new_fvec(2*laglen,channels);
    90         p->phout   = new_fvec(MAXRP,channels);
     87        p->phout   = new_fvec(winlen,channels);
     88
    9189        //p->timesig = 0;
     90
     91        p->inds    = new_fvec(maxnumelem,channels);
     92        p->locacf  = new_fvec(winlen,channels);
    9293
    9394        /* exponential weighting, dfwv = 0.5 when i =  43 */
     
    115116        del_fvec(p->phwv);
    116117        del_fvec(p->phout);
     118        del_fvec(p->locacf);
     119        del_fvec(p->inds);
    117120        AUBIO_FREE(p);
    118121}
     
    158161        /* get acfout - assume Rayleigh weightvector only */
    159162        /* if timesig is unknown, use metrically unbiased version of filterbank */
    160         //if(!timesig) 
    161         //        AUBIO_DBG("using unbiased filterbank, timesig: %d\n", timesig);
    162         //else         
    163         //        AUBIO_DBG("using biased filterbank, timesig: %d\n", timesig);
    164163        if(!timesig) 
    165164                numelem = 4;
     165        //        AUBIO_DBG("using unbiased filterbank, timesig: %d\n", timesig);
    166166        else
    167167                numelem = timesig;
     168        //        AUBIO_DBG("using biased filterbank, timesig: %d\n", timesig);
    168169
    169170        /* first and last output values are left intentionally as zero */
     
    183184        maxindex = vec_max_elem(bt->acfout);
    184185        rp = maxindex ? maxindex : 1;
    185         rp = (maxindex==127) ? 43 : maxindex; //rayparam
     186        //rp = (maxindex==127) ? 43 : maxindex; //rayparam
     187        rp = (maxindex==bt->acfout->length-1) ? bt->rayparam : maxindex; //rayparam
    186188
    187189        // get float period
    188         myperiod = fvec_getperiod(acf,timesig,rp);
     190        myperiod = fvec_getperiod(bt,timesig,rp);
    189191        //AUBIO_DBG("\nrp =  %d myperiod = %f\n",rp,myperiod);
    190192        //AUBIO_DBG("accurate tempo is %f bpm\n",5168./myperiod);
    191        
    192193
    193194        /* activate biased filterbank */
     
    196197
    197198        /* initialize output */
    198         for(i=0;i<MAXRP;i++)     {phout[i] = 0.;}
    199 
    200         /* deliberate integer operation */
    201         /* could be set to 3 max eventually */
     199        for(i=0;i<bt->phout->length;i++)     {phout[i] = 0.;}
     200
     201        /* deliberate integer operation, could be set to 3 max eventually */
    202202        kmax = winlen/bp;
    203203
     
    239239
    240240        lastbeat = beat;
    241 
     241        /* store the number of beat found in this frame as the first element */
    242242        output->data[0][0] = i;
    243 
    244243}
    245244
     
    262261}
    263262
    264 smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp){
     263smpl_t fvec_getperiod(aubio_beattracking_t * bt, uint_t timesig, uint_t rp){
    265264        /*function to make a more accurate beat period measurement.*/
    266265
     
    268267        smpl_t maxval = 0.;
    269268       
    270 
    271 
    272         int a,b;
     269        sint_t a,b;
    273270        uint_t i,j;     
    274271        uint_t acfmi = rp; //acfout max index
     
    281278
    282279        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.;
     280        bt->inds->data[0][i] = 0.;
     281
     282        for (i=0;i<bt->locacf->length;i++) // initialize
     283                bt->locacf->data[0][i] = 0.;
    287284       
    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                         }
     285        // get appropriate acf elements from acf and store in locacf
     286        for (a=1;a<=4;a++){
     287                for(b=(1-a);b<a;b++){           
     288                        bt->locacf->data[0][a*(acfmi)+b-1] =
     289                                bt->acf->data[0][a*(acfmi)+b-1];                                                     
     290                }
     291        }
    294292
    295293        for(i=0;i<numelem;i++){
     
    299297       
    300298                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.;
     299                        if(bt->locacf->data[0][j]>maxval){
     300                                maxval = bt->locacf->data[0][j];
     301                                maxind = j;
     302                        }
     303                        //bt->locacf->data[0][maxind] = 0.;
     304                        bt->locacf->data[0][j] = 0.;
    306305                }
    307                 //printf("\n\n");
    308306                //AUBIO_DBG("\n maxind is  %d\n",maxind);
    309                 inds[i] = maxind;
     307                bt->inds->data[0][i] = maxind;
    310308
    311309        }
    312310
    313311        for (i=0;i<numelem;i++){
    314                 period += inds[i]/(i+1.);}
     312                period += bt->inds->data[0][i]/(i+1.);}
    315313
    316314        period = period/numelem;
     
    357355
    358356        //now look for step change - i.e. a difference between gp and rp that
    359         // is greater than stepthresh - always true in first case, since gp = 0
     357        // is greater than 2*constthresh - always true in first case, since gp = 0
    360358        if(counter == 0){
    361                 if(ABS(gp - rp) > stepthresh) {
     359                if(ABS(gp - rp) > 2.*constthresh) {
    362360                        flagstep = 1; // have observed  step change.
    363361                        counter  = 3; // setup 3 frame counter
     
    421419        /* if tempo is > 206 bpm, half it */
    422420        while (bp < 25) {
    423                 AUBIO_DBG("warning, halving the tempo from %f\n", 5168./bp);
     421        //while (bp < fact/206.) {
     422                AUBIO_DBG("warning, doubling the beat period from %d\n", bp);
     423                //AUBIO_DBG("warning, halving the tempo from %f\n", 60.*samplerate/hopsize/bp);
    424424                bp = bp*2;
    425425        }
    426426       
    427         AUBIO_DBG("tempo:\t%3.5f bpm | ", 5168./bp);
     427        //AUBIO_DBG("tempo:\t%3.5f bpm | ", 5168./bp);
    428428
    429429        /* smoothing */
     
    431431        //AUBIO_DBG("tempo:\t%3.5f bpm smoothed | bp2 %d | bp %d | ", 5168./bp, bp2, bp);
    432432        //bp2 = bp;
    433         AUBIO_DBG("time signature: %d \n", timesig);
    434 
    435 }
     433        //AUBIO_DBG("time signature: %d \n", timesig);
     434
     435}
  • src/beattracking.h

    r97b8c3d r0ce9acc3  
    3737 * \param channel number (not functionnal) [1] */
    3838aubio_beattracking_t * new_aubio_beattracking(uint_t winlen,
    39                 uint_t step,
    40                 uint_t laglen,
    41                 uint_t rayparam,
    4239                uint_t channels);
    4340/**
Note: See TracChangeset for help on using the changeset viewer.