changeset 103:1cbbe5b5e461

- Added some previously uncommitted Pd testing examples - Improved python bindings. Now we can do vector features as well as scalar from Python
author Jamie Bullock <jamie@postlude.co.uk>
date Fri, 21 Dec 2007 11:05:20 +0000
parents 7a5859764ccd
children a32738e9d955
files configure.in examples/puredata/simple-test.pd examples/puredata/spectrum-512-test.pd swig/python/test.py swig/python/xtract.i swig/xtract.i
diffstat 6 files changed, 51 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Tue Oct 16 09:37:06 2007 +0000
+++ b/configure.in	Fri Dec 21 11:05:20 2007 +0000
@@ -162,11 +162,6 @@
     esac],[swig=false])
 
 
-dnl SWIG stuff
-if [[ "$swig" = "true" ]] ; then
-    AC_PROG_SWIG(1.3.21)
-    AC_DEFINE([BUILD_SWIG], [1], [Build the swig bindings])
-fi
 
 if [[ "$with_java" = "true" ]] ; then
     if test "$JAVAC" = ""
@@ -194,6 +189,12 @@
 
 AM_CONDITIONAL(BUILD_SWIG, test "x${swig}" = 'xtrue')
 
+dnl SWIG stuff
+if [[ "$swig" = "true" ]] ; then
+    AC_PROG_SWIG(1.3.21)
+    AC_DEFINE([BUILD_SWIG], [1], [Build the swig bindings])
+fi
+
 dnl Are we building with fftw?
 if [[ "$fft" = "true" ]] ; then
     LDFLAGS="$LDFLAGS -lfftw3f"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/puredata/simple-test.pd	Fri Dec 21 11:05:20 2007 +0000
@@ -0,0 +1,11 @@
+#N canvas 642 248 670 289 10;
+#X obj 192 63 osc~ 440;
+#X floatatom 194 187 10 0 0 0 - - -;
+#X obj 194 150 xtract~ spectral_mean;
+#X obj 193 94 *~ 0.3;
+#X text 337 121 Optional second argument gives blocksize;
+#X obj 193 121 xtract~ spectrum 64;
+#X connect 0 0 3 0;
+#X connect 2 0 1 0;
+#X connect 3 0 5 0;
+#X connect 5 0 2 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/puredata/spectrum-512-test.pd	Fri Dec 21 11:05:20 2007 +0000
@@ -0,0 +1,8 @@
+#N canvas 5 48 450 300 10;
+#X obj 127 77 noise~;
+#X obj 262 59 loadbang;
+#X msg 262 86 list 86.1328;
+#X obj 127 112 xtract~ spectrum 64;
+#X connect 0 0 3 0;
+#X connect 1 0 2 0;
+#X connect 2 0 3 1;
--- a/swig/python/test.py	Tue Oct 16 09:37:06 2007 +0000
+++ b/swig/python/test.py	Fri Dec 21 11:05:20 2007 +0000
@@ -3,11 +3,11 @@
 try:
     import xtract
 except ImportError:
-    print 'Failed to load the library "jxtract"'
+    print 'Failed to load the library "xtract"'
 
 print '\nRunning libxtract Python bindings test...\n'
 
-len = 5
+len = 8
 
 a = xtract.floatArray(len)
 temp = []
@@ -19,4 +19,19 @@
 print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % \
 	  xtract.xtract_mean(a,len,None)[1]
 
+print 'Computing spectrum...'
+
+argv = xtract.floatArray(1)
+argv[0] = 44100.0 / len  # Fake sample rate
+
+xtract.xtract_init_fft(len, xtract.XTRACT_SPECTRUM);
+
+result = xtract.floatArray(len)
+
+xtract.xtract_spectrum(a,len,argv, result)
+
+
+for i in range(len):
+    print result[i]
+
 print '\nFinished!\n'
--- a/swig/python/xtract.i	Tue Oct 16 09:37:06 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-%module xtract
-%include carrays.i 
-%include typemaps.i
-
-%{
-#include "xtract/xtract_scalar.h"
-%}
-
-%array_functions(float, floatArray); 
-%apply float *OUTPUT { float *result };
-
-%include "xtract/xtract_scalar.h"
--- a/swig/xtract.i	Tue Oct 16 09:37:06 2007 +0000
+++ b/swig/xtract.i	Fri Dec 21 11:05:20 2007 +0000
@@ -4,10 +4,19 @@
 
 %{
 #include "xtract/xtract_scalar.h"
+#include "xtract/xtract_vector.h"
+#include "xtract/libxtract.h"
 %}
 
 %array_class(float, floatArray); 
 %apply float *OUTPUT { float *result };
 /* %apply float *INPUT { float *data }; */
 
+%ignore xtract;
+
 %include "xtract/xtract_scalar.h"
+
+%clear float *result;
+
+%include "xtract/xtract_vector.h"
+%include "xtract/libxtract.h"