shithub: aubio

Download patch

ref: fc61225e10b7a6acfcdbda0f4b4a25e2bcb821b4
parent: 8e5c051fac86fc9b04ea2853f1fc30245bf56ad7
author: Paul Brossier <piem@piem.org>
date: Thu Dec 3 20:43:29 EST 2009

src/utils: switch to mono

--- a/src/utils/hist.c
+++ b/src/utils/hist.c
@@ -31,7 +31,6 @@
 struct _aubio_hist_t {
   fvec_t * hist;
   uint_t nelems;
-  uint_t channels;
   fvec_t * cent;
   aubio_scale_t *scaler;
 };
@@ -39,22 +38,21 @@
 /**
  * Object creation/deletion calls
  */
-aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems, uint_t channels){
+aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems){
   aubio_hist_t * s = AUBIO_NEW(aubio_hist_t);
   smpl_t step = (ihig-ilow)/(smpl_t)(nelems);
   smpl_t accum = step;
   uint_t i;
-  s->channels = channels;
   s->nelems = nelems;
-  s->hist = new_fvec(nelems, channels);
-  s->cent = new_fvec(nelems, 1);
+  s->hist = new_fvec(nelems);
+  s->cent = new_fvec(nelems);
 
   /* use scale to map ilow/ihig -> 0/nelems */
   s->scaler = new_aubio_scale(ilow,ihig,0,nelems);
   /* calculate centers now once */
-  s->cent->data[0][0] = ilow + 0.5 * step;
+  s->cent->data[0] = ilow + 0.5 * step;
   for (i=1; i < s->nelems; i++, accum+=step )
-    s->cent->data[0][i] = s->cent->data[0][0] + accum;
+    s->cent->data[i] = s->cent->data[0] + accum;
 
   return s;
 }
@@ -70,45 +68,40 @@
  * do it
  */
 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) {
-  uint_t i,j;
+  uint_t j;
   sint_t tmp = 0;
   aubio_scale_do(s->scaler, input);
   /* reset data */
-  for (i=0; i < s->channels; i++)
-    for (j=0; j < s->nelems; j++)
-      s->hist->data[i][j] = 0;
+  fvec_zeros(s->hist);
   /* run accum */
-  for (i=0; i < input->channels; i++)
-    for (j=0;  j < input->length; j++)
-    {
-      tmp = (sint_t)FLOOR(input->data[i][j]);
-      if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
-        s->hist->data[i][tmp] += 1;
+  for (j=0;  j < input->length; j++)
+  {
+    tmp = (sint_t)FLOOR(input->data[j]);
+    if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) {
+      s->hist->data[tmp] += 1;
     }
+  }
 }
 
 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) {
-  uint_t i,j;
+  uint_t j;
   sint_t tmp = 0;
   aubio_scale_do(s->scaler, input);
   /* reset data */
-  for (i=0; i < s->channels; i++)
-    for (j=0; j < s->nelems; j++)
-      s->hist->data[i][j] = 0;
+  fvec_zeros(s->hist);
   /* run accum */
-  for (i=0; i < input->channels; i++)
-    for (j=0;  j < input->length; j++) {
-      if (input->data[i][j] != 0) {
-        tmp = (sint_t)FLOOR(input->data[i][j]);
-        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
-          s->hist->data[i][tmp] += 1;
-      }
+  for (j=0;  j < input->length; j++) {
+    if (input->data[j] != 0) {
+      tmp = (sint_t)FLOOR(input->data[j]);
+      if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
+        s->hist->data[tmp] += 1;
     }
+  }
 }
 
 
 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) {
-  uint_t i,j;
+  uint_t i;
   sint_t tmp = 0;
   smpl_t ilow = fvec_min(input);
   smpl_t ihig = fvec_max(input);
@@ -118,42 +111,37 @@
   aubio_scale_set_limits (s->scaler, ilow, ihig, 0, s->nelems);
 
   /* recalculate centers */
-  s->cent->data[0][0] = ilow + 0.5f * step;
+  s->cent->data[0] = ilow + 0.5f * step;
   for (i=1; i < s->nelems; i++)
-    s->cent->data[0][i] = s->cent->data[0][0] + i * step;
+    s->cent->data[i] = s->cent->data[0] + i * step;
 
   /* scale */
   aubio_scale_do(s->scaler, input);
 
   /* reset data */
-  for (i=0; i < s->channels; i++)
-    for (j=0; j < s->nelems; j++)
-      s->hist->data[i][j] = 0;
+  fvec_zeros(s->hist);
   /* run accum */
-  for (i=0; i < input->channels; i++)
-    for (j=0;  j < input->length; j++) {
-      if (input->data[i][j] != 0) {
-        tmp = (sint_t)FLOOR(input->data[i][j]);
-        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
-          s->hist->data[i][tmp] += 1;
-      }
+  for (i=0;  i < input->length; i++) {
+    if (input->data[i] != 0) {
+      tmp = (sint_t)FLOOR(input->data[i]);
+      if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
+        s->hist->data[tmp] += 1;
     }
+  }
 }
 
 void aubio_hist_weight (aubio_hist_t *s) {
-  uint_t i,j;
-  for (i=0; i < s->channels; i++)
-    for (j=0; j < s->nelems; j++) {
-      s->hist->data[i][j] *= s->cent->data[0][j];
-    }
+  uint_t j;
+  for (j=0; j < s->nelems; j++) {
+    s->hist->data[j] *= s->cent->data[j];
+  }
 }
 
 smpl_t aubio_hist_mean (aubio_hist_t *s) {
-  uint_t i,j;
+  uint_t j;
   smpl_t tmp = 0.0;
-  for (i=0; i < s->channels; i++)
-    for (j=0; j < s->nelems; j++)
-      tmp += s->hist->data[i][j];
+  for (j=0; j < s->nelems; j++)
+    tmp += s->hist->data[j];
   return tmp/(smpl_t)(s->nelems);
 }
 
--- a/src/utils/hist.h
+++ b/src/utils/hist.h
@@ -39,9 +39,8 @@
  * \param flow minimum input
  * \param fhig maximum input
  * \param nelems number of histogram columns
- * \param channels number of channels
  */
-aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems, uint_t channels);
+aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems);
 /** histogram deletion */
 void del_aubio_hist(aubio_hist_t *s);
 /** compute the histogram */
--- a/src/utils/scale.c
+++ b/src/utils/scale.c
@@ -69,13 +69,11 @@
 
 void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 
 {
-  uint_t i, j;
-  for (i=0; i < input->channels; i++){
-    for (j=0;  j < input->length; j++){
-      input->data[i][j] -= s->ilow;
-      input->data[i][j] *= s->scaler;
-      input->data[i][j] += s->olow;
-    }
+  uint_t j;
+  for (j=0;  j < input->length; j++){
+    input->data[j] -= s->ilow;
+    input->data[j] *= s->scaler;
+    input->data[j] += s->olow;
   }
 }