Changeset 787f1f3 for src


Ignore:
Timestamp:
Sep 12, 2007, 5:55:48 PM (17 years ago)
Author:
Amaury Hazan <mahmoudax@gmail.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:
95a64c7
Parents:
7a46bf6 (diff), 83d5abf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merged from laptop, change debug to AUBIO_DBG in filterbank.c

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/filterbank.c

    r7a46bf6 r787f1f3  
    1919*/
    2020
    21 /* part of this mfcc implementation were inspired from LibXtract
    22    http://libxtract.sourceforge.net/
    23 */
    2421
    2522#include "aubio_priv.h"
     
    5552}
    5653
    57 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max){
    58  
    59   uint_t writelog=1;
    60 
    61   FILE * mlog;
    62   if(writelog==1) mlog=fopen("filterbank.txt","w");
    63  
    64 
     54aubio_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 
    6556  smpl_t nyquist = samplerate/2.;
    6657  uint_t style = 1;
     
    152143      fb->filters[n]->data[0][k]=0.f;
    153144
    154     if(writelog){
    155       //dumping filter values
    156       smpl_t area_tmp=0.f;
    157       for(k = 0; k < fb->win_s; k++){
    158         fprintf(mlog,"%f ",fb->filters[n]->data[0][k]);
    159       }
    160       fprintf(mlog,"\n");
    161     }
    162145
    163146  }
     
    168151  free(fft_peak);
    169152
     153
     154  return fb;
     155
     156}
     157
     158/*
     159FB initialization based on Slaney's auditory toolbox
     160TODO:
     161  *solve memory leak problems while
     162  *solve quantization issues when constructing signal:
     163    *bug for win_s=512
     164    *corrections for win_s=1024 -> why even filters with smaller amplitude
     165
     166*/
     167
     168aubio_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){
     169 
     170  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
     171 
     172 
     173  //slaney params
     174  smpl_t lowestFrequency = 133.3333;
     175  smpl_t linearSpacing = 66.66666666;
     176  smpl_t logSpacing = 1.0711703;
     177
     178  uint_t linearFilters = 13;
     179  uint_t logFilters = 27;
     180  uint_t allFilters = linearFilters + logFilters;
     181 
     182  //buffers for computing filter frequencies
     183  fvec_t * freqs=new_fvec( allFilters +2 , 1);
     184 
     185  fvec_t * lower_freqs=new_fvec( allFilters, 1);
     186  fvec_t * upper_freqs=new_fvec( allFilters, 1);
     187  fvec_t * center_freqs=new_fvec( allFilters, 1);
     188     
     189  /*fvec_t * lower_freqs=freqs;
     190  fvec_t * upper_freqs=freqs;
     191  fvec_t * center_freqs=freqs*/;
     192 
     193  fvec_t * triangle_heights=new_fvec( allFilters, 1);
     194  //lookup table of each bin frequency in hz
     195  fvec_t * fft_freqs=new_fvec(win_s, 1);
     196
     197  uint_t filter_cnt, bin_cnt;
     198 
     199  //first: filling all the linear filter frequencies
     200  for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){
     201    freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing;
     202  }
     203  smpl_t lastlinearCF=freqs->data[0][filter_cnt-1];
     204 
     205  //second: filling all the log filter frequencies
     206  for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
     207    freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1));
     208  }
     209 
     210 
     211  //make fvec->data point directly to freqs arrays
     212  lower_freqs->data=freqs->data;
     213  center_freqs->data[0]=&(freqs->data[0][1]);
     214  upper_freqs->data[0]=&(freqs->data[0][2]);
     215
     216 
     217  //computing triangle heights so that each triangle has unit area
     218  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  //AUBIO_DBG
     223  AUBIO_DBG("filter tables frequencies\n");
     224  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++)
     225    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]);
     226 
     227 
     228  //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
     229 
     230  for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){
     231   
     232    //TODO: check the formula!
     233   
     234    fft_freqs->data[0][bin_cnt]= (smpl_t)samplerate* (smpl_t)bin_cnt/ (smpl_t)win_s;
     235
     236  }
     237 
     238 
     239  //building each filter table
     240  for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
     241
     242    //TODO:check special case : lower freq =0
     243   
     244    //calculating rise increment in mag/Hz
     245    smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
     246   
     247    //zeroing begining of filter
     248    AUBIO_DBG("\nfilter %d",filter_cnt);
     249
     250    AUBIO_DBG("\nzero begin\n");
     251   
     252    for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
     253      //zeroing beigining of array
     254      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
     255      AUBIO_DBG(".");
     256      //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]);
     257      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]){
     258        break;
     259      }
     260    }
     261    bin_cnt++;
     262   
     263    AUBIO_DBG("\npos slope\n");
     264    //positive slope
     265    for(; bin_cnt<win_s-1; bin_cnt++){
     266      AUBIO_DBG(".");
     267      fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
     268      //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])
     269      if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
     270        break;
     271    }
     272    //bin_cnt++;
     273   
     274   
     275    //negative slope
     276    AUBIO_DBG("\nneg slope\n");   
     277    for(; bin_cnt<win_s-1; bin_cnt++){
     278      //AUBIO_DBG(".");
     279     
     280      //checking whether last value is less than 0...
     281      smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc;
     282      if(val>=0)
     283        fb->filters[filter_cnt]->data[0][bin_cnt]=val;
     284      else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
     285     
     286      //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])
     287      //TODO: CHECK whether bugfix correct
     288      if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
     289        break;
     290    }
     291    //bin_cnt++;
     292   
     293    AUBIO_DBG("\nzero end\n");
     294    //zeroing tail
     295    for(; bin_cnt<win_s; bin_cnt++)
     296      //AUBIO_DBG(".");
     297      fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
     298
     299  }
     300 
     301 
     302  del_fvec(freqs);
     303  //TODO: Check how to do a proper free for the following f_vec
     304
     305  //del_fvec(lower_freqs);
     306  //del_fvec(upper_freqs);
     307  //del_fvec(center_freqs);
     308  del_fvec(triangle_heights);
     309  del_fvec(fft_freqs);
     310
     311 
     312
     313  return fb;
     314
     315}
     316
     317void aubio_dump_filterbank(aubio_filterbank_t * fb){
     318
     319  FILE * mlog;
     320  mlog=fopen("filterbank.txt","w");
     321 
     322  int k,n;
     323  //dumping filter values
     324  //smpl_t area_tmp=0.f;
     325  for(n = 0; n < fb->n_filters; n++){
     326    for(k = 0; k < fb->win_s; k++){
     327      fprintf(mlog,"%f ",fb->filters[n]->data[0][k]);
     328    }
     329    fprintf(mlog,"\n");
     330  }
     331 
    170332  if(mlog) fclose(mlog);
    171 
    172   return fb;
    173 
    174 }
    175 
     333}
    176334
    177335void del_aubio_filterbank(aubio_filterbank_t * fb){
  • src/filterbank.h

    r7a46bf6 r787f1f3  
    4646/** filterbank initialization for mel filters
    4747
    48   \param nyquist nyquist frequency, i.e. half of the sampling rate
    49   \param style libxtract style
    50   \param freqmin lowest filter frequency
    51   \param freqmax highest filter frequency
     48 
     49  \param n_filters number of filters
     50  \param win_s window size
     51  \param samplerate
     52  \param freq_min lowest filter frequency
     53  \param freq_max highest filter frequency
    5254
    5355*/
    54 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
     56aubio_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);
     57
     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*/
     67aubio_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);
    5568
    5669
     
    6780void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
    6881
     82/** dump filterbank filter tables in a txt file
     83
     84*/
     85void aubio_dump_filterbank(aubio_filterbank_t * fb);
     86
    6987#ifdef __cplusplus
    7088}
  • src/mfcc.c

    r7a46bf6 r787f1f3  
    6060  mfcc->highfreq=highfreq;
    6161
     62 
    6263  /** filterbank allocation */
    63   mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
     64  mfcc->fb = new_aubio_filterbank_mfcc2(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
    6465
    6566  /** allocating space for fft object (used for dct) */
     
    112113}
    113114
     115//a bit a kludge
     116void dump_filterbank(aubio_mfcc_t * mf){
     117  aubio_dump_filterbank(mf->fb);
     118
     119}
     120
  • src/mfcc.h

    r7a46bf6 r787f1f3  
    7070void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
    7171
     72/** dump filterbank to log file
     73
     74  \param mf mfcc object as returned by new_aubio_mfcc
     75 
     76*/
     77void dump_filterbank(aubio_mfcc_t * mf);
     78
    7279#ifdef __cplusplus
    7380}
Note: See TracChangeset for help on using the changeset viewer.