Changeset cfd35db
 Timestamp:
 Sep 17, 2009, 1:26:49 AM (11 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 addc9ec
 Parents:
 3b3b03e
 Location:
 src/spectral
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/spectral/filterbank_mel.c
r3b3b03e rcfd35db 26 26 #include "mathutils.h" 27 27 28 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max){ 28 void 29 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, uint_t samplerate, 30 smpl_t freq_min, smpl_t freq_max) 31 { 29 32 30 fvec_t *filters = aubio_filterbank_get_coeffs (fb);33 fvec_t *filters = aubio_filterbank_get_coeffs (fb); 31 34 uint_t n_filters = filters>channels, win_s = filters>length; 32 35 33 36 //slaney params 34 37 smpl_t lowestFrequency = 133.3333; … … 39 42 uint_t logFilters = 27; 40 43 uint_t allFilters = linearFilters + logFilters; 41 44 42 45 //buffers for computing filter frequencies 43 fvec_t * freqs=new_fvec(allFilters+2 , 1); 44 45 fvec_t * lower_freqs=new_fvec( allFilters, 1); 46 fvec_t * upper_freqs=new_fvec( allFilters, 1); 47 fvec_t * center_freqs=new_fvec( allFilters, 1); 46 fvec_t *freqs = new_fvec (allFilters + 2, 1); 48 47 49 fvec_t * triangle_heights=new_fvec( allFilters, 1); 48 fvec_t *lower_freqs = new_fvec (allFilters, 1); 49 fvec_t *upper_freqs = new_fvec (allFilters, 1); 50 fvec_t *center_freqs = new_fvec (allFilters, 1); 51 52 fvec_t *triangle_heights = new_fvec (allFilters, 1); 50 53 //lookup table of each bin frequency in hz 51 fvec_t * fft_freqs=new_fvec(win_s, 1);54 fvec_t *fft_freqs = new_fvec (win_s, 1); 52 55 53 56 uint_t filter_cnt, bin_cnt; 54 57 55 58 //first step: filling all the linear filter frequencies 56 for (filter_cnt=0; filter_cnt<linearFilters; filter_cnt++){57 freqs>data[0][filter_cnt] =lowestFrequency+ filter_cnt*linearSpacing;59 for (filter_cnt = 0; filter_cnt < linearFilters; filter_cnt++) { 60 freqs>data[0][filter_cnt] = lowestFrequency + filter_cnt * linearSpacing; 58 61 } 59 smpl_t lastlinearCF =freqs>data[0][filter_cnt1];60 62 smpl_t lastlinearCF = freqs>data[0][filter_cnt  1]; 63 61 64 //second step: filling all the log filter frequencies 62 for (filter_cnt=0; filter_cnt<logFilters+2; filter_cnt++){63 freqs>data[0][filter_cnt +linearFilters] =64 lastlinearCF*(pow(logSpacing,filter_cnt+1));65 for (filter_cnt = 0; filter_cnt < logFilters + 2; filter_cnt++) { 66 freqs>data[0][filter_cnt + linearFilters] = 67 lastlinearCF * (pow (logSpacing, filter_cnt + 1)); 65 68 } 66 69 67 70 //Option 1. copying interesting values to lower_freqs, center_freqs and upper freqs arrays 68 71 //TODO: would be nicer to have a reference to freqs>data, anyway we do not care in this init step 69 70 for (filter_cnt=0; filter_cnt<allFilters; filter_cnt++){71 lower_freqs>data[0][filter_cnt] =freqs>data[0][filter_cnt];72 center_freqs>data[0][filter_cnt] =freqs>data[0][filter_cnt+1];73 upper_freqs>data[0][filter_cnt] =freqs>data[0][filter_cnt+2];72 73 for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { 74 lower_freqs>data[0][filter_cnt] = freqs>data[0][filter_cnt]; 75 center_freqs>data[0][filter_cnt] = freqs>data[0][filter_cnt + 1]; 76 upper_freqs>data[0][filter_cnt] = freqs>data[0][filter_cnt + 2]; 74 77 } 75 78 76 79 //computing triangle heights so that each triangle has unit area 77 for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++){ 78 triangle_heights>data[0][filter_cnt] = 2./(upper_freqs>data[0][filter_cnt] 79  lower_freqs>data[0][filter_cnt]); 80 for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { 81 triangle_heights>data[0][filter_cnt] = 82 2. / (upper_freqs>data[0][filter_cnt] 83  lower_freqs>data[0][filter_cnt]); 80 84 } 81 85 82 86 //AUBIO_DBG("filter tables frequencies\n"); 83 87 //for(filter_cnt=0; filter_cnt<allFilters; filter_cnt++) … … 88 92 89 93 //filling the fft_freqs lookup table, which assigns the frequency in hz to each bin 90 for (bin_cnt=0; bin_cnt<win_s; bin_cnt++){91 fft_freqs>data[0][bin_cnt] = aubio_bintofreq(bin_cnt, samplerate, win_s);94 for (bin_cnt = 0; bin_cnt < win_s; bin_cnt++) { 95 fft_freqs>data[0][bin_cnt] = aubio_bintofreq (bin_cnt, samplerate, win_s); 92 96 } 93 97 94 98 //building each filter table 95 for (filter_cnt=0; filter_cnt<allFilters; filter_cnt++){99 for (filter_cnt = 0; filter_cnt < allFilters; filter_cnt++) { 96 100 97 101 //TODO:check special case : lower freq =0 98 102 //calculating rise increment in mag/Hz 99 smpl_t riseInc= triangle_heights>data[0][filter_cnt]/(center_freqs>data[0][filter_cnt]lower_freqs>data[0][filter_cnt]); 100 103 smpl_t riseInc = 104 triangle_heights>data[0][filter_cnt] / 105 (center_freqs>data[0][filter_cnt]  lower_freqs>data[0][filter_cnt]); 106 101 107 //zeroing begining of filter 102 for (bin_cnt=0; bin_cnt<win_s1; bin_cnt++){103 filters>data[filter_cnt][bin_cnt] =0.0;104 if ( fft_freqs>data[0][bin_cnt]<= lower_freqs>data[0][filter_cnt] &&105 fft_freqs>data[0][bin_cnt +1] > lower_freqs>data[0][filter_cnt]) {108 for (bin_cnt = 0; bin_cnt < win_s  1; bin_cnt++) { 109 filters>data[filter_cnt][bin_cnt] = 0.0; 110 if (fft_freqs>data[0][bin_cnt] <= lower_freqs>data[0][filter_cnt] && 111 fft_freqs>data[0][bin_cnt + 1] > lower_freqs>data[0][filter_cnt]) { 106 112 break; 107 113 } 108 114 } 109 115 bin_cnt++; 110 116 111 117 //positive slope 112 for(; bin_cnt<win_s1; bin_cnt++){ 113 filters>data[filter_cnt][bin_cnt]=(fft_freqs>data[0][bin_cnt]lower_freqs>data[0][filter_cnt])*riseInc; 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; 114 122 //if(fft_freqs>data[0][bin_cnt]<= center_freqs>data[0][filter_cnt] && fft_freqs>data[0][bin_cnt+1]> center_freqs>data[0][filter_cnt]) 115 if (fft_freqs>data[0][bin_cnt+1]> center_freqs>data[0][filter_cnt])123 if (fft_freqs>data[0][bin_cnt + 1] > center_freqs>data[0][filter_cnt]) 116 124 break; 117 125 } 118 126 //bin_cnt++; 119 127 120 128 //negative slope 121 for (; bin_cnt<win_s1; bin_cnt++){122 129 for (; bin_cnt < win_s  1; bin_cnt++) { 130 123 131 //checking whether last value is less than 0... 124 smpl_t val=triangle_heights>data[0][filter_cnt](fft_freqs>data[0][bin_cnt]center_freqs>data[0][filter_cnt])*riseInc; 125 if(val>=0) 126 filters>data[filter_cnt][bin_cnt]=val; 127 else filters>data[filter_cnt][bin_cnt]=0.0; 128 132 smpl_t val = 133 triangle_heights>data[0][filter_cnt]  (fft_freqs>data[0][bin_cnt]  134 center_freqs>data[0][filter_cnt]) * riseInc; 135 if (val >= 0) 136 filters>data[filter_cnt][bin_cnt] = val; 137 else 138 filters>data[filter_cnt][bin_cnt] = 0.0; 139 129 140 //if(fft_freqs>data[0][bin_cnt]<= upper_freqs>data[0][bin_cnt] && fft_freqs>data[0][bin_cnt+1]> upper_freqs>data[0][filter_cnt]) 130 141 //TODO: CHECK whether bugfix correct 131 if (fft_freqs>data[0][bin_cnt+1]> upper_freqs>data[0][filter_cnt])142 if (fft_freqs>data[0][bin_cnt + 1] > upper_freqs>data[0][filter_cnt]) 132 143 break; 133 144 } 134 145 //bin_cnt++; 135 146 136 147 //zeroing tail 137 for (; bin_cnt<win_s; bin_cnt++)138 filters>data[filter_cnt][bin_cnt] =0.f;148 for (; bin_cnt < win_s; bin_cnt++) 149 filters>data[filter_cnt][bin_cnt] = 0.f; 139 150 140 151 } 141 142 /* destroy temporarly allocated vectors */143 del_fvec(freqs);144 del_fvec(lower_freqs);145 del_fvec(upper_freqs);146 del_fvec(center_freqs);147 152 148 del_fvec(triangle_heights); 149 del_fvec(fft_freqs); 153 /* destroy temporarly allocated vectors */ 154 del_fvec (freqs); 155 del_fvec (lower_freqs); 156 del_fvec (upper_freqs); 157 del_fvec (center_freqs); 158 159 del_fvec (triangle_heights); 160 del_fvec (fft_freqs); 150 161 151 162 } 152 
src/spectral/filterbank_mel.h
r3b3b03e rcfd35db 36 36 37 37 #ifdef __cplusplus 38 extern "C" { 38 extern "C" 39 { 39 40 #endif 40 41 … … 50 51 51 52 */ 52 void aubio_filterbank_set_mel_coeffs(aubio_filterbank_t *fb, uint_t samplerate, smpl_t freq_min, smpl_t freq_max); 53 void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, 54 uint_t samplerate, smpl_t freq_min, smpl_t freq_max); 53 55 54 56 #ifdef __cplusplus … … 56 58 #endif 57 59 58 #endif // FILTERBANK_MEL_H60 #endif // FILTERBANK_MEL_H
Note: See TracChangeset
for help on using the changeset viewer.