fix bw_sqrtf_2() and 3band eq example

This commit is contained in:
Stefano D'Angelo 2023-01-20 18:27:55 +01:00
parent 4077c5271b
commit 3384d0ea69
3 changed files with 7 additions and 6 deletions

View File

@ -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);

View File

@ -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 }
};

View File

@ -396,6 +396,8 @@ 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%.
*
* #### bw_tanhf_3()
@ -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;
}