shithub: aubio

Download patch

ref: d2073008dcbc8f07eb16446a618c10aa8f2dd2e1
parent: 741bdda6b26a37c6f58d02738d8b8221cb294542
author: Paul Brossier <piem@piem.org>
date: Thu Dec 3 20:40:48 EST 2009

src/tempo: switch to mono

--- a/src/tempo/beattracking.c
+++ b/src/tempo/beattracking.c
@@ -54,7 +54,7 @@
 };
 
 aubio_beattracking_t *
-new_aubio_beattracking (uint_t winlen, uint_t channels)
+new_aubio_beattracking (uint_t winlen)
 {
 
   aubio_beattracking_t *p = AUBIO_NEW (aubio_beattracking_t);
@@ -78,25 +78,25 @@
 
   p->rayparam = rayparam;
   p->step = step;
-  p->rwv = new_fvec (laglen, 1);
-  p->gwv = new_fvec (laglen, 1);
-  p->dfwv = new_fvec (winlen, 1);
-  p->dfrev = new_fvec (winlen, channels);
-  p->acf = new_fvec (winlen, channels);
-  p->acfout = new_fvec (laglen, channels);
-  p->phwv = new_fvec (2 * laglen, 1);
-  p->phout = new_fvec (winlen, channels);
+  p->rwv = new_fvec (laglen);
+  p->gwv = new_fvec (laglen);
+  p->dfwv = new_fvec (winlen);
+  p->dfrev = new_fvec (winlen);
+  p->acf = new_fvec (winlen);
+  p->acfout = new_fvec (laglen);
+  p->phwv = new_fvec (2 * laglen);
+  p->phout = new_fvec (winlen);
 
   p->timesig = 0;
 
   /* exponential weighting, dfwv = 0.5 when i =  43 */
   for (i = 0; i < winlen; i++) {
-    p->dfwv->data[0][i] = (EXP ((LOG (2.0) / rayparam) * (i + 1)))
+    p->dfwv->data[i] = (EXP ((LOG (2.0) / rayparam) * (i + 1)))
         / dfwvnorm;
   }
 
   for (i = 0; i < (laglen); i++) {
-    p->rwv->data[0][i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) *
+    p->rwv->data[i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) *
         EXP ((-SQR ((smpl_t) (i + 1.)) / (2. * SQR ((smpl_t) rayparam))));
   }
 
@@ -160,7 +160,7 @@
   for (i = 1; i < laglen - 1; i++) {
     for (a = 1; a <= numelem; a++) {
       for (b = (1 - a); b < a; b++) {
-        bt->acfout->data[0][i] += bt->acf->data[0][a * (i + 1) + b - 1]
+        bt->acfout->data[i] += bt->acf->data[a * (i + 1) + b - 1]
             * 1. / (2. * a - 1.);
       }
     }
@@ -170,7 +170,7 @@
 
   /* find non-zero Rayleigh period */
   maxindex = fvec_max_elem (bt->acfout);
-  bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex, 0) : 1;
+  bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex) : 1;
   //rp = (maxindex==127) ? 43 : maxindex; //rayparam
   bt->rp = (maxindex == bt->acfout->length - 1) ? bt->rayparam : maxindex;      //rayparam
 
@@ -190,7 +190,7 @@
   fvec_zeros (bt->phout);
   for (i = 0; i < bp; i++) {
     for (k = 0; k < kmax; k++) {
-      bt->phout->data[0][i] += bt->dfrev->data[0][i + (uint_t) ROUND (bp * k)];
+      bt->phout->data[i] += bt->dfrev->data[i + (uint_t) ROUND (bp * k)];
     }
   }
   fvec_weight (bt->phout, bt->phwv);
@@ -203,7 +203,7 @@
 #endif /* AUBIO_BEAT_WARNINGS */
     phase = step - bt->lastbeat;
   } else {
-    phase = fvec_quadint (bt->phout, maxindex, 0);
+    phase = fvec_quadint (bt->phout, maxindex);
   }
   /* take back one frame delay */
   phase += 1.;
@@ -236,7 +236,7 @@
 
   if (beat >= 0) {
     //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat);
-    output->data[0][i] = beat;
+    output->data[i] = beat;
     i++;
   }
 
@@ -243,13 +243,13 @@
   while (beat + bp <= step) {
     beat += bp;
     //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat);
-    output->data[0][i] = beat;
+    output->data[i] = beat;
     i++;
   }
 
   bt->lastbeat = beat;
   /* store the number of beats in this frame as the first element */
-  output->data[0][0] = i;
+  output->data[0] = i;
 }
 
 uint_t
@@ -259,14 +259,14 @@
   smpl_t three_energy = 0., four_energy = 0.;
   if (acflen > 6 * gp + 2) {
     for (k = -2; k < 2; k++) {
-      three_energy += acf->data[0][3 * gp + k];
-      four_energy += acf->data[0][4 * gp + k];
+      three_energy += acf->data[3 * gp + k];
+      four_energy += acf->data[4 * gp + k];
     }
   } else {
     /*Expanded to be more accurate in time sig estimation */
     for (k = -2; k < 2; k++) {
-      three_energy += acf->data[0][3 * gp + k] + acf->data[0][6 * gp + k];
-      four_energy += acf->data[0][4 * gp + k] + acf->data[0][2 * gp + k];
+      three_energy += acf->data[3 * gp + k] + acf->data[6 * gp + k];
+      four_energy += acf->data[4 * gp + k] + acf->data[2 * gp + k];
     }
   }
   return (three_energy > four_energy) ? 3 : 4;
@@ -300,12 +300,12 @@
     for (i = 1; i < laglen - 1; i++) {
       for (a = 1; a <= bt->timesig; a++) {
         for (b = (1 - a); b < a; b++) {
-          acfout->data[0][i] += acf->data[0][a * (i + 1) + b - 1];
+          acfout->data[i] += acf->data[a * (i + 1) + b - 1];
         }
       }
     }
     fvec_weight (acfout, bt->gwv);
-    gp = fvec_quadint (acfout, fvec_max_elem (acfout), 0);
+    gp = fvec_quadint (acfout, fvec_max_elem (acfout));
     /*
        while(gp<32) gp =gp*2;
        while(gp>64) gp = gp/2;
@@ -350,7 +350,7 @@
     gp = rp;
     bt->timesig = fvec_gettimesig (acf, acflen, gp);
     for (j = 0; j < laglen; j++)
-      bt->gwv->data[0][j] =
+      bt->gwv->data[j] =
           EXP (-.5 * SQR ((smpl_t) (j + 1. - gp)) / SQR (bt->g_var));
     flagconst = 0;
     bp = gp;
@@ -362,7 +362,7 @@
     /* gaussian phase weighting */
     if (step > bt->lastbeat) {
       for (j = 0; j < 2 * laglen; j++) {
-        bt->phwv->data[0][j] =
+        bt->phwv->data[j] =
             EXP (-.5 * SQR ((smpl_t) (1. + j - step +
                     bt->lastbeat)) / (bp / 8.));
       }
@@ -409,7 +409,7 @@
 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, 0);
+    return 5168. / fvec_quadint (bt->acfout, bt->bp);
   } else {
     return 0.;
   }
--- a/src/tempo/beattracking.h
+++ b/src/tempo/beattracking.h
@@ -47,10 +47,9 @@
 /** create beat tracking object
 
   \param hop_size number of onset detection samples [512] 
-  \param channels number (not functionnal) [1]
 
 */
-aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size, uint_t channels);
+aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size);
 
 /** track the beat 
 
--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -58,7 +58,7 @@
   aubio_specdesc_do (o->od, o->fftgrain, o->of);
   /*if (usedoubled) {
     aubio_specdesc_do(o2,fftgrain, onset2);
-    onset->data[0][0] *= onset2->data[0][0];
+    onset->data[0] *= onset2->data[0];
   }*/
   /* execute every overlap_size*step */
   if (o->blockpos == (signed)step -1 ) {
@@ -66,26 +66,26 @@
     aubio_beattracking_do(o->bt,o->dfframe,o->out);
     /* rotate dfframe */
     for (i = 0 ; i < winlen - step; i++ ) 
-      o->dfframe->data[0][i] = o->dfframe->data[0][i+step];
+      o->dfframe->data[i] = o->dfframe->data[i+step];
     for (i = winlen - step ; i < winlen; i++ ) 
-      o->dfframe->data[0][i] = 0.;
+      o->dfframe->data[i] = 0.;
     o->blockpos = -1;
   }
   o->blockpos++;
   aubio_peakpicker_do (o->pp, o->of, o->onset);
-  tempo->data[0][1] = o->onset->data[0][0];
+  tempo->data[1] = o->onset->data[0];
   thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
-  o->dfframe->data[0][winlen - step + o->blockpos] = thresholded->data[0][0];
+  o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0];
   /* end of second level loop */
-  tempo->data[0][0] = 0; /* reset tactus */
+  tempo->data[0] = 0; /* reset tactus */
   i=0;
-  for (i = 1; i < o->out->data[0][0]; i++ ) {
+  for (i = 1; i < o->out->data[0]; i++ ) {
     /* if current frame is a predicted tactus */
-    if (o->blockpos == FLOOR(o->out->data[0][i])) {
-      tempo->data[0][0] = o->out->data[0][i] - FLOOR(o->out->data[0][i]); /* set tactus */
+    if (o->blockpos == FLOOR(o->out->data[i])) {
+      tempo->data[0] = o->out->data[i] - FLOOR(o->out->data[i]); /* set tactus */
       /* test for silence */
       if (aubio_silence_detection(input, o->silence)==1) {
-        tempo->data[0][1] = 0; /* unset onset */
+        tempo->data[1] = 0; /* unset onset */
       }
     }
   }
@@ -104,7 +104,7 @@
 
 /* Allocate memory for an tempo detection */
 aubio_tempo_t * new_aubio_tempo (char_t * onset_mode, 
-    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate)
+    uint_t buf_size, uint_t hop_size, uint_t samplerate)
 {
   aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
   o->samplerate = samplerate;
@@ -114,19 +114,19 @@
   o->threshold = 0.3;
   o->silence = -90.;
   o->blockpos = 0;
-  o->dfframe  = new_fvec(o->winlen,channels);
-  o->fftgrain = new_cvec(buf_size, channels);
-  o->out      = new_fvec(o->step,channels);
-  o->pv       = new_aubio_pvoc(buf_size, hop_size, channels);
-  o->pp       = new_aubio_peakpicker(channels);
+  o->dfframe  = new_fvec(o->winlen);
+  o->fftgrain = new_cvec(buf_size);
+  o->out      = new_fvec(o->step);
+  o->pv       = new_aubio_pvoc(buf_size, hop_size);
+  o->pp       = new_aubio_peakpicker();
   aubio_peakpicker_set_threshold (o->pp, o->threshold);
-  o->od       = new_aubio_specdesc(onset_mode,buf_size,channels);
-  o->of       = new_fvec(1, channels);
-  o->bt       = new_aubio_beattracking(o->winlen,channels);
-  o->onset    = new_fvec(1, channels);
+  o->od       = new_aubio_specdesc(onset_mode,buf_size);
+  o->of       = new_fvec(1);
+  o->bt       = new_aubio_beattracking(o->winlen);
+  o->onset    = new_fvec(1);
   /*if (usedoubled)    {
-    o2 = new_aubio_specdesc(type_onset2,buffer_size,channels);
-    onset2 = new_fvec(1 , channels);
+    o2 = new_aubio_specdesc(type_onset2,buffer_size);
+    onset2 = new_fvec(1);
   }*/
   return o;
 }
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -39,7 +39,7 @@
 
 /** create tempo detection object */
 aubio_tempo_t * new_aubio_tempo (char_t * method, 
-    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
+    uint_t buf_size, uint_t hop_size, uint_t samplerate);
 
 /** execute tempo detection */
 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo);