Index: src/temporal/biquad.c
===================================================================
--- src/temporal/biquad.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/biquad.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,114 @@
+/*
+   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 "mathutils.h"
+#include "temporal/biquad.h"
+
+/** \note this file needs to be in double or more less precision would lead to large
+ * errors in the output 
+ */
+
+struct _aubio_biquad_t {
+  lsmp_t a2;
+  lsmp_t a3;
+  lsmp_t b1;
+  lsmp_t b2;
+  lsmp_t b3;
+  lsmp_t o1;
+  lsmp_t o2;
+  lsmp_t i1;
+  lsmp_t i2;
+};
+
+void aubio_biquad_do(aubio_biquad_t * b, fvec_t * in) {
+  uint_t i,j;
+  lsmp_t i1 = b->i1;
+  lsmp_t i2 = b->i2;
+  lsmp_t o1 = b->o1;
+  lsmp_t o2 = b->o2;
+  lsmp_t a2 = b->a2;
+  lsmp_t a3 = b->a3;
+  lsmp_t b1 = b->b1;
+  lsmp_t b2 = b->b2;
+  lsmp_t b3 = b->b3;
+
+  i=0; // works in mono only !!!
+  //for (i=0;i<in->channels;i++) {
+  for (j = 0; j < in->length; j++) {
+    lsmp_t i0 = in->data[i][j];
+    lsmp_t o0 = b1 * i0 + b2 * i1 + b3 * i2
+      - a2 * o1 - a3 * o2;// + 1e-37;
+    in->data[i][j] = o0;
+    i2 = i1;
+    i1 = i0;
+    o2 = o1;
+    o1 = o0;
+  }
+  b->i2 = i2;
+  b->i1 = i1;
+  b->o2 = o2;
+  b->o1 = o1;
+  //}
+}
+
+void aubio_biquad_do_filtfilt(aubio_biquad_t * b, fvec_t * in, fvec_t * tmp) {
+  uint_t j,i=0;
+  uint_t length = in->length;
+  lsmp_t mir;
+  /* mirroring */
+  mir = 2*in->data[i][0];
+  b->i1 = mir - in->data[i][2];
+  b->i2 = mir - in->data[i][1];
+  /* apply filtering */
+  aubio_biquad_do(b,in);
+  /* invert  */
+  for (j = 0; j < length; j++)
+    tmp->data[i][length-j-1] = in->data[i][j];
+  /* mirror again */
+  mir = 2*tmp->data[i][0];
+  b->i1 = mir - tmp->data[i][2];
+  b->i2 = mir - tmp->data[i][1];
+  /* apply filtering */
+  aubio_biquad_do(b,tmp);
+  /* invert back */
+  for (j = 0; j < length; j++)
+    in->data[i][j] = tmp->data[i][length-j-1];
+}
+
+aubio_biquad_t * new_aubio_biquad(
+    lsmp_t b1, lsmp_t b2, lsmp_t b3, 
+    lsmp_t a2, lsmp_t a3) {
+  aubio_biquad_t * b = AUBIO_NEW(aubio_biquad_t);
+  b->a2 = a2;
+  b->a3 = a3;
+  b->b1 = b1;
+  b->b2 = b2;
+  b->b3 = b3;
+  b->i1 = 0.;
+  b->i2 = 0.;
+  b->o1 = 0.;
+  b->o2 = 0.;
+  return b;
+}
+
+void del_aubio_biquad(aubio_biquad_t * b) {
+  AUBIO_FREE(b);
+}
Index: src/temporal/biquad.h
===================================================================
--- src/temporal/biquad.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/biquad.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,80 @@
+/*
+	 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.
+
+*/
+
+#ifndef BIQUAD_H
+#define BIQUAD_H
+
+/** \file 
+
+  Second order Infinite Impulse Response filter
+
+  This file implements a normalised biquad filter (second order IIR):
+ 
+  \f$ y[n] = b_1 x[n] + b_2 x[n-1] + b_3 x[n-2] - a_2 y[n-1] - a_3 y[n-2] \f$
+
+  The filtfilt version runs the filter twice, forward and backward, to
+  compensate the phase shifting of the forward operation.
+
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** biquad filter object */
+typedef struct _aubio_biquad_t aubio_biquad_t;
+
+/** filter input vector
+
+  \param b biquad object as returned by new_aubio_biquad
+  \param in input vector to filter
+
+*/
+void aubio_biquad_do(aubio_biquad_t * b, fvec_t * in);
+/** filter input vector forward and backward
+
+  \param b biquad object as returned by new_aubio_biquad
+  \param in input vector to filter
+  \param tmp memory space to use for computation
+
+*/
+void aubio_biquad_do_filtfilt(aubio_biquad_t * b, fvec_t * in, fvec_t * tmp);
+/** create new biquad filter
+
+  \param b1 forward filter coefficient
+  \param b2 forward filter coefficient
+  \param b3 forward filter coefficient
+  \param a2 feedback filter coefficient
+  \param a3 feedback filter coefficient
+
+*/
+aubio_biquad_t * new_aubio_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3);
+
+/** delete biquad filter 
+ 
+  \param b biquad object to delete 
+
+*/
+void del_aubio_biquad(aubio_biquad_t * b);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*BIQUAD_H*/
Index: src/temporal/filter.c
===================================================================
--- src/temporal/filter.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/filter.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,225 @@
+/*
+   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.
+
+*/
+
+
+/* Requires lsmp_t to be long or double. float will NOT give reliable 
+ * results */
+
+#include "aubio_priv.h"
+#include "sample.h"
+#include "mathutils.h"
+#include "temporal/filter.h"
+
+struct _aubio_filter_t {
+  uint_t order;
+  lsmp_t * a;
+  lsmp_t * b;
+  lsmp_t * y;
+  lsmp_t * x;
+};
+
+/* bug: mono only */
+void aubio_filter_do(aubio_filter_t * f, fvec_t * in) {
+  uint_t i,j,l, order = f->order;
+  lsmp_t *x = f->x;
+  lsmp_t *y = f->y;
+  lsmp_t *a = f->a;
+  lsmp_t *b = f->b;
+  i=0;//for (i=0;i<in->channels;i++) {
+  for (j = 0; j < in->length; j++) {
+    /* new input */
+    //AUBIO_DBG("befor %f\t", in->data[i][j]);
+    x[0] = in->data[i][j];
+    y[0] = b[0] * x[0];
+    for (l=1;l<order; l++) {
+      y[0] += b[l] * x[l];
+      y[0] -= a[l] * y[l];
+    } /* + 1e-37; for denormal ? */
+    /* new output */
+    in->data[i][j] = y[0];
+    //AUBIO_DBG("after %f\n", in->data[i][j]);
+    /* store states for next sample */
+    for (l=order-1; l>0; l--){
+      x[l] = x[l-1];
+      y[l] = y[l-1];
+    }
+  }
+  /* store states for next buffer */
+  f->x = x;
+  f->y = y;
+  //}	
+}
+
+void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out) {
+  uint_t i,j,l, order = f->order;
+  lsmp_t *x = f->x;
+  lsmp_t *y = f->y;
+  lsmp_t *a = f->a;
+  lsmp_t *b = f->b;
+
+  i=0; // works in mono only !!!
+  //for (i=0;i<in->channels;i++) {
+  for (j = 0; j < in->length; j++) {
+    /* new input */
+    x[0] = in->data[i][j];
+    y[0] = b[0] * x[0];
+    for (l=1;l<order; l++) {
+      y[0] += b[l] * x[l];
+      y[0] -= a[l] * y[l];
+    }
+    // + 1e-37;
+    /* new output */
+    out->data[i][j] = y[0];
+    /* store for next sample */
+    for (l=order-1; l>0; l--){
+      x[l] = x[l-1];
+      y[l] = y[l-1];
+    }
+  }
+  /* store for next run */
+  f->x = x;
+  f->y = y;
+  //}
+}
+
+/*  
+ *
+ * despite mirroring, end effects destroy both phse and amplitude. the longer
+ * the buffer, the less affected they are.
+ *
+ * replacing with zeros clicks.
+ *
+ * seems broken for order > 4 (see biquad_do_filtfilt for audible one) 
+ */
+void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp) {
+  uint_t j,i=0;
+  uint_t length = in->length;
+  //uint_t order = f->order;
+  //lsmp_t mir;
+  /* mirroring */
+  //mir = 2*in->data[i][0];
+  //for (j=1;j<order;j++)
+  //f->x[j] = 0.;//mir - in->data[i][order-j];
+  /* apply filtering */
+  aubio_filter_do(f,in);
+  /* invert */
+  for (j = 0; j < length; j++)
+    tmp->data[i][length-j-1] = in->data[i][j];
+  /* mirror inverted */
+  //mir = 2*tmp->data[i][0];
+  //for (j=1;j<order;j++)
+  //f->x[j] = 0.;//mir - tmp->data[i][order-j];
+  /* apply filtering on inverted */
+  aubio_filter_do(f,tmp);
+  /* invert back */
+  for (j = 0; j < length; j++)
+    in->data[i][j] = tmp->data[i][length-j-1];
+}
+
+
+aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate) {
+  aubio_filter_t * f = new_aubio_filter(samplerate, 7);
+  lsmp_t * a = f->a;
+  lsmp_t * b = f->b;
+  /* uint_t l; */
+  /* for now, 44100, adsgn */
+  a[0] =  1.00000000000000000000000000000000000000000000000000000; 
+  a[1] = -4.01957618111583236952810693765059113502502441406250000; 
+  a[2] =  6.18940644292069386267485242569819092750549316406250000; 
+  a[3] = -4.45319890354411640487342083360999822616577148437500000; 
+  a[4] =  1.42084294962187751565352300531230866909027099609375000; 
+  a[5] = -0.14182547383030480458998567883099894970655441284179688; 
+  a[6] =  0.00435117723349511334451911181986361043527722358703613; 
+  b[0] =  0.25574112520425740235907596797915175557136535644531250;
+  b[1] = -0.51148225040851391653973223583307117223739624023437500;
+  b[2] = -0.25574112520426162120656954357400536537170410156250000;
+  b[3] =  1.02296450081703405032840237254276871681213378906250000;
+  b[4] = -0.25574112520426051098354491841746494174003601074218750;
+  b[5] = -0.51148225040851369449512731080176308751106262207031250;
+  b[6] =  0.25574112520425729133677350546349771320819854736328125;
+  /* DBG: filter coeffs at creation time */
+  /*
+  for (l=0; l<f->order; l++){
+    AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
+  }
+  */
+  f->a = a;
+  f->b = b;
+  return f;
+}
+
+aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate) {
+  aubio_filter_t * f = new_aubio_filter(samplerate, 5);
+  lsmp_t * a = f->a;
+  lsmp_t * b = f->b;
+  /* uint_t l; */
+  /* for now, 44100, cdsgn */
+  a[0] =  1.000000000000000000000000000000000000000000000000000000000000; 
+  a[1] = -2.134674963687040794013682898366823792457580566406250000000000; 
+  a[2] =  1.279333533236063358273781886964570730924606323242187500000000; 
+  a[3] = -0.149559846089396208945743182994192466139793395996093750000000; 
+  a[4] =  0.004908700174624848651394604104325480875559151172637939453125; 
+  b[0] =  0.217008561949218803377448239189106971025466918945312500000000;
+  b[1] = -0.000000000000000222044604925031308084726333618164062500000000;
+  b[2] = -0.434017123898438272888711253472138196229934692382812500000000;
+  b[3] =  0.000000000000000402455846426619245903566479682922363281250000;
+  b[4] =  0.217008561949218969910901932962588034570217132568359375000000;
+  /* DBG: filter coeffs at creation time */
+  /*
+  for (l=0; l<f->order; l++){
+    AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
+  }
+  */
+  f->a = a;
+  f->b = b;
+  return f;
+}
+
+aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order) {
+  aubio_filter_t * f = AUBIO_NEW(aubio_filter_t);
+  lsmp_t * x = f->x;
+  lsmp_t * y = f->y;
+  lsmp_t * a = f->a;
+  lsmp_t * b = f->b;
+  uint_t l;
+  f->order = order;
+  a = AUBIO_ARRAY(lsmp_t,f->order);
+  b = AUBIO_ARRAY(lsmp_t,f->order);
+  x = AUBIO_ARRAY(lsmp_t,f->order);
+  y = AUBIO_ARRAY(lsmp_t,f->order);
+  /* initial states to zeros */
+  for (l=0; l<f->order; l++){
+    x[l] = 0.;
+    y[l] = 0.;
+  }
+  f->x = x;
+  f->y = y;
+  f->a = a;
+  f->b = b;
+  return f;
+}
+
+void del_aubio_filter(aubio_filter_t * f) {
+  AUBIO_FREE(f->a);
+  AUBIO_FREE(f->b);
+  AUBIO_FREE(f->x);
+  AUBIO_FREE(f->y);
+  AUBIO_FREE(f);
+  return;
+}
Index: src/temporal/filter.h
===================================================================
--- src/temporal/filter.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/filter.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,97 @@
+/*
+	 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.
+
+*/
+
+#ifndef FILTER_H
+#define FILTER_H
+
+/** \file 
+
+  Infinite Impulse Response filter
+
+  This file implements IIR filters of any order:
+ 
+  \f$ y[n] = b_1 x[n] + ... + b_{order} x[n-order] -
+       a_2 y[n-1] - ... - a_{order} y[n-order]\f$
+
+  The filtfilt version runs the filter twice, forward and backward, to
+  compensate the phase shifting of the forward operation.
+
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** IIR filter object */
+typedef struct _aubio_filter_t aubio_filter_t;
+
+/** filter input vector (in-place)
+
+  \param b biquad object as returned by new_aubio_biquad
+  \param in input vector to filter
+
+*/
+void aubio_filter_do(aubio_filter_t * b, fvec_t * in);
+/** filter input vector (out-of-place)
+
+  \param b biquad object as returned by new_aubio_biquad
+  \param in input vector to filter
+  \param out output vector to store filtered input
+
+*/
+void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out);
+/** filter input vector forward and backward
+
+  \param b biquad object as returned by new_aubio_biquad
+  \param in input vector to filter
+  \param tmp memory space to use for computation
+
+*/
+void aubio_filter_do_filtfilt(aubio_filter_t * b, fvec_t * in, fvec_t * tmp);
+/** create new IIR filter
+
+  \param samplerate signal sampling rate
+  \param order order of the filter (number of coefficients)
+
+*/
+aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order);
+/** create a new A-design filter 
+
+  \param samplerate sampling-rate of the signal to filter 
+
+*/
+aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate);
+/** create a new C-design filter 
+
+  \param samplerate sampling-rate of the signal to filter 
+
+*/
+aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate);
+/** delete a filter object
+ 
+  \param f filter object to delete
+
+*/
+void del_aubio_filter(aubio_filter_t * f);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*FILTER_H*/
Index: src/temporal/resample.c
===================================================================
--- src/temporal/resample.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/resample.c	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,65 @@
+/*
+	 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 <samplerate.h> /* from libsamplerate */
+
+#include "aubio_priv.h"
+#include "sample.h"
+#include "temporal/resample.h"
+
+struct _aubio_resampler_t {
+	SRC_DATA  *proc;
+	SRC_STATE *stat;
+	float ratio;
+	uint_t type;
+};
+
+aubio_resampler_t * new_aubio_resampler(float ratio, uint_t type) {
+	aubio_resampler_t * s  = AUBIO_NEW(aubio_resampler_t);
+	int error = 0;
+	s->stat = src_new (type, 1, &error) ; /* only one channel */
+	s->proc = AUBIO_NEW(SRC_DATA);
+	if (error) AUBIO_ERR("%s\n",src_strerror(error));
+	s->ratio = ratio;
+	return s;
+}
+
+void del_aubio_resampler(aubio_resampler_t *s) {
+	src_delete(s->stat);
+	AUBIO_FREE(s->proc);
+	AUBIO_FREE(s);
+}
+
+uint_t aubio_resampler_process(aubio_resampler_t *s, 
+    fvec_t * input,  fvec_t * output) {
+	uint_t i ;
+	s->proc->input_frames = input->length;
+	s->proc->output_frames = output->length;
+	s->proc->src_ratio = s->ratio;
+	for (i = 0 ; i< input->channels; i++) 
+	{
+		/* make SRC_PROC data point to input outputs */
+		s->proc->data_in = input->data[i];
+		s->proc->data_out= output->data[i];
+		/* do resampling */
+		src_process (s->stat, s->proc) ;
+	}
+	return AUBIO_OK;
+}	
Index: src/temporal/resample.h
===================================================================
--- src/temporal/resample.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
+++ src/temporal/resample.h	(revision 32d69586108e1d0e451655e0a0da51bbea9169d4)
@@ -0,0 +1,60 @@
+/*
+	 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.
+	 
+*/
+
+#ifndef _RESAMPLE_H
+#define _RESAMPLE_H
+
+/** \file
+ 
+ Resampling object
+
+ This object resamples an input vector into an output vector using
+ libsamplerate. See http://www.mega-nerd.com/SRC/
+ 
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** resampler object */
+typedef struct _aubio_resampler_t aubio_resampler_t;
+/** create resampler object 
+
+  \param ratio output_sample_rate / input_sample_rate 
+  \param type libsamplerate resampling type
+
+*/
+aubio_resampler_t * new_aubio_resampler(float ratio, uint_t type);
+/** delete resampler object */
+void del_aubio_resampler(aubio_resampler_t *s);
+/** resample input in output
+
+  \param s resampler object
+  \param input input buffer of size N
+  \param output output buffer of size N*ratio
+
+*/
+uint_t aubio_resampler_process(aubio_resampler_t *s, fvec_t * input,  fvec_t * output);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RESAMPLE_H */
