Ignore:
Timestamp:
Sep 13, 2009, 11:54:23 PM (15 years ago)
Author:
Paul Brossier <piem@piem.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:
7bf3dcb
Parents:
3b2d32c
Message:

src/tempo/beattracking.c: use fvec_ utilities, improve comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tempo/beattracking.c

    r3b2d32c r6f1727f  
    2323#include "tempo/beattracking.h"
    2424
    25 uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp);
     25uint_t fvec_gettimesig(fvec_t * acf, uint_t acflen, uint_t gp);
    2626void aubio_beattracking_checkstate(aubio_beattracking_t * bt);
    2727
    2828struct _aubio_beattracking_t {
    29         fvec_t * rwv;    /** rayleigh weight vector - rayleigh distribution function */                   
    30         fvec_t * gwv;    /** rayleigh weight vector - rayleigh distribution function */                   
    31         fvec_t * dfwv;   /** detection function weighting - exponential curve */
     29        fvec_t * rwv;    /** rayleigh weighting for beat period in general model */
     30        fvec_t * dfwv;   /** exponential weighting for beat alignment in general model */
     31        fvec_t * gwv;    /** gaussian weighting for beat period in context dependant model */
     32        fvec_t * phwv;   /** gaussian weighting for beat alignment in context dependant model */
    3233        fvec_t * dfrev;  /** reversed onset detection function */
    3334        fvec_t * acf;    /** vector for autocorrelation function (of current detection function frame) */
    3435        fvec_t * acfout; /** store result of passing acf through s.i.c.f.b. */
    35         fvec_t * phwv;   /** beat expectation alignment weighting */
    3636        fvec_t * phout;
    3737        uint_t timesig;  /** time signature of input, set to zero until context dependent model activated */
     
    7373        p->rayparam = rayparam;
    7474        p->step    = step;
    75         p->rwv     = new_fvec(laglen,channels);
    76         p->gwv     = new_fvec(laglen,channels);
    77         p->dfwv    = new_fvec(winlen,channels);
     75        p->rwv     = new_fvec(laglen,1);
     76        p->gwv     = new_fvec(laglen,1);
     77        p->dfwv    = new_fvec(winlen,1);
    7878        p->dfrev   = new_fvec(winlen,channels);
    7979        p->acf     = new_fvec(winlen,channels);
    8080        p->acfout  = new_fvec(laglen,channels);
    81         p->phwv    = new_fvec(2*laglen,channels);
     81        p->phwv    = new_fvec(2*laglen,1);
    8282        p->phout   = new_fvec(winlen,channels);
    8383
     
    118118        uint_t laglen   = bt->rwv->length;
    119119        uint_t winlen   = bt->dfwv->length;
    120         smpl_t * phout  = bt->phout->data[0];
    121         smpl_t * phwv   = bt->phwv->data[0];
    122         smpl_t * dfrev  = bt->dfrev->data[0];
    123         smpl_t * dfwv   = bt->dfwv->data[0];
    124         smpl_t * rwv    = bt->rwv->data[0];
    125         smpl_t * acfout = bt->acfout->data[0];
    126         smpl_t * acf    = bt->acf->data[0];
    127120        uint_t maxindex = 0;
    128121        //number of harmonics in shift invariant comb filterbank
     
    135128        uint_t kmax;  // number of elements used to find beat phase
    136129
    137         for (i = 0; i < winlen; i++){
    138                 dfrev[winlen-1-i] = 0.;
    139                 dfrev[winlen-1-i] = dfframe->data[0][i]*dfwv[i];
    140         }
    141 
    142         /* find autocorrelation function */
     130        /* copy dfframe, apply detection function weighting, and revert */
     131        fvec_copy(dfframe, bt->dfrev);
     132        fvec_weight(bt->dfrev, bt->dfwv);
     133        fvec_rev(bt->dfrev);
     134
     135        /* compute autocorrelation function */
    143136        aubio_autocorr(dfframe,bt->acf);
    144137
     
    151144
    152145        /* first and last output values are left intentionally as zero */
    153         for (i=0; i < bt->acfout->length; i++)
    154                 acfout[i] = 0.;
    155 
    156         /* get acfout - assume Rayleigh weightvector only */
     146        fvec_zeros(bt->acfout);
     147
     148        /* compute shift invariant comb filterbank */
    157149        for(i=1;i<laglen-1;i++){
    158150                for (a=1; a<=numelem; a++){
    159151                        for(b=(1-a); b<a; b++){
    160                                 acfout[i] += acf[a*(i+1)+b-1]
    161                                         * 1./(2.*a-1.)*rwv[i];
     152                                bt->acfout->data[0][i] += bt->acf->data[0][a*(i+1)+b-1]
     153                                        * 1./(2.*a-1.);
    162154                        }
    163155                }
    164156        }
     157        /* apply Rayleigh weight */
     158        fvec_weight(bt->acfout, bt->rwv);
    165159
    166160        /* find non-zero Rayleigh period */
     
    178172        /* end of biased filterbank */
    179173
    180         /* initialize output */
    181         for(i=0;i<bt->phout->length;i++)     {phout[i] = 0.;}
    182174
    183175        /* deliberate integer operation, could be set to 3 max eventually */
    184176        kmax = FLOOR(winlen/bp);
    185177
     178        /* initialize output */
     179        fvec_zeros(bt->phout);
    186180        for(i=0;i<bp;i++){
    187                 phout[i] = 0.;
    188181                for(k=0;k<kmax;k++){
    189                         phout[i] += dfrev[i+(uint_t)ROUND(bp*k)] * phwv[i];
    190                 }
    191         }
     182                        bt->phout->data[0][i] += bt->dfrev->data[0][i+(uint_t)ROUND(bp*k)];
     183                }
     184        }
     185        fvec_weight(bt->phout, bt->phwv);
    192186
    193187        /* find Rayleigh period */
     
    200194
    201195        /* reset output */
    202         for (i = 0; i < laglen; i++)
    203                 output->data[0][i] = 0.;
     196        fvec_zeros(output);
    204197
    205198        i = 1;
    206199        beat = bp - phase;
    207200        /* start counting the beats */
    208         if(beat >= 0)
    209         {
     201        if(beat >= 0) {
    210202                output->data[0][i] = beat;
    211203                i++;
    212204        }
    213205
    214         while( beat + bp <= step)
    215         {
     206        while( beat + bp <= step) {
    216207                beat += bp;
    217208                output->data[0][i] = beat;
     
    224215}
    225216
    226 uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp){
     217uint_t fvec_gettimesig(fvec_t * acf, uint_t acflen, uint_t gp){
    227218        sint_t k = 0;
    228219        smpl_t three_energy = 0., four_energy = 0.;
    229220        if( acflen > 6 * gp + 2 ){
    230221                for(k=-2;k<2;k++){
    231                         three_energy += acf[3*gp+k];
    232                         four_energy += acf[4*gp+k];
     222                        three_energy += acf->data[0][3*gp+k];
     223                        four_energy += acf->data[0][4*gp+k];
    233224                }
    234225        }
    235226        else{ /*Expanded to be more accurate in time sig estimation*/
    236227                for(k=-2;k<2;k++){
    237                         three_energy += acf[3*gp+k]+acf[6*gp+k];
    238                         four_energy += acf[4*gp+k]+acf[2*gp+k];
     228                        three_energy += acf->data[0][3*gp+k]+acf->data[0][6*gp+k];
     229                        four_energy += acf->data[0][4*gp+k]+acf->data[0][2*gp+k];
    239230                }
    240231        }
     
    255246        uint_t acflen   = bt->acf->length;
    256247        uint_t step     = bt->step;
    257         smpl_t * acf    = bt->acf->data[0];
    258         smpl_t * acfout = bt->acfout->data[0];
    259         smpl_t * gwv    = bt->gwv->data[0];
    260         smpl_t * phwv   = bt->phwv->data[0];
     248        fvec_t * acf    = bt->acf;
     249        fvec_t * acfout = bt->acfout;
    261250
    262251        if (gp) {
     
    266255                // gwv is, in first loop, definitely all zeros, but will have
    267256                // proper values when context dependent model is activated
    268                 for (i=0; i < bt->acfout->length; i++)
    269                        acfout[i] = 0.;
     257                fvec_zeros(acfout);
    270258                for(i=1;i<laglen-1;i++){
    271259                        for (a=1;a<=bt->timesig;a++){
    272260                                for(b=(1-a);b<a;b++){
    273                                         acfout[i] += acf[a*(i+1)+b-1]
    274                                                 * 1. * gwv[i];
     261                                        acfout->data[0][i] += acf->data[0][a*(i+1)+b-1];
    275262                                }
    276263                        }
    277264                }
    278                 gp = vec_quadint(bt->acfout, vec_max_elem(bt->acfout), 1);
     265                fvec_weight(acfout, bt->gwv);
     266                gp = vec_quadint(acfout, vec_max_elem(acfout), 1);
    279267                /*
    280268                while(gp<32) gp =gp*2;
     
    321309                bt->timesig = fvec_gettimesig(acf,acflen, gp);
    322310                for(j=0;j<laglen;j++)
    323                         gwv[j] = EXP(-.5*SQR((smpl_t)(j+1.-gp))/SQR(bt->g_var));
     311                        bt->gwv->data[0][j] = EXP(-.5*SQR((smpl_t)(j+1.-gp))/SQR(bt->g_var));
    324312                flagconst = 0;
    325313                bp = gp;
    326314                /* flat phase weighting */
    327                 for(j=0;j<2*laglen;j++)  {phwv[j] = 1.;}
     315                fvec_ones(bt->phwv);
    328316        } else if (bt->timesig) {
    329317                /* context dependant model */
     
    332320                if (step > bt->lastbeat) {
    333321                        for(j=0;j<2*laglen;j++)  {
    334                                 phwv[j] = EXP(-.5*SQR((smpl_t)(1.+j-step+bt->lastbeat))/(bp/8.));
     322                                bt->phwv->data[0][j] = EXP(-.5*SQR((smpl_t)(1.+j-step+bt->lastbeat))/(bp/8.));
    335323                        }
    336324                } else {
    337325                        //AUBIO_DBG("NOT using phase weighting as step is %d and lastbeat %d \n",
    338326                        //                step,bt->lastbeat);
    339                         for(j=0;j<2*laglen;j++)  {phwv[j] = 1.;}
     327                        fvec_ones(bt->phwv);
    340328                }
    341329        } else {
     
    343331                bp = rp;
    344332                /* flat phase weighting */
    345                 for(j=0;j<2*laglen;j++)  {phwv[j] = 1.;}
     333                fvec_ones(bt->phwv);
    346334        }
    347335
Note: See TracChangeset for help on using the changeset viewer.