shithub: aubio

Download patch

ref: acd97d1038823180179882ebb3d3dc72da0fd3e3
parent: 69c39ca249f1a1c6f5006c8c8d218876751e4040
author: Paul Brossier <piem@piem.org>
date: Tue Oct 15 18:57:38 EDT 2013

src/mathutils.{c,h}: remove fvec_quadint, use fvec_quadratic_peak_pos

--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -367,20 +367,9 @@
   }
 }
 
-smpl_t fvec_quadint (fvec_t * x, uint_t pos) {
-  smpl_t s0, s1, s2;
-  uint_t x0 = (pos < 1) ? pos : pos - 1;
-  uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos;
-  if (x0 == pos) return (x->data[pos] <= x->data[x2]) ? pos : x2;
-  if (x2 == pos) return (x->data[pos] <= x->data[x0]) ? pos : x0;
-  s0 = x->data[x0];
-  s1 = x->data[pos];
-  s2 = x->data[x2];
-  return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0);
-}
-
 smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) {
   smpl_t s0, s1, s2;
+  if (pos == 0 || pos == x->length - 1) return pos;
   uint_t x0 = (pos < 1) ? pos : pos - 1;
   uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos;
   if (x0 == pos) return (x->data[pos] <= x->data[x2]) ? pos : x2;
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -231,9 +231,6 @@
 */
 smpl_t fvec_median (fvec_t * v);
 
-/** finds exact peak index by quadratic interpolation*/
-smpl_t fvec_quadint (fvec_t * x, uint_t pos);
-
 /** finds exact peak index by quadratic interpolation
 
   See [Quadratic Interpolation of Spectral
--- a/src/onset/peakpicker.c
+++ b/src/onset/peakpicker.c
@@ -124,7 +124,7 @@
   onset_peek->data[2] = thresholded->data[0];
   out->data[0] = (p->pickerfn) (onset_peek, 1);
   if (out->data[0]) {
-    out->data[0] = fvec_quadint (onset_peek, 1);
+    out->data[0] = fvec_quadratic_peak_pos (onset_peek, 1);
   }
 }
 
--- a/src/tempo/beattracking.c
+++ b/src/tempo/beattracking.c
@@ -170,7 +170,7 @@
 
   /* find non-zero Rayleigh period */
   maxindex = fvec_max_elem (bt->acfout);
-  bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex) : 1;
+  bt->rp = maxindex ? fvec_quadratic_peak_pos (bt->acfout, maxindex) : 1;
   //rp = (maxindex==127) ? 43 : maxindex; //rayparam
   bt->rp = (maxindex == bt->acfout->length - 1) ? bt->rayparam : maxindex;      //rayparam
 
@@ -203,7 +203,7 @@
 #endif /* AUBIO_BEAT_WARNINGS */
     phase = step - bt->lastbeat;
   } else {
-    phase = fvec_quadint (bt->phout, maxindex);
+    phase = fvec_quadratic_peak_pos (bt->phout, maxindex);
   }
   /* take back one frame delay */
   phase += 1.;
@@ -305,7 +305,7 @@
       }
     }
     fvec_weight (acfout, bt->gwv);
-    gp = fvec_quadint (acfout, fvec_max_elem (acfout));
+    gp = fvec_quadratic_peak_pos (acfout, fvec_max_elem (acfout));
     /*
        while(gp<32) gp =gp*2;
        while(gp>64) gp = gp/2;
@@ -408,8 +408,8 @@
 smpl_t
 aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
 {
-  if (bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
-    return 5168. / fvec_quadint (bt->acfout, bt->bp);
+  if (bt->bp != 0 && bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
+    return 5168. / fvec_quadratic_peak_pos (bt->acfout, bt->bp);
   } else {
     return 0.;
   }