Changeset 3c18f9e for src/spectral


Ignore:
Timestamp:
Oct 7, 2009, 11:32:42 PM (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:
a9f1656
Parents:
9a12264
Message:

src/spectral/filterbank_mel.{c,h}: rename _set_mel_coeffs to _set_triangle_bands, add some warnings, setters return uint_t,

Location:
src/spectral
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    r9a12264 r3c18f9e  
    2626#include "mathutils.h"
    2727
    28 void
    29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, fvec_t * freqs,
    30     smpl_t samplerate)
     28uint_t
     29aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
     30    smpl_t samplerate, fvec_t * freqs)
    3131{
    3232
     
    4242    AUBIO_WRN ("not enough filters, %d allocated but %d requested\n",
    4343        n_filters, freqs->length - 2);
     44  }
     45
     46  if (freqs->length - 2 < n_filters) {
     47    AUBIO_WRN ("too many filters, %d allocated but %d requested\n",
     48        n_filters, freqs->length - 2);
     49  }
     50
     51  if (freqs->data[0][freqs->length - 1] > samplerate / 2) {
     52    AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
     53%fHz\n", samplerate / 2, freqs->data[0][freqs->length - 1]);
    4454  }
    4555
     
    7080  /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */
    7181  for (bin = 0; bin < win_s; bin++) {
    72     fft_freqs->data[0][bin] = aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
     82    fft_freqs->data[0][bin] =
     83        aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
    7384  }
    7485
    7586  /* zeroing of all filters */
    7687  fvec_zeros (filters);
     88
     89  if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) {
     90    /* - 1 to make sure we don't miss the smallest power of two */
     91    uint_t min_win_s =
     92        (uint_t) FLOOR (samplerate / lower_freqs->data[0][0]) - 1;
     93    AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
     94band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
     95        fft_freqs->data[0][1], lower_freqs->data[0][0],
     96        upper_freqs->data[0][0], (win_s - 1) * 2,
     97        aubio_next_power_of_two (min_win_s));
     98  }
    7799
    78100  /* building each filter table */
     
    83105      if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] &&
    84106          fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) {
     107        bin++;
    85108        break;
    86109      }
    87110    }
    88     bin++;
    89111
    90112    /* compute positive slope step size */
     
    98120          (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc;
    99121
    100       if (fft_freqs->data[0][bin + 1] > center_freqs->data[0][fn])
     122      if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) {
     123        bin++;
    101124        break;
     125      }
    102126    }
    103     bin++;
    104127
    105128    /* compute negative slope step size */
     
    113136          (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc;
    114137
    115       if (fft_freqs->data[0][bin + 1] > upper_freqs->data[0][fn])
     138      if (filters->data[fn][bin] < 0.) {
     139        filters->data[fn][bin] = 0.;
     140      }
     141
     142      if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn])
    116143        break;
    117144    }
     
    128155  del_fvec (fft_freqs);
    129156
     157  return 0;
    130158}
    131159
    132 void
     160uint_t
    133161aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
    134162    smpl_t samplerate)
    135163{
     164  uint_t retval;
     165
    136166  /* Malcolm Slaney parameters */
    137167  smpl_t lowestFrequency = 133.3333;
     
    161191
    162192  /* now compute the actual coefficients */
    163   aubio_filterbank_set_mel_coeffs (fb, freqs, samplerate);
     193  retval = aubio_filterbank_set_triangle_bands (fb, samplerate, freqs);
    164194
    165195  /* destroy vector used to store frequency limits */
    166196  del_fvec (freqs);
    167197
     198  return retval;
    168199}
  • src/spectral/filterbank_mel.h

    r9a12264 r3c18f9e  
    4040#endif
    4141
    42 /** filterbank initialization for mel filters
     42/** filterbank initialization with triangular and overlapping bands
    4343
    4444  \param fb filterbank object
     
    4747
    4848  This function computes the coefficients of the filterbank based on the
    49   boundaries found in freqs, in Hz, and using triangular overlapping windows.
     49  boundaries found in freqs, in Hz, and using triangular overlapping bands.
    5050
    5151*/
    52 void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,
    53     fvec_t * freqs, smpl_t samplerate);
     52uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
     53    smpl_t samplerate, fvec_t * freqs);
    5454
    5555/** filterbank initialization for Mel filters using Slaney's coefficients
     
    6161
    6262*/
    63 void aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
     63uint_t aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
    6464    smpl_t samplerate);
    6565
Note: See TracChangeset for help on using the changeset viewer.