Changes in / [45134c5:e5f6a0b]
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
r45134c5 re5f6a0b 23 23 fvec_t * mfcc_out; 24 24 aubio_mfcc_t * mfcc; 25 26 uint_t n_filters = 40; 27 uint_t n_coefs = 11; 25 28 26 29 unsigned int pos = 0; /*frames%dspblocksize*/ … … 50 53 //compute mfccs 51 54 aubio_mfcc_do(mfcc, fftgrain, mfcc_out); 52 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 53 62 /* end of block loop */ 54 63 pos = -1; /* so it will be zero next j loop */ … … 65 74 */ 66 75 67 uint_t filter_cnt;76 uint_t coef_cnt; 68 77 if (output_filename == NULL) { 69 if(frames >= 4) { 70 outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate); 71 } else if (frames < 4) { 72 outmsg("%f\t",0.); 73 } 74 outmsg("%f",mfcc_out->data[0][0]); 75 for (filter_cnt = 1; filter_cnt < mfcc_out->length; filter_cnt++) { 76 outmsg(",%f",mfcc_out->data[0][filter_cnt]); 77 } 78 outmsg("\n"); 78 // if(frames >= 4) { 79 // outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate); 80 // } 81 // else if (frames < 4) { 82 // outmsg("%f\t",0.); 83 // } 84 //outmsg("%f ",mfcc_out->data[0][0]); 85 86 79 87 } 80 88 } … … 82 90 int main(int argc, char **argv) { 83 91 // params 84 uint_t n_filters = 11;92 85 93 examples_common_init(argc,argv); 86 smpl_t lowfreq = 0.; 87 smpl_t highfreq = samplerate; 88 mfcc_out = new_fvec(n_filters,channels); 94 smpl_t lowfreq = 133.333f; 95 smpl_t highfreq = 44100.f; 96 mfcc_out = new_fvec(n_coefs,channels); 97 89 98 90 99 //populating the filter 91 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq, 92 channels); 93 100 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels); 101 dump_filterbank(mfcc); 102 103 94 104 //process 95 105 examples_common_process(aubio_process,process_print); -
examples/utils.c
r45134c5 re5f6a0b 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; 46 // uint_t buffer_size = 2048; 47 // uint_t overlap_size = 1024; 44 48 uint_t channels = 1; 45 49 uint_t samplerate = 44100; … … 60 64 int isonset = 0; 61 65 aubio_pickpeak_t * parms; 62 63 /* mfcc objects */64 //parameters65 uint_t n_filters=20;66 smpl_t lowfreq=80.f;67 smpl_t highfreq=18000.f;68 // filterbank object69 aubio_filterbank_t * mf;70 71 // DCT mfft and result storage72 aubio_mfft_t * fft_dct;73 cvec_t * fftgrain_dct;74 smpl_t * mfcc_outbuf[11];75 76 66 77 67 /* pitch objects */ … … 314 304 fftgrain = new_cvec(buffer_size, channels); 315 305 316 //init for mfcc process 317 fftgrain_dct= new_cvec(n_filters, channels); 318 306 319 307 if (usepitch) { 320 308 pitchdet = new_aubio_pitchdetection(buffer_size*4, … … 330 318 pv = new_aubio_pvoc(buffer_size, overlap_size, channels); 331 319 332 // dct phase vocoder333 //TODO: check size334 fft_dct = new_aubio_mfft(n_filters, channels);335 336 320 /* onsets */ 337 321 parms = new_aubio_peakpicker(threshold); … … 367 351 del_fvec(onset); 368 352 del_fvec(woodblock); 369 370 //mffc related371 del_aubio_mfft(fft_dct);372 del_cvec(fftgrain_dct);373 353 374 354 aubio_cleanup(); -
src/filterbank.c
r45134c5 re5f6a0b 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" 26 23 #include "sample.h" 27 24 #include "filterbank.h" 25 26 #include "stdio.h" 28 27 29 28 #define USE_EQUAL_GAIN 1 … … 53 52 } 54 53 55 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){ 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 56 56 smpl_t nyquist = samplerate/2.; 57 57 uint_t style = 1; … … 142 142 for(k = next_peak + 1; k < fb->win_s; k++) 143 143 fb->filters[n]->data[0][k]=0.f; 144 145 144 146 } 145 147 … … 149 151 free(fft_peak); 150 152 153 151 154 return fb; 152 155 153 156 } 154 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 190 fvec_t * triangle_heights=new_fvec( allFilters, 1); 191 //lookup table of each bin frequency in hz 192 fvec_t * fft_freqs=new_fvec(win_s, 1); 193 194 uint_t filter_cnt, bin_cnt; 195 196 //first step: filling all the linear filter frequencies 197 for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){ 198 freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing; 199 } 200 smpl_t lastlinearCF=freqs->data[0][filter_cnt-1]; 201 202 //second step: filling all the log filter frequencies 203 for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){ 204 freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1)); 205 } 206 207 //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays 208 //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step 209 210 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){ 211 lower_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt]; 212 center_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+1]; 213 upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2]; 214 } 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 223 //AUBIO_DBG 224 AUBIO_DBG("filter tables frequencies\n"); 225 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++) 226 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]); 227 228 //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin 229 for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){ 230 //TODO: check the formula! 231 fft_freqs->data[0][bin_cnt]= (smpl_t)samplerate* (smpl_t)bin_cnt/ (smpl_t)win_s; 232 } 233 234 //building each filter table 235 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){ 236 237 //TODO:check special case : lower freq =0 238 //calculating rise increment in mag/Hz 239 smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]); 240 241 242 AUBIO_DBG("\nfilter %d",filter_cnt); 243 //zeroing begining of filter 244 AUBIO_DBG("\nzero begin\n"); 245 for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){ 246 //zeroing beigining of array 247 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 248 AUBIO_DBG("."); 249 //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]); 250 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]){ 251 break; 252 } 253 } 254 bin_cnt++; 255 256 AUBIO_DBG("\npos slope\n"); 257 //positive slope 258 for(; bin_cnt<win_s-1; bin_cnt++){ 259 AUBIO_DBG("."); 260 fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc; 261 //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]) 262 if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt]) 263 break; 264 } 265 //bin_cnt++; 266 267 268 //negative slope 269 AUBIO_DBG("\nneg slope\n"); 270 for(; bin_cnt<win_s-1; bin_cnt++){ 271 //AUBIO_DBG("."); 272 273 //checking whether last value is less than 0... 274 smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc; 275 if(val>=0) 276 fb->filters[filter_cnt]->data[0][bin_cnt]=val; 277 else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 278 279 //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]) 280 //TODO: CHECK whether bugfix correct 281 if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt]) 282 break; 283 } 284 //bin_cnt++; 285 286 AUBIO_DBG("\nzero end\n"); 287 //zeroing tail 288 for(; bin_cnt<win_s; bin_cnt++) 289 //AUBIO_DBG("."); 290 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 291 292 } 293 294 295 296 del_fvec(freqs); 297 del_fvec(lower_freqs); 298 del_fvec(upper_freqs); 299 del_fvec(center_freqs); 300 301 del_fvec(triangle_heights); 302 del_fvec(fft_freqs); 303 304 return fb; 305 306 } 307 308 void aubio_dump_filterbank(aubio_filterbank_t * fb){ 309 310 FILE * mlog; 311 mlog=fopen("filterbank.txt","w"); 312 313 int k,n; 314 //dumping filter values 315 //smpl_t area_tmp=0.f; 316 for(n = 0; n < fb->n_filters; n++){ 317 for(k = 0; k < fb->win_s; k++){ 318 fprintf(mlog,"%f ",fb->filters[n]->data[0][k]); 319 } 320 fprintf(mlog,"\n"); 321 } 322 323 if(mlog) fclose(mlog); 324 } 155 325 156 326 void del_aubio_filterbank(aubio_filterbank_t * fb){ -
src/filterbank.h
r45134c5 re5f6a0b 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
r45134c5 re5f6a0b 34 34 uint_t samplerate; /** sample rate (needed?) */ 35 35 uint_t channels; /** number of channels */ 36 uint_t n_coefs; /** number of coefficients (= fb->n_filters/2 +1) */ 36 uint_t n_filters; /** number of *filters */ 37 uint_t n_coefs; /** number of coefficients (<= n_filters/2 +1) */ 37 38 smpl_t lowfreq; /** lowest frequency for filters */ 38 39 smpl_t highfreq; /** highest frequency for filters */ … … 44 45 45 46 46 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){ 47 48 /** allocating space for mfcc object */ 48 49 aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t); 49 50 50 51 //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct 51 uint_t n_filters = (n_coefs-1)*2;52 //uint_t n_filters = (n_coefs-1)*2; 52 53 53 54 mfcc->win_s=win_s; 54 55 mfcc->samplerate=samplerate; 55 56 mfcc->channels=channels; 57 mfcc->n_filters=n_filters; 56 58 mfcc->n_coefs=n_coefs; 57 59 mfcc->lowfreq=lowfreq; 58 60 mfcc->highfreq=highfreq; 59 61 62 60 63 /** filterbank allocation */ 61 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); 62 65 63 66 /** allocating space for fft object (used for dct) */ … … 102 105 aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct); 103 106 //extract real part of fft grain 104 //for(i=0; i<mf->n_coefs ;i++){105 for(i=0; i<out->length;i++){107 for(i=0; i<mf->n_coefs ;i++){ 108 //for(i=0; i<out->length;i++){ 106 109 out->data[0][i]= mf->fftgrain_dct->norm[0][i] 107 110 *COS(mf->fftgrain_dct->phas[0][i]); … … 110 113 } 111 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
r45134c5 re5f6a0b 45 45 46 46 */ 47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels); 48 48 /** delete mfcc object 49 49 … … 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 } -
src/sample.c
r45134c5 re5f6a0b 20 20 #include "aubio_priv.h" 21 21 #include "sample.h" 22 22 23 23 24 fvec_t * new_fvec( uint_t length, uint_t channels) { -
swig/aubio.i
r45134c5 re5f6a0b 148 148 smpl_t aubio_zero_crossing_rate(fvec_t * input); 149 149 smpl_t aubio_spectral_centroid(cvec_t * spectrum, smpl_t samplerate); 150 151 /* filterbank */ 152 153 /* mfcc */ 154 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels); 155 void del_aubio_mfcc(aubio_mfcc_t *mf); 156 void aubio_mfcc_do(aubio_mfcc_t *mf, cvec_t *in, fvec_t *out); 157 150 158 151 159 /* scale */
Note: See TracChangeset
for help on using the changeset viewer.