Changeset f264b17 for src/mathutils.c
- Timestamp:
- Jun 22, 2016, 1:00:10 PM (9 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:
- 4b9443c4
- Parents:
- 60fc05b (diff), 6769586 (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
r60fc05b rf264b17 26 26 #include "musicutils.h" 27 27 #include "config.h" 28 29 #ifdef HAVE_ACCELERATE30 #include <Accelerate/Accelerate.h>31 #endif32 28 33 29 /** Window types */ … … 167 163 return tmp / (smpl_t) (s->length); 168 164 #else 169 #if !HAVE_AUBIO_DOUBLE 170 vDSP_meanv(s->data, 1, &tmp, s->length); 171 #else /* HAVE_AUBIO_DOUBLE */ 172 vDSP_meanvD(s->data, 1, &tmp, s->length); 173 #endif /* HAVE_AUBIO_DOUBLE */ 165 aubio_vDSP_meanv(s->data, 1, &tmp, s->length); 174 166 return tmp; 175 167 #endif /* HAVE_ACCELERATE */ … … 186 178 } 187 179 #else 188 #if !HAVE_AUBIO_DOUBLE 189 vDSP_sve(s->data, 1, &tmp, s->length); 190 #else /* HAVE_AUBIO_DOUBLE */ 191 vDSP_sveD(s->data, 1, &tmp, s->length); 192 #endif /* HAVE_AUBIO_DOUBLE */ 180 aubio_vDSP_sve(s->data, 1, &tmp, s->length); 193 181 #endif /* HAVE_ACCELERATE */ 194 182 return tmp; … … 206 194 #else 207 195 smpl_t tmp = 0.; 208 #if !HAVE_AUBIO_DOUBLE 209 vDSP_maxv(s->data, 1, &tmp, s->length); 210 #else 211 vDSP_maxvD(s->data, 1, &tmp, s->length); 212 #endif 196 aubio_vDSP_maxv(s->data, 1, &tmp, s->length); 213 197 #endif 214 198 return tmp; … … 226 210 #else 227 211 smpl_t tmp = 0.; 228 #if !HAVE_AUBIO_DOUBLE 229 vDSP_minv(s->data, 1, &tmp, s->length); 230 #else 231 vDSP_minvD(s->data, 1, &tmp, s->length); 232 #endif 212 aubio_vDSP_minv(s->data, 1, &tmp, s->length); 233 213 #endif 234 214 return tmp; … … 248 228 smpl_t tmp = 0.; 249 229 uint_t pos = 0.; 250 #if !HAVE_AUBIO_DOUBLE 251 vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 252 #else 253 vDSP_minviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 254 #endif 230 aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 255 231 #endif 256 232 return pos; … … 270 246 smpl_t tmp = 0.; 271 247 uint_t pos = 0.; 272 #if !HAVE_AUBIO_DOUBLE 273 vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 274 #else 275 vDSP_maxviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 276 #endif 248 aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length); 277 249 #endif 278 250 return pos; … … 282 254 fvec_shift (fvec_t * s) 283 255 { 284 uint_t j; 285 for (j = 0; j < s->length / 2; j++) { 286 ELEM_SWAP (s->data[j], s->data[j + s->length / 2]); 287 } 288 } 289 290 smpl_t 291 aubio_level_lin (fvec_t * f) 256 uint_t half = s->length / 2, start = half, j; 257 // if length is odd, middle element is moved to the end 258 if (2 * half < s->length) start ++; 259 #ifndef HAVE_ATLAS 260 for (j = 0; j < half; j++) { 261 ELEM_SWAP (s->data[j], s->data[j + start]); 262 } 263 #else 264 aubio_cblas_swap(half, s->data, 1, s->data + start, 1); 265 #endif 266 if (start != half) { 267 for (j = 0; j < half; j++) { 268 ELEM_SWAP (s->data[j + start - 1], s->data[j + start]); 269 } 270 } 271 } 272 273 void 274 fvec_ishift (fvec_t * s) 275 { 276 uint_t half = s->length / 2, start = half, j; 277 // if length is odd, middle element is moved to the beginning 278 if (2 * half < s->length) start ++; 279 #ifndef HAVE_ATLAS 280 for (j = 0; j < half; j++) { 281 ELEM_SWAP (s->data[j], s->data[j + start]); 282 } 283 #else 284 aubio_cblas_swap(half, s->data, 1, s->data + start, 1); 285 #endif 286 if (start != half) { 287 for (j = 0; j < half; j++) { 288 ELEM_SWAP (s->data[half], s->data[j]); 289 } 290 } 291 } 292 293 smpl_t 294 aubio_level_lin (const fvec_t * f) 292 295 { 293 296 smpl_t energy = 0.; 297 #ifndef HAVE_ATLAS 294 298 uint_t j; 295 299 for (j = 0; j < f->length; j++) { 296 300 energy += SQR (f->data[j]); 297 301 } 302 #else 303 energy = aubio_cblas_dot(f->length, f->data, 1, f->data, 1); 304 #endif 298 305 return energy / f->length; 299 306 } … … 434 441 } 435 442 436 smpl_t fvec_quadratic_peak_pos ( fvec_t * x, uint_t pos) {443 smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t pos) { 437 444 smpl_t s0, s1, s2; uint_t x0, x2; 445 smpl_t half = .5, two = 2.; 438 446 if (pos == 0 || pos == x->length - 1) return pos; 439 447 x0 = (pos < 1) ? pos : pos - 1; … … 444 452 s1 = x->data[pos]; 445 453 s2 = x->data[x2]; 446 return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);454 return pos + half * (s0 - s2 ) / (s0 - two * s1 + s2); 447 455 } 448 456 … … 458 466 } 459 467 460 uint_t fvec_peakpick( fvec_t * onset, uint_t pos) {468 uint_t fvec_peakpick(const fvec_t * onset, uint_t pos) { 461 469 uint_t tmp=0; 462 470 tmp = (onset->data[pos] > onset->data[pos-1] … … 545 553 546 554 smpl_t 547 aubio_db_spl ( fvec_t * o)555 aubio_db_spl (const fvec_t * o) 548 556 { 549 557 return 10. * LOG10 (aubio_level_lin (o)); … … 551 559 552 560 uint_t 553 aubio_silence_detection ( fvec_t * o, smpl_t threshold)561 aubio_silence_detection (const fvec_t * o, smpl_t threshold) 554 562 { 555 563 return (aubio_db_spl (o) < threshold); … … 591 599 592 600 void 593 aubio_autocorr ( fvec_t * input, fvec_t * output)601 aubio_autocorr (const fvec_t * input, fvec_t * output) 594 602 { 595 603 uint_t i, j, length = input->length;
Note: See TracChangeset
for help on using the changeset viewer.