aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/descriptors.c7
-rw-r--r--src/fini.c14
-rw-r--r--src/init.c12
-rw-r--r--src/vector.c1
-rw-r--r--swig/java/Makefile.am2
-rw-r--r--swig/python/test.py12
-rw-r--r--swig/xtract.i92
-rw-r--r--xtract/libxtract.h12
8 files changed, 135 insertions, 17 deletions
diff --git a/src/descriptors.c b/src/descriptors.c
index 4c232d7..ac1fd1b 100644
--- a/src/descriptors.c
+++ b/src/descriptors.c
@@ -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 @@ void *xtract_make_descriptors(){
while(f--){
d = &fd[f];
+ d->id = f;
argc = &d->argc;
argv_type = &d->argv.type;
@@ -502,7 +503,7 @@ void *xtract_make_descriptors(){
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 @@ void *xtract_make_descriptors(){
return fd;
}
-int xtract_free_descriptors(void *fd){
+int xtract_free_descriptors(xtract_function_descriptor_t *fd){
if (fd != NULL) {
free(fd);
diff --git a/src/fini.c b/src/fini.c
index 185fb62..35b7f65 100644
--- a/src/fini.c
+++ b/src/fini.c
@@ -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 @@ void _fini()
#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
}
diff --git a/src/init.c b/src/init.c
index 6112e73..6e544af 100644
--- a/src/init.c
+++ b/src/init.c
@@ -203,6 +203,18 @@ int xtract_init_fft(int N, int feature_name){
}
+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){
diff --git a/src/vector.c b/src/vector.c
index d3fdd67..0ffd8ae 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -368,6 +368,7 @@ int xtract_bark_coefficients(const float *data, const int N, const void *argv, f
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];
}
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"
+
+
diff --git a/xtract/libxtract.h b/xtract/libxtract.h
index ae70efb..32d3c31 100644
--- a/xtract/libxtract.h
+++ b/xtract/libxtract.h
@@ -249,6 +249,8 @@ typedef enum xtract_vector_ {
/** \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_bark(int N, float sr, int *band_limits);
*/
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 @@ float *xtract_init_window(const int N, const int type);
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 */
/** @} */