aubio_pitchyinfft_t *p = AUBIO_NEW (aubio_pitchyinfft_t);
p->winput = new_fvec (bufsize);
p->fft = new_aubio_fft (bufsize);
+ if (!p->fft) goto beach;
p->fftout = new_fvec (bufsize);
p->sqrmag = new_fvec (bufsize);
p->yinfft = new_fvec (bufsize / 2 + 1);
// check for octave errors above 1300 Hz
p->short_period = (uint_t)ROUND(samplerate / 1300.);
return p;
+
+beach:
+ if (p->winput) del_fvec(p->winput);
+ AUBIO_FREE(p);
+ return NULL;
}
void
-aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
+aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, const fvec_t * input, fvec_t * output)
{
uint_t tau, l;
uint_t length = p->fftout->length;
fvec_t *yin = p->yinfft;
smpl_t tmp = 0., sum = 0.;
// window the input
- for (l = 0; l < input->length; l++) {
- p->winput->data[l] = p->win->data[l] * input->data[l];
- }
+ fvec_weighted_copy(input, p->win, p->winput);
// get the real / imag parts of its fft
aubio_fft_do_complex (p->fft, p->winput, fftout);
// get the squared magnitude spectrum, applying some weight
yin->data[tau] = sum - fftout->data[tau];
// and the cumulative mean normalized difference function
tmp += yin->data[tau];
- yin->data[tau] *= tau / tmp;
+ if (tmp != 0) {
+ yin->data[tau] *= tau / tmp;
+ } else {
+ yin->data[tau] = 1.;
+ }
}
// find best candidates
tau = fvec_min_elem (yin);