now using backward Euler method in bw_one_pole

This commit is contained in:
Stefano D'Angelo 2023-08-14 12:11:11 +02:00
parent 262d4f9a5d
commit ee94fba57b
2 changed files with 6 additions and 5 deletions

1
TODO
View File

@ -6,7 +6,6 @@ code:
* check all examples again
* osc post filter (and one pole init, slew rate, etc.) val from input? set state instead?
* audio rate optional pulse width/slope inputs?
* should rather use backward Euler in bw_onepole?
* one pole process const input? (return also if const out)
* empty functions etc. to keep consistency and forward compatibility?
* float in [-1,1] for velocity, pitch bend, mod wheel

View File

@ -40,6 +40,8 @@
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* <li>Now using backward Euler rather than impulse invariant
* method.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -364,7 +366,7 @@ struct bw_one_pole_coeffs {
#endif
// Coefficients
float Ttm2pi;
float fs_2pi;
float mA1u;
float mA1d;
@ -412,7 +414,7 @@ static inline void bw_one_pole_set_sample_rate(bw_one_pole_coeffs *BW_RESTRICT c
BW_ASSERT_DEEP(bw_one_pole_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_one_pole_coeffs_state_init);
coeffs->Ttm2pi = -6.283185307179586f / sample_rate;
coeffs->fs_2pi = 0.15915494309189535f * sample_rate;
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_one_pole_coeffs_state_set_sample_rate;
@ -424,10 +426,10 @@ static inline void bw_one_pole_set_sample_rate(bw_one_pole_coeffs *BW_RESTRICT c
static inline void bw_one_pole_do_update_coeffs_ctrl(bw_one_pole_coeffs *BW_RESTRICT coeffs) {
if (coeffs->param_changed) {
if (coeffs->param_changed & BW_ONE_POLE_PARAM_CUTOFF_UP)
coeffs->mA1u = coeffs->cutoff_up > 1.591549430918953e8f ? 0.f : bw_expf(coeffs->Ttm2pi * coeffs->cutoff_up);
coeffs->mA1u = coeffs->cutoff_up > 1.591549430918953e8f ? 0.f : coeffs->fs_2pi * bw_rcpf(coeffs->fs_2pi + coeffs->cutoff_up);
// tau < 1 ns is instantaneous for any practical purpose
if (coeffs->param_changed & BW_ONE_POLE_PARAM_CUTOFF_DOWN)
coeffs->mA1d = coeffs->cutoff_down > 1.591549430918953e8f ? 0.f : bw_expf(coeffs->Ttm2pi * coeffs->cutoff_down);
coeffs->mA1d = coeffs->cutoff_down > 1.591549430918953e8f ? 0.f : coeffs->fs_2pi * bw_rcpf(coeffs->fs_2pi + coeffs->cutoff_down);
// as before
if (coeffs->param_changed & BW_ONE_POLE_PARAM_STICKY_THRESH)
coeffs->st2 = coeffs->sticky_thresh * coeffs->sticky_thresh;