Changeset aa83433
- Timestamp:
- Sep 16, 2007, 9:55:42 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:
- 9170e4c
- Parents:
- aeb38cf
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/filterbank.c
raeb38cf raa83433 50 50 51 51 return fb; 52 }53 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 smpl_t nyquist = samplerate/2.;57 uint_t style = 1;58 aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);59 60 uint_t n, i, k, *fft_peak, M, next_peak;61 smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val,62 freq_bw_mel, *mel_peak, *height_norm, *lin_peak;63 64 mel_peak = height_norm = lin_peak = NULL;65 fft_peak = NULL;66 norm = 1;67 68 mel_freq_max = 1127 * log(1 + freq_max / 700);69 mel_freq_min = 1127 * log(1 + freq_min / 700);70 freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;71 72 mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));73 /* +2 for zeros at start and end */74 lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));75 fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));76 height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));77 78 if(mel_peak == NULL || height_norm == NULL ||79 lin_peak == NULL || fft_peak == NULL)80 return NULL;81 82 M = fb->win_s >> 1;83 84 mel_peak[0] = mel_freq_min;85 lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);86 fft_peak[0] = lin_peak[0] / nyquist * M;87 88 for (n = 1; n <= fb->n_filters; n++){89 /*roll out peak locations - mel, linear and linear on fft window scale */90 mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;91 lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);92 fft_peak[n] = lin_peak[n] / nyquist * M;93 }94 95 for (n = 0; n < fb->n_filters; n++){96 /*roll out normalised gain of each peak*/97 if (style == USE_EQUAL_GAIN){98 height = 1;99 norm_fact = norm;100 }101 else{102 height = 2 / (lin_peak[n + 2] - lin_peak[n]);103 norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));104 }105 height_norm[n] = height * norm_fact;106 }107 108 i = 0;109 110 for(n = 0; n < fb->n_filters; n++){111 112 /*calculate the rise increment*/113 if(n > 0)114 inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);115 else116 inc = height_norm[n] / fft_peak[n];117 val = 0;118 119 /*zero the start of the array*/120 for(k = 0; k < i; k++)121 fb->filters[n]->data[0][k]=0.f;122 123 /*fill in the rise */124 for(; i <= fft_peak[n]; i++){125 fb->filters[n]->data[0][k]=val;126 val += inc;127 }128 129 /*calculate the fall increment */130 inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);131 132 val = 0;133 next_peak = fft_peak[n + 1];134 135 /*reverse fill the 'fall' */136 for(i = next_peak; i > fft_peak[n]; i--){137 fb->filters[n]->data[0][k]=val;138 val += inc;139 }140 141 /*zero the rest of the array*/142 for(k = next_peak + 1; k < fb->win_s; k++)143 fb->filters[n]->data[0][k]=0.f;144 145 146 }147 148 free(mel_peak);149 free(lin_peak);150 free(height_norm);151 free(fft_peak);152 153 154 return fb;155 156 52 } 157 53 … … 166 62 */ 167 63 168 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){64 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){ 169 65 170 66 aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s); … … 187 83 fvec_t * center_freqs=new_fvec( allFilters, 1); 188 84 189 190 85 fvec_t * triangle_heights=new_fvec( allFilters, 1); 191 86 //lookup table of each bin frequency in hz … … 202 97 //second step: filling all the log filter frequencies 203 98 for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){ 204 freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1)); 99 freqs->data[0][filter_cnt+linearFilters] = 100 lastlinearCF*(pow(logSpacing,filter_cnt+1)); 205 101 } 206 102 … … 214 110 } 215 111 216 217 112 //computing triangle heights so that each triangle has unit area 218 113 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]); 114 triangle_heights->data[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt] 115 - lower_freqs->data[0][filter_cnt]); 116 } 117 118 //AUBIO_DBG("filter tables frequencies\n"); 119 //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++) 120 // AUBIO_DBG("filter n. %d %f %f %f %f\n", 121 // filter_cnt, lower_freqs->data[0][filter_cnt], 122 // center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt], 123 // triangle_heights->data[0][filter_cnt]); 227 124 228 125 //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin … … 239 136 smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]); 240 137 241 242 AUBIO_DBG("\nfilter %d",filter_cnt);243 138 //zeroing begining of filter 244 AUBIO_DBG("\nzero begin\n");245 139 for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){ 246 //zeroing beigining of array247 140 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]){ 141 if( fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] && 142 fft_freqs->data[0][bin_cnt+1] > lower_freqs->data[0][filter_cnt]) { 251 143 break; 252 144 } … … 254 146 bin_cnt++; 255 147 256 AUBIO_DBG("\npos slope\n");257 148 //positive slope 258 149 for(; bin_cnt<win_s-1; bin_cnt++){ 259 AUBIO_DBG(".");260 150 fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc; 261 151 //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]) … … 265 155 //bin_cnt++; 266 156 267 268 157 //negative slope 269 AUBIO_DBG("\nneg slope\n");270 158 for(; bin_cnt<win_s-1; bin_cnt++){ 271 //AUBIO_DBG(".");272 159 273 160 //checking whether last value is less than 0... … … 284 171 //bin_cnt++; 285 172 286 AUBIO_DBG("\nzero end\n");287 173 //zeroing tail 288 174 for(; bin_cnt<win_s; bin_cnt++) 289 //AUBIO_DBG(".");290 175 fb->filters[filter_cnt]->data[0][bin_cnt]=0.f; 291 176 … … 293 178 294 179 295 296 180 del_fvec(freqs); 297 181 del_fvec(lower_freqs); -
src/filterbank.h
raeb38cf raa83433 56 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 57 58 /** filterbank initialization for mel filters59 60 \param n_filters number of filters61 \param win_s window size62 \param samplerate63 \param freq_min lowest filter frequency64 \param freq_max highest filter frequency65 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);68 69 70 58 /** destroy filterbank object 71 59 … … 80 68 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out); 81 69 82 /** dump filterbank filter tables in a txt file83 84 */85 void aubio_dump_filterbank(aubio_filterbank_t * fb);86 87 70 #ifdef __cplusplus 88 71 }
Note: See TracChangeset
for help on using the changeset viewer.