From 13987673f54f36684b86c81e7aa8f40ad6e4c180 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Tue, 12 Sep 2023 17:05:51 +0200 Subject: [PATCH] proper computing of initial values in finalized modules --- include/bw_ap1.h | 5 +++-- include/bw_ap2.h | 4 +++- include/bw_hp1.h | 7 +++++-- include/bw_hs1.h | 1 + include/bw_hs2.h | 1 + include/bw_lp1.h | 1 + include/bw_ls1.h | 1 + include/bw_ls2.h | 1 + include/bw_mm1.h | 5 +++-- include/bw_mm2.h | 7 ++++++- include/bw_notch.h | 3 ++- include/bw_one_pole.h | 1 + include/bw_peak.h | 1 + include/bw_slew_lim.h | 1 + include/bw_svf.h | 1 + 15 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/bw_ap1.h b/include/bw_ap1.h index 23b013d..3c2d3c2 100644 --- a/include/bw_ap1.h +++ b/include/bw_ap1.h @@ -310,6 +310,7 @@ struct bw_ap1_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_lp1_state lp1_state; }; @@ -371,8 +372,8 @@ static inline float bw_ap1_reset_state( BW_ASSERT(state != NULL); BW_ASSERT(bw_is_finite(x_0)); - bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); - const float y = x_0; + const float lp = bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); + const float y = lp + lp - x_0; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_ap1_state"); diff --git a/include/bw_ap2.h b/include/bw_ap2.h index 87dcb7e..209e664 100644 --- a/include/bw_ap2.h +++ b/include/bw_ap2.h @@ -319,6 +319,7 @@ struct bw_ap2_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_svf_state svf_state; }; @@ -382,7 +383,8 @@ static inline float bw_ap2_reset_state( float lp, bp, hp; bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x_0, &lp, &bp, &hp); - const float y = x_0; + const float lh = lp + hp; + const float y = lh + lh - x_0; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_ap2_state"); diff --git a/include/bw_hp1.h b/include/bw_hp1.h index 2deb91c..9d2ca63 100644 --- a/include/bw_hp1.h +++ b/include/bw_hp1.h @@ -308,6 +308,7 @@ struct bw_hp1_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_lp1_state lp1_state; }; @@ -369,7 +370,8 @@ static inline float bw_hp1_reset_state( BW_ASSERT(state != NULL); BW_ASSERT(bw_is_finite(x_0)); - bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); + const float lp = bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); + const float y = x_0 - lp; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_hp1_state"); @@ -378,8 +380,9 @@ static inline float bw_hp1_reset_state( BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs)); BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs); BW_ASSERT_DEEP(bw_hp1_state_is_valid(coeffs, state)); + BW_ASSERT(bw_is_finite(y)); - return 0.f; + return y; } static inline void bw_hp1_reset_state_multi( diff --git a/include/bw_hs1.h b/include/bw_hs1.h index af154b5..5f30313 100644 --- a/include/bw_hs1.h +++ b/include/bw_hs1.h @@ -355,6 +355,7 @@ struct bw_hs1_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_mm1_state mm1_state; }; diff --git a/include/bw_hs2.h b/include/bw_hs2.h index 93bfad6..cd4ee6b 100644 --- a/include/bw_hs2.h +++ b/include/bw_hs2.h @@ -375,6 +375,7 @@ struct bw_hs2_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_mm2_state mm2_state; }; diff --git a/include/bw_lp1.h b/include/bw_lp1.h index a2e5054..cbb2b5e 100644 --- a/include/bw_lp1.h +++ b/include/bw_lp1.h @@ -326,6 +326,7 @@ struct bw_lp1_state { uint32_t coeffs_reset_id; #endif + // States float y_z1; float X_z1; }; diff --git a/include/bw_ls1.h b/include/bw_ls1.h index 15a594a..1d3c5df 100644 --- a/include/bw_ls1.h +++ b/include/bw_ls1.h @@ -357,6 +357,7 @@ struct bw_ls1_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_mm1_state mm1_state; }; diff --git a/include/bw_ls2.h b/include/bw_ls2.h index e761dfa..9f9dbb0 100644 --- a/include/bw_ls2.h +++ b/include/bw_ls2.h @@ -372,6 +372,7 @@ struct bw_ls2_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_mm2_state mm2_state; }; diff --git a/include/bw_mm1.h b/include/bw_mm1.h index 6cea0d4..eff84f0 100644 --- a/include/bw_mm1.h +++ b/include/bw_mm1.h @@ -332,6 +332,7 @@ struct bw_mm1_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_lp1_state lp1_state; }; @@ -403,8 +404,8 @@ static inline float bw_mm1_reset_state( BW_ASSERT(state != NULL); BW_ASSERT(bw_is_finite(x_0)); - bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); - const float y = (bw_gain_get_gain_lin(&coeffs->gain_x_coeffs) + bw_gain_get_gain_lin(&coeffs->gain_lp_coeffs)) * x_0; + const float lp = bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); + const float y = bw_gain_get_gain_lin(&coeffs->gain_x_coeffs) * x_0 + bw_gain_get_gain_lin(&coeffs->gain_lp_coeffs) * lp; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_mm1_state"); diff --git a/include/bw_mm2.h b/include/bw_mm2.h index fd26d36..52cf2e9 100644 --- a/include/bw_mm2.h +++ b/include/bw_mm2.h @@ -371,6 +371,7 @@ struct bw_mm2_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_svf_state svf_state; }; @@ -454,7 +455,11 @@ static inline float bw_mm2_reset_state( float lp, bp, hp; bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x_0, &lp, &bp, &hp); - const float y = (bw_gain_get_gain_lin(&coeffs->gain_x_coeffs) + bw_gain_get_gain_lin(&coeffs->gain_lp_coeffs)) * x_0; + const float y = + bw_gain_get_gain_lin(&coeffs->gain_x_coeffs) * x_0 + + bw_gain_get_gain_lin(&coeffs->gain_lp_coeffs) * lp + + bw_gain_get_gain_lin(&coeffs->gain_bp_coeffs) * bp + + bw_gain_get_gain_lin(&coeffs->gain_hp_coeffs) * hp; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_mm2_state"); diff --git a/include/bw_notch.h b/include/bw_notch.h index 80ecdcc..ffcbbcc 100644 --- a/include/bw_notch.h +++ b/include/bw_notch.h @@ -319,6 +319,7 @@ struct bw_notch_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_svf_state svf_state; }; @@ -382,7 +383,7 @@ static inline float bw_notch_reset_state( float lp, bp, hp; bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x_0, &lp, &bp, &hp); - const float y = x_0; + const float y = lp + hp; #ifdef BW_DEBUG_DEEP state->hash = bw_hash_sdbm("bw_notch_state"); diff --git a/include/bw_one_pole.h b/include/bw_one_pole.h index e7532f9..2238569 100644 --- a/include/bw_one_pole.h +++ b/include/bw_one_pole.h @@ -495,6 +495,7 @@ struct bw_one_pole_state { uint32_t coeffs_reset_id; #endif + // States float y_z1; }; diff --git a/include/bw_peak.h b/include/bw_peak.h index 81f2dd5..2ec1293 100644 --- a/include/bw_peak.h +++ b/include/bw_peak.h @@ -407,6 +407,7 @@ struct bw_peak_state { uint32_t coeffs_reset_id; #endif + // Sub-components bw_mm2_state mm2_state; }; diff --git a/include/bw_slew_lim.h b/include/bw_slew_lim.h index 0cecef2..a66e9c1 100644 --- a/include/bw_slew_lim.h +++ b/include/bw_slew_lim.h @@ -368,6 +368,7 @@ struct bw_slew_lim_state { uint32_t coeffs_reset_id; #endif + // States float y_z1; }; diff --git a/include/bw_svf.h b/include/bw_svf.h index e6ffa84..f578d97 100644 --- a/include/bw_svf.h +++ b/include/bw_svf.h @@ -391,6 +391,7 @@ struct bw_svf_state { uint32_t coeffs_reset_id; #endif + // States float hp_z1; float lp_z1; float bp_z1;