- Timestamp:
- Sep 12, 2007, 5:55:48 PM (17 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 95a64c7
- Parents:
- 7a46bf6 (diff), 83d5abf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/filterbank.c
r7a46bf6 r787f1f3 19 19 */ 20 20 21 /* part of this mfcc implementation were inspired from LibXtract22 http://libxtract.sourceforge.net/23 */24 21 25 22 #include "aubio_priv.h" … … 55 52 } 56 53 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 59 uint_t writelog=1; 60 61 FILE * mlog; 62 if(writelog==1) mlog=fopen("filterbank.txt","w"); 63 64 54 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){ 55 65 56 smpl_t nyquist = samplerate/2.; 66 57 uint_t style = 1; … … 152 143 fb->filters[n]->data[0][k]=0.f; 153 144 154 if(writelog){155 //dumping filter values156 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 }162 145 163 146 } … … 168 151 free(fft_peak); 169 152 153 154 return fb; 155 156 } 157 158 /* 159 FB initialization based on Slaney's auditory toolbox 160 TODO: 161 *solve memory leak problems while 162 *solve quantization issues when constructing signal: 163 *bug for win_s=512 164 *corrections for win_s=1024 -> why even filters with smaller amplitude 165 166 */ 167 168 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){ 169 170 aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s); 171 172 173 //slaney params 174 smpl_t lowestFrequency = 133.3333; 175 smpl_t linearSpacing = 66.66666666; 176 smpl_t logSpacing = 1.0711703; 177 178 uint_t linearFilters = 13; 179 uint_t logFilters = 27; 180 uint_t allFilters = linearFilters + logFilters; 181 182 //buffers for computing filter frequencies 183 fvec_t * freqs=new_fvec( allFilters +2 , 1); 184 185 fvec_t * lower_freqs=new_fvec( allFilters, 1); 186 fvec_t * upper_freqs=new_fvec( allFilters, 1); 187 fvec_t * center_freqs=new_fvec( allFilters, 1); 188 189 /*fvec_t * lower_freqs=freqs; 190 fvec_t * upper_freqs=freqs; 191 fvec_t * center_freqs=freqs*/; 192 193 fvec_t * triangle_heights=new_fvec( allFilters, 1); 194 //lookup table of each bin frequency in hz 195 fvec_t * fft_freqs=new_fvec(win_s, 1); 196 197 uint_t filter_cnt, bin_cnt; 198 199 //first: filling all the linear filter frequencies 200 for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){ 201 freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing; 202 } 203 smpl_t lastlinearCF=freqs->data[0][filter_cnt-1]; 204 205 //second: filling all the log filter frequencies 206 for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){ 207 freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1)); 208 } 209 210 211 //make fvec->data point directly to freqs arrays 212 lower_freqs->data=freqs->data; 213 center_freqs->data[0]=&(freqs->data[0][1]); 214 upper_freqs->data[0]=&(freqs->data[0][2]); 215 216 217 //computing triangle heights so that each triangle has unit area 218 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){ 219 triangle_heights->data[0][filter_cnt]=2./(upper_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]); 220 } 221 222 //AUBIO_DBG 223 AUBIO_DBG("filter tables frequencies\n"); 224 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++) 225 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]); 226 227 228 //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin 229 230 for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){ 231 232 //TODO: check the formula! 233 234 fft_freqs->data[0][bin_cnt]= (smpl_t)samplerate* (smpl_t)bin_cnt/ (smpl_t)win_s; 235 236 } 237 238 239 //building each filter table 240 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){ 241 242 //TODO:check special case : lower freq =0 243 244 //calculating rise increment in mag/Hz 245 smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]); 246 247 //zeroing begining of filter 248 AUBIO_DBG("\nfilter %d",filter_cnt); 249 250 AUBIO_DBG("\nzero begin\n"); 251 252 for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){ 253 //zeroing beigining of array 254 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 255 AUBIO_DBG("."); 256 //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]); 257 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]){ 258 break; 259 } 260 } 261 bin_cnt++; 262 263 AUBIO_DBG("\npos slope\n"); 264 //positive slope 265 for(; bin_cnt<win_s-1; bin_cnt++){ 266 AUBIO_DBG("."); 267 fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc; 268 //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]) 269 if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt]) 270 break; 271 } 272 //bin_cnt++; 273 274 275 //negative slope 276 AUBIO_DBG("\nneg slope\n"); 277 for(; bin_cnt<win_s-1; bin_cnt++){ 278 //AUBIO_DBG("."); 279 280 //checking whether last value is less than 0... 281 smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc; 282 if(val>=0) 283 fb->filters[filter_cnt]->data[0][bin_cnt]=val; 284 else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 285 286 //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]) 287 //TODO: CHECK whether bugfix correct 288 if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt]) 289 break; 290 } 291 //bin_cnt++; 292 293 AUBIO_DBG("\nzero end\n"); 294 //zeroing tail 295 for(; bin_cnt<win_s; bin_cnt++) 296 //AUBIO_DBG("."); 297 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 298 299 } 300 301 302 del_fvec(freqs); 303 //TODO: Check how to do a proper free for the following f_vec 304 305 //del_fvec(lower_freqs); 306 //del_fvec(upper_freqs); 307 //del_fvec(center_freqs); 308 del_fvec(triangle_heights); 309 del_fvec(fft_freqs); 310 311 312 313 return fb; 314 315 } 316 317 void aubio_dump_filterbank(aubio_filterbank_t * fb){ 318 319 FILE * mlog; 320 mlog=fopen("filterbank.txt","w"); 321 322 int k,n; 323 //dumping filter values 324 //smpl_t area_tmp=0.f; 325 for(n = 0; n < fb->n_filters; n++){ 326 for(k = 0; k < fb->win_s; k++){ 327 fprintf(mlog,"%f ",fb->filters[n]->data[0][k]); 328 } 329 fprintf(mlog,"\n"); 330 } 331 170 332 if(mlog) fclose(mlog); 171 172 return fb; 173 174 } 175 333 } 176 334 177 335 void del_aubio_filterbank(aubio_filterbank_t * fb){ -
src/filterbank.h
r7a46bf6 r787f1f3 46 46 /** filterbank initialization for mel filters 47 47 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 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 52 54 53 55 */ 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); 56 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max); 57 58 /** filterbank initialization for mel filters 59 60 \param n_filters number of filters 61 \param win_s window size 62 \param samplerate 63 \param freq_min lowest filter frequency 64 \param freq_max highest filter frequency 65 66 */ 67 aubio_filterbank_t * new_aubio_filterbank_mfcc_2(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max); 55 68 56 69 … … 67 80 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out); 68 81 82 /** dump filterbank filter tables in a txt file 83 84 */ 85 void aubio_dump_filterbank(aubio_filterbank_t * fb); 86 69 87 #ifdef __cplusplus 70 88 } -
src/mfcc.c
r7a46bf6 r787f1f3 60 60 mfcc->highfreq=highfreq; 61 61 62 62 63 /** filterbank allocation */ 63 mfcc->fb = new_aubio_filterbank_mfcc (n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);64 mfcc->fb = new_aubio_filterbank_mfcc2(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq); 64 65 65 66 /** allocating space for fft object (used for dct) */ … … 112 113 } 113 114 115 //a bit a kludge 116 void dump_filterbank(aubio_mfcc_t * mf){ 117 aubio_dump_filterbank(mf->fb); 118 119 } 120 -
src/mfcc.h
r7a46bf6 r787f1f3 70 70 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out); 71 71 72 /** dump filterbank to log file 73 74 \param mf mfcc object as returned by new_aubio_mfcc 75 76 */ 77 void dump_filterbank(aubio_mfcc_t * mf); 78 72 79 #ifdef __cplusplus 73 80 }
Note: See TracChangeset
for help on using the changeset viewer.