Changeset 56ef7e1 for src/mathutils.c
- Timestamp:
- Oct 18, 2009, 3:08:59 PM (14 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:
- e5f49af
- Parents:
- 74516f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mathutils.c
r74516f7 r56ef7e1 142 142 143 143 smpl_t 144 fvec_mean_channel (fvec_t * s, uint_t i) 145 { 146 uint_t j; 147 smpl_t tmp = 0.0; 148 for (j = 0; j < s->length; j++) 149 tmp += s->data[i][j]; 150 return tmp / (smpl_t) (s->length); 151 } 152 153 smpl_t 144 154 fvec_sum (fvec_t * s) 145 155 { … … 289 299 290 300 void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp, 291 uint_t post, uint_t pre ) {292 uint_t length = vec->length, i= 0, j;301 uint_t post, uint_t pre, uint_t channel) { 302 uint_t length = vec->length, i=channel, j; 293 303 for (j=0;j<length;j++) { 294 vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j );304 vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j, i); 295 305 } 296 306 } … … 298 308 smpl_t 299 309 fvec_moving_thres (fvec_t * vec, fvec_t * tmpvec, 300 uint_t post, uint_t pre, uint_t pos )301 { 302 smpl_t *medar = (smpl_t *) tmpvec->data[0];303 uint_t k;310 uint_t post, uint_t pre, uint_t pos, uint_t channel) 311 { 312 uint_t i = channel, k; 313 smpl_t *medar = (smpl_t *) tmpvec->data[i]; 304 314 uint_t win_length = post + pre + 1; 305 315 uint_t length = vec->length; … … 321 331 medar[k] = 0.; /* 0-padding at the end */ 322 332 } 323 return fvec_median (tmpvec);324 } 325 326 smpl_t fvec_median (fvec_t * input) {333 return fvec_median_channel (tmpvec, i); 334 } 335 336 smpl_t fvec_median_channel (fvec_t * input, uint_t channel) { 327 337 uint_t n = input->length; 328 smpl_t * arr = (smpl_t *) input->data[ 0];338 smpl_t * arr = (smpl_t *) input->data[channel]; 329 339 uint_t low, high ; 330 340 uint_t median; … … 375 385 } 376 386 377 smpl_t fvec_quadint (fvec_t * x,uint_t pos, uint_t span) {387 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t i) { 378 388 smpl_t s0, s1, s2; 379 uint_t x0 = (pos < span) ? pos : pos - span;380 uint_t x2 = (pos + span < x->length) ? pos + span: pos;381 if (x0 == pos) return (x->data[ 0][pos] <= x->data[0][x2]) ? pos : x2;382 if (x2 == pos) return (x->data[ 0][pos] <= x->data[0][x0]) ? pos : x0;383 s0 = x->data[ 0][x0];384 s1 = x->data[ 0][pos];385 s2 = x->data[ 0][x2];389 uint_t x0 = (pos < 1) ? pos : pos - 1; 390 uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos; 391 if (x0 == pos) return (x->data[i][pos] <= x->data[i][x2]) ? pos : x2; 392 if (x2 == pos) return (x->data[i][pos] <= x->data[i][x0]) ? pos : x0; 393 s0 = x->data[i][x0]; 394 s1 = x->data[i][pos]; 395 s2 = x->data[i][x2]; 386 396 return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0); 387 397 }
Note: See TracChangeset
for help on using the changeset viewer.