Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision e34b0101944dbd29c994deeabc481d7aa0032b9f)
+++ src/Makefile.am	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -22,5 +22,8 @@
 	onset.h \
 	tempo.h \
-	filter.h
+	filter.h \
+	filterbank.h \
+	mfcc.h
+
 nodist_pkginclude_HEADERS = config.h
 
@@ -69,5 +72,9 @@
 	tempo.h \
 	filter.c \
-	filter.h
+	filter.h \
+	filterbank.c \
+	filterbank.h \
+	mfcc.h \
+	mfcc.c 
 
 AM_CFLAGS = @AUBIO_CFLAGS@ @FFTWLIB_CFLAGS@ @SAMPLERATE_CFLAGS@
Index: src/aubio.h
===================================================================
--- src/aubio.h	(revision e34b0101944dbd29c994deeabc481d7aa0032b9f)
+++ src/aubio.h	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -80,4 +80,6 @@
 #include "onset.h"
 #include "tempo.h"
+#include "filterbank.h"
+#include "mfcc.h"
 
 #ifdef __cplusplus
Index: src/filterbank.c
===================================================================
--- src/filterbank.c	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
+++ src/filterbank.c	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -0,0 +1,221 @@
+/*
+   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
+                  and Paul Brossier <piem@piem.org>
+
+   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 "filterbank.h"
+#include "mathutils.h"
+
+#include "stdio.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 */
+struct aubio_filterbank_t_ {
+    uint_t win_s;
+    uint_t n_filters;
+    fvec_t **filters;
+};
+
+aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s){
+  /** allocating space for filterbank object */
+  aubio_filterbank_t * fb = AUBIO_NEW(aubio_filterbank_t);
+  uint_t filter_cnt;
+  fb->win_s=win_s;
+  fb->n_filters=n_filters;
+
+  /** allocating filter tables */
+  fb->filters=AUBIO_ARRAY(fvec_t*,n_filters);
+  for (filter_cnt=0; filter_cnt<n_filters; filter_cnt++)
+    /* considering one-channel filters */
+    fb->filters[filter_cnt]=new_fvec(win_s, 1);
+
+  return fb;
+}
+
+/*
+FB initialization based on Slaney's auditory toolbox
+TODO:
+  *solve memory leak problems while
+  *solve quantization issues when constructing signal:
+    *bug for win_s=512
+    *corrections for win_s=1024 -> why even filters with smaller amplitude
+
+*/
+
+aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){
+  
+  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
+  
+  
+  //slaney params
+  smpl_t lowestFrequency = 133.3333;
+  smpl_t linearSpacing = 66.66666666;
+  smpl_t logSpacing = 1.0711703;
+
+  uint_t linearFilters = 13;
+  uint_t logFilters = 27;
+  uint_t allFilters = linearFilters + logFilters;
+  
+  //buffers for computing filter frequencies
+  fvec_t * freqs=new_fvec(allFilters+2 , 1);
+  
+  fvec_t * lower_freqs=new_fvec( allFilters, 1);
+  fvec_t * upper_freqs=new_fvec( allFilters, 1);
+  fvec_t * center_freqs=new_fvec( allFilters, 1);
+
+  fvec_t * triangle_heights=new_fvec( allFilters, 1);
+  //lookup table of each bin frequency in hz
+  fvec_t * fft_freqs=new_fvec(win_s, 1);
+
+  uint_t filter_cnt, bin_cnt;
+  
+  //first step: filling all the linear filter frequencies
+  for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){
+    freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing;
+  }
+  smpl_t lastlinearCF=freqs->data[0][filter_cnt-1];
+  
+  //second step: filling all the log filter frequencies
+  for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
+    freqs->data[0][filter_cnt+linearFilters] = 
+      lastlinearCF*(pow(logSpacing,filter_cnt+1));
+  }
+
+  //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays
+  //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step
+    
+  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
+    lower_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt];
+    center_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+1];
+    upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2];
+  }
+
+  //computing triangle heights so that each triangle has unit area
+  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
+    triangle_heights->data[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt] 
+      - lower_freqs->data[0][filter_cnt]);
+  }
+  
+  //AUBIO_DBG("filter tables frequencies\n");
+  //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
+  //  AUBIO_DBG("filter n. %d %f %f %f %f\n",
+  //    filter_cnt, lower_freqs->data[0][filter_cnt], 
+  //    center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt], 
+  //    triangle_heights->data[0][filter_cnt]);
+
+  //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
+  for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){
+    fft_freqs->data[0][bin_cnt]= aubio_bintofreq(bin_cnt, samplerate, win_s);
+  }
+
+  //building each filter table
+  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
+
+    //TODO:check special case : lower freq =0
+    //calculating rise increment in mag/Hz
+    smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
+    
+    //zeroing begining of filter
+    for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
+      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
+      if( fft_freqs->data[0][bin_cnt]  <= lower_freqs->data[0][filter_cnt] &&
+          fft_freqs->data[0][bin_cnt+1] > lower_freqs->data[0][filter_cnt]) {
+        break;
+      }
+    }
+    bin_cnt++;
+    
+    //positive slope
+    for(; bin_cnt<win_s-1; bin_cnt++){
+      fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
+      //if(fft_freqs->data[0][bin_cnt]<= center_freqs->data[0][filter_cnt] && fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
+      if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
+        break;
+    }
+    //bin_cnt++;
+    
+    //negative slope
+    for(; bin_cnt<win_s-1; bin_cnt++){
+      
+      //checking whether last value is less than 0...
+      smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc;
+      if(val>=0)
+        fb->filters[filter_cnt]->data[0][bin_cnt]=val;
+      else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
+      
+      //if(fft_freqs->data[0][bin_cnt]<= upper_freqs->data[0][bin_cnt] && fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
+      //TODO: CHECK whether bugfix correct
+      if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
+        break;
+    }
+    //bin_cnt++;
+    
+    //zeroing tail
+    for(; bin_cnt<win_s; bin_cnt++)
+      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
+
+  }
+  
+  
+  del_fvec(freqs);
+  del_fvec(lower_freqs);
+  del_fvec(upper_freqs);
+  del_fvec(center_freqs);
+
+  del_fvec(triangle_heights);
+  del_fvec(fft_freqs);
+
+  return fb;
+
+}
+
+void del_aubio_filterbank(aubio_filterbank_t * fb){
+  uint_t filter_cnt;
+  /** deleting filter tables first */
+  for (filter_cnt=0; filter_cnt<fb->n_filters; filter_cnt++)
+    del_fvec(fb->filters[filter_cnt]);
+  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->length); filter_cnt++){
+      out->data[0][filter_cnt] = 0.f;
+      for(n = 0; n < in->length; 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;
+}
+
+fvec_t * aubio_filterbank_getchannel(aubio_filterbank_t * f, uint_t channel) {
+  if ( (channel >= 0) && (channel < f->n_filters) ) { return f->filters[channel]; }
+  else { return NULL; }
+}
Index: src/filterbank.h
===================================================================
--- src/filterbank.h	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
+++ src/filterbank.h	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -0,0 +1,79 @@
+/*
+   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
+                  and Paul Brossier <piem@piem.org>
+
+   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
+
+  Filterbank object
+
+  General-purpose spectral filterbank object. Comes with mel-filter initialization function.
+
+*/
+
+#ifndef FILTERBANK_H
+#define FILTERBANK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct aubio_filterbank_t_ aubio_filterbank_t;
+
+/** create filterbank object
+
+  \param win_s size of analysis buffer (and length the FFT transform)
+  \param n_filters number of filters to create
+
+*/
+
+aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s);
+
+/** filterbank initialization for mel filters
+
+  
+  \param n_filters number of filters
+  \param win_s window size
+  \param samplerate
+  \param freq_min lowest filter frequency
+  \param freq_max highest filter frequency
+
+*/
+aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
+
+/** destroy filterbank object
+
+  \param fb filterbank, as returned by new_aubio_filterbank method
+
+*/
+void del_aubio_filterbank(aubio_filterbank_t * fb);
+
+/** compute filterbank
+
+*/
+void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
+
+/** return the vector containing the filter coefficients of one channel
+
+ */
+fvec_t * aubio_filterbank_getchannel(aubio_filterbank_t * f, uint_t channel);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // FILTERBANK_H
Index: src/mfcc.c
===================================================================
--- src/mfcc.c	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
+++ src/mfcc.c	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -0,0 +1,124 @@
+/*
+   Copyright (C) 2006 Amaury Hazan
+   Ported to aubio from LibXtract
+   http://libxtract.sourceforge.net/
+   
+
+   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 "fft.h"
+#include "filterbank.h"
+#include "mfcc.h"
+#include "math.h"
+
+/** Internal structure for mfcc object **/
+
+struct aubio_mfcc_t_{
+  uint_t win_s;             /** grain length */
+  uint_t samplerate;        /** sample rate (needed?) */
+  uint_t channels;          /** number of channels */
+  uint_t n_filters;         /** number of  *filters */
+  uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
+  smpl_t lowfreq;           /** lowest frequency for filters */ 
+  smpl_t highfreq;          /** highest frequency for filters */
+  aubio_filterbank_t * fb;  /** filter bank */
+  fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
+  aubio_mfft_t * fft_dct;   /** fft object for dct */
+  cvec_t * fftgrain_dct;    /** output buffer for dct */
+};
+
+
+aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
+  /** allocating space for mfcc object */
+  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
+
+  //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
+  //uint_t n_filters = (n_coefs-1)*2;
+  
+  mfcc->win_s=win_s;
+  mfcc->samplerate=samplerate;
+  mfcc->channels=channels;
+  mfcc->n_filters=n_filters;
+  mfcc->n_coefs=n_coefs;
+  mfcc->lowfreq=lowfreq;
+  mfcc->highfreq=highfreq;
+
+  
+  /** filterbank allocation */
+  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(n_filters, 1);
+
+  /** allocating buffers */
+  mfcc->in_dct=new_fvec(mfcc->win_s, 1);
+  
+  mfcc->fftgrain_dct=new_cvec(n_filters, 1);
+
+  return mfcc;
+};
+
+void del_aubio_mfcc(aubio_mfcc_t *mf){
+  /** deleting filterbank */
+  del_aubio_filterbank(mf->fb);
+  /** deleting mfft object */
+  del_aubio_mfft(mf->fft_dct);
+  /** deleting buffers */
+  del_fvec(mf->in_dct);
+  del_cvec(mf->fftgrain_dct);
+  
+  /** deleting mfcc object */
+  AUBIO_FREE(mf);
+}
+
+
+/** intermediate dct involved in aubio_mfcc_do
+
+  \param mf mfcc object as returned by new_aubio_mfcc
+  \param in input spectrum (n_filters long)
+  \param out output mel coefficients buffer (n_filters/2 +1 long)
+
+*/
+void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
+
+void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
+    // 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
+    //for(n = filter + 1; n < N; n++) result[n] = 0; 
+    
+    aubio_dct_do(mf, mf->in_dct, out);
+
+    return;
+}
+
+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);
+    //extract real part of fft grain
+    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;
+}
+
Index: src/mfcc.h
===================================================================
--- src/mfcc.h	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
+++ src/mfcc.h	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -0,0 +1,67 @@
+/*
+   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
+                  and Paul Brossier <piem@piem.org>
+
+   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.
+
+*/
+
+/* part of this mfcc implementation were inspired from LibXtract
+   http://libxtract.sourceforge.net/
+*/
+
+#ifndef MFCC_H 
+#define MFCC_H 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "sample.h"
+#include "filterbank.h"
+
+typedef struct aubio_mfcc_t_ aubio_mfcc_t;
+
+/** create mfcc object
+
+  \param win_s size of analysis buffer (and length the FFT transform)
+  \param samplerate 
+  \param n_coefs: number of desired coefs
+  \param lowfreq: lowest frequency to use in filterbank
+  \param highfreq highest frequency to use in filterbank
+  \param channels number of channels
+
+*/
+aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
+/** delete mfcc object
+
+  \param mf mfcc object as returned by new_aubio_mfcc
+
+*/
+void del_aubio_mfcc(aubio_mfcc_t *mf);
+/** mfcc object processing
+
+  \param mf mfcc object as returned by new_aubio_mfcc
+  \param in input spectrum (win_s long)
+  \param out output mel coefficients buffer (n_filters/2 +1 long)
+
+*/
+void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // MFCC_H
Index: src/sample.c
===================================================================
--- src/sample.c	(revision e34b0101944dbd29c994deeabc481d7aa0032b9f)
+++ src/sample.c	(revision c1656cf8f471bd852affbd839abbfff6e7b8f210)
@@ -20,4 +20,5 @@
 #include "aubio_priv.h"
 #include "sample.h"
+
 
 fvec_t * new_fvec( uint_t length, uint_t channels) {
