- Timestamp:
- Sep 17, 2009, 7:31:54 PM (15 years ago)
- 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
- Location:
- src/spectral
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/mfcc.c
r14a299e rc185ebb 33 33 uint_t win_s; /** grain length */ 34 34 uint_t samplerate; /** sample rate (needed?) */ 35 uint_t channels; /** number of channels */36 35 uint_t n_filters; /** number of *filters */ 37 36 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 */40 37 aubio_filterbank_t * fb; /** filter bank */ 41 38 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 */ 44 40 }; 45 41 46 42 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){ 43 aubio_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 48 47 /** allocating space for mfcc object */ 49 48 aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t); … … 54 53 mfcc->win_s=win_s; 55 54 mfcc->samplerate=samplerate; 56 mfcc->channels=channels;57 55 mfcc->n_filters=n_filters; 58 56 mfcc->n_coefs=n_coefs; 59 mfcc->lowfreq=lowfreq;60 mfcc->highfreq=highfreq;61 57 62 58 … … 65 61 aubio_filterbank_set_mel_coeffs_slaney(mfcc->fb, samplerate); 66 62 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); 69 67 70 /** allocating buffers */71 mfcc->in_dct=new_fvec(mfcc->win_s, 1);72 68 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 } 74 80 75 81 return mfcc; … … 79 85 /** deleting filterbank */ 80 86 del_aubio_filterbank(mf->fb); 81 /** deleting fft object */82 del_aubio_fft(mf->fft_dct);83 87 /** deleting buffers */ 84 88 del_fvec(mf->in_dct); 85 del_cvec(mf->fftgrain_dct);86 89 87 90 /** deleting mfcc object */ … … 90 93 91 94 92 /** intermediate dct involved in aubio_mfcc_do 95 void 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); 93 99 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 } 97 107 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; 111 109 } 112 113 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){114 uint_t i;115 //compute mag spectrum116 aubio_fft_do (mf->fft_dct, in, mf->fftgrain_dct);117 //extract real part of fft grain118 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 37 37 \param samplerate 38 38 \param n_coefs: number of desired coefs 39 \param lowfreq: lowest frequency to use in filterbank40 \param highfreq highest frequency to use in filterbank41 \param channels number of channels42 39 43 40 */ 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);41 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs); 45 42 /** delete mfcc object 46 43
Note: See TracChangeset
for help on using the changeset viewer.