Changeset 787f1f3


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

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    r7a46bf6 r787f1f3  
    2424aubio_mfcc_t * mfcc;
    2525
    26 uint_t n_filters = 20;
     26uint_t n_filters = 40;
    2727uint_t n_coefs = 11;
    2828
     
    5353      //compute mfccs
    5454      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    55 
     55     
     56      uint_t coef_cnt;
     57      for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
     58          outmsg("%f ",mfcc_out->data[0][coef_cnt]);
     59      }
     60      outmsg("\n");
     61     
    5662      /* end of block loop */
    5763      pos = -1; /* so it will be zero next j loop */
     
    7884        //outmsg("%f ",mfcc_out->data[0][0]);
    7985       
    80         /*for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
    81           outmsg("%f ",mfcc_out->data[0][coef_cnt]);
    82         }
    83         outmsg("\n");/*/
     86       
    8487      }
    8588}
     
    8790int main(int argc, char **argv) {
    8891  // params
    89   //uint_t n_filters = 40;
    90   //uint_t n_coefs = 15;
    91 
     92 
    9293  examples_common_init(argc,argv);
    9394  smpl_t lowfreq = 133.333f;
     
    9596  mfcc_out = new_fvec(n_coefs,channels);
    9697 
     98 
    9799  //populating the filter
    98100  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels);
    99 
     101  dump_filterbank(mfcc);
     102 
     103 
    100104  //process
    101105  examples_common_process(aubio_process,process_print);
  • examples/plotfb.py

    r7a46bf6 r787f1f3  
    55import sys
    66
     7
    78filename=sys.argv[1]
     9
     10doLog=False
     11if len(sys.argv)>2:
     12  if sys.argv[2]=='log':
     13    doLog=True
    814
    915mat = pylab.load(filename)
     
    1521n_filters=numpy.shape(nmat)[0]
    1622for i in range(n_filters):
    17   pylab.plot(nmat[i,:])
     23  if doLog==True:
     24    pylab.semilogx(nmat[i,:])
     25  else:
     26    pylab.plot(nmat[i,:])
    1827
    1928
  • examples/utils.c

    r7a46bf6 r787f1f3  
    4040smpl_t threshold                      = 0.3;
    4141smpl_t silence                        = -90.;
    42 uint_t buffer_size                    = 512; //1024;
    43 uint_t overlap_size                   = 256; //512;
     42// uint_t buffer_size                    = 512;
     43// uint_t overlap_size                   = 256;
     44uint_t buffer_size                    = 1024;
     45uint_t overlap_size                   = 512;
    4446uint_t channels                       = 1;
    4547uint_t samplerate                     = 44100;
  • 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.