filterbank.{c,h}: remove old new_aubio_filterbank_mfcc, replace with new one, remove...
authorPaul Brossier <piem@piem.org>
Sun, 16 Sep 2007 19:55:42 +0000 (21:55 +0200)
committerPaul Brossier <piem@piem.org>
Sun, 16 Sep 2007 19:55:42 +0000 (21:55 +0200)
src/filterbank.c
src/filterbank.h

index d79bb1540b3541c229a8743d14b9e8109d210c79..e34bef074750b7edec9bfe0ed8f97e376129722c 100644 (file)
@@ -51,110 +51,6 @@ aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s){
   return fb;
 }
 
-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){
-  
-  smpl_t nyquist = samplerate/2.;
-  uint_t style = 1;
-  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
-
-  uint_t n, i, k, *fft_peak, M, next_peak; 
-  smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, 
-         freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
-
-  mel_peak = height_norm = lin_peak = NULL;
-  fft_peak = NULL;
-  norm = 1; 
-
-  mel_freq_max = 1127 * log(1 + freq_max / 700);
-  mel_freq_min = 1127 * log(1 + freq_min / 700);
-  freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;
-
-  mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t)); 
-  /* +2 for zeros at start and end */
-  lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
-  fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));
-  height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));
-
-  if(mel_peak == NULL || height_norm == NULL || 
-      lin_peak == NULL || fft_peak == NULL)
-    return NULL;
-
-  M = fb->win_s >> 1;
-
-  mel_peak[0] = mel_freq_min;
-  lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
-  fft_peak[0] = lin_peak[0] / nyquist * M;
-
-  for (n = 1; n <= fb->n_filters; n++){  
-    /*roll out peak locations - mel, linear and linear on fft window scale */
-    mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
-    lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
-    fft_peak[n] = lin_peak[n] / nyquist * M;
-  }
-
-  for (n = 0; n < fb->n_filters; n++){
-    /*roll out normalised gain of each peak*/
-    if (style == USE_EQUAL_GAIN){
-      height = 1; 
-      norm_fact = norm;
-    }
-    else{
-      height = 2 / (lin_peak[n + 2] - lin_peak[n]);
-      norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
-    }
-    height_norm[n] = height * norm_fact;
-  }
-
-  i = 0;
-
-  for(n = 0; n < fb->n_filters; n++){
-
-    /*calculate the rise increment*/
-    if(n > 0)
-      inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
-    else
-      inc = height_norm[n] / fft_peak[n];
-    val = 0;  
-
-    /*zero the start of the array*/
-    for(k = 0; k < i; k++)
-      fb->filters[n]->data[0][k]=0.f;
-
-    /*fill in the rise */
-    for(; i <= fft_peak[n]; i++){ 
-      fb->filters[n]->data[0][k]=val;
-      val += inc;
-    }
-
-    /*calculate the fall increment */
-    inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
-
-    val = 0;
-    next_peak = fft_peak[n + 1];
-
-    /*reverse fill the 'fall' */
-    for(i = next_peak; i > fft_peak[n]; i--){ 
-      fb->filters[n]->data[0][k]=val;
-      val += inc;
-    }
-
-    /*zero the rest of the array*/
-    for(k = next_peak + 1; k < fb->win_s; k++)
-      fb->filters[n]->data[0][k]=0.f;
-
-
-  }
-
-  free(mel_peak);
-  free(lin_peak);
-  free(height_norm);
-  free(fft_peak);
-
-
-  return fb;
-
-}
-
 /*
 FB initialization based on Slaney's auditory toolbox
 TODO:
@@ -165,7 +61,7 @@ TODO:
 
 */
 
-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){
+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){
   
   aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
   
@@ -186,7 +82,6 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
   fvec_t * upper_freqs=new_fvec( allFilters, 1);
   fvec_t * center_freqs=new_fvec( allFilters, 1);
 
-  
   fvec_t * triangle_heights=new_fvec( allFilters, 1);
   //lookup table of each bin frequency in hz
   fvec_t * fft_freqs=new_fvec(win_s, 1);
@@ -201,7 +96,8 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
   
   //second step: filling all the log filter frequencies
   for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
-    freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1));
+    freqs->data[0][filter_cnt+linearFilters] = 
+      lastlinearCF*(pow(logSpacing,filter_cnt+1));
   }
 
   //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays
@@ -213,17 +109,18 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
     upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2];
   }
 
-
   //computing triangle heights so that each triangle has unit area
   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
-    triangle_heights->data[0][filter_cnt]=2./(upper_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
+    triangle_heights->data[0][filter_cnt] = 2./(upper_freqs->data[0][filter_cnt] 
+      - lower_freqs->data[0][filter_cnt]);
   }
   
-  
-  //AUBIO_DBG
-  AUBIO_DBG("filter tables frequencies\n");
-  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
-    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]);
+  //AUBIO_DBG("filter tables frequencies\n");
+  //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
+  //  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]);
 
   //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
   for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){
@@ -238,25 +135,18 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
     //calculating rise increment in mag/Hz
     smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
     
-
-    AUBIO_DBG("\nfilter %d",filter_cnt);
     //zeroing begining of filter
-    AUBIO_DBG("\nzero begin\n");
     for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
-      //zeroing beigining of array
       fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
-      AUBIO_DBG(".");
-      //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]); 
-      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]){
+      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]) {
         break;
       }
     }
     bin_cnt++;
     
-    AUBIO_DBG("\npos slope\n");
     //positive slope
     for(; bin_cnt<win_s-1; bin_cnt++){
-      AUBIO_DBG(".");
       fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
       //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])
       if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
@@ -264,11 +154,8 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
     }
     //bin_cnt++;
     
-    
     //negative slope
-    AUBIO_DBG("\nneg slope\n");   
     for(; bin_cnt<win_s-1; bin_cnt++){
-      //AUBIO_DBG(".");
       
       //checking whether last value is less than 0...
       smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc;
@@ -283,16 +170,13 @@ aubio_filterbank_t * new_aubio_filterbank_mfcc2(uint_t n_filters, uint_t win_s,
     }
     //bin_cnt++;
     
-    AUBIO_DBG("\nzero end\n");
     //zeroing tail
     for(; bin_cnt<win_s; bin_cnt++)
-      //AUBIO_DBG(".");
       fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
 
   }
   
   
-
   del_fvec(freqs);
   del_fvec(lower_freqs);
   del_fvec(upper_freqs);
index 44db510609e1bd001f3780ad2e0fc6cc42c4ac9c..5b64a5b62875cd952b8a8989a434331ae38cb94a 100644 (file)
@@ -55,18 +55,6 @@ aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s);
 */
 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);
 
-/** filterbank initialization for mel filters
-
-  \param n_filters number of filters
-  \param win_s window size
-  \param samplerate
-  \param freq_min lowest filter frequency
-  \param freq_max highest filter frequency
-
-*/
-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);
-
-
 /** destroy filterbank object
 
   \param fb filterbank, as returned by new_aubio_filterbank method
@@ -79,11 +67,6 @@ void del_aubio_filterbank(aubio_filterbank_t * fb);
 */
 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
 
-/** dump filterbank filter tables in a txt file
-
-*/
-void aubio_dump_filterbank(aubio_filterbank_t * fb);
-
 #ifdef __cplusplus
 }
 #endif