Mercurial > hg > libxtract
changeset 30:4df9012cebf1
Replaced --enable-vector with --enable-fft and improved build
author | Jamie Bullock <jamie@postlude.co.uk> |
---|---|
date | Fri, 20 Oct 2006 12:30:46 +0000 |
parents | a9154a4599c2 |
children | cb667e483ad4 |
files | config.h.in configure.in doc/documentation.doxygen.in src/Makefile.am src/libxtract.c src/vector.c xtract/Makefile.am xtract/libxtract.h xtract/xtract_vector.h |
diffstat | 9 files changed, 166 insertions(+), 145 deletions(-) [+] |
line wrap: on
line diff
--- a/config.h.in Fri Oct 20 11:30:55 2006 +0000 +++ b/config.h.in Fri Oct 20 12:30:46 2006 +0000 @@ -1,14 +1,14 @@ /* config.h.in. Generated from configure.in by autoheader. */ +/* Build the fft functions */ +#undef BUILD_FFT + /* Build the pd example */ #undef BUILD_PD_EXAMPLE /* Build the simpletest example */ #undef BUILD_SIMPLETEST -/* Build the vector functions */ -#undef BUILD_VECTOR - /* Define to enable debug */ #undef DEBUG
--- a/configure.in Fri Oct 20 11:30:55 2006 +0000 +++ b/configure.in Fri Oct 20 12:30:46 2006 +0000 @@ -25,13 +25,13 @@ AC_CHECK_PROG([DOXYGEN], [doxygen], [doc], []) AC_SUBST(DOXYGEN) -AC_ARG_ENABLE(vector, - [ --enable-vector Turn fft-based vector processing on], +AC_ARG_ENABLE(fft, + [ --enable-fft Turn fft-based fft processing on], [case "${enableval}" in - yes) vector=true ;; - no) vector=false ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-vector) ;; - esac],[vector=false]) + yes) fft=true ;; + no) fft=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-fft) ;; + esac],[fft=false]) AC_ARG_ENABLE(pd_example, [ --enable-pd_example Compile the Pure Data external example], @@ -86,9 +86,9 @@ ]) dnl Are we building with fftw? -if [[ "$vector" = "true" ]] ; then +if [[ "$fft" = "true" ]] ; then LDFLAGS="$LDFLAGS -lfftw3f" - AC_DEFINE([BUILD_VECTOR], [1], [Build the vector functions]) + AC_DEFINE([BUILD_FFT], [1], [Build the fft functions]) AC_CHECK_HEADER(fftw3.h, [have_fftw3_hdr=yes ], [ have_pd_hdr=no echo @@ -98,7 +98,7 @@ ]) fi -AM_CONDITIONAL(BUILD_VECTOR, test "x${vector}" = 'xtrue') +AM_CONDITIONAL(BUILD_FFT, test "x${fft}" = 'xtrue') dnl are we building the simpletest example @@ -221,10 +221,10 @@ echo dnl echo you are using the ${host} architecture -if test "$vector" = "true"; then - echo "Fftw3: yes (using fftw3f)" +if test "$fft" = "true"; then + echo "fft: yes (using fftw3f)" else - echo "Fftw3: no (not using fftw3, no vector functions)" + echo "fft: no (not using fftw3, no fft functions)" fi if test "$simpletest" = "true"; then echo "simpletest example: yes"
--- a/doc/documentation.doxygen.in Fri Oct 20 11:30:55 2006 +0000 +++ b/doc/documentation.doxygen.in Fri Oct 20 12:30:46 2006 +0000 @@ -1005,7 +1005,7 @@ # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = XTRACT +PREDEFINED = XTRACT XTRACT_FFT # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded.
--- a/src/Makefile.am Fri Oct 20 11:30:55 2006 +0000 +++ b/src/Makefile.am Fri Oct 20 12:30:46 2006 +0000 @@ -1,17 +1,15 @@ -SOURCES = libxtract.c scalar.c delta.c init.c +SOURCES = libxtract.c scalar.c vector.c delta.c init.c -if BUILD_VECTOR -VECTOR = vector.c -VECTOR_DEFINE = -DVECTORFUNCS +if BUILD_FFT +FFT_DEFINE = -DXTRACT_FFT else -VECTOR = -VECTOR_DEFINE = +FFT_DEFINE = endif lib_LTLIBRARIES = libxtract.la -libxtract_la_CFLAGS = $(VECTOR_DEFINE) -libxtract_la_SOURCES = $(SOURCES) $(VECTOR) +libxtract_la_CFLAGS = $(FFT_DEFINE) +libxtract_la_SOURCES = $(SOURCES) libxtract_la_LDFLAGS = -shared
--- a/src/libxtract.c Fri Oct 20 11:30:55 2006 +0000 +++ b/src/libxtract.c Fri Oct 20 12:30:46 2006 +0000 @@ -54,23 +54,21 @@ xtract_lowest_match, xtract_hps, xtract_f0, - /* xtract_vector.h */ -#ifdef VECTORFUNCS - xtract_magnitude_spectrum, - xtract_autocorrelation, - xtract_autocorrelation_fft, - xtract_amdf, - xtract_asdf, - xtract_mfcc, - xtract_dct, - xtract_bark_coefficients, - xtract_peaks, -#endif - /* xtract_delta.h */ +/* xtract_delta.h */ xtract_flux, xtract_attack_time, xtract_decay_time, - xtract_delta_feature + xtract_delta_feature, +/* xtract_vector.h */ + xtract_autocorrelation, + xtract_amdf, + xtract_asdf, + xtract_bark_coefficients, + xtract_peaks, + xtract_magnitude_spectrum, + xtract_autocorrelation_fft, + xtract_mfcc, + xtract_dct }; char *xtract_help_strings[] = { @@ -104,17 +102,17 @@ "xtract_lowest_match", "xtract_hps", "xtract_f0", - "xtract_magnitude_spectrum", - "xtract_autocorrelation", - "xtract_autocorrelation_fft", - "xtract_amdf", - "xtract_asdf", - "xtract_mfcc", - "xtract_dct", - "xtract_bark_coefficients", - "xtract_peaks", "xtract_flux", "xtract_attack_time", "xtract_decay_time", "xtract_delta_feature" -}; + "xtract_autocorrelation", + "xtract_amdf", + "xtract_asdf", + "xtract_bark_coefficients", + "xtract_peaks", + "xtract_magnitude_spectrum", + "xtract_autocorrelation_fft", + "xtract_mfcc", + "xtract_dct", + };
--- a/src/vector.c Fri Oct 20 11:30:55 2006 +0000 +++ b/src/vector.c Fri Oct 20 12:30:46 2006 +0000 @@ -23,6 +23,9 @@ #include "xtract/libxtract.h" #include <math.h> + +#ifdef XTRACT_FFT + #include <fftw3.h> int xtract_magnitude_spectrum(float *data, int N, void *argv, float *result){ @@ -50,23 +53,6 @@ } -int xtract_autocorrelation(float *data, int N, void *argv, float *result){ - - /* Naive time domain implementation */ - - int n = N, i; - - float corr; - - while(n--){ - corr = 0; - for(i = 0; i < N - n; i++){ - corr += data[i] * data[i + n]; - } - result[n] = corr / N; - } -} - int xtract_autocorrelation_fft(float *data, int N, void *argv, float *result){ float *temp; @@ -85,6 +71,84 @@ fftwf_free(temp); } +int xtract_mfcc(float *data, int N, void *argv, float *result){ + + xtract_mel_filter *f; + int n, filter; + fftwf_plan plan; + + f = (xtract_mel_filter *)argv; + + for(filter = 0; filter < f->n_filters; filter++){ + for(n = 0; n < N; n++){ + result[filter] += data[n] * f->filters[filter][n]; + } + if(result[filter] < LOG_LIMIT) result[filter] = LOG_LIMIT; + result[filter] = log(result[filter]); + } + + for(n = filter + 1; n < N; n++) result[n] = 0; + + xtract_dct(result, f->n_filters, NULL, result); + +} + +int xtract_dct(float *data, int N, void *argv, float *result){ + + fftwf_plan plan; + + plan = + fftwf_plan_r2r_1d(N, data, result, FFTW_REDFT00, FFTW_ESTIMATE); + + fftwf_execute(plan); + fftwf_destroy_plan(plan); +} + +#else + +int xtract_magnitude_spectrum(float *data, int N, void *argv, float *result){ + + NOT_IMPLEMENTED; + +} + +int xtract_autocorrelation_fft(float *data, int N, void *argv, float *result){ + + NOT_IMPLEMENTED; + +} + +int xtract_mfcc(float *data, int N, void *argv, float *result){ + + NOT_IMPLEMENTED; + +} + +int xtract_dct(float *data, int N, void *argv, float *result){ + + NOT_IMPLEMENTED; + +} + +#endif + +int xtract_autocorrelation(float *data, int N, void *argv, float *result){ + + /* Naive time domain implementation */ + + int n = N, i; + + float corr; + + while(n--){ + corr = 0; + for(i = 0; i < N - n; i++){ + corr += data[i] * data[i + n]; + } + result[n] = corr / N; + } +} + int xtract_amdf(float *data, int N, void *argv, float *result){ int n = N, i; @@ -118,39 +182,6 @@ } } -int xtract_mfcc(float *data, int N, void *argv, float *result){ - - xtract_mel_filter *f; - int n, filter; - fftwf_plan plan; - - f = (xtract_mel_filter *)argv; - - for(filter = 0; filter < f->n_filters; filter++){ - for(n = 0; n < N; n++){ - result[filter] += data[n] * f->filters[filter][n]; - } - if(result[filter] < LOG_LIMIT) result[filter] = LOG_LIMIT; - result[filter] = log(result[filter]); - } - - for(n = filter + 1; n < N; n++) result[n] = 0; - - xtract_dct(result, f->n_filters, NULL, result); - -} - -int xtract_dct(float *data, int N, void *argv, float *result){ - - fftwf_plan plan; - - plan = - fftwf_plan_r2r_1d(N, data, result, FFTW_REDFT00, FFTW_ESTIMATE); - - fftwf_execute(plan); - fftwf_destroy_plan(plan); -} - int xtract_bark_coefficients(float *data, int N, void *argv, float *result){ int *limits, band, n;
--- a/xtract/Makefile.am Fri Oct 20 11:30:55 2006 +0000 +++ b/xtract/Makefile.am Fri Oct 20 12:30:46 2006 +0000 @@ -1,11 +1,5 @@ libxtractdir = $(includedir)/xtract -if BUILD_VECTOR -XTRACT_VECTOR = xtract_vector.h -else -XTRACT_VECTOR = -endif +libxtract_HEADERS = libxtract.h xtract_macros.h xtract_types.h xtract_delta.h \ + xtract_scalar.h xtract_vector.h -libxtract_HEADERS = libxtract.h xtract_macros.h xtract_types.h xtract_delta.h \ - xtract_scalar.h $(XTRACT_VECTOR) -
--- a/xtract/libxtract.h Fri Oct 20 11:30:55 2006 +0000 +++ b/xtract/libxtract.h Fri Oct 20 12:30:46 2006 +0000 @@ -53,7 +53,8 @@ * @{ */ -#define XTRACT_FEATURES 43 +#define XTRACT_FEATURES 42 + #define LOG_LIMIT 10e-10 #define VERY_BIG_NUMBER 2e10 #define SR_LIMIT 192000 @@ -91,19 +92,19 @@ LOWEST_MATCH, HPS, F0, - MAGNITUDE_SPECTRUM, - AUTOCORRELATION, - AUTOCORRELATION_FFT, - AMDF, - ASDF, - MFCC, - DCT, - BARK_COEFFICIENTS, - PEAKS, FLUX, ATTACK_TIME, DECAY_TIME, - DELTA_FEATURE + DELTA_FEATURE, + AUTOCORRELATION, + AMDF, + ASDF, + BARK_COEFFICIENTS, + PEAKS, + MAGNITUDE_SPECTRUM, + AUTOCORRELATION_FFT, + MFCC, + DCT }; /** \brief Enumeration of feature types */
--- a/xtract/xtract_vector.h Fri Oct 20 11:30:55 2006 +0000 +++ b/xtract/xtract_vector.h Fri Oct 20 12:30:46 2006 +0000 @@ -43,6 +43,33 @@ */ int xtract_magnitude_spectrum(float *data, int N, void *argv, float *result); +/** \brief Extract autocorrelation from time domain signal using FFT based method + * + * \param *data: a pointer to the first element in an array of floats representing an audio vector + * \param N: the number of array elements to be considered + * \param *argv: a pointer to NULL + * \param *result: the autocorrelation of N values from the array pointed to by *data + */ +int xtract_autocorrelation_fft(float *data, int N, void *argv, float *result); + +/** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner + * + * \param *data: a pointer to the first element in an array of floats + * \param N: the number of array elements to be considered + * \param *argv: a pointer to a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank + * \param *result: a pointer to an array containing the resultant MFCC + * + * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc + */ +int xtract_mfcc(float *data, int N, void *argv, float *result); + +/** \brief Extract the Discrete Cosine transform of a time domain signal + * \param *data: a pointer to the first element in an array of floats representing an audio vector + * \param N: the number of array elements to be considered + * \param *argv: a pointer to NULL + * \param *result: a pointer to an array containing resultant dct coefficients + */ +int xtract_dct(float *data, int N, void *argv, float *result); /** \brief Extract autocorrelation from time domain signal using time-domain autocorrelation technique * @@ -53,15 +80,6 @@ */ int xtract_autocorrelation(float *data, int N, void *argv, float *result); -/** \brief Extract autocorrelation from time domain signal using FFT based method - * - * \param *data: a pointer to the first element in an array of floats representing an audio vector - * \param N: the number of array elements to be considered - * \param *argv: a pointer to NULL - * \param *result: the autocorrelation of N values from the array pointed to by *data - */ -int xtract_autocorrelation_fft(float *data, int N, void *argv, float *result); - /** \brief Extract Average Magnitude Difference Function from time domain signal * * \param *data: a pointer to the first element in an array of floats @@ -80,17 +98,6 @@ */ int xtract_asdf(float *data, int N, void *argv, float *result); -/** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner - * - * \param *data: a pointer to the first element in an array of floats - * \param N: the number of array elements to be considered - * \param *argv: a pointer to a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank - * \param *result: a pointer to an array containing the resultant MFCC - * - * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc - */ -int xtract_mfcc(float *data, int N, void *argv, float *result); - /** \brief Extract Bark band coefficients based on a method * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector * \param N: the number of array elements to be considered @@ -102,14 +109,6 @@ */ int xtract_bark_coefficients(float *data, int N, void *argv, float *result); -/** \brief Extract the Discrete Cosine transform of a time domain signal - * \param *data: a pointer to the first element in an array of floats representing an audio vector - * \param N: the number of array elements to be considered - * \param *argv: a pointer to NULL - * \param *result: a pointer to an array containing resultant dct coefficients - */ -int xtract_dct(float *data, int N, void *argv, float *result); - /** \brief Extract the frequency and amplitude of spectral peaks from a of a magnitude spectrum * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector * \param N: the number of array elements to be considered