From: Amaury Hazan Date: Thu, 6 Sep 2007 17:32:13 +0000 (+0200) Subject: minor changes X-Git-Tag: bzr2git~442^2~14^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7c6c806dda27c76b03afac7bfeecdaa88371a0ed;p=aubio.git minor changes --- diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index 7a13328e..df4dd2a4 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -26,10 +26,6 @@ int aubio_process(float **input, float **output, int nframes) { unsigned int i; /*channels*/ unsigned int j; /*frames*/ - // declare the mel filter bank - // TODO: should be done only once - aubio_mfcc_init(int N, NYQUIST, int style, float freq_min, float freq_max, int freq_bands, float **fft_tables); - for (j=0;j<(unsigned)nframes;j++) { if(usejack) { for (i=0;inorm, nframes, mf, outbuf); + aubio_mffc_do(fftgrain->norm, nframes, mf, mfcc_outbuf, fft_dct, fftgrain_dct); - for (coef_cnt=0; coef_cntn_filters = 20; mf->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *)); diff --git a/examples/utils.c b/examples/utils.c index 0a676068..b0b02e75 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -60,6 +60,20 @@ fvec_t *onset2; int isonset = 0; aubio_pickpeak_t * parms; +/* mfcc objects */ +//parameters +uint_t n_filters=20; +uint_t nyquist= samplerate / 2.; +smpl_t lowfreq=80.f; +smpl_t highfreq=18000.f; +// filterbank object +aubio_mel_filter * mf; + +// DCT mfft and result storage +aubio_mfft * fft_dct; +cvec_t * fftgrain_dct; +smpl_t mfcc_outbuf[11]; + /* pitch objects */ smpl_t pitch = 0.; @@ -300,6 +314,9 @@ void examples_common_init(int argc,char ** argv) { obuf = new_fvec(overlap_size, channels); fftgrain = new_cvec(buffer_size, channels); + //init for mfcc process + fftgrain_dct= new_cvec(n_filters, channels); + if (usepitch) { pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, type_pitch, mode_pitch); @@ -312,6 +329,11 @@ void examples_common_init(int argc,char ** argv) { } /* phase vocoder */ pv = new_aubio_pvoc(buffer_size, overlap_size, channels); + + // dct phase vocoder + //TODO: check size + fft_dct = new_aubio_mfft(n_filters, channels); + /* onsets */ parms = new_aubio_peakpicker(threshold); o = new_aubio_onsetdetection(type_onset,buffer_size,channels); @@ -345,6 +367,11 @@ void examples_common_del(void){ del_cvec(fftgrain); del_fvec(onset); del_fvec(woodblock); + + //mffc related + del_aubio_mfft(fft_dct); + del_cvec(fftgrain_dct); + aubio_cleanup(); } diff --git a/examples/utils.h b/examples/utils.h index d4d02235..affedfd9 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -97,6 +97,18 @@ extern fvec_t *onset2; extern int isonset; extern aubio_pickpeak_t * parms; +/* mfcc objects */ +// params +extern uint_t n_filters; +extern uint_t nyquist; +extern smpl_t lowfreq; +extern smpl_t highfreq; +// filterbank object +extern aubio_mel_filter * mf; +// DCT pvoc and result storage +extern aubio_mfft_t * fft_dct; +extern cvec_t * fftgrain_dct; +extern smpl_t mfcc_outbuf[20]; /* pitch objects */ extern smpl_t pitch; diff --git a/src/Makefile.am b/src/Makefile.am index bd952e21..2fdf0756 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,8 @@ pkginclude_HEADERS = aubio.h \ beattracking.h \ onset.h \ tempo.h \ - filter.h + filter.h \ + mfcc.h nodist_pkginclude_HEADERS = config.h @@ -70,6 +71,8 @@ libaubio_la_SOURCES = aubio.h \ tempo.h \ filter.c \ filter.h \ + mfcc.h \ + mfcc.c AM_CFLAGS = @AUBIO_CFLAGS@ @FFTWLIB_CFLAGS@ @SAMPLERATE_CFLAGS@ libaubio_la_LIBADD = @FFTWLIB_LIBS@ @SAMPLERATE_LIBS@ @LTLIBOBJS@ diff --git a/src/filterbank.c b/src/filterbank.c index d6aa1e8d..3a63eebb 100644 --- a/src/filterbank.c +++ b/src/filterbank.c @@ -20,8 +20,18 @@ */ +#include "aubio_priv.h" #include "filterbank.h" + +// Struct Declaration + +/** \brief A structure to store a set of n_filters Mel filters */ +typedef struct aubio_mel_filter_ { + int n_filters; + smpl_t **filters; +}; + // Initialization int aubio_mfcc_init(int N, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max, int freq_bands, smpl_t **fft_tables){ diff --git a/src/filterbank.h b/src/filterbank.h index 8a8fecf8..4b57bd12 100644 --- a/src/filterbank.h +++ b/src/filterbank.h @@ -22,14 +22,13 @@ #ifndef AUBIOFILTERBANK_H #define AUBIOFILTERBANK_H +#ifdef __cplusplus +extern "C" { +#endif + -// Struct Declaration -/** \brief A structure to store a set of n_filters Mel filters */ -typedef struct aubio_mel_filter_ { - int n_filters; - smpl_t **filters; -} aubio_mel_filter; +typedef struct aubio_mel_filter_ aubio_mel_filter; // Initialization @@ -37,6 +36,10 @@ typedef struct aubio_mel_filter_ { * * It is up to the caller to pass in a pointer to memory allocated for freq_bands arrays of length N. This function populates these arrays with magnitude coefficients representing the mel filterbank on a linear scale */ -int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, smpl_t ** fft_tables); +int aubio_mfcc_init(int N, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max, int freq_bands, smpl_t ** fft_tables); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/mfcc.c b/src/mfcc.c index 1d94a0d0..a92d9e61 100644 --- a/src/mfcc.c +++ b/src/mfcc.c @@ -20,12 +20,24 @@ */ +#include "aubio_priv.h" +#include "sample.h" +#include "fft.h" +#include "mfcc.h" +#include "math.h" -#include "mffc.h" +/* +new_aubio_mfcc +aubio_mfcc_do +del_aubio_mfcc +*/ // Computation +// Added last two arguments to be able to pass from example + -int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result){ + +int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ aubio_mel_filter *f; int n, filter; @@ -37,41 +49,38 @@ int aubio_mfcc_do(const float *data, const int N, const void *argv, float *resul for(n = 0; n < N; n++){ result[filter] += data[n] * f->filters[filter][n]; } - result[filter] = log(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]); + result[filter] = LOG(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]); } - //TODO: check that zero padding + //TODO: check that zero padding for(n = filter + 1; n < N; n++) result[n] = 0; - aubio_dct_do(result, f->n_filters, NULL, result); + aubio_dct_do(result, f->n_filters, NULL, result, fft_dct, fftgrain_dct); return XTRACT_SUCCESS; } -int aubio_dct_do(const float *data, const int N, const void *argv, float *result){ +// Added last two arguments to be able to pass from example + +int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ //call aubio p_voc in dct setting //TODO: fvec as input? Remove data length, N? + fvec_t * momo = new_fvec(20, 1); + momo->data = data; + //compute mag spectrum - aubio_pvoc_do (pv,data, fftgrain); + aubio_mfft_do (fft_dct, data, fftgrain_dct); int i; //extract real part of fft grain for(i=0; inorm[i]*cos(fftgrain->phase[i]); + result[i]= fftgrain_dct->norm[0][i]*COS(fftgrain_dct->phas[0][i]); } - - /* - fftwf_plan plan; - - plan = - fftwf_plan_r2r_1d(N, (float *) data, result, FFTW_REDFT00, FFTW_ESTIMATE); - - fftwf_execute(plan); - fftwf_destroy_plan(plan);*/ + return XTRACT_SUCCESS; } diff --git a/src/mfcc.h b/src/mfcc.h index c9251349..d4b03639 100644 --- a/src/mfcc.h +++ b/src/mfcc.h @@ -23,11 +23,40 @@ #ifndef MFCC_H #define MFCC_H +#ifdef __cplusplus +extern "C" { +#endif + #include "filterbank.h" -//libXtract enums +//libXtract constants and enums // TODO: remove them +#define XTRACT_SQ(a) ((a) * (a)) +#define XTRACT_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define XTRACT_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define XTRACT_NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n") +#define XTRACT_VERY_SMALL_NUMBER 2e-42 +#define XTRACT_LOG_LIMIT XTRACT_VERY_SMALL_NUMBER +#define XTRACT_LOG_LIMIT_DB -96.0 +#define XTRACT_DB_SCALE_OFFSET 96.0 +#define XTRACT_VERY_BIG_NUMBER 2e42 +#define XTRACT_SR_UPPER_LIMIT 192000.0 +#define XTRACT_SR_LOWER_LIMIT 22050.0 +#define XTRACT_SR_DEFAULT 44100.0 +#define XTRACT_FUNDAMENTAL_DEFAULT 440.0 +#define XTRACT_CHECK_nyquist if(!nyquist) nyquist = XTRACT_SR_DEFAULT / 2 +#define XTRACT_CHECK_q if(!q) q = XTRACT_SR_DEFAULT / N +#define XTRACT_IS_ODD(x) (x % 2 != 0 ? 1 : 0) +#define XTRACT_SR_LIMIT SR_UPPER_LIMIT +#define XTRACT_FFT_BANDS_MIN 16 +#define XTRACT_FFT_BANDS_MAX 65536 +#define XTRACT_FFT_BANDS_DEF 1024 +#define XTRACT_SPEC_BW_MIN 0.168 /* Minimum spectral bandwidth \ + (= SR_LOWER_LIMIT / FFT_BANDS_MAX*/ +#define XTRACT_SPEC_BW_MAX 12000.0 /* SR_UPPER_LIMIT / FFT_BANDS_MIN */ +#define XTRACT_SPEC_BW_DEF 43.066 /* SR_DEFAULT / FFT_BANDS_DEF */ + /** \brief Enumeration of feature initialisation functions */ enum xtract_feature_init_ { XTRACT_INIT_MFCC = 100, @@ -131,7 +160,9 @@ typedef enum xtract_vector_ { * * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc */ -int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result); + + +int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct); /** \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 @@ -139,7 +170,10 @@ int aubio_mfcc_do(const float *data, const int N, const void *argv, float *resul * \param *argv: a pointer to NULL * \param *result: a pointer to an array containing resultant dct coefficients */ -int aubio_dct_do(const float *data, const int N, const void *argv, float *result); +int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct); +#ifdef __cplusplus +} +#endif #endif