Changes in / [5bdbb83:f98063b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchyinfft.c
r5bdbb83 rf98063b 38 38 smpl_t tol; /**< Yin tolerance */ 39 39 smpl_t confidence; /**< confidence */ 40 uint_t s amplerate; /**< samplerate we got initialized with*/40 uint_t short_period; /** shortest period under which to check for octave error */ 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;73 72 for (i = 0; i < p->weight->length; i++) { 74 73 freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate; … … 95 94 //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i])); 96 95 } 97 98 // disable weighting 99 fvec_set_all (p->weight, 1.0); 100 96 // check for octave errors above 1300 Hz 97 p->short_period = (uint_t)ROUND(samplerate / 1300.); 101 98 return p; 102 99 … … 112 109 uint_t tau, l; 113 110 uint_t length = p->fftout->length; 111 uint_t halfperiod; 114 112 fvec_t *fftout = p->fftout; 115 113 fvec_t *yin = p->yinfft; 116 114 smpl_t tmp = 0., sum = 0.; 117 // empirically derived peak width to look for118 uint_t lookafter = yin->length / 128, endbin;119 120 115 // window the input 121 116 fvec_weighted_copy(input, p->win, p->winput); … … 151 146 } 152 147 } 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 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 { 158 169 output->data[0] = 0.; 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); 170 } 186 171 } 187 172
Note: See TracChangeset
for help on using the changeset viewer.