diff --git a/README.md b/README.md
index be7152f..00f9317 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ You can find information and documentation [on the official web page](https://ww
## Subfolders
-* examples: synth and an effect examples in VST3, Web Audio, and Daisy Seed formats;
+* examples: synth and an effect examples in VST3, Web Audio, Daisy Seed, Android ap appp, and iOS app formats;
* include: header files.
## Legal
diff --git a/examples/fx_noise_gate/src/bw_example_fx_noise_gate.c b/examples/fx_noise_gate/src/bw_example_fx_noise_gate.c
index 072f71c..7f8aab9 100644
--- a/examples/fx_noise_gate/src/bw_example_fx_noise_gate.c
+++ b/examples/fx_noise_gate/src/bw_example_fx_noise_gate.c
@@ -30,7 +30,7 @@ void bw_example_fx_noise_gate_set_sample_rate(bw_example_fx_noise_gate *instance
void bw_example_fx_noise_gate_reset(bw_example_fx_noise_gate *instance) {
bw_noise_gate_reset_coeffs(&instance->noise_gate_coeffs);
- bw_noise_gate_reset_state(&instance->noise_gate_coeffs, &instance->noise_gate_state);
+ bw_noise_gate_reset_state(&instance->noise_gate_coeffs, &instance->noise_gate_state, 0.f, 0.f);
}
void bw_example_fx_noise_gate_process(bw_example_fx_noise_gate *instance, const float** x, float** y, int n_samples) {
diff --git a/examples/fx_noise_gate/vst3/Makefile b/examples/fx_noise_gate/vst3/Makefile
index bb6a30a..46b3460 100644
--- a/examples/fx_noise_gate/vst3/Makefile
+++ b/examples/fx_noise_gate/vst3/Makefile
@@ -4,3 +4,6 @@ NAME := bw_example_fx_noise_gate
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_noise_gate.c
include ${ROOT_DIR}/../../common/vst3/vst3.mk
+
+CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
+#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP
diff --git a/examples/fxpp_noise_gate/vst3/Makefile b/examples/fxpp_noise_gate/vst3/Makefile
index b46c61e..1ee4032 100644
--- a/examples/fxpp_noise_gate/vst3/Makefile
+++ b/examples/fxpp_noise_gate/vst3/Makefile
@@ -4,3 +4,6 @@ NAME := bw_example_fxpp_noise_gate
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_noise_gate.cpp
include ${ROOT_DIR}/../../common/vst3/vst3.mk
+
+CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
+#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP
diff --git a/include/bw_comp.h b/include/bw_comp.h
index 44799c7..1248a57 100644
--- a/include/bw_comp.h
+++ b/include/bw_comp.h
@@ -46,6 +46,9 @@
*
Added overloaded C++ process()
function taking
* C-style arrays as arguments.
* Fixed missing smoothing filter initialization.
+ * Fixed missing forced coefficients' update in
+ * bw_comp_reset_coeffs()
.
+ * Improved and strengthened algorithm.
* Removed usage of reserved identifiers.
* Clearly specified parameter validity ranges.
* Added debugging code.
@@ -364,6 +367,7 @@ struct bw_comp_coeffs {
// Coefficients
float kc;
+ float lt;
// Parameters
float thresh;
@@ -420,6 +424,15 @@ static inline void bw_comp_set_sample_rate(
BW_ASSERT_DEEP(coeffs->state == bw_comp_coeffs_state_set_sample_rate);
}
+static inline void bw_comp_do_update_coeffs_audio(
+ bw_comp_coeffs * BW_RESTRICT coeffs) {
+ bw_env_follow_update_coeffs_audio(&coeffs->env_follow_coeffs);
+ bw_gain_update_coeffs_audio(&coeffs->gain_coeffs);
+ bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
+ coeffs->kc = 1.f - bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio);
+ coeffs->lt = bw_log2f(bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state));
+}
+
static inline void bw_comp_reset_coeffs(
bw_comp_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
@@ -430,6 +443,7 @@ static inline void bw_comp_reset_coeffs(
bw_gain_reset_coeffs(&coeffs->gain_coeffs);
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio);
+ bw_comp_do_update_coeffs_audio(coeffs);
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_comp_coeffs_state_reset_coeffs;
@@ -449,19 +463,10 @@ static inline float bw_comp_reset_state(
BW_ASSERT_DEEP(coeffs->state >= bw_comp_coeffs_state_reset_coeffs);
BW_ASSERT(state != NULL);
BW_ASSERT(bw_is_finite(x_0));
+ BW_ASSERT(bw_is_finite(x_sc_0));
const float env = bw_env_follow_reset_state(&coeffs->env_follow_coeffs, &state->env_follow_state, x_sc_0);
- const float thresh = bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state);
- float y;
- if (env > thresh) {
- float v = thresh * bw_rcpf(env);
- if (v >= 1.175494350822287e-38f) {
- v = coeffs->kc * bw_log2f(v);
- y = v > -126.f ? bw_pow2f(v) * x_0 : thresh;
- } else
- y = thresh;
- } else
- y = x_0;
+ float y = env > bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state) ? bw_pow2f(coeffs->kc * (coeffs->lt - bw_log2f(env))) * x_0 : x_0;
y = bw_gain_get_gain_cur(&coeffs->gain_coeffs) * y;
#ifdef BW_DEBUG_DEEP
@@ -526,6 +531,7 @@ static inline void bw_comp_update_coeffs_audio(
bw_gain_update_coeffs_audio(&coeffs->gain_coeffs);
bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
coeffs->kc = 1.f - bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio);
+ coeffs->lt = bw_log2f(bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state));
BW_ASSERT_DEEP(bw_comp_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_comp_coeffs_state_reset_coeffs);
@@ -545,17 +551,7 @@ static inline float bw_comp_process1(
BW_ASSERT(bw_is_finite(x_sc));
const float env = bw_env_follow_process1(&coeffs->env_follow_coeffs, &state->env_follow_state, x_sc);
- const float thresh = bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state);
- float y;
- if (env > thresh) {
- float v = thresh * bw_rcpf(env);
- if (v >= 1.175494350822287e-38f) {
- v = coeffs->kc * bw_log2f(v);
- y = v > -126.f ? bw_pow2f(v) * x : thresh;
- } else
- y = thresh;
- } else
- y = x;
+ float y = env > bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state) ? bw_pow2f(coeffs->kc * (coeffs->lt - bw_log2f(env))) * x : x;
y = bw_gain_process1(&coeffs->gain_coeffs, y);
BW_ASSERT_DEEP(bw_comp_coeffs_is_valid(coeffs));
@@ -580,6 +576,8 @@ static inline void bw_comp_process(
BW_ASSERT_DEEP(bw_comp_state_is_valid(coeffs, state));
BW_ASSERT(x != NULL);
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
+ BW_ASSERT(x_sc != NULL);
+ BW_ASSERT_DEEP(bw_has_only_finite(x_sc, n_samples));
BW_ASSERT(y != NULL);
bw_comp_update_coeffs_ctrl(coeffs);
@@ -748,6 +746,8 @@ static inline char bw_comp_coeffs_is_valid(
if (coeffs->state >= bw_comp_coeffs_state_reset_coeffs) {
if (!bw_is_finite(coeffs->kc) || coeffs->kc < 0.f || coeffs->kc > 1.f)
return 0;
+ if (!bw_is_finite(coeffs->lt))
+ return 0;
if (!bw_one_pole_state_is_valid(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state))
return 0;
diff --git a/include/bw_math.h b/include/bw_math.h
index 3f706e9..6cfa6f6 100644
--- a/include/bw_math.h
+++ b/include/bw_math.h
@@ -307,7 +307,7 @@ static inline float bw_rcpf(
/*! <<<```
* Returns the reciprocal of `x` (i.e., `1.f / x`).
*
- * |`x`| must be in [2^-90, 2^90].
+ * |`x`| must be in [`8.077935669463161e-28f`, `1.237940039285380e+27`].
*
* Relative error < 0.0013%.
*
diff --git a/include/bw_noise_gate.h b/include/bw_noise_gate.h
index b07ddc4..0af77b8 100644
--- a/include/bw_noise_gate.h
+++ b/include/bw_noise_gate.h
@@ -29,6 +29,12 @@
*
* - Version 1.0.0:
*
+ * - Added
bw_noise_gate_reset_state_multi()
and updated
+ * C++ API in this regard.
+ * - Now
bw_noise_gate_reset_state()
returns the initial
+ * output value.
+ * - Added overloaded C++
reset()
functions taking
+ * arrays as arguments.
* bw_noise_gate_process()
and
* bw_noise_gate_process_multi()
now use
* size_t
to count samples and channels.
@@ -37,7 +43,13 @@
* - Moved C++ code to C header.
* - Added overloaded C++
process()
function taking
* C-style arrays as arguments.
+ * - Fixed missing smoothing filter initialization.
+* - Fixed missing forced coefficients' update in
+ *
bw_noise_gate_reset_coeffs()
.
+ * - Improved and strengthened algorithm.
* - Removed usage of reserved identifiers.
+ * - Clearly specified parameter validity ranges.
+ * - Added debugging code.
*
*
* - Version 0.6.0:
@@ -84,43 +96,77 @@ typedef struct bw_noise_gate_state bw_noise_gate_state;
*
* #### bw_noise_gate_init()
* ```>>> */
-static inline void bw_noise_gate_init(bw_noise_gate_coeffs *BW_RESTRICT coeffs);
+static inline void bw_noise_gate_init(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Initializes input parameter values in `coeffs`.
*
* #### bw_noise_gate_set_sample_rate()
* ```>>> */
-static inline void bw_noise_gate_set_sample_rate(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float sample_rate);
+static inline void bw_noise_gate_set_sample_rate(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value in `coeffs`.
*
* #### bw_noise_gate_reset_coeffs()
* ```>>> */
-static inline void bw_noise_gate_reset_coeffs(bw_noise_gate_coeffs *BW_RESTRICT coeffs);
+static inline void bw_noise_gate_reset_coeffs(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Resets coefficients in `coeffs` to assume their target values.
*
* #### bw_noise_gate_reset_state()
* ```>>> */
-static inline void bw_noise_gate_reset_state(const bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state);
+static inline float bw_noise_gate_reset_state(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ float x_0,
+ float x_sc_0);
/*! <<<```
- * Resets the given `state` to its initial values using the given `coeffs`.
+ * Resets the given `state` to its initial values using the given `coeffs`
+ * and the initial input value `x_0` and sidechain input value `x_sc_0`.
+ *
+ * Returns the corresponding initial output value.
+ *
+ * #### bw_noise_gate_reset_state_multi()
+ * ```>>> */
+static inline void bw_noise_gate_reset_state_multi(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT const * BW_RESTRICT state,
+ const float * x_0,
+ const float * x_sc_0,
+ float * y_0,
+ size_t n_channels);
+/*! <<<```
+ * Resets each of the `n_channels` `state`s to its initial values using the
+ * given `coeffs` and the corresponding initial input value in the `x_0`
+ * array and sidechain input value in the `x_sc_0` array.
+ *
+ * The corresponding initial output values are written into the `y_0` array,
+ * if not `NULL`.
*
* #### bw_noise_gate_update_coeffs_ctrl()
* ```>>> */
-static inline void bw_noise_gate_update_coeffs_ctrl(bw_noise_gate_coeffs *BW_RESTRICT coeffs);
+static inline void bw_noise_gate_update_coeffs_ctrl(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Triggers control-rate update of coefficients in `coeffs`.
*
* #### bw_noise_gate_update_coeffs_audio()
* ```>>> */
-static inline void bw_noise_gate_update_coeffs_audio(bw_noise_gate_coeffs *BW_RESTRICT coeffs);
+static inline void bw_noise_gate_update_coeffs_audio(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Triggers audio-rate update of coefficients in `coeffs`.
*
* #### bw_noise_gate_process1()
* ```>>> */
-static inline float bw_noise_gate_process1(const bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, float x, float x_sc);
+static inline float bw_noise_gate_process1(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ float x,
+ float x_sc);
/*! <<<```
* Processes one input sample `x` and the corresponding sidechain input
* sample `x_sc` using `coeffs`, while using and updating `state`. Returns
@@ -128,7 +174,13 @@ static inline float bw_noise_gate_process1(const bw_noise_gate_coeffs *BW_RESTRI
*
* #### bw_noise_gate_process()
* ```>>> */
-static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, size_t n_samples);
+static inline void bw_noise_gate_process(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ const float * x,
+ const float * x_sc,
+ float * y,
+ size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the input buffer `x` and the first
* `n_samples` of the sidechain input buffer `x_sc`, and fills the first
@@ -137,7 +189,14 @@ static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeff
*
* #### bw_noise_gate_process_multi()
* ```>>> */
-static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT const *BW_RESTRICT state, const float * const *x, const float * const *x_sc, float * const *y, size_t n_channels, size_t n_samples);
+static inline void bw_noise_gate_process_multi(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT const * BW_RESTRICT state,
+ const float * const * x,
+ const float * const * x_sc,
+ float * const * y,
+ size_t n_channels,
+ size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and
* the first `n_samples` of the `n_channels` sidechain input buffers `x_sc`,
@@ -147,48 +206,94 @@ static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT
*
* #### bw_noise_gate_set_thresh_lin()
* ```>>> */
-static inline void bw_noise_gate_set_thresh_lin(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value);
+static inline void bw_noise_gate_set_thresh_lin(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value);
/*! <<<```
* Sets the threshold `value` (linear) in `coeffs`.
*
+ * Valid range: [`1e-20f`, `1e20f`].
+ *
* Default value: `1.f`.
*
* #### bw_noise_gate_set_thresh_dBFS()
* ```>>> */
-static inline void bw_noise_gate_set_thresh_dBFS(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value);
+static inline void bw_noise_gate_set_thresh_dBFS(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value);
/*! <<<```
* Sets the threshold `value` (dBFS) in `coeffs`.
*
+ * Valid range: [`-400.f`, `400.f`].
+ *
* Default value: `0.f`.
*
* #### bw_noise_gate_set_ratio()
* ```>>> */
-static inline void bw_noise_gate_set_ratio(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value);
+static inline void bw_noise_gate_set_ratio(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value);
/*! <<<```
* Sets the copmpression ratio `value` in `coeffs`.
*
* `value` is actually the slope of the gain curve below the threshold, hence
* `1.f` means no gating and `INIFINITY` leads to a hard gate.
*
- * Valid range: [`1.f`, `INFINITY`].
+ * `value` must be greater than or equal to `1.f`.
*
* Default value: `1.f`.
*
* #### bw_noise_gate_set_attack_tau()
* ```>>> */
-static inline void bw_noise_gate_set_attack_tau(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value);
+static inline void bw_noise_gate_set_attack_tau(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value);
/*! <<<```
* Sets the attack time constant `value` (s) in `coeffs`.
*
+ * `value` must be non-negative.
+ *
* Default value: `0.f`.
*
* #### bw_noise_gate_set_release_tau()
* ```>>> */
-static inline void bw_noise_gate_set_release_tau(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value);
+static inline void bw_noise_gate_set_release_tau(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value);
/*! <<<```
* Sets the release time constant `value` (s) in `coeffs`.
*
+ * `value` must be non-negative.
+ *
* Default value: `0.f`.
+ *
+ * #### bw_noise_gate_coeffs_is_valid()
+ * ```>>> */
+static inline char bw_noise_gate_coeffs_is_valid(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs);
+/*! <<<```
+ * Tries to determine whether `coeffs` is valid and returns non-`0` if it
+ * seems to be the case and `0` if it is certainly not. False positives are
+ * possible, false negatives are not.
+ *
+ * `coeffs` must at least point to a readable memory block of size greater
+ * than or equal to that of `bw_noise_gate_coeffs`.
+ *
+ * #### bw_noise_gate_state_is_valid()
+ * ```>>> */
+static inline char bw_noise_gate_state_is_valid(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ const bw_noise_gate_state * BW_RESTRICT state);
+/*! <<<```
+ * Tries to determine whether `state` is valid and returns non-`0` if it
+ * seems to be the case and `0` if it is certainly not. False positives are
+ * possible, false negatives are not.
+ *
+ * If `coeffs` is not `NULL` extra cross-checks might be performed (`state`
+ * is supposed to be associated to `coeffs`).
+ *
+ * `state` must at least point to a readable memory block of size greater
+ * than or equal to that of `bw_noise_gate_state`.
* }}} */
#ifdef __cplusplus
@@ -208,100 +313,398 @@ static inline void bw_noise_gate_set_release_tau(bw_noise_gate_coeffs *BW_RESTRI
extern "C" {
#endif
+#ifdef BW_DEBUG_DEEP
+enum bw_noise_gate_coeffs_state {
+ bw_noise_gate_coeffs_state_invalid,
+ bw_noise_gate_coeffs_state_init,
+ bw_noise_gate_coeffs_state_set_sample_rate,
+ bw_noise_gate_coeffs_state_reset_coeffs
+};
+#endif
+
struct bw_noise_gate_coeffs {
- // Sub-noise_gateonents
- bw_env_follow_coeffs env_follow_coeffs;
- bw_one_pole_coeffs smooth_coeffs;
- bw_one_pole_state smooth_thresh_state;
- bw_one_pole_state smooth_ratio_state;
+#ifdef BW_DEBUG_DEEP
+ uint32_t hash;
+ enum bw_noise_gate_coeffs_state state;
+ uint32_t reset_id;
+#endif
+
+ // Sub-components
+ bw_env_follow_coeffs env_follow_coeffs;
+ bw_one_pole_coeffs smooth_coeffs;
+ bw_one_pole_state smooth_thresh_state;
+ bw_one_pole_state smooth_ratio_state;
// Coefficients
- float kc;
+ float kc;
+ float lt;
// Parameters
- float thresh;
- float ratio;
+ float thresh;
+ float ratio;
};
struct bw_noise_gate_state {
+#ifdef BW_DEBUG_DEEP
+ uint32_t hash;
+ uint32_t coeffs_reset_id;
+#endif
+
+ // Sub-components
bw_env_follow_state env_follow_state;
};
-static inline void bw_noise_gate_init(bw_noise_gate_coeffs *BW_RESTRICT coeffs) {
+static inline void bw_noise_gate_init(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
+ BW_ASSERT(coeffs != NULL);
+
bw_env_follow_init(&coeffs->env_follow_coeffs);
+ bw_one_pole_init(&coeffs->smooth_coeffs);
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f);
coeffs->thresh = 1.f;
coeffs->ratio = 1.f;
+
+#ifdef BW_DEBUG_DEEP
+ coeffs->hash = bw_hash_sdbm("bw_noise_gate_coeffs");
+ coeffs->state = bw_noise_gate_coeffs_state_init;
+ coeffs->reset_id = coeffs->hash + 1;
+#endif
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state == bw_noise_gate_coeffs_state_init);
}
-static inline void bw_noise_gate_set_sample_rate(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float sample_rate) {
+static inline void bw_noise_gate_set_sample_rate(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float sample_rate) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
+
bw_env_follow_set_sample_rate(&coeffs->env_follow_coeffs, sample_rate);
bw_one_pole_set_sample_rate(&coeffs->smooth_coeffs, sample_rate);
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
+
+#ifdef BW_DEBUG_DEEP
+ coeffs->state = bw_noise_gate_coeffs_state_set_sample_rate;
+#endif
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state == bw_noise_gate_coeffs_state_set_sample_rate);
}
-static inline void bw_noise_gate_reset_coeffs(bw_noise_gate_coeffs *BW_RESTRICT coeffs) {
- bw_env_follow_reset_coeffs(&coeffs->env_follow_coeffs);
- bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
- bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio > 1e12f ? 0.f : bw_rcpf(coeffs->ratio));
-}
-
-static inline void bw_noise_gate_reset_state(const bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state) {
- bw_env_follow_reset_state(&coeffs->env_follow_coeffs, &state->env_follow_state);
-}
-
-static inline void bw_noise_gate_update_coeffs_ctrl(bw_noise_gate_coeffs *BW_RESTRICT coeffs) {
- bw_env_follow_update_coeffs_ctrl(&coeffs->env_follow_coeffs);
-}
-
-static inline void bw_noise_gate_update_coeffs_audio(bw_noise_gate_coeffs *BW_RESTRICT coeffs) {
+static inline void bw_noise_gate_do_update_coeffs_audio(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
bw_env_follow_update_coeffs_audio(&coeffs->env_follow_coeffs);
bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
const float rev_ratio = bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio > 1e12f ? 0.f : bw_rcpf(coeffs->ratio));
coeffs->kc = rev_ratio < 1e-12f ? -INFINITY : 1.f - bw_rcpf(rev_ratio);
+ coeffs->lt = bw_log2f(bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state));
}
-static inline float bw_noise_gate_process1(const bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, float x, float x_sc) {
+static inline void bw_noise_gate_reset_coeffs(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_set_sample_rate);
+
+ bw_env_follow_reset_coeffs(&coeffs->env_follow_coeffs);
+ bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state, coeffs->thresh);
+ bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state, coeffs->ratio > 1e12f ? 0.f : bw_rcpf(coeffs->ratio));
+ bw_noise_gate_do_update_coeffs_audio(coeffs);
+
+#ifdef BW_DEBUG_DEEP
+ coeffs->state = bw_noise_gate_coeffs_state_reset_coeffs;
+ coeffs->reset_id++;
+#endif
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state == bw_noise_gate_coeffs_state_reset_coeffs);
+}
+
+static inline float bw_noise_gate_reset_state(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ float x_0,
+ float x_sc_0) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT(state != NULL);
+ BW_ASSERT(bw_is_finite(x_0));
+ BW_ASSERT(bw_is_finite(x_sc_0));
+
+ const float env = bw_env_follow_reset_state(&coeffs->env_follow_coeffs, &state->env_follow_state, x_sc_0);
+ const float y = env < bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state) ? (env >= 1e-30f ? bw_pow2f(coeffs->kc * (coeffs->lt - bw_log2f(env))) * x_0 : 0.f) : x_0;
+
+#ifdef BW_DEBUG_DEEP
+ state->hash = bw_hash_sdbm("bw_noise_gate_state");
+ state->coeffs_reset_id = coeffs->reset_id;
+#endif
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT_DEEP(bw_noise_gate_state_is_valid(coeffs, state));
+ BW_ASSERT(bw_is_finite(y));
+
+ return y;
+}
+
+static inline void bw_noise_gate_reset_state_multi(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT const * BW_RESTRICT state,
+ const float * x_0,
+ const float * x_sc_0,
+ float * y_0,
+ size_t n_channels) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT(state != NULL);
+ BW_ASSERT(x_0 != NULL);
+ BW_ASSERT(x_sc_0 != NULL);
+
+ if (y_0 != NULL)
+ for (size_t i = 0; i < n_channels; i++)
+ y_0[i] = bw_noise_gate_reset_state(coeffs, state[i], x_0[i], x_sc_0[i]);
+ else
+ for (size_t i = 0; i < n_channels; i++)
+ bw_noise_gate_reset_state(coeffs, state[i], x_0[i], x_sc_0[i]);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT_DEEP(bw_has_only_finite(y_0, n_channels));
+ BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
+}
+
+static inline void bw_noise_gate_update_coeffs_ctrl(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+
+ bw_env_follow_update_coeffs_ctrl(&coeffs->env_follow_coeffs);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+}
+
+static inline void bw_noise_gate_update_coeffs_audio(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+
+ bw_noise_gate_do_update_coeffs_audio(coeffs);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+}
+
+static inline float bw_noise_gate_process1(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ float x,
+ float x_sc) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT(state != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_state_is_valid(coeffs, state));
+ BW_ASSERT(bw_is_finite(x));
+ BW_ASSERT(bw_is_finite(x_sc));
+
const float env = bw_env_follow_process1(&coeffs->env_follow_coeffs, &state->env_follow_state, x_sc);
- const float thresh = bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state);
- return env < thresh ? bw_pow2f(coeffs->kc * bw_log2f(thresh * bw_rcpf(env))) * x : x;
+ const float y = env < bw_one_pole_get_y_z1(&coeffs->smooth_thresh_state) ? (env >= 1e-30f ? bw_pow2f(coeffs->kc * (coeffs->lt - bw_log2f(env))) * x : 0.f) : x;
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT_DEEP(bw_noise_gate_state_is_valid(coeffs, state));
+ BW_ASSERT(bw_is_finite(y));
+
+ return y;
}
-static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, size_t n_samples) {
+static inline void bw_noise_gate_process(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT state,
+ const float * x,
+ const float * x_sc,
+ float * y,
+ size_t n_samples) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT(state != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_state_is_valid(coeffs, state));
+ BW_ASSERT(x != NULL);
+ BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
+ BW_ASSERT(x_sc != NULL);
+ BW_ASSERT_DEEP(bw_has_only_finite(x_sc, n_samples));
+ BW_ASSERT(y != NULL);
+
bw_noise_gate_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_noise_gate_update_coeffs_audio(coeffs);
y[i] = bw_noise_gate_process1(coeffs, state, x[i], x_sc[i]);
}
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT_DEEP(bw_noise_gate_state_is_valid(coeffs, state));
+ BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
}
-static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT const *BW_RESTRICT state, const float * const *x, const float * const *x_sc, float * const *y, size_t n_channels, size_t n_samples) {
+static inline void bw_noise_gate_process_multi(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ bw_noise_gate_state * BW_RESTRICT const * BW_RESTRICT state,
+ const float * const * x, const float * const * x_sc,
+ float * const * y,
+ size_t n_channels,
+ size_t n_samples) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
+ BW_ASSERT(state != NULL);
+ BW_ASSERT(x != NULL);
+ BW_ASSERT(x_sc != NULL);
+ BW_ASSERT(y != NULL);
+
bw_noise_gate_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_noise_gate_update_coeffs_audio(coeffs);
for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_noise_gate_process1(coeffs, state[j], x[j][i], x_sc[j][i]);
}
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs);
}
-static inline void bw_noise_gate_set_thresh_lin(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value) {
+static inline void bw_noise_gate_set_thresh_lin(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(bw_is_finite(value));
+ BW_ASSERT(value >= 1e-20f && value <= 1e20f);
+
coeffs->thresh = value;
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
}
-static inline void bw_noise_gate_set_thresh_dBFS(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value) {
+static inline void bw_noise_gate_set_thresh_dBFS(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(bw_is_finite(value));
+ BW_ASSERT(value >= -400.f && value <= 400.f);
+
coeffs->thresh = bw_dB2linf(value);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
}
-static inline void bw_noise_gate_set_ratio(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value) {
+static inline void bw_noise_gate_set_ratio(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(!bw_is_nan(value));
+ BW_ASSERT(value >= 1.f);
+
coeffs->ratio = value;
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
}
-static inline void bw_noise_gate_set_attack_tau(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value) {
+static inline void bw_noise_gate_set_attack_tau(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(!bw_is_nan(value));
+ BW_ASSERT(value >= 0.f);
+
bw_env_follow_set_attack_tau(&coeffs->env_follow_coeffs, value);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
}
-static inline void bw_noise_gate_set_release_tau(bw_noise_gate_coeffs *BW_RESTRICT coeffs, float value) {
+static inline void bw_noise_gate_set_release_tau(
+ bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ float value) {
+ BW_ASSERT(coeffs != NULL);
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+ BW_ASSERT(!bw_is_nan(value));
+ BW_ASSERT(value >= 0.f);
+
bw_env_follow_set_release_tau(&coeffs->env_follow_coeffs, value);
+
+ BW_ASSERT_DEEP(bw_noise_gate_coeffs_is_valid(coeffs));
+ BW_ASSERT_DEEP(coeffs->state >= bw_noise_gate_coeffs_state_init);
+}
+
+static inline char bw_noise_gate_coeffs_is_valid(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs) {
+ BW_ASSERT(coeffs != NULL);
+
+#ifdef BW_DEBUG_DEEP
+ if (coeffs->hash != bw_hash_sdbm("bw_noise_gate_coeffs"))
+ return 0;
+ if (coeffs->state < bw_noise_gate_coeffs_state_init || coeffs->state > bw_noise_gate_coeffs_state_reset_coeffs)
+ return 0;
+#endif
+
+ if (!bw_is_finite(coeffs->thresh) || coeffs->thresh < 1e-20f || coeffs->thresh > 1e20f)
+ return 0;
+ if (bw_is_nan(coeffs->ratio) || coeffs->ratio < 1.f)
+ return 0;
+
+ if (!bw_one_pole_coeffs_is_valid(&coeffs->smooth_coeffs))
+ return 0;
+
+#ifdef BW_DEBUG_DEEP
+ if (coeffs->state >= bw_noise_gate_coeffs_state_reset_coeffs) {
+ if (bw_is_nan(coeffs->kc) || coeffs->kc > 0.f)
+ return 0;
+ if (!bw_is_finite(coeffs->lt))
+ return 0;
+
+ if (!bw_one_pole_state_is_valid(&coeffs->smooth_coeffs, &coeffs->smooth_thresh_state))
+ return 0;
+ if (!bw_one_pole_state_is_valid(&coeffs->smooth_coeffs, &coeffs->smooth_ratio_state))
+ return 0;
+ }
+#endif
+
+ return bw_env_follow_coeffs_is_valid(&coeffs->env_follow_coeffs);
+}
+
+static inline char bw_noise_gate_state_is_valid(
+ const bw_noise_gate_coeffs * BW_RESTRICT coeffs,
+ const bw_noise_gate_state * BW_RESTRICT state) {
+ BW_ASSERT(state != NULL);
+
+#ifdef BW_DEBUG_DEEP
+ if (state->hash != bw_hash_sdbm("bw_noise_gate_state"))
+ return 0;
+
+ if (coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
+ return 0;
+#endif
+
+ (void)coeffs;
+
+ return bw_env_follow_state_is_valid(&coeffs->env_follow_coeffs, &state->env_follow_state);
}
#ifdef __cplusplus
@@ -321,24 +724,55 @@ class NoiseGate {
public:
NoiseGate();
- void setSampleRate(float sampleRate);
- void reset();
+ void setSampleRate(
+ float sampleRate);
+
+ void reset(
+ float x0 = 0.f,
+ float xSc0 = 0.f,
+ float * BW_RESTRICT y0 = nullptr);
+
+ void reset(
+ float x0,
+ float xSc0,
+ std::array * BW_RESTRICT y0);
+
+ void reset(
+ const float * x0,
+ const float * xSc0,
+ float * y0 = nullptr);
+
+ void reset(
+ std::array x0,
+ std::array xSc0,
+ std::array * BW_RESTRICT y0 = nullptr);
+
void process(
- const float * const *x,
- const float * const *x_sc,
- float * const *y,
- size_t nSamples);
+ const float * const * x,
+ const float * const * xSc,
+ float * const * y,
+ size_t nSamples);
+
void process(
std::array x,
- std::array x_sc,
- std::array y,
- size_t nSamples);
+ std::array xSc,
+ std::array y,
+ size_t nSamples);
- void setTreshLin(float value);
- void setTreshDBFS(float value);
- void setRatio(float value);
- void setAttackTau(float value);
- void setReleaseTau(float value);
+ void setTreshLin(
+ float value);
+
+ void setTreshDBFS(
+ float value);
+
+ void setRatio(
+ float value);
+
+ void setAttackTau(
+ float value);
+
+ void setReleaseTau(
+ float value);
/*! <<<...
* }
* ```
@@ -350,9 +784,9 @@ public:
* change at any time in future versions. Please, do not use it directly. */
private:
- bw_noise_gate_coeffs coeffs;
- bw_noise_gate_state states[N_CHANNELS];
- bw_noise_gate_state *BW_RESTRICT statesP[N_CHANNELS];
+ bw_noise_gate_coeffs coeffs;
+ bw_noise_gate_state states[N_CHANNELS];
+ bw_noise_gate_state * BW_RESTRICT statesP[N_CHANNELS];
};
template
@@ -363,57 +797,95 @@ inline NoiseGate::NoiseGate() {
}
template
-inline void NoiseGate::setSampleRate(float sampleRate) {
+inline void NoiseGate::setSampleRate(
+ float sampleRate) {
bw_noise_gate_set_sample_rate(&coeffs, sampleRate);
}
template
-inline void NoiseGate::reset() {
+inline void NoiseGate::reset(
+ float x0,
+ float xSc0,
+ float * BW_RESTRICT y0) {
bw_noise_gate_reset_coeffs(&coeffs);
- for (size_t i = 0; i < N_CHANNELS; i++)
- bw_noise_gate_reset_state(&coeffs, states + i);
+ if (y0 != nullptr)
+ for (size_t i = 0; i < N_CHANNELS; i++)
+ y0[i] = bw_noise_gate_reset_state(&coeffs, states + i, x0, xSc0);
+ else
+ for (size_t i = 0; i < N_CHANNELS; i++)
+ bw_noise_gate_reset_state(&coeffs, states + i, x0, xSc0);
+}
+
+template
+inline void NoiseGate::reset(
+ float x0,
+ float xSc0,
+ std::array * BW_RESTRICT y0) {
+ reset(x0, xSc0, y0 != nullptr ? y0->data() : nullptr);
+}
+
+template
+inline void NoiseGate::reset(
+ const float * x0,
+ const float * xSc0,
+ float * y0) {
+ bw_noise_gate_reset_coeffs(&coeffs);
+ bw_noise_gate_reset_state_multi(&coeffs, statesP, x0, xSc0, y0, N_CHANNELS);
+}
+
+template
+inline void NoiseGate::reset(
+ std::array x0,
+ std::array xSc0,
+ std::array * BW_RESTRICT y0) {
+ reset(x0.data(), xSc0.data(), y0 != nullptr ? y0->data() : nullptr);
}
template
inline void NoiseGate::process(
- const float * const *x,
- const float * const *x_sc,
- float * const *y,
- size_t nSamples) {
- bw_noise_gate_process_multi(&coeffs, statesP, x, x_sc, y, N_CHANNELS, nSamples);
+ const float * const * x,
+ const float * const * xSc,
+ float * const * y,
+ size_t nSamples) {
+ bw_noise_gate_process_multi(&coeffs, statesP, x, xSc, y, N_CHANNELS, nSamples);
}
template
inline void NoiseGate::process(
std::array x,
- std::array x_sc,
- std::array y,
- size_t nSamples) {
- process(x.data(), x_sc.data(), y.data(), nSamples);
+ std::array xSc,
+ std::array y,
+ size_t nSamples) {
+ process(x.data(), xSc.data(), y.data(), nSamples);
}
template
-inline void NoiseGate::setTreshLin(float value) {
+inline void NoiseGate::setTreshLin(
+ float value) {
bw_noise_gate_set_thresh_lin(&coeffs, value);
}
template
-inline void NoiseGate::setTreshDBFS(float value) {
+inline void NoiseGate::setTreshDBFS(
+ float value) {
bw_noise_gate_set_thresh_dBFS(&coeffs, value);
}
template
-inline void NoiseGate::setRatio(float value) {
+inline void NoiseGate::setRatio(
+ float value) {
bw_noise_gate_set_ratio(&coeffs, value);
}
template
-inline void NoiseGate::setAttackTau(float value) {
+inline void NoiseGate::setAttackTau(
+ float value) {
bw_noise_gate_set_attack_tau(&coeffs, value);
}
template
-inline void NoiseGate::setReleaseTau(float value) {
+inline void NoiseGate::setReleaseTau(
+ float value) {
bw_noise_gate_set_release_tau(&coeffs, value);
}
diff --git a/include/bw_one_pole.h b/include/bw_one_pole.h
index 74795be..cbf4ba2 100644
--- a/include/bw_one_pole.h
+++ b/include/bw_one_pole.h
@@ -1141,9 +1141,9 @@ static inline char bw_one_pole_coeffs_is_valid(
return 0;
#endif
- if (coeffs->cutoff_up < 0.f)
+ if (bw_is_nan(coeffs->cutoff_up) || coeffs->cutoff_up < 0.f)
return 0;
- if (coeffs->cutoff_down < 0.f)
+ if (bw_is_nan(coeffs->cutoff_down) || coeffs->cutoff_down < 0.f)
return 0;
if (!bw_is_finite(coeffs->sticky_thresh) || coeffs->sticky_thresh < 0.f || coeffs->sticky_thresh > 1e18f)
return 0;
diff --git a/include/bw_slew_lim.h b/include/bw_slew_lim.h
index 0f94fdc..c13a10c 100644
--- a/include/bw_slew_lim.h
+++ b/include/bw_slew_lim.h
@@ -802,9 +802,9 @@ static inline char bw_slew_lim_coeffs_is_valid(
return 0;
#endif
- if (!bw_is_finite(coeffs->max_rate_up) || coeffs->max_rate_up < 0.f)
+ if (bw_is_nan(coeffs->max_rate_up) || coeffs->max_rate_up < 0.f)
return 0;
- if (!bw_is_finite(coeffs->max_rate_down) || coeffs->max_rate_down < 0.f)
+ if (bw_is_nan(coeffs->max_rate_down) || coeffs->max_rate_down < 0.f)
return 0;
#ifdef BW_DEBUG_DEEP
@@ -814,9 +814,9 @@ static inline char bw_slew_lim_coeffs_is_valid(
}
if (coeffs->state >= bw_slew_lim_coeffs_state_reset_coeffs) {
- if (!bw_is_finite(coeffs->max_inc) || coeffs->max_inc < 0.f)
+ if (bw_is_nan(coeffs->max_inc) || coeffs->max_inc < 0.f)
return 0;
- if (!bw_is_finite(coeffs->max_dec) || coeffs->max_dec < 0.f)
+ if (bw_is_nan(coeffs->max_dec) || coeffs->max_dec < 0.f)
return 0;
}
#endif