Changeset 1e37ade


Ignore:
Timestamp:
Sep 17, 2009, 5:54:25 AM (15 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, pitchshift, sampler, timestretch, yinfft+
Children:
e7b3629
Parents:
bc3c51b
Message:

src/spectral/filterbank_mel.c: move Slaney's specific code to _slaney function

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    rbc3c51b r1e37ade  
    2727
    2828void
    29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
    30     smpl_t freq_min, smpl_t freq_max)
     29aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, fvec_t * freqs,
     30    smpl_t samplerate)
    3131{
    3232
     
    3434  uint_t n_filters = filters->channels, win_s = filters->length;
    3535
    36   /* Malcolm Slaney parameters */
    37   smpl_t lowestFrequency = 133.3333;
    38   smpl_t linearSpacing = 66.66666666;
    39   smpl_t logSpacing = 1.0711703;
     36  uint_t fn;                    /* filter counter */
     37  uint_t bin;                   /* bin counter */
    4038
    41   uint_t linearFilters = 13;
    42   uint_t logFilters = 27;
    43   uint_t allFilters = linearFilters + logFilters;
    44 
    45   /* throw a warning if filterbank object fb is too short */
    46   if (allFilters > n_filters) {
    47     AUBIO_WRN ("not enough Mel filters, got %d but %d needed\n",
    48         n_filters, allFilters);
     39  /* freqs define the bands of triangular overlapping windows.
     40     throw a warning if filterbank object fb is too short. */
     41  if (freqs->length - 2 > n_filters) {
     42    AUBIO_WRN ("not enough filters, %d allocated but %d requested\n",
     43        n_filters, freqs->length - 2);
    4944  }
    5045
    51   /* buffers for computing filter frequencies */
    52   fvec_t *freqs = new_fvec (allFilters + 2, 1);
    53 
    5446  /* convenience reference to lower/center/upper frequency for each triangle */
    55   fvec_t *lower_freqs = new_fvec (allFilters, 1);
    56   fvec_t *upper_freqs = new_fvec (allFilters, 1);
    57   fvec_t *center_freqs = new_fvec (allFilters, 1);
     47  fvec_t *lower_freqs = new_fvec (n_filters, 1);
     48  fvec_t *upper_freqs = new_fvec (n_filters, 1);
     49  fvec_t *center_freqs = new_fvec (n_filters, 1);
    5850
    5951  /* height of each triangle */
    60   fvec_t *triangle_heights = new_fvec (allFilters, 1);
     52  fvec_t *triangle_heights = new_fvec (n_filters, 1);
    6153
    6254  /* lookup table of each bin frequency in hz */
    6355  fvec_t *fft_freqs = new_fvec (win_s, 1);
    6456
    65   uint_t fn;                    /* filter counter */
    66   uint_t bin;                   /* bin counter */
    67 
    68   /* first step: filling all the linear filter frequencies */
    69   for (fn = 0; fn < linearFilters; fn++) {
    70     freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;
    71   }
    72   smpl_t lastlinearCF = freqs->data[0][fn - 1];
    73 
    74   /* second step: filling all the log filter frequencies */
    75   for (fn = 0; fn < logFilters + 2; fn++) {
    76     freqs->data[0][fn + linearFilters] =
    77         lastlinearCF * (POW (logSpacing, fn + 1));
    78   }
    79 
    8057  /* fill up the lower/center/upper */
    81   for (fn = 0; fn < allFilters; fn++) {
     58  for (fn = 0; fn < n_filters; fn++) {
    8259    lower_freqs->data[0][fn] = freqs->data[0][fn];
    8360    center_freqs->data[0][fn] = freqs->data[0][fn + 1];
     
    8663
    8764  /* compute triangle heights so that each triangle has unit area */
    88   for (fn = 0; fn < allFilters; fn++) {
     65  for (fn = 0; fn < n_filters; fn++) {
    8966    triangle_heights->data[0][fn] =
    9067        2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]);
     
    144121
    145122  /* destroy temporarly allocated vectors */
    146   del_fvec (freqs);
    147123  del_fvec (lower_freqs);
    148124  del_fvec (upper_freqs);
     
    153129
    154130}
     131
     132void
     133aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
     134    smpl_t samplerate)
     135{
     136  /* Malcolm Slaney parameters */
     137  smpl_t lowestFrequency = 133.3333;
     138  smpl_t linearSpacing = 66.66666666;
     139  smpl_t logSpacing = 1.0711703;
     140
     141  uint_t linearFilters = 13;
     142  uint_t logFilters = 27;
     143  uint_t n_filters = linearFilters + logFilters;
     144
     145  uint_t fn;                    /* filter counter */
     146  uint_t bin;                   /* bin counter */
     147
     148  /* buffers to compute filter frequencies */
     149  fvec_t *freqs = new_fvec (n_filters + 2, 1);
     150
     151  /* first step: fill all the linear filter frequencies */
     152  for (fn = 0; fn < linearFilters; fn++) {
     153    freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;
     154  }
     155  smpl_t lastlinearCF = freqs->data[0][fn - 1];
     156
     157  /* second step: fill all the log filter frequencies */
     158  for (fn = 0; fn < logFilters + 2; fn++) {
     159    freqs->data[0][fn + linearFilters] =
     160        lastlinearCF * (POW (logSpacing, fn + 1));
     161  }
     162
     163  /* now compute the actual coefficients */
     164  aubio_filterbank_set_mel_coeffs (fb, freqs, samplerate);
     165
     166  /* destroy vector used to store frequency limits */
     167  del_fvec (freqs);
     168
     169}
  • src/spectral/filterbank_mel.h

    rbc3c51b r1e37ade  
    4444/** filterbank initialization for mel filters
    4545
    46   \param n_filters number of filters
    47   \param win_s window size
     46  \param fb filterbank object
     47  \param freqs arbitrary array of boundary frequencies
    4848  \param samplerate audio sampling rate
    49   \param freq_min lowest filter frequency
    50   \param freq_max highest filter frequency
     49
     50  This function computes the coefficients of the filterbank based on the
     51  boundaries found in freqs, in Hz, and using triangular overlapping windows.
    5152
    5253*/
    5354void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,
    54     smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
     55    fvec_t * freqs, smpl_t samplerate);
     56
     57/** filterbank initialization for Mel filters using Slaney's coefficients
     58
     59  \param fb filterbank object
     60  \param samplerate audio sampling rate
     61
     62  This function fills the filterbank coefficients according to Malcolm Slaney.
     63
     64*/
     65void aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
     66    smpl_t samplerate);
    5567
    5668#ifdef __cplusplus
  • src/spectral/mfcc.c

    rbc3c51b r1e37ade  
    6363  /** filterbank allocation */
    6464  mfcc->fb = new_aubio_filterbank(n_filters, mfcc->win_s);
    65   aubio_filterbank_set_mel_coeffs(mfcc->fb, samplerate, lowfreq, highfreq);
     65  aubio_filterbank_set_mel_coeffs_slaney(mfcc->fb, samplerate);
    6666
    6767  /** allocating space for fft object (used for dct) */
  • swig/aubio.i

    rbc3c51b r1e37ade  
    163163/* filterbank */
    164164aubio_filterbank_t * new_aubio_filterbank(uint_t win_s, uint_t channels);
    165 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
     165void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, fvec_t *freqs, uint_t samplerate);
     166void aubio_filterbank_set_mel_coeffs_slaney(aubio_filterbank_t *fb, uint_t samplerate);
    166167void del_aubio_filterbank(aubio_filterbank_t * fb);
    167168void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
Note: See TracChangeset for help on using the changeset viewer.