- Timestamp:
- Sep 17, 2009, 4:21:40 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:
- bc3c51b
- Parents:
- b507607
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/filterbank_mel.c
rb507607 r4e0fbe6 34 34 uint_t n_filters = filters->channels, win_s = filters->length; 35 35 36 / /slaney params36 /* Malcolm Slaney parameters */ 37 37 smpl_t lowestFrequency = 133.3333; 38 38 smpl_t linearSpacing = 66.66666666; … … 43 43 uint_t allFilters = linearFilters + logFilters; 44 44 45 /* throw a warning if filterbank object fb is too short */ 45 46 if (allFilters > n_filters) { 46 AUBIO_WRN ("not enough Mel filters, got %d but %d needed\n",47 AUBIO_WRN ("not enough Mel filters, got %d but %d needed\n", 47 48 n_filters, allFilters); 48 49 } 49 50 50 / /buffers for computing filter frequencies51 /* buffers for computing filter frequencies */ 51 52 fvec_t *freqs = new_fvec (allFilters + 2, 1); 52 53 54 /* convenience reference to lower/center/upper frequency for each triangle */ 53 55 fvec_t *lower_freqs = new_fvec (allFilters, 1); 54 56 fvec_t *upper_freqs = new_fvec (allFilters, 1); 55 57 fvec_t *center_freqs = new_fvec (allFilters, 1); 56 58 59 /* height of each triangle */ 57 60 fvec_t *triangle_heights = new_fvec (allFilters, 1); 58 //lookup table of each bin frequency in hz 61 62 /* lookup table of each bin frequency in hz */ 59 63 fvec_t *fft_freqs = new_fvec (win_s, 1); 60 64 61 uint_t filter_cnt, bin_cnt; 65 uint_t fn; /* filter counter */ 66 uint_t bin; /* bin counter */ 62 67 63 / /first step: filling all the linear filter frequencies64 for (f ilter_cnt = 0; filter_cnt < linearFilters; filter_cnt++) {65 freqs->data[0][f ilter_cnt] = lowestFrequency + filter_cnt* linearSpacing;68 /* first step: filling all the linear filter frequencies */ 69 for (fn = 0; fn < linearFilters; fn++) { 70 freqs->data[0][fn] = lowestFrequency + fn * linearSpacing; 66 71 } 67 smpl_t lastlinearCF = freqs->data[0][f ilter_cnt- 1];72 smpl_t lastlinearCF = freqs->data[0][fn - 1]; 68 73 69 / /second step: filling all the log filter frequencies70 for (f ilter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) {71 freqs->data[0][f ilter_cnt+ linearFilters] =72 lastlinearCF * (POW (logSpacing, filter_cnt+ 1));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)); 73 78 } 74 79 75 //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays 76 //TODO: would be nicer to have a reference to freqs->data, anyway we do not care in this init step 77 78 for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { 79 lower_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt]; 80 center_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 1]; 81 upper_freqs->data[0][filter_cnt] = freqs->data[0][filter_cnt + 2]; 80 /* fill up the lower/center/upper */ 81 for (fn = 0; fn < allFilters; fn++) { 82 lower_freqs->data[0][fn] = freqs->data[0][fn]; 83 center_freqs->data[0][fn] = freqs->data[0][fn + 1]; 84 upper_freqs->data[0][fn] = freqs->data[0][fn + 2]; 82 85 } 83 86 84 //computing triangle heights so that each triangle has unit area 85 for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { 86 triangle_heights->data[0][filter_cnt] = 87 2. / (upper_freqs->data[0][filter_cnt] 88 - lower_freqs->data[0][filter_cnt]); 87 /* compute triangle heights so that each triangle has unit area */ 88 for (fn = 0; fn < allFilters; fn++) { 89 triangle_heights->data[0][fn] = 90 2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]); 89 91 } 90 92 91 / /filling the fft_freqs lookup table, which assigns the frequency in hz to each bin92 for (bin _cnt = 0; bin_cnt < win_s; bin_cnt++) {93 fft_freqs->data[0][bin _cnt] = aubio_bintofreq (bin_cnt, samplerate, win_s);93 /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */ 94 for (bin = 0; bin < win_s; bin++) { 95 fft_freqs->data[0][bin] = aubio_bintofreq (bin, samplerate, win_s); 94 96 } 95 97 96 97 /* zeroing begining of filter */ 98 fvec_zeros(filters); 98 /* zeroing of all filters */ 99 fvec_zeros (filters); 99 100 100 101 /* building each filter table */ 101 for (f ilter_cnt = 0; filter_cnt < n_filters; filter_cnt++) {102 for (fn = 0; fn < n_filters; fn++) { 102 103 103 104 /* skip first elements */ 104 for (bin _cnt = 0; bin_cnt < win_s - 1; bin_cnt++) {105 if (fft_freqs->data[0][bin _cnt] <= lower_freqs->data[0][filter_cnt] &&106 fft_freqs->data[0][bin _cnt + 1] > lower_freqs->data[0][filter_cnt]) {105 for (bin = 0; bin < win_s - 1; bin++) { 106 if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] && 107 fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) { 107 108 break; 108 109 } 109 110 } 110 bin _cnt++;111 bin++; 111 112 112 113 /* compute positive slope step size */ 113 114 smpl_t riseInc = 114 triangle_heights->data[0][f ilter_cnt] /115 (center_freqs->data[0][f ilter_cnt] - lower_freqs->data[0][filter_cnt]);115 triangle_heights->data[0][fn] / 116 (center_freqs->data[0][fn] - lower_freqs->data[0][fn]); 116 117 117 118 /* compute coefficients in positive slope */ 118 for (; bin_cnt < win_s - 1; bin_cnt++) { 119 filters->data[filter_cnt][bin_cnt] = 120 (fft_freqs->data[0][bin_cnt] - 121 lower_freqs->data[0][filter_cnt]) * riseInc; 122 123 if (fft_freqs->data[0][bin_cnt + 1] > center_freqs->data[0][filter_cnt]) 119 for (; bin < win_s - 1; bin++) { 120 filters->data[fn][bin] = 121 (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc; 122 123 if (fft_freqs->data[0][bin + 1] > center_freqs->data[0][fn]) 124 124 break; 125 125 } 126 bin _cnt++;126 bin++; 127 127 128 128 /* compute negative slope step size */ 129 129 smpl_t downInc = 130 triangle_heights->data[0][f ilter_cnt] /131 (upper_freqs->data[0][f ilter_cnt] - center_freqs->data[0][filter_cnt]);130 triangle_heights->data[0][fn] / 131 (upper_freqs->data[0][fn] - center_freqs->data[0][fn]); 132 132 133 133 /* compute coefficents in negative slope */ 134 for (; bin_cnt < win_s - 1; bin_cnt++) { 135 filters->data[filter_cnt][bin_cnt] += 136 (upper_freqs->data[0][filter_cnt] - 137 fft_freqs->data[0][bin_cnt]) * downInc; 134 for (; bin < win_s - 1; bin++) { 135 filters->data[fn][bin] += 136 (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc; 138 137 139 if (fft_freqs->data[0][bin _cnt + 1] > upper_freqs->data[0][filter_cnt])138 if (fft_freqs->data[0][bin + 1] > upper_freqs->data[0][fn]) 140 139 break; 141 140 }
Note: See TracChangeset
for help on using the changeset viewer.