ref: 89823283829ebb7845de7f13d2212e2052b27b32
parent: 7166ef8f3c2c07ea2fe4a6b6b540aac96509e56d
author: Paul Brossier <piem@piem.org>
date: Sat Sep 5 07:07:11 EDT 2015
src/mathutils.c: optimized fvec_shift and aubio_level_lin
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -30,6 +30,14 @@
#include <Accelerate/Accelerate.h>
#endif
+#if !HAVE_AUBIO_DOUBLE
+#define aubio_cblas_xswap cblas_sswap
+#define aubio_cblas_dot cblas_sdot
+#else
+#define aubio_cblas_xswap cblas_dswap
+#define aubio_cblas_dot cblas_ddot
+#endif
+
/** Window types */
typedef enum
{
@@ -281,10 +289,15 @@
void
fvec_shift (fvec_t * s)
{
+#ifndef HAVE_ACCELERATE
uint_t j;
for (j = 0; j < s->length / 2; j++) {
ELEM_SWAP (s->data[j], s->data[j + s->length / 2]);
}
+#else
+ uint_t half = s->length / 2;
+ aubio_cblas_xswap(half, s->data, 1, s->data + half, 1);
+#endif
}
smpl_t
@@ -291,10 +304,14 @@
aubio_level_lin (fvec_t * f)
{
smpl_t energy = 0.;
+#ifndef HAVE_ACCELERATE
uint_t j;
for (j = 0; j < f->length; j++) {
energy += SQR (f->data[j]);
}
+#else
+ energy = aubio_cblas_dot(f->length, f->data, 1, f->data, 1);
+#endif
return energy / f->length;
}