Protect a-comp's display/state against NaN/Inf.
authorRobin Gareus <robin@gareus.org>
Tue, 29 Nov 2016 08:04:13 +0000 (09:04 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 29 Nov 2016 08:04:13 +0000 (09:04 +0100)
libs/plugins/a-comp.lv2/a-comp.c

index b27ab1d3f6600193d5b0ad6da56ae627f5a188c6..43d6b31b90efc79776820a5a2114c68eb55a4720 100644 (file)
 #  define M_PI 3.14159265358979323846
 #endif
 
+#ifdef COMPILER_MSVC
+#include <float.h>
+#define isfinite_local(val) (bool)_finite((double)val)
+#else
+#define isfinite_local isfinite
+#endif
+
 typedef enum {
        ACOMP_ATTACK = 0,
        ACOMP_RELEASE,
@@ -357,7 +364,10 @@ run_mono(LV2_Handle instance, uint32_t n_samples)
        acomp->makeup_gain = makeup_gain;
 
 #ifdef LV2_EXTENDED
-       acomp->v_lvl += .1 * (in_peak - acomp->v_lvl);  // crude LPF TODO use n_samples/rate TC
+       acomp->v_lvl += .1 * (in_peak - acomp->v_lvl) + 1e-12;  // crude LPF TODO use n_samples/rate TC
+       if (!isfinite_local (acomp->v_lvl)) {
+               acomp->v_lvl = 0.f;
+       }
        const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
        const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
        if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
@@ -491,7 +501,10 @@ run_stereo(LV2_Handle instance, uint32_t n_samples)
        acomp->makeup_gain = makeup_gain;
 
 #ifdef LV2_EXTENDED
-       acomp->v_lvl += .1 * (in_peak - acomp->v_lvl);  // crude LPF TODO use n_samples/rate TC
+       acomp->v_lvl += .1 * (in_peak - acomp->v_lvl) + 1e-12;  // crude LPF TODO use n_samples/rate TC
+       if (!isfinite_local (acomp->v_lvl)) {
+               acomp->v_lvl = 0.f;
+       }
        const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
        const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
        if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {