Changeset c185ebb for src


Ignore:
Timestamp:
Sep 17, 2009, 7:31:54 PM (15 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:
7a84b21
Parents:
14a299e
Message:

mfcc.c: use a coefficient table for DCT computation, remove unused parameters

Location:
src/spectral
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/mfcc.c

    r14a299e rc185ebb  
    3333  uint_t win_s;             /** grain length */
    3434  uint_t samplerate;        /** sample rate (needed?) */
    35   uint_t channels;          /** number of channels */
    3635  uint_t n_filters;         /** number of  *filters */
    3736  uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
    38   smpl_t lowfreq;           /** lowest frequency for filters */
    39   smpl_t highfreq;          /** highest frequency for filters */
    4037  aubio_filterbank_t * fb;  /** filter bank */
    4138  fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
    42   aubio_fft_t * fft_dct;   /** fft object for dct */
    43   cvec_t * fftgrain_dct;    /** output buffer for dct */
     39  fvec_t * dct_coeffs;      /** DCT transform n_filters * n_coeffs */
    4440};
    4541
    4642
    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){
     43aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs){
     44
     45  uint_t i, j;
     46
    4847  /** allocating space for mfcc object */
    4948  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
     
    5453  mfcc->win_s=win_s;
    5554  mfcc->samplerate=samplerate;
    56   mfcc->channels=channels;
    5755  mfcc->n_filters=n_filters;
    5856  mfcc->n_coefs=n_coefs;
    59   mfcc->lowfreq=lowfreq;
    60   mfcc->highfreq=highfreq;
    6157
    6258 
     
    6561  aubio_filterbank_set_mel_coeffs_slaney(mfcc->fb, samplerate);
    6662
    67   /** allocating space for fft object (used for dct) */
    68   mfcc->fft_dct=new_aubio_fft(n_filters, 1);
     63  /** allocating buffers */
     64  mfcc->in_dct=new_fvec(n_filters, 1);
     65 
     66  mfcc->dct_coeffs = new_fvec(n_coefs, n_filters);
    6967
    70   /** allocating buffers */
    71   mfcc->in_dct=new_fvec(mfcc->win_s, 1);
    7268 
    73   mfcc->fftgrain_dct=new_cvec(n_filters, 1);
     69  /* compute DCT transform dct_coeffs[i][j] as
     70    cos ( j * (i+.5) * PI / n_filters )
     71  */
     72  smpl_t scaling = 1./SQRT(n_filters/2.);
     73  for (i = 0; i < n_filters; i++) {
     74    for (j = 0; j < n_coefs; j++) {
     75      mfcc->dct_coeffs->data[i][j] =
     76        scaling * COS (j * (i + 0.5) * PI / n_filters);
     77    }
     78    mfcc->dct_coeffs->data[i][0] *= SQRT(2.)/2.;
     79  }
    7480
    7581  return mfcc;
     
    7985  /** deleting filterbank */
    8086  del_aubio_filterbank(mf->fb);
    81   /** deleting fft object */
    82   del_aubio_fft(mf->fft_dct);
    8387  /** deleting buffers */
    8488  del_fvec(mf->in_dct);
    85   del_cvec(mf->fftgrain_dct);
    8689 
    8790  /** deleting mfcc object */
     
    9093
    9194
    92 /** intermediate dct involved in aubio_mfcc_do
     95void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
     96  uint_t i, j;
     97  // compute filterbank
     98  aubio_filterbank_do(mf->fb, in, mf->in_dct);
    9399
    94   \param mf mfcc object as returned by new_aubio_mfcc
    95   \param in input spectrum (n_filters long)
    96   \param out output mel coefficients buffer (n_filters/2 +1 long)
     100  //extract real part of fft grain
     101  for (i = 0; i < mf->n_filters; i++) {
     102    for (j = 0; j < mf->n_coefs; j++) {
     103      out->data[0][j] += mf->in_dct->data[0][i]
     104        * mf->dct_coeffs->data[i][j];
     105    }
     106  }
    97107
    98 */
    99 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
    100 
    101 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
    102     // compute filterbank
    103     aubio_filterbank_do(mf->fb, in, mf->in_dct);
    104     //TODO: check that zero padding
    105     // the following line seems useless since the in_dct buffer has the correct size
    106     //for(n = filter + 1; n < N; n++) result[n] = 0;
    107    
    108     aubio_dct_do(mf, mf->in_dct, out);
    109 
    110     return;
     108  return;
    111109}
    112 
    113 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){
    114     uint_t i;
    115     //compute mag spectrum
    116     aubio_fft_do (mf->fft_dct, in, mf->fftgrain_dct);
    117     //extract real part of fft grain
    118     for(i=0; i<mf->n_coefs ;i++){
    119     //for(i=0; i<out->length;i++){
    120       out->data[0][i]= mf->fftgrain_dct->norm[0][i]
    121         *COS(mf->fftgrain_dct->phas[0][i]);
    122     }
    123     return;
    124 }
    125 
  • src/spectral/mfcc.h

    r14a299e rc185ebb  
    3737  \param samplerate
    3838  \param n_coefs: number of desired coefs
    39   \param lowfreq: lowest frequency to use in filterbank
    40   \param highfreq highest frequency to use in filterbank
    41   \param channels number of channels
    4239
    4340*/
    44 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);
     41aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs);
    4542/** delete mfcc object
    4643
Note: See TracChangeset for help on using the changeset viewer.