Changeset 6d41dac


Ignore:
Timestamp:
Nov 17, 2018, 1:54:20 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
f6bfc26
Parents:
0316feb
Message:

[filterbank] factorize input validation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    r0316feb r6d41dac  
    210210}
    211211
     212static uint_t aubio_filterbank_check_freqs (aubio_filterbank_t *fb UNUSED,
     213    smpl_t samplerate, smpl_t *freq_min, smpl_t *freq_max)
     214{
     215  if (samplerate <= 0) {
     216    AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
     217    return AUBIO_FAIL;
     218  }
     219  if (*freq_max < 0) {
     220    AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     221    return AUBIO_FAIL;
     222  } else if (*freq_max == 0) {
     223    *freq_max = samplerate / 2.;
     224  }
     225  if (*freq_min < 0) {
     226    AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
     227    return AUBIO_FAIL;
     228  }
     229  return AUBIO_OK;
     230}
     231
    212232uint_t
    213233aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
     
    215235{
    216236  uint_t m, retval;
    217   smpl_t start, end, step;
     237  smpl_t start = freq_min, end = freq_max, step;
    218238  fvec_t *freqs;
    219239  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
    220240  uint_t n_bands = coeffs->height;
    221241
    222   if (samplerate <= 0) {
    223     AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
    224     return AUBIO_FAIL;
    225   }
    226   if (freq_max < 0) {
    227     AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
    228     return AUBIO_FAIL;
    229   } else if (freq_max == 0) {
    230     end = aubio_hztomel(samplerate / 2.);
    231   } else {
    232     end = aubio_hztomel(freq_max);
    233   }
    234   if (freq_min < 0) {
    235     AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
    236     return AUBIO_FAIL;
    237   } else {
    238     start = aubio_hztomel(freq_min);
    239   }
     242  if (aubio_filterbank_check_freqs(fb, samplerate, &freq_min, &freq_max)) {
     243    return AUBIO_FAIL;
     244  }
     245
     246  start = aubio_hztomel(start);
     247  end = aubio_hztomel(end);
    240248
    241249  freqs = new_fvec(n_bands + 2);
     
    259267{
    260268  uint_t m, retval;
    261   smpl_t start, end, step;
     269  smpl_t start = freq_min, end = freq_max, step;
    262270  fvec_t *freqs;
    263271  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
    264272  uint_t n_bands = coeffs->height;
    265273
    266   if (samplerate <= 0) {
    267     AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
    268     return AUBIO_FAIL;
    269   }
    270   if (freq_max < 0) {
    271     AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
    272     return AUBIO_FAIL;
    273   } else if (freq_max == 0) {
    274     end = aubio_hztomel_htk(samplerate / 2.);
    275   } else {
    276     end = aubio_hztomel_htk(freq_max);
    277   }
    278   if (freq_min < 0) {
    279     AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
    280     return AUBIO_FAIL;
    281   } else {
    282     start = aubio_hztomel_htk(freq_min);
    283   }
     274  if (aubio_filterbank_check_freqs(fb, samplerate, &freq_min, &freq_max)) {
     275    return AUBIO_FAIL;
     276  }
     277
     278  start = aubio_hztomel_htk(start);
     279  end = aubio_hztomel_htk(end);
    284280
    285281  freqs = new_fvec (n_bands + 2);
Note: See TracChangeset for help on using the changeset viewer.