From: Amaury Hazan Date: Wed, 12 Sep 2007 15:55:48 +0000 (+0200) Subject: merged from laptop, change debug to AUBIO_DBG in filterbank.c X-Git-Tag: bzr2git~442^2~14^2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=787f1f341dda2329703d7b0759fdb25a214eba01;p=aubio.git merged from laptop, change debug to AUBIO_DBG in filterbank.c --- 787f1f341dda2329703d7b0759fdb25a214eba01 diff --cc examples/aubiomfcc.c index 189150b9,d1cd64dd..bba21993 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@@ -23,8 -23,8 +23,8 @@@ fvec_t * mfcc_out; aubio_mfcc_t * mfcc; - uint_t n_filters = 20; + uint_t n_filters = 40; -uint_t n_coefs = 20; +uint_t n_coefs = 11; unsigned int pos = 0; /*frames%dspblocksize*/ uint_t usepitch = 0; diff --cc src/filterbank.c index c6e496dd,22a4558c..a0aa50ed --- a/src/filterbank.c +++ b/src/filterbank.c @@@ -173,6 -155,176 +155,182 @@@ aubio_filterbank_t * new_aubio_filterba } + /* + FB initialization based on Slaney's auditory toolbox + TODO: + *solve memory leak problems while + *solve quantization issues when constructing signal: + *bug for win_s=512 + *corrections for win_s=1024 -> why even filters with smaller amplitude + + */ + + aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){ + + aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s); + + + //slaney params + smpl_t lowestFrequency = 133.3333; + smpl_t linearSpacing = 66.66666666; + smpl_t logSpacing = 1.0711703; + + 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 * lower_freqs=freqs; ++ fvec_t * upper_freqs=freqs; ++ fvec_t * center_freqs=freqs*/; ++ + 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); + + uint_t filter_cnt, bin_cnt; + + //first: filling all the linear filter frequencies + for(filter_cnt=0; filter_cntdata[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing; + } + smpl_t lastlinearCF=freqs->data[0][filter_cnt-1]; + + //second: filling all the log filter frequencies + for(filter_cnt=0; filter_cntdata[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1)); + } + + - //TODO: Check how these f_vec will be freed ++ //make fvec->data point directly to freqs arrays + lower_freqs->data=freqs->data; + center_freqs->data[0]=&(freqs->data[0][1]); + upper_freqs->data[0]=&(freqs->data[0][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]); + } + - //debug - debug("filter tables frequencies\n"); ++ //AUBIO_DBG ++ AUBIO_DBG("filter tables frequencies\n"); + for(filter_cnt=0; filter_cntdata[0][filter_cnt], center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt], triangle_heights->data[0][filter_cnt]); ++ AUBIO_DBG("filter n. %d %f %f %f %f\n",filter_cnt, lower_freqs->data[0][filter_cnt], center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt], triangle_heights->data[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]= (smpl_t)samplerate* (smpl_t)bin_cnt/ (smpl_t)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]); + + //zeroing begining of filter - debug("\nfilter %d",filter_cnt); ++ AUBIO_DBG("\nfilter %d",filter_cnt); + - debug("\nzero begin\n"); ++ AUBIO_DBG("\nzero begin\n"); + + for(bin_cnt=0; bin_cntfilters[filter_cnt]->data[0][bin_cnt]=0.f; - debug("."); - //debug("%f %f %f\n", fft_freqs->data[0][bin_cnt], fft_freqs->data[0][bin_cnt+1], lower_freqs->data[0][filter_cnt]); ++ AUBIO_DBG("."); ++ //AUBIO_DBG("%f %f %f\n", fft_freqs->data[0][bin_cnt], fft_freqs->data[0][bin_cnt+1], lower_freqs->data[0][filter_cnt]); + 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++; + - debug("\npos slope\n"); ++ AUBIO_DBG("\npos slope\n"); + //positive slope + for(; bin_cntfilters[filter_cnt]->data[0][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]) + break; + } + //bin_cnt++; + - //debug("\nneg slope\n"); + + //negative slope ++ AUBIO_DBG("\nneg slope\n"); + for(; bin_cntdata[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc; + if(val>=0) + fb->filters[filter_cnt]->data[0][bin_cnt]=val; + else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; + + //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]) + break; + } + //bin_cnt++; + - //debug("\nzero end\n"); ++ AUBIO_DBG("\nzero end\n"); + //zeroing tail + for(; bin_cntfilters[filter_cnt]->data[0][bin_cnt]=0.f; + + } + + + del_fvec(freqs); + //TODO: Check how to do a proper free for the following f_vec + + //del_fvec(lower_freqs); + //del_fvec(upper_freqs); + //del_fvec(center_freqs); + del_fvec(triangle_heights); + del_fvec(fft_freqs); + + + + return fb; + + } + + void aubio_dump_filterbank(aubio_filterbank_t * fb){ + + FILE * mlog; + mlog=fopen("filterbank.txt","w"); + + int k,n; + //dumping filter values + //smpl_t area_tmp=0.f; + for(n = 0; n < fb->n_filters; n++){ + for(k = 0; k < fb->win_s; k++){ + fprintf(mlog,"%f ",fb->filters[n]->data[0][k]); + } + fprintf(mlog,"\n"); + } + + if(mlog) fclose(mlog); + } void del_aubio_filterbank(aubio_filterbank_t * fb){ uint_t filter_cnt;