Changes in / [ef1c3b7:7a46bf6]
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
ref1c3b7 r7a46bf6 87 87 int main(int argc, char **argv) { 88 88 // params 89 89 //uint_t n_filters = 40; 90 //uint_t n_coefs = 15; 91 90 92 examples_common_init(argc,argv); 91 93 smpl_t lowfreq = 133.333f; … … 95 97 //populating the filter 96 98 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels); 97 dump_filterbank(mfcc); 98 99 99 100 //process 100 101 examples_common_process(aubio_process,process_print); -
src/filterbank.c
ref1c3b7 r7a46bf6 57 57 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max){ 58 58 59 uint_t writelog=1; 60 61 FILE * mlog; 62 if(writelog==1) mlog=fopen("filterbank.txt","w"); 63 64 59 65 smpl_t nyquist = samplerate/2.; 60 66 uint_t style = 1; … … 146 152 fb->filters[n]->data[0][k]=0.f; 147 153 154 if(writelog){ 155 //dumping filter values 156 smpl_t area_tmp=0.f; 157 for(k = 0; k < fb->win_s; k++){ 158 fprintf(mlog,"%f ",fb->filters[n]->data[0][k]); 159 } 160 fprintf(mlog,"\n"); 161 } 148 162 149 163 } … … 154 168 free(fft_peak); 155 169 170 if(mlog) fclose(mlog); 156 171 157 172 return fb; … … 159 174 } 160 175 161 162 aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max){163 164 //slaney params165 smpl_t lowestFrequency = 133.3333;166 smpl_t linearSpacing = 66.66666666;167 smpl_t logSpacing = 1.0711703;168 169 uint_t linearFilters = 13;170 uint_t logFilters = 27;171 uint_t allFilters = linearFilters + logFilters;172 173 //buffers for computing filter frequencies174 fvec_t * freqs=new_fvec( allFilters +2 , 1);175 fvec_t * lower_freqs=new_fvec( allFilters, 1);176 fvec_t * upper_freqs=new_fvec( allFilters, 1);177 fvec_t * center_freqs=new_fvec( allFilters, 1);178 fvec_t * triangle_heights=new_fvec( allFilters, 1);179 //lookup table of each bin frequency in hz180 fvec_t * fft_freqs=(win_s, 1);181 182 uint_t filter_cnt, bin_cnt;183 184 //first: filling all the linear filter frequencies185 for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){186 freqs[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing;187 }188 smpl_t lastlinearCF=freqs[0][filter_cnt-1];189 190 //second: filling all the log filter frequencies191 for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){192 freqs[filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1));193 }194 //TODO: check if the referencing above works!195 lower_freqs->data=freqs->data;196 center_freqs->data=&(freqs->data[1]);197 upper_freqs->data=&(freqs->data[2]);198 199 //computing triangle heights so that each triangle has unit area200 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){201 triangle_heights[filter_cnt]=2./(upper_freqs[filter_cnt]-lower_freqs[filter_cnt]);202 }203 204 //filling the lookup table, which assign the frequency in hz to each bin205 for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){206 //TODO: check the formula!207 fft_freqs[bin_cnt]=((smpl_t) bin_cnt/(smpl_t) win_s)* (smpl_t) samplerate;208 }209 210 //building each filter211 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){212 //finding bins corresponding to lower, center, and upper frequencies213 214 for(bin_cnt=0; bin_cnt<; bin_cnt++)215 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;216 }217 218 // xtract219 smpl_t nyquist = samplerate/2.;220 uint_t style = 1;221 aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);222 223 uint_t n, i, k, *fft_peak, M, next_peak;224 smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val,225 freq_bw_mel, *mel_peak, *height_norm, *lin_peak;226 227 mel_peak = height_norm = lin_peak = NULL;228 fft_peak = NULL;229 norm = 1;230 231 mel_freq_max = 1127 * log(1 + freq_max / 700);232 mel_freq_min = 1127 * log(1 + freq_min / 700);233 freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;234 235 mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));236 /* +2 for zeros at start and end */237 lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));238 fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));239 height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));240 241 if(mel_peak == NULL || height_norm == NULL ||242 lin_peak == NULL || fft_peak == NULL)243 return NULL;244 245 M = fb->win_s >> 1;246 247 mel_peak[0] = mel_freq_min;248 lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);249 fft_peak[0] = lin_peak[0] / nyquist * M;250 251 for (n = 1; n <= fb->n_filters; n++){252 /*roll out peak locations - mel, linear and linear on fft window scale */253 mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;254 lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);255 fft_peak[n] = lin_peak[n] / nyquist * M;256 }257 258 for (n = 0; n < fb->n_filters; n++){259 /*roll out normalised gain of each peak*/260 if (style == USE_EQUAL_GAIN){261 height = 1;262 norm_fact = norm;263 }264 else{265 height = 2 / (lin_peak[n + 2] - lin_peak[n]);266 norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));267 }268 height_norm[n] = height * norm_fact;269 }270 271 i = 0;272 273 for(n = 0; n < fb->n_filters; n++){274 275 /*calculate the rise increment*/276 if(n > 0)277 inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);278 else279 inc = height_norm[n] / fft_peak[n];280 val = 0;281 282 /*zero the start of the array*/283 for(k = 0; k < i; k++)284 fb->filters[n]->data[0][k]=0.f;285 286 /*fill in the rise */287 for(; i <= fft_peak[n]; i++){288 fb->filters[n]->data[0][k]=val;289 val += inc;290 }291 292 /*calculate the fall increment */293 inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);294 295 val = 0;296 next_peak = fft_peak[n + 1];297 298 /*reverse fill the 'fall' */299 for(i = next_peak; i > fft_peak[n]; i--){300 fb->filters[n]->data[0][k]=val;301 val += inc;302 }303 304 /*zero the rest of the array*/305 for(k = next_peak + 1; k < fb->win_s; k++)306 fb->filters[n]->data[0][k]=0.f;307 308 309 }310 311 free(mel_peak);312 free(lin_peak);313 free(height_norm);314 free(fft_peak);315 316 317 return fb;318 319 }320 321 void aubio_dump_filterbank(aubio_filterbank_t * fb){322 323 FILE * mlog;324 mlog=fopen("filterbank.txt","w");325 326 int k,n;327 //dumping filter values328 //smpl_t area_tmp=0.f;329 for(n = 0; n < fb->n_filters; n++){330 for(k = 0; k < fb->win_s; k++){331 fprintf(mlog,"%f ",fb->filters[n]->data[0][k]);332 }333 fprintf(mlog,"\n");334 }335 336 if(mlog) fclose(mlog);337 }338 176 339 177 void del_aubio_filterbank(aubio_filterbank_t * fb){ -
src/filterbank.h
ref1c3b7 r7a46bf6 46 46 /** filterbank initialization for mel filters 47 47 48 49 \param n_filters number of filters 50 \param win_s window size 51 \param samplerate 52 \param freq_min lowest filter frequency 53 \param freq_max highest filter frequency 48 \param nyquist nyquist frequency, i.e. half of the sampling rate 49 \param style libxtract style 50 \param freqmin lowest filter frequency 51 \param freqmax highest filter frequency 54 52 55 53 */ 56 54 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max); 57 58 /** filterbank initialization for mel filters59 60 \param n_filters number of filters61 \param win_s window size62 \param samplerate63 \param freq_min lowest filter frequency64 \param freq_max highest filter frequency65 66 */67 aubio_filterbank_t * new_aubio_filterbank_mfcc_2(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);68 55 69 56 … … 80 67 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out); 81 68 82 /** dump filterbank filter tables in a txt file83 84 */85 void aubio_dump_filterbank(aubio_filterbank_t * fb);86 87 69 #ifdef __cplusplus 88 70 } -
src/mfcc.c
ref1c3b7 r7a46bf6 112 112 } 113 113 114 //a bit a kludge115 void dump_filterbank(aubio_mfcc_t * mf){116 aubio_dump_filterbank(mf->fb);117 118 }119 -
src/mfcc.h
ref1c3b7 r7a46bf6 70 70 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out); 71 71 72 /** dump filterbank to log file73 74 \param mf mfcc object as returned by new_aubio_mfcc75 76 */77 void dump_filterbank(aubio_mfcc_t * mf);78 79 72 #ifdef __cplusplus 80 73 }
Note: See TracChangeset
for help on using the changeset viewer.