aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fini.c16
-rw-r--r--src/init.c42
-rw-r--r--src/vector.c10
-rw-r--r--src/xtract_globals_private.h23
4 files changed, 58 insertions, 33 deletions
diff --git a/src/fini.c b/src/fini.c
index 3ec9133..185fb62 100644
--- a/src/fini.c
+++ b/src/fini.c
@@ -32,14 +32,14 @@ void _fini()
#endif
{
#ifdef XTRACT_FFT
- if(spectrum_plan != NULL)
- fftwf_destroy_plan(spectrum_plan);
- if(autocorrelation_fft_plan_1 != NULL)
- fftwf_destroy_plan(autocorrelation_fft_plan_1);
- if(autocorrelation_fft_plan_2 != NULL)
- fftwf_destroy_plan(autocorrelation_fft_plan_2);
- if(dct_plan != NULL)
- fftwf_destroy_plan(dct_plan);
+ 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
}
diff --git a/src/init.c b/src/init.c
index dd4ed78..37be14c 100644
--- a/src/init.c
+++ b/src/init.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include "xtract/libxtract.h"
+#define DEFINE_GLOBALS
#include "xtract_globals_private.h"
#ifdef XTRACT_FFT
@@ -166,30 +167,30 @@ int xtract_init_fft(int N, int feature_name){
switch(feature_name){
case XTRACT_SPECTRUM:
- if(spectrum_plan != NULL)
- fftwf_destroy_plan(spectrum_plan);
- spectrum_plan =
+ if(fft_plans.spectrum_plan != NULL)
+ fftwf_destroy_plan(fft_plans.spectrum_plan);
+ fft_plans.spectrum_plan =
fftwf_plan_r2r_1d(N, input, output, FFTW_R2HC, optimisation);
break;
case XTRACT_AUTOCORRELATION_FFT:
- if(autocorrelation_fft_plan_1 != NULL)
- fftwf_destroy_plan(autocorrelation_fft_plan_1);
- if(autocorrelation_fft_plan_2 != NULL)
- fftwf_destroy_plan(autocorrelation_fft_plan_2);
- autocorrelation_fft_plan_1 =
+ 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);
+ fft_plans.autocorrelation_fft_plan_1 =
fftwf_plan_r2r_1d(N, input, output, FFTW_R2HC, optimisation);
- autocorrelation_fft_plan_2 =
+ fft_plans.autocorrelation_fft_plan_2 =
fftwf_plan_r2r_1d(N, input, output, FFTW_HC2R, optimisation);
break;
case XTRACT_DCT:
- if(dct_plan != NULL)
- fftwf_destroy_plan(dct_plan);
- dct_plan =
+ if(fft_plans.dct_plan != NULL)
+ fftwf_destroy_plan(fft_plans.dct_plan);
+ fft_plans.dct_plan =
fftwf_plan_r2r_1d(N, input, output, FFTW_REDFT00, optimisation);
case XTRACT_MFCC:
- if(dct_plan != NULL)
- fftwf_destroy_plan(dct_plan);
- dct_plan =
+ if(fft_plans.dct_plan != NULL)
+ fftwf_destroy_plan(fft_plans.dct_plan);
+ fft_plans.dct_plan =
fftwf_plan_r2r_1d(N, output, output, FFTW_REDFT00, optimisation);
break;
}
@@ -216,3 +217,14 @@ int xtract_init_bark(int N, float sr, int *band_limits){
return XTRACT_SUCCESS;
}
+#ifdef __GNUC__
+__attribute__((constructor)) void init()
+#else
+ void _init()ยท
+#endif
+{
+ fft_plans.spectrum_plan = NULL;
+ fft_plans.autocorrelation_fft_plan_1 = NULL;
+ fft_plans.autocorrelation_fft_plan_2 = NULL;
+ fft_plans.dct_plan = NULL;
+}
diff --git a/src/vector.c b/src/vector.c
index a9c5290..0305751 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -65,7 +65,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res
XTRACT_CHECK_q;
- if(spectrum_plan == NULL){
+ if(fft_plans.spectrum_plan == NULL){
/* FIX: Not sure this should really be here. Might introduce
* DEBUG_POST macro, or some kind of error handler, or leave it to the
* caller... */
@@ -74,7 +74,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res
return XTRACT_NO_RESULT;
}
- fftwf_execute_r2r(spectrum_plan, input, rfft);
+ fftwf_execute_r2r(fft_plans.spectrum_plan, input, rfft);
switch(vector){
@@ -186,7 +186,7 @@ int xtract_autocorrelation_fft(const float *data, const int N, const void *argv,
time = (float *)calloc(M, sizeof(float));
time = memcpy(time, data, N * sizeof(float));
- fftwf_execute_r2r(autocorrelation_fft_plan_1, time, freq);
+ fftwf_execute_r2r(fft_plans.autocorrelation_fft_plan_1, time, freq);
//plan = fftwf_plan_r2r_1d(M, time, freq, FFTW_R2HC, FFTW_ESTIMATE);
//fftwf_execute(plan);
@@ -203,7 +203,7 @@ int xtract_autocorrelation_fft(const float *data, const int N, const void *argv,
//fftwf_execute(plan);
- fftwf_execute_r2r(autocorrelation_fft_plan_2, freq, time);
+ fftwf_execute_r2r(fft_plans.autocorrelation_fft_plan_2, freq, time);
/* Normalisation factor */
M = M * N;
@@ -246,7 +246,7 @@ int xtract_dct(const float *data, const int N, const void *argv, float *result){
//plan =
// fftwf_plan_r2r_1d(N, (float *) data, result, FFTW_REDFT00, FFTW_ESTIMATE);
- fftwf_execute_r2r(dct_plan, (float *)data, result);
+ fftwf_execute_r2r(fft_plans.dct_plan, (float *)data, result);
//fftwf_execute(plan);
//fftwf_destroy_plan(plan);
diff --git a/src/xtract_globals_private.h b/src/xtract_globals_private.h
index dd0f36f..cab1660 100644
--- a/src/xtract_globals_private.h
+++ b/src/xtract_globals_private.h
@@ -26,11 +26,24 @@
#ifdef XTRACT_FFT
#include <fftw3.h>
-extern fftwf_plan spectrum_plan,
- autocorrelation_fft_plan_1,
- autocorrelation_fft_plan_2,
- dct_plan;
-#endif
+struct xtract_fft_plans_ {
+
+ fftwf_plan spectrum_plan;
+ fftwf_plan autocorrelation_fft_plan_1;
+ fftwf_plan autocorrelation_fft_plan_2;
+ fftwf_plan dct_plan;
+
+};
+#ifdef DEFINE_GLOBALS
+#define GLOBAL
+#else
+#define GLOBAL extern
#endif
+GLOBAL struct xtract_fft_plans_ fft_plans;
+
+#endif /* FFT */
+
+#endif /* Header guard */
+