Changeset 3e48568


Ignore:
Timestamp:
Jul 30, 2017, 10:53:43 PM (7 years ago)
Author:
Eduard Müller <mueller.eduard@googlemail.com>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
2a4ce6d
Parents:
34ce715
Message:

yin pitch confidence tweaks

return pitch candidate search's confidence in yin algorithms and not the
global minimum, so that the confidence reflects the returned pitch value

Location:
src/pitch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyin.c

    r34ce715 r3e48568  
    3737  fvec_t *yin;
    3838  smpl_t tol;
    39   smpl_t confidence;
     39  uint_t peak_pos;
    4040};
    4141
     
    6868  o->yin = new_fvec (bufsize / 2);
    6969  o->tol = 0.15;
     70  o->peak_pos = 0;
    7071  return o;
    7172}
     
    157158    if (tau > 4 && (yin_data[period] < tol) &&
    158159        (yin_data[period] < yin_data[period + 1])) {
    159       out->data[0] = fvec_quadratic_peak_pos (yin, period);
    160       goto beach;
     160      o->peak_pos = (uint_t)period;
     161      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
     162      return;
    161163    }
    162164  }
    163   out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin));
    164 beach:
    165   return;
     165  o->peak_pos = (uint_t)fvec_min_elem (yin);
     166  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
    166167}
    167168
    168169smpl_t
    169170aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) {
    170   o->confidence = 1. - fvec_min (o->yin);
    171   return o->confidence;
     171  return 1. - o->yin->data[o->peak_pos];
    172172}
    173173
  • src/pitch/pitchyinfast.c

    r34ce715 r3e48568  
    3939  fvec_t *yin;
    4040  smpl_t tol;
    41   smpl_t confidence;
     41  uint_t peak_pos;
    4242  fvec_t *tmpdata;
    4343  fvec_t *sqdiff;
     
    6060  o->fft = new_aubio_fft (bufsize);
    6161  o->tol = 0.15;
     62  o->peak_pos = 0;
    6263  return o;
    6364}
     
    8687  uint_t W = o->yin->length; // B / 2
    8788  fvec_t tmp_slice, kernel_ptr;
    88   smpl_t *yin_data = yin->data;
    8989  uint_t tau;
    9090  sint_t period;
     
    143143    // compute square difference r_t(tau) = sqdiff - 2 * r_t_tau[W-1:-1]
    144144    for (tau = 0; tau < W; tau++) {
    145       yin_data[tau] = o->sqdiff->data[tau] - 2. * rt_of_tau->data[tau+W];
     145      yin->data[tau] = o->sqdiff->data[tau] - 2. * rt_of_tau->data[tau+W];
    146146    }
    147147  }
    148148
    149149  // now build yin and look for first minimum
    150   fvec_set_all(out, 0.);
    151   yin_data[0] = 1.;
     150  fvec_zeros(out);
     151  yin->data[0] = 1.;
    152152  for (tau = 1; tau < length; tau++) {
    153     tmp2 += yin_data[tau];
     153    tmp2 += yin->data[tau];
    154154    if (tmp2 != 0) {
    155155      yin->data[tau] *= tau / tmp2;
     
    158158    }
    159159    period = tau - 3;
    160     if (tau > 4 && (yin_data[period] < tol) &&
    161         (yin_data[period] < yin_data[period + 1])) {
    162       out->data[0] = fvec_quadratic_peak_pos (yin, period);
    163       goto beach;
     160    if (tau > 4 && (yin->data[period] < tol) &&
     161        (yin->data[period] < yin->data[period + 1])) {
     162      o->peak_pos = (uint_t)period;
     163      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
     164      return;
    164165    }
    165166  }
    166   out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin) );
    167 beach:
    168   return;
     167  // use global minimum
     168  o->peak_pos = (uint_t)fvec_min_elem (yin);
     169  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
    169170}
    170171
    171172smpl_t
    172173aubio_pitchyinfast_get_confidence (aubio_pitchyinfast_t * o) {
    173   o->confidence = 1. - fvec_min (o->yin);
    174   return o->confidence;
     174  return 1. - o->yin->data[o->peak_pos];
    175175}
    176176
  • src/pitch/pitchyinfft.c

    r34ce715 r3e48568  
    3737  fvec_t *yinfft;     /**< Yin function */
    3838  smpl_t tol;         /**< Yin tolerance */
    39   smpl_t confidence;  /**< confidence */
     39  uint_t peak_pos;    /**< currently selected peak pos*/
    4040  uint_t short_period; /** shortest period under which to check for octave error */
    4141};
     
    6868  p->yinfft = new_fvec (bufsize / 2 + 1);
    6969  p->tol = 0.85;
     70  p->peak_pos = 0;
    7071  p->win = new_aubio_window ("hanningz", bufsize);
    7172  p->weight = new_fvec (bufsize / 2 + 1);
     
    162163      halfperiod = FLOOR (tau / 2 + .5);
    163164      if (yin->data[halfperiod] < p->tol)
    164         output->data[0] = fvec_quadratic_peak_pos (yin, halfperiod);
     165        p->peak_pos = halfperiod;
    165166      else
    166         output->data[0] = fvec_quadratic_peak_pos (yin, tau);
     167        p->peak_pos = tau;
     168      output->data[0] = fvec_quadratic_peak_pos (yin, p->peak_pos);
    167169    }
    168170  } else {
     171    p->peak_pos = 0;
    169172    output->data[0] = 0.;
    170173  }
     
    186189smpl_t
    187190aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o) {
    188   o->confidence = 1. - fvec_min (o->yinfft);
    189   return o->confidence;
     191  return 1. - o->yinfft->data[o->peak_pos];
    190192}
    191193
Note: See TracChangeset for help on using the changeset viewer.