Changes in / [f131ba8:a7b14a6]
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/pitch/pitchyinfft.c
rf131ba8 ra7b14a6 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 … … 113 116 fvec_t *yin = p>yinfft; 114 117 smpl_t tmp = 0., sum = 0.; 118 115 119 // window the input 116 120 fvec_weighted_copy(input, p>win, p>winput); … … 146 150 } 147 151 } 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 { 152 153 // calc min available confidence first 154 tmp = fvec_min(yin); 155 if (tmp > p>tol) { 156 // give up  got no confident candidate at all 169 157 output>data[0] = 0.; 170 } 158 return; 159 } 160 161 // choose lowest confident candidate first, to avoid choosing harmonics 162 tau = 0; 163 for (l = 1; l < yin>length; l++) { 164 // is this candidate "roughly" as good as the lowest one? 165 if (ABS (yin>data[l]  tmp) < 0.1) { 166 tau = l; 167 break; 168 } 169 } 170 // find local min around current pick to sharpen the results 171 const uint_t LOCAL_NOTE_SEEK_RANGE = 1; 172 const smpl_t note = aubio_bintomidi (tau, p>samplerate, p>fftout>length); 173 const uint_t startbin = MAX (0, (uint_t)aubio_miditobin (note  LOCAL_NOTE_SEEK_RANGE, 174 p>samplerate, p>fftout>length)); 175 const uint_t endbin = MIN (yin>length, (uint_t)(aubio_miditobin (note + LOCAL_NOTE_SEEK_RANGE, 176 p>samplerate, p>fftout>length) + 0.5)); 177 tmp = yin>data[tau]; 178 for (l = startbin; l < endbin; l++) { 179 if (yin>data[l] < tmp ) { 180 tmp = yin>data[l]; 181 tau = l; 182 } 183 } 184 output>data[0] = fvec_quadratic_peak_pos(yin, tau); 171 185 } 172 186
Note: See TracChangeset
for help on using the changeset viewer.