shithub: aubio

Download patch

ref: 72db1cfb12b6344f5765233bc2d6e15a53adf4ef
parent: ce12f3ad40f94b6b670f0cf100f5efc9eb5be835
author: Paul Brossier <[email protected]>
date: Sat Feb 9 16:18:37 EST 2013

src/tempo/beattracking.c: avoid casting, make sure b is well behaved

  Many thanks to Olivier Robert for his patch, and sorry for the delay!

--- a/src/tempo/beattracking.c
+++ b/src/tempo/beattracking.c
@@ -135,7 +135,7 @@
   smpl_t phase;                 // beat alignment (step - lastbeat) 
   smpl_t beat;                  // beat position 
   smpl_t bp;                    // beat period
-  uint_t a; sint_t b;           // used to build shift invariant comb filterbank
+  uint_t a, b;                  // used to build shift invariant comb filterbank
   uint_t kmax;                  // number of elements used to find beat phase
 
   /* copy dfframe, apply detection function weighting, and revert */
@@ -159,8 +159,8 @@
   /* compute shift invariant comb filterbank */
   for (i = 1; i < laglen - 1; i++) {
     for (a = 1; a <= numelem; a++) {
-      for (b = (1 - a); b < (sint_t)a; b++) {
-        bt->acfout->data[i] += bt->acf->data[a * (i + 1) + b - 1]
+      for (b = 1; b < 2 * a; b++) {
+        bt->acfout->data[i] += bt->acf->data[i * a + b - 1]
             * 1. / (2. * a - 1.);
       }
     }
@@ -275,7 +275,7 @@
 void
 aubio_beattracking_checkstate (aubio_beattracking_t * bt)
 {
-  uint_t i, j, a; sint_t b;
+  uint_t i, j, a, b;
   uint_t flagconst = 0;
   sint_t counter = bt->counter;
   uint_t flagstep = bt->flagstep;
@@ -299,8 +299,8 @@
     fvec_zeros (acfout);
     for (i = 1; i < laglen - 1; i++) {
       for (a = 1; a <= bt->timesig; a++) {
-        for (b = (1 - a); b < (sint_t)a; b++) {
-          acfout->data[i] += acf->data[a * (i + 1) + b - 1];
+        for (b = 1; b < 2 * a; b++) {
+          acfout->data[i] += acf->data[i * a + b - 1];
         }
       }
     }