Changeset c03d191 for src/spectral/filterbank_mel.c
- Timestamp:
- Nov 17, 2018, 10:19:27 PM (6 years ago)
- Branches:
- feature/constantq
- Children:
- d1d4ad4
- Parents:
- 088760e (diff), a114fe0 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/filterbank_mel.c
r088760e rc03d191 55 55 } 56 56 57 if (freqs->data[freqs->length - 1] > samplerate / 2) { 58 AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \ 59 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]); 57 for (fn = 0; fn < freqs->length; fn++) { 58 if (freqs->data[fn] < 0) { 59 AUBIO_ERR("filterbank_mel: freqs must contain only positive values.\n"); 60 return AUBIO_FAIL; 61 } else if (freqs->data[fn] > samplerate / 2) { 62 AUBIO_WRN("filterbank_mel: freqs should contain only " 63 "values < samplerate / 2.\n"); 64 } else if (fn > 0 && freqs->data[fn] < freqs->data[fn-1]) { 65 AUBIO_ERR("filterbank_mel: freqs should be a list of frequencies " 66 "sorted from low to high, but freq[%d] < freq[%d-1]\n", fn, fn); 67 return AUBIO_FAIL; 68 } else if (fn > 0 && freqs->data[fn] == freqs->data[fn-1]) { 69 AUBIO_WRN("filterbank_mel: set_triangle_bands received a list " 70 "with twice the frequency %f\n", freqs->data[fn]); 71 } 60 72 } 61 73 … … 79 91 80 92 /* compute triangle heights so that each triangle has unit area */ 81 for (fn = 0; fn < n_filters; fn++) { 82 triangle_heights->data[fn] = 83 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 93 if (aubio_filterbank_get_norm(fb)) { 94 for (fn = 0; fn < n_filters; fn++) { 95 triangle_heights->data[fn] = 96 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 97 } 98 } else { 99 fvec_ones (triangle_heights); 84 100 } 85 101 … … 92 108 /* zeroing of all filters */ 93 109 fmat_zeros (filters); 94 95 if (fft_freqs->data[1] >= lower_freqs->data[0]) {96 /* - 1 to make sure we don't miss the smallest power of two */97 uint_t min_win_s =98 (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;99 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \100 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",101 fft_freqs->data[1], lower_freqs->data[0],102 upper_freqs->data[0], (win_s - 1) * 2,103 aubio_next_power_of_two (min_win_s));104 }105 110 106 111 /* building each filter table */ … … 117 122 118 123 /* compute positive slope step size */ 119 riseInc = 120 triangle_heights->data[fn] / 121 (center_freqs->data[fn] - lower_freqs->data[fn]); 124 riseInc = triangle_heights->data[fn] 125 / (center_freqs->data[fn] - lower_freqs->data[fn]); 122 126 123 127 /* compute coefficients in positive slope */ … … 133 137 134 138 /* compute negative slope step size */ 135 downInc = 136 triangle_heights->data[fn] / 137 (upper_freqs->data[fn] - center_freqs->data[fn]); 139 downInc = triangle_heights->data[fn] 140 / (upper_freqs->data[fn] - center_freqs->data[fn]); 138 141 139 142 /* compute coefficents in negative slope */ … … 161 164 del_fvec (fft_freqs); 162 165 163 return 0;166 return AUBIO_OK; 164 167 } 165 168 … … 168 171 smpl_t samplerate) 169 172 { 170 uint_t retval;171 172 173 /* Malcolm Slaney parameters */ 173 smpl_t lowestFrequency = 133.3333; 174 smpl_t linearSpacing = 66.66666666; 175 smpl_t logSpacing = 1.0711703; 176 177 uint_t linearFilters = 13; 178 uint_t logFilters = 27; 179 uint_t n_filters = linearFilters + logFilters; 180 181 uint_t fn; /* filter counter */ 182 174 const smpl_t lowestFrequency = 133.3333; 175 const smpl_t linearSpacing = 66.66666666; 176 const smpl_t logSpacing = 1.0711703; 177 178 const uint_t linearFilters = 13; 179 const uint_t logFilters = 27; 180 const uint_t n_filters = linearFilters + logFilters; 181 182 uint_t fn, retval; 183 183 smpl_t lastlinearCF; 184 184 185 185 /* buffers to compute filter frequencies */ 186 fvec_t *freqs = new_fvec (n_filters + 2); 186 fvec_t *freqs; 187 188 if (samplerate <= 0) { 189 AUBIO_ERR("filterbank: set_mel_coeffs_slaney samplerate should be > 0\n"); 190 return AUBIO_FAIL; 191 } 192 193 freqs = new_fvec (n_filters + 2); 187 194 188 195 /* first step: fill all the linear filter frequencies */ … … 206 213 return retval; 207 214 } 215 216 static uint_t aubio_filterbank_check_freqs (aubio_filterbank_t *fb UNUSED, 217 smpl_t samplerate, smpl_t *freq_min, smpl_t *freq_max) 218 { 219 if (samplerate <= 0) { 220 AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n"); 221 return AUBIO_FAIL; 222 } 223 if (*freq_max < 0) { 224 AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n"); 225 return AUBIO_FAIL; 226 } else if (*freq_max == 0) { 227 *freq_max = samplerate / 2.; 228 } 229 if (*freq_min < 0) { 230 AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n"); 231 return AUBIO_FAIL; 232 } 233 return AUBIO_OK; 234 } 235 236 uint_t 237 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate, 238 smpl_t freq_min, smpl_t freq_max) 239 { 240 uint_t m, retval; 241 smpl_t start = freq_min, end = freq_max, step; 242 fvec_t *freqs; 243 fmat_t *coeffs = aubio_filterbank_get_coeffs(fb); 244 uint_t n_bands = coeffs->height; 245 246 if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) { 247 return AUBIO_FAIL; 248 } 249 250 start = aubio_hztomel(start); 251 end = aubio_hztomel(end); 252 253 freqs = new_fvec(n_bands + 2); 254 step = (end - start) / (n_bands + 1); 255 256 for (m = 0; m < n_bands + 2; m++) 257 { 258 freqs->data[m] = MIN(aubio_meltohz(start + step * m), samplerate/2.); 259 } 260 261 retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate); 262 263 /* destroy vector used to store frequency limits */ 264 del_fvec (freqs); 265 return retval; 266 } 267 268 uint_t 269 aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate, 270 smpl_t freq_min, smpl_t freq_max) 271 { 272 uint_t m, retval; 273 smpl_t start = freq_min, end = freq_max, step; 274 fvec_t *freqs; 275 fmat_t *coeffs = aubio_filterbank_get_coeffs(fb); 276 uint_t n_bands = coeffs->height; 277 278 if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) { 279 return AUBIO_FAIL; 280 } 281 282 start = aubio_hztomel_htk(start); 283 end = aubio_hztomel_htk(end); 284 285 freqs = new_fvec (n_bands + 2); 286 step = (end - start) / (n_bands + 1); 287 288 for (m = 0; m < n_bands + 2; m++) 289 { 290 freqs->data[m] = MIN(aubio_meltohz_htk(start + step * m), samplerate/2.); 291 } 292 293 retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate); 294 295 /* destroy vector used to store frequency limits */ 296 del_fvec (freqs); 297 return retval; 298 }
Note: See TracChangeset
for help on using the changeset viewer.