diff options
-rw-r--r-- | src/fft.h | 2 | ||||
-rw-r--r-- | src/vector.c | 9 | ||||
-rw-r--r-- | src/window.c | 4 | ||||
-rw-r--r-- | swig/java/Makefile.am | 8 | ||||
-rw-r--r-- | swig/java/jxtract.i | 36 | ||||
-rw-r--r-- | swig/java/test.java | 6 | ||||
-rw-r--r-- | swig/python/test.py | 8 | ||||
-rw-r--r-- | swig/xtract.i | 49 |
8 files changed, 45 insertions, 77 deletions
@@ -28,6 +28,8 @@ #include <config.h> #endif +#include <stdbool.h> + #ifdef USE_OOURA #include "ooura/fftsg.h" #else diff --git a/src/vector.c b/src/vector.c index 4773797..80b5424 100644 --- a/src/vector.c +++ b/src/vector.c @@ -33,6 +33,10 @@ #include "xtract_macros_private.h" #include "xtract_globals_private.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327 +#endif + int xtract_spectrum(const double *data, const int N, const void *argv, double *result) { @@ -249,9 +253,9 @@ int xtract_autocorrelation_fft(const double *data, const int N, const void *argv double *rfft = NULL; int n = 0; int M = 0; - double M_double = 0.0; #ifndef USE_OOURA DSPDoubleSplitComplex *fft = NULL; + double M_double = 0.0; #endif M = N << 1; @@ -545,7 +549,7 @@ int xtract_harmonic_spectrum(const double *data, const int N, const void *argv, int xtract_lpc(const double *data, const int N, const void *argv, double *result) { - int i, j, k, M, L; + int i, j, M, L; double r = 0.0, error = 0.0; @@ -553,7 +557,6 @@ int xtract_lpc(const double *data, const int N, const void *argv, double *result *lpc = NULL ; error = data[0]; - k = N; /* The length of *data */ L = N - 1; /* The number of LPC coefficients */ M = L * 2; /* The length of *result */ ref = result; diff --git a/src/window.c b/src/window.c index 0d00402..6fe9a18 100644 --- a/src/window.c +++ b/src/window.c @@ -25,6 +25,10 @@ #include <math.h> +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327 +#endif + #include "xtract_window_private.h" void gauss(double *window, const int N, const double sd) diff --git a/swig/java/Makefile.am b/swig/java/Makefile.am index 4830d5a..e45d297 100644 --- a/swig/java/Makefile.am +++ b/swig/java/Makefile.am @@ -3,9 +3,9 @@ TESTNAME = test JAVA = java javasources = \ - SWIGTYPE_p_float.java \ + SWIGTYPE_p_double.java \ SWIGTYPE_p_int.java \ - SWIGTYPE_p_p_float.java \ + SWIGTYPE_p_p_double.java \ SWIGTYPE_p_unit_.java \ SWIGTYPE_p_void.java \ xtract_bool_t.java \ @@ -35,9 +35,9 @@ javasources = \ javaclasses = \ - SWIGTYPE_p_float.class \ + SWIGTYPE_p_double.class \ SWIGTYPE_p_int.class \ - SWIGTYPE_p_p_float.class \ + SWIGTYPE_p_p_double.class \ SWIGTYPE_p_unit_.class \ SWIGTYPE_p_void.class \ xtract_bool_t.class \ diff --git a/swig/java/jxtract.i b/swig/java/jxtract.i index 6918436..5c8c1db 100644 --- a/swig/java/jxtract.i +++ b/swig/java/jxtract.i @@ -2,29 +2,22 @@ %include "../xtract.i" %include "arrays_java.i" -/* -%{ -int mean(const float *data, const int N, void *in, float *result) { - return xtract_mean(data, N, in, result); -} -%} -*/ -%apply float[] {const float *data}; -/*%apply void *in {const void *argv}; */ -%apply float *OUTPUT { float *result }; +%apply double[] {const double *data}; +%apply double *OUTPUT { double *result }; %typemap(in,numinputs=0) JNIEnv *env "$1 = jenv;" -%javamethodmodifiers arr2voidf "private"; +%javamethodmodifiers arr2voidd "private"; %javamethodmodifiers arr2voidi "private"; -%javamethodmodifiers freearrf "private"; +%javamethodmodifiers freearrd "private"; %javamethodmodifiers freearri "private"; + %inline %{ -jlong arr2voidf(JNIEnv *env, jfloatArray arr) { +jlong arr2voidd(JNIEnv *env, jdoubleArray arr) { void *ptr = (*env)->GetFloatArrayElements(env, arr, NULL); return (intptr_t)ptr; } -void freearrf(JNIEnv *env, jfloatArray arr, jlong map) { +void freearrd(JNIEnv *env, jdoubleArray arr, jlong map) { void *ptr = 0; ptr = *(void **)↦ (*env)->ReleaseFloatArrayElements(env, arr, ptr, JNI_ABORT); @@ -45,8 +38,8 @@ void freearri(JNIEnv *env, jintArray arr, jlong map) { %pragma(java) modulecode=%{ private static long arrPtr(Object o) { - if (o instanceof float[]) { - return arr2voidf((float[])o); + if (o instanceof double[]) { + return arr2voidd((double[])o); } else if (o instanceof int[]) { return arr2voidi((int[])o); @@ -58,8 +51,8 @@ void freearri(JNIEnv *env, jintArray arr, jlong map) { } private static void freeArrPtr(Object o, long addr) { - if (o instanceof float[]) { - freearrf((float[])o, addr); + if (o instanceof double[]) { + freearrd((double[])o, addr); return; } else if (o instanceof int[]) { @@ -76,12 +69,5 @@ void freearri(JNIEnv *env, jintArray arr, jlong map) { %typemap(jstype) void *argv "Object" %typemap(javain,pre=" long tmp$javainput = arrPtr($javainput);",post=" freeArrPtr($javainput, tmp$javainput);") void *argv "tmp$javainput" -/* -int xtract_mean(const float *data, const int N, void *argv, float *result); -int xtract_variance(const float *data, const int N, void *argv, float *result); -*/ %include xtract_redeclare.i -/*%{ -#include "xtract/xtract_scalar.h" -%}*/ diff --git a/swig/java/test.java b/swig/java/test.java index 54328aa..82dd768 100644 --- a/swig/java/test.java +++ b/swig/java/test.java @@ -18,9 +18,9 @@ public class test { int len = 5; int retval = 0; - float mean[] = new float[1]; - float variance[] = new float[1]; - float data[] = new float[len]; + double mean[] = new double[1]; + double variance[] = new double[1]; + double data[] = new double[len]; for (int i = 0; i < len; i++){ System.out.print(i * 3 + ", "); diff --git a/swig/python/test.py b/swig/python/test.py index fe4981e..a89a6f9 100644 --- a/swig/python/test.py +++ b/swig/python/test.py @@ -9,7 +9,7 @@ print '\nRunning libxtract Python bindings test...\n' len = 8 -a = xtract.floatArray(len) +a = xtract.doubleArray(len) temp = [] for i in range(0, len): @@ -20,7 +20,7 @@ mean = xtract.xtract_mean(a,len,None)[1] print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % mean -argv = xtract.floatArray(1) +argv = xtract.doubleArray(1) argv[0] = mean variance = xtract.xtract_variance(a, len, argv)[1] @@ -29,12 +29,12 @@ print 'The variance is %.2f' % variance print 'Computing spectrum...' -argv = xtract.floatArray(1) +argv = xtract.doubleArray(1) argv[0] = 44100.0 / len # Fake sample rate xtract.xtract_init_fft(len, xtract.XTRACT_SPECTRUM); -result = xtract.floatArray(len) +result = xtract.doubleArray(len) xtract.xtract_spectrum(a,len,argv, result) diff --git a/swig/xtract.i b/swig/xtract.i index f550341..226aa2b 100644 --- a/swig/xtract.i +++ b/swig/xtract.i @@ -13,21 +13,10 @@ #include "xtract/libxtract.h" %} -/* -%typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], - SWIGTYPE (CLASS::*) "SWIG" - -%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], - SWIGTYPE (CLASS::*) %{ - protected long getPointer() { - return swigCPtr; - } -%} -*/ /* Helper functions */ %inline %{ - void *floata_to_voidp(float f[]) + void *doublea_to_voidp(double f[]) { return (void *)f; } @@ -41,7 +30,7 @@ /* Return a pointer to memory allocated for a mel filterbank */ xtract_mel_filter *create_filterbank(int n_filters, int blocksize){ - float **filters; + double **filters; xtract_mel_filter *mf; int n, N; @@ -50,10 +39,10 @@ mf = malloc(sizeof(xtract_mel_filter)); mf->n_filters = n_filters; - filters = (float **)malloc(n_filters * sizeof(float *)); + filters = (double **)malloc(n_filters * sizeof(double *)); for(n = 0; n < n_filters; n++) - filters[n] = (float *)malloc(N * sizeof(float)); + filters[n] = (double *)malloc(N * sizeof(double)); mf->filters = filters; @@ -65,7 +54,7 @@ void destroy_filterbank(xtract_mel_filter *filterbank){ int i = filterbank->n_filters; - float **filters; + double **filters; filters = filterbank->filters; @@ -78,29 +67,13 @@ } - /* 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); - } -*/ - - - %} #ifndef SWIGJAVA -%array_class(float, floatArray); +%array_class(double, doubleArray); %array_class(int, intArray); #endif -%apply float *OUTPUT { float *result }; - -/* %apply float[] {const float *data}; */ +%apply double *OUTPUT { double *result }; %ignore xtract; @@ -110,16 +83,16 @@ /* 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); + int xtract_flux(const double *data, const int N, const void *argv , double *result); + int xtract_lnorm(const double *data, const int N, const void *argv , double *result); %} -%clear float *result; +%clear double *result; %inline %{ - int xtract_difference_vector(const float *data, const int N, const void *argv, float *result); + int xtract_difference_vector(const double *data, const int N, const void *argv, double *result); %} |