Changeset fa713bd


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

Location:
src/spectral
Files:
2 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}
  • src/spectral/filterbank_mel.h

    r2886984 rfa713bd  
    5858  \param samplerate audio sampling rate
    5959
    60   The filter coefficients are built according to Malcolm Slaney's Auditory
    61   Toolbox, available online at the following address (see file mfcc.m):
     60  The filter coefficients are built to match exactly Malcolm Slaney's Auditory
     61  Toolbox implementation (see file mfcc.m). The number of filters should be 40.
    6262
     63  References
     64  ----------
     65
     66  Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
    6367  https://engineering.purdue.edu/~malcolm/interval/1998-010/
    6468
     
    6771    smpl_t samplerate);
    6872
     73/** Mel filterbank initialization
     74
     75  \param fb filterbank object
     76  \param samplerate audio sampling rate
     77  \param fmin start frequency, in Hz
     78  \param fmax end frequency, in Hz
     79
     80  The filterbank will be initialized with bands linearly spaced in the mel
     81  scale, from `fmin` to `fmax`.
     82
     83  References
     84  ----------
     85
     86  Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
     87  https://engineering.purdue.edu/~malcolm/interval/1998-010/
     88
     89*/
     90uint_t aubio_filterbank_set_mel_coeffs(aubio_filterbank_t * fb,
     91    smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
     92
     93/** Mel filterbank initialization
     94
     95  \param fb filterbank object
     96  \param samplerate audio sampling rate
     97  \param fmin start frequency, in Hz
     98  \param fmax end frequency, in Hz
     99
     100  The bank of filters will be initalized to to cover linearly spaced bands in
     101  the Htk mel scale, from `fmin` to `fmax`.
     102
     103  References
     104  ----------
     105
     106  Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
     107  Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
     108
     109  HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
     110
     111*/
     112uint_t aubio_filterbank_set_mel_coeffs_htk(aubio_filterbank_t * fb,
     113    smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
     114
    69115#ifdef __cplusplus
    70116}
Note: See TracChangeset for help on using the changeset viewer.