Changes in src/mathutils.c [ade9afe:0dbdb40]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mathutils.c
rade9afe r0dbdb40 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 76 77 smpl_t aubio_unwrap2pi(smpl_t phase) { 77 78 /* mod(phase+pi,-2pi)+pi */ … … 79 80 } 80 81 81 smpl_t vec_mean(fvec_t *s) { 82 83 smpl_t vec_mean(fvec_t *s) 84 { 82 85 uint_t i,j; 83 86 smpl_t tmp = 0.0f; … … 88 91 } 89 92 90 smpl_t vec_sum(fvec_t *s) { 93 94 smpl_t vec_sum(fvec_t *s) 95 { 91 96 uint_t i,j; 92 97 smpl_t tmp = 0.0f; … … 97 102 } 98 103 99 smpl_t vec_max(fvec_t *s) { 104 105 smpl_t vec_max(fvec_t *s) 106 { 100 107 uint_t i,j; 101 108 smpl_t tmp = 0.0f; … … 106 113 } 107 114 108 smpl_t vec_min(fvec_t *s) { 115 smpl_t vec_min(fvec_t *s) 116 { 109 117 uint_t i,j; 110 118 smpl_t tmp = s->data[0][0]; … … 115 123 } 116 124 117 uint_t vec_min_elem(fvec_t *s) { 125 126 uint_t vec_min_elem(fvec_t *s) 127 { 118 128 uint_t i,j=0, pos=0.; 119 129 smpl_t tmp = s->data[0][0]; … … 126 136 } 127 137 128 uint_t vec_max_elem(fvec_t *s) { 138 uint_t vec_max_elem(fvec_t *s) 139 { 129 140 uint_t i,j=0, pos=0.; 130 141 smpl_t tmp = 0.0f; … … 137 148 } 138 149 139 void vec_shift(fvec_t *s) { 150 void vec_shift(fvec_t *s) 151 { 140 152 uint_t i,j; 141 153 //smpl_t tmp = 0.0f; … … 149 161 } 150 162 151 smpl_t vec_local_energy(fvec_t * f) { 163 smpl_t vec_local_energy(fvec_t * f) 164 { 152 165 smpl_t locE = 0.; 153 166 uint_t i,j; … … 158 171 } 159 172 160 smpl_t vec_local_hfc(fvec_t * f) { 173 smpl_t vec_local_hfc(fvec_t * f) 174 { 161 175 smpl_t locE = 0.; 162 176 uint_t i,j; … … 167 181 } 168 182 169 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha) { 183 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha) 184 { 170 185 smpl_t tmp = 0.; 171 186 uint_t i,j; … … 176 191 } 177 192 178 void vec_dc_removal(fvec_t * mag) { 193 194 void vec_dc_removal(fvec_t * mag) 195 { 179 196 smpl_t mini = 0.; 180 197 uint_t length = mag->length, i=0, j; … … 185 202 } 186 203 187 void vec_alpha_normalise(fvec_t * mag, uint_t alpha) { 204 205 void vec_alpha_normalise(fvec_t * mag, uint_t alpha) 206 { 188 207 smpl_t alphan = 1.; 189 208 uint_t length = mag->length, i=0, j; … … 194 213 } 195 214 215 196 216 void vec_add(fvec_t * mag, smpl_t threshold) { 197 217 uint_t length = mag->length, i=0, j; … … 201 221 } 202 222 203 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp, 204 uint_t post, uint_t pre) { 223 224 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp, 225 uint_t post, uint_t pre) 226 { 205 227 uint_t length = vec->length, i=0, j; 206 228 for (j=0;j<length;j++) { … … 210 232 211 233 smpl_t vec_moving_thres(fvec_t * vec, fvec_t * tmpvec, 212 uint_t post, uint_t pre, uint_t pos) { 234 uint_t post, uint_t pre, uint_t pos) 235 { 213 236 smpl_t * medar = (smpl_t *)tmpvec->data[0]; 214 237 uint_t k; … … 217 240 /* post part of the buffer does not exist */ 218 241 if (pos<post+1) { 219 for (k=0;k<post+1-pos;k++) 242 for (k=0;k<post+1-pos;k++) 220 243 medar[k] = 0.; /* 0-padding at the beginning */ 221 244 for (k=post+1-pos;k<win_length;k++) … … 229 252 for (k=0;k<length-pos+post+1;k++) 230 253 medar[k] = vec->data[0][k+pos-post]; 231 for (k=length-pos+post+1;k<win_length;k++) 254 for (k=length-pos+post+1;k<win_length;k++) 232 255 medar[k] = 0.; /* 0-padding at the end */ 233 } 256 } 234 257 return vec_median(tmpvec); 235 258 } … … 298 321 for (frac = 0.; frac < 2.; frac = frac + step) { 299 322 res = aubio_quadfrac(s0, s1, s2, frac); 300 if (res > resold) 323 if (res > resold) 301 324 resold = res; 302 else { 325 else { 303 326 exactpos += (frac-step)*2. - 1.; 304 327 break; … … 322 345 if (res < resold) { 323 346 resold = res; 324 } else { 347 } else { 325 348 exactpos += (frac-step)*span - span/2.; 326 349 break; … … 337 360 338 361 uint_t vec_peakpick(fvec_t * onset, uint_t pos) { 339 340 341 342 343 &&onset->data[i][pos] > 0.);344 362 uint_t i=0, tmp=0; 363 /*for (i=0;i<onset->channels;i++)*/ 364 tmp = (onset->data[i][pos] > onset->data[i][pos-1] 365 && onset->data[i][pos] > onset->data[i][pos+1] 366 && onset->data[i][pos] > 0.); 367 return tmp; 345 368 } 346 369 347 370 smpl_t aubio_freqtomidi(smpl_t freq) { 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;371 /* log(freq/A-2)/log(2) */ 372 smpl_t midi = freq/6.875; 373 midi = LOG(midi)/0.69314718055995; 374 midi *= 12; 375 midi -= 3; 376 return midi; 354 377 } 355 378 356 379 smpl_t aubio_miditofreq(smpl_t midi) { 357 smpl_t freq = (midi+3.)/12.;358 freq = EXP(freq*0.69314718055995);359 freq *= 6.875;360 return freq;380 smpl_t freq = (midi+3.)/12.; 381 freq = EXP(freq*0.69314718055995); 382 freq *= 6.875; 383 return freq; 361 384 } 362 385 … … 381 404 } 382 405 383 /** returns 1 if wassilence is 0 and RMS(ibuf)<threshold 406 407 408 /** returns 1 if wassilence is 0 and RMS(ibuf)<threshold 384 409 * \bug mono 385 410 */ … … 411 436 412 437 if (loudness < threshold) 413 return 1.;438 return 1.; 414 439 else 415 return loudness;440 return loudness; 416 441 } 417 442 … … 426 451 } 427 452 //previous was positive 428 } else if ( input->data[i][j] <= 0. ) 453 } else if ( input->data[i][j] <= 0. ){ 429 454 zcr += 1; 430 455 } … … 446 471 } 447 472 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) { 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 { 463 489 #if FFTW3_SUPPORT 464 fftw_cleanup();490 fftw_cleanup(); 465 491 #else 466 492 #if FFTW3F_SUPPORT 467 fftwf_cleanup();493 fftwf_cleanup(); 468 494 #endif 469 495 #endif
Note: See TracChangeset
for help on using the changeset viewer.