added initial value to bw_{ap2,hs2,ls2,mm2,notch,peak,svf,wah}

This commit is contained in:
Stefano D'Angelo 2023-03-23 14:03:27 +01:00
parent 1aa2cca858
commit 8c9796f025
16 changed files with 92 additions and 47 deletions

1
TODO
View File

@ -34,6 +34,7 @@ code:
* bw_satur gain compensation to divide by actual gain (derivative) rather than gain parameter?
* cite papers, thank authors
* process1 and multi-channel
* add initial state (x0) to reset state of lp1, ap1, mm1, hs1, ls1, others? all?
build system:
* make makefiles handle paths with spaces etc

View File

@ -30,7 +30,7 @@ void bw_example_fx_ap2_set_sample_rate(bw_example_fx_ap2 *instance, float sample
void bw_example_fx_ap2_reset(bw_example_fx_ap2 *instance) {
bw_ap2_reset_coeffs(&instance->ap2_coeffs);
bw_ap2_reset_state(&instance->ap2_coeffs, &instance->ap2_state);
bw_ap2_reset_state(&instance->ap2_coeffs, &instance->ap2_state, 0.f);
}
void bw_example_fx_ap2_process(bw_example_fx_ap2 *instance, const float** x, float** y, int n_samples) {

View File

@ -34,11 +34,11 @@ void bw_example_fx_eq_3band_set_sample_rate(bw_example_fx_eq_3band *instance, fl
void bw_example_fx_eq_3band_reset(bw_example_fx_eq_3band *instance) {
bw_ls2_reset_coeffs(&instance->ls2_coeffs);
bw_ls2_reset_state(&instance->ls2_coeffs, &instance->ls2_state);
bw_ls2_reset_state(&instance->ls2_coeffs, &instance->ls2_state, 0.f);
bw_peak_reset_coeffs(&instance->peak_coeffs);
bw_peak_reset_state(&instance->peak_coeffs, &instance->peak_state);
bw_peak_reset_state(&instance->peak_coeffs, &instance->peak_state, 0.f);
bw_hs2_reset_coeffs(&instance->hs2_coeffs);
bw_hs2_reset_state(&instance->hs2_coeffs, &instance->hs2_state);
bw_hs2_reset_state(&instance->hs2_coeffs, &instance->hs2_state, 0.f);
}
void bw_example_fx_eq_3band_process(bw_example_fx_eq_3band *instance, const float** x, float** y, int n_samples) {

View File

@ -30,7 +30,7 @@ void bw_example_fx_mm2_set_sample_rate(bw_example_fx_mm2 *instance, float sample
void bw_example_fx_mm2_reset(bw_example_fx_mm2 *instance) {
bw_mm2_reset_coeffs(&instance->mm2_coeffs);
bw_mm2_reset_state(&instance->mm2_coeffs, &instance->mm2_state);
bw_mm2_reset_state(&instance->mm2_coeffs, &instance->mm2_state, 0.f);
}
void bw_example_fx_mm2_process(bw_example_fx_mm2 *instance, const float** x, float** y, int n_samples) {

View File

@ -30,7 +30,7 @@ void bw_example_fx_notch_set_sample_rate(bw_example_fx_notch *instance, float sa
void bw_example_fx_notch_reset(bw_example_fx_notch *instance) {
bw_notch_reset_coeffs(&instance->notch_coeffs);
bw_notch_reset_state(&instance->notch_coeffs, &instance->notch_state);
bw_notch_reset_state(&instance->notch_coeffs, &instance->notch_state, 0.f);
}
void bw_example_fx_notch_process(bw_example_fx_notch *instance, const float** x, float** y, int n_samples) {

View File

@ -30,7 +30,7 @@ void bw_example_fx_svf_set_sample_rate(bw_example_fx_svf *instance, float sample
void bw_example_fx_svf_reset(bw_example_fx_svf *instance) {
bw_svf_reset_coeffs(&instance->svf_coeffs);
bw_svf_reset_state(&instance->svf_coeffs, &instance->svf_state);
bw_svf_reset_state(&instance->svf_coeffs, &instance->svf_state, 0.f);
}
void bw_example_fx_svf_process(bw_example_fx_svf *instance, const float** x, float** y, int n_samples) {

View File

@ -111,7 +111,7 @@ void bw_example_synth_mono_reset(bw_example_synth_mono *instance) {
bw_env_gen_reset_coeffs(&instance->vcf_env_gen_coeffs);
bw_env_gen_reset_state(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state);
bw_svf_reset_coeffs(&instance->vcf_coeffs);
bw_svf_reset_state(&instance->vcf_coeffs, &instance->vcf_state);
bw_svf_reset_state(&instance->vcf_coeffs, &instance->vcf_state, 0.f);
bw_env_gen_reset_coeffs(&instance->vca_env_gen_coeffs);
bw_env_gen_reset_state(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state);
bw_phase_gen_reset_coeffs(&instance->a440_phase_gen_coeffs);

View File

@ -50,7 +50,7 @@ void bw_example_synth_simple_reset(bw_example_synth_simple *instance) {
bw_osc_pulse_reset_coeffs(&instance->osc_pulse_coeffs);
bw_osc_filt_reset_state(&instance->osc_filt_state);
bw_svf_reset_coeffs(&instance->svf_coeffs);
bw_svf_reset_state(&instance->svf_coeffs, &instance->svf_state);
bw_svf_reset_state(&instance->svf_coeffs, &instance->svf_state, 0.f);
bw_env_gen_reset_coeffs(&instance->env_gen_coeffs);
bw_env_gen_reset_state(&instance->env_gen_coeffs, &instance->env_gen_state);
bw_gain_reset_coeffs(&instance->gain_coeffs);

View File

@ -1,7 +1,7 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
* Copyright (C) 2022, 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{ bw_config bw_common bw_math bw_one_pole bw_svf }}}
* description {{{
* Second-order allpass filter (180° shift at cutoff, approaching 360° shift
@ -28,6 +28,11 @@
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_ap2_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -79,9 +84,10 @@ static inline void bw_ap2_reset_coeffs(bw_ap2_coeffs *BW_RESTRICT coeffs);
*
* #### bw_ap2_reset_state()
* ```>>> */
static inline void bw_ap2_reset_state(const bw_ap2_coeffs *BW_RESTRICT coeffs, bw_ap2_state *BW_RESTRICT state);
static inline void bw_ap2_reset_state(const bw_ap2_coeffs *BW_RESTRICT coeffs, bw_ap2_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_ap2_update_coeffs_ctrl()
* ```>>> */
@ -157,8 +163,8 @@ static inline void bw_ap2_reset_coeffs(bw_ap2_coeffs *BW_RESTRICT coeffs) {
bw_svf_reset_coeffs(&coeffs->svf_coeffs);
}
static inline void bw_ap2_reset_state(const bw_ap2_coeffs *BW_RESTRICT coeffs, bw_ap2_state *BW_RESTRICT state) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state);
static inline void bw_ap2_reset_state(const bw_ap2_coeffs *BW_RESTRICT coeffs, bw_ap2_state *BW_RESTRICT state, float x0) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x0);
}
static inline void bw_ap2_update_coeffs_ctrl(bw_ap2_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{
* bw_config bw_common bw_gain bw_math bw_mm2 bw_one_pole bw_svf
* }}}
@ -29,6 +29,11 @@
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_hs2_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -80,9 +85,10 @@ static inline void bw_hs2_reset_coeffs(bw_hs2_coeffs *BW_RESTRICT coeffs);
*
* #### bw_hs2_reset_state()
* ```>>> */
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state);
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_hs2_update_coeffs_ctrl()
* ```>>> */
@ -210,8 +216,8 @@ static inline void bw_hs2_reset_coeffs(bw_hs2_coeffs *BW_RESTRICT coeffs) {
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
}
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state);
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0);
}
static inline void bw_hs2_update_coeffs_ctrl(bw_hs2_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{
* bw_config bw_common bw_gain bw_math bw_mm2 bw_one_pole bw_svf
* }}}
@ -30,6 +30,11 @@
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_ls2_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -81,9 +86,10 @@ static inline void bw_ls2_reset_coeffs(bw_ls2_coeffs *BW_RESTRICT coeffs);
*
* #### bw_ls2_reset_state()
* ```>>> */
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state);
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_ls2_update_coeffs_ctrl()
* ```>>> */
@ -209,8 +215,8 @@ static inline void bw_ls2_reset_coeffs(bw_ls2_coeffs *BW_RESTRICT coeffs) {
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
}
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state);
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0);
}
static inline void bw_ls2_update_coeffs_ctrl(bw_ls2_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,13 +20,18 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{ bw_config bw_common bw_gain bw_math bw_one_pole bw_svf }}}
* description {{{
* Second-order multimode filter.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_mm2_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -78,9 +83,10 @@ static inline void bw_mm2_reset_coeffs(bw_mm2_coeffs *BW_RESTRICT coeffs);
*
* #### bw_mm2_reset_state()
* ```>>> */
static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state);
static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_mm2_update_coeffs_ctrl()
* ```>>> */
@ -232,8 +238,8 @@ static inline void bw_mm2_reset_coeffs(bw_mm2_coeffs *BW_RESTRICT coeffs) {
bw_gain_reset_coeffs(&coeffs->gain_hp_coeffs);
}
static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state);
static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x0) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x0);
}
static inline void bw_mm2_update_coeffs_ctrl(bw_mm2_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{ bw_config bw_common bw_math bw_one_pole bw_svf }}}
* description {{{
* Second-order notch filter with unitary gain at DC and asymptotically as
@ -28,6 +28,11 @@
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_notch_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -79,9 +84,10 @@ static inline void bw_notch_reset_coeffs(bw_notch_coeffs *BW_RESTRICT coeffs);
*
* #### bw_notch_reset_state()
* ```>>> */
static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state);
static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_notch_update_coeffs_ctrl()
* ```>>> */
@ -157,8 +163,8 @@ static inline void bw_notch_reset_coeffs(bw_notch_coeffs *BW_RESTRICT coeffs) {
bw_svf_reset_coeffs(&coeffs->svf_coeffs);
}
static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state);
static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x0) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x0);
}
static inline void bw_notch_update_coeffs_ctrl(bw_notch_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{
* bw_config bw_common bw_gain bw_math bw_mm2 bw_one_pole bw_svf
* }}}
@ -37,6 +37,11 @@
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_peak_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>First release.</li>
@ -88,9 +93,10 @@ static inline void bw_peak_reset_coeffs(bw_peak_coeffs *BW_RESTRICT coeffs);
*
* #### bw_peak_reset_state()
* ```>>> */
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state);
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_peak_update_coeffs_ctrl()
* ```>>> */
@ -242,8 +248,8 @@ static inline void bw_peak_reset_coeffs(bw_peak_coeffs *BW_RESTRICT coeffs) {
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
}
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state);
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0);
}
static inline void bw_peak_update_coeffs_ctrl(bw_peak_coeffs *BW_RESTRICT coeffs) {

View File

@ -20,14 +20,19 @@
/*!
* module_type {{{ dsp }}}
* version {{{ 0.3.0 }}}
* version {{{ 0.4.0 }}}
* requires {{{ bw_config bw_common bw_math bw_one_pole }}}
* description {{{
* State variable filter (2nd order, 12 dB/oct) model with separated lowpass,
* bandpass, and highpass outputs.
* }}}
* changelog {{{
* <ul>
<ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Added initial input value to `bw_svf_reset_state()`.</li>
* </ul>
* </li>
* <li>Version <strong>0.3.0</strong>:
* <ul>
* <li>Strenghtened algorithm for modulation.</li>
@ -93,9 +98,10 @@ static inline void bw_svf_reset_coeffs(bw_svf_coeffs *BW_RESTRICT coeffs);
*
* #### bw_svf_reset_state()
* ```>>> */
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state);
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, float x0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`.
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
*
* #### bw_svf_update_coeffs_ctrl()
* ```>>> */
@ -250,9 +256,9 @@ static inline void bw_svf_reset_coeffs(bw_svf_coeffs *BW_RESTRICT coeffs) {
_bw_svf_do_update_coeffs(coeffs, 1);
}
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state) {
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, float x0) {
state->hp_z1 = 0.f;
state->lp_z1 = 0.f;
state->lp_z1 = x0;
state->bp_z1 = 0.f;
state->cutoff_z1 = coeffs->cutoff;
}

View File

@ -31,6 +31,8 @@
* <ul>
* <li>Version <strong>0.4.0</strong>:
* <ul>
* <li>Now specifying `0.f` as initial input value for
* `bw_svf_reset_state()`.</li>
* <li>Fixed documentation for `bw_wah_state` and `bw_wah_reset_state()`.</li>
* </ul>
* </li>
@ -163,7 +165,7 @@ static inline void bw_wah_reset_coeffs(bw_wah_coeffs *BW_RESTRICT coeffs) {
}
static inline void bw_wah_reset_state(const bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state);
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, 0.f);
}
static inline void bw_wah_update_coeffs_ctrl(bw_wah_coeffs *BW_RESTRICT coeffs) {