src/musicutils.h: add fvec_clamp, basic limiter
authorPaul Brossier <piem@piem.org>
Fri, 10 Mar 2017 19:16:28 +0000 (20:16 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 10 Mar 2017 19:16:28 +0000 (20:16 +0100)
src/mathutils.c
src/musicutils.h

index 12cbe01..cd1b719 100644 (file)
@@ -297,6 +297,17 @@ void fvec_push(fvec_t *in, smpl_t new_elem) {
   in->data[in->length - 1] = new_elem;
 }
 
+void fvec_clamp(fvec_t *in, smpl_t absmax) {
+  uint_t i;
+  for (i = 0; i < in->length; i++) {
+    if (in->data[i] > 0 && in->data[i] > ABS(absmax)) {
+      in->data[i] = absmax;
+    } else if (in->data[i] < 0 && in->data[i] < -ABS(absmax)) {
+      in->data[i] = -absmax;
+    }
+  }
+}
+
 smpl_t
 aubio_level_lin (const fvec_t * f)
 {
index f71d20b..b3b266e 100644 (file)
@@ -156,6 +156,14 @@ uint_t aubio_silence_detection (const fvec_t * v, smpl_t threshold);
 */
 smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold);
 
+/** clamp the values of a vector within the range [-abs(max), abs(max)]
+
+  \param in vector to clamp
+  \param max maximum value over which input vector elements should be clamped
+
+*/
+void fvec_clamp(fvec_t *in, smpl_t absmax);
+
 #ifdef __cplusplus
 }
 #endif