changeset 110:c8502708853b

- 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.
author Jamie Bullock <jamie@postlude.co.uk>
date Tue, 01 Jan 2008 16:17:44 +0000
parents 9518ae6afff4
children c7e1fe63eedb
files src/descriptors.c src/fini.c src/init.c src/vector.c swig/java/Makefile.am swig/python/test.py swig/xtract.i xtract/libxtract.h
diffstat 8 files changed, 135 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/descriptors.c	Sat Dec 29 18:35:35 2007 +0000
+++ b/src/descriptors.c	Tue Jan 01 16:17:44 2008 +0000
@@ -24,7 +24,7 @@
 #include <string.h>
 #define XTRACT
 
-void *xtract_make_descriptors(){
+xtract_function_descriptor_t *xtract_make_descriptors(void){
 
     int f , F;
     char *name, *p_name, *desc, *p_desc, *author; 
@@ -45,6 +45,7 @@
     while(f--){
 
         d = &fd[f];
+        d->id = f;
         argc = &d->argc;
         argv_type = &d->argv.type;
 
@@ -502,7 +503,7 @@
                 strcpy(author, "");
                 break;
             case XTRACT_ROLLOFF:
-                strcpy(name, "spectral_rolloff");
+                strcpy(name, "rolloff");
                 strcpy(p_name, "Spectral Rolloff");
                 strcpy(desc, 
                         "Extract the rolloff point of a spectrum");
@@ -1250,7 +1251,7 @@
     return fd;
 }
 
-int xtract_free_descriptors(void *fd){
+int xtract_free_descriptors(xtract_function_descriptor_t *fd){
 
     if (fd != NULL) {
         free(fd);
--- a/src/fini.c	Sat Dec 29 18:35:35 2007 +0000
+++ b/src/fini.c	Tue Jan 01 16:17:44 2008 +0000
@@ -22,7 +22,8 @@
 
 #ifdef XTRACT_FFT
 #include <fftw3.h>
-#include "xtract_globals_private.h"
+//#include "xtract_globals_private.h"
+#include "xtract/libxtract.h"
 #endif
 
 #ifdef __GNUC__
@@ -32,15 +33,8 @@
 #endif
 {
 #ifdef XTRACT_FFT
-    if(fft_plans.spectrum_plan != NULL)
-        fftwf_destroy_plan(fft_plans.spectrum_plan);
-    if(fft_plans.autocorrelation_fft_plan_1 != NULL)
-        fftwf_destroy_plan(fft_plans.autocorrelation_fft_plan_1);
-    if(fft_plans.autocorrelation_fft_plan_2 != NULL)
-        fftwf_destroy_plan(fft_plans.autocorrelation_fft_plan_2);
-    if(fft_plans.dct_plan != NULL)
-        fftwf_destroy_plan(fft_plans.dct_plan);
-    fftwf_cleanup();
+xtract_free_fft();
+fftwf_cleanup();
 #endif
 }
 
--- a/src/init.c	Sat Dec 29 18:35:35 2007 +0000
+++ b/src/init.c	Tue Jan 01 16:17:44 2008 +0000
@@ -203,6 +203,18 @@
 
 }
 
+void xtract_free_fft(void){
+    if(fft_plans.spectrum_plan != NULL)
+        fftwf_destroy_plan(fft_plans.spectrum_plan);
+    if(fft_plans.autocorrelation_fft_plan_1 != NULL)
+        fftwf_destroy_plan(fft_plans.autocorrelation_fft_plan_1);
+    if(fft_plans.autocorrelation_fft_plan_2 != NULL)
+        fftwf_destroy_plan(fft_plans.autocorrelation_fft_plan_2);
+    if(fft_plans.dct_plan != NULL)
+        fftwf_destroy_plan(fft_plans.dct_plan);
+//    fftwf_cleanup();
+}
+
 #endif
 
 int xtract_init_bark(int N, float sr, int *band_limits){
--- a/src/vector.c	Sat Dec 29 18:35:35 2007 +0000
+++ b/src/vector.c	Tue Jan 01 16:17:44 2008 +0000
@@ -368,6 +368,7 @@
     limits = (int *)argv;
     
     for(band = 0; band < XTRACT_BARK_BANDS - 1; band++){
+        result[band] = 0.f;
         for(n = limits[band]; n < limits[band + 1]; n++)
             result[band] += data[n];
     }
--- a/swig/java/Makefile.am	Sat Dec 29 18:35:35 2007 +0000
+++ b/swig/java/Makefile.am	Tue Jan 01 16:17:44 2008 +0000
@@ -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 @@
 	
 javaclasses = \
 	floatArray.class \
+	intArray.class \
 	SWIGTYPE_p_float.class \
 	SWIGTYPE_p_int.class \
 	SWIGTYPE_p_p_float.class \
--- a/swig/python/test.py	Sat Dec 29 18:35:35 2007 +0000
+++ b/swig/python/test.py	Tue Jan 01 16:17:44 2008 +0000
@@ -16,8 +16,16 @@
     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...'
 
--- a/swig/xtract.i	Sat Dec 29 18:35:35 2007 +0000
+++ b/swig/xtract.i	Tue Jan 01 16:17:44 2008 +0000
@@ -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"
+
+
--- a/xtract/libxtract.h	Sat Dec 29 18:35:35 2007 +0000
+++ b/xtract/libxtract.h	Tue Jan 01 16:17:44 2008 +0000
@@ -249,6 +249,8 @@
 /** \brief Data structure containing useful information about functions provided by LibXtract. */
 typedef struct _xtract_function_descriptor {
 
+    int id;
+
     struct {
 	char name[XTRACT_MAX_NAME_LENGTH];
 	char p_name[XTRACT_MAX_NAME_LENGTH]; /* pretty name */
@@ -379,6 +381,12 @@
  */
 int xtract_init_fft(int N, int feature_name);
 
+/** \brief Free memory used for fft plans
+ *
+ * This function should be used to explicitly free memory allocated for ffts by xtract_init_fft(). It is primarily intended for use if a new FFT needs to be taken with a different blocksize. If only one fft size is required then there is no need to call this function since it will be called when the program exits. 
+ * */
+void xtract_free_fft(void);
+
 /** \brief Make a window of a given type and return a pointer to it
  *
  * \param N: the size of the window
@@ -395,10 +403,10 @@
 void xtract_free_window(float *window);
 
 /* \brief A function to build an array of function descriptors */
-void *xtract_make_descriptors();
+xtract_function_descriptor_t *xtract_make_descriptors();
 
 /* \brief A function to free an array of function descriptors */
-int xtract_free_descriptors(void *fd);
+int xtract_free_descriptors(xtract_function_descriptor_t *fd);
 /* Free functions */
 
 /** @} */