Changeset 3c18f9e for src/spectral
- Timestamp:
- Oct 7, 2009, 11:32:42 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:
- a9f1656
- Parents:
- 9a12264
- Location:
- src/spectral
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/filterbank_mel.c
r9a12264 r3c18f9e 26 26 #include "mathutils.h" 27 27 28 void 29 aubio_filterbank_set_ mel_coeffs (aubio_filterbank_t * fb, fvec_t * freqs,30 smpl_t samplerate )28 uint_t 29 aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 30 smpl_t samplerate, fvec_t * freqs) 31 31 { 32 32 … … 42 42 AUBIO_WRN ("not enough filters, %d allocated but %d requested\n", 43 43 n_filters, freqs->length - 2); 44 } 45 46 if (freqs->length - 2 < n_filters) { 47 AUBIO_WRN ("too many filters, %d allocated but %d requested\n", 48 n_filters, freqs->length - 2); 49 } 50 51 if (freqs->data[0][freqs->length - 1] > samplerate / 2) { 52 AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \ 53 %fHz\n", samplerate / 2, freqs->data[0][freqs->length - 1]); 44 54 } 45 55 … … 70 80 /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */ 71 81 for (bin = 0; bin < win_s; bin++) { 72 fft_freqs->data[0][bin] = aubio_bintofreq (bin, samplerate, (win_s - 1) * 2); 82 fft_freqs->data[0][bin] = 83 aubio_bintofreq (bin, samplerate, (win_s - 1) * 2); 73 84 } 74 85 75 86 /* zeroing of all filters */ 76 87 fvec_zeros (filters); 88 89 if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) { 90 /* - 1 to make sure we don't miss the smallest power of two */ 91 uint_t min_win_s = 92 (uint_t) FLOOR (samplerate / lower_freqs->data[0][0]) - 1; 93 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \ 94 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n", 95 fft_freqs->data[0][1], lower_freqs->data[0][0], 96 upper_freqs->data[0][0], (win_s - 1) * 2, 97 aubio_next_power_of_two (min_win_s)); 98 } 77 99 78 100 /* building each filter table */ … … 83 105 if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] && 84 106 fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) { 107 bin++; 85 108 break; 86 109 } 87 110 } 88 bin++;89 111 90 112 /* compute positive slope step size */ … … 98 120 (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc; 99 121 100 if (fft_freqs->data[0][bin + 1] > center_freqs->data[0][fn]) 122 if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) { 123 bin++; 101 124 break; 125 } 102 126 } 103 bin++;104 127 105 128 /* compute negative slope step size */ … … 113 136 (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc; 114 137 115 if (fft_freqs->data[0][bin + 1] > upper_freqs->data[0][fn]) 138 if (filters->data[fn][bin] < 0.) { 139 filters->data[fn][bin] = 0.; 140 } 141 142 if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn]) 116 143 break; 117 144 } … … 128 155 del_fvec (fft_freqs); 129 156 157 return 0; 130 158 } 131 159 132 void 160 uint_t 133 161 aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb, 134 162 smpl_t samplerate) 135 163 { 164 uint_t retval; 165 136 166 /* Malcolm Slaney parameters */ 137 167 smpl_t lowestFrequency = 133.3333; … … 161 191 162 192 /* now compute the actual coefficients */ 163 aubio_filterbank_set_mel_coeffs (fb, freqs, samplerate);193 retval = aubio_filterbank_set_triangle_bands (fb, samplerate, freqs); 164 194 165 195 /* destroy vector used to store frequency limits */ 166 196 del_fvec (freqs); 167 197 198 return retval; 168 199 } -
src/spectral/filterbank_mel.h
r9a12264 r3c18f9e 40 40 #endif 41 41 42 /** filterbank initialization for mel filters42 /** filterbank initialization with triangular and overlapping bands 43 43 44 44 \param fb filterbank object … … 47 47 48 48 This function computes the coefficients of the filterbank based on the 49 boundaries found in freqs, in Hz, and using triangular overlapping windows.49 boundaries found in freqs, in Hz, and using triangular overlapping bands. 50 50 51 51 */ 52 void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,53 fvec_t * freqs, smpl_t samplerate);52 uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 53 smpl_t samplerate, fvec_t * freqs); 54 54 55 55 /** filterbank initialization for Mel filters using Slaney's coefficients … … 61 61 62 62 */ 63 voidaubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,63 uint_t aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb, 64 64 smpl_t samplerate); 65 65
Note: See TracChangeset
for help on using the changeset viewer.