ref: 274839fbaabb20bb8ad05ef54855dcf5ea85bd49
parent: 2b3280abacda5f37518ee1579428fa9a4a908c68
author: Paul Brossier <piem@piem.org>
date: Sun Nov 4 11:14:31 EST 2007
hist.c: move hist data to a structure, rename aubio_hist_weigth to aubio_hist_weight
--- a/src/hist.c
+++ b/src/hist.c
@@ -27,8 +27,7 @@
*/
struct _aubio_hist_t {
- /*bug: move to a fvec */
- smpl_t ** hist;
+ fvec_t * hist;
uint_t nelems;
uint_t channels;
smpl_t * cent;
@@ -45,10 +44,7 @@
uint_t i;
s->channels = channels;
s->nelems = nelems;
- s->hist = AUBIO_ARRAY(smpl_t*, channels);
- for (i=0; i< s->channels; i++) {
- s->hist[i] = AUBIO_ARRAY(smpl_t, nelems);
- }
+ s->hist = new_fvec(nelems, channels);
s->cent = AUBIO_ARRAY(smpl_t, nelems);
/* use scale to map ilow/ihig -> 0/nelems */
@@ -62,11 +58,7 @@
}
void del_aubio_hist(aubio_hist_t *s) {
- uint_t i;
- for (i=0; i< s->channels; i++) {
- AUBIO_FREE(s->hist[i]);
- }
- AUBIO_FREE(s->hist);
+ del_fvec(s->hist);
AUBIO_FREE(s->cent);
del_aubio_scale(s->scaler);
AUBIO_FREE(s);
@@ -83,7 +75,7 @@
/* reset data */
for (i=0; i < s->channels; i++)
for (j=0; j < s->nelems; j++)
- s->hist[i][j] = 0;
+ s->hist->data[i][j] = 0;
/* run accum */
for (i=0; i < input->channels; i++)
for (j=0; j < input->length; j++)
@@ -90,7 +82,7 @@
{
tmp = (sint_t)FLOOR(input->data[i][j]);
if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
- s->hist[i][tmp] += 1;
+ s->hist->data[i][tmp] += 1;
}
}
@@ -102,7 +94,7 @@
/* reset data */
for (i=0; i < s->channels; i++)
for (j=0; j < s->nelems; j++)
- s->hist[i][j] = 0;
+ s->hist->data[i][j] = 0;
/* run accum */
for (i=0; i < input->channels; i++)
for (j=0; j < input->length; j++)
@@ -110,7 +102,7 @@
if (input->data[i][j] != 0) {
tmp = (sint_t)FLOOR(input->data[i][j]);
if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
- s->hist[i][tmp] += 1;
+ s->hist->data[i][tmp] += 1;
}
}
}
@@ -138,7 +130,7 @@
/* reset data */
for (i=0; i < s->channels; i++)
for (j=0; j < s->nelems; j++)
- s->hist[i][j] = 0;
+ s->hist->data[i][j] = 0;
/* run accum */
for (i=0; i < input->channels; i++)
for (j=0; j < input->length; j++)
@@ -146,17 +138,17 @@
if (input->data[i][j] != 0) {
tmp = (sint_t)FLOOR(input->data[i][j]);
if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
- s->hist[i][tmp] += 1;
+ s->hist->data[i][tmp] += 1;
}
}
}
-void aubio_hist_weigth (aubio_hist_t *s)
+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[i][j] *= s->cent[j];
+ s->hist->data[i][j] *= s->cent[j];
}
}
@@ -166,7 +158,7 @@
smpl_t tmp = 0.0f;
for (i=0; i < s->channels; i++)
for (j=0; j < s->nelems; j++)
- tmp += s->hist[i][j];
+ tmp += s->hist->data[i][j];
return tmp/(smpl_t)(s->nelems);
}
--- a/src/hist.h
+++ b/src/hist.h
@@ -49,7 +49,7 @@
/** compute the mean of the histogram */
smpl_t aubio_hist_mean(aubio_hist_t *s);
/** weight the histogram */
-void aubio_hist_weigth(aubio_hist_t *s);
+void aubio_hist_weight(aubio_hist_t *s);
/** compute dynamic histogram for non-null elements */
void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input);
--- a/src/onsetdetection.c
+++ b/src/onsetdetection.c
@@ -128,7 +128,7 @@
/* apply o->histogram */
aubio_hist_dyn_notnull(o->histog,o->dev1);
/* weight it */
- aubio_hist_weigth(o->histog);
+ aubio_hist_weight(o->histog);
/* its mean is the result */
onset->data[i][0] = aubio_hist_mean(o->histog);
//onset->data[i][0] = vec_mean(o->dev1);
@@ -157,7 +157,7 @@
* overall function)*/
aubio_hist_dyn_notnull(o->histog,o->dev1);
/* weight it */
- aubio_hist_weigth(o->histog);
+ aubio_hist_weight(o->histog);
/* its mean is the result */
onset->data[i][0] = aubio_hist_mean(o->histog);