From cfd35dbe9ee20e0697abf8b3ffb2b7182b4e2b41 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 17 Sep 2009 01:26:49 +0200 Subject: [PATCH] src/spectral/filterbank_mel.{c,h}: indent --- src/spectral/filterbank_mel.c | 134 ++++++++++++++++++---------------- src/spectral/filterbank_mel.h | 8 +- 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/src/spectral/filterbank_mel.c b/src/spectral/filterbank_mel.c index 55d9ef14..01b6c4db 100644 --- a/src/spectral/filterbank_mel.c +++ b/src/spectral/filterbank_mel.c @@ -25,11 +25,14 @@ #include "spectral/filterbank.h" #include "mathutils.h" -void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){ +void +aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, uint_t samplerate, + smpl_t freq_min, smpl_t freq_max) +{ - fvec_t *filters = aubio_filterbank_get_coeffs(fb); + fvec_t *filters = aubio_filterbank_get_coeffs (fb); uint_t n_filters = filters->channels, win_s = filters->length; - + //slaney params smpl_t lowestFrequency = 133.3333; smpl_t linearSpacing = 66.66666666; @@ -38,47 +41,48 @@ void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, uint_t linearFilters = 13; uint_t logFilters = 27; uint_t allFilters = linearFilters + logFilters; - + //buffers for computing filter frequencies - fvec_t * freqs=new_fvec(allFilters+2 , 1); - - fvec_t * lower_freqs=new_fvec( allFilters, 1); - fvec_t * upper_freqs=new_fvec( allFilters, 1); - fvec_t * center_freqs=new_fvec( allFilters, 1); + fvec_t *freqs = new_fvec (allFilters + 2, 1); - fvec_t * triangle_heights=new_fvec( allFilters, 1); + fvec_t *lower_freqs = new_fvec (allFilters, 1); + fvec_t *upper_freqs = new_fvec (allFilters, 1); + fvec_t *center_freqs = new_fvec (allFilters, 1); + + fvec_t *triangle_heights = new_fvec (allFilters, 1); //lookup table of each bin frequency in hz - fvec_t * fft_freqs=new_fvec(win_s, 1); + fvec_t *fft_freqs = new_fvec (win_s, 1); uint_t filter_cnt, bin_cnt; - + //first step: filling all the linear filter frequencies - for(filter_cnt=0; filter_cntdata[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing; + for (filter_cnt = 0; filter_cnt < linearFilters; filter_cnt++) { + freqs->data[0][filter_cnt] = lowestFrequency + filter_cnt * linearSpacing; } - smpl_t lastlinearCF=freqs->data[0][filter_cnt-1]; - + smpl_t lastlinearCF = freqs->data[0][filter_cnt - 1]; + //second step: filling all the log filter frequencies - for(filter_cnt=0; filter_cntdata[0][filter_cnt+linearFilters] = - lastlinearCF*(pow(logSpacing,filter_cnt+1)); + for (filter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) { + freqs->data[0][filter_cnt + linearFilters] = + lastlinearCF * (pow (logSpacing, filter_cnt + 1)); } //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step - - for(filter_cnt=0; filter_cntdata[0][filter_cnt]=freqs->data[0][filter_cnt]; - center_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+1]; - upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2]; + + for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { + lower_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt]; + center_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 1]; + upper_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 2]; } //computing triangle heights so that each triangle has unit area - for(filter_cnt=0; filter_cntdata[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt] - - lower_freqs->data[0][filter_cnt]); + for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { + triangle_heights->data[0][filter_cnt] = + 2. / (upper_freqs->data[0][filter_cnt] + - lower_freqs->data[0][filter_cnt]); } - + //AUBIO_DBG("filter tables frequencies\n"); //for(filter_cnt=0; filter_cntdata[0][filter_cnt]); //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin - for(bin_cnt=0; bin_cntdata[0][bin_cnt]= aubio_bintofreq(bin_cnt, samplerate, win_s); + for (bin_cnt = 0; bin_cnt < win_s; bin_cnt++) { + fft_freqs->data[0][bin_cnt] = aubio_bintofreq (bin_cnt, samplerate, win_s); } //building each filter table - for(filter_cnt=0; filter_cntdata[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]); - + smpl_t riseInc = + triangle_heights->data[0][filter_cnt] / + (center_freqs->data[0][filter_cnt] - lower_freqs->data[0][filter_cnt]); + //zeroing begining of filter - for(bin_cnt=0; bin_cntdata[filter_cnt][bin_cnt]=0.0; - if( fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] && - fft_freqs->data[0][bin_cnt+1] > lower_freqs->data[0][filter_cnt]) { + for (bin_cnt = 0; bin_cnt < win_s - 1; bin_cnt++) { + filters->data[filter_cnt][bin_cnt] = 0.0; + if (fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] && + fft_freqs->data[0][bin_cnt + 1] > lower_freqs->data[0][filter_cnt]) { break; } } bin_cnt++; - + //positive slope - for(; bin_cntdata[filter_cnt][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc; + for (; bin_cnt < win_s - 1; bin_cnt++) { + filters->data[filter_cnt][bin_cnt] = + (fft_freqs->data[0][bin_cnt] - + lower_freqs->data[0][filter_cnt]) * riseInc; //if(fft_freqs->data[0][bin_cnt]<= center_freqs->data[0][filter_cnt] && fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt]) - if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt]) + if (fft_freqs->data[0][bin_cnt + 1] > center_freqs->data[0][filter_cnt]) break; } //bin_cnt++; - + //negative slope - for(; bin_cntdata[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc; - if(val>=0) - filters->data[filter_cnt][bin_cnt]=val; - else filters->data[filter_cnt][bin_cnt]=0.0; - + smpl_t val = + triangle_heights->data[0][filter_cnt] - (fft_freqs->data[0][bin_cnt] - + center_freqs->data[0][filter_cnt]) * riseInc; + if (val >= 0) + filters->data[filter_cnt][bin_cnt] = val; + else + filters->data[filter_cnt][bin_cnt] = 0.0; + //if(fft_freqs->data[0][bin_cnt]<= upper_freqs->data[0][bin_cnt] && fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt]) //TODO: CHECK whether bugfix correct - if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt]) + if (fft_freqs->data[0][bin_cnt + 1] > upper_freqs->data[0][filter_cnt]) break; } //bin_cnt++; - + //zeroing tail - for(; bin_cntdata[filter_cnt][bin_cnt]=0.f; + for (; bin_cnt < win_s; bin_cnt++) + filters->data[filter_cnt][bin_cnt] = 0.f; } - - /* destroy temporarly allocated vectors */ - del_fvec(freqs); - del_fvec(lower_freqs); - del_fvec(upper_freqs); - del_fvec(center_freqs); - del_fvec(triangle_heights); - del_fvec(fft_freqs); + /* destroy temporarly allocated vectors */ + del_fvec (freqs); + del_fvec (lower_freqs); + del_fvec (upper_freqs); + del_fvec (center_freqs); -} + del_fvec (triangle_heights); + del_fvec (fft_freqs); +} diff --git a/src/spectral/filterbank_mel.h b/src/spectral/filterbank_mel.h index d1fcb31a..e75f7332 100644 --- a/src/spectral/filterbank_mel.h +++ b/src/spectral/filterbank_mel.h @@ -35,7 +35,8 @@ #define FILTERBANK_MEL_H #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include "filterbank.h" @@ -49,10 +50,11 @@ extern "C" { \param freq_max highest filter frequency */ -void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max); +void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, + uint_t samplerate, smpl_t freq_min, smpl_t freq_max); #ifdef __cplusplus } #endif -#endif // FILTERBANK_MEL_H +#endif // FILTERBANK_MEL_H -- 2.26.2