Changeset b507607 for src


Ignore:
Timestamp:
Sep 17, 2009, 4:02:04 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:
4e0fbe6
Parents:
addc9ec
Message:

src/spectral/filterbank_mel.c: correct computation of coefficients, use float samplerate, use POW, make sure we don't try to set unexisting filters

Location:
src/spectral
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    raddc9ec rb507607  
    2727
    2828void
    29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, uint_t samplerate,
     29aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
    3030    smpl_t freq_min, smpl_t freq_max)
    3131{
     
    4242  uint_t logFilters = 27;
    4343  uint_t allFilters = linearFilters + logFilters;
     44
     45  if (allFilters > n_filters) {
     46    AUBIO_WRN("not enough Mel filters, got %d but %d needed\n",
     47        n_filters, allFilters);
     48  }
    4449
    4550  //buffers for computing filter frequencies
     
    6570  for (filter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) {
    6671    freqs->data[0][filter_cnt + linearFilters] =
    67         lastlinearCF * (pow (logSpacing, filter_cnt + 1));
     72        lastlinearCF * (POW(logSpacing, filter_cnt + 1));
    6873  }
    6974
     
    8489  }
    8590
    86   //AUBIO_DBG("filter tables frequencies\n");
    87   //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
    88   //  AUBIO_DBG("filter n. %d %f %f %f %f\n",
    89   //    filter_cnt, lower_freqs->data[0][filter_cnt],
    90   //    center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt],
    91   //    triangle_heights->data[0][filter_cnt]);
    92 
    9391  //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
    9492  for (bin_cnt = 0; bin_cnt < win_s; bin_cnt++) {
     
    9694  }
    9795
    98   //building each filter table
    99   for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
    10096
    101     //TODO:check special case : lower freq =0
    102     //calculating rise increment in mag/Hz
    103     smpl_t riseInc =
    104         triangle_heights->data[0][filter_cnt] /
    105         (center_freqs->data[0][filter_cnt] - lower_freqs->data[0][filter_cnt]);
     97  /* zeroing begining of filter */
     98  fvec_zeros(filters);
    10699
    107     //zeroing begining of filter
     100  /* building each filter table */
     101  for (filter_cnt = 0; filter_cnt < n_filters; filter_cnt++) {
     102
     103    /* skip first elements */
    108104    for (bin_cnt = 0; bin_cnt < win_s - 1; bin_cnt++) {
    109       filters->data[filter_cnt][bin_cnt] = 0.0;
    110105      if (fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] &&
    111106          fft_freqs->data[0][bin_cnt + 1] > lower_freqs->data[0][filter_cnt]) {
     
    115110    bin_cnt++;
    116111
    117     //positive slope
     112    /* compute positive slope step size */
     113    smpl_t riseInc =
     114        triangle_heights->data[0][filter_cnt] /
     115        (center_freqs->data[0][filter_cnt] - lower_freqs->data[0][filter_cnt]);
     116
     117    /* compute coefficients in positive slope */
    118118    for (; bin_cnt < win_s - 1; bin_cnt++) {
    119119      filters->data[filter_cnt][bin_cnt] =
    120120          (fft_freqs->data[0][bin_cnt] -
    121121          lower_freqs->data[0][filter_cnt]) * riseInc;
    122       //if(fft_freqs->data[0][bin_cnt]<= center_freqs->data[0][filter_cnt] && fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
     122     
    123123      if (fft_freqs->data[0][bin_cnt + 1] > center_freqs->data[0][filter_cnt])
    124124        break;
    125125    }
    126     //bin_cnt++;
     126    bin_cnt++;
    127127
    128     //negative slope
     128    /* compute negative slope step size */
     129    smpl_t downInc =
     130        triangle_heights->data[0][filter_cnt] /
     131        (upper_freqs->data[0][filter_cnt] - center_freqs->data[0][filter_cnt]);
     132
     133    /* compute coefficents in negative slope */
    129134    for (; bin_cnt < win_s - 1; bin_cnt++) {
     135      filters->data[filter_cnt][bin_cnt] +=
     136          (upper_freqs->data[0][filter_cnt] -
     137          fft_freqs->data[0][bin_cnt]) * downInc;
    130138
    131       //checking whether last value is less than 0...
    132       smpl_t val =
    133           triangle_heights->data[0][filter_cnt] - (fft_freqs->data[0][bin_cnt] -
    134           center_freqs->data[0][filter_cnt]) * riseInc;
    135       if (val >= 0)
    136         filters->data[filter_cnt][bin_cnt] = val;
    137       else
    138         filters->data[filter_cnt][bin_cnt] = 0.0;
    139 
    140       //if(fft_freqs->data[0][bin_cnt]<= upper_freqs->data[0][bin_cnt] && fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
    141       //TODO: CHECK whether bugfix correct
    142139      if (fft_freqs->data[0][bin_cnt + 1] > upper_freqs->data[0][filter_cnt])
    143140        break;
    144141    }
    145     //bin_cnt++;
    146 
    147     //zeroing tail
    148     for (; bin_cnt < win_s; bin_cnt++)
    149       filters->data[filter_cnt][bin_cnt] = 0.f;
     142    /* nothing else to do */
    150143
    151144  }
  • src/spectral/filterbank_mel.h

    raddc9ec rb507607  
    4646  \param n_filters number of filters
    4747  \param win_s window size
    48   \param samplerate
     48  \param samplerate audio sampling rate
    4949  \param freq_min lowest filter frequency
    5050  \param freq_max highest filter frequency
     
    5252*/
    5353void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,
    54     uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
     54    smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
    5555
    5656#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.