Changeset e5f6a0b


Ignore:
Timestamp:
Sep 16, 2007, 6:06:07 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:
177f09a
Parents:
45134c5 (diff), bc4ba75 (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:

merge from amaury's branch

Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    r45134c5 re5f6a0b  
    2323fvec_t * mfcc_out;
    2424aubio_mfcc_t * mfcc;
     25
     26uint_t n_filters = 40;
     27uint_t n_coefs = 11;
    2528
    2629unsigned int pos = 0; /*frames%dspblocksize*/
     
    5053      //compute mfccs
    5154      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    52 
     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     
    5362      /* end of block loop */
    5463      pos = -1; /* so it will be zero next j loop */
     
    6574      */
    6675     
    67       uint_t filter_cnt;
     76      uint_t coef_cnt;
    6877      if (output_filename == NULL) {
    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");
     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       
    7987      }
    8088}
     
    8290int main(int argc, char **argv) {
    8391  // params
    84   uint_t n_filters = 11;
     92 
    8593  examples_common_init(argc,argv);
    86   smpl_t lowfreq = 0.;
    87   smpl_t highfreq = samplerate;
    88   mfcc_out = new_fvec(n_filters,channels);
     94  smpl_t lowfreq = 133.333f;
     95  smpl_t highfreq = 44100.f;
     96  mfcc_out = new_fvec(n_coefs,channels);
     97 
    8998 
    9099  //populating the filter
    91   mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq,
    92       channels);
    93 
     100  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels);
     101  dump_filterbank(mfcc);
     102 
     103 
    94104  //process
    95105  examples_common_process(aubio_process,process_print);
  • examples/utils.c

    r45134c5 re5f6a0b  
    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;
     46// uint_t buffer_size                    = 2048;
     47// uint_t overlap_size                   = 1024;
    4448uint_t channels                       = 1;
    4549uint_t samplerate                     = 44100;
     
    6064int isonset = 0;
    6165aubio_pickpeak_t * parms;
    62 
    63 /* mfcc objects */
    64 //parameters
    65 uint_t n_filters=20;
    66 smpl_t lowfreq=80.f;
    67 smpl_t highfreq=18000.f;
    68 // filterbank object
    69 aubio_filterbank_t * mf;
    70 
    71 // DCT mfft and result storage
    72 aubio_mfft_t * fft_dct;
    73 cvec_t * fftgrain_dct;
    74 smpl_t * mfcc_outbuf[11];
    75 
    7666
    7767/* pitch objects */
     
    314304  fftgrain  = new_cvec(buffer_size, channels);
    315305
    316   //init for mfcc process
    317   fftgrain_dct= new_cvec(n_filters, channels);
    318 
     306 
    319307  if (usepitch) {
    320308    pitchdet = new_aubio_pitchdetection(buffer_size*4,
     
    330318  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    331319 
    332   // dct phase vocoder
    333   //TODO: check size
    334   fft_dct = new_aubio_mfft(n_filters, channels);
    335 
    336320  /* onsets */
    337321  parms = new_aubio_peakpicker(threshold);
     
    367351  del_fvec(onset);
    368352  del_fvec(woodblock);
    369  
    370   //mffc related
    371   del_aubio_mfft(fft_dct);
    372   del_cvec(fftgrain_dct);
    373353 
    374354  aubio_cleanup();
  • src/filterbank.c

    r45134c5 re5f6a0b  
    1919*/
    2020
    21 /* part of this mfcc implementation were inspired from LibXtract
    22    http://libxtract.sourceforge.net/
    23 */
    2421
    2522#include "aubio_priv.h"
    2623#include "sample.h"
    2724#include "filterbank.h"
     25
     26#include "stdio.h"
    2827
    2928#define USE_EQUAL_GAIN 1
     
    5352}
    5453
    55 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){
     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 
    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
    144146  }
    145147
     
    149151  free(fft_peak);
    150152
     153
    151154  return fb;
    152155
    153156}
    154157
     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 
     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
     308void 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}
    155325
    156326void del_aubio_filterbank(aubio_filterbank_t * fb){
  • src/filterbank.h

    r45134c5 re5f6a0b  
    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

    r45134c5 re5f6a0b  
    3434  uint_t samplerate;        /** sample rate (needed?) */
    3535  uint_t channels;          /** number of channels */
    36   uint_t n_coefs;           /** number of coefficients (= fb->n_filters/2 +1) */
     36  uint_t n_filters;         /** number of  *filters */
     37  uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
    3738  smpl_t lowfreq;           /** lowest frequency for filters */
    3839  smpl_t highfreq;          /** highest frequency for filters */
     
    4445
    4546
    46 aubio_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){
     47aubio_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){
    4748  /** allocating space for mfcc object */
    4849  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
    4950
    5051  //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
    51   uint_t n_filters = (n_coefs-1)*2;
     52  //uint_t n_filters = (n_coefs-1)*2;
    5253 
    5354  mfcc->win_s=win_s;
    5455  mfcc->samplerate=samplerate;
    5556  mfcc->channels=channels;
     57  mfcc->n_filters=n_filters;
    5658  mfcc->n_coefs=n_coefs;
    5759  mfcc->lowfreq=lowfreq;
    5860  mfcc->highfreq=highfreq;
    5961
     62 
    6063  /** filterbank allocation */
    61   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);
    6265
    6366  /** allocating space for fft object (used for dct) */
     
    102105    aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
    103106    //extract real part of fft grain
    104     //for(i=0; i<mf->n_coefs ;i++){
    105     for(i=0; i<out->length;i++){
     107    for(i=0; i<mf->n_coefs ;i++){
     108    //for(i=0; i<out->length;i++){
    106109      out->data[0][i]= mf->fftgrain_dct->norm[0][i]
    107110        *COS(mf->fftgrain_dct->phas[0][i]);
     
    110113}
    111114
     115//a bit a kludge
     116void dump_filterbank(aubio_mfcc_t * mf){
     117  aubio_dump_filterbank(mf->fb);
     118
     119}
     120
  • src/mfcc.h

    r45134c5 re5f6a0b  
    4545
    4646*/
    47 aubio_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);
     47aubio_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);
    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*/
     77void dump_filterbank(aubio_mfcc_t * mf);
     78
    7279#ifdef __cplusplus
    7380}
  • src/sample.c

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

    r45134c5 re5f6a0b  
    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 */
     154aubio_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);
     155void del_aubio_mfcc(aubio_mfcc_t *mf);
     156void aubio_mfcc_do(aubio_mfcc_t *mf, cvec_t *in, fvec_t *out);
     157
    150158
    151159/* scale */
Note: See TracChangeset for help on using the changeset viewer.