From: Paul Brossier Date: Fri, 10 Mar 2017 19:16:28 +0000 (+0100) Subject: src/musicutils.h: add fvec_clamp, basic limiter X-Git-Tag: 0.4.5~20^2~32 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=b799241bdde98885bb18b0f2e2cc06b063eb2d13;p=aubio.git src/musicutils.h: add fvec_clamp, basic limiter --- diff --git a/src/mathutils.c b/src/mathutils.c index 12cbe017..cd1b719c 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -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) { diff --git a/src/musicutils.h b/src/musicutils.h index f71d20ba..b3b266e4 100644 --- a/src/musicutils.h +++ b/src/musicutils.h @@ -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