Changeset ef1c3b7 for src/mathutils.c
- Timestamp:
- Sep 11, 2007, 12:14:01 AM (17 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:
- f72ceeb
- Parents:
- 7212394 (diff), 7a46bf6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mathutils.c
r7212394 ref1c3b7 30 30 case aubio_win_rectangle: 31 31 for (i=0;i<size;i++) 32 w[i] = 0.5; 32 w[i] = 0.5; 33 33 break; 34 34 case aubio_win_hamming: … … 48 48 w[i] = 0.42 49 49 - 0.50 * COS( TWO_PI*i/(size-1.0)) 50 + 50 + 0.08 * COS(2.0*TWO_PI*i/(size-1.0)); 51 51 break; 52 52 case aubio_win_blackman_harris: 53 53 for (i=0;i<size;i++) 54 w[i] = 0.35875 54 w[i] = 0.35875 55 55 - 0.48829 * COS( TWO_PI*i/(size-1.0)) 56 56 + 0.14128 * COS(2.0*TWO_PI*i/(size-1.0)) … … 74 74 } 75 75 76 77 76 smpl_t aubio_unwrap2pi(smpl_t phase) { 78 77 /* mod(phase+pi,-2pi)+pi */ … … 80 79 } 81 80 82 83 smpl_t vec_mean(fvec_t *s) 84 { 81 smpl_t vec_mean(fvec_t *s) { 85 82 uint_t i,j; 86 83 smpl_t tmp = 0.0f; … … 91 88 } 92 89 93 94 smpl_t vec_sum(fvec_t *s) 95 { 90 smpl_t vec_sum(fvec_t *s) { 96 91 uint_t i,j; 97 92 smpl_t tmp = 0.0f; … … 102 97 } 103 98 104 105 smpl_t vec_max(fvec_t *s) 106 { 99 smpl_t vec_max(fvec_t *s) { 107 100 uint_t i,j; 108 101 smpl_t tmp = 0.0f; … … 113 106 } 114 107 115 smpl_t vec_min(fvec_t *s) 116 { 108 smpl_t vec_min(fvec_t *s) { 117 109 uint_t i,j; 118 110 smpl_t tmp = s->data[0][0]; … … 123 115 } 124 116 125 126 uint_t vec_min_elem(fvec_t *s) 127 { 117 uint_t vec_min_elem(fvec_t *s) { 128 118 uint_t i,j=0, pos=0.; 129 119 smpl_t tmp = s->data[0][0]; … … 136 126 } 137 127 138 uint_t vec_max_elem(fvec_t *s) 139 { 128 uint_t vec_max_elem(fvec_t *s) { 140 129 uint_t i,j=0, pos=0.; 141 130 smpl_t tmp = 0.0f; … … 148 137 } 149 138 150 void vec_shift(fvec_t *s) 151 { 139 void vec_shift(fvec_t *s) { 152 140 uint_t i,j; 153 141 //smpl_t tmp = 0.0f; … … 161 149 } 162 150 163 smpl_t vec_local_energy(fvec_t * f) 164 { 151 smpl_t vec_local_energy(fvec_t * f) { 165 152 smpl_t locE = 0.; 166 153 uint_t i,j; … … 171 158 } 172 159 173 smpl_t vec_local_hfc(fvec_t * f) 174 { 160 smpl_t vec_local_hfc(fvec_t * f) { 175 161 smpl_t locE = 0.; 176 162 uint_t i,j; … … 181 167 } 182 168 183 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha) 184 { 169 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha) { 185 170 smpl_t tmp = 0.; 186 171 uint_t i,j; … … 191 176 } 192 177 193 194 void vec_dc_removal(fvec_t * mag) 195 { 178 void vec_dc_removal(fvec_t * mag) { 196 179 smpl_t mini = 0.; 197 180 uint_t length = mag->length, i=0, j; … … 202 185 } 203 186 204 205 void vec_alpha_normalise(fvec_t * mag, uint_t alpha) 206 { 187 void vec_alpha_normalise(fvec_t * mag, uint_t alpha) { 207 188 smpl_t alphan = 1.; 208 189 uint_t length = mag->length, i=0, j; … … 213 194 } 214 195 215 216 196 void vec_add(fvec_t * mag, smpl_t threshold) { 217 197 uint_t length = mag->length, i=0, j; … … 221 201 } 222 202 223 224 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp, 225 uint_t post, uint_t pre) 226 { 203 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp, 204 uint_t post, uint_t pre) { 227 205 uint_t length = vec->length, i=0, j; 228 206 for (j=0;j<length;j++) { … … 232 210 233 211 smpl_t vec_moving_thres(fvec_t * vec, fvec_t * tmpvec, 234 uint_t post, uint_t pre, uint_t pos) 235 { 212 uint_t post, uint_t pre, uint_t pos) { 236 213 smpl_t * medar = (smpl_t *)tmpvec->data[0]; 237 214 uint_t k; … … 240 217 /* post part of the buffer does not exist */ 241 218 if (pos<post+1) { 242 for (k=0;k<post+1-pos;k++) 219 for (k=0;k<post+1-pos;k++) 243 220 medar[k] = 0.; /* 0-padding at the beginning */ 244 221 for (k=post+1-pos;k<win_length;k++) … … 252 229 for (k=0;k<length-pos+post+1;k++) 253 230 medar[k] = vec->data[0][k+pos-post]; 254 for (k=length-pos+post+1;k<win_length;k++) 231 for (k=length-pos+post+1;k<win_length;k++) 255 232 medar[k] = 0.; /* 0-padding at the end */ 256 } 233 } 257 234 return vec_median(tmpvec); 258 235 } … … 321 298 for (frac = 0.; frac < 2.; frac = frac + step) { 322 299 res = aubio_quadfrac(s0, s1, s2, frac); 323 if (res > resold) 300 if (res > resold) 324 301 resold = res; 325 else { 302 else { 326 303 exactpos += (frac-step)*2. - 1.; 327 304 break; … … 345 322 if (res < resold) { 346 323 resold = res; 347 } else { 324 } else { 348 325 exactpos += (frac-step)*span - span/2.; 349 326 break; … … 360 337 361 338 uint_t vec_peakpick(fvec_t * onset, uint_t pos) { 362 363 364 365 366 &&onset->data[i][pos] > 0.);367 339 uint_t i=0, tmp=0; 340 /*for (i=0;i<onset->channels;i++)*/ 341 tmp = (onset->data[i][pos] > onset->data[i][pos-1] 342 && onset->data[i][pos] > onset->data[i][pos+1] 343 && onset->data[i][pos] > 0.); 344 return tmp; 368 345 } 369 346 370 347 smpl_t aubio_freqtomidi(smpl_t freq) { 371 372 373 374 375 midi -= 3;376 348 /* log(freq/A-2)/log(2) */ 349 smpl_t midi = freq/6.875; 350 midi = LOG(midi)/0.69314718055995; 351 midi *= 12; 352 midi -= 3; 353 return midi; 377 354 } 378 355 379 356 smpl_t aubio_miditofreq(smpl_t midi) { 380 381 382 383 357 smpl_t freq = (midi+3.)/12.; 358 freq = EXP(freq*0.69314718055995); 359 freq *= 6.875; 360 return freq; 384 361 } 385 362 … … 404 381 } 405 382 406 407 408 /** returns 1 if wassilence is 0 and RMS(ibuf)<threshold 383 /** returns 1 if wassilence is 0 and RMS(ibuf)<threshold 409 384 * \bug mono 410 385 */ … … 436 411 437 412 if (loudness < threshold) 438 413 return 1.; 439 414 else 440 415 return loudness; 441 416 } 442 417 … … 451 426 } 452 427 //previous was positive 453 } else if ( input->data[i][j] <= 0. ) {428 } else if ( input->data[i][j] <= 0. ) { 454 429 zcr += 1; 455 430 } … … 471 446 } 472 447 473 void aubio_autocorr(fvec_t * input, fvec_t * output){ 474 uint_t i = 0, j = 0, length = input->length; 475 smpl_t * data = input->data[0]; 476 smpl_t * acf = output->data[0]; 477 smpl_t tmp =0.; 478 for(i=0;i<length;i++){ 479 for(j=i;j<length;j++){ 480 tmp += data[j-i]*data[j]; 481 } 482 acf[i] = tmp /(smpl_t)(length-i); 483 tmp = 0.0; 484 } 485 } 486 487 void aubio_cleanup(void) 488 { 448 void aubio_autocorr(fvec_t * input, fvec_t * output) { 449 uint_t i = 0, j = 0, length = input->length; 450 smpl_t * data = input->data[0]; 451 smpl_t * acf = output->data[0]; 452 smpl_t tmp =0.; 453 for(i=0;i<length;i++){ 454 for(j=i;j<length;j++){ 455 tmp += data[j-i]*data[j]; 456 } 457 acf[i] = tmp /(smpl_t)(length-i); 458 tmp = 0.0; 459 } 460 } 461 462 void aubio_cleanup(void) { 489 463 #if FFTW3_SUPPORT 490 464 fftw_cleanup(); 491 465 #else 492 466 #if FFTW3F_SUPPORT 493 467 fftwf_cleanup(); 494 468 #endif 495 469 #endif
Note: See TracChangeset
for help on using the changeset viewer.