Changeset b4eadf0


Ignore:
Timestamp:
Feb 1, 2017, 10:53:54 PM (4 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
yinfft+
Children:
a7b14a6
Parents:
8f0db97
git-author:
Eduard Müller <mueller.eduard@googlemail.com> (01/13/17 16:33:37)
git-committer:
Paul Brossier <piem@piem.org> (02/01/17 22:53:54)
Message:

new yinfft f0 "candidate selection" strategy

Signed-off-by: Paul Brossier <piem@piem.org>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r8f0db97 rb4eadf0  
    3838  smpl_t tol;         /**< Yin tolerance */
    3939  smpl_t confidence;  /**< confidence */
    40   uint_t short_period; /** shortest period under which to check for octave error */
     40  uint_t samplerate;  /**< samplerate we got initialized with */
    4141};
    4242
     
    7070  p->win = new_aubio_window ("hanningz", bufsize);
    7171  p->weight = new_fvec (bufsize / 2 + 1);
     72  p->samplerate = samplerate;
    7273  for (i = 0; i < p->weight->length; i++) {
    7374    freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate;
     
    9495    //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i]));
    9596  }
    96   // check for octave errors above 1300 Hz
    97   p->short_period = (uint_t)ROUND(samplerate / 1300.);
     97
     98  // disable weighting
     99  fvec_set_all (p->weight, 1.0);
     100
    98101  return p;
    99102
     
    113116  fvec_t *yin = p->yinfft;
    114117  smpl_t tmp = 0., sum = 0.;
     118
    115119  // window the input
    116120  fvec_weighted_copy(input, p->win, p->winput);
     
    146150    }
    147151  }
    148   // find best candidates
    149   tau = fvec_min_elem (yin);
    150   if (yin->data[tau] < p->tol) {
    151     // no interpolation, directly return the period as an integer
    152     //output->data[0] = tau;
    153     //return;
    154 
    155     // 3 point quadratic interpolation
    156     //return fvec_quadratic_peak_pos (yin,tau,1);
    157     /* additional check for (unlikely) octave doubling in higher frequencies */
    158     if (tau > p->short_period) {
    159       output->data[0] = fvec_quadratic_peak_pos (yin, tau);
    160     } else {
    161       /* should compare the minimum value of each interpolated peaks */
    162       halfperiod = FLOOR (tau / 2 + .5);
    163       if (yin->data[halfperiod] < p->tol)
    164         output->data[0] = fvec_quadratic_peak_pos (yin, halfperiod);
    165       else
    166         output->data[0] = fvec_quadratic_peak_pos (yin, tau);
    167     }
    168   } else {
     152
     153  // calc min available confidence first
     154  tmp = fvec_min(yin);
     155  if (tmp > p->tol) {
     156    // give up - got no confident candidate at all
    169157    output->data[0] = 0.;
    170   }
     158    return;
     159  }
     160
     161  // choose lowest confident candidate first, to avoid choosing harmonics
     162  tau = 0;
     163  for (l = 1; l < yin->length; l++) {
     164    // is this candidate "roughly" as good as the lowest one?
     165    if (ABS (yin->data[l] - tmp) < 0.1) {
     166      tau = l;
     167      break;
     168    }
     169  }
     170  // find local min around current pick to sharpen the results
     171  const uint_t LOCAL_NOTE_SEEK_RANGE = 1;
     172  const smpl_t note = aubio_bintomidi (tau, p->samplerate, p->fftout->length);
     173  const uint_t startbin = MAX (0, (uint_t)aubio_miditobin (note - LOCAL_NOTE_SEEK_RANGE,
     174    p->samplerate, p->fftout->length));
     175  const uint_t endbin = MIN (yin->length, (uint_t)(aubio_miditobin (note + LOCAL_NOTE_SEEK_RANGE,
     176    p->samplerate, p->fftout->length) + 0.5));
     177  tmp = yin->data[tau];
     178  for (l = startbin; l < endbin; l++) {
     179    if (yin->data[l] < tmp ) {
     180      tmp = yin->data[l];
     181      tau = l;
     182    }
     183  }
     184  output->data[0] = fvec_quadratic_peak_pos(yin, tau);
    171185}
    172186
Note: See TracChangeset for help on using the changeset viewer.