merge from banane
authorPaul Brossier <piem@piem.org>
Tue, 6 Nov 2007 10:53:50 +0000 (11:53 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 6 Nov 2007 10:53:50 +0000 (11:53 +0100)
33 files changed:
.bzrignore
python/aubio/aubioclass.py
src/Makefile.am
src/aubio_priv.h
src/cvec.c [new file with mode: 0644]
src/cvec.h [new file with mode: 0644]
src/fft.c
src/fft.h
src/fvec.c [new file with mode: 0644]
src/fvec.h [new file with mode: 0644]
src/phasevoc.c
src/sample.c [deleted file]
src/sample.h
tests/Makefile.am [new file with mode: 0644]
tests/list_missing_python_tests [deleted file]
tests/list_missing_tests [new file with mode: 0755]
tests/python/examples/README [new file with mode: 0644]
tests/python/examples/__init__.py [new file with mode: 0644]
tests/python/examples/aubionotes.py [new file with mode: 0644]
tests/python/examples/aubioonset.py [new file with mode: 0644]
tests/python/examples/aubiopitch.py [new file with mode: 0644]
tests/python/examples/aubiopitch/yinfft.16568_acclivity_TwoCows.wav.txt [new file with mode: 0644]
tests/python/examples/template.py [new file with mode: 0644]
tests/python/fft.py [new file with mode: 0644]
tests/python/fvec.py
tests/python/phasevoc.py [new file with mode: 0644]
tests/python/run_all_tests
tests/python/unittest_examples.py [new file with mode: 0644]
tests/src/Makefile.am
tests/src/test-cvec.c [new file with mode: 0644]
tests/src/test-fft.c
tests/src/test-fvec.c [new file with mode: 0644]
tests/src/test-sample.c [deleted file]

index 4fb10de..61312ec 100644 (file)
@@ -1,25 +1,44 @@
-*/Makefile.in
-*/*/Makefile.in
-*/*/*/Makefile.in
-*/Makefile
-*/*/Makefile
-*/*/*/Makefile
-*/.deps
-*/*/.deps
-*/*/*/.deps
-*/.libs
-*/*/.libs
-*/*/*/.libs
-*/*.lo
-*/*/*.lo
-*/*/*/*.lo
-*/*.la
+**/Makefile.in
+**/Makefile
+**/.deps
+**/.libs
+**/*.lo
+**/*.la
+
+# ignore compiled examples
+RE:examples/[a-z]*
+
+# ignore compiled test programs
+RE:tests/src/test-[a-z-]*$
+
+# ignore aubio
 plugins/puredata/aubio.pd_linux
-doc/aubiocut.1
-doc/aubionotes.1
-doc/aubioonset.1
-doc/aubiopitch.1
-doc/aubiotrack.1
+
+# only sgml manpages count
+doc/*.1
+
+# cachegrind/callgrind stuff
+**/cachegrind.out.[0-9]*
+**/callgrind.out.[0-9]*
+
+# autoreconf -f -i will create these
+INSTALL
+aclocal.m4
+aubio.pc
+autom4te.cache/
+compile
+config.guess
+config.log
+config.status
+config.sub
+configure
+depcomp
+install-sh
+libtool
+ltmain.sh
+missing
+py-compile
 src/config.h
 src/config.h.in
 src/stamp-h1
+
index 4269e29..b6e5be3 100644 (file)
@@ -42,8 +42,9 @@ class sndfile:
             self.file = new_aubio_sndfile_wo(model.file,filename)
         else:
             self.file = new_aubio_sndfile_ro(filename)
+        if self.file == None: raise(ValueError, "failed opening file")
     def __del__(self):
-        del_aubio_sndfile(self.file)
+        if self.file != None: del_aubio_sndfile(self.file)
     def info(self):
         aubio_sndfile_info(self.file)
     def samplerate(self):
index 1ca5d68..c57d72d 100644 (file)
@@ -5,6 +5,8 @@ pkginclude_HEADERS = aubio.h \
        mathutils.h \
        fft.h \
        sample.h \
+       fvec.h \
+       cvec.h \
        hist.h \
        scale.h \
        resample.h \
@@ -33,8 +35,10 @@ libaubio_la_SOURCES = aubio.h \
        mathutils.h \
        fft.c \
        fft.h \
-       sample.c \
-       sample.h \
+       fvec.c \
+       fvec.h \
+       cvec.c \
+       cvec.h \
        hist.c \
        hist.h \
        scale.c \
index d3504f7..299d24c 100644 (file)
@@ -1,20 +1,20 @@
 /*
-        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.
-        
+   Copyright (C) 2003-2007 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
  */
 
 /* Memory management */
-#define AUBIO_MALLOC(_n)               malloc(_n)
-#define AUBIO_REALLOC(_p,_n)           realloc(_p,_n)
-#define AUBIO_NEW(_t)                  (_t*)malloc(sizeof(_t))
-#define AUBIO_ARRAY(_t,_n)             (_t*)malloc((_n)*sizeof(_t))
-#define AUBIO_MEMCPY(_dst,_src,_n)     memcpy(_dst,_src,_n)
-#define AUBIO_MEMSET(_dst,_src,_t)     memset(_dst,_src,_t)
-#define AUBIO_FREE(_p)                 free(_p)        
+#define AUBIO_MALLOC(_n)             malloc(_n)
+#define AUBIO_REALLOC(_p,_n)         realloc(_p,_n)
+#define AUBIO_NEW(_t)                (_t*)malloc(sizeof(_t))
+#define AUBIO_ARRAY(_t,_n)           (_t*)malloc((_n)*sizeof(_t))
+#define AUBIO_MEMCPY(_dst,_src,_n)   memcpy(_dst,_src,_n)
+#define AUBIO_MEMSET(_dst,_src,_t)   memset(_dst,_src,_t)
+#define AUBIO_FREE(_p)               free(_p)
 
 
 /* file interface */
diff --git a/src/cvec.c b/src/cvec.c
new file mode 100644 (file)
index 0000000..74840db
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+   Copyright (C) 2003-2007 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 "cvec.h"
+
+cvec_t * new_cvec( uint_t length, uint_t channels) {
+  cvec_t * s = AUBIO_NEW(cvec_t);
+  uint_t i,j;
+  s->channels = channels;
+  s->length = length/2 + 1;
+  s->norm = AUBIO_ARRAY(smpl_t*,s->channels);
+  s->phas = AUBIO_ARRAY(smpl_t*,s->channels);
+  for (i=0; i< s->channels; i++) {
+    s->norm[i] = AUBIO_ARRAY(smpl_t,s->length);
+    s->phas[i] = AUBIO_ARRAY(smpl_t,s->length);
+    for (j=0; j< s->length; j++) {
+      s->norm[i][j]=0.;
+      s->phas[i][j]=0.;
+    }
+  }
+  return s;
+}
+
+void del_cvec(cvec_t *s) {
+  uint_t i;
+  for (i=0; i<s->channels; i++) {
+    AUBIO_FREE(s->norm[i]);
+    AUBIO_FREE(s->phas[i]);
+  }
+  AUBIO_FREE(s->norm);
+  AUBIO_FREE(s->phas);
+  AUBIO_FREE(s);
+}
+
+void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
+  s->norm[channel][position] = data;
+}
+void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
+  s->phas[channel][position] = data;
+}
+smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) {
+  return s->norm[channel][position];
+}
+smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) {
+  return s->phas[channel][position];
+}
+void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) {
+  s->norm[channel] = data;
+}
+void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) {
+  s->phas[channel] = data;
+}
+smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) {
+  return s->norm[channel];
+}
+smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) {
+  return s->phas[channel];
+}
+smpl_t ** cvec_get_norm(cvec_t *s) {
+  return s->norm;
+}
+smpl_t ** cvec_get_phas(cvec_t *s) {
+  return s->phas;
+}
+
diff --git a/src/cvec.h b/src/cvec.h
new file mode 100644 (file)
index 0000000..1029d89
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+   Copyright (C) 2003-2007 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.
+
+*/
+
+#ifndef _CVEC_H
+#define _CVEC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file
+
+  Real and complex buffers
+
+  This file specifies the cvec_t buffer type, which is used throughout aubio to
+  store complex data. Complex values are stored in terms of phase and
+  norm, within size/2+1 long vectors.
+
+*/
+
+/** Spectrum buffer type */
+typedef struct _cvec_t cvec_t;
+/** Buffer for complex data */
+struct _cvec_t {
+  uint_t length;   /**< length of buffer = (requested length)/2 + 1 */
+  uint_t channels; /**< number of channels */
+  smpl_t **norm;   /**< norm array of size [length] * [channels] */
+  smpl_t **phas;   /**< phase array of size [length] * [channels] */
+};
+
+/** cvec_t buffer creation function
+
+  This function creates a cvec_t structure holding two arrays of size
+  [length/2+1] * channels, corresponding to the norm and phase values of the
+  spectral frame. The length stored in the structure is the actual size of both
+  arrays, not the length of the complex and symetrical vector, specified as
+  creation argument.
+
+  \param length the length of the buffer to create
+  \param channels the number of channels in the buffer
+
+*/
+cvec_t * new_cvec(uint_t length, uint_t channels);
+/** cvec_t buffer deletion function
+
+  \param s buffer to delete as returned by new_cvec()
+
+*/
+void del_cvec(cvec_t *s);
+/** write norm value in a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->norm[channel][position]. Its purpose
+  is to access these values from wrappers, as created by swig.
+
+  \param s vector to write to 
+  \param data norm value to write in s->norm[channel][position]
+  \param channel channel to write to 
+  \param position sample position to write to
+
+*/
+void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
+/** write phase value in a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->phas[channel][position]. Its purpose
+  is to access these values from wrappers, as created by swig.
+
+  \param s vector to write to
+  \param data phase value to write in s->phas[channel][position]
+  \param channel channel to write to
+  \param position sample position to write to
+
+*/
+void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
+/** read norm value from a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->norm[channel][position]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to read from
+  \param channel channel to read from
+  \param position sample position to read from
+
+*/
+smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
+/** read phase value from a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->phas[channel][position]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to read from
+  \param channel channel to read from
+  \param position sample position to read from
+
+*/
+smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
+/** write norm channel in a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->norm[channel]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to write to
+  \param data norm vector of [length] samples to write in s->norm[channel]
+  \param channel channel to write to
+
+*/
+void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
+/** write phase channel in a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->phas[channel]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to write to
+  \param data phase vector of [length] samples to write in s->phas[channel]
+  \param channel channel to write to
+
+*/
+void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
+/** read norm channel from a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->norm[channel]. Its purpose is to access
+  these values from wrappers, as created by swig.
+
+  \param s vector to read from 
+  \param channel channel to read from
+
+*/
+smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
+/** write phase channel in a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->phas[channel]. Its purpose is to access
+  these values from wrappers, as created by swig.
+
+  \param s vector to read from 
+  \param channel channel to read from 
+
+*/
+smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
+/** read norm data from a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->norm. Its purpose is to access these values
+  from wrappers, as created by swig.
+
+  \param s vector to read from
+
+*/
+smpl_t ** cvec_get_norm(cvec_t *s);
+/** read phase data from a complex buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->phas. Its purpose is to access these values
+  from wrappers, as created by swig.
+
+  \param s vector to read from
+
+*/
+smpl_t ** cvec_get_phas(cvec_t *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CVEC_H */
+
index 37c7cb9..e5c1a03 100644 (file)
--- a/src/fft.c
+++ b/src/fft.c
 #include "fft.h"
 
 #if FFTW3F_SUPPORT
-#define fftw_malloc            fftwf_malloc
-#define fftw_free              fftwf_free
-#define fftw_execute           fftwf_execute
-#define fftw_plan_dft_r2c_1d   fftwf_plan_dft_r2c_1d
-#define fftw_plan_dft_c2r_1d   fftwf_plan_dft_c2r_1d
-#define fftw_plan_r2r_1d      fftwf_plan_r2r_1d
-#define fftw_plan              fftwf_plan
-#define fftw_destroy_plan      fftwf_destroy_plan
+#define fftw_malloc            fftwf_malloc
+#define fftw_free              fftwf_free
+#define fftw_execute           fftwf_execute
+#define fftw_plan_dft_r2c_1d   fftwf_plan_dft_r2c_1d
+#define fftw_plan_dft_c2r_1d   fftwf_plan_dft_c2r_1d
+#define fftw_plan_r2r_1d       fftwf_plan_r2r_1d
+#define fftw_plan              fftwf_plan
+#define fftw_destroy_plan      fftwf_destroy_plan
 #endif
 
 #if FFTW3F_SUPPORT
 #endif
 
 struct _aubio_fft_t {
-       uint_t fft_size;
-       uint_t channels;
-       real_t          *in, *out;
-       fft_data_t      *specdata;
-       fftw_plan       pfw, pbw;
+  uint_t fft_size;
+  uint_t channels;
+  real_t    *in, *out;
+  fft_data_t   *specdata;
+  fftw_plan   pfw, pbw;
 };
 
 static void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size);
 
 aubio_fft_t * new_aubio_fft(uint_t size) {
-       aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
-       /* allocate memory */
-       s->in       = AUBIO_ARRAY(real_t,size);
-       s->out      = AUBIO_ARRAY(real_t,size);
-       s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
-       /* create plans */
+  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
+  /* allocate memory */
+  s->in       = AUBIO_ARRAY(real_t,size);
+  s->out      = AUBIO_ARRAY(real_t,size);
+  /* create plans */
 #ifdef HAVE_COMPLEX_H
-       s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
-       s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
+  s->fft_size = size/2+1;
+  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
+  s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
+  s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
 #else
-       s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
-       s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
+  s->fft_size = size;
+  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
+  s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
+  s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
 #endif
-       return s;
+  return s;
 }
 
 void del_aubio_fft(aubio_fft_t * s) {
-       /* destroy data */
-       fftw_destroy_plan(s->pfw);
-       fftw_destroy_plan(s->pbw);
-       fftw_free(s->specdata);
-       AUBIO_FREE(s->out);
-       AUBIO_FREE(s->in );
-       AUBIO_FREE(s);
+  /* destroy data */
+  fftw_destroy_plan(s->pfw);
+  fftw_destroy_plan(s->pbw);
+  fftw_free(s->specdata);
+  AUBIO_FREE(s->out);
+  AUBIO_FREE(s->in );
+  AUBIO_FREE(s);
 }
 
 void aubio_fft_do(const aubio_fft_t * s, 
-               const smpl_t * data, fft_data_t * spectrum, 
-               const uint_t size) {
-       uint_t i;
-       for (i=0;i<size;i++) s->in[i] = data[i];
-       fftw_execute(s->pfw);
-       for (i=0;i<size;i++) spectrum[i] = s->specdata[i];
+    const smpl_t * data, fft_data_t * spectrum, const uint_t size) {
+  uint_t i;
+  for (i=0;i<size;i++) s->in[i] = data[i];
+  fftw_execute(s->pfw);
+  for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i];
 }
 
 void aubio_fft_rdo(const aubio_fft_t * s, 
-               const fft_data_t * spectrum, 
-               smpl_t * data, 
-               const uint_t size) {
-       uint_t i;
-       const smpl_t renorm = 1./(smpl_t)size;
-       for (i=0;i<size;i++) s->specdata[i] = spectrum[i];
-       fftw_execute(s->pbw);
-       for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
+    const fft_data_t * spectrum, smpl_t * data, const uint_t size) {
+  uint_t i;
+  const smpl_t renorm = 1./(smpl_t)size;
+  for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i];
+  fftw_execute(s->pbw);
+  for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
 }
 
 #ifdef HAVE_COMPLEX_H
 
 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
-       uint_t i;
-       for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
-       //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
+  uint_t i;
+  for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
 }
 
 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
-       uint_t i;
-       for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
-       //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
+  uint_t i;
+  for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
 }
 
 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
@@ -121,17 +119,17 @@ void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, u
 #else
 
 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
-       uint_t i;
-  norm[0] = -spectrum[0];
-       for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i]));
-       //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
+  uint_t i;
+  norm[0] = spectrum[0];
+  for (i=1;i<size/2;i++) norm[i] = SQRT((SQR(spectrum[i]) + SQR(spectrum[size-i])));
+  norm[size/2] = spectrum[size/2];
 }
 
 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
-       uint_t i;
-  phas[0] = PI;
-       for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
-       //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
+  uint_t i;
+  phas[0] = 0;
+  for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
+  phas[size/2] = 0;
 }
 
 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
@@ -155,43 +153,43 @@ struct _aubio_mfft_t {
 };
 
 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){
-        uint_t i;
-       aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
-       fft->winsize       = winsize;
-       fft->channels      = channels;
-       fft->fft           = new_aubio_fft(winsize);
-       fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
-        for (i=0; i < channels; i++)
-                fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
-        return fft;
+  uint_t i;
+  aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
+  fft->winsize       = winsize;
+  fft->channels      = channels;
+  fft->fft           = new_aubio_fft(winsize);
+  fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
+  for (i=0; i < channels; i++)
+    fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
+  return fft;
 }
 
 /* execute stft */
 void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){
-        uint_t i=0;
-        /* execute stft */
-        for (i=0; i < fft->channels; i++) {
-                aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
-                /* put norm and phase into fftgrain */
-                aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
-                aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
-        }
+  uint_t i=0;
+  /* execute stft */
+  for (i=0; i < fft->channels; i++) {
+    aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
+    /* put norm and phase into fftgrain */
+    aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
+    aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
+  }
 }
 
 /* execute inverse fourier transform */
 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
-        uint_t i=0;
-        for (i=0; i < fft->channels; i++) {
-                aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
-                aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
-        }
+  uint_t i=0;
+  for (i=0; i < fft->channels; i++) {
+    aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
+    aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
+  }
 }
 
 void del_aubio_mfft(aubio_mfft_t * fft) {
-        uint_t i;
-        for (i=0; i < fft->channels; i++)
-                AUBIO_FREE(fft->spec[i]);
-        AUBIO_FREE(fft->spec);
-        del_aubio_fft(fft->fft);
-        AUBIO_FREE(fft);        
+  uint_t i;
+  for (i=0; i < fft->channels; i++)
+    AUBIO_FREE(fft->spec[i]);
+  AUBIO_FREE(fft->spec);
+  del_aubio_fft(fft->fft);
+  AUBIO_FREE(fft);        
 }
index a2abeca..72187eb 100644 (file)
--- a/src/fft.h
+++ b/src/fft.h
@@ -1,20 +1,20 @@
 /*
-        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.
-        
+   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 
diff --git a/src/fvec.c b/src/fvec.c
new file mode 100644 (file)
index 0000000..941830b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+   Copyright (C) 2003-2007 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"
+
+fvec_t * new_fvec( uint_t length, uint_t channels) {
+  fvec_t * s = AUBIO_NEW(fvec_t);
+  uint_t i,j;
+  s->channels = channels;
+  s->length = length;
+  s->data = AUBIO_ARRAY(smpl_t*,s->channels);
+  for (i=0; i< s->channels; i++) {
+    s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
+    for (j=0; j< s->length; j++) {
+      s->data[i][j]=0.;
+    }
+  }
+  return s;
+}
+
+void del_fvec(fvec_t *s) {
+  uint_t i;
+  for (i=0; i<s->channels; i++) {
+    AUBIO_FREE(s->data[i]);
+  }
+  AUBIO_FREE(s->data);
+  AUBIO_FREE(s);
+}
+
+void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
+  s->data[channel][position] = data;
+}
+smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
+  return s->data[channel][position];
+}
+void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
+  s->data[channel] = data;
+}
+smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
+  return s->data[channel];
+}
+
+smpl_t ** fvec_get_data(fvec_t *s) {
+  return s->data;
+}
+
diff --git a/src/fvec.h b/src/fvec.h
new file mode 100644 (file)
index 0000000..1d78852
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+   Copyright (C) 2003-2007 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.
+
+*/
+
+#ifndef _FVEC_H
+#define _FVEC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file
+
+  Real buffers
+
+  This file specifies the fvec_t buffer type, which is used throughout aubio to
+  store real data.
+
+*/
+
+/** Sample buffer type */
+typedef struct _fvec_t fvec_t;
+/** Buffer for real values */
+struct _fvec_t {
+  uint_t length;   /**< length of buffer */
+  uint_t channels; /**< number of channels */
+  smpl_t **data;   /**< data array of size [length] * [channels] */
+};
+/** fvec_t buffer creation function
+
+  \param length the length of the buffer to create
+  \param channels the number of channels in the buffer
+
+*/
+fvec_t * new_fvec(uint_t length, uint_t channels);
+/** fvec_t buffer deletion function
+
+  \param s buffer to delete as returned by new_fvec()
+
+*/
+void del_fvec(fvec_t *s);
+/** read sample value in a buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained using vec->data[channel][position]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to read from
+  \param channel channel to read from
+  \param position sample position to read from 
+
+*/
+smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
+/** write sample value in a buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->data[channel][position]. Its purpose
+  is to access these values from wrappers, as created by swig.
+
+  \param s vector to write to 
+  \param data value to write in s->data[channel][position]
+  \param channel channel to write to 
+  \param position sample position to write to 
+
+*/
+void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
+/** read channel vector from a buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->data[channel]. Its purpose is to access
+  these values from wrappers, as created by swig.
+
+  \param s vector to read from
+  \param channel channel to read from
+
+*/
+smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
+/** write channel vector into a buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained by assigning vec->data[channel]. Its purpose is to
+  access these values from wrappers, as created by swig.
+
+  \param s vector to write to 
+  \param data vector of [length] values to write
+  \param channel channel to write to 
+
+*/
+void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
+/** read data from a buffer
+
+  Note that this function is not used in the aubio library, since the same
+  result can be obtained with vec->data. Its purpose is to access these values
+  from wrappers, as created by swig.
+
+  \param s vector to read from
+
+*/
+smpl_t ** fvec_get_data(fvec_t *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FVEC_H */
index 8eeaef8..6fdf6cf 100644 (file)
 
 /** phasevocoder internal object */
 struct _aubio_pvoc_t {
-       /** grain length */
-       uint_t win_s;
-       /** overlap step */
-       uint_t hop_s;
-       /** number of channels */
-       uint_t channels;
-       /** spectral data */
-       aubio_mfft_t * fft;
-       /**cur output grain             [win_s] */
-       fvec_t * synth;          
-       /**last input frame             [win_s-hop_s] */
-       fvec_t * synthold; 
-       /**current input grain          [win_s] */
-       fvec_t * data;           
-       /**last input frame             [win_s-hop_s] */
-       fvec_t * dataold;  
-       /** grain window                [win_s] */
-       float * w;
+  uint_t win_s;       /** grain length */
+  uint_t hop_s;       /** overlap step */
+  uint_t channels;    /** number of channels */
+  aubio_mfft_t * fft; /** spectral data */
+  fvec_t * synth;     /**cur output grain [win_s] */
+  fvec_t * synthold;  /**last input frame [win_s-hop_s] */
+  fvec_t * data;      /**current input grain [win_s] */
+  fvec_t * dataold;   /**last input frame [win_s-hop_s] */
+  smpl_t * w;          /** grain window [win_s] */
 };
 
 
 /** returns data and dataold slided by hop_s */
-static void aubio_pvoc_swapbuffers(
-               smpl_t * data,
-               smpl_t * dataold,
-               const smpl_t * datanew,
-               uint_t win_s, uint_t hop_s);
-/** do additive synthesis from 'old' and 'cur' */
-static void aubio_pvoc_addsynth(
-               const smpl_t * synth,
-               smpl_t * synthold,
-               smpl_t * synthnew, 
-               uint_t win_s, uint_t hop_s);
+static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const
+    smpl_t * datanew, uint_t win_s, uint_t hop_s);
 
+/** do additive synthesis from 'old' and 'cur' */
+static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
+    smpl_t * synthnew, uint_t win_s, uint_t hop_s);
 
 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
-       uint_t i,j;
-       for (i=0; i<pv->channels; i++) {
-               /* slide  */
-               aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
-                               datanew->data[i],pv->win_s,pv->hop_s);
-               /* windowing */
-               for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
-        }
-        /* shift */
-        vec_shift(pv->data);
-       /* calculate fft */
-        aubio_mfft_do (pv->fft,pv->data,fftgrain);
+  uint_t i,j;
+  for (i=0; i<pv->channels; i++) {
+    /* slide  */
+    aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
+        datanew->data[i],pv->win_s,pv->hop_s);
+    /* windowing */
+    for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
+  }
+  /* shift */
+  vec_shift(pv->data);
+  /* calculate fft */
+  aubio_mfft_do (pv->fft,pv->data,fftgrain);
 }
 
 void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
-       uint_t i,j;
-       /* calculate rfft */
-        aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
-        /* unshift */
-        vec_shift(pv->synth);
-       for (i=0; i<pv->channels; i++) {
-               for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j];
-               aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
-                               synthnew->data[i],pv->win_s,pv->hop_s);
-       }
+  uint_t i;
+  /* calculate rfft */
+  aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
+  /* unshift */
+  vec_shift(pv->synth);
+  for (i=0; i<pv->channels; i++) {
+    aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
+        synthnew->data[i],pv->win_s,pv->hop_s);
+  }
 }
 
 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
-       aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
-
-       if (win_s < 2*hop_s) {
-               AUBIO_ERR("Hop size bigger than half the window size!\n");
-               AUBIO_ERR("Resetting hop size to half the window size.\n");
-                hop_s = win_s / 2;
-       }
-
-       if (hop_s < 1) {
-               AUBIO_ERR("Hop size is smaller than 1!\n");
-               AUBIO_ERR("Resetting hop size to half the window size.\n");
-                hop_s = win_s / 2;
-       }
-       
-       pv->fft      = new_aubio_mfft(win_s,channels);
-
-       /* remember old */
-       pv->data     = new_fvec (win_s, channels);
-       pv->synth    = new_fvec (win_s, channels);
-
-       /* new input output */
-       pv->dataold  = new_fvec  (win_s-hop_s, channels);
-       pv->synthold = new_fvec (win_s-hop_s, channels);
-       pv->w        = AUBIO_ARRAY(smpl_t,win_s);
-       aubio_window(pv->w,win_s,aubio_win_hanningz);
-
-       pv->channels = channels;
-       pv->hop_s    = hop_s;
-       pv->win_s    = win_s;
-
-       return pv;
+  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
+
+  if (win_s < 2*hop_s) {
+    AUBIO_ERR("Hop size bigger than half the window size!\n");
+    AUBIO_ERR("Resetting hop size to half the window size.\n");
+    hop_s = win_s / 2;
+  }
+
+  if (hop_s < 1) {
+    AUBIO_ERR("Hop size is smaller than 1!\n");
+    AUBIO_ERR("Resetting hop size to half the window size.\n");
+    hop_s = win_s / 2;
+  }
+
+  pv->fft      = new_aubio_mfft(win_s,channels);
+
+  /* remember old */
+  pv->data     = new_fvec (win_s, channels);
+  pv->synth    = new_fvec (win_s, channels);
+
+  /* new input output */
+  pv->dataold  = new_fvec  (win_s-hop_s, channels);
+  pv->synthold = new_fvec (win_s-hop_s, channels);
+  pv->w        = AUBIO_ARRAY(smpl_t,win_s);
+  aubio_window(pv->w,win_s,aubio_win_hanningz);
+
+  pv->channels = channels;
+  pv->hop_s    = hop_s;
+  pv->win_s    = win_s;
+
+  return pv;
 }
 
 void del_aubio_pvoc(aubio_pvoc_t *pv) {
-       del_fvec(pv->data);
-       del_fvec(pv->synth);
-       del_fvec(pv->dataold);
-       del_fvec(pv->synthold);
-       del_aubio_mfft(pv->fft);
-       AUBIO_FREE(pv->w);
-       AUBIO_FREE(pv);
+  del_fvec(pv->data);
+  del_fvec(pv->synth);
+  del_fvec(pv->dataold);
+  del_fvec(pv->synthold);
+  del_aubio_mfft(pv->fft);
+  AUBIO_FREE(pv->w);
+  AUBIO_FREE(pv);
 }
 
 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, 
-                const smpl_t * datanew, uint_t win_s, uint_t hop_s)
+    const smpl_t * datanew, uint_t win_s, uint_t hop_s)
 {
-       uint_t i;
-       for (i=0;i<win_s-hop_s;i++)
-               data[i] = dataold[i];
-       for (i=0;i<hop_s;i++)
-               data[win_s-hop_s+i] = datanew[i];
-       for (i=0;i<win_s-hop_s;i++)
-               dataold[i] = data[i+hop_s];
+  uint_t i;
+  for (i=0;i<win_s-hop_s;i++)
+    data[i] = dataold[i];
+  for (i=0;i<hop_s;i++)
+    data[win_s-hop_s+i] = datanew[i];
+  for (i=0;i<win_s-hop_s;i++)
+    dataold[i] = data[i+hop_s];
 }
 
 static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold, 
                 smpl_t * synthnew, uint_t win_s, uint_t hop_s)
 {
-       uint_t i;
-       smpl_t scale = 2*hop_s/(win_s+.0);
-       /* add new synth to old one and put result in synthnew */
-       for (i=0;i<hop_s;i++)                                           
-               synthnew[i] = synthold[i]+synth[i]*scale;
-       /* shift synthold */
-       for (i=0;i<win_s-2*hop_s;i++)   
-               synthold[i] = synthold[i+hop_s];
-       /* erase last frame in synthold */
-       for (i=win_s-hop_s;i<win_s;i++) 
-               synthold[i-hop_s]=0.;
-       /* additive synth */
-       for (i=0;i<win_s-hop_s;i++)     
-               synthold[i] += synth[i+hop_s]*scale;
+  uint_t i;
+  smpl_t scale = 2*hop_s/(win_s+.0);
+  /* add new synth to old one and put result in synthnew */
+  for (i=0;i<hop_s;i++)
+    synthnew[i] = synthold[i]+synth[i]*scale;
+  /* shift synthold */
+  for (i=0;i<win_s-2*hop_s;i++)
+    synthold[i] = synthold[i+hop_s];
+  /* erase last frame in synthold */
+  for (i=win_s-hop_s;i<win_s;i++)
+    synthold[i-hop_s]=0.;
+  /* additive synth */
+  for (i=0;i<win_s-hop_s;i++)
+    synthold[i] += synth[i+hop_s]*scale;
 }
 
diff --git a/src/sample.c b/src/sample.c
deleted file mode 100644 (file)
index c85694a..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
-   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"
-
-fvec_t * new_fvec( uint_t length, uint_t channels) {
-  fvec_t * s = AUBIO_NEW(fvec_t);
-  uint_t i,j;
-  s->channels = channels;
-  s->length = length;
-  s->data = AUBIO_ARRAY(smpl_t*,s->channels);
-  for (i=0; i< s->channels; i++) {
-    s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
-    for (j=0; j< s->length; j++) {
-      s->data[i][j]=0.;
-    }
-  }
-  return s;
-}
-
-void del_fvec(fvec_t *s) {
-  uint_t i;
-  for (i=0; i<s->channels; i++) {
-    AUBIO_FREE(s->data[i]);
-  }
-  AUBIO_FREE(s->data);
-  AUBIO_FREE(s);
-}
-
-void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
-  s->data[channel][position] = data;
-}
-smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
-  return s->data[channel][position];
-}
-void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
-  s->data[channel] = data;
-}
-smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
-  return s->data[channel];
-}
-
-smpl_t ** fvec_get_data(fvec_t *s) {
-  return s->data;
-}
-
-cvec_t * new_cvec( uint_t length, uint_t channels) {
-  cvec_t * s = AUBIO_NEW(cvec_t);
-  uint_t i,j;
-  s->channels = channels;
-  s->length = length/2 + 1;
-  s->norm = AUBIO_ARRAY(smpl_t*,s->channels);
-  s->phas = AUBIO_ARRAY(smpl_t*,s->channels);
-  for (i=0; i< s->channels; i++) {
-    s->norm[i] = AUBIO_ARRAY(smpl_t,s->length);
-    s->phas[i] = AUBIO_ARRAY(smpl_t,s->length);
-    for (j=0; j< s->length; j++) {
-      s->norm[i][j]=0.;
-      s->phas[i][j]=0.;
-    }
-  }
-  return s;
-}
-
-void del_cvec(cvec_t *s) {
-  uint_t i;
-  for (i=0; i<s->channels; i++) {
-    AUBIO_FREE(s->norm[i]);
-    AUBIO_FREE(s->phas[i]);
-  }
-  AUBIO_FREE(s->norm);
-  AUBIO_FREE(s->phas);
-  AUBIO_FREE(s);
-}
-
-void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
-  s->norm[channel][position] = data;
-}
-void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
-  s->phas[channel][position] = data;
-}
-smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) {
-  return s->norm[channel][position];
-}
-smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) {
-  return s->phas[channel][position];
-}
-void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) {
-  s->norm[channel] = data;
-}
-void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) {
-  s->phas[channel] = data;
-}
-smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) {
-  return s->norm[channel];
-}
-smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) {
-  return s->phas[channel];
-}
-smpl_t ** cvec_get_norm(cvec_t *s) {
-  return s->norm;
-}
-smpl_t ** cvec_get_phas(cvec_t *s) {
-  return s->phas;
-}
index 13ac31d..c8b03fb 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2003 Paul Brossier
+   Copyright (C) 2003-2007 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
 #ifndef _SAMPLE_H
 #define _SAMPLE_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** \file
-
-  Real and complex buffers
-
-  This file specifies fvec_t and cvec_t buffers types, which are used
-  throughout aubio to store real and complex data. Complex values are stored in
-  terms of phase and norm.
-
-*/
-
-/** Sample buffer type */
-typedef struct _fvec_t fvec_t;
-/** Spectrum buffer type */
-typedef struct _cvec_t cvec_t;
-/** Buffer for real values */
-struct _fvec_t {
-  uint_t length;   /**< length of buffer */
-  uint_t channels; /**< number of channels */
-  smpl_t **data;   /**< data array of size [length] * [channels] */
-};
-/** Buffer for complex data */
-struct _cvec_t {
-  uint_t length;   /**< length of buffer = (requested length)/2 + 1 */
-  uint_t channels; /**< number of channels */
-  smpl_t **norm;   /**< norm array of size [length] * [channels] */
-  smpl_t **phas;   /**< phase array of size [length] * [channels] */
-};
-/** fvec_t buffer creation function
-
-  \param length the length of the buffer to create
-  \param channels the number of channels in the buffer
-
-*/
-fvec_t * new_fvec(uint_t length, uint_t channels);
-/** fvec_t buffer deletion function
-
-  \param s buffer to delete as returned by new_fvec()
-
-*/
-void del_fvec(fvec_t *s);
-/** read sample value in a buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained using vec->data[channel][position]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to read from
-  \param channel channel to read from
-  \param position sample position to read from 
-
-*/
-smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
-/** write sample value in a buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->data[channel][position]. Its purpose
-  is to access these values from wrappers, as created by swig.
-
-  \param s vector to write to 
-  \param data value to write in s->data[channel][position]
-  \param channel channel to write to 
-  \param position sample position to write to 
-
-*/
-void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
-/** read channel vector from a buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->data[channel]. Its purpose is to access
-  these values from wrappers, as created by swig.
-
-  \param s vector to read from
-  \param channel channel to read from
-
-*/
-smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
-/** write channel vector into a buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->data[channel]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to write to 
-  \param data vector of [length] values to write
-  \param channel channel to write to 
-
-*/
-void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
-/** read data from a buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->data. Its purpose is to access these values
-  from wrappers, as created by swig.
-
-  \param s vector to read from
-
-*/
-smpl_t ** fvec_get_data(fvec_t *s);
-
-/** cvec_t buffer creation function
-
-  This function creates a cvec_t structure holding two arrays of size
-  [length/2+1] * channels, corresponding to the norm and phase values of the
-  spectral frame. The length stored in the structure is the actual size of both
-  arrays, not the length of the complex and symetrical vector, specified as
-  creation argument.
-
-  \param length the length of the buffer to create
-  \param channels the number of channels in the buffer
-
-*/
-cvec_t * new_cvec(uint_t length, uint_t channels);
-/** cvec_t buffer deletion function
-
-  \param s buffer to delete as returned by new_cvec()
-
-*/
-void del_cvec(cvec_t *s);
-/** write norm value in a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->norm[channel][position]. Its purpose
-  is to access these values from wrappers, as created by swig.
-
-  \param s vector to write to 
-  \param data norm value to write in s->norm[channel][position]
-  \param channel channel to write to 
-  \param position sample position to write to
-
-*/
-void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
-/** write phase value in a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->phas[channel][position]. Its purpose
-  is to access these values from wrappers, as created by swig.
-
-  \param s vector to write to
-  \param data phase value to write in s->phas[channel][position]
-  \param channel channel to write to
-  \param position sample position to write to
-
-*/
-void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
-/** read norm value from a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->norm[channel][position]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to read from
-  \param channel channel to read from
-  \param position sample position to read from
-
-*/
-smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
-/** read phase value from a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->phas[channel][position]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to read from
-  \param channel channel to read from
-  \param position sample position to read from
-
-*/
-smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
-/** write norm channel in a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->norm[channel]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to write to
-  \param data norm vector of [length] samples to write in s->norm[channel]
-  \param channel channel to write to
-
-*/
-void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
-/** write phase channel in a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained by assigning vec->phas[channel]. Its purpose is to
-  access these values from wrappers, as created by swig.
-
-  \param s vector to write to
-  \param data phase vector of [length] samples to write in s->phas[channel]
-  \param channel channel to write to
-
-*/
-void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
-/** read norm channel from a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->norm[channel]. Its purpose is to access
-  these values from wrappers, as created by swig.
-
-  \param s vector to read from 
-  \param channel channel to read from
-
-*/
-smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
-/** write phase channel in a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->phas[channel]. Its purpose is to access
-  these values from wrappers, as created by swig.
-
-  \param s vector to read from 
-  \param channel channel to read from 
-
-*/
-smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
-/** read norm data from a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->norm. Its purpose is to access these values
-  from wrappers, as created by swig.
-
-  \param s vector to read from
-
-*/
-smpl_t ** cvec_get_norm(cvec_t *s);
-/** read phase data from a complex buffer
-
-  Note that this function is not used in the aubio library, since the same
-  result can be obtained with vec->phas. Its purpose is to access these values
-  from wrappers, as created by swig.
-
-  \param s vector to read from
-
-*/
-smpl_t ** cvec_get_phas(cvec_t *s);
-
-#ifdef __cplusplus
-}
-#endif
+#include "fvec.h"
+#include "cvec.h"
 
 #endif /* _SAMPLE_H */
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..c72fea3
--- /dev/null
@@ -0,0 +1,3 @@
+if COMPILE_TESTS 
+SUBDIRS = src 
+endif
diff --git a/tests/list_missing_python_tests b/tests/list_missing_python_tests
deleted file mode 100755 (executable)
index 33bd8bc..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#! /usr/bin/python
-
-from glob import glob
-from os.path import splitext, exists, join, dirname
-import sys
-
-tst_dir = join(dirname(sys.argv[0]),'python')
-src_dir = join(dirname(sys.argv[0]),'..','src')
-
-if len(sys.argv) > 1: verbose = True
-else: verbose = False
-
-status = 0
-
-cfiles = [ file.split('/')[-1] for file in glob(join(src_dir,'*.c')) ]
-cfiles.sort()
-
-for cfile in cfiles: 
-  pythonfile=splitext(cfile)[0]+'.py'
-  if not exists(pythonfile):
-    print "%20s [X]" % cfile, "[ ] %s" % pythonfile
-    status = 1
-  elif verbose:
-    print "%20s [X]" % cfile, "[X] %s" % pythonfile
-
-pythonfiles = [ file.split('/')[-1] for file in glob(join(tst_dir,'*.py')) ]
-pythonfiles.sort()
-
-for pythonfile in pythonfiles: 
-  cfile=splitext(pythonfile)[0]+'.c'
-  if not exists(join(src_dir,cfile)):
-    print "%20s [ ]" % cfile, "[X] %s" % pythonfile
-    status = 1
-  elif verbose:
-    print "%20s [X]" % cfile, "[X] %s" % pythonfile
-
-sys.exit(status)
diff --git a/tests/list_missing_tests b/tests/list_missing_tests
new file mode 100755 (executable)
index 0000000..520cb7c
--- /dev/null
@@ -0,0 +1,64 @@
+#! /usr/bin/python
+
+from glob import glob
+from os.path import splitext, exists, join, dirname, basename
+import sys
+
+def check_tst_against_src(src_dir, src_ext, ext_dir, verbose = False, tst_prefix = ''):
+  src_files = [ basename(file) for file in glob( join(src_dir, '*'+src_ext) ) ]
+  src_files.sort()
+  status = 0
+  for src_file in src_files: 
+    tst_file = (splitext(src_file)[0] + tst_ext).replace(tst_prefix,"")
+    if not exists(join(tst_dir,tst_prefix+tst_file)):
+      print "%20s [X]" % src_file, "[ ] %s" % tst_file
+      status = 1
+    elif verbose:
+      print "%20s [X]" % src_file, "[X] %s" % tst_file
+  return status
+
+def check_src_against_tst(tst_dir, tst_ext, src_dir, verbose = False, tst_prefix = ''):
+  tst_files = [ basename(file) for file in glob( join(tst_dir, '*'+tst_ext) ) ]
+  tst_files.sort()
+  status = 0
+  for tst_file in tst_files: 
+    src_file = (splitext(tst_file)[0] + src_ext).replace(tst_prefix,"")
+    if not exists(join(src_dir,src_file)):
+      print "%20s [ ]" % src_file, "[X] %s" % tst_file
+      status = 2
+    elif verbose:
+      print "%20s [X]" % src_file, "[X] %s" % tst_file
+  return status
+
+def check_two_ways(src_dir, src_ext, tst_dir, tst_ext, verbose = False, tst_prefix = ''):
+  print "%20s    " % (" FILES IN " + src_dir) + "|" + "    FILES IN " + tst_dir
+  status  = check_tst_against_src(src_dir, src_ext, tst_dir, verbose = verbose, tst_prefix = tst_prefix)
+  status += check_src_against_tst(tst_dir, tst_ext, src_dir, verbose = verbose, tst_prefix = tst_prefix)
+  return status
+
+if __name__ == '__main__':
+
+  if len(sys.argv) > 1: verbose = True
+  else: verbose = False
+
+  base_directory = dirname(sys.argv[0])
+
+  status = 0
+
+  src_dir = join(base_directory,'..','src')
+  src_ext = '.c'
+  tst_dir = join(base_directory,'python')
+  tst_ext = '.py'
+  status += check_two_ways(src_dir, src_ext, tst_dir, tst_ext, verbose = verbose)
+
+  tst_dir = join(base_directory,'src')
+  tst_ext = '.c'
+  status += check_two_ways(src_dir, src_ext, tst_dir, tst_ext, verbose = verbose, tst_prefix = 'test-')
+
+  src_dir = join(base_directory,'..','examples')
+  src_ext = '.c'
+  tst_dir = join(base_directory,'python','examples')
+  tst_ext = '.py'
+  status += check_two_ways(src_dir, src_ext, tst_dir, tst_ext, verbose = verbose)
+
+  sys.exit(status)
diff --git a/tests/python/examples/README b/tests/python/examples/README
new file mode 100644 (file)
index 0000000..684e1a2
--- /dev/null
@@ -0,0 +1 @@
+Python unit tests checking the output of the programs in aubio/examples/
diff --git a/tests/python/examples/__init__.py b/tests/python/examples/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/python/examples/aubionotes.py b/tests/python/examples/aubionotes.py
new file mode 100644 (file)
index 0000000..6c22a34
--- /dev/null
@@ -0,0 +1,41 @@
+from template import *
+
+class aubionotes_test_case(program_test_case):
+
+  import os.path
+  filename = os.path.join('..','..','sounds','woodblock.aiff')
+  progname = os.path.join('..','..','examples','aubionotes')
+
+  def test_aubionotes(self):
+    """ test aubionotes with default parameters """
+    self.getOutput()
+    # FIXME: useless check
+    self.assertEqual(len(self.output.split('\n')), 1)
+    self.assertEqual(float(self.output.strip()), 0.017415)
+
+  def test_aubionotes_verbose(self):
+    """ test aubionotes with -v parameter """
+    self.command += " -v "
+    self.getOutput()
+    # FIXME: loose checking: make sure at least 8 lines are printed
+    assert len(self.output) >= 8
+
+  def test_aubionotes_devnull(self):
+    """ test aubionotes on /dev/null """
+    self.filename = "/dev/null"
+    # exit status should not be 0
+    self.getOutput(expected_status = 256)
+    # and there should be an error message
+    assert len(self.output) > 0
+    # that looks like this 
+    output_lines = self.output.split('\n')
+    assert output_lines[0] == "Unable to open input file /dev/null."
+    #assert output_lines[1] == "Supported file format but file is malformed."
+    assert output_lines[2] == "Could not open input file /dev/null."
+
+mode_names = ["yinfft", "yin", "fcomb", "mcomb", "schmitt"]
+for name in mode_names:
+  exec("class aubionotes_test_case_" + name + "(aubionotes_test_case):\n\
+    options = \" -p " + name + " \"")
+
+if __name__ == '__main__': unittest.main()
diff --git a/tests/python/examples/aubioonset.py b/tests/python/examples/aubioonset.py
new file mode 100644 (file)
index 0000000..6d14141
--- /dev/null
@@ -0,0 +1,36 @@
+from template import *
+
+class aubioonset_test_case(program_test_case):
+  
+  import os.path
+  filename = os.path.join('..','..','sounds','woodblock.aiff')
+  progname = os.path.join('..','..','examples','aubioonset')
+
+  def test_aubioonset(self):
+    """ test aubioonset with default parameters """
+    self.getOutput()
+    assert len(str(self.output)) != 0, "no output produced with command:\n" \
+      + self.command
+
+  def test_aubioonset_with_inf_silence(self):
+    """ test aubioonset with -s 0  """
+    self.command += " -s 0" 
+    self.getOutput()
+    assert len(self.output) == 0, self.output
+
+  def test_aubioonset_with_no_silence(self):
+    """ test aubioonset with -s -100 """ 
+    self.command += " -s -100 " 
+    self.getOutput()
+    # only one onset in woodblock.aiff
+    assert len(str(self.output)) != 0, "no output produced with command:\n" \
+      + self.command
+    assert len(self.output.split('\n')) == 1
+    # onset should be at 0.00000
+    assert float(self.output.strip()) == 0.
+
+for name in ["energy", "specdiff", "hfc", "complex", "phase", "kl", "mkl"]:
+  exec("class aubioonset_test_case_"+name+"(aubioonset_test_case):\n\
+  options = \" -O "+name+" \"")
+
+if __name__ == '__main__': unittest.main()
diff --git a/tests/python/examples/aubiopitch.py b/tests/python/examples/aubiopitch.py
new file mode 100644 (file)
index 0000000..356daa2
--- /dev/null
@@ -0,0 +1,58 @@
+from template import *
+
+import os.path
+
+class aubiopitch_test_case(program_test_case):
+
+  import os.path
+  filename = os.path.join('..','..','sounds','woodblock.aiff')
+  progname = "PYTHONPATH=../../python:../../python/aubio/.libs " + \
+              os.path.join('..','..','python','aubiopitch')
+
+  def test_aubiopitch(self):
+    """ test aubiopitch with default parameters """
+    self.getOutput()
+    # FIXME: useless check
+    self.assertEqual(len(self.output.split('\n')), 1)
+    #self.assertEqual(float(self.output.strip()), 0.)
+
+  def test_aubiopitch_verbose(self):
+    """ test aubiopitch with -v parameter """
+    self.command += " -v "
+    self.getOutput()
+    # FIXME: loose checking: make sure at least 8 lines are printed
+    assert len(self.output) >= 8
+
+  def test_aubiopitch_devnull(self):
+    """ test aubiopitch on /dev/null """
+    self.filename = "/dev/null"
+    # exit status should not be 0
+    self.getOutput(expected_status = 256)
+    # and there should be an error message
+    assert len(self.output) > 0
+    # that looks like this 
+    output_lines = self.output.split('\n')
+    #assert output_lines[0] == "Unable to open input file /dev/null."
+    #assert output_lines[1] == "Supported file format but file is malformed."
+    #assert output_lines[2] == "Could not open input file /dev/null."
+
+mode_names = ["yinfft", "yin", "fcomb", "mcomb", "schmitt"]
+for name in mode_names:
+  exec("class aubiopitch_test_case_" + name + "(aubiopitch_test_case):\n\
+    options = \" -m " + name + " \"")
+
+class aubiopitch_test_yinfft(program_test_case):
+
+  filename = os.path.join('..','..','sounds','16568_acclivity_TwoCows.wav')
+  progname = "PYTHONPATH=../../python:../../python/aubio/.libs " + \
+              os.path.join('..','..','python','aubiopitch')
+  options  = " -m yinfft -t 0.75 "
+
+  def test_aubiopitch(self):
+    """ test aubiopitch with default parameters """
+    self.getOutput()
+    expected_output = open(os.path.join('examples','aubiopitch','yinfft'+'.'+os.path.basename(self.filename)+'.txt')).read()
+    for line_out, line_exp in zip(self.output.split('\n'), expected_output.split('\n')):
+      assert line_out == line_exp, line_exp + " vs. " + line_out
+
+if __name__ == '__main__': unittest.main()
diff --git a/tests/python/examples/aubiopitch/yinfft.16568_acclivity_TwoCows.wav.txt b/tests/python/examples/aubiopitch/yinfft.16568_acclivity_TwoCows.wav.txt
new file mode 100644 (file)
index 0000000..dcdd52b
--- /dev/null
@@ -0,0 +1,566 @@
+0.0232199546485        -1.0
+0.0464399092971        -1.0
+0.0696598639456        -1.0
+0.0928798185941        -1.0
+0.116099773243 -1.0
+0.139319727891 -1.0
+0.16253968254  -1.0
+0.185759637188 -1.0
+0.208979591837 -1.0
+0.232199546485 -1.0
+0.255419501134 -1.0
+0.278639455782 -1.0
+0.301859410431 -1.0
+0.325079365079 -1.0
+0.348299319728 -1.0
+0.371519274376 -1.0
+0.394739229025 -1.0
+0.417959183673 -1.0
+0.441179138322 -1.0
+0.464399092971 -1.0
+0.487619047619 -1.0
+0.510839002268 -1.0
+0.534058956916 -1.0
+0.557278911565 -1.0
+0.580498866213 -1.0
+0.603718820862 -1.0
+0.62693877551  -1.0
+0.650158730159 -1.0
+0.673378684807 -1.0
+0.696598639456 -1.0
+0.719818594104 -1.0
+0.743038548753 -1.0
+0.766258503401 -1.0
+0.78947845805  -1.0
+0.812698412698 -1.0
+0.835918367347 -1.0
+0.859138321995 -1.0
+0.882358276644 -1.0
+0.905578231293 -1.0
+0.928798185941 -1.0
+0.95201814059  -1.0
+0.975238095238 -1.0
+0.998458049887 -1.0
+1.02167800454  -1.0
+1.04489795918  -1.0
+1.06811791383  392.768096924
+1.09133786848  115.522140503
+1.11455782313  116.574150085
+1.13777777778  117.720863342
+1.16099773243  120.00163269
+1.18421768707  123.633300781
+1.20743764172  426.787963867
+1.23065759637  141.312179565
+1.25387755102  144.336975098
+1.27709750567  148.604934692
+1.30031746032  150.864654541
+1.32353741497  154.889007568
+1.34675736961  156.505081177
+1.36997732426  158.878829956
+1.39319727891  160.931289673
+1.41641723356  163.155059814
+1.43963718821  324.814025879
+1.46285714286  167.016983032
+1.48607709751  168.871704102
+1.50929705215  170.665634155
+1.5325170068   172.353149414
+1.55573696145  174.764205933
+1.5789569161   176.318893433
+1.60217687075  178.282669067
+1.6253968254   179.82383728
+1.64861678005  181.488952637
+1.67183673469  183.1927948
+1.69505668934  184.449371338
+1.71827664399  185.715484619
+1.74149659864  186.702224731
+1.76471655329  187.907455444
+1.78793650794  188.703475952
+1.81115646259  189.502182007
+1.83437641723  190.250213623
+1.85759637188  190.834747314
+1.88081632653  190.98348999
+1.90403628118  190.847137451
+1.92725623583  190.805847168
+1.95047619048  191.00831604
+1.97369614512  191.377182007
+1.99691609977  191.935241699
+2.02013605442  192.395782471
+2.04335600907  192.534378052
+2.06657596372  192.404174805
+2.08979591837  192.085708618
+2.11301587302  191.410400391
+2.13623582766  191.070388794
+2.15945578231  190.677963257
+2.18267573696  190.020675659
+2.20589569161  189.669265747
+2.22911564626  189.298828125
+2.25233560091  188.546142578
+2.27555555556  186.856491089
+2.2987755102   184.917297363
+2.32199546485  183.044509888
+2.3452154195   181.399368286
+2.36843537415  179.126312256
+2.3916553288   175.22946167
+2.41487528345  171.139190674
+2.4380952381   338.55368042
+2.46131519274  162.799713135
+2.48453514739  320.075500488
+2.50775510204  148.602432251
+2.53097505669  139.503982544
+2.55419501134  340.922271729
+2.57741496599  326.436950684
+2.60063492063  333.484558105
+2.62385487528  -1.0
+2.64707482993  -1.0
+2.67029478458  -1.0
+2.69351473923  -1.0
+2.71673469388  -1.0
+2.73995464853  -1.0
+2.76317460317  -1.0
+2.78639455782  -1.0
+2.80961451247  -1.0
+2.83283446712  -1.0
+2.85605442177  -1.0
+2.87927437642  -1.0
+2.90249433107  -1.0
+2.92571428571  -1.0
+2.94893424036  -1.0
+2.97215419501  -1.0
+2.99537414966  -1.0
+3.01859410431  -1.0
+3.04181405896  -1.0
+3.06503401361  -1.0
+3.08825396825  -1.0
+3.1114739229   -1.0
+3.13469387755  -1.0
+3.1579138322   -1.0
+3.18113378685  -1.0
+3.2043537415   -1.0
+3.22757369615  -1.0
+3.25079365079  -1.0
+3.27401360544  -1.0
+3.29723356009  -1.0
+3.32045351474  -1.0
+3.34367346939  -1.0
+3.36689342404  -1.0
+3.39011337868  -1.0
+3.41333333333  -1.0
+3.43655328798  -1.0
+3.45977324263  -1.0
+3.48299319728  -1.0
+3.50621315193  -1.0
+3.52943310658  -1.0
+3.55265306122  -1.0
+3.57587301587  -1.0
+3.59909297052  -1.0
+3.62231292517  -1.0
+3.64553287982  -1.0
+3.66875283447  -1.0
+3.69197278912  -1.0
+3.71519274376  -1.0
+3.73841269841  -1.0
+3.76163265306  -1.0
+3.78485260771  -1.0
+3.80807256236  -1.0
+3.83129251701  -1.0
+3.85451247166  -1.0
+3.8777324263   -1.0
+3.90095238095  -1.0
+3.9241723356   -1.0
+3.94739229025  -1.0
+3.9706122449   -1.0
+3.99383219955  -1.0
+4.0170521542   -1.0
+4.04027210884  -1.0
+4.06349206349  -1.0
+4.08671201814  -1.0
+4.10993197279  -1.0
+4.13315192744  -1.0
+4.15637188209  -1.0
+4.17959183673  -1.0
+4.20281179138  -1.0
+4.22603174603  -1.0
+4.24925170068  -1.0
+4.27247165533  -1.0
+4.29569160998  -1.0
+4.31891156463  -1.0
+4.34213151927  -1.0
+4.36535147392  -1.0
+4.38857142857  -1.0
+4.41179138322  -1.0
+4.43501133787  -1.0
+4.45823129252  -1.0
+4.48145124717  -1.0
+4.50467120181  -1.0
+4.52789115646  -1.0
+4.55111111111  -1.0
+4.57433106576  -1.0
+4.59755102041  -1.0
+4.62077097506  -1.0
+4.64399092971  -1.0
+4.66721088435  -1.0
+4.690430839    -1.0
+4.71365079365  -1.0
+4.7368707483   -1.0
+4.76009070295  -1.0
+4.7833106576   -1.0
+4.80653061224  -1.0
+4.82975056689  -1.0
+4.85297052154  -1.0
+4.87619047619  -1.0
+4.89941043084  -1.0
+4.92263038549  -1.0
+4.94585034014  -1.0
+4.96907029478  -1.0
+4.99229024943  -1.0
+5.01551020408  -1.0
+5.03873015873  -1.0
+5.06195011338  -1.0
+5.08517006803  -1.0
+5.10839002268  -1.0
+5.13160997732  -1.0
+5.15482993197  -1.0
+5.17804988662  -1.0
+5.20126984127  -1.0
+5.22448979592  -1.0
+5.24770975057  -1.0
+5.27092970522  -1.0
+5.29414965986  -1.0
+5.31736961451  -1.0
+5.34058956916  -1.0
+5.36380952381  -1.0
+5.38702947846  -1.0
+5.41024943311  -1.0
+5.43346938776  -1.0
+5.4566893424   -1.0
+5.47990929705  -1.0
+5.5031292517   -1.0
+5.52634920635  -1.0
+5.549569161    -1.0
+5.57278911565  -1.0
+5.59600907029  -1.0
+5.61922902494  -1.0
+5.64244897959  -1.0
+5.66566893424  -1.0
+5.68888888889  -1.0
+5.71210884354  -1.0
+5.73532879819  -1.0
+5.75854875283  -1.0
+5.78176870748  -1.0
+5.80498866213  -1.0
+5.82820861678  -1.0
+5.85142857143  -1.0
+5.87464852608  -1.0
+5.89786848073  -1.0
+5.92108843537  -1.0
+5.94430839002  -1.0
+5.96752834467  -1.0
+5.99074829932  -1.0
+6.01396825397  -1.0
+6.03718820862  -1.0
+6.06040816327  -1.0
+6.08362811791  -1.0
+6.10684807256  -1.0
+6.13006802721  -1.0
+6.15328798186  -1.0
+6.17650793651  -1.0
+6.19972789116  -1.0
+6.2229478458   -1.0
+6.24616780045  -1.0
+6.2693877551   -1.0
+6.29260770975  -1.0
+6.3158276644   -1.0
+6.33904761905  -1.0
+6.3622675737   -1.0
+6.38548752834  -1.0
+6.40870748299  -1.0
+6.43192743764  -1.0
+6.45514739229  -1.0
+6.47836734694  -1.0
+6.50158730159  187.887435913
+6.52480725624  143.988250732
+6.54802721088  147.904678345
+6.57124716553  151.674087524
+6.59446712018  3221.32983398
+6.61768707483  3159.02587891
+6.64090702948  160.395706177
+6.66412698413  162.535690308
+6.68734693878  164.282516479
+6.71056689342  166.054779053
+6.73378684807  167.578659058
+6.75700680272  169.234619141
+6.78022675737  171.029663086
+6.80344671202  173.257110596
+6.82666666667  174.64654541
+6.84988662132  175.149429321
+6.87310657596  175.456039429
+6.89632653061  176.283660889
+6.91954648526  177.318511963
+6.94276643991  178.066696167
+6.96598639456  178.517211914
+6.98920634921  179.053573608
+7.01242630385  179.549285889
+7.0356462585   180.029403687
+7.05886621315  180.64515686
+7.0820861678   180.8934021
+7.10530612245  180.952774048
+7.1285260771   181.48147583
+7.15174603175  182.092208862
+7.17496598639  183.082504272
+7.19818594104  183.907089233
+7.22140589569  184.607666016
+7.24462585034  185.0181427
+7.26784580499  185.282440186
+7.29106575964  185.946502686
+7.31428571429  186.74571228
+7.33750566893  187.205505371
+7.36072562358  187.595703125
+7.38394557823  187.939483643
+7.40716553288  188.01159668
+7.43038548753  187.807418823
+7.45360544218  187.751464844
+7.47682539683  187.811416626
+7.50004535147  187.951507568
+7.52326530612  188.168029785
+7.54648526077  188.630828857
+7.56970521542  188.946014404
+7.59292517007  189.095901489
+7.61614512472  189.302886963
+7.63936507937  189.673339844
+7.66258503401  189.881591797
+7.68580498866  189.865234375
+7.70902494331  189.865234375
+7.73224489796  189.595870972
+7.75546485261  188.954116821
+7.77868480726  188.192108154
+7.8019047619   187.352645874
+7.82512471655  186.524551392
+7.8483446712   184.967712402
+7.87156462585  183.589355469
+7.8947845805   182.828231812
+7.91800453515  181.968215942
+7.9412244898   180.796981812
+7.96444444444  180.0
+7.98766439909  179.184524536
+8.01088435374  178.799484253
+8.03410430839  178.29347229
+8.05732426304  178.088272095
+8.08054421769  177.894317627
+8.10376417234  177.693618774
+8.12698412698  177.905075073
+8.15020408163  178.041549683
+8.17342403628  178.045135498
+8.19664399093  177.650650024
+8.21986394558  177.32208252
+8.24308390023  176.611938477
+8.26630385488  175.525878906
+8.28952380952  172.121078491
+8.31274376417  584.997009277
+8.33596371882  575.042358398
+8.35918367347  465.681121826
+8.38240362812  447.307037354
+8.40562358277  -1.0
+8.42884353741  -1.0
+8.45206349206  -1.0
+8.47528344671  -1.0
+8.49850340136  -1.0
+8.52172335601  -1.0
+8.54494331066  -1.0
+8.56816326531  -1.0
+8.59138321995  -1.0
+8.6146031746   -1.0
+8.63782312925  -1.0
+8.6610430839   -1.0
+8.68426303855  -1.0
+8.7074829932   -1.0
+8.73070294785  -1.0
+8.75392290249  -1.0
+8.77714285714  -1.0
+8.80036281179  -1.0
+8.82358276644  -1.0
+8.84680272109  -1.0
+8.87002267574  -1.0
+8.89324263039  -1.0
+8.91646258503  -1.0
+8.93968253968  -1.0
+8.96290249433  -1.0
+8.98612244898  -1.0
+9.00934240363  -1.0
+9.03256235828  -1.0
+9.05578231293  -1.0
+9.07900226757  -1.0
+9.10222222222  -1.0
+9.12544217687  -1.0
+9.14866213152  -1.0
+9.17188208617  -1.0
+9.19510204082  -1.0
+9.21832199546  -1.0
+9.24154195011  -1.0
+9.26476190476  -1.0
+9.28798185941  -1.0
+9.31120181406  -1.0
+9.33442176871  -1.0
+9.35764172336  -1.0
+9.380861678    -1.0
+9.40408163265  -1.0
+9.4273015873   -1.0
+9.45052154195  -1.0
+9.4737414966   -1.0
+9.49696145125  -1.0
+9.5201814059   -1.0
+9.54340136054  -1.0
+9.56662131519  -1.0
+9.58984126984  -1.0
+9.61306122449  -1.0
+9.63628117914  -1.0
+9.65950113379  -1.0
+9.68272108844  -1.0
+9.70594104308  -1.0
+9.72916099773  -1.0
+9.75238095238  -1.0
+9.77560090703  -1.0
+9.79882086168  -1.0
+9.82204081633  -1.0
+9.84526077098  -1.0
+9.86848072562  -1.0
+9.89170068027  -1.0
+9.91492063492  -1.0
+9.93814058957  -1.0
+9.96136054422  -1.0
+9.98458049887  -1.0
+10.0078004535  -1.0
+10.0310204082  -1.0
+10.0542403628  -1.0
+10.0774603175  -1.0
+10.1006802721  -1.0
+10.1239002268  -1.0
+10.1471201814  -1.0
+10.1703401361  -1.0
+10.1935600907  -1.0
+10.2167800454  -1.0
+10.24  -1.0
+10.2632199546  -1.0
+10.2864399093  100.193115234
+10.3096598639  -1.0
+10.3328798186  326.038757324
+10.3560997732  104.222053528
+10.3793197279  105.370048523
+10.4025396825  106.595123291
+10.4257596372  107.893875122
+10.4489795918  108.992500305
+10.4721995465  109.93119812
+10.4954195011  110.819335938
+10.5186394558  112.031303406
+10.5418594104  113.389472961
+10.5650793651  114.239830017
+10.5882993197  116.827377319
+10.6115192744  119.250427246
+10.634739229   122.184356689
+10.6579591837  148.222839355
+10.6811791383  150.104660034
+10.704399093   153.361968994
+10.7276190476  155.115112305
+10.7508390023  158.433624268
+10.7740589569  161.372955322
+10.7972789116  163.421096802
+10.8204988662  167.165771484
+10.8437188209  170.329452515
+10.8669387755  173.311584473
+10.8901587302  175.445571899
+10.9133786848  177.304244995
+10.9365986395  179.024490356
+10.9598185941  180.073501587
+10.9830385488  180.826629639
+11.0062585034  181.559936523
+11.029478458   182.487792969
+11.0526984127  183.303192139
+11.0759183673  183.976135254
+11.099138322   184.650161743
+11.1223582766  185.613876343
+11.1455782313  186.123062134
+11.1687981859  186.852523804
+11.1920181406  187.531890869
+11.2152380952  188.232284546
+11.2384580499  189.20135498
+11.2616780045  189.485900879
+11.2848979592  190.094390869
+11.3081179138  190.636749268
+11.3313378685  191.252670288
+11.3545578231  191.647476196
+11.3777777778  192.673187256
+11.4009977324  193.018920898
+11.4242176871  193.641860962
+11.4474376417  194.307373047
+11.4706575964  194.234619141
+11.493877551   194.290252686
+11.5170975057  194.641845703
+11.5403174603  194.663314819
+11.563537415   194.719177246
+11.5867573696  194.149108887
+11.6099773243  194.166213989
+11.6331972789  194.136291504
+11.6564172336  193.786529541
+11.6796371882  192.605865479
+11.7028571429  190.785202026
+11.7260770975  188.578399658
+11.7492970522  182.544433594
+11.7725170068  173.676742554
+11.7957369615  415.019744873
+11.8189569161  417.989685059
+11.8421768707  333.699066162
+11.8653968254  415.058837891
+11.88861678    352.025543213
+11.9118367347  -1.0
+11.9350566893  -1.0
+11.958276644   -1.0
+11.9814965986  -1.0
+12.0047165533  -1.0
+12.0279365079  -1.0
+12.0511564626  -1.0
+12.0743764172  -1.0
+12.0975963719  -1.0
+12.1208163265  -1.0
+12.1440362812  -1.0
+12.1672562358  -1.0
+12.1904761905  -1.0
+12.2136961451  -1.0
+12.2369160998  -1.0
+12.2601360544  -1.0
+12.2833560091  -1.0
+12.3065759637  -1.0
+12.3297959184  -1.0
+12.353015873   -1.0
+12.3762358277  -1.0
+12.3994557823  -1.0
+12.422675737   -1.0
+12.4458956916  -1.0
+12.4691156463  -1.0
+12.4923356009  -1.0
+12.5155555556  -1.0
+12.5387755102  -1.0
+12.5619954649  -1.0
+12.5852154195  -1.0
+12.6084353741  -1.0
+12.6316553288  -1.0
+12.6548752834  -1.0
+12.6780952381  -1.0
+12.7013151927  -1.0
+12.7245351474  -1.0
+12.747755102   -1.0
+12.7709750567  -1.0
+12.7941950113  -1.0
+12.817414966   -1.0
+12.8406349206  -1.0
+12.8638548753  -1.0
+12.8870748299  -1.0
+12.9102947846  -1.0
+12.9335147392  -1.0
+12.9567346939  -1.0
+12.9799546485  -1.0
+13.0031746032  -1.0
+13.0263945578  -1.0
+13.0496145125  -1.0
+13.0728344671  -1.0
+13.0960544218  -1.0
+13.1192743764  -1.0
+13.1424943311  -1.0
diff --git a/tests/python/examples/template.py b/tests/python/examples/template.py
new file mode 100644 (file)
index 0000000..a30e08e
--- /dev/null
@@ -0,0 +1,18 @@
+import unittest
+from commands import getstatusoutput
+
+class program_test_case(unittest.TestCase):
+
+  filename = "/dev/null"
+  progname = "UNDEFINED"
+  command = ""
+  options = ""
+
+  def getOutput(self, expected_status = 0):
+    self.command = self.progname + ' -i ' + self.filename + self.command
+    self.command += self.options
+    [self.status, self.output] = getstatusoutput(self.command)
+    if expected_status != -1:
+      assert self.status == expected_status, \
+        "expected status was %s, got %s\nOutput was:\n%s" % \
+        (expected_status, self.status, self.output)
diff --git a/tests/python/fft.py b/tests/python/fft.py
new file mode 100644 (file)
index 0000000..b856238
--- /dev/null
@@ -0,0 +1,150 @@
+import unittest
+import math
+
+from aubio.aubiowrapper import *
+
+buf_size = 8092 
+channels = 4
+
+precision = 6
+
+class aubio_mfft_test_case(unittest.TestCase):
+
+  def setUp(self):
+    self.o = new_aubio_mfft(buf_size, channels)
+
+  def tearDown(self):
+    del_aubio_mfft(self.o)
+
+  def test_create(self):
+    """ test creation and deletion of fft object """
+    pass
+
+  def test_aubio_mfft_do_zeroes(self):
+    """ test aubio_mfft_do on zeroes """
+    input    = new_fvec(buf_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    for index in range(buf_size):
+      for channel in range(channels):
+        self.assertEqual(0., fvec_read_sample(input, channel, index))
+    aubio_mfft_do(self.o, input, fftgrain)
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
+    del fftgrain
+    del input
+
+  def test_aubio_mfft_rdo_zeroes(self):
+    """ test aubio_mfft_rdo on zeroes """
+    fftgrain = new_cvec(buf_size, channels)
+    output    = new_fvec(buf_size, channels)
+    aubio_mfft_rdo(self.o, fftgrain, output)
+    # check output
+    for index in range(buf_size):
+      for channel in range(channels):
+        self.assertEqual(0., fvec_read_sample(output, channel, index))
+    del fftgrain
+    del output
+
+  def test_aubio_mfft_do_impulse(self):
+    """ test aubio_mfft_do with an impulse on one channel """
+    input    = new_fvec(buf_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    # write impulse in channel 0, sample 0.
+    some_constant = 0.3412432456
+    fvec_write_sample(input, some_constant, 0, 0)
+    aubio_mfft_do(self.o, input, fftgrain)
+    # check norm
+    for index in range(buf_size/2+1):
+      self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)
+    for index in range(buf_size/2+1):
+      for channel in range(1, channels):
+        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
+    # check phas
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
+    del fftgrain
+    del input
+
+  def test_aubio_mfft_do_constant(self):
+    """ test aubio_mfft_do with a constant on one channel """
+    input    = new_fvec(buf_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    # write impulse in channel 0, sample 0.
+    some_constant = 0.003412432456
+    for index in range(1,buf_size):
+      fvec_write_sample(input, some_constant, 0, index)
+    aubio_mfft_do(self.o, input, fftgrain)
+    # check norm and phase == 0 in all other channels 
+    for index in range(buf_size/2+1):
+      for channel in range(1, channels):
+        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
+    # check norm and phase == 0 in first first and last bin of first channel
+    self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision)
+    self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0))
+    self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1))
+    self.assertEqual(0., cvec_read_phas(fftgrain, 0, buf_size/2+1))
+    # check unwrap2pi(phas) ~= pi everywhere but in first bin
+    for index in range(1,buf_size/2+1):
+       self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision)
+       self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)
+    del fftgrain
+    del input
+
+  def test_aubio_mfft_do_impulse_multichannel(self):
+    " test aubio_mfft_do on impulse two channels "
+    input    = new_fvec(buf_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    # put an impulse in first an last channel, at first and last index
+    fvec_write_sample(input, 1., 0, 0)
+    fvec_write_sample(input, 1., channels-1, 0)
+    aubio_mfft_do(self.o, input, fftgrain)
+    # check the norm
+    for index in range(buf_size/2+1):
+      self.assertEqual(1., cvec_read_norm(fftgrain, 0, index))
+    for index in range(buf_size/2+1):
+      for channel in range(1, channels-1):
+        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
+    for index in range(buf_size/2+1):
+      self.assertEqual(1., cvec_read_norm(fftgrain, channels-1, index))
+    # check the phase
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
+    del fftgrain
+    del input
+
+  def test_aubio_mfft_rdo_impulse(self):
+    """ test aubio_mfft_rdo on impulse """
+    fftgrain  = new_cvec(buf_size, channels)
+    for channel in range(channels):
+      cvec_write_norm(fftgrain, 1., channel, 0)
+    output    = new_fvec(buf_size, channels)
+    aubio_mfft_rdo(self.o, fftgrain, output)
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)
+    del fftgrain
+    del output
+
+  def test_aubio_mfft_do_back_and_forth(self):
+    """ test aubio_mfft_rdo on a constant """
+    input    = new_fvec(buf_size, channels)
+    output   = new_fvec(buf_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        fvec_write_sample(input, 0.67, channel, index)
+    aubio_mfft_do(self.o, input, fftgrain)
+    aubio_mfft_rdo(self.o, fftgrain, output)
+    for index in range(buf_size/2+1):
+      for channel in range(channels):
+        self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)
+    del fftgrain
+    del output
+
+if __name__ == '__main__': unittest.main()
index 5159af9..98ad1cd 100644 (file)
@@ -21,7 +21,7 @@ class fvec_test_case(unittest.TestCase):
     """ check new fvec elements are set to 0. """
     for index in range(buf_size):
       for channel in range(channels):
-        self.assertEqual(fvec_read_sample(self.vector,channel,index),0.)
+        self.assertEqual(0., fvec_read_sample(self.vector,channel,index))
 
   def test_fvec_write_sample(self):
     """ check new fvec elements are set with fvec_write_sample """
@@ -30,7 +30,7 @@ class fvec_test_case(unittest.TestCase):
         fvec_write_sample(self.vector,1.,channel,index)
     for index in range(buf_size):
       for channel in range(channels):
-        self.assertEqual(fvec_read_sample(self.vector,channel,index),1.)
+        self.assertEqual(1., fvec_read_sample(self.vector,channel,index))
 
 if __name__ == '__main__':
   unittest.main()
diff --git a/tests/python/phasevoc.py b/tests/python/phasevoc.py
new file mode 100644 (file)
index 0000000..bc1c754
--- /dev/null
@@ -0,0 +1,62 @@
+import unittest
+
+from aubio.aubiowrapper import *
+
+buf_size = 1024
+hop_size = 256
+channels = 2
+
+precision = 6
+
+class aubio_phasevoc_test(unittest.TestCase):
+
+  def setUp(self):
+    self.o = new_aubio_pvoc(buf_size, hop_size, channels)
+
+  def tearDown(self):
+    del_aubio_pvoc(self.o)
+
+  def test_create(self):
+    """ create and delete phasevoc object """
+    pass
+
+  def test_zeroes(self):
+    """ run phasevoc object on zeroes """
+    input    = new_fvec(hop_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    output   = new_fvec(hop_size, channels)
+    for index in range(hop_size):
+      for channel in range(channels):
+        self.assertEqual(0., fvec_read_sample(input, channel, index))
+    aubio_pvoc_do (self.o, input, fftgrain)
+    aubio_pvoc_rdo(self.o, fftgrain, output)
+    for index in range(hop_size):
+      for channel in range(channels):
+        self.assertEqual(0., fvec_read_sample(output, channel, index))
+    del input
+    del fftgrain
+
+  def test_ones(self):
+    """ run phasevoc object on ones """
+    input    = new_fvec(hop_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    output   = new_fvec(hop_size, channels)
+    for index in range(hop_size):
+      for channel in range(channels):
+        fvec_write_sample(input, 1., channel, index)
+        self.assertEqual(1., fvec_read_sample(input, channel, index))
+    # make sure the first buf_size-hop_size samples are zeroes
+    for i in range(buf_size/hop_size - 1):
+      aubio_pvoc_do (self.o, input, fftgrain)
+      aubio_pvoc_rdo(self.o, fftgrain, output)
+      for index in range(hop_size):
+        for channel in range(channels):
+          self.assertAlmostEqual(0., fvec_read_sample(output, channel, index), precision)
+    # make sure the first non zero input is correctly resynthesised
+    aubio_pvoc_do (self.o, input, fftgrain)
+    aubio_pvoc_rdo(self.o, fftgrain, output)
+    for index in range(hop_size):
+      for channel in range(channels):
+        self.assertAlmostEqual(1., fvec_read_sample(output, channel, index), precision)
+    del input
+    del fftgrain
index bcb4afe..e2f8065 100755 (executable)
@@ -11,10 +11,14 @@ sys.path.append(os.path.join(cur_dir,'..','..','python','aubio','.libs'))
 import unittest
 
 from glob import glob
-modules_to_test = [i.split('.')[0] for i in glob('*.py')]
+def list_of_test_files(path):
+  return [i.split('.')[0].replace('/','.') for i in glob(path)]
+
+modules_to_test  = list_of_test_files('*.py')
+modules_to_test += list_of_test_files('examples/aubio*.py')
 
 if __name__ == '__main__':
   for module in modules_to_test: 
-    if module != 'all_tests': # (not actually needed)
+    if module != 'run_all_tests': # (not actually needed)
       exec('from %s import *' % module)
   unittest.main()
diff --git a/tests/python/unittest_examples.py b/tests/python/unittest_examples.py
new file mode 100644 (file)
index 0000000..740c731
--- /dev/null
@@ -0,0 +1,31 @@
+import unittest
+
+# this file is just to illustrates and test some of the unittest module
+# functionalities.
+
+class raise_test_case(unittest.TestCase):
+  def test_assertEqual(self):
+    """ check assertEqual returns AssertionError """
+    try:
+      self.assertEqual(0.,1.)
+    except AssertionError:
+      pass
+    else:
+      fail('expected an AssertionError exception')
+
+  def test_assertAlmostEqual(self):
+    """ check assertAlmostEqual returns AssertionError """
+    try:
+      self.assertAlmostEqual(0.,1.)
+    except AssertionError:
+      pass
+    else:
+      fail('expected an AssertionError exception')
+
+  def test_assertRaises(self):
+    """ check assertRaises works as expected """
+    self.assertRaises(AssertionError, self.assertEqual, 0.,1.)
+    self.assertRaises(AssertionError, self.assertAlmostEqual, 0.,1.,1)
+
+if __name__ == '__main__':
+  unittest.main()
index 7c44abf..6855040 100644 (file)
@@ -9,7 +9,8 @@ bin_PROGRAMS = \
        test-mfft \
        test-hist \
        test-scale \
-       test-sample \
+       test-cvec \
+       test-fvec \
        test-window \
        test-filter \
        test-biquad \
diff --git a/tests/src/test-cvec.c b/tests/src/test-cvec.c
new file mode 100644 (file)
index 0000000..e76471d
--- /dev/null
@@ -0,0 +1,12 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        cvec_t * sp       = new_cvec (win_s, channels); /* input buffer */
+        del_cvec(sp);
+
+        return 0;
+}
+
index 17adeb5..8fe781f 100644 (file)
@@ -8,35 +8,34 @@
 
 int main(){
         uint_t i,j;
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        uint_t channels   = 1;                          /* number of channel */
-        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
-        cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
-        fvec_t * out      = new_fvec (win_s, channels); /* output buffer */
+        uint_t win_s      = 1024;                       // window size
+        uint_t channels   = 1;                          // number of channel
+        fvec_t * in       = new_fvec (win_s, channels); // input buffer
+        cvec_t * fftgrain = new_cvec (win_s, channels); // fft norm and phase
+        fvec_t * out      = new_fvec (win_s, channels); // output buffer
   
-        /* allocate fft and other memory space */
-        aubio_fft_t * fft      = new_aubio_fft(win_s);      /* fft interface */
-        smpl_t * w             = NEW_ARRAY(smpl_t,win_s); /* window */
-        /* complex spectral data */
+        // allocate fft and other memory space
+        aubio_fft_t * fft      = new_aubio_fft(win_s);    // fft interface
+        smpl_t * w             = NEW_ARRAY(smpl_t,win_s); // window
+        // complex spectral data
         fft_data_t ** spec     = NEW_ARRAY(fft_data_t*,channels); 
         for (i=0; i < channels; i++)
                 spec[i] = NEW_ARRAY(fft_data_t,win_s);
-        /* initialize the window (see mathutils.c) */
+        // initialize the window (see mathutils.c)
         aubio_window(w,win_s,aubio_win_hanningz);
   
-        /* fill input with some data */
+        // fill input with some data
         in->data[0][win_s/2] = 1;
   
-        /* execute stft */
+        // execute stft
         for (i=0; i < channels; i++) {
                 aubio_fft_do (fft,in->data[i],spec[i],win_s);
-                /* put norm and phase into fftgrain */
+                // put norm and phase into fftgrain
                 aubio_fft_getnorm(fftgrain->norm[i], spec[i], win_s/2+1);
                 aubio_fft_getphas(fftgrain->phas[i], spec[i], win_s/2+1);
         }
   
-        /* execute inverse fourier transform */
+        // execute inverse fourier transform
         for (i=0; i < channels; i++) {
                 for (j=0; j<win_s/2+1; j++) {
                         spec[i][j]  = cexp(I*aubio_unwrap2pi(fftgrain->phas[i][j]));
diff --git a/tests/src/test-fvec.c b/tests/src/test-fvec.c
new file mode 100644 (file)
index 0000000..8fa1f7c
--- /dev/null
@@ -0,0 +1,12 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        del_fvec(in);
+
+        return 0;
+}
+
diff --git a/tests/src/test-sample.c b/tests/src/test-sample.c
deleted file mode 100644 (file)
index d31c1d2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <aubio.h>
-
-int main(){
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        uint_t channels   = 1;                          /* number of channel */
-        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
-        cvec_t * sp       = new_cvec (win_s, channels); /* input buffer */
-        del_fvec(in);
-        del_cvec(sp);
-
-        return 0;
-}
-