shithub: aubio

Download patch

ref: 1dd95c7d85d270770d58bd9e80abae5e1b6a8220
parent: 5b896e015dbf103dd588ee6dd71e8b0ddad93efb
author: Paul Brossier <piem@piem.org>
date: Thu Sep 3 05:21:19 EDT 2015

src/fvec.c: use macros for single/double precision, prefere memset/memcpy over Accelerate

--- a/src/fvec.c
+++ b/src/fvec.c
@@ -23,6 +23,15 @@
 
 #ifdef HAVE_ACCELERATE
 #include <Accelerate/Accelerate.h>
+#if !HAVE_AUBIO_DOUBLE
+#define aubio_vDSP_mmov       vDSP_mmov
+#define aubio_vDSP_vmul       vDSP_vmul
+#define aubio_vDSP_vfill      vDSP_vfill
+#else /* HAVE_AUBIO_DOUBLE */
+#define aubio_vDSP_mmov       vDSP_mmovD
+#define aubio_vDSP_vmul       vDSP_vmulD
+#define aubio_vDSP_vfill      vDSP_vfillD
+#endif /* HAVE_AUBIO_DOUBLE */
 #endif
 
 fvec_t * new_fvec( uint_t length) {
@@ -70,27 +79,19 @@
     s->data[j] = val;
   }
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vfill(&val, s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vfillD(&val, s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
+  aubio_vDSP_vfill(&val, s->data, 1, s->length);
 #endif
 }
 
 void fvec_zeros(fvec_t *s) {
-#ifndef HAVE_ACCELERATE
-#if HAVE_MEMCPY_HACKS
+#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
+  fvec_set_all (s, 0.);
+#else
+#if defined(HAVE_MEMCPY_HACKS)
   memset(s->data, 0, s->length * sizeof(smpl_t));
 #else
-  fvec_set_all (s, 0.);
+  aubio_vDSP_vclr(s->data, 1, s->length);
 #endif
-#else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vclr(s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vclrD(s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
 #endif
 }
 
@@ -113,11 +114,7 @@
     s->data[j] *= weight->data[j];
   }
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vmulD(s->data, 1, weight->data, 1, s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
+  aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
 #endif /* HAVE_ACCELERATE */
 }
 
@@ -127,20 +124,16 @@
         s->length, t->length);
     return;
   }
-#ifndef HAVE_ACCELERATE
-#if HAVE_MEMCPY_HACKS
-  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
-#else
+#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
   uint_t j;
   for (j=0; j< t->length; j++) {
     t->data[j] = s->data[j];
   }
-#endif
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_mmovD(s->data, t->data, 1, s->length, 1, 1);
-#endif /* HAVE_AUBIO_DOUBLE */
-#endif /* HAVE_ACCELERATE */
+#if defined(HAVE_MEMCPY_HACKS)
+  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
+#else
+  aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
+#endif
+#endif
 }