From: Paul Brossier Date: Wed, 5 Sep 2007 19:37:09 +0000 (+0200) Subject: minor corrections X-Git-Tag: bzr2git~442^2~31^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fe28ff360b46117dcf22aa6baf889798f7a9bc81;p=aubio.git minor corrections --- diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index cca66054..3dcd2ab9 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -41,10 +41,9 @@ int aubio_process(float **input, float **output, int nframes) { //compute mag spectrum aubio_pvoc_do (pv,ibuf, fftgrain); - //TODO: extract Magnitude buffer f_fvec from fftgrain cvec - - //compute mfccs - aubio_mffc_do (magbuf, nframes, filterbank, outbuf); + + //compute mfcics + aubio_mffc_do(fftgrain->norm, nframes, filterbank, outbuf); @@ -73,10 +72,31 @@ void process_print (void) { int main(int argc, char **argv) { examples_common_init(argc,argv); + + //allocate and initialize mel filter bank + uint_t n_filters=20; + uint_t nyquist= samplerate / 2.; + + uint_t banksize = (uint) ( sizeof(aubio_mel_filter)); + aubio_mel_filter * mf = (aubio_mel_filter *)getbytes(banksize); + + mfilterbank->n_filters = 20; + mfilterbank->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *)); + for(n = 0; n < mf->n_filters; n++) + mf->filters[n] = (smpl_t *)getbytes((buffer_size/2+1) * sizeof(smpl_t)); + + //populating the filter + new_aubio_mfcc(buffer_size, nyquist, XTRACT_EQUAL_GAIN, 80.0f, 18000.0f, mf->n_filters, mf->filters); + + //process examples_common_process(aubio_process,process_print); examples_common_del(); debug("End of program.\n"); fflush(stderr); + + //destroying filterbank + free(mf); + return 0; } diff --git a/src/aubio.h b/src/aubio.h index f5235823..3006bcfb 100644 --- a/src/aubio.h +++ b/src/aubio.h @@ -79,6 +79,7 @@ extern "C" { #include "beattracking.h" #include "onset.h" #include "tempo.h" +#include "mfcc.h" #ifdef __cplusplus } /* extern "C" */ diff --git a/src/aubiofilterbank.c b/src/aubiofilterbank.c index a4fa1997..6039998e 100644 --- a/src/aubiofilterbank.c +++ b/src/aubiofilterbank.c @@ -24,10 +24,10 @@ // Initialization -int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, float **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){ int n, i, k, *fft_peak, M, next_peak; - float norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, + smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, freq_bw_mel, *mel_peak, *height_norm, *lin_peak; mel_peak = height_norm = lin_peak = NULL; @@ -38,11 +38,11 @@ int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_ mel_freq_min = 1127 * log(1 + freq_min / 700); freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands; - mel_peak = (float *)malloc((freq_bands + 2) * sizeof(float)); + mel_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t)); /* +2 for zeros at start and end */ - lin_peak = (float *)malloc((freq_bands + 2) * sizeof(float)); + lin_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t)); fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int)); - height_norm = (float *)malloc(freq_bands * sizeof(float)); + height_norm = (smpl_t *)malloc(freq_bands * sizeof(smpl_t)); if(mel_peak == NULL || height_norm == NULL || lin_peak == NULL || fft_peak == NULL) @@ -120,4 +120,4 @@ int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_ return XTRACT_SUCCESS; -} \ No newline at end of file +} diff --git a/src/aubiofilterbank.h b/src/aubiofilterbank.h index acd32e5b..8a8fecf8 100644 --- a/src/aubiofilterbank.h +++ b/src/aubiofilterbank.h @@ -17,20 +17,18 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef AUBIOFILTERBANK_H -#include AUBIOFILTERBANK_H +#define AUBIOFILTERBANK_H -#define NYQUIST 22050.f // Struct Declaration /** \brief A structure to store a set of n_filters Mel filters */ typedef struct aubio_mel_filter_ { int n_filters; - float **filters; + smpl_t **filters; } aubio_mel_filter; // Initialization @@ -39,6 +37,6 @@ 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, float **fft_tables); +int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, smpl_t ** fft_tables); -#endif \ No newline at end of file +#endif diff --git a/src/mfcc.h b/src/mfcc.h index 03a9c5d6..856f77c7 100644 --- a/src/mfcc.h +++ b/src/mfcc.h @@ -23,6 +23,8 @@ #ifndef MFCC_H #define MFCC_H +#include "aubiofilterbank.h" + #define NYQUIST 22050.f //libXtract enums @@ -142,4 +144,4 @@ int aubio_mfcc_do(const float *data, const int N, const void *argv, float *resul int aubio_dct_do(const float *data, const int N, const void *argv, float *result); -#endif \ No newline at end of file +#endif