src/mathutils.h: add fvec_push
authorPaul Brossier <piem@piem.org>
Fri, 10 Mar 2017 16:17:33 +0000 (17:17 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 10 Mar 2017 16:17:33 +0000 (17:17 +0100)
src/mathutils.c
src/mathutils.h

index 45f61c9..12cbe01 100644 (file)
@@ -289,6 +289,14 @@ fvec_ishift (fvec_t * s)
   }
 }
 
+void fvec_push(fvec_t *in, smpl_t new_elem) {
+  uint_t i;
+  for (i = 0; i < in->length - 1; i++) {
+    in->data[i] = in->data[i + 1];
+  }
+  in->data[in->length - 1] = new_elem;
+}
+
 smpl_t
 aubio_level_lin (const fvec_t * f)
 {
index 6638f69..7bef5a4 100644 (file)
@@ -117,6 +117,17 @@ of the resulting spectrum. See Amalia de Götzen's paper referred to above.
 */
 void fvec_ishift (fvec_t * v);
 
+/** push a new element to the end of a vector, erasing the first element and
+ * sliding all others
+
+  \param in vector to push to
+  \param new_elem new_element to add at the end of the vector
+
+  In numpy words, this is equivalent to: in = np.concatenate([in, [new_elem]])[1:]
+
+*/
+void fvec_push(fvec_t *in, smpl_t new_elem);
+
 /** compute the sum of all elements of a vector
 
   \param v vector to compute the sum of