From 4ebcac26de53c94630ce35e3a5ff10765d2e7ece Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Mon, 28 Nov 2022 14:07:50 +0100 Subject: [PATCH] allow null output where get_y_z1 is present --- examples/synth/src/bw_example_synth.c | 4 +- include/bw_env_follow.h | 14 ++++-- include/bw_one_pole.h | 70 +++++++++++++++++++-------- include/bw_slew_lim.h | 45 ++++++++++++----- 4 files changed, 93 insertions(+), 40 deletions(-) diff --git a/examples/synth/src/bw_example_synth.c b/examples/synth/src/bw_example_synth.c index 3d0b88f..0d9b47d 100644 --- a/examples/synth/src/bw_example_synth.c +++ b/examples/synth/src/bw_example_synth.c @@ -186,7 +186,6 @@ void bw_example_synth_process(bw_example_synth instance, const float** x, float* instance->level = instance->buf[i + n - 1]; } */ - instance->level = 0.f; if (instance->params[p_a440] >= 0.5f) for (int i = 0; i < n_samples; i++) { @@ -197,8 +196,7 @@ void bw_example_synth_process(bw_example_synth instance, const float** x, float* } bw_vol_process(&instance->vol_coeffs, y[0], y[0], n_samples); - for (int i = 0; i < n_samples; i++) - bw_env_follow_process1(&instance->env_follow_coeffs, &instance->env_follow_state, y[0][i]); + bw_env_follow_process(&instance->env_follow_coeffs, &instance->env_follow_state, y[0], NULL, n_samples); instance->level = bw_env_follow_get_y_z1(&instance->env_follow_state); } diff --git a/include/bw_env_follow.h b/include/bw_env_follow.h index 6b8c406..237afd5 100644 --- a/include/bw_env_follow.h +++ b/include/bw_env_follow.h @@ -155,10 +155,16 @@ static inline float bw_env_follow_process1(const bw_env_follow_coeffs *BW_RESTRI static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { bw_env_follow_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { - bw_env_follow_update_coeffs_audio(coeffs); - y[i] = bw_env_follow_process1(coeffs, state, x[i]); - } + if (y) + for (int i = 0; i < n_samples; i++) { + bw_env_follow_update_coeffs_audio(coeffs); + y[i] = bw_env_follow_process1(coeffs, state, x[i]); + } + else + for (int i = 0; i < n_samples; i++) { + bw_env_follow_update_coeffs_audio(coeffs); + bw_env_follow_process1(coeffs, state, x[i]); + } } static inline void bw_env_follow_set_attack_tau(bw_env_follow_coeffs *BW_RESTRICT coeffs, float value) { diff --git a/include/bw_one_pole.h b/include/bw_one_pole.h index 9534482..37e7c6e 100644 --- a/include/bw_one_pole.h +++ b/include/bw_one_pole.h @@ -345,33 +345,63 @@ static inline float bw_one_pole_process1_asym_sticky_rel(const bw_one_pole_coeff static inline void bw_one_pole_process(bw_one_pole_coeffs *BW_RESTRICT coeffs, bw_one_pole_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { bw_one_pole_update_coeffs_ctrl(coeffs); - - if (coeffs->mA1u != coeffs->mA1d) { - if (coeffs->st2 != 0.f) { - if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + if (y) { + if (coeffs->mA1u != coeffs->mA1d) { + if (coeffs->st2 != 0.f) { + if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + for (int i = 0; i < n_samples; i++) + y[i] = bw_one_pole_process1_asym_sticky_abs(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + y[i] = bw_one_pole_process1_asym_sticky_rel(coeffs, state, x[i]); + } + else { for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1_asym_sticky_abs(coeffs, state, x[i]); - else - for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1_asym_sticky_rel(coeffs, state, x[i]); + y[i] = bw_one_pole_process1_asym(coeffs, state, x[i]); + } } else { - for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1_asym(coeffs, state, x[i]); + if (coeffs->st2 != 0.f) { + if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + for (int i = 0; i < n_samples; i++) + y[i] = bw_one_pole_process1_sticky_abs(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + y[i] = bw_one_pole_process1_sticky_rel(coeffs, state, x[i]); + } + else { + for (int i = 0; i < n_samples; i++) + y[i] = bw_one_pole_process1(coeffs, state, x[i]); + } } - } - else { - if (coeffs->st2 != 0.f) { - if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + } else { + if (coeffs->mA1u != coeffs->mA1d) { + if (coeffs->st2 != 0.f) { + if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + for (int i = 0; i < n_samples; i++) + bw_one_pole_process1_asym_sticky_abs(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + bw_one_pole_process1_asym_sticky_rel(coeffs, state, x[i]); + } + else { for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1_sticky_abs(coeffs, state, x[i]); - else - for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1_sticky_rel(coeffs, state, x[i]); + bw_one_pole_process1_asym(coeffs, state, x[i]); + } } else { - for (int i = 0; i < n_samples; i++) - y[i] = bw_one_pole_process1(coeffs, state, x[i]); + if (coeffs->st2 != 0.f) { + if (coeffs->sticky_mode == bw_one_pole_sticky_mode_abs) + for (int i = 0; i < n_samples; i++) + bw_one_pole_process1_sticky_abs(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + bw_one_pole_process1_sticky_rel(coeffs, state, x[i]); + } + else { + for (int i = 0; i < n_samples; i++) + bw_one_pole_process1(coeffs, state, x[i]); + } } } } diff --git a/include/bw_slew_lim.h b/include/bw_slew_lim.h index d95c490..e02554d 100644 --- a/include/bw_slew_lim.h +++ b/include/bw_slew_lim.h @@ -217,20 +217,39 @@ static inline float bw_slew_lim_process1_down(const bw_slew_lim_coeffs *BW_RESTR static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { bw_slew_lim_update_coeffs_ctrl(coeffs); - if (coeffs->max_rate_up != INFINITY) { - if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) - y[i] = bw_slew_lim_process1(coeffs, state, x[i]); - else - for (int i = 0; i < n_samples; i++) - y[i] = bw_slew_lim_process1_up(coeffs, state, x[i]); + if (y) { + if (coeffs->max_rate_up != INFINITY) { + if (coeffs->max_rate_down != INFINITY) + for (int i = 0; i < n_samples; i++) + y[i] = bw_slew_lim_process1(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + y[i] = bw_slew_lim_process1_up(coeffs, state, x[i]); + } else { + if (coeffs->max_rate_down != INFINITY) + for (int i = 0; i < n_samples; i++) + y[i] = bw_slew_lim_process1_down(coeffs, state, x[i]); + else { + for (int i = 0; i < n_samples; i++) + y[i] = x[i]; + state->y_z1 = x[n_samples - 1]; + } + } } else { - if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) - y[i] = bw_slew_lim_process1_down(coeffs, state, x[i]); - else - for (int i = 0; i < n_samples; i++) - y[i] = x[i]; + if (coeffs->max_rate_up != INFINITY) { + if (coeffs->max_rate_down != INFINITY) + for (int i = 0; i < n_samples; i++) + bw_slew_lim_process1(coeffs, state, x[i]); + else + for (int i = 0; i < n_samples; i++) + bw_slew_lim_process1_up(coeffs, state, x[i]); + } else { + if (coeffs->max_rate_down != INFINITY) + for (int i = 0; i < n_samples; i++) + bw_slew_lim_process1_down(coeffs, state, x[i]); + else + state->y_z1 = x[n_samples - 1]; + } } }