Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyin.c

    r5b46bc3 r633400d  
    3737  fvec_t *yin;
    3838  smpl_t tol;
    39   smpl_t confidence;
     39  uint_t peak_pos;
    4040};
    4141
     42#if 0
    4243/** compute difference function
    4344
     
    6162*/
    6263uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf);
     64#endif
    6365
    6466aubio_pitchyin_t *
     
    6870  o->yin = new_fvec (bufsize / 2);
    6971  o->tol = 0.15;
     72  o->peak_pos = 0;
    7073  return o;
    7174}
     
    7881}
    7982
     83#if 0
    8084/* outputs the difference function */
    8185void
     
    127131  return 0;
    128132}
    129 
     133#endif
    130134
    131135/* all the above in one */
     
    133137aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out)
    134138{
    135   smpl_t tol = o->tol;
    136   fvec_t *yin = o->yin;
    137   uint_t j, tau = 0;
     139  const smpl_t tol = o->tol;
     140  fvec_t* yin = o->yin;
     141  const smpl_t *input_data = input->data;
     142  const uint_t length = yin->length;
     143  smpl_t *yin_data = yin->data;
     144  uint_t j, tau;
    138145  sint_t period;
    139   smpl_t tmp = 0., tmp2 = 0.;
    140   yin->data[0] = 1.;
    141   for (tau = 1; tau < yin->length; tau++) {
    142     yin->data[tau] = 0.;
    143     for (j = 0; j < yin->length; j++) {
    144       tmp = input->data[j] - input->data[j + tau];
    145       yin->data[tau] += SQR (tmp);
     146  smpl_t tmp, tmp2 = 0.;
     147
     148  yin_data[0] = 1.;
     149  for (tau = 1; tau < length; tau++) {
     150    yin_data[tau] = 0.;
     151    for (j = 0; j < length; j++) {
     152      tmp = input_data[j] - input_data[j + tau];
     153      yin_data[tau] += SQR (tmp);
    146154    }
    147     tmp2 += yin->data[tau];
     155    tmp2 += yin_data[tau];
    148156    if (tmp2 != 0) {
    149157      yin->data[tau] *= tau / tmp2;
     
    152160    }
    153161    period = tau - 3;
    154     if (tau > 4 && (yin->data[period] < tol) &&
    155         (yin->data[period] < yin->data[period + 1])) {
    156       out->data[0] = fvec_quadratic_peak_pos (yin, period);
    157       goto beach;
     162    if (tau > 4 && (yin_data[period] < tol) &&
     163        (yin_data[period] < yin_data[period + 1])) {
     164      o->peak_pos = (uint_t)period;
     165      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
     166      return;
    158167    }
    159168  }
    160   out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin));
    161 beach:
    162   return;
     169  o->peak_pos = (uint_t)fvec_min_elem (yin);
     170  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
    163171}
    164172
    165173smpl_t
    166174aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) {
    167   o->confidence = 1. - fvec_min (o->yin);
    168   return o->confidence;
     175  return 1. - o->yin->data[o->peak_pos];
    169176}
    170177
Note: See TracChangeset for help on using the changeset viewer.