From 3384d0ea691a5bd543b06a14bf65b75b97aac429 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Fri, 20 Jan 2023 18:27:55 +0100 Subject: [PATCH] fix bw_sqrtf_2() and 3band eq example --- examples/fx_eq_3band/src/bw_example_fx_eq_3band.c | 3 +-- examples/fx_eq_3band/src/config.h | 2 +- include/bw_math.h | 8 +++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/fx_eq_3band/src/bw_example_fx_eq_3band.c b/examples/fx_eq_3band/src/bw_example_fx_eq_3band.c index 2670b30..197cdf5 100644 --- a/examples/fx_eq_3band/src/bw_example_fx_eq_3band.c +++ b/examples/fx_eq_3band/src/bw_example_fx_eq_3band.c @@ -90,7 +90,6 @@ void bw_example_fx_eq_3band_process(bw_example_fx_eq_3band instance, const float bw_ls2_process(&instance->ls2_coeffs, &instance->ls2_state, x[0], y[0], n_samples); bw_peak_process(&instance->peak_coeffs, &instance->peak_state, y[0], y[0], n_samples); bw_hs2_process(&instance->hs2_coeffs, &instance->hs2_state, y[0], y[0], n_samples); - //bw_peak_process(&instance->peak_coeffs, &instance->peak_state, x[0], y[0], n_samples); } void bw_example_fx_eq_3band_set_parameter(bw_example_fx_eq_3band instance, int index, float value) { @@ -111,7 +110,7 @@ void bw_example_fx_eq_3band_set_parameter(bw_example_fx_eq_3band instance, int i bw_peak_set_peak_gain_dB(&instance->peak_coeffs, -20.f + 40.f * value); break; case p_peak_bw: - bw_peak_set_bandwidth(&instance->peak_coeffs, 0.5f + 3.9f * value); + bw_peak_set_bandwidth(&instance->peak_coeffs, 0.01f + 1.99f * value); break; case p_hs_cutoff: bw_hs2_set_cutoff(&instance->hs2_coeffs, 20.f + (20e3f - 20.f) * value * value * value); diff --git a/examples/fx_eq_3band/src/config.h b/examples/fx_eq_3band/src/config.h index ace9ac1..38acad5 100644 --- a/examples/fx_eq_3band/src/config.h +++ b/examples/fx_eq_3band/src/config.h @@ -75,7 +75,7 @@ static struct config_parameter config_parameters[NUM_PARAMETERS] = { { "Peak cutoff", "Peak cutoff", "Hz", 0, 0, 0, 0.5f }, { "Peak gain", "Peak gain", "dB", 0, 0, 0, 0.5f }, { "Peak bandiwdth", "Peak BW", "", 0, 0, 0, 1.f }, - { "High shelf cutoff", "HS cutoff", "Hz", 0, 0, 0, 0.2f }, + { "High shelf cutoff", "HS cutoff", "Hz", 0, 0, 0, 0.8f }, { "High shelf gain", "HS gain", "dB", 0, 0, 0, 0.5f }, { "High shelf slope", "HS slope", "", 0, 0, 0, 0.f } }; diff --git a/include/bw_math.h b/include/bw_math.h index 507cece..aa21eca 100644 --- a/include/bw_math.h +++ b/include/bw_math.h @@ -395,6 +395,8 @@ static inline float bw_omega_3lognr(float x); static inline float bw_sqrtf_2(float x); /*! <<<``` * Returns an approximation of the square root of `x`. + * + * Do not feed `0.f`. * * Relative error < 0.0007%. * @@ -623,10 +625,10 @@ static inline float bw_omega_3lognr(float x) { static inline float bw_sqrtf_2(float x) { _bw_floatint v = {.f = x}; - v.u = ((v.u - 0x3f82a127) >> 1) + 0x3f7d8fc7; + v.u = (((v.u - 0x3f82a127) >> 1) + 0x3f7d8fc7) & 0x7fffffff; float r = bw_rcpf_2(x); - v.f = v.f + v.f * (0.5f + 0.5f * r * v.f * v.f); - v.f = v.f + v.f * (0.5f + 0.5f * r * v.f * v.f); + v.f = v.f + v.f * (0.5f - 0.5f * r * v.f * v.f); + v.f = v.f + v.f * (0.5f - 0.5f * r * v.f * v.f); return v.f; }