Ignore:
Timestamp:
Feb 2, 2017, 2:29:43 AM (4 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
yinfft+
Children:
5bdbb83
Parents:
09558b8
Message:

src/pitch/pitchyinfft.c: lookahead only, stop at valley low, improve comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r09558b8 r422a2a9  
    115115  fvec_t *yin = p->yinfft;
    116116  smpl_t tmp = 0., sum = 0.;
    117   uint_t startbin = 0, endbin = 0, before = 0, after = 0;
     117  // empirically derived peak width to look for
     118  uint_t lookafter = yin->length / 128, endbin;
    118119
    119120  // window the input
     
    159160  }
    160161
    161   // choose lowest confident candidate first, to avoid choosing harmonics
     162  // choose first confident candidate, to avoid choosing lower harmonics
    162163  tau = 0;
    163164  for (l = 1; l < yin->length; l++) {
    164165    // is this candidate "roughly" as good as the lowest one?
     166    // the constant 0.1 is empirically derived
    165167    if (ABS (yin->data[l] - tmp) < 0.1) {
    166168      tau = l;
     
    168170    }
    169171  }
    170   // find local min around current pick to sharpen the results
    171   before = 2, after = 5;
    172   // for low frequency, the peak may be large, we use a larger after
    173   if (tau > yin->length/2) { before = 1; after = 20; }
    174   startbin = tau > before ? tau - before : 0;
    175   endbin = tau < yin->length - 1 - after ? tau + after : yin->length - 1;
     172  // find local min around current peak to sharpen the results
     173  endbin = tau + lookafter < yin->length - 1 ? tau + lookafter : yin->length - 1;
    176174  tmp = yin->data[tau];
    177   for (l = startbin; l < endbin; l++) {
     175  for (l = tau; l < endbin; l++) {
    178176    if (yin->data[l] < tmp ) {
    179177      tmp = yin->data[l];
    180178      tau = l;
     179    }
     180    // stop as soon as we start going up again
     181    if (yin->data[l] > tmp && l > tau) {
     182      break;
    181183    }
    182184  }
Note: See TracChangeset for help on using the changeset viewer.