Changeset aa83433


Ignore:
Timestamp:
Sep 16, 2007, 9:55:42 PM (17 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:
9170e4c
Parents:
aeb38cf
Message:

filterbank.{c,h}: remove old new_aubio_filterbank_mfcc, replace with new one, remove aubio_dump_filterbank, start wrapping lines to 80 chars, remove some debug output

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/filterbank.c

    raeb38cf raa83433  
    5050
    5151  return fb;
    52 }
    53 
    54 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){
    55  
    56   smpl_t nyquist = samplerate/2.;
    57   uint_t style = 1;
    58   aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
    59 
    60   uint_t n, i, k, *fft_peak, M, next_peak;
    61   smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val,
    62          freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
    63 
    64   mel_peak = height_norm = lin_peak = NULL;
    65   fft_peak = NULL;
    66   norm = 1;
    67 
    68   mel_freq_max = 1127 * log(1 + freq_max / 700);
    69   mel_freq_min = 1127 * log(1 + freq_min / 700);
    70   freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;
    71 
    72   mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
    73   /* +2 for zeros at start and end */
    74   lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
    75   fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));
    76   height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));
    77 
    78   if(mel_peak == NULL || height_norm == NULL ||
    79       lin_peak == NULL || fft_peak == NULL)
    80     return NULL;
    81 
    82   M = fb->win_s >> 1;
    83 
    84   mel_peak[0] = mel_freq_min;
    85   lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
    86   fft_peak[0] = lin_peak[0] / nyquist * M;
    87 
    88   for (n = 1; n <= fb->n_filters; n++){ 
    89     /*roll out peak locations - mel, linear and linear on fft window scale */
    90     mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
    91     lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
    92     fft_peak[n] = lin_peak[n] / nyquist * M;
    93   }
    94 
    95   for (n = 0; n < fb->n_filters; n++){
    96     /*roll out normalised gain of each peak*/
    97     if (style == USE_EQUAL_GAIN){
    98       height = 1;
    99       norm_fact = norm;
    100     }
    101     else{
    102       height = 2 / (lin_peak[n + 2] - lin_peak[n]);
    103       norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
    104     }
    105     height_norm[n] = height * norm_fact;
    106   }
    107 
    108   i = 0;
    109 
    110   for(n = 0; n < fb->n_filters; n++){
    111 
    112     /*calculate the rise increment*/
    113     if(n > 0)
    114       inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
    115     else
    116       inc = height_norm[n] / fft_peak[n];
    117     val = 0; 
    118 
    119     /*zero the start of the array*/
    120     for(k = 0; k < i; k++)
    121       fb->filters[n]->data[0][k]=0.f;
    122 
    123     /*fill in the rise */
    124     for(; i <= fft_peak[n]; i++){
    125       fb->filters[n]->data[0][k]=val;
    126       val += inc;
    127     }
    128 
    129     /*calculate the fall increment */
    130     inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
    131 
    132     val = 0;
    133     next_peak = fft_peak[n + 1];
    134 
    135     /*reverse fill the 'fall' */
    136     for(i = next_peak; i > fft_peak[n]; i--){
    137       fb->filters[n]->data[0][k]=val;
    138       val += inc;
    139     }
    140 
    141     /*zero the rest of the array*/
    142     for(k = next_peak + 1; k < fb->win_s; k++)
    143       fb->filters[n]->data[0][k]=0.f;
    144 
    145 
    146   }
    147 
    148   free(mel_peak);
    149   free(lin_peak);
    150   free(height_norm);
    151   free(fft_peak);
    152 
    153 
    154   return fb;
    155 
    15652}
    15753
     
    16662*/
    16763
    168 aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){
     64aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){
    16965 
    17066  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
     
    18783  fvec_t * center_freqs=new_fvec( allFilters, 1);
    18884
    189  
    19085  fvec_t * triangle_heights=new_fvec( allFilters, 1);
    19186  //lookup table of each bin frequency in hz
     
    20297  //second step: filling all the log filter frequencies
    20398  for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
    204     freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1));
     99    freqs->data[0][filter_cnt+linearFilters] =
     100      lastlinearCF*(pow(logSpacing,filter_cnt+1));
    205101  }
    206102
     
    214110  }
    215111
    216 
    217112  //computing triangle heights so that each triangle has unit area
    218113  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
    219     triangle_heights->data[0][filter_cnt]=2./(upper_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
    220   }
    221  
    222  
    223   //AUBIO_DBG
    224   AUBIO_DBG("filter tables frequencies\n");
    225   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
    226     AUBIO_DBG("filter n. %d %f %f %f %f\n",filter_cnt, lower_freqs->data[0][filter_cnt], center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt], triangle_heights->data[0][filter_cnt]);
     114    triangle_heights->data[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt]
     115      - lower_freqs->data[0][filter_cnt]);
     116  }
     117 
     118  //AUBIO_DBG("filter tables frequencies\n");
     119  //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
     120  //  AUBIO_DBG("filter n. %d %f %f %f %f\n",
     121  //    filter_cnt, lower_freqs->data[0][filter_cnt],
     122  //    center_freqs->data[0][filter_cnt], upper_freqs->data[0][filter_cnt],
     123  //    triangle_heights->data[0][filter_cnt]);
    227124
    228125  //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
     
    239136    smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
    240137   
    241 
    242     AUBIO_DBG("\nfilter %d",filter_cnt);
    243138    //zeroing begining of filter
    244     AUBIO_DBG("\nzero begin\n");
    245139    for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
    246       //zeroing beigining of array
    247140      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
    248       AUBIO_DBG(".");
    249       //AUBIO_DBG("%f %f %f\n", fft_freqs->data[0][bin_cnt], fft_freqs->data[0][bin_cnt+1], lower_freqs->data[0][filter_cnt]);
    250       if(fft_freqs->data[0][bin_cnt]<= lower_freqs->data[0][filter_cnt] && fft_freqs->data[0][bin_cnt+1]> lower_freqs->data[0][filter_cnt]){
     141      if( fft_freqs->data[0][bin_cnt]  <= lower_freqs->data[0][filter_cnt] &&
     142          fft_freqs->data[0][bin_cnt+1] > lower_freqs->data[0][filter_cnt]) {
    251143        break;
    252144      }
     
    254146    bin_cnt++;
    255147   
    256     AUBIO_DBG("\npos slope\n");
    257148    //positive slope
    258149    for(; bin_cnt<win_s-1; bin_cnt++){
    259       AUBIO_DBG(".");
    260150      fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
    261151      //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])
     
    265155    //bin_cnt++;
    266156   
    267    
    268157    //negative slope
    269     AUBIO_DBG("\nneg slope\n");   
    270158    for(; bin_cnt<win_s-1; bin_cnt++){
    271       //AUBIO_DBG(".");
    272159     
    273160      //checking whether last value is less than 0...
     
    284171    //bin_cnt++;
    285172   
    286     AUBIO_DBG("\nzero end\n");
    287173    //zeroing tail
    288174    for(; bin_cnt<win_s; bin_cnt++)
    289       //AUBIO_DBG(".");
    290175      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
    291176
     
    293178 
    294179 
    295 
    296180  del_fvec(freqs);
    297181  del_fvec(lower_freqs);
  • src/filterbank.h

    raeb38cf raa83433  
    5656aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
    5757
    58 /** filterbank initialization for mel filters
    59 
    60   \param n_filters number of filters
    61   \param win_s window size
    62   \param samplerate
    63   \param freq_min lowest filter frequency
    64   \param freq_max highest filter frequency
    65 
    66 */
    67 aubio_filterbank_t * new_aubio_filterbank_mfcc_2(uint_t n_filters, uint_t win_s, uint_t samplerate, smpl_t freq_min, smpl_t freq_max);
    68 
    69 
    7058/** destroy filterbank object
    7159
     
    8068void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
    8169
    82 /** dump filterbank filter tables in a txt file
    83 
    84 */
    85 void aubio_dump_filterbank(aubio_filterbank_t * fb);
    86 
    8770#ifdef __cplusplus
    8871}
Note: See TracChangeset for help on using the changeset viewer.