Changeset 2ba3440


Ignore:
Timestamp:
Oct 8, 2009, 8:24:43 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
22d33e2
Parents:
f162cf9
Message:

src/pitch/pitchyin.{c,h}: add proper aubio_pitchyin_t object, clean and update prototypes, make multichannel

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyin.c

    rf162cf9 r2ba3440  
    3030#include "mathutils.h"
    3131#include "pitch/pitchyin.h"
     32
     33struct _aubio_pitchyin_t {
     34  fvec_t * yin;
     35  smpl_t tol;
     36};
     37
     38/** compute difference function
     39 
     40  \param input input signal
     41  \param yinbuf output buffer to store difference function (half shorter than input)
     42
     43*/
     44void aubio_pitchyin_diff(fvec_t * input, fvec_t * yinbuf);
     45
     46/** in place computation of the YIN cumulative normalised function
     47 
     48  \param yinbuf input signal (a square difference function), also used to store function
     49
     50*/
     51void aubio_pitchyin_getcum(fvec_t * yinbuf);
     52
     53/** detect pitch in a YIN function
     54 
     55  \param yinbuf input buffer as computed by aubio_pitchyin_getcum
     56
     57*/
     58uint_t aubio_pitchyin_getpitch(fvec_t *yinbuf);
     59
     60aubio_pitchyin_t * new_aubio_pitchyin (uint_t bufsize) {
     61  aubio_pitchyin_t * o = AUBIO_NEW(aubio_pitchyin_t);
     62  o->yin = new_fvec (bufsize/2, 1);
     63  o->tol = 0.15;
     64  return o;
     65}
     66
     67void del_aubio_pitchyin (aubio_pitchyin_t *o) {
     68  del_fvec(o->yin);
     69  AUBIO_FREE(o);
     70}
    3271
    3372/* outputs the difference function */
     
    89128
    90129/* all the above in one */
    91 smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t * yin, smpl_t tol){
    92   uint_t c=0,j,tau = 0;
     130void aubio_pitchyin_do(aubio_pitchyin_t *o, fvec_t * input, fvec_t * out){
     131  smpl_t tol = o->tol;
     132  fvec_t * yin = o->yin;
     133  uint_t c , j,tau = 0;
    93134  sint_t period;
    94135  smpl_t tmp = 0., tmp2 = 0.;
    95   yin->data[c][0] = 1.;
    96   for (tau=1;tau<yin->length;tau++)
    97   {
    98     yin->data[c][tau] = 0.;
    99     for (j=0;j<yin->length;j++)
     136  for (c = 0; c < input->channels; c++) {
     137    yin->data[c][0] = 1.;
     138    for (tau=1;tau<yin->length;tau++)
    100139    {
    101       tmp = input->data[c][j] - input->data[c][j+tau];
    102       yin->data[c][tau] += SQR(tmp);
     140      yin->data[c][tau] = 0.;
     141      for (j=0;j<yin->length;j++)
     142      {
     143        tmp = input->data[c][j] - input->data[c][j+tau];
     144        yin->data[c][tau] += SQR(tmp);
     145      }
     146      tmp2 += yin->data[c][tau];
     147      yin->data[c][tau] *= tau/tmp2;
     148      period = tau-3;
     149      if(tau > 4 && (yin->data[c][period] < tol) &&
     150          (yin->data[c][period] < yin->data[c][period+1])) {
     151        out->data[c][0] = fvec_quadint(yin,period,1);
     152        goto beach;
     153      }
    103154    }
    104     tmp2 += yin->data[c][tau];
    105     yin->data[c][tau] *= tau/tmp2;
    106     period = tau-3;
    107     if(tau > 4 && (yin->data[c][period] < tol) &&
    108         (yin->data[c][period] < yin->data[c][period+1])) {
    109       return fvec_quadint(yin,period,1);
    110     }
     155    out->data[c][0] = fvec_quadint(yin,fvec_min_elem(yin),1);
     156beach:
     157    continue;
    111158  }
    112   return fvec_quadint(yin,fvec_min_elem(yin),1);
    113159  //return 0;
    114160}
    115161
     162uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t *o, smpl_t tol) {
     163  o->tol = tol;
     164  return 0;
     165}
     166
     167smpl_t aubio_pitchyin_get_tolerance (aubio_pitchyin_t *o) {
     168  return o->tol;
     169}
  • src/pitch/pitchyin.h

    rf162cf9 r2ba3440  
    3838#endif
    3939
    40 /** compute difference function
     40/** pitch detection object */
     41typedef struct _aubio_pitchyin_t aubio_pitchyin_t;
     42
     43/** creation of the pitch detection object
     44 
     45  \param bufsize size of the input buffer to analyse
     46 
     47*/
     48aubio_pitchyin_t * new_aubio_pitchyin (uint_t bufsize);
     49
     50/** deletion of the pitch detection object
     51 
     52  \param p pitch detection object as returned by new_aubio_pitchyin()
     53 
     54*/
     55void del_aubio_pitchyin (aubio_pitchyin_t * o);
     56
     57/** execute pitch detection on an input buffer
     58 
     59  \param p pitch detection object as returned by new_aubio_pitchyin()
     60  \param input input signal window (length as specified at creation time)
     61  \param tol tolerance parameter for minima selection [default 0.85]
     62 
     63*/
     64void aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t *in, fvec_t *out);
     65
     66
     67/** set tolerance parameter for YIN algorithm
    4168 
    42   \param input input signal
    43   \param yinbuf output buffer to store difference function (half shorter than input)
    44 
    45 */
    46 void aubio_pitchyin_diff(fvec_t * input, fvec_t * yinbuf);
    47 
    48 /** in place computation of the YIN cumulative normalised function
    49  
    50   \param yinbuf input signal (a square difference function), also used to store function
    51 
    52 */
    53 void aubio_pitchyin_getcum(fvec_t * yinbuf);
    54 
    55 /** detect pitch in a YIN function
    56  
    57   \param yinbuf input buffer as computed by aubio_pitchyin_getcum
    58 
    59 */
    60 uint_t aubio_pitchyin_getpitch(fvec_t *yinbuf);
    61 
    62 /** fast implementation of the YIN algorithm
    63  
    64   \param input input signal
    65   \param yinbuf input buffer used to compute the YIN function
     69  \param o YIN pitch detection object
    6670  \param tol tolerance parameter for minima selection [default 0.15]
    6771
    6872*/
    69 smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yinbuf, smpl_t tol);
     73uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t *o, smpl_t tol);
     74
     75/** get tolerance parameter for YIN algorithm
     76 
     77  \param o YIN pitch detection object
     78  \return tolerance parameter for minima selection [default 0.15]
     79
     80*/
     81smpl_t aubio_pitchyin_get_tolerance (aubio_pitchyin_t *o);
    7082
    7183#ifdef __cplusplus
  • tests/src/test-pitchyin.c

    rf162cf9 r2ba3440  
    77        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
    88        fvec_t * out      = new_fvec (win_s/2, channels); /* input buffer */
     9        aubio_pitchyin_t *p = new_aubio_pitchyin (win_s);
    910        uint_t i = 0;
    1011
    1112        while (i < 10) {
    12           aubio_pitchyin_diff   (in,out);
    13           aubio_pitchyin_getcum (out);
    14           aubio_pitchyin_getpitch (out);
    15           aubio_pitchyin_getpitchfast (in,out,0.2);
     13          aubio_pitchyin_do (p, in,out);
    1614          i++;
    1715        };
Note: See TracChangeset for help on using the changeset viewer.