Changeset cfd35db


Ignore:
Timestamp:
Sep 17, 2009, 1:26:49 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:
addc9ec
Parents:
3b3b03e
Message:

src/spectral/filterbank_mel.{c,h}: indent

Location:
src/spectral
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    r3b3b03e rcfd35db  
    2626#include "mathutils.h"
    2727
    28 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){
     28void
     29aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, uint_t samplerate,
     30    smpl_t freq_min, smpl_t freq_max)
     31{
    2932
    30   fvec_t *filters = aubio_filterbank_get_coeffs(fb);
     33  fvec_t *filters = aubio_filterbank_get_coeffs (fb);
    3134  uint_t n_filters = filters->channels, win_s = filters->length;
    32  
     35
    3336  //slaney params
    3437  smpl_t lowestFrequency = 133.3333;
     
    3942  uint_t logFilters = 27;
    4043  uint_t allFilters = linearFilters + logFilters;
    41  
     44
    4245  //buffers for computing filter frequencies
    43   fvec_t * freqs=new_fvec(allFilters+2 , 1);
    44  
    45   fvec_t * lower_freqs=new_fvec( allFilters, 1);
    46   fvec_t * upper_freqs=new_fvec( allFilters, 1);
    47   fvec_t * center_freqs=new_fvec( allFilters, 1);
     46  fvec_t *freqs = new_fvec (allFilters + 2, 1);
    4847
    49   fvec_t * triangle_heights=new_fvec( allFilters, 1);
     48  fvec_t *lower_freqs = new_fvec (allFilters, 1);
     49  fvec_t *upper_freqs = new_fvec (allFilters, 1);
     50  fvec_t *center_freqs = new_fvec (allFilters, 1);
     51
     52  fvec_t *triangle_heights = new_fvec (allFilters, 1);
    5053  //lookup table of each bin frequency in hz
    51   fvec_t * fft_freqs=new_fvec(win_s, 1);
     54  fvec_t *fft_freqs = new_fvec (win_s, 1);
    5255
    5356  uint_t filter_cnt, bin_cnt;
    54  
     57
    5558  //first step: filling all the linear filter frequencies
    56   for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){
    57     freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing;
     59  for (filter_cnt = 0; filter_cnt < linearFilters; filter_cnt++) {
     60    freqs->data[0][filter_cnt] = lowestFrequency + filter_cnt * linearSpacing;
    5861  }
    59   smpl_t lastlinearCF=freqs->data[0][filter_cnt-1];
    60  
     62  smpl_t lastlinearCF = freqs->data[0][filter_cnt - 1];
     63
    6164  //second step: filling all the log filter frequencies
    62   for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
    63     freqs->data[0][filter_cnt+linearFilters] =
    64       lastlinearCF*(pow(logSpacing,filter_cnt+1));
     65  for (filter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) {
     66    freqs->data[0][filter_cnt + linearFilters] =
     67        lastlinearCF * (pow (logSpacing, filter_cnt + 1));
    6568  }
    6669
    6770  //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays
    6871  //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step
    69    
    70   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
    71     lower_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt];
    72     center_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+1];
    73     upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2];
     72
     73  for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
     74    lower_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt];
     75    center_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 1];
     76    upper_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 2];
    7477  }
    7578
    7679  //computing triangle heights so that each triangle has unit area
    77   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
    78     triangle_heights->data[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt]
    79       - lower_freqs->data[0][filter_cnt]);
     80  for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
     81    triangle_heights->data[0][filter_cnt] =
     82        2. / (upper_freqs->data[0][filter_cnt]
     83        - lower_freqs->data[0][filter_cnt]);
    8084  }
    81  
     85
    8286  //AUBIO_DBG("filter tables frequencies\n");
    8387  //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
     
    8892
    8993  //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
    90   for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){
    91     fft_freqs->data[0][bin_cnt]= aubio_bintofreq(bin_cnt, samplerate, win_s);
     94  for (bin_cnt = 0; bin_cnt < win_s; bin_cnt++) {
     95    fft_freqs->data[0][bin_cnt] = aubio_bintofreq (bin_cnt, samplerate, win_s);
    9296  }
    9397
    9498  //building each filter table
    95   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
     99  for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) {
    96100
    97101    //TODO:check special case : lower freq =0
    98102    //calculating rise increment in mag/Hz
    99     smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
    100    
     103    smpl_t riseInc =
     104        triangle_heights->data[0][filter_cnt] /
     105        (center_freqs->data[0][filter_cnt] - lower_freqs->data[0][filter_cnt]);
     106
    101107    //zeroing begining of filter
    102     for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
    103       filters->data[filter_cnt][bin_cnt]=0.0;
    104       if( fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] &&
    105           fft_freqs->data[0][bin_cnt+1] > lower_freqs->data[0][filter_cnt]) {
     108    for (bin_cnt = 0; bin_cnt < win_s - 1; bin_cnt++) {
     109      filters->data[filter_cnt][bin_cnt] = 0.0;
     110      if (fft_freqs->data[0][bin_cnt] <= lower_freqs->data[0][filter_cnt] &&
     111          fft_freqs->data[0][bin_cnt + 1] > lower_freqs->data[0][filter_cnt]) {
    106112        break;
    107113      }
    108114    }
    109115    bin_cnt++;
    110    
     116
    111117    //positive slope
    112     for(; bin_cnt<win_s-1; bin_cnt++){
    113       filters->data[filter_cnt][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
     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;
    114122      //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])
    115       if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
     123      if (fft_freqs->data[0][bin_cnt + 1] > center_freqs->data[0][filter_cnt])
    116124        break;
    117125    }
    118126    //bin_cnt++;
    119    
     127
    120128    //negative slope
    121     for(; bin_cnt<win_s-1; bin_cnt++){
    122      
     129    for (; bin_cnt < win_s - 1; bin_cnt++) {
     130
    123131      //checking whether last value is less than 0...
    124       smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc;
    125       if(val>=0)
    126         filters->data[filter_cnt][bin_cnt]=val;
    127       else filters->data[filter_cnt][bin_cnt]=0.0;
    128      
     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
    129140      //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])
    130141      //TODO: CHECK whether bugfix correct
    131       if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
     142      if (fft_freqs->data[0][bin_cnt + 1] > upper_freqs->data[0][filter_cnt])
    132143        break;
    133144    }
    134145    //bin_cnt++;
    135    
     146
    136147    //zeroing tail
    137     for(; bin_cnt<win_s; bin_cnt++)
    138       filters->data[filter_cnt][bin_cnt]=0.f;
     148    for (; bin_cnt < win_s; bin_cnt++)
     149      filters->data[filter_cnt][bin_cnt] = 0.f;
    139150
    140151  }
    141  
    142   /* destroy temporarly allocated vectors */ 
    143   del_fvec(freqs);
    144   del_fvec(lower_freqs);
    145   del_fvec(upper_freqs);
    146   del_fvec(center_freqs);
    147152
    148   del_fvec(triangle_heights);
    149   del_fvec(fft_freqs);
     153  /* destroy temporarly allocated vectors */
     154  del_fvec (freqs);
     155  del_fvec (lower_freqs);
     156  del_fvec (upper_freqs);
     157  del_fvec (center_freqs);
     158
     159  del_fvec (triangle_heights);
     160  del_fvec (fft_freqs);
    150161
    151162}
    152 
  • src/spectral/filterbank_mel.h

    r3b3b03e rcfd35db  
    3636
    3737#ifdef __cplusplus
    38 extern "C" {
     38extern "C"
     39{
    3940#endif
    4041
     
    5051
    5152*/
    52 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
     53void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,
     54    uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
    5355
    5456#ifdef __cplusplus
     
    5658#endif
    5759
    58 #endif // FILTERBANK_MEL_H
     60#endif                          // FILTERBANK_MEL_H
Note: See TracChangeset for help on using the changeset viewer.