src/mathutils.c: Accelerate fvec_sum and fvec_mean
authorPaul Brossier <piem@piem.org>
Wed, 2 Sep 2015 12:27:52 +0000 (14:27 +0200)
committerPaul Brossier <piem@piem.org>
Wed, 2 Sep 2015 12:27:52 +0000 (14:27 +0200)
src/mathutils.c

index 2298f46..4657bd8 100644 (file)
@@ -158,22 +158,39 @@ aubio_unwrap2pi (smpl_t phase)
 smpl_t
 fvec_mean (fvec_t * s)
 {
-  uint_t j;
   smpl_t tmp = 0.0;
+#ifndef HAVE_ACCELERATE
+  uint_t j;
   for (j = 0; j < s->length; j++) {
     tmp += s->data[j];
   }
   return tmp / (smpl_t) (s->length);
+#else
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_meanv(s->data, 1, &tmp, s->length);
+#else /* HAVE_AUBIO_DOUBLE */
+  vDSP_meanvD(s->data, 1, &tmp, s->length);
+#endif /* HAVE_AUBIO_DOUBLE */
+  return tmp;
+#endif /* HAVE_ACCELERATE */
 }
 
 smpl_t
 fvec_sum (fvec_t * s)
 {
-  uint_t j;
   smpl_t tmp = 0.0;
+#ifndef HAVE_ACCELERATE
+  uint_t j;
   for (j = 0; j < s->length; j++) {
     tmp += s->data[j];
   }
+#else
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_sve(s->data, 1, &tmp, s->length);
+#else /* HAVE_AUBIO_DOUBLE */
+  vDSP_sveD(s->data, 1, &tmp, s->length);
+#endif /* HAVE_AUBIO_DOUBLE */
+#endif /* HAVE_ACCELERATE */
   return tmp;
 }