Merge branch 'fix/awhitening'
[aubio.git] / src / pitch / pitchspecacf.c
index 7b25a22..170cfa3 100644 (file)
@@ -42,21 +42,26 @@ aubio_pitchspecacf_t *
 new_aubio_pitchspecacf (uint_t bufsize)
 {
   aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t);
+  p->fft = new_aubio_fft (bufsize);
+  if (!p->fft) goto beach;
   p->win = new_aubio_window ("hanningz", bufsize);
   p->winput = new_fvec (bufsize);
-  p->fft = new_aubio_fft (bufsize);
   p->fftout = new_fvec (bufsize);
   p->sqrmag = new_fvec (bufsize);
   p->acf = new_fvec (bufsize / 2 + 1);
   p->tol = 1.;
   p->confidence = 0.;
   return p;
+
+beach:
+  AUBIO_FREE(p);
+  return NULL;
 }
 
 void
-aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
+aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, const fvec_t * input, fvec_t * output)
 {
-  uint_t l;
+  uint_t l, tau;
   fvec_t *fftout = p->fftout;
   // window the input
   for (l = 0; l < input->length; l++) {
@@ -74,7 +79,7 @@ aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output
     p->acf->data[l] = fftout->data[l];
   }
   // get the minimum
-  uint_t tau = fvec_min_elem (p->acf);
+  tau = fvec_min_elem (p->acf);
   // get the interpolated minimum
   output->data[0] = fvec_quadratic_peak_pos (p->acf, tau) * 2.;
 }
@@ -87,11 +92,12 @@ del_aubio_pitchspecacf (aubio_pitchspecacf_t * p)
   del_aubio_fft (p->fft);
   del_fvec (p->sqrmag);
   del_fvec (p->fftout);
+  del_fvec (p->acf);
   AUBIO_FREE (p);
 }
 
 smpl_t
-aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
+aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o) {
   // no confidence for now
   return o->confidence;
 }
@@ -104,7 +110,7 @@ aubio_pitchspecacf_set_tolerance (aubio_pitchspecacf_t * p, smpl_t tol)
 }
 
 smpl_t
-aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)
+aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * p)
 {
   return p->tol;
 }