Changes in / [f98063b:5bdbb83]
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/pitch/pitchyinfft.c
rf98063b r5bdbb83 38 38 smpl_t tol; /**< Yin tolerance */ 39 39 smpl_t confidence; /**< confidence */ 40 uint_t s hort_period; /** shortest period under which to check for octave error*/40 uint_t samplerate; /**< samplerate we got initialized with */ 41 41 }; 42 42 … … 70 70 p>win = new_aubio_window ("hanningz", bufsize); 71 71 p>weight = new_fvec (bufsize / 2 + 1); 72 p>samplerate = samplerate; 72 73 for (i = 0; i < p>weight>length; i++) { 73 74 freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate; … … 94 95 //p>weight>data[i] = SQRT(DB2LIN(p>weight>data[i])); 95 96 } 96 // check for octave errors above 1300 Hz 97 p>short_period = (uint_t)ROUND(samplerate / 1300.); 97 98 // disable weighting 99 fvec_set_all (p>weight, 1.0); 100 98 101 return p; 99 102 … … 109 112 uint_t tau, l; 110 113 uint_t length = p>fftout>length; 111 uint_t halfperiod;112 114 fvec_t *fftout = p>fftout; 113 115 fvec_t *yin = p>yinfft; 114 116 smpl_t tmp = 0., sum = 0.; 117 // empirically derived peak width to look for 118 uint_t lookafter = yin>length / 128, endbin; 119 115 120 // window the input 116 121 fvec_weighted_copy(input, p>win, p>winput); … … 146 151 } 147 152 } 148 // find best candidates 149 tau = fvec_min_elem (yin); 150 if (yin>data[tau] < p>tol) { 151 // no interpolation, directly return the period as an integer 152 //output>data[0] = tau; 153 //return; 154 155 // 3 point quadratic interpolation 156 //return fvec_quadratic_peak_pos (yin,tau,1); 157 /* additional check for (unlikely) octave doubling in higher frequencies */ 158 if (tau > p>short_period) { 159 output>data[0] = fvec_quadratic_peak_pos (yin, tau); 160 } else { 161 /* should compare the minimum value of each interpolated peaks */ 162 halfperiod = FLOOR (tau / 2 + .5); 163 if (yin>data[halfperiod] < p>tol) 164 output>data[0] = fvec_quadratic_peak_pos (yin, halfperiod); 165 else 166 output>data[0] = fvec_quadratic_peak_pos (yin, tau); 167 } 168 } else { 153 154 // calc min available confidence first 155 tmp = fvec_min(yin); 156 if (tmp > p>tol) { 157 // give up  got no confident candidate at all 169 158 output>data[0] = 0.; 170 } 159 return; 160 } 161 162 // choose first confident candidate, to avoid choosing lower harmonics 163 tau = 0; 164 for (l = 1; l < yin>length; l++) { 165 // is this candidate "roughly" as good as the lowest one? 166 // the constant 0.1 is empirically derived 167 if (ABS (yin>data[l]  tmp) < 0.1) { 168 tau = l; 169 break; 170 } 171 } 172 // find local min around current peak to sharpen the results 173 endbin = tau + lookafter < yin>length  1 ? tau + lookafter : yin>length  1; 174 tmp = yin>data[tau]; 175 for (l = tau; l < endbin; l++) { 176 if (yin>data[l] < tmp ) { 177 tmp = yin>data[l]; 178 tau = l; 179 } 180 // stop as soon as we start going up again 181 if (yin>data[l] > tmp && l > tau) { 182 break; 183 } 184 } 185 output>data[0] = fvec_quadratic_peak_pos(yin, tau); 171 186 } 172 187
Note: See TracChangeset
for help on using the changeset viewer.