Changes in / [e5f6a0b:45134c5]


Ignore:
Files:
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    re5f6a0b r45134c5  
    2323fvec_t * mfcc_out;
    2424aubio_mfcc_t * mfcc;
    25 
    26 uint_t n_filters = 40;
    27 uint_t n_coefs = 11;
    2825
    2926unsigned int pos = 0; /*frames%dspblocksize*/
     
    5350      //compute mfccs
    5451      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    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      
     52
    6253      /* end of block loop */
    6354      pos = -1; /* so it will be zero next j loop */
     
    7465      */
    7566     
    76       uint_t coef_cnt;
     67      uint_t filter_cnt;
    7768      if (output_filename == NULL) {
    78 //         if(frames >= 4) {
    79 //           outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate);
    80 //         }
    81 //         else if (frames < 4) {
    82 //           outmsg("%f\t",0.);
    83 //         }
    84         //outmsg("%f ",mfcc_out->data[0][0]);
    85        
    86        
     69        if(frames >= 4) {
     70          outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate);
     71        } else if (frames < 4) {
     72          outmsg("%f\t",0.);
     73        }
     74        outmsg("%f",mfcc_out->data[0][0]);
     75        for (filter_cnt = 1; filter_cnt < mfcc_out->length; filter_cnt++) {
     76          outmsg(",%f",mfcc_out->data[0][filter_cnt]);
     77        }
     78        outmsg("\n");
    8779      }
    8880}
     
    9082int main(int argc, char **argv) {
    9183  // params
    92  
     84  uint_t n_filters = 11;
    9385  examples_common_init(argc,argv);
    94   smpl_t lowfreq = 133.333f;
    95   smpl_t highfreq = 44100.f;
    96   mfcc_out = new_fvec(n_coefs,channels);
    97  
     86  smpl_t lowfreq = 0.;
     87  smpl_t highfreq = samplerate;
     88  mfcc_out = new_fvec(n_filters,channels);
    9889 
    9990  //populating the filter
    100   mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels);
    101   dump_filterbank(mfcc);
    102  
    103  
     91  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq,
     92      channels);
     93
    10494  //process
    10595  examples_common_process(aubio_process,process_print);
  • examples/utils.c

    re5f6a0b r45134c5  
    4040smpl_t threshold                      = 0.3;
    4141smpl_t silence                        = -90.;
    42 // uint_t buffer_size                    = 512;
    43 // uint_t overlap_size                   = 256;
    44 uint_t buffer_size                    = 1024;
    45 uint_t overlap_size                   = 512;
    46 // uint_t buffer_size                    = 2048;
    47 // uint_t overlap_size                   = 1024;
     42uint_t buffer_size                    = 512; //1024;
     43uint_t overlap_size                   = 256; //512;
    4844uint_t channels                       = 1;
    4945uint_t samplerate                     = 44100;
     
    6460int isonset = 0;
    6561aubio_pickpeak_t * parms;
     62
     63/* mfcc objects */
     64//parameters
     65uint_t n_filters=20;
     66smpl_t lowfreq=80.f;
     67smpl_t highfreq=18000.f;
     68// filterbank object
     69aubio_filterbank_t * mf;
     70
     71// DCT mfft and result storage
     72aubio_mfft_t * fft_dct;
     73cvec_t * fftgrain_dct;
     74smpl_t * mfcc_outbuf[11];
     75
    6676
    6777/* pitch objects */
     
    304314  fftgrain  = new_cvec(buffer_size, channels);
    305315
    306  
     316  //init for mfcc process
     317  fftgrain_dct= new_cvec(n_filters, channels);
     318
    307319  if (usepitch) {
    308320    pitchdet = new_aubio_pitchdetection(buffer_size*4,
     
    318330  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    319331 
     332  // dct phase vocoder
     333  //TODO: check size
     334  fft_dct = new_aubio_mfft(n_filters, channels);
     335
    320336  /* onsets */
    321337  parms = new_aubio_peakpicker(threshold);
     
    351367  del_fvec(onset);
    352368  del_fvec(woodblock);
     369 
     370  //mffc related
     371  del_aubio_mfft(fft_dct);
     372  del_cvec(fftgrain_dct);
    353373 
    354374  aubio_cleanup();
  • src/filterbank.c

    re5f6a0b r45134c5  
    1919*/
    2020
     21/* part of this mfcc implementation were inspired from LibXtract
     22   http://libxtract.sourceforge.net/
     23*/
    2124
    2225#include "aubio_priv.h"
    2326#include "sample.h"
    2427#include "filterbank.h"
    25 
    26 #include "stdio.h"
    2728
    2829#define USE_EQUAL_GAIN 1
     
    5253}
    5354
    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  
     55aubio_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){
    5656  smpl_t nyquist = samplerate/2.;
    5757  uint_t style = 1;
     
    142142    for(k = next_peak + 1; k < fb->win_s; k++)
    143143      fb->filters[n]->data[0][k]=0.f;
    144 
    145 
    146144  }
    147145
     
    151149  free(fft_peak);
    152150
    153 
    154151  return fb;
    155152
    156153}
    157154
    158 /*
    159 FB initialization based on Slaney's auditory toolbox
    160 TODO:
    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 
    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){
    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  
    190   fvec_t * triangle_heights=new_fvec( allFilters, 1);
    191   //lookup table of each bin frequency in hz
    192   fvec_t * fft_freqs=new_fvec(win_s, 1);
    193 
    194   uint_t filter_cnt, bin_cnt;
    195  
    196   //first step: filling all the linear filter frequencies
    197   for(filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){
    198     freqs->data[0][filter_cnt]=lowestFrequency+ filter_cnt*linearSpacing;
    199   }
    200   smpl_t lastlinearCF=freqs->data[0][filter_cnt-1];
    201  
    202   //second step: filling all the log filter frequencies
    203   for(filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){
    204     freqs->data[0][filter_cnt+linearFilters]=lastlinearCF*(pow(logSpacing,filter_cnt+1));
    205   }
    206 
    207   //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays
    208   //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step
    209    
    210   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
    211     lower_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt];
    212     center_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+1];
    213     upper_freqs->data[0][filter_cnt]=freqs->data[0][filter_cnt+2];
    214   }
    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  
    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]);
    227 
    228   //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin
    229   for(bin_cnt=0; bin_cnt<win_s; bin_cnt++){
    230     //TODO: check the formula!
    231     fft_freqs->data[0][bin_cnt]= (smpl_t)samplerate* (smpl_t)bin_cnt/ (smpl_t)win_s;
    232   }
    233 
    234   //building each filter table
    235   for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){
    236 
    237     //TODO:check special case : lower freq =0
    238     //calculating rise increment in mag/Hz
    239     smpl_t riseInc= triangle_heights->data[0][filter_cnt]/(center_freqs->data[0][filter_cnt]-lower_freqs->data[0][filter_cnt]);
    240    
    241 
    242     AUBIO_DBG("\nfilter %d",filter_cnt);
    243     //zeroing begining of filter
    244     AUBIO_DBG("\nzero begin\n");
    245     for(bin_cnt=0; bin_cnt<win_s-1; bin_cnt++){
    246       //zeroing beigining of array
    247       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]){
    251         break;
    252       }
    253     }
    254     bin_cnt++;
    255    
    256     AUBIO_DBG("\npos slope\n");
    257     //positive slope
    258     for(; bin_cnt<win_s-1; bin_cnt++){
    259       AUBIO_DBG(".");
    260       fb->filters[filter_cnt]->data[0][bin_cnt]=(fft_freqs->data[0][bin_cnt]-lower_freqs->data[0][filter_cnt])*riseInc;
    261       //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])
    262       if(fft_freqs->data[0][bin_cnt+1]> center_freqs->data[0][filter_cnt])
    263         break;
    264     }
    265     //bin_cnt++;
    266    
    267    
    268     //negative slope
    269     AUBIO_DBG("\nneg slope\n");   
    270     for(; bin_cnt<win_s-1; bin_cnt++){
    271       //AUBIO_DBG(".");
    272      
    273       //checking whether last value is less than 0...
    274       smpl_t val=triangle_heights->data[0][filter_cnt]-(fft_freqs->data[0][bin_cnt]-center_freqs->data[0][filter_cnt])*riseInc;
    275       if(val>=0)
    276         fb->filters[filter_cnt]->data[0][bin_cnt]=val;
    277       else fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
    278      
    279       //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])
    280       //TODO: CHECK whether bugfix correct
    281       if(fft_freqs->data[0][bin_cnt+1]> upper_freqs->data[0][filter_cnt])
    282         break;
    283     }
    284     //bin_cnt++;
    285    
    286     AUBIO_DBG("\nzero end\n");
    287     //zeroing tail
    288     for(; bin_cnt<win_s; bin_cnt++)
    289       //AUBIO_DBG(".");
    290       fb->filters[filter_cnt]->data[0][bin_cnt]=0.f;
    291 
    292   }
    293  
    294  
    295 
    296   del_fvec(freqs);
    297   del_fvec(lower_freqs);
    298   del_fvec(upper_freqs);
    299   del_fvec(center_freqs);
    300 
    301   del_fvec(triangle_heights);
    302   del_fvec(fft_freqs);
    303 
    304   return fb;
    305 
    306 }
    307 
    308 void aubio_dump_filterbank(aubio_filterbank_t * fb){
    309 
    310   FILE * mlog;
    311   mlog=fopen("filterbank.txt","w");
    312  
    313   int k,n;
    314   //dumping filter values
    315   //smpl_t area_tmp=0.f;
    316   for(n = 0; n < fb->n_filters; n++){
    317     for(k = 0; k < fb->win_s; k++){
    318       fprintf(mlog,"%f ",fb->filters[n]->data[0][k]);
    319     }
    320     fprintf(mlog,"\n");
    321   }
    322  
    323   if(mlog) fclose(mlog);
    324 }
    325155
    326156void del_aubio_filterbank(aubio_filterbank_t * fb){
  • src/filterbank.h

    re5f6a0b r45134c5  
    4646/** filterbank initialization for mel filters
    4747
    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
     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
    5452
    5553*/
    56 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);
    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 */
    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);
     54aubio_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);
    6855
    6956
     
    8067void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
    8168
    82 /** dump filterbank filter tables in a txt file
    83 
    84 */
    85 void aubio_dump_filterbank(aubio_filterbank_t * fb);
    86 
    8769#ifdef __cplusplus
    8870}
  • src/mfcc.c

    re5f6a0b r45134c5  
    3434  uint_t samplerate;        /** sample rate (needed?) */
    3535  uint_t channels;          /** number of channels */
    36   uint_t n_filters;         /** number of  *filters */
    37   uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
     36  uint_t n_coefs;           /** number of coefficients (= fb->n_filters/2 +1) */
    3837  smpl_t lowfreq;           /** lowest frequency for filters */
    3938  smpl_t highfreq;          /** highest frequency for filters */
     
    4544
    4645
    47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
     46aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
    4847  /** allocating space for mfcc object */
    4948  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
    5049
    5150  //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
    52   //uint_t n_filters = (n_coefs-1)*2;
     51  uint_t n_filters = (n_coefs-1)*2;
    5352 
    5453  mfcc->win_s=win_s;
    5554  mfcc->samplerate=samplerate;
    5655  mfcc->channels=channels;
    57   mfcc->n_filters=n_filters;
    5856  mfcc->n_coefs=n_coefs;
    5957  mfcc->lowfreq=lowfreq;
    6058  mfcc->highfreq=highfreq;
    6159
    62  
    6360  /** filterbank allocation */
    64   mfcc->fb = new_aubio_filterbank_mfcc2(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
     61  mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
    6562
    6663  /** allocating space for fft object (used for dct) */
     
    105102    aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
    106103    //extract real part of fft grain
    107     for(i=0; i<mf->n_coefs ;i++){
    108     //for(i=0; i<out->length;i++){
     104    //for(i=0; i<mf->n_coefs ;i++){
     105    for(i=0; i<out->length;i++){
    109106      out->data[0][i]= mf->fftgrain_dct->norm[0][i]
    110107        *COS(mf->fftgrain_dct->phas[0][i]);
     
    113110}
    114111
    115 //a bit a kludge
    116 void dump_filterbank(aubio_mfcc_t * mf){
    117   aubio_dump_filterbank(mf->fb);
    118 
    119 }
    120 
  • src/mfcc.h

    re5f6a0b r45134c5  
    4545
    4646*/
    47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
     47aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
    4848/** delete mfcc object
    4949
     
    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 */
    77 void dump_filterbank(aubio_mfcc_t * mf);
    78 
    7972#ifdef __cplusplus
    8073}
  • src/sample.c

    re5f6a0b r45134c5  
    2020#include "aubio_priv.h"
    2121#include "sample.h"
    22 
    2322
    2423fvec_t * new_fvec( uint_t length, uint_t channels) {
  • swig/aubio.i

    re5f6a0b r45134c5  
    148148smpl_t aubio_zero_crossing_rate(fvec_t * input);
    149149smpl_t aubio_spectral_centroid(cvec_t * spectrum, smpl_t samplerate);
    150 
    151 /* filterbank */
    152 
    153 /* mfcc */
    154 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
    155 void del_aubio_mfcc(aubio_mfcc_t *mf);
    156 void aubio_mfcc_do(aubio_mfcc_t *mf, cvec_t *in, fvec_t *out);
    157 
    158150
    159151/* scale */
Note: See TracChangeset for help on using the changeset viewer.