summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-11-29 09:04:13 +0100
committerRobin Gareus <robin@gareus.org>2016-11-29 09:04:13 +0100
commit5f1d94a7b23c828711741c072e41697ceaea3a13 (patch)
tree742ad127b831a0b52b1b919ff0b0c1b323cdf929
parent0fe62a34dab8dad7be81f9f010f2f74ab2bcb8c1 (diff)
Protect a-comp's display/state against NaN/Inf.
-rw-r--r--libs/plugins/a-comp.lv2/a-comp.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/libs/plugins/a-comp.lv2/a-comp.c b/libs/plugins/a-comp.lv2/a-comp.c
index b27ab1d3f6..43d6b31b90 100644
--- a/libs/plugins/a-comp.lv2/a-comp.c
+++ b/libs/plugins/a-comp.lv2/a-comp.c
@@ -31,6 +31,13 @@
# 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) {