Changes in / [5bdbb83:f98063b]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r5bdbb83 rf98063b  
    3838  smpl_t tol;         /**< Yin tolerance */
    3939  smpl_t confidence;  /**< confidence */
    40   uint_t samplerate;  /**< samplerate we got initialized with */
     40  uint_t short_period; /** shortest period under which to check for octave error */
    4141};
    4242
     
    7070  p->win = new_aubio_window ("hanningz", bufsize);
    7171  p->weight = new_fvec (bufsize / 2 + 1);
    72   p->samplerate = samplerate;
    7372  for (i = 0; i < p->weight->length; i++) {
    7473    freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate;
     
    9594    //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i]));
    9695  }
    97 
    98   // disable weighting
    99   fvec_set_all (p->weight, 1.0);
    100 
     96  // check for octave errors above 1300 Hz
     97  p->short_period = (uint_t)ROUND(samplerate / 1300.);
    10198  return p;
    10299
     
    112109  uint_t tau, l;
    113110  uint_t length = p->fftout->length;
     111  uint_t halfperiod;
    114112  fvec_t *fftout = p->fftout;
    115113  fvec_t *yin = p->yinfft;
    116114  smpl_t tmp = 0., sum = 0.;
    117   // empirically derived peak width to look for
    118   uint_t lookafter = yin->length / 128, endbin;
    119 
    120115  // window the input
    121116  fvec_weighted_copy(input, p->win, p->winput);
     
    151146    }
    152147  }
    153 
    154   // calc min available confidence first
    155   tmp = fvec_min(yin);
    156   if (tmp > p->tol) {
    157     // give up - got no confident candidate at all
     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 {
    158169    output->data[0] = 0.;
    159     return;
    160   }
    161 
    162   // choose first confident candidate, to avoid choosing lower harmonics
    163   tau = 0;
    164   for (l = 1; l < yin->length; l++) {
    165     // is this candidate "roughly" as good as the lowest one?
    166     // the constant 0.1 is empirically derived
    167     if (ABS (yin->data[l] - tmp) < 0.1) {
    168       tau = l;
    169       break;
    170     }
    171   }
    172   // find local min around current peak to sharpen the results
    173   endbin = tau + lookafter < yin->length - 1 ? tau + lookafter : yin->length - 1;
    174   tmp = yin->data[tau];
    175   for (l = tau; l < endbin; l++) {
    176     if (yin->data[l] < tmp ) {
    177       tmp = yin->data[l];
    178       tau = l;
    179     }
    180     // stop as soon as we start going up again
    181     if (yin->data[l] > tmp && l > tau) {
    182       break;
    183     }
    184   }
    185   output->data[0] = fvec_quadratic_peak_pos(yin, tau);
     170  }
    186171}
    187172
Note: See TracChangeset for help on using the changeset viewer.