ref: 7c07af2b9df2a3e9f48e7d51a5ba704205bea3ba
parent: 7609f6d349703dc16107e09f2a607115d2a9f543
author: Paul Brossier <piem@piem.org>
date: Tue Oct 15 21:21:29 EDT 2013
src/mathutils.c: use vDSP if available
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -26,6 +26,9 @@
#include "musicutils.h"
#include "config.h"
+#ifdef HAVE_ACCELERATE
+#include <Accelerate/Accelerate.h>
+#endif
/** Window types */
typedef enum
@@ -169,11 +172,20 @@
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;
}
@@ -180,11 +192,20 @@
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;
}
@@ -191,6 +212,7 @@
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++) {
@@ -197,6 +219,15 @@
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;
}
@@ -203,6 +234,7 @@
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++) {
@@ -209,6 +241,15 @@
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;
}