shithub: aubio

Download patch

ref: 7166ef8f3c2c07ea2fe4a6b6b540aac96509e56d
parent: 6c8ef5833b56fa8ed2fb0a8200b8c36fea4a4dd0
author: Paul Brossier <piem@piem.org>
date: Sat Sep 5 07:05:43 EDT 2015

src/fvec.{c,h}: add fvec_weighted_copy

--- a/src/fvec.c
+++ b/src/fvec.c
@@ -121,6 +121,18 @@
 #endif /* HAVE_ACCELERATE */
 }
 
+void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out) {
+#ifndef HAVE_ACCELERATE
+  uint_t j;
+  uint_t length = MIN(s->length, weight->length);
+  for (j=0; j< length; j++) {
+    out->data[j] = in->data[j] * weight->data[j];
+  }
+#else
+  aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length);
+#endif /* HAVE_ACCELERATE */
+}
+
 void fvec_copy(fvec_t *s, fvec_t *t) {
   if (s->length != t->length) {
     AUBIO_ERR("trying to copy %d elements to %d elements \n",
--- a/src/fvec.h
+++ b/src/fvec.h
@@ -162,6 +162,15 @@
 */
 void fvec_copy(fvec_t *s, fvec_t *t);
 
+/** make a copy of a vector, applying weights to each element
+
+  \param in input vector
+  \param weight weights vector
+  \param out output vector
+
+*/
+void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out);
+
 #ifdef __cplusplus
 }
 #endif