aboutsummaryrefslogtreecommitdiff
path: root/swig
diff options
context:
space:
mode:
authorJamie Bullock <jamie@postlude.co.uk>2008-01-01 16:17:44 +0000
committerJamie Bullock <jamie@postlude.co.uk>2008-01-01 16:17:44 +0000
commit7f86524dd021c5905df111d1254004576fd872f0 (patch)
treef6ee0de29c3ca6d5cb28b081c19168623aef505f /swig
parent445505b69a8517b5ab586bfdba2e1c719aa9ef7d (diff)
downloadLibXtract-7f86524dd021c5905df111d1254004576fd872f0.tar.gz
LibXtract-7f86524dd021c5905df111d1254004576fd872f0.tar.bz2
LibXtract-7f86524dd021c5905df111d1254004576fd872f0.zip
- Improvements to SWIG bindings generation script
- Fixed omission in xtract_bark_coefficients that was causing the output to be complete b/s! This fixed bark_coeffs and loudness feature which depends on it - Changes to descriptor API: added is_delta and id. id corresponds to value in xtract_features_ enum and is useful for programmatic conversions between id and name string.
Diffstat (limited to 'swig')
-rw-r--r--swig/java/Makefile.am2
-rw-r--r--swig/python/test.py12
-rw-r--r--swig/xtract.i92
3 files changed, 104 insertions, 2 deletions
diff --git a/swig/java/Makefile.am b/swig/java/Makefile.am
index 31317b7..25452a1 100644
--- a/swig/java/Makefile.am
+++ b/swig/java/Makefile.am
@@ -1,6 +1,7 @@
javasources = \
floatArray.java \
+ intArray.java \
SWIGTYPE_p_float.java \
SWIGTYPE_p_int.java \
SWIGTYPE_p_p_float.java \
@@ -32,6 +33,7 @@ javasources = \
javaclasses = \
floatArray.class \
+ intArray.class \
SWIGTYPE_p_float.class \
SWIGTYPE_p_int.class \
SWIGTYPE_p_p_float.class \
diff --git a/swig/python/test.py b/swig/python/test.py
index 923adb7..e2f0d24 100644
--- a/swig/python/test.py
+++ b/swig/python/test.py
@@ -16,8 +16,16 @@ for i in range(0, len):
a[i] = 2 * i
temp.append(str(a[i]))
-print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % \
- xtract.xtract_mean(a,len,None)[1]
+mean = xtract.xtract_mean(a,len,None)[1]
+
+print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % mean
+
+argv = xtract.floatArray(1)
+argv[0] = mean
+
+variance = xtract.xtract_variance(a, len, argv)[1]
+
+print 'The variance is %.2f' % variance
print 'Computing spectrum...'
diff --git a/swig/xtract.i b/swig/xtract.i
index 07798af..e0cd113 100644
--- a/swig/xtract.i
+++ b/swig/xtract.i
@@ -6,10 +6,85 @@
#include "xtract/xtract_scalar.h"
#include "xtract/xtract_vector.h"
#include "xtract/xtract_helper.h"
+#include "xtract/xtract_macros.h"
+#include "xtract/xtract_delta.h"
#include "xtract/libxtract.h"
%}
+/* Ensure filterbank gets freed */
+/** FIX: This doesn't work, or I'm not using properly. For now just add an explicit call to destroy_filterbank() in the target code */
+%newobject create_filterbank;
+%delobject destroy_filterbank;
+
+
+/* Helper functions */
+%inline %{
+
+ xtract_function_descriptor_t
+ *get_descriptor(xtract_function_descriptor_t *fd, int i){
+
+ return &fd[i];
+ }
+
+ /* Return a pointer to memory allocated for a mel filterbank */
+ xtract_mel_filter *create_filterbank(int n_filters, int blocksize){
+
+ float **filters;
+ xtract_mel_filter *mf;
+ int n, N;
+
+ N = blocksize;
+
+ mf = malloc(sizeof(xtract_mel_filter));
+ mf->n_filters = n_filters;
+
+ filters = (float **)malloc(n_filters * sizeof(float *));
+
+ for(n = 0; n < n_filters; n++)
+ filters[n] = (float *)malloc(N * sizeof(float));
+
+ mf->filters = filters;
+
+ return mf;
+
+ }
+
+ /* Free a mel filterbank */
+ void destroy_filterbank(xtract_mel_filter *filterbank){
+
+ int i = filterbank->n_filters;
+ float **filters;
+
+ filters = filterbank->filters;
+
+ while(i--)
+ free(filters[i]);
+
+ free(filters);
+
+ free(filterbank);
+
+ }
+
+ /* Eventually this should be deprecated */
+/* void destroy_filterbank_explicit(float **filterbank, int n_filters){
+
+ int i = n_filters;
+
+ while(i--)
+ free(filterbank[i]);
+
+ free(filterbank);
+ }
+*/
+
+
+
+%}
+
+
%array_class(float, floatArray);
+%array_class(int, intArray);
%apply float *OUTPUT { float *result };
/* %apply float *INPUT { float *data }; */
@@ -17,8 +92,25 @@
%include "xtract/xtract_scalar.h"
+/* We have to put xtract_delta declarations inline because it contains a mixture of vector and scalar functions */
+%inline %{
+
+ int xtract_flux(const float *data, const int N, const void *argv , float *result);
+ int xtract_lnorm(const float *data, const int N, const void *argv , float *result);
+
+%}
+
%clear float *result;
+%inline %{
+
+ int xtract_difference_vector(const float *data, const int N, const void *argv, float *result);
+
+%}
+
%include "xtract/xtract_vector.h"
%include "xtract/xtract_helper.h"
+%include "xtract/xtract_macros.h"
%include "xtract/libxtract.h"
+
+