src/mathutils.c: use vDSP if available
authorPaul Brossier <piem@piem.org>
Tue, 15 Oct 2013 23:21:29 +0000 (01:21 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 15 Oct 2013 23:21:29 +0000 (01:21 +0200)
src/mathutils.c

index 00f7e09..812e297 100644 (file)
@@ -26,6 +26,9 @@
 #include "musicutils.h"
 #include "config.h"
 
+#ifdef HAVE_ACCELERATE
+#include <Accelerate/Accelerate.h>
+#endif
 
 /** Window types */
 typedef enum
@@ -169,46 +172,84 @@ fvec_sum (fvec_t * s)
 smpl_t
 fvec_max (fvec_t * s)
 {
+#ifndef HAVE_ACCELERATE
   uint_t j;
   smpl_t tmp = 0.0;
   for (j = 0; j < s->length; j++) {
     tmp = (tmp > s->data[j]) ? tmp : s->data[j];
   }
+#else
+  smpl_t tmp = 0.;
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_maxv(s->data, 1, &tmp, s->length);
+#else
+  vDSP_maxvD(s->data, 1, &tmp, s->length);
+#endif
+#endif
   return tmp;
 }
 
 smpl_t
 fvec_min (fvec_t * s)
 {
+#ifndef HAVE_ACCELERATE
   uint_t j;
   smpl_t tmp = s->data[0];
   for (j = 0; j < s->length; j++) {
     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
   }
+#else
+  smpl_t tmp = 0.;
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_minv(s->data, 1, &tmp, s->length);
+#else
+  vDSP_minvD(s->data, 1, &tmp, s->length);
+#endif
+#endif
   return tmp;
 }
 
 uint_t
 fvec_min_elem (fvec_t * s)
 {
+#ifndef HAVE_ACCELERATE
   uint_t j, pos = 0.;
   smpl_t tmp = s->data[0];
   for (j = 0; j < s->length; j++) {
     pos = (tmp < s->data[j]) ? pos : j;
     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
   }
+#else
+  smpl_t tmp = 0.;
+  uint_t pos = 0.;
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
+#else
+  vDSP_minviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
+#endif
+#endif
   return pos;
 }
 
 uint_t
 fvec_max_elem (fvec_t * s)
 {
+#ifndef HAVE_ACCELERATE
   uint_t j, pos = 0;
   smpl_t tmp = 0.0;
   for (j = 0; j < s->length; j++) {
     pos = (tmp > s->data[j]) ? pos : j;
     tmp = (tmp > s->data[j]) ? tmp : s->data[j];
   }
+#else
+  smpl_t tmp = 0.;
+  uint_t pos = 0.;
+#if !HAVE_AUBIO_DOUBLE
+  vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
+#else
+  vDSP_maxviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
+#endif
+#endif
   return pos;
 }