src/fvec.{c,h}: add fvec_weighted_copy
authorPaul Brossier <piem@piem.org>
Sat, 5 Sep 2015 09:05:43 +0000 (11:05 +0200)
committerPaul Brossier <piem@piem.org>
Sat, 5 Sep 2015 09:05:43 +0000 (11:05 +0200)
src/fvec.c
src/fvec.h

index e2361cc..619e542 100644 (file)
@@ -121,6 +121,18 @@ void fvec_weight(fvec_t *s, fvec_t *weight) {
 #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",
index c79295d..ceaec22 100644 (file)
@@ -162,6 +162,15 @@ void fvec_weight(fvec_t *s, fvec_t *weight);
 */
 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