Changeset 7a6cbbe


Ignore:
Timestamp:
Oct 8, 2009, 8:51:06 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:
05773a2c
Parents:
22d33e2
Message:

src/pitch/pitchdetection.{c,h}: clean and update prototypes, sync with latest pitch objects

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchdetection.c

    r22d33e2 r7a6cbbe  
    3232#include "pitch/pitchdetection.h"
    3333
    34 typedef smpl_t (*aubio_pitchdetection_func_t)
    35   (aubio_pitchdetection_t *p, fvec_t * ibuf);
     34typedef void (*aubio_pitchdetection_func_t)
     35  (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf);
    3636typedef smpl_t (*aubio_pitchdetection_conv_t)
    3737  (smpl_t value, uint_t srate, uint_t bufsize);
     
    3939void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf);
    4040
    41 smpl_t aubio_pitchdetection_mcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf);
    42 smpl_t aubio_pitchdetection_yin     (aubio_pitchdetection_t *p, fvec_t *ibuf);
    43 smpl_t aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf);
    44 smpl_t aubio_pitchdetection_fcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf);
    45 smpl_t aubio_pitchdetection_yinfft  (aubio_pitchdetection_t *p, fvec_t *ibuf);
     41void aubio_pitchdetection_mcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
     42void aubio_pitchdetection_yin     (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
     43void aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
     44void aubio_pitchdetection_fcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
     45void aubio_pitchdetection_yinfft  (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
    4646
    4747/** generic pitch detection structure */
     
    5555  aubio_pitchschmitt_t * schmitt; /**< schmitt object */
    5656  aubio_pitchyinfft_t * yinfft;   /**< yinfft object */
     57  aubio_pitchyin_t * yin;   /**< yinfft object */
    5758  aubio_filter_t * filter;        /**< filter */
    5859  aubio_pvoc_t * pv;              /**< phase vocoder for mcomb */
    5960  cvec_t * fftgrain;              /**< spectral frame for mcomb */
    6061  fvec_t * buf;                   /**< temporary buffer for yin */
    61   fvec_t * yin;                   /**< yin function */
    62   smpl_t yinthres;                /**< yin peak picking threshold parameter */
    6362  aubio_pitchdetection_func_t callback; /**< pointer to current pitch detection method */
    6463  aubio_pitchdetection_conv_t freqconv; /**< pointer to current pitch conversion method */
     
    9796    case aubio_pitch_yin:
    9897      p->buf      = new_fvec(bufsize,channels);
    99       p->yin      = new_fvec(bufsize/2,channels);
     98      p->yin      = new_aubio_pitchyin(bufsize);
    10099      p->callback = aubio_pitchdetection_yin;
    101       p->yinthres = 0.15;
     100      aubio_pitchyin_set_tolerance (p->yin, 0.15);
    102101      break;
    103102    case aubio_pitch_mcomb:
    104103      p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
    105104      p->fftgrain = new_cvec(bufsize, channels);
    106       p->mcomb    = new_aubio_pitchmcomb(bufsize,hopsize,channels,samplerate);
     105      p->mcomb    = new_aubio_pitchmcomb(bufsize,hopsize,channels);
    107106      p->filter   = new_aubio_filter_c_weighting (samplerate, channels);
    108107      p->callback = aubio_pitchdetection_mcomb;
     
    110109    case aubio_pitch_fcomb:
    111110      p->buf      = new_fvec(bufsize,channels);
    112       p->fcomb    = new_aubio_pitchfcomb(bufsize,hopsize,samplerate);
     111      p->fcomb    = new_aubio_pitchfcomb(bufsize,hopsize,channels);
    113112      p->callback = aubio_pitchdetection_fcomb;
    114113      break;
    115114    case aubio_pitch_schmitt:
    116115      p->buf      = new_fvec(bufsize,channels);
    117       p->schmitt  = new_aubio_pitchschmitt(bufsize,samplerate);
     116      p->schmitt  = new_aubio_pitchschmitt(bufsize);
    118117      p->callback = aubio_pitchdetection_schmitt;
    119118      break;
     
    122121      p->yinfft   = new_aubio_pitchyinfft(bufsize);
    123122      p->callback = aubio_pitchdetection_yinfft;
    124       p->yinthres = 0.85;
     123      aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85);
    125124      break;
    126125    default:
     
    150149  switch(p->type) {
    151150    case aubio_pitch_yin:
    152       del_fvec(p->yin);
    153       del_fvec(p->buf);
     151      del_fvec(p->buf);
     152      del_aubio_pitchyin(p->yin);
    154153      break;
    155154    case aubio_pitch_mcomb:
     
    192191}
    193192
    194 void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres) {
    195   p->yinthres = thres;
    196 }
    197 
    198 smpl_t aubio_pitchdetection_do (aubio_pitchdetection_t *p, fvec_t * ibuf) {
    199   return p->freqconv(p->callback(p,ibuf),p->srate,p->bufsize);
    200 }
    201 
    202 smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) {
    203   smpl_t pitch = 0.;
     193void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol) {
     194  switch(p->type) {
     195    case aubio_pitch_yin:
     196      aubio_pitchyin_set_tolerance (p->yin, tol);
     197      break;
     198    case aubio_pitch_yinfft:
     199      aubio_pitchyinfft_set_tolerance (p->yinfft, tol);
     200      break;
     201    default:
     202      break;
     203  }
     204}
     205
     206void aubio_pitchdetection_do (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf) {
     207  uint_t i;
     208  p->callback(p, ibuf, obuf);
     209  for (i = 0; i < obuf->channels; i++) {
     210    p->freqconv(obuf->data[i][0],p->srate,p->bufsize);
     211  }
     212}
     213
     214void aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) {
     215  uint_t i;
    204216  aubio_filter_do(p->filter,ibuf);
    205217  aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
    206   pitch = aubio_pitchmcomb_do(p->mcomb,p->fftgrain);
    207   /** \bug should move the >0 check within aubio_bintofreq */
    208   if (pitch>0.) {
    209     pitch = aubio_bintofreq(pitch,p->srate,p->bufsize);
    210   } else {
    211     pitch = 0.;
    212   }
    213   return pitch;
    214 }
    215 
    216 smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) {
     218  aubio_pitchmcomb_do(p->mcomb,p->fftgrain, obuf);
     219  for (i = 0; i < obuf->channels; i++) {
     220    obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
     221  }
     222}
     223
     224void aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) {
    217225  smpl_t pitch = 0.;
    218   aubio_pitchdetection_slideblock(p,ibuf);
    219   pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, p->yinthres);
    220   if (pitch>0) {
    221     pitch = p->srate/(pitch+0.);
    222   } else {
    223     pitch = 0.;
    224   }
    225   return pitch;
    226 }
    227 
    228 
    229 smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf){
     226  uint_t i;
     227  aubio_pitchdetection_slideblock(p,ibuf);
     228  aubio_pitchyin_do(p->yin,p->buf, obuf);
     229  for (i = 0; i < obuf->channels; i++) {
     230    pitch = obuf->data[i][0];
     231    if (pitch>0) {
     232      pitch = p->srate/(pitch+0.);
     233    } else {
     234      pitch = 0.;
     235    }
     236    obuf->data[i][0] = pitch;
     237  }
     238}
     239
     240
     241void aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf){
    230242  smpl_t pitch = 0.;
    231   aubio_pitchdetection_slideblock(p,ibuf);
    232   pitch = aubio_pitchyinfft_do(p->yinfft,p->buf,p->yinthres);
    233   if (pitch>0) {
    234     pitch = p->srate/(pitch+0.);
    235   } else {
    236     pitch = 0.;
    237   }
    238   return pitch;
    239 }
    240 
    241 smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){
    242   aubio_pitchdetection_slideblock(p,ibuf);
    243   return aubio_pitchfcomb_do(p->fcomb,p->buf);
    244 }
    245 
    246 smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){
    247   aubio_pitchdetection_slideblock(p,ibuf);
    248   return aubio_pitchschmitt_do(p->schmitt,p->buf);
    249 }
     243  uint_t i;
     244  aubio_pitchdetection_slideblock(p,ibuf);
     245  aubio_pitchyinfft_do(p->yinfft,p->buf,obuf);
     246  for (i = 0; i < obuf->channels; i++) {
     247    pitch = obuf->data[i][0];
     248    if (pitch>0) {
     249      pitch = p->srate/(pitch+0.);
     250    } else {
     251      pitch = 0.;
     252    }
     253    obuf->data[i][0] = pitch;
     254  }
     255}
     256
     257void aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * out){
     258  uint_t i;
     259  aubio_pitchdetection_slideblock(p,ibuf);
     260  aubio_pitchfcomb_do(p->fcomb,p->buf, out);
     261  for (i = 0; i < out->channels; i++) {
     262    out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
     263  }
     264}
     265
     266void aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *out){
     267  smpl_t period, pitch = 0.;
     268  uint_t i;
     269  aubio_pitchdetection_slideblock(p,ibuf);
     270  aubio_pitchschmitt_do(p->schmitt,p->buf, out);
     271  for (i = 0; i < out->channels; i++) {
     272    period = out->data[i][0];
     273    if (period>0) {
     274      pitch = p->srate/period;
     275    } else {
     276      pitch = 0.;
     277    }
     278    out->data[i][0] = pitch;
     279  }
     280}
  • src/pitch/pitchdetection.h

    r22d33e2 r7a6cbbe  
    5959
    6060*/
    61 smpl_t aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf);
     61void aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf, fvec_t * obuf);
    6262
    6363/** change yin or yinfft tolerance threshold
     
    6666
    6767*/
    68 void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres);
     68void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol);
    6969
    7070/** deletion of the pitch detection object
  • tests/src/test-pitchdetection.c

    r22d33e2 r7a6cbbe  
    1010        aubio_pitchdetection_type type = aubio_pitch_yinfft;
    1111        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
     12        fvec_t * out       = new_fvec (1, channels); /* input buffer */
    1213        aubio_pitchdetection_t * o  = new_aubio_pitchdetection(
    1314          win_s, hop_s, channels, samplerate, type, mode
     
    1516        uint_t i = 0;
    1617
    17         while (i < 1000) {
    18           aubio_pitchdetection_do (o,in);
     18        while (i < 100) {
     19          aubio_pitchdetection_do (o,in, out);
    1920          i++;
    2021        };
Note: See TracChangeset for help on using the changeset viewer.