Changeset 4e0fbe6 for src/spectral


Ignore:
Timestamp:
Sep 17, 2009, 4:21:40 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:
bc3c51b
Parents:
b507607
Message:

src/spectral/filterbank_mel.c: shorten counter variable names, improve comments, run through indent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    rb507607 r4e0fbe6  
    3434  uint_t n_filters = filters->channels, win_s = filters->length;
    3535
    36   //slaney params
     36  /* Malcolm Slaney parameters */
    3737  smpl_t lowestFrequency = 133.3333;
    3838  smpl_t linearSpacing = 66.66666666;
     
    4343  uint_t allFilters = linearFilters + logFilters;
    4444
     45  /* throw a warning if filterbank object fb is too short */
    4546  if (allFilters > n_filters) {
    46     AUBIO_WRN("not enough Mel filters, got %d but %d needed\n",
     47    AUBIO_WRN ("not enough Mel filters, got %d but %d needed\n",
    4748        n_filters, allFilters);
    4849  }
    4950
    50   //buffers for computing filter frequencies
     51  /* buffers for computing filter frequencies */
    5152  fvec_t *freqs = new_fvec (allFilters + 2, 1);
    5253
     54  /* convenience reference to lower/center/upper frequency for each triangle */
    5355  fvec_t *lower_freqs = new_fvec (allFilters, 1);
    5456  fvec_t *upper_freqs = new_fvec (allFilters, 1);
    5557  fvec_t *center_freqs = new_fvec (allFilters, 1);
    5658
     59  /* height of each triangle */
    5760  fvec_t *triangle_heights = new_fvec (allFilters, 1);
    58   //lookup table of each bin frequency in hz
     61
     62  /* lookup table of each bin frequency in hz */
    5963  fvec_t *fft_freqs = new_fvec (win_s, 1);
    6064
    61   uint_t filter_cnt, bin_cnt;
     65  uint_t fn;                    /* filter counter */
     66  uint_t bin;                   /* bin counter */
    6267
    63   //first step: filling all the linear filter frequencies
    64   for (filter_cnt = 0; filter_cnt < linearFilters; filter_cnt++) {
    65     freqs->data[0][filter_cnt] = lowestFrequency + filter_cnt * linearSpacing;
     68  /* first step: filling all the linear filter frequencies */
     69  for (fn = 0; fn < linearFilters; fn++) {
     70    freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;
    6671  }
    67   smpl_t lastlinearCF = freqs->data[0][filter_cnt - 1];
     72  smpl_t lastlinearCF = freqs->data[0][fn - 1];
    6873
    69   //second step: filling all the log filter frequencies
    70   for (filter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) {
    71     freqs->data[0][filter_cnt + linearFilters] =
    72         lastlinearCF * (POW(logSpacing, filter_cnt + 1));
     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));
    7378  }
    7479
    75   //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays
    76   //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step
    77 
    78   for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
    79     lower_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt];
    80     center_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 1];
    81     upper_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 2];
     80  /* fill up the lower/center/upper */
     81  for (fn = 0; fn < allFilters; fn++) {
     82    lower_freqs->data[0][fn] = freqs->data[0][fn];
     83    center_freqs->data[0][fn] = freqs->data[0][fn + 1];
     84    upper_freqs->data[0][fn] = freqs->data[0][fn + 2];
    8285  }
    8386
    84   //computing triangle heights so that each triangle has unit area
    85   for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
    86     triangle_heights->data[0][filter_cnt] =
    87         2. / (upper_freqs->data[0][filter_cnt]
    88         - lower_freqs->data[0][filter_cnt]);
     87  /* compute triangle heights so that each triangle has unit area */
     88  for (fn = 0; fn < allFilters; fn++) {
     89    triangle_heights->data[0][fn] =
     90        2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]);
    8991  }
    9092
    91   //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
    92   for (bin_cnt = 0; bin_cnt < win_s; bin_cnt++) {
    93     fft_freqs->data[0][bin_cnt] = aubio_bintofreq (bin_cnt, samplerate, win_s);
     93  /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */
     94  for (bin = 0; bin < win_s; bin++) {
     95    fft_freqs->data[0][bin] = aubio_bintofreq (bin, samplerate, win_s);
    9496  }
    9597
    96 
    97   /* zeroing begining of filter */
    98   fvec_zeros(filters);
     98  /* zeroing of all filters */
     99  fvec_zeros (filters);
    99100
    100101  /* building each filter table */
    101   for (filter_cnt = 0; filter_cnt < n_filters; filter_cnt++) {
     102  for (fn = 0; fn < n_filters; fn++) {
    102103
    103104    /* skip first elements */
    104     for (bin_cnt = 0; bin_cnt < win_s - 1; bin_cnt++) {
    105       if (fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] &&
    106           fft_freqs->data[0][bin_cnt + 1] > lower_freqs->data[0][filter_cnt]) {
     105    for (bin = 0; bin < win_s - 1; bin++) {
     106      if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] &&
     107          fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) {
    107108        break;
    108109      }
    109110    }
    110     bin_cnt++;
     111    bin++;
    111112
    112113    /* compute positive slope step size */
    113114    smpl_t riseInc =
    114         triangle_heights->data[0][filter_cnt] /
    115         (center_freqs->data[0][filter_cnt] - lower_freqs->data[0][filter_cnt]);
     115        triangle_heights->data[0][fn] /
     116        (center_freqs->data[0][fn] - lower_freqs->data[0][fn]);
    116117
    117118    /* compute coefficients in positive slope */
    118     for (; bin_cnt < win_s - 1; bin_cnt++) {
    119       filters->data[filter_cnt][bin_cnt] =
    120           (fft_freqs->data[0][bin_cnt] -
    121           lower_freqs->data[0][filter_cnt]) * riseInc;
    122      
    123       if (fft_freqs->data[0][bin_cnt + 1] > center_freqs->data[0][filter_cnt])
     119    for (; bin < win_s - 1; bin++) {
     120      filters->data[fn][bin] =
     121          (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc;
     122
     123      if (fft_freqs->data[0][bin + 1] > center_freqs->data[0][fn])
    124124        break;
    125125    }
    126     bin_cnt++;
     126    bin++;
    127127
    128128    /* compute negative slope step size */
    129129    smpl_t downInc =
    130         triangle_heights->data[0][filter_cnt] /
    131         (upper_freqs->data[0][filter_cnt] - center_freqs->data[0][filter_cnt]);
     130        triangle_heights->data[0][fn] /
     131        (upper_freqs->data[0][fn] - center_freqs->data[0][fn]);
    132132
    133133    /* compute coefficents in negative slope */
    134     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;
     134    for (; bin < win_s - 1; bin++) {
     135      filters->data[fn][bin] +=
     136          (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc;
    138137
    139       if (fft_freqs->data[0][bin_cnt + 1] > upper_freqs->data[0][filter_cnt])
     138      if (fft_freqs->data[0][bin + 1] > upper_freqs->data[0][fn])
    140139        break;
    141140    }
Note: See TracChangeset for help on using the changeset viewer.