Index: src/utils/hist.c
===================================================================
--- src/utils/hist.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/utils/hist.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,157 @@
+/*
+   Copyright (C) 2003 Paul Brossier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "aubio_priv.h"
+#include "sample.h"
+#include "utils/scale.h"
+#include "mathutils.h" //vec_min vec_max
+#include "utils/hist.h"
+
+/********
+ * Object Structure
+ */
+
+struct _aubio_hist_t {
+  fvec_t * hist;
+  uint_t nelems;
+  uint_t channels;
+  fvec_t * cent;
+  aubio_scale_t *scaler;
+};
+
+/**
+ * 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 * 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);
+
+  /* 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;
+  for (i=1; i < s->nelems; i++, accum+=step )
+    s->cent->data[0][i] = s->cent->data[0][0] + accum;
+
+  return s;
+}
+
+void del_aubio_hist(aubio_hist_t *s) {
+  del_fvec(s->hist);
+  del_fvec(s->cent);
+  del_aubio_scale(s->scaler);
+  AUBIO_FREE(s);
+}
+
+/***
+ * do it
+ */
+void aubio_hist_do (aubio_hist_t *s, fvec_t *input) {
+  uint_t i,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;
+  /* 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;
+    }
+}
+
+void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) {
+  uint_t i,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;
+  /* 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;
+      }
+    }
+}
+
+
+void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) {
+  uint_t i,j;
+  sint_t tmp = 0;
+  smpl_t ilow = vec_min(input);
+  smpl_t ihig = vec_max(input);
+  smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems);
+
+  /* readapt */
+  aubio_scale_set(s->scaler, ilow, ihig, 0, s->nelems);
+
+  /* recalculate centers */
+  s->cent->data[0][0] = ilow + 0.5f * step;
+  for (i=1; i < s->nelems; i++)
+    s->cent->data[0][i] = s->cent->data[0][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;
+  /* 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;
+      }
+    }
+}
+
+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];
+    }
+}
+
+smpl_t aubio_hist_mean (aubio_hist_t *s) {
+  uint_t i,j;
+  smpl_t tmp = 0.0f;
+  for (i=0; i < s->channels; i++)
+    for (j=0; j < s->nelems; j++)
+      tmp += s->hist->data[i][j];
+  return tmp/(smpl_t)(s->nelems);
+}
+
Index: src/utils/hist.h
===================================================================
--- src/utils/hist.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/utils/hist.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,61 @@
+/*
+   Copyright (C) 2003 Paul Brossier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file
+ *
+ * Histogram function
+ *
+ * Big hacks to implement an histogram
+ */
+
+#ifndef HIST_H
+#define HIST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** histogram object */
+typedef struct _aubio_hist_t aubio_hist_t;
+
+/** histogram creation
+ * \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);
+/** histogram deletion */
+void del_aubio_hist(aubio_hist_t *s);
+/** compute the histogram */
+void aubio_hist_do(aubio_hist_t *s, fvec_t * input);
+/** compute the histogram ignoring null elements */
+void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input);
+/** compute the mean of the histogram */
+smpl_t aubio_hist_mean(aubio_hist_t *s);
+/** weight the histogram */
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: src/utils/scale.c
===================================================================
--- src/utils/scale.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/utils/scale.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,79 @@
+/*
+   Copyright (C) 2003 Paul Brossier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "aubio_priv.h"
+#include "sample.h"
+#include "utils/scale.h"
+
+struct _aubio_scale_t {
+  smpl_t ilow;
+  smpl_t ihig;
+  smpl_t olow;
+  smpl_t ohig;
+
+  smpl_t scaler;
+  smpl_t irange;
+
+  /* not implemented yet : type in/out data
+     bool inint;
+     bool outint;
+     */
+};
+
+aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, 
+    smpl_t olow, smpl_t ohig) {
+  aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
+  aubio_scale_set (s, ilow, ihig, olow, ohig);
+  return s;
+}
+
+void del_aubio_scale(aubio_scale_t *s) {
+  AUBIO_FREE(s);
+}
+
+void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
+    smpl_t olow, smpl_t ohig) {
+  smpl_t inputrange = ihig - ilow;
+  smpl_t outputrange= ohig - olow;
+  s->ilow = ilow;
+  s->ihig = ihig;
+  s->olow = olow;
+  s->ohig = ohig;
+  if (inputrange == 0) {
+    s->scaler = 0.0f;
+  } else {
+    s->scaler = outputrange/inputrange;
+    if (inputrange < 0) {
+      inputrange = inputrange * -1.0f;
+    }
+  }
+}
+
+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;
+    }
+  }
+}
+
Index: src/utils/scale.h
===================================================================
--- src/utils/scale.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/utils/scale.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,78 @@
+/*
+   Copyright (C) 2003 Paul Brossier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/** \file
+
+ Vector scaling function 
+ 
+ This object, inspired from the scale object in FTS, the jMax engine, scales
+ the values of a vector according to an affine function defined as follow:
+ 
+ \f$ y = (x - ilow)*(ohig-olow)/(ihig-ilow) + olow \f$ 
+ 
+*/
+#ifndef SCALE_H
+#define SCALE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** scale object */
+typedef struct _aubio_scale_t aubio_scale_t;
+
+/** create a scale object
+ 
+  \param flow lower value of output function
+  \param fhig higher value of output function
+  \param ilow lower value of input function
+  \param ihig higher value of output function
+
+*/
+aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig,
+    smpl_t ilow, smpl_t ihig);
+/** delete a scale object 
+
+  \param s scale object as returned by new_aubio_scale
+
+*/
+void del_aubio_scale(aubio_scale_t *s);
+/** scale input vector
+
+  \param s scale object as returned by new_aubio_scale
+  \param input vector to scale
+
+*/
+void aubio_scale_do(aubio_scale_t *s, fvec_t * input);
+/** modify scale parameters after object creation
+
+  \param s scale object as returned by new_aubio_scale
+  \param olow lower value of output function
+  \param ohig higher value of output function
+  \param ilow lower value of input function
+  \param ihig higher value of output function
+
+*/
+void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
+    smpl_t olow, smpl_t ohig);
+
+#ifdef __cplusplus
+}
+#endif 
+
+#endif
