Changeset 22d33e2


Ignore:
Timestamp:
Oct 8, 2009, 8:49:10 PM (12 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, master, pitchshift, sampler, timestretch, yinfft+
Children:
7a6cbbe
Parents:
2ba3440
Message:

src/pitch/pitchyinfft.{c,h}: add get/set for tolerance, clean and update prototypes, make multichannel

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r2ba3440 r22d33e2  
    3434  aubio_fft_t * fft;  /**< fft object to compute square difference function */
    3535  fvec_t * yinfft;    /**< Yin function */
     36  smpl_t tol;         /**< Yin tolerance */
    3637};
    3738
     
    5556  p->res    = new_cvec(bufsize,1);
    5657  p->yinfft = new_fvec(bufsize/2+1,1);
     58  p->tol    = 0.85;
    5759  p->win    = new_aubio_window(bufsize, aubio_win_hanningz);
    5860  p->weight      = new_fvec(bufsize/2+1,1);
     
    8890}
    8991
    90 smpl_t aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, smpl_t tol) {
    91   uint_t tau, l = 0;
     92void aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) {
     93  uint_t i, tau, l;
    9294  uint_t halfperiod;
    93   smpl_t tmp = 0, sum = 0;
     95  smpl_t tmp, sum;
    9496  cvec_t * res = (cvec_t *)p->res;
    9597  fvec_t * yin = (fvec_t *)p->yinfft;
     98  for (i=0; i < input->channels; i++){
     99  l = 0; tmp = 0.; sum = 0.;
    96100  for (l=0; l < input->length; l++){
    97     p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
     101    p->winput->data[0][l] = p->win->data[0][l] * input->data[i][l];
    98102  }
    99103  aubio_fft_do(p->fft,p->winput,p->fftout);
     
    121125  }
    122126  tau = fvec_min_elem(yin);
    123   if (yin->data[0][tau] < tol) {
     127  if (yin->data[0][tau] < p->tol) {
    124128    /* no interpolation */
    125129    //return tau;
     
    128132    /* additional check for (unlikely) octave doubling in higher frequencies */
    129133    if (tau>35) {
    130       return fvec_quadint(yin,tau,1);
     134      output->data[i][0] = fvec_quadint(yin,tau,1);
    131135    } else {
    132136      /* should compare the minimum value of each interpolated peaks */
    133137      halfperiod = FLOOR(tau/2+.5);
    134       if (yin->data[0][halfperiod] < tol)
    135         return fvec_quadint(yin,halfperiod,1);
     138      if (yin->data[0][halfperiod] < p->tol)
     139        output->data[i][0] = fvec_quadint(yin,halfperiod,1);
    136140      else
    137         return fvec_quadint(yin,tau,1);
     141        output->data[i][0] = fvec_quadint(yin,tau,1);
    138142    }
    139   } else
    140     return 0.;
     143  } else {
     144    output->data[i][0] = 0.;
     145  }
     146  }
    141147}
    142148
     
    152158  AUBIO_FREE(p);
    153159}
     160
     161uint_t aubio_pitchyinfft_set_tolerance (aubio_pitchyinfft_t * p, smpl_t tol) {
     162  p->tol = tol;
     163  return 0;
     164}
     165
     166smpl_t aubio_pitchyinfft_get_tolerance (aubio_pitchyinfft_t * p) {
     167  return p->tol;
     168}
  • src/pitch/pitchyinfft.h

    r2ba3440 r22d33e2  
    4646  \param p pitch detection object as returned by new_aubio_pitchyinfft
    4747  \param input input signal window (length as specified at creation time)
    48   \param tol tolerance parameter for minima selection [default 0.85]
     48  \param output pitch period candidates, in samples
    4949 
    5050*/
    51 smpl_t aubio_pitchyinfft_do (aubio_pitchyinfft_t *p, fvec_t * input, smpl_t tol);
     51void aubio_pitchyinfft_do (aubio_pitchyinfft_t *p, fvec_t * input, fvec_t * output);
    5252/** creation of the pitch detection object
    5353 
     
    6363void del_aubio_pitchyinfft (aubio_pitchyinfft_t *p);
    6464
     65/** get tolerance parameter for YIN algorithm
     66 
     67  \param o YIN pitch detection object
     68
     69  \return tolerance parameter for minima selection [default 0.15]
     70
     71*/
     72smpl_t aubio_pitchyinfft_get_tolerance (aubio_pitchyinfft_t * p);
     73
     74/** set tolerance parameter for YIN algorithm
     75 
     76  \param o YIN pitch detection object
     77  \param tol tolerance parameter for minima selection [default 0.15]
     78
     79*/
     80uint_t aubio_pitchyinfft_set_tolerance (aubio_pitchyinfft_t * p, smpl_t tol);
     81
    6582#ifdef __cplusplus
    6683}
  • tests/src/test-pitchyinfft.c

    r2ba3440 r22d33e2  
    66        uint_t channels   = 1;                          /* number of channel */
    77        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     8        fvec_t * out      = new_fvec (1, channels); /* output pitch periods */
    89        aubio_pitchyinfft_t * o  = new_aubio_pitchyinfft(win_s);
     10        aubio_pitchyinfft_set_tolerance (o, 0.2);
    911        uint_t i = 0;
    1012
    1113        while (i < 10) {
    12           aubio_pitchyinfft_do (o,in,0.2);
     14          aubio_pitchyinfft_do (o,in,out);
    1315          i++;
    1416        };
Note: See TracChangeset for help on using the changeset viewer.