summaryrefslogtreecommitdiff
path: root/libs/plugins
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-08-27 14:10:51 +0200
committerRobin Gareus <robin@gareus.org>2016-08-27 14:10:51 +0200
commit62de4d0c31a7bb2e5f9688a8576dc65039b51e8e (patch)
treebc91ad433b2c03dd487123395a98c5635824ba9e /libs/plugins
parent36776bafcdac6b86fb420785c7936c06c5ad7a29 (diff)
add NaN/Inf protection now that bypass no longer de/activates
Diffstat (limited to 'libs/plugins')
-rw-r--r--libs/plugins/a-eq.lv2/a-eq.c18
-rw-r--r--libs/plugins/a-reverb.lv2/a-reverb.c21
2 files changed, 37 insertions, 2 deletions
diff --git a/libs/plugins/a-eq.lv2/a-eq.c b/libs/plugins/a-eq.lv2/a-eq.c
index deac7a641e..d286552e03 100644
--- a/libs/plugins/a-eq.lv2/a-eq.c
+++ b/libs/plugins/a-eq.lv2/a-eq.c
@@ -23,6 +23,13 @@
#include <stdbool.h>
#include <stdio.h>
+#ifdef COMPILER_MSVC
+#include <float.h>
+#define isfinite_local(val) (bool)_finite((double)val)
+#else
+#define isfinite_local isfinite
+#endif
+
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
#ifdef LV2_EXTENDED
@@ -92,6 +99,13 @@ static void linear_svf_reset(struct linear_svf *self)
self->s[0] = self->s[1] = 0.0;
}
+static void linear_svf_protect(struct linear_svf *self)
+{
+ if (!isfinite_local (self->s[0]) || !isfinite_local (self->s[1])) {
+ linear_svf_reset (self);
+ }
+}
+
typedef struct {
float* f0[BANDS];
float* g[BANDS];
@@ -432,6 +446,10 @@ run(LV2_Handle instance, uint32_t n_samples)
offset += block;
}
+ for (uint32_t j = 0; j < BANDS; j++) {
+ linear_svf_protect(&aeq->v_filter[j]);
+ }
+
#ifdef LV2_EXTENDED
if (aeq->need_expose && aeq->queue_draw) {
aeq->need_expose = false;
diff --git a/libs/plugins/a-reverb.lv2/a-reverb.c b/libs/plugins/a-reverb.lv2/a-reverb.c
index ed4a247406..40811bdf91 100644
--- a/libs/plugins/a-reverb.lv2/a-reverb.c
+++ b/libs/plugins/a-reverb.lv2/a-reverb.c
@@ -32,6 +32,13 @@
#define RV_NZ 7
#define DENORMAL_PROTECT (1e-14)
+#ifdef COMPILER_MSVC
+#include <float.h>
+#define isfinite_local(val) (bool)_finite((double)val)
+#else
+#define isfinite_local isfinite
+#endif
+
typedef struct {
float* delays[2][RV_NZ]; /**< delay line buffer */
@@ -164,10 +171,15 @@ reverb (b_reverb* r,
for (size_t i = 0; i < n_samples; ++i) {
int j;
float y;
- const float xo0 = *xp0++;
- const float xo1 = *xp1++;
+ float xo0 = *xp0++;
+ float xo1 = *xp1++;
+ if (!isfinite_local(xo0) || fabsf (xo0) > 10.f) { xo0 = 0; }
+ if (!isfinite_local(xo1) || fabsf (xo1) > 10.f) { xo1 = 0; }
+ xo0 += DENORMAL_PROTECT;
+ xo1 += DENORMAL_PROTECT;
const float x0 = y_1_0 + (inputGain * xo0);
const float x1 = y_1_1 + (inputGain * xo1);
+
float xa = 0.0;
float xb = 0.0;
/* First we do four feedback comb filters (ie parallel delay lines,
@@ -220,6 +232,11 @@ reverb (b_reverb* r,
*yp1++ = ((wet * y) + (dry * xo1));
}
+ if (!isfinite_local(y_1_0)) { y_1_0 = 0; }
+ if (!isfinite_local(yy1_1)) { yy1_0 = 0; }
+ if (!isfinite_local(y_1_1)) { y_1_1 = 0; }
+ if (!isfinite_local(yy1_1)) { yy1_1 = 0; }
+
r->y_1_0 = y_1_0 + DENORMAL_PROTECT;
r->yy1_0 = yy1_0 + DENORMAL_PROTECT;
r->y_1_1 = y_1_1 + DENORMAL_PROTECT;