Changeset 1e37ade
- Timestamp:
- Sep 17, 2009, 5:54:25 AM (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:
- e7b3629
- Parents:
- bc3c51b
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/filterbank_mel.c
rbc3c51b r1e37ade 27 27 28 28 void 29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,30 smpl_t freq_min, smpl_t freq_max)29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, fvec_t * freqs, 30 smpl_t samplerate) 31 31 { 32 32 … … 34 34 uint_t n_filters = filters->channels, win_s = filters->length; 35 35 36 /* Malcolm Slaney parameters */ 37 smpl_t lowestFrequency = 133.3333; 38 smpl_t linearSpacing = 66.66666666; 39 smpl_t logSpacing = 1.0711703; 36 uint_t fn; /* filter counter */ 37 uint_t bin; /* bin counter */ 40 38 41 uint_t linearFilters = 13; 42 uint_t logFilters = 27; 43 uint_t allFilters = linearFilters + logFilters; 44 45 /* throw a warning if filterbank object fb is too short */ 46 if (allFilters > n_filters) { 47 AUBIO_WRN ("not enough Mel filters, got %d but %d needed\n", 48 n_filters, allFilters); 39 /* freqs define the bands of triangular overlapping windows. 40 throw a warning if filterbank object fb is too short. */ 41 if (freqs->length - 2 > n_filters) { 42 AUBIO_WRN ("not enough filters, %d allocated but %d requested\n", 43 n_filters, freqs->length - 2); 49 44 } 50 45 51 /* buffers for computing filter frequencies */52 fvec_t *freqs = new_fvec (allFilters + 2, 1);53 54 46 /* convenience reference to lower/center/upper frequency for each triangle */ 55 fvec_t *lower_freqs = new_fvec ( allFilters, 1);56 fvec_t *upper_freqs = new_fvec ( allFilters, 1);57 fvec_t *center_freqs = new_fvec ( allFilters, 1);47 fvec_t *lower_freqs = new_fvec (n_filters, 1); 48 fvec_t *upper_freqs = new_fvec (n_filters, 1); 49 fvec_t *center_freqs = new_fvec (n_filters, 1); 58 50 59 51 /* height of each triangle */ 60 fvec_t *triangle_heights = new_fvec ( allFilters, 1);52 fvec_t *triangle_heights = new_fvec (n_filters, 1); 61 53 62 54 /* lookup table of each bin frequency in hz */ 63 55 fvec_t *fft_freqs = new_fvec (win_s, 1); 64 56 65 uint_t fn; /* filter counter */66 uint_t bin; /* bin counter */67 68 /* first step: filling all the linear filter frequencies */69 for (fn = 0; fn < linearFilters; fn++) {70 freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;71 }72 smpl_t lastlinearCF = freqs->data[0][fn - 1];73 74 /* second step: filling all the log filter frequencies */75 for (fn = 0; fn < logFilters + 2; fn++) {76 freqs->data[0][fn + linearFilters] =77 lastlinearCF * (POW (logSpacing, fn + 1));78 }79 80 57 /* fill up the lower/center/upper */ 81 for (fn = 0; fn < allFilters; fn++) {58 for (fn = 0; fn < n_filters; fn++) { 82 59 lower_freqs->data[0][fn] = freqs->data[0][fn]; 83 60 center_freqs->data[0][fn] = freqs->data[0][fn + 1]; … … 86 63 87 64 /* compute triangle heights so that each triangle has unit area */ 88 for (fn = 0; fn < allFilters; fn++) {65 for (fn = 0; fn < n_filters; fn++) { 89 66 triangle_heights->data[0][fn] = 90 67 2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]); … … 144 121 145 122 /* destroy temporarly allocated vectors */ 146 del_fvec (freqs);147 123 del_fvec (lower_freqs); 148 124 del_fvec (upper_freqs); … … 153 129 154 130 } 131 132 void 133 aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb, 134 smpl_t samplerate) 135 { 136 /* Malcolm Slaney parameters */ 137 smpl_t lowestFrequency = 133.3333; 138 smpl_t linearSpacing = 66.66666666; 139 smpl_t logSpacing = 1.0711703; 140 141 uint_t linearFilters = 13; 142 uint_t logFilters = 27; 143 uint_t n_filters = linearFilters + logFilters; 144 145 uint_t fn; /* filter counter */ 146 uint_t bin; /* bin counter */ 147 148 /* buffers to compute filter frequencies */ 149 fvec_t *freqs = new_fvec (n_filters + 2, 1); 150 151 /* first step: fill all the linear filter frequencies */ 152 for (fn = 0; fn < linearFilters; fn++) { 153 freqs->data[0][fn] = lowestFrequency + fn * linearSpacing; 154 } 155 smpl_t lastlinearCF = freqs->data[0][fn - 1]; 156 157 /* second step: fill all the log filter frequencies */ 158 for (fn = 0; fn < logFilters + 2; fn++) { 159 freqs->data[0][fn + linearFilters] = 160 lastlinearCF * (POW (logSpacing, fn + 1)); 161 } 162 163 /* now compute the actual coefficients */ 164 aubio_filterbank_set_mel_coeffs (fb, freqs, samplerate); 165 166 /* destroy vector used to store frequency limits */ 167 del_fvec (freqs); 168 169 } -
src/spectral/filterbank_mel.h
rbc3c51b r1e37ade 44 44 /** filterbank initialization for mel filters 45 45 46 \param n_filters number of filters47 \param win_s window size46 \param fb filterbank object 47 \param freqs arbitrary array of boundary frequencies 48 48 \param samplerate audio sampling rate 49 \param freq_min lowest filter frequency 50 \param freq_max highest filter frequency 49 50 This function computes the coefficients of the filterbank based on the 51 boundaries found in freqs, in Hz, and using triangular overlapping windows. 51 52 52 53 */ 53 54 void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, 54 smpl_t samplerate, smpl_t freq_min, smpl_t freq_max); 55 fvec_t * freqs, smpl_t samplerate); 56 57 /** filterbank initialization for Mel filters using Slaney's coefficients 58 59 \param fb filterbank object 60 \param samplerate audio sampling rate 61 62 This function fills the filterbank coefficients according to Malcolm Slaney. 63 64 */ 65 void aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb, 66 smpl_t samplerate); 55 67 56 68 #ifdef __cplusplus -
src/spectral/mfcc.c
rbc3c51b r1e37ade 63 63 /** filterbank allocation */ 64 64 mfcc->fb = new_aubio_filterbank(n_filters, mfcc->win_s); 65 aubio_filterbank_set_mel_coeffs (mfcc->fb, samplerate, lowfreq, highfreq);65 aubio_filterbank_set_mel_coeffs_slaney(mfcc->fb, samplerate); 66 66 67 67 /** allocating space for fft object (used for dct) */ -
swig/aubio.i
rbc3c51b r1e37ade 163 163 /* filterbank */ 164 164 aubio_filterbank_t * new_aubio_filterbank(uint_t win_s, uint_t channels); 165 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max); 165 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, fvec_t *freqs, uint_t samplerate); 166 void aubio_filterbank_set_mel_coeffs_slaney(aubio_filterbank_t *fb, uint_t samplerate); 166 167 void del_aubio_filterbank(aubio_filterbank_t * fb); 167 168 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
Note: See TracChangeset
for help on using the changeset viewer.