Changes in / [e5f6a0b:45134c5]
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
re5f6a0b r45134c5 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;28 25 29 26 unsigned int pos = 0; /*frames%dspblocksize*/ … … 53 50 //compute mfccs 54 51 aubio_mfcc_do(mfcc, fftgrain, mfcc_out); 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 52 62 53 /* end of block loop */ 63 54 pos = -1; /* so it will be zero next j loop */ … … 74 65 */ 75 66 76 uint_t coef_cnt;67 uint_t filter_cnt; 77 68 if (output_filename == NULL) { 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 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"); 87 79 } 88 80 } … … 90 82 int main(int argc, char **argv) { 91 83 // params 92 84 uint_t n_filters = 11; 93 85 examples_common_init(argc,argv); 94 smpl_t lowfreq = 133.333f; 95 smpl_t highfreq = 44100.f; 96 mfcc_out = new_fvec(n_coefs,channels); 97 86 smpl_t lowfreq = 0.; 87 smpl_t highfreq = samplerate; 88 mfcc_out = new_fvec(n_filters,channels); 98 89 99 90 //populating the filter 100 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels); 101 dump_filterbank(mfcc); 102 103 91 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq, 92 channels); 93 104 94 //process 105 95 examples_common_process(aubio_process,process_print); -
examples/utils.c
re5f6a0b r45134c5 40 40 smpl_t threshold = 0.3; 41 41 smpl_t silence = -90.; 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; 42 uint_t buffer_size = 512; //1024; 43 uint_t overlap_size = 256; //512; 48 44 uint_t channels = 1; 49 45 uint_t samplerate = 44100; … … 64 60 int isonset = 0; 65 61 aubio_pickpeak_t * parms; 62 63 /* mfcc objects */ 64 //parameters 65 uint_t n_filters=20; 66 smpl_t lowfreq=80.f; 67 smpl_t highfreq=18000.f; 68 // filterbank object 69 aubio_filterbank_t * mf; 70 71 // DCT mfft and result storage 72 aubio_mfft_t * fft_dct; 73 cvec_t * fftgrain_dct; 74 smpl_t * mfcc_outbuf[11]; 75 66 76 67 77 /* pitch objects */ … … 304 314 fftgrain = new_cvec(buffer_size, channels); 305 315 306 316 //init for mfcc process 317 fftgrain_dct= new_cvec(n_filters, channels); 318 307 319 if (usepitch) { 308 320 pitchdet = new_aubio_pitchdetection(buffer_size*4, … … 318 330 pv = new_aubio_pvoc(buffer_size, overlap_size, channels); 319 331 332 // dct phase vocoder 333 //TODO: check size 334 fft_dct = new_aubio_mfft(n_filters, channels); 335 320 336 /* onsets */ 321 337 parms = new_aubio_peakpicker(threshold); … … 351 367 del_fvec(onset); 352 368 del_fvec(woodblock); 369 370 //mffc related 371 del_aubio_mfft(fft_dct); 372 del_cvec(fftgrain_dct); 353 373 354 374 aubio_cleanup(); -
src/filterbank.c
re5f6a0b r45134c5 19 19 */ 20 20 21 /* part of this mfcc implementation were inspired from LibXtract 22 http://libxtract.sourceforge.net/ 23 */ 21 24 22 25 #include "aubio_priv.h" 23 26 #include "sample.h" 24 27 #include "filterbank.h" 25 26 #include "stdio.h"27 28 28 29 #define USE_EQUAL_GAIN 1 … … 52 53 } 53 54 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 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){ 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 146 144 } 147 145 … … 151 149 free(fft_peak); 152 150 153 154 151 return fb; 155 152 156 153 } 157 154 158 /*159 FB initialization based on Slaney's auditory toolbox160 TODO:161 *solve memory leak problems while162 *solve quantization issues when constructing signal:163 *bug for win_s=512164 *corrections for win_s=1024 -> why even filters with smaller amplitude165 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 params174 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 frequencies183 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 hz192 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 frequencies197 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 frequencies203 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 arrays208 //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step209 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 area218 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_DBG224 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 bin229 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 table235 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){236 237 //TODO:check special case : lower freq =0238 //calculating rise increment in mag/Hz239 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 filter244 AUBIO_DBG("\nzero begin\n");245 for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){246 //zeroing beigining of array247 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 slope258 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 slope269 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 correct281 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 tail288 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 values315 //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 }325 155 326 156 void del_aubio_filterbank(aubio_filterbank_t * fb){ -
src/filterbank.h
re5f6a0b r45134c5 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 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); 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); 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
re5f6a0b r45134c5 34 34 uint_t samplerate; /** sample rate (needed?) */ 35 35 uint_t channels; /** number of channels */ 36 uint_t n_filters; /** number of *filters */ 37 uint_t n_coefs; /** number of coefficients (<= n_filters/2 +1) */ 36 uint_t n_coefs; /** number of coefficients (= fb->n_filters/2 +1) */ 38 37 smpl_t lowfreq; /** lowest frequency for filters */ 39 38 smpl_t highfreq; /** highest frequency for filters */ … … 45 44 46 45 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){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){ 48 47 /** allocating space for mfcc object */ 49 48 aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t); 50 49 51 50 //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct 52 //uint_t n_filters = (n_coefs-1)*2;51 uint_t n_filters = (n_coefs-1)*2; 53 52 54 53 mfcc->win_s=win_s; 55 54 mfcc->samplerate=samplerate; 56 55 mfcc->channels=channels; 57 mfcc->n_filters=n_filters;58 56 mfcc->n_coefs=n_coefs; 59 57 mfcc->lowfreq=lowfreq; 60 58 mfcc->highfreq=highfreq; 61 59 62 63 60 /** filterbank allocation */ 64 mfcc->fb = new_aubio_filterbank_mfcc 2(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);61 mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq); 65 62 66 63 /** allocating space for fft object (used for dct) */ … … 105 102 aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct); 106 103 //extract real part of fft grain 107 for(i=0; i<mf->n_coefs ;i++){108 //for(i=0; i<out->length;i++){104 //for(i=0; i<mf->n_coefs ;i++){ 105 for(i=0; i<out->length;i++){ 109 106 out->data[0][i]= mf->fftgrain_dct->norm[0][i] 110 107 *COS(mf->fftgrain_dct->phas[0][i]); … … 113 110 } 114 111 115 //a bit a kludge116 void dump_filterbank(aubio_mfcc_t * mf){117 aubio_dump_filterbank(mf->fb);118 119 }120 -
src/mfcc.h
re5f6a0b r45134c5 45 45 46 46 */ 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 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); 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 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 } -
src/sample.c
re5f6a0b r45134c5 20 20 #include "aubio_priv.h" 21 21 #include "sample.h" 22 23 22 24 23 fvec_t * new_fvec( uint_t length, uint_t channels) { -
swig/aubio.i
re5f6a0b r45134c5 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 158 150 159 151 /* scale */
Note: See TracChangeset
for help on using the changeset viewer.