Ignore:
Timestamp:
Nov 17, 2018, 3:15:07 AM (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:
04cd251
Parents:
2886984
Message:

[filterbank] add set_mel_coeffs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    r2886984 rfa713bd  
    207207  return retval;
    208208}
     209
     210uint_t
     211aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
     212    smpl_t freq_min, smpl_t freq_max)
     213{
     214  uint_t m, retval;
     215  smpl_t start, end, step;
     216  fvec_t *freqs;
     217  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
     218  uint_t n_bands = coeffs->height;
     219
     220  if (freq_max < 0) {
     221    AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     222    return AUBIO_FAIL;
     223  } else if (freq_max == 0) {
     224    end = aubio_hztomel(samplerate / 2.);
     225  } else {
     226    end = aubio_hztomel(freq_max);
     227  }
     228  if (freq_min < 0) {
     229    AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
     230    return AUBIO_FAIL;
     231  } else {
     232    start = aubio_hztomel(freq_min);
     233  }
     234  if (n_bands <= 0) {
     235    AUBIO_ERR("filterbank: set_mel_coeffs n_bands should be > 0\n");
     236    return AUBIO_FAIL;
     237  }
     238
     239  freqs = new_fvec(n_bands + 2);
     240  step = (end - start) / (n_bands + 1);
     241
     242  for (m = 0; m < n_bands + 2; m++)
     243  {
     244    freqs->data[m] = MIN(aubio_meltohz(start + step * m), samplerate/2.);
     245  }
     246
     247  retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
     248
     249  /* destroy vector used to store frequency limits */
     250  del_fvec (freqs);
     251  return retval;
     252}
     253
     254uint_t
     255aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate,
     256    smpl_t freq_min, smpl_t freq_max)
     257{
     258  uint_t m, retval;
     259  smpl_t start, end, step;
     260  fvec_t *freqs;
     261  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
     262  uint_t n_bands = coeffs->height;
     263
     264  if (freq_max < 0) {
     265    AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     266    return AUBIO_FAIL;
     267  } else if (freq_max == 0) {
     268    end = aubio_hztomel_htk(samplerate / 2.);
     269  } else {
     270    end = aubio_hztomel_htk(freq_max);
     271  }
     272  if (freq_min < 0) {
     273    AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
     274    return AUBIO_FAIL;
     275  } else {
     276    start = aubio_hztomel_htk(freq_min);
     277  }
     278  if (n_bands <= 0) {
     279    AUBIO_ERR("filterbank: set_mel_coeffs n_bands should be > 0\n");
     280    return AUBIO_FAIL;
     281  }
     282
     283  freqs = new_fvec (n_bands + 2);
     284  step = (end - start) / (n_bands + 1);
     285
     286  for (m = 0; m < n_bands + 2; m++)
     287  {
     288    freqs->data[m] = MIN(aubio_meltohz_htk(step * m), samplerate/2.);
     289  }
     290
     291  retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
     292
     293  /* destroy vector used to store frequency limits */
     294  del_fvec (freqs);
     295  return retval;
     296}
Note: See TracChangeset for help on using the changeset viewer.