Changeset 787f1f3
- 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. - Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
r7a46bf6 r787f1f3 24 24 aubio_mfcc_t * mfcc; 25 25 26 uint_t n_filters = 20;26 uint_t n_filters = 40; 27 27 uint_t n_coefs = 11; 28 28 … … 53 53 //compute mfccs 54 54 aubio_mfcc_do(mfcc, fftgrain, mfcc_out); 55 55 56 uint_t coef_cnt; 57 for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) { 58 outmsg("%f ",mfcc_out->data[0][coef_cnt]); 59 } 60 outmsg("\n"); 61 56 62 /* end of block loop */ 57 63 pos = -1; /* so it will be zero next j loop */ … … 78 84 //outmsg("%f ",mfcc_out->data[0][0]); 79 85 80 /*for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) { 81 outmsg("%f ",mfcc_out->data[0][coef_cnt]); 82 } 83 outmsg("\n");/*/ 86 84 87 } 85 88 } … … 87 90 int main(int argc, char **argv) { 88 91 // params 89 //uint_t n_filters = 40; 90 //uint_t n_coefs = 15; 91 92 92 93 examples_common_init(argc,argv); 93 94 smpl_t lowfreq = 133.333f; … … 95 96 mfcc_out = new_fvec(n_coefs,channels); 96 97 98 97 99 //populating the filter 98 100 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels); 99 101 dump_filterbank(mfcc); 102 103 100 104 //process 101 105 examples_common_process(aubio_process,process_print); -
examples/plotfb.py
r7a46bf6 r787f1f3 5 5 import sys 6 6 7 7 8 filename=sys.argv[1] 9 10 doLog=False 11 if len(sys.argv)>2: 12 if sys.argv[2]=='log': 13 doLog=True 8 14 9 15 mat = pylab.load(filename) … … 15 21 n_filters=numpy.shape(nmat)[0] 16 22 for i in range(n_filters): 17 pylab.plot(nmat[i,:]) 23 if doLog==True: 24 pylab.semilogx(nmat[i,:]) 25 else: 26 pylab.plot(nmat[i,:]) 18 27 19 28 -
examples/utils.c
r7a46bf6 r787f1f3 40 40 smpl_t threshold = 0.3; 41 41 smpl_t silence = -90.; 42 uint_t buffer_size = 512; //1024; 43 uint_t overlap_size = 256; //512; 42 // uint_t buffer_size = 512; 43 // uint_t overlap_size = 256; 44 uint_t buffer_size = 1024; 45 uint_t overlap_size = 512; 44 46 uint_t channels = 1; 45 47 uint_t samplerate = 44100; -
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.