Changeset 8708556 for src/mfcc.c
- Timestamp:
- Sep 7, 2007, 3:47:55 PM (17 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:
- 21bd43c
- Parents:
- fdf39ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mfcc.c
rfdf39ba r8708556 24 24 #include "sample.h" 25 25 #include "fft.h" 26 #include "filterbank.h" 26 27 #include "mfcc.h" 27 28 #include "math.h" 28 29 29 /* 30 new_aubio_mfcc 31 aubio_mfcc_do 32 del_aubio_mfcc 33 */ 30 31 32 /** Internal structure for mfcc object **/ 33 34 struct aubio_mfcc_t_{ 35 36 /** grain length */ 37 uint_t win_s; 38 39 /** sample rate (needed?) */ 40 uint_t samplerate; 41 42 /** number of channels */ 43 uint_t channels; 44 45 /** filter bank */ 46 aubio_filterbank_t * fb; 47 48 /** number of coefficients (= fb->n_filters/2 +1) */ 49 uint_t n_coefs; 50 51 /** lowest frequency for filters */ 52 smpl_t lowfreq; 53 54 /** highest frequency for filters */ 55 smpl_t highfreq; 56 57 /** input buffer for dct * [fb->n_filters] */ 58 fvec_t * in_dct; 59 60 /** fft object for dct */ 61 aubio_mfft_t * fft_dct; 62 63 /** output buffer for dct */ 64 cvec_t * fftgrain_dct; 65 66 }; 67 68 69 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){ 70 71 72 /** allocating space for mfcc object */ 73 74 aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t); 75 76 mfcc->win_s=win_s; 77 mfcc->samplerate=samplerate; 78 mfcc->channels=channels; 79 mfcc->n_coefs=n_coefs; 80 mfcc->lowfreq=lowfreq; 81 mfcc->highfreq=highfreq; 82 83 /** filterbank allocation */ 84 //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct 85 mfcc->fb=new_aubio_filterbank((n_coefs-1)*2, mfcc->win_s); 86 87 /** allocating space for fft object (used for dct) */ 88 mfcc->fft_dct=new_aubio_mfft(mfcc->win_s, 1); 89 90 /** allocating buffers */ 91 92 mfcc->in_dct=new_fvec(mfcc->win_s, 1); 93 94 mfcc->fftgrain_dct=new_cvec(mfcc->fb->n_filters, 1); 95 96 /** populating the filterbank */ 97 98 aubio_filterbank_mfcc_init(mfcc->fb, (mfcc->samplerate)/2, XTRACT_EQUAL_GAIN, mfcc->lowfreq, mfcc->highfreq); 99 100 return mfcc; 101 102 }; 103 104 105 void del_aubio_mfcc(aubio_mfcc_t *mf){ 106 107 /** deleting filterbank */ 108 del_aubio_filterbank(mf->fb); 109 /** deleting mfft object */ 110 del_aubio_mfft(mf->fft_dct); 111 /** deleting buffers */ 112 del_fvec(mf->in_dct); 113 del_cvec(mf->fftgrain_dct); 114 115 /** deleting mfcc object */ 116 AUBIO_FREE(mf); 117 118 } 119 34 120 35 121 // Computation 36 // Added last two arguments to be able to pass from example 37 38 39 40 int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ 41 42 aubio_mel_filter *f; 43 int n, filter; 44 45 f = (aubio_mel_filter *)argv; 46 47 for(filter = 0; filter < f->n_filters; filter++){ 48 result[filter] = 0.f; 49 for(n = 0; n < N; n++){ 50 result[filter] += data[n] * f->filters[filter][n]; 122 123 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){ 124 125 aubio_filterbank_t *f = mf->fb; 126 uint_t n, filter_cnt; 127 128 for(filter_cnt = 0; filter_cnt < f->n_filters; filter_cnt++){ 129 mf->in_dct->data[0][filter_cnt] = 0.f; 130 for(n = 0; n < mf->win_s; n++){ 131 mf->in_dct->data[0][filter_cnt] += in->norm[0][n] * f->filters[filter_cnt]->data[0][n]; 51 132 } 52 result[filter] = LOG(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]);133 mf->in_dct->data[0][filter_cnt] = LOG(mf->in_dct->data[0][filter_cnt] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : mf->in_dct->data[0][filter_cnt]); 53 134 } 54 135 55 136 //TODO: check that zero padding 56 for(n = filter + 1; n < N; n++) result[n] = 0; 57 58 aubio_dct_do(result, f->n_filters, NULL, result, fft_dct, fftgrain_dct); 59 60 return XTRACT_SUCCESS; 137 // the following line seems useless since the in_dct buffer has the correct size 138 //for(n = filter + 1; n < N; n++) result[n] = 0; 139 140 aubio_dct_do(mf, mf->in_dct, out); 141 142 //return XTRACT_SUCCESS; 61 143 } 62 144 63 // Added last two arguments to be able to pass from example 64 65 int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ 66 67 68 //call aubio p_voc in dct setting 69 70 //TODO: fvec as input? Remove data length, N? 71 72 fvec_t * momo = new_fvec(20, 1); 73 momo->data = data; 145 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){ 146 147 148 149 //fvec_t * momo = new_fvec(20, 1); 150 //momo->data = data; 74 151 75 152 //compute mag spectrum 76 aubio_mfft_do ( fft_dct, data,fftgrain_dct);153 aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct); 77 154 78 155 int i; 79 156 //extract real part of fft grain 80 for(i=0; i< N;i++){81 result[i]= fftgrain_dct->norm[0][i]*COS(fftgrain_dct->phas[0][i]);157 for(i=0; i<mf->n_coefs ;i++){ 158 out->data[0][i]= mf->fftgrain_dct->norm[0][i]*COS(mf->fftgrain_dct->phas[0][i]); 82 159 } 83 160 84 161 85 return XTRACT_SUCCESS;162 //return XTRACT_SUCCESS; 86 163 } 164 165 166 ///////// OLD CODE 167 168 // int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ 169 // 170 // aubio_mel_filter *f; 171 // uint_t n, filter; 172 // 173 // f = (aubio_mel_filter *)argv; 174 // printf("%d",f->n_filters); 175 // 176 // for(filter = 0; filter < f->n_filters; filter++){ 177 // result[filter] = 0.f; 178 // for(n = 0; n < N; n++){ 179 // result[filter] += data[n] * f->filters[filter][n]; 180 // } 181 // result[filter] = LOG(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]); 182 // } 183 // 184 // //TODO: check that zero padding 185 // for(n = filter + 1; n < N; n++) result[n] = 0; 186 // 187 // aubio_dct_do(result, f->n_filters, NULL, result, fft_dct, fftgrain_dct); 188 // 189 // return XTRACT_SUCCESS; 190 // } 191 192 // Added last two arguments to be able to pass from example 193 194 // int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){ 195 // 196 // 197 // //call aubio p_voc in dct setting 198 // 199 // //TODO: fvec as input? Remove data length, N? 200 // 201 // fvec_t * momo = new_fvec(20, 1); 202 // momo->data = data; 203 // 204 // //compute mag spectrum 205 // aubio_mfft_do (fft_dct, data, fftgrain_dct); 206 // 207 // int i; 208 // //extract real part of fft grain 209 // for(i=0; i<N ;i++){ 210 // result[i]= fftgrain_dct->norm[0][i]*COS(fftgrain_dct->phas[0][i]); 211 // } 212 // 213 // 214 // return XTRACT_SUCCESS; 215 // }
Note: See TracChangeset
for help on using the changeset viewer.