Index: src/filterbank.c
===================================================================
--- src/filterbank.c	(revision 53a75769de213bbe237879c6b3bab8a2e6f4bc5c)
+++ src/filterbank.c	(revision b276dee4f0888ff5eaff9f03244e2d49f6e7241b)
@@ -24,5 +24,9 @@
 
 #include "aubio_priv.h"
+#include "sample.h"
 #include "filterbank.h"
+
+#define USE_EQUAL_GAIN 1
+#define VERY_SMALL_NUMBER 2e-42
 
 /** \brief A structure to store a set of n_filters filters of lenghts win_s */
@@ -30,5 +34,5 @@
     uint_t win_s;
     uint_t n_filters;
-    fvec_t *filters;
+    fvec_t **filters;
 };
 
@@ -41,14 +45,120 @@
 
   /** allocating filter tables */
-  fb->filters=AUBIO_ARRAY(n_filters,fvec_t);
+  fb->filters=AUBIO_ARRAY(fvec_t*,n_filters);
   for (filter_cnt=0; filter_cnt<n_filters; filter_cnt++)
     /* considering one-channel filters */
-    filters[filter_cnt]=new_fvec(win_s, 1);
+    fb->filters[filter_cnt]=new_fvec(win_s, 1);
+
+  return fb;
+}
+
+aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max){
+  smpl_t nyquist = samplerate/2.;
+  uint_t style = 1;
+  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
+
+  uint_t n, i, k, *fft_peak, M, next_peak; 
+  smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, 
+         freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
+
+  mel_peak = height_norm = lin_peak = NULL;
+  fft_peak = NULL;
+  norm = 1; 
+
+  mel_freq_max = 1127 * log(1 + freq_max / 700);
+  mel_freq_min = 1127 * log(1 + freq_min / 700);
+  freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;
+
+  mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t)); 
+  /* +2 for zeros at start and end */
+  lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
+  fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));
+  height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));
+
+  if(mel_peak == NULL || height_norm == NULL || 
+      lin_peak == NULL || fft_peak == NULL)
+    return NULL;
+
+  M = fb->win_s >> 1;
+
+  mel_peak[0] = mel_freq_min;
+  lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
+  fft_peak[0] = lin_peak[0] / nyquist * M;
+
+
+  for (n = 1; n <= fb->n_filters; n++){  
+    /*roll out peak locations - mel, linear and linear on fft window scale */
+    mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
+    lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
+    fft_peak[n] = lin_peak[n] / nyquist * M;
+  }
+
+  for (n = 0; n < fb->n_filters; n++){
+    /*roll out normalised gain of each peak*/
+    if (style == USE_EQUAL_GAIN){
+      height = 1; 
+      norm_fact = norm;
+    }
+    else{
+      height = 2 / (lin_peak[n + 2] - lin_peak[n]);
+      norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
+    }
+    height_norm[n] = height * norm_fact;
+  }
+
+  i = 0;
+
+  for(n = 0; n < fb->n_filters; n++){
+
+    /*calculate the rise increment*/
+    if(n > 0)
+      inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
+    else
+      inc = height_norm[n] / fft_peak[n];
+    val = 0;  
+
+    /*zero the start of the array*/
+    for(k = 0; k < i; k++)
+      //fft_tables[n][k] = 0.f;
+      fb->filters[n]->data[0][k]=0.f;
+
+    /*fill in the rise */
+    for(; i <= fft_peak[n]; i++){ 
+      // fft_tables[n][i] = val;
+      fb->filters[n]->data[0][k]=val;
+      val += inc;
+    }
+
+    /*calculate the fall increment */
+    inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
+
+    val = 0;
+    next_peak = fft_peak[n + 1];
+
+    /*reverse fill the 'fall' */
+    for(i = next_peak; i > fft_peak[n]; i--){ 
+      //fft_tables[n][i] = val;
+      fb->filters[n]->data[0][k]=val;
+      val += inc;
+    }
+
+    /*zero the rest of the array*/
+    for(k = next_peak + 1; k < fb->win_s; k++)
+      //fft_tables[n][k] = 0.f;
+      fb->filters[n]->data[0][k]=0.f;
+  }
+
+  free(mel_peak);
+  free(lin_peak);
+  free(height_norm);
+  free(fft_peak);
+
+  return fb;
 
 }
 
+
 void del_aubio_filterbank(aubio_filterbank_t * fb){
-  
-  int filter_cnt;
+  uint_t filter_cnt;
   /** deleting filter tables first */
   for (filter_cnt=0; filter_cnt<fb->n_filters; filter_cnt++)
@@ -56,5 +166,19 @@
   AUBIO_FREE(fb->filters);
   AUBIO_FREE(fb);
-
 }
 
+void aubio_filterbank_do(aubio_filterbank_t * f, cvec_t * in, fvec_t *out) {
+  uint_t n, filter_cnt;
+  for(filter_cnt = 0; filter_cnt < f->n_filters; filter_cnt++){
+      out->data[0][filter_cnt] = 0.f;
+      for(n = 0; n < f->win_s; n++){
+          out->data[0][filter_cnt] += in->norm[0][n] 
+            * f->filters[filter_cnt]->data[0][n];
+      }
+      out->data[0][filter_cnt] =
+        LOG(out->data[0][filter_cnt] < VERY_SMALL_NUMBER ? 
+            VERY_SMALL_NUMBER : out->data[0][filter_cnt]);
+  }
+
+  return;
+}
Index: src/filterbank.h
===================================================================
--- src/filterbank.h	(revision 53a75769de213bbe237879c6b3bab8a2e6f4bc5c)
+++ src/filterbank.h	(revision b276dee4f0888ff5eaff9f03244e2d49f6e7241b)
@@ -44,4 +44,15 @@
 aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s);
 
+/** filterbank initialization for mel filters
+
+  \param nyquist nyquist frequency, i.e. half of the sampling rate
+  \param style libxtract style
+  \param freqmin lowest filter frequency
+  \param freqmax highest filter frequency
+
+*/
+aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
+
+
 /** destroy filterbank object
 
@@ -51,22 +62,8 @@
 void del_aubio_filterbank(aubio_filterbank_t * fb);
 
-/** filterbank initialization for mel filters
-
-  \param fb filterbank, as returned by new_aubio_filterbank method
-  \param nyquist nyquist frequency, i.e. half of the sampling rate
-  \param style libxtract style
-  \param freqmin lowest filter frequency
-  \param freqmax highest filter frequency
+/** compute filterbank
 
 */
-void aubio_filterbank_mfcc_init(aubio_filterbank_t * fb, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max);
-
-// Initialization
-
-/** \brief A function to initialise a mel filter bank 
- * 
- * It is up to the caller to pass in a pointer to memory allocated for freq_bands arrays of length N. This function populates these arrays with magnitude coefficients representing the mel filterbank on a linear scale 
- */
-int aubio_mfcc_init(int N, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max, int freq_bands, smpl_t ** fft_tables);
+void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
 
 #ifdef __cplusplus
Index: src/mfcc.c
===================================================================
--- src/mfcc.c	(revision 53a75769de213bbe237879c6b3bab8a2e6f4bc5c)
+++ src/mfcc.c	(revision b276dee4f0888ff5eaff9f03244e2d49f6e7241b)
@@ -28,8 +28,4 @@
 #include "math.h"
 
-#define VERY_SMALL_NUMBER 2e-42
-#define USE_EQUAL_GAIN 1
-
-
 /** Internal structure for mfcc object **/
 
@@ -48,15 +44,4 @@
 
 
-/** filterbank initialization for mel filters
-
-  \param fb filterbank, as returned by new_aubio_filterbank method
-  \param nyquist nyquist frequency, i.e. half of the sampling rate
-  \param style libxtract style
-  \param freqmin lowest filter frequency
-  \param freqmax highest filter frequency
-
-*/
-void aubio_filterbank_mfcc_init(aubio_filterbank_t * fb, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max);
-
 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
   /** allocating space for mfcc object */
@@ -74,8 +59,8 @@
 
   /** filterbank allocation */
-  mfcc->fb = new_aubio_filterbank(n_filters, mfcc->win_s);
+  mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
 
   /** allocating space for fft object (used for dct) */
-  mfcc->fft_dct=new_aubio_mfft(mfcc->win_s, 1);
+  mfcc->fft_dct=new_aubio_mfft(n_filters, 1);
 
   /** allocating buffers */
@@ -83,7 +68,4 @@
   
   mfcc->fftgrain_dct=new_cvec(n_filters, 1);
-
-  /** populating the filterbank */
-  aubio_filterbank_mfcc_init(mfcc->fb, (mfcc->samplerate)/2, mfcc->lowfreq, mfcc->highfreq);
 
   return mfcc;
@@ -104,16 +86,6 @@
 
 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
-
-    aubio_filterbank_t *f = mf->fb;
-    uint_t n, filter_cnt;
-
-    for(filter_cnt = 0; filter_cnt < f->n_filters; filter_cnt++){
-        mf->in_dct->data[0][filter_cnt] = 0.f;
-        for(n = 0; n < mf->win_s; n++){
-            mf->in_dct->data[0][filter_cnt] += in->norm[0][n] * f->filters[filter_cnt]->data[0][n];
-        }
-        mf->in_dct->data[0][filter_cnt] = LOG(mf->in_dct->data[0][filter_cnt] < VERY_SMALL_NUMBER ? VERY_SMALL_NUMBER : mf->in_dct->data[0][filter_cnt]);
-    }
-
+    // compute filterbank
+    aubio_filterbank_do(mf->fb, in, mf->in_dct);
     //TODO: check that zero padding 
     // the following line seems useless since the in_dct buffer has the correct size
@@ -126,114 +98,14 @@
 
 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){
+    uint_t i;
     //compute mag spectrum
     aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
-
-    int i;
     //extract real part of fft grain
-    for(i=0; i<mf->n_coefs ;i++){
-      out->data[0][i]= mf->fftgrain_dct->norm[0][i]*COS(mf->fftgrain_dct->phas[0][i]);
+    //for(i=0; i<mf->n_coefs ;i++){
+    for(i=0; i<out->length;i++){
+      out->data[0][i]= mf->fftgrain_dct->norm[0][i]
+        *COS(mf->fftgrain_dct->phas[0][i]);
     }
-
     return;
 }
 
-void aubio_filterbank_mfcc_init(aubio_filterbank_t * fb, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max){
-
-  int n, i, k, *fft_peak, M, next_peak; 
-  smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, 
-         freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
-
-  mel_peak = height_norm = lin_peak = NULL;
-  fft_peak = NULL;
-  norm = 1; 
-
-  mel_freq_max = 1127 * log(1 + freq_max / 700);
-  mel_freq_min = 1127 * log(1 + freq_min / 700);
-  freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;
-
-  mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t)); 
-  /* +2 for zeros at start and end */
-  lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
-  fft_peak = (int *)malloc((fb->n_filters + 2) * sizeof(int));
-  height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));
-
-  if(mel_peak == NULL || height_norm == NULL || 
-      lin_peak == NULL || fft_peak == NULL)
-    return NULL;
-
-  M = fb->win_s >> 1;
-
-  mel_peak[0] = mel_freq_min;
-  lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
-  fft_peak[0] = lin_peak[0] / nyquist * M;
-
-
-  for (n = 1; n <= fb->n_filters; n++){  
-    /*roll out peak locations - mel, linear and linear on fft window scale */
-    mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
-    lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
-    fft_peak[n] = lin_peak[n] / nyquist * M;
-  }
-
-  for (n = 0; n < fb->n_filters; n++){
-    /*roll out normalised gain of each peak*/
-    if (style == USE_EQUAL_GAIN){
-      height = 1; 
-      norm_fact = norm;
-    }
-    else{
-      height = 2 / (lin_peak[n + 2] - lin_peak[n]);
-      norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
-    }
-    height_norm[n] = height * norm_fact;
-  }
-
-  i = 0;
-
-  for(n = 0; n < fb->n_filters; n++){
-
-    /*calculate the rise increment*/
-    if(n > 0)
-      inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
-    else
-      inc = height_norm[n] / fft_peak[n];
-    val = 0;  
-
-    /*zero the start of the array*/
-    for(k = 0; k < i; k++)
-      //fft_tables[n][k] = 0.f;
-      fb->filters[n]->data[0][k]=0.f;
-
-    /*fill in the rise */
-    for(; i <= fft_peak[n]; i++){ 
-      // fft_tables[n][i] = val;
-      fb->filters[n]->data[0][k]=val;
-      val += inc;
-    }
-
-    /*calculate the fall increment */
-    inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
-
-    val = 0;
-    next_peak = fft_peak[n + 1];
-
-    /*reverse fill the 'fall' */
-    for(i = next_peak; i > fft_peak[n]; i--){ 
-      //fft_tables[n][i] = val;
-      fb->filters[n]->data[0][k]=val;
-      val += inc;
-    }
-
-    /*zero the rest of the array*/
-    for(k = next_peak + 1; k < fb->win_s; k++)
-      //fft_tables[n][k] = 0.f;
-      fb->filters[n]->data[0][k]=0.f;
-  }
-
-  free(mel_peak);
-  free(lin_peak);
-  free(height_norm);
-  free(fft_peak);
-
-}
-
Index: src/mfcc.h
===================================================================
--- src/mfcc.h	(revision 53a75769de213bbe237879c6b3bab8a2e6f4bc5c)
+++ src/mfcc.h	(revision b276dee4f0888ff5eaff9f03244e2d49f6e7241b)
@@ -30,4 +30,5 @@
 #endif
 
+#include "sample.h"
 #include "filterbank.h"
 
