finalized bw_phaser + examples + improved docs

This commit is contained in:
Stefano D'Angelo 2023-09-19 10:22:36 +02:00
parent 3e1400922f
commit f470af1a92
10 changed files with 562 additions and 130 deletions

View File

@ -30,7 +30,7 @@ void bw_example_fx_phaser_set_sample_rate(bw_example_fx_phaser *instance, float
void bw_example_fx_phaser_reset(bw_example_fx_phaser *instance) {
bw_phaser_reset_coeffs(&instance->phaser_coeffs);
bw_phaser_reset_state(&instance->phaser_coeffs, &instance->phaser_state);
bw_phaser_reset_state(&instance->phaser_coeffs, &instance->phaser_state, 0.f);
}
void bw_example_fx_phaser_process(bw_example_fx_phaser *instance, const float** x, float** y, int n_samples) {

View File

@ -4,3 +4,6 @@ NAME := bw_example_fx_phaser
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_phaser.c
include ${ROOT_DIR}/../../common/vst3/vst3.mk
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP

View File

@ -4,3 +4,6 @@ NAME := bw_example_fxpp_phaser
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_phaser.cpp
include ${ROOT_DIR}/../../common/vst3/vst3.mk
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP

View File

@ -211,9 +211,10 @@ static inline void bw_hs1_set_cutoff(
*
* `value` must be finite and positive.
*
* By the time `bw_hs1_update_coeffs_ctrl()`, `bw_hs1_update_coeffs_audio()`,
* `bw_hs1_process1()`, `bw_hs1_process()`, or `bw_hs1_process_multi()` is
* called, `cutoff * bw_sqrtf(high_gain)` must be in [`1e-6f`, `1e12f`].
* By the time `bw_hs1_reset_coeffs()`, `bw_hs1_update_coeffs_ctrl()`,
* `bw_hs1_update_coeffs_audio()`, `bw_hs1_process1()`, `bw_hs1_process()`,
* or `bw_hs1_process_multi()` is called, `cutoff * bw_sqrtf(high_gain)` must
* be in [`1e-6f`, `1e12f`].
*
* Default value: `1e3f`.
*
@ -254,9 +255,10 @@ static inline void bw_hs1_set_high_gain_lin(
*
* Valid range: [`1e-30f`, `1e30f`].
*
* By the time `bw_hs1_update_coeffs_ctrl()`, `bw_hs1_update_coeffs_audio()`,
* `bw_hs1_process1()`, `bw_hs1_process()`, or `bw_hs1_process_multi()` is
* called, `cutoff * bw_sqrtf(high_gain)` must be in [`1e-6f`, `1e12f`].
* By the time `bw_hs1_reset_coeffs()`, `bw_hs1_update_coeffs_ctrl()`,
* `bw_hs1_update_coeffs_audio()`, `bw_hs1_process1()`, `bw_hs1_process()`,
* or `bw_hs1_process_multi()` is called, `cutoff * bw_sqrtf(high_gain)` must
* be in [`1e-6f`, `1e12f`].
*
* Default value: `1.f`.
*
@ -271,9 +273,10 @@ static inline void bw_hs1_set_high_gain_dB(
*
* Valid range: [`-600.f`, `600.f`].
*
* By the time `bw_hs1_update_coeffs_ctrl()`, `bw_hs1_update_coeffs_audio()`,
* `bw_hs1_process1()`, `bw_hs1_process()`, or `bw_hs1_process_multi()` is
* called, `cutoff * bw_sqrtf(high_gain)` must be in [`1e-6f`, `1e12f`].
* By the time `bw_hs1_reset_coeffs()`, `bw_hs1_update_coeffs_ctrl()`,
* `bw_hs1_update_coeffs_audio()`, `bw_hs1_process1()`, `bw_hs1_process()`,
* or `bw_hs1_process_multi()` is called, `cutoff * bw_sqrtf(high_gain)` must
* be in [`1e-6f`, `1e12f`].
*
* Default value: `0.f`.
*
@ -414,6 +417,7 @@ static inline void bw_hs1_reset_coeffs(
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hs1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hs1_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->cutoff * bw_sqrtf(coeffs->high_gain) >= 1e-6f && coeffs->cutoff * bw_sqrtf(coeffs->high_gain) <= 1e12f);
coeffs->update = 1;
bw_hs1_update_mm1_params(coeffs);

View File

@ -212,10 +212,10 @@ static inline void bw_hs2_set_cutoff(
*
* `value` must be finite and positive.
*
* By the time `bw_hs2_update_coeffs_ctrl()`, `bw_hs2_update_coeffs_audio()`,
* `bw_hs2_process1()`, `bw_hs2_process()`, or `bw_hs2_process_multi()` is
* called, `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_hs2_reset_coeffs()`, `bw_hs2_update_coeffs_ctrl()`,
* `bw_hs2_update_coeffs_audio()`, `bw_hs2_process1()`, `bw_hs2_process()`,
* or `bw_hs2_process_multi()` is called,
* `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1e3f`.
*
@ -268,10 +268,10 @@ static inline void bw_hs2_set_high_gain_lin(
*
* Valid range: [`1e-30f`, `1e30f`].
*
* By the time `bw_hs2_update_coeffs_ctrl()`, `bw_hs2_update_coeffs_audio()`,
* `bw_hs2_process1()`, `bw_hs2_process()`, or `bw_hs2_process_multi()` is
* called, `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_hs2_reset_coeffs()`, `bw_hs2_update_coeffs_ctrl()`,
* `bw_hs2_update_coeffs_audio()`, `bw_hs2_process1()`, `bw_hs2_process()`,
* or `bw_hs2_process_multi()` is called,
* `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1.f`.
*
@ -286,10 +286,10 @@ static inline void bw_hs2_set_high_gain_dB(
*
* Valid range: [`-600.f`, `600.f`].
*
* By the time `bw_hs2_update_coeffs_ctrl()`, `bw_hs2_update_coeffs_audio()`,
* `bw_hs2_process1()`, `bw_hs2_process()`, or `bw_hs2_process_multi()` is
* called, `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_hs2_reset_coeffs()`, `bw_hs2_update_coeffs_ctrl()`,
* `bw_hs2_update_coeffs_audio()`, `bw_hs2_process1()`, `bw_hs2_process()`,
* or `bw_hs2_process_multi()` is called,
* `cutoff * bw_sqrtf(bw_sqrtf(high_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `0.f`.
*
@ -440,6 +440,7 @@ static inline void bw_hs2_reset_coeffs(
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hs2_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hs2_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->cutoff * bw_sqrtf(bw_sqrtf(coeffs->high_gain)) >= 1e-6f && coeffs->cutoff * bw_sqrtf(bw_sqrtf(coeffs->high_gain)) <= 1e12f);
coeffs->param_changed = ~0;
bw_hs2_update_mm2_params(coeffs);

View File

@ -212,10 +212,10 @@ static inline void bw_ls1_set_cutoff(
*
* `value` must be finite and positive.
*
* By the time `bw_ls1_update_coeffs_ctrl()`, `bw_ls1_update_coeffs_audio()`,
* `bw_ls1_process1()`, `bw_ls1_process()`, or `bw_ls1_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_ls1_reset_coeffs()`, `bw_ls1_update_coeffs_ctrl()`,
* `bw_ls1_update_coeffs_audio()`, `bw_ls1_process1()`, `bw_ls1_process()`,
* or `bw_ls1_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1e3f`.
*
@ -255,10 +255,10 @@ static inline void bw_ls1_set_dc_gain_lin(
*
* Valid range: [`1e-30f`, `1e30f`].
*
* By the time `bw_ls1_update_coeffs_ctrl()`, `bw_ls1_update_coeffs_audio()`,
* `bw_ls1_process1()`, `bw_ls1_process()`, or `bw_ls1_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_ls1_reset_coeffs()`, `bw_ls1_update_coeffs_ctrl()`,
* `bw_ls1_update_coeffs_audio()`, `bw_ls1_process1()`, `bw_ls1_process()`,
* or `bw_ls1_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1.f`.
*
@ -272,10 +272,10 @@ static inline void bw_ls1_set_dc_gain_dB(
*
* Valid range: [`-600.f`, `600.f`].
*
* By the time `bw_ls1_update_coeffs_ctrl()`, `bw_ls1_update_coeffs_audio()`,
* `bw_ls1_process1()`, `bw_ls1_process()`, or `bw_ls1_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`,
* `1e12f`].
* By the time `bw_ls1_reset_coeffs()`, `bw_ls1_update_coeffs_ctrl()`,
* `bw_ls1_update_coeffs_audio()`, `bw_ls1_process1()`, `bw_ls1_process()`,
* or `bw_ls1_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(dc_gain))` must be in [`1e-6f`, `1e12f`].
*
* Default value: `0.f`.
*
@ -415,6 +415,7 @@ static inline void bw_ls1_reset_coeffs(
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_ls1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_ls1_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->cutoff * bw_rcpf(bw_sqrtf(coeffs->dc_gain)) >= 1e-6f && coeffs->cutoff * bw_rcpf(bw_sqrtf(coeffs->dc_gain)) <= 1e12f);
coeffs->update = 1;
bw_ls1_update_mm1_params(coeffs);

View File

@ -211,10 +211,11 @@ static inline void bw_ls2_set_cutoff(
*
* `value` must be finite and positive.
*
* By the time `bw_ls2_update_coeffs_ctrl()`, `bw_ls2_update_coeffs_audio()`,
* `bw_ls2_process1()`, `bw_ls2_process()`, or `bw_ls2_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in
* [`1e-6f`, `1e12f`].
* By the time ``bw_ls2_reset_coeffs(), `bw_ls2_update_coeffs_ctrl()`,
* `bw_ls2_update_coeffs_audio()`, `bw_ls2_process1()`, `bw_ls2_process()`,
* or `bw_ls2_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in [`1e-6f`,
* `1e12f`].
*
* Default value: `1e3f`.
*
@ -266,10 +267,11 @@ static inline void bw_ls2_set_dc_gain_lin(
*
* Valid range: [`1e-30f`, `1e30f`].
*
* By the time `bw_ls2_update_coeffs_ctrl()`, `bw_ls2_update_coeffs_audio()`,
* `bw_ls2_process1()`, `bw_ls2_process()`, or `bw_ls2_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in
* [`1e-6f`, `1e12f`].
* By the time ``bw_ls2_reset_coeffs(), `bw_ls2_update_coeffs_ctrl()`,
* `bw_ls2_update_coeffs_audio()`, `bw_ls2_process1()`, `bw_ls2_process()`,
* or `bw_ls2_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in [`1e-6f`,
* `1e12f`].
*
* Default value: `1.f`.
*
@ -283,10 +285,11 @@ static inline void bw_ls2_set_dc_gain_dB(
*
* Valid range: [`-600.f`, `600.f`].
*
* By the time `bw_ls2_update_coeffs_ctrl()`, `bw_ls2_update_coeffs_audio()`,
* `bw_ls2_process1()`, `bw_ls2_process()`, or `bw_ls2_process_multi()` is
* called, `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in
* [`1e-6f`, `1e12f`].
* By the time ``bw_ls2_reset_coeffs(), `bw_ls2_update_coeffs_ctrl()`,
* `bw_ls2_update_coeffs_audio()`, `bw_ls2_process1()`, `bw_ls2_process()`,
* or `bw_ls2_process_multi()` is called,
* `cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(dc_gain)))` must be in [`1e-6f`,
* `1e12f`].
*
* Default value: `0.f`.
*
@ -437,6 +440,7 @@ static inline void bw_ls2_reset_coeffs(
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_ls2_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_ls2_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(coeffs->dc_gain))) >= 1e-6f && coeffs->cutoff * bw_rcpf(bw_sqrtf(bw_sqrtf(coeffs->dc_gain))) <= 1e12f);
coeffs->param_changed = ~0;
bw_ls2_update_mm2_params(coeffs);

View File

@ -486,7 +486,7 @@ static inline float bw_sqrtf(
/*! <<<```
* Returns an approximation of the square root of `x`.
*
* `x` must be finite and greater than or equal to `0.f`.
* `x` must be finite and non-negative.
*
* Absolute error < 1.09e-19 or relative error < 0.0007%, whatever is worse.
*

View File

@ -272,9 +272,10 @@ static inline void bw_peak_set_peak_gain_lin(
* Valid range: [`1e-30f`, `1e30f`].
*
* If actually using the bandwidth parameter to control Q, by the time
* `bw_peak_update_coeffs_ctrl()`, `bw_peak_update_coeffs_audio()`,
* `bw_peak_process1()`, `bw_peak_process()`, or `bw_peak_process_multi()` is
* called, `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* `bw_peak_reset_coeffs()`, `bw_peak_update_coeffs_ctrl()`,
* `bw_peak_update_coeffs_audio()`, `bw_peak_process1()`,
* `bw_peak_process()`, or `bw_peak_process_multi()` is called,
* `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* bw_rcpf(bw_pow2f(bandwidth) - 1.f)` must be in [`1e-6f`, `1e6f`].
*
* Default value: `1.f`.
@ -290,9 +291,10 @@ static inline void bw_peak_set_peak_gain_dB(
* Valid range: [`-600.f`, `600.f`].
*
* If actually using the bandwidth parameter to control Q, by the time
* `bw_peak_update_coeffs_ctrl()`, `bw_peak_update_coeffs_audio()`,
* `bw_peak_process1()`, `bw_peak_process()`, or `bw_peak_process_multi()` is
* called, `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* `bw_peak_reset_coeffs()`, `bw_peak_update_coeffs_ctrl()`,
* `bw_peak_update_coeffs_audio()`, `bw_peak_process1()`,
* `bw_peak_process()`, or `bw_peak_process_multi()` is called,
* `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* bw_rcpf(bw_pow2f(bandwidth) - 1.f)` must be in [`1e-6f`, `1e6f`].
*
* Default value: `0.f`.
@ -308,9 +310,10 @@ static inline void bw_peak_set_bandwidth(
* Valid range: [`1e-6f`, `90.f`].
*
* If actually using the bandwidth parameter to control Q, by the time
* `bw_peak_update_coeffs_ctrl()`, `bw_peak_update_coeffs_audio()`,
* `bw_peak_process1()`, `bw_peak_process()`, or `bw_peak_process_multi()` is
* called, `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* `bw_peak_reset_coeffs()`, `bw_peak_update_coeffs_ctrl()`,
* `bw_peak_update_coeffs_audio()`, `bw_peak_process1()`,
* `bw_peak_process()`, or `bw_peak_process_multi()` is called,
* `bw_sqrtf(bw_pow2f(bandwidth) * peak_gain) *
* bw_rcpf(bw_pow2f(bandwidth) - 1.f)` must be in [`1e-6f`, `1e6f`].
*
* Default value: `2.543106606327224f`.
@ -478,6 +481,10 @@ static inline void bw_peak_reset_coeffs(
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_peak_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_peak_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: 1);
coeffs->param_changed = ~0;
bw_peak_update_mm2_params(coeffs);
@ -547,7 +554,7 @@ static inline void bw_peak_update_coeffs_ctrl(
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: coeffs->Q >= 1e-6 && coeffs->Q <= 1e6);
: 1);
bw_peak_update_mm2_params(coeffs);
bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs);
@ -564,7 +571,7 @@ static inline void bw_peak_update_coeffs_audio(
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: coeffs->Q >= 1e-6 && coeffs->Q <= 1e6);
: 1);
bw_mm2_update_coeffs_audio(&coeffs->mm2_coeffs);
@ -582,7 +589,7 @@ static inline float bw_peak_process1(
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: coeffs->Q >= 1e-6 && coeffs->Q <= 1e6);
: 1);
BW_ASSERT(state != NULL);
BW_ASSERT_DEEP(bw_peak_state_is_valid(coeffs, state));
BW_ASSERT(bw_is_finite(x));
@ -609,7 +616,7 @@ static inline void bw_peak_process(
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: coeffs->Q >= 1e-6 && coeffs->Q <= 1e6);
: 1);
BW_ASSERT(state != NULL);
BW_ASSERT_DEEP(bw_peak_state_is_valid(coeffs, state));
BW_ASSERT(x != NULL);
@ -642,7 +649,7 @@ static inline void bw_peak_process_multi(
BW_ASSERT_DEEP(coeffs->use_bandwidth
? bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) >= 1e-6f
&& bw_sqrtf(bw_pow2f(coeffs->bandwidth) * coeffs->peak_gain) * bw_rcpf(bw_pow2f(coeffs->bandwidth) - 1.f) <= 1e6f
: coeffs->Q >= 1e-6 && coeffs->Q <= 1e6);
: 1);
BW_ASSERT(state != NULL);
BW_ASSERT(x != NULL);
BW_ASSERT(y != NULL);

View File

@ -32,6 +32,14 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Added initial input value to
* <code>bw_phaser_reset_state()</code>.</li>
* <li>Added <code>bw_phaser_reset_state_multi()</code> and updated C++
* API in this regard.</li>
* <li>Now <code>bw_phaser_reset_state()</code> returns the initial
* output value.</li>
* <li>Added overloaded C++ <code>reset()</code> functions taking
* arrays as arguments.</li>
* <li><code>bw_phaser_process()</code> and
* <code>bw_phaser_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
@ -40,7 +48,10 @@
* <li>Moved C++ code to C header.</li>
* <li>Added overloaded C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed internal limits on cutoff frequency.</li>
* <li>Removed usage of reserved identifiers.</li>
* <li>Clearly specified parameter validity ranges.</li>
* <li>Added debugging code.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -88,50 +99,86 @@ typedef struct bw_phaser_state bw_phaser_state;
*
* #### bw_phaser_init()
* ```>>> */
static inline void bw_phaser_init(bw_phaser_coeffs *BW_RESTRICT coeffs);
static inline void bw_phaser_init(
bw_phaser_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Initializes input parameter values in `coeffs`.
*
* #### bw_phaser_set_sample_rate()
* ```>>> */
static inline void bw_phaser_set_sample_rate(bw_phaser_coeffs *BW_RESTRICT coeffs, float sample_rate);
static inline void bw_phaser_set_sample_rate(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value in `coeffs`.
*
* #### bw_phaser_reset_coeffs()
* ```>>> */
static inline void bw_phaser_reset_coeffs(bw_phaser_coeffs *BW_RESTRICT coeffs);
static inline void bw_phaser_reset_coeffs(
bw_phaser_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Resets coefficients in `coeffs` to assume their target values.
*
* #### bw_phaser_reset_state()
* ```>>> */
static inline void bw_phaser_reset_state(const bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state);
static inline float bw_phaser_reset_state(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
float x_0);
/*! <<<```
* 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 initial input value `x_0`.
*
* Returns the corresponding initial output value.
*
* #### bw_phaser_reset_state_multi()
* ```>>> */
static inline void bw_phaser_reset_state_multi(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT const * BW_RESTRICT state,
const float * x_0,
float * y_0,
size_t n_channels);
/*! <<<```
* Resets each of the `n_channels` `state`s to its initial values using the
* given `coeffs` and the corresponding initial input value in the `x_0`
* array.
*
* The corresponding initial output values are written into the `y_0` array,
* if not `NULL`.
*
* #### bw_phaser_update_coeffs_ctrl()
* ```>>> */
static inline void bw_phaser_update_coeffs_ctrl(bw_phaser_coeffs *BW_RESTRICT coeffs);
static inline void bw_phaser_update_coeffs_ctrl(
bw_phaser_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Triggers control-rate update of coefficients in `coeffs`.
*
* #### bw_phaser_update_coeffs_audio()
* ```>>> */
static inline void bw_phaser_update_coeffs_audio(bw_phaser_coeffs *BW_RESTRICT coeffs);
static inline void bw_phaser_update_coeffs_audio(
bw_phaser_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Triggers audio-rate update of coefficients in `coeffs`.
*
* #### bw_phaser_process1()
* ```>>> */
static inline float bw_phaser_process1(const bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, float x);
static inline float bw_phaser_process1(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
float x);
/*! <<<```
* Processes one input sample `x` using `coeffs`, while using and updating
* `state`. Returns the corresponding output sample.
*
* #### bw_phaser_process()
* ```>>> */
static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
static inline void bw_phaser_process(
bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
const float * x,
float * y,
size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffer `y`, while using and updating both
@ -139,7 +186,13 @@ static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_ph
*
* #### bw_phaser_process_multi()
* ```>>> */
static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT const *BW_RESTRICT state, const float * const *x, float * const *y, size_t n_channels, size_t n_samples);
static inline void bw_phaser_process_multi(
bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT const * BW_RESTRICT state,
const float * const * x,
float * const * y,
size_t n_channels,
size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -148,27 +201,77 @@ static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs,
*
* #### bw_phaser_set_rate()
* ```>>> */
static inline void bw_phaser_set_rate(bw_phaser_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_phaser_set_rate(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value);
/*! <<<```
* Sets the modulation rate `value` (Hz) in `coeffs`.
*
* `value` must be finite.
*
* Default value: `1.f`.
*
* #### bw_phaser_set_center()
* ```>>> */
static inline void bw_phaser_set_center(bw_phaser_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_phaser_set_center(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value);
/*! <<<```
* Sets the center frequency `value` (Hz) in `coeffs`.
*
* Valid range: [`1e-6f`, `1e12f`].
*
* By the time `bw_phaser_reset_coeffs()`, `bw_phaser_update_coeffs_ctrl()`,
* `bw_phaser_update_coeffs_audio()`, `bw_phaser_process1()`,
* `bw_phaser_process()`, or `bw_phaser_process_multi()` is called,
* `center * bw_pow2f(amount)` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1e3f`.
*
* #### bw_phaser_set_amount()
* ```>>> */
static inline void bw_phaser_set_amount(bw_phaser_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_phaser_set_amount(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value);
/*! <<<```
* Sets the modulation amount `value` (octaves) in `coeffs`.
*
* `value` must be finite and non-negative.
*
* By the time `bw_phaser_reset_coeffs()`, `bw_phaser_update_coeffs_ctrl()`,
* `bw_phaser_update_coeffs_audio()`, `bw_phaser_process1()`,
* `bw_phaser_process()`, or `bw_phaser_process_multi()` is called,
* `center * bw_pow2f(amount)` must be in [`1e-6f`, `1e12f`].
*
* Default value: `1.f`.
*
* #### bw_phaser_coeffs_is_valid()
* ```>>> */
static inline char bw_phaser_coeffs_is_valid(
const bw_phaser_coeffs * BW_RESTRICT coeffs);
/*! <<<```
* Tries to determine whether `coeffs` is valid and returns non-`0` if it
* seems to be the case and `0` if it is certainly not. False positives are
* possible, false negatives are not.
*
* `coeffs` must at least point to a readable memory block of size greater
* than or equal to that of `bw_phaser_coeffs`.
*
* #### bw_phaser_state_is_valid()
* ```>>> */
static inline char bw_phaser_state_is_valid(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
const bw_phaser_state * BW_RESTRICT state);
/*! <<<```
* Tries to determine whether `state` is valid and returns non-`0` if it
* seems to be the case and `0` if it is certainly not. False positives are
* possible, false negatives are not.
*
* If `coeffs` is not `NULL` extra cross-checks might be performed (`state`
* is supposed to be associated to `coeffs`).
*
* `state` must at least point to a readable memory block of size greater
* than or equal to that of `bw_phaser_state`.
* }}} */
#ifdef __cplusplus
@ -189,99 +292,350 @@ static inline void bw_phaser_set_amount(bw_phaser_coeffs *BW_RESTRICT coeffs, fl
extern "C" {
#endif
#ifdef BW_DEBUG_DEEP
enum bw_phaser_coeffs_state {
bw_phaser_coeffs_state_invalid,
bw_phaser_coeffs_state_init,
bw_phaser_coeffs_state_set_sample_rate,
bw_phaser_coeffs_state_reset_coeffs
};
#endif
struct bw_phaser_coeffs {
#ifdef BW_DEBUG_DEEP
uint32_t hash;
enum bw_phaser_coeffs_state state;
uint32_t reset_id;
#endif
// Sub-components
bw_phase_gen_coeffs phase_gen_coeffs;
bw_phase_gen_state phase_gen_state;
bw_ap1_coeffs ap1_coeffs;
// Coefficients
float cutoff_max;
// Parameters
float center;
float amount;
};
struct bw_phaser_state {
#ifdef BW_DEBUG_DEEP
uint32_t hash;
uint32_t coeffs_reset_id;
#endif
// Sub-components
bw_ap1_state ap1_state[4];
};
static inline void bw_phaser_init(bw_phaser_coeffs *BW_RESTRICT coeffs) {
static inline void bw_phaser_init(
bw_phaser_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
bw_phase_gen_init(&coeffs->phase_gen_coeffs);
bw_ap1_init(&coeffs->ap1_coeffs);
coeffs->center = 1e3f;
coeffs->amount = 1.f;
#ifdef BW_DEBUG_DEEP
coeffs->hash = bw_hash_sdbm("bw_phaser_coeffs");
coeffs->state = bw_phaser_coeffs_state_init;
coeffs->reset_id = coeffs->hash + 1;
#endif
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_phaser_coeffs_state_init);
}
static inline void bw_phaser_set_sample_rate(bw_phaser_coeffs *BW_RESTRICT coeffs, float sample_rate) {
static inline void bw_phaser_set_sample_rate(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float sample_rate) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
bw_phase_gen_set_sample_rate(&coeffs->phase_gen_coeffs, sample_rate);
bw_ap1_set_sample_rate(&coeffs->ap1_coeffs, sample_rate);
coeffs->cutoff_max = 0.48f * sample_rate;
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_phaser_coeffs_state_set_sample_rate;
#endif
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_phaser_coeffs_state_set_sample_rate);
}
static inline void bw_phaser_reset_coeffs(bw_phaser_coeffs *BW_RESTRICT coeffs) {
static inline void bw_phaser_reset_coeffs(
bw_phaser_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_set_sample_rate);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
bw_phase_gen_reset_coeffs(&coeffs->phase_gen_coeffs);
bw_phase_gen_reset_state(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state, 0.f);
bw_ap1_set_cutoff(&coeffs->ap1_coeffs, bw_clipf(coeffs->center, 1.f, coeffs->cutoff_max));
float p, inc;
bw_phase_gen_reset_state(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state, 0.f, &p, &inc);
bw_ap1_set_cutoff(&coeffs->ap1_coeffs, coeffs->center);
bw_ap1_reset_coeffs(&coeffs->ap1_coeffs);
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_phaser_coeffs_state_reset_coeffs;
coeffs->reset_id++;
#endif
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_phaser_coeffs_state_reset_coeffs);
}
static inline void bw_phaser_reset_state(const bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state) {
bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[0], 0.f);
bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[1], 0.f);
bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[2], 0.f);
bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[3], 0.f);
static inline float bw_phaser_reset_state(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
float x_0) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT(state != NULL);
BW_ASSERT(bw_is_finite(x_0));
float y = bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[0], x_0);
y = bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[1], y);
y = bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[2], y);
y = x_0 + bw_ap1_reset_state(&coeffs->ap1_coeffs, &state->ap1_state[3], y);
#ifdef BW_DEBUG_DEEP
state->hash = bw_hash_sdbm("bw_phaser_state");
state->coeffs_reset_id = coeffs->reset_id;
#endif
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(bw_phaser_state_is_valid(coeffs, state));
BW_ASSERT(bw_is_finite(y));
return y;
}
static inline void bw_phaser_update_coeffs_ctrl(bw_phaser_coeffs *BW_RESTRICT coeffs) {
static inline void bw_phaser_reset_state_multi(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT const * BW_RESTRICT state,
const float * x_0,
float * y_0,
size_t n_channels) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT(state != NULL);
BW_ASSERT(x_0 != NULL);
if (y_0 != NULL)
for (size_t i = 0; i < n_channels; i++)
y_0[i] = bw_phaser_reset_state(coeffs, state[i], x_0[i]);
else
for (size_t i = 0; i < n_channels; i++)
bw_phaser_reset_state(coeffs, state[i], x_0[i]);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
}
static inline void bw_phaser_update_coeffs_ctrl(
bw_phaser_coeffs *BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
bw_phase_gen_update_coeffs_ctrl(&coeffs->phase_gen_coeffs);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
}
static inline void bw_phaser_update_coeffs_audio(bw_phaser_coeffs *BW_RESTRICT coeffs) {
static inline void bw_phaser_update_coeffs_audio(
bw_phaser_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
bw_phase_gen_update_coeffs_audio(&coeffs->phase_gen_coeffs);
float p, pi;
bw_phase_gen_process1(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state, &p, &pi);
const float m = coeffs->amount * bw_osc_sin_process1(p);
bw_ap1_set_cutoff(&coeffs->ap1_coeffs, bw_clipf(coeffs->center * bw_pow2f(m), 1.f, coeffs->cutoff_max));
bw_ap1_set_cutoff(&coeffs->ap1_coeffs, coeffs->center * bw_pow2f(m));
bw_ap1_update_coeffs_ctrl(&coeffs->ap1_coeffs);
bw_ap1_update_coeffs_audio(&coeffs->ap1_coeffs);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
}
static inline float bw_phaser_process1(const bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, float x) {
static inline float bw_phaser_process1(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
float x) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
BW_ASSERT(state != NULL);
BW_ASSERT_DEEP(bw_phaser_state_is_valid(coeffs, state));
BW_ASSERT(bw_is_finite(x));
float y = bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[0], x);
y = bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[1], y);
y = bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[2], y);
return x + bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[3], y);
y = x + bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[3], y);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(bw_phaser_state_is_valid(coeffs, state));
BW_ASSERT(bw_is_finite(y));
return y;
}
static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
static inline void bw_phaser_process(
bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT state,
const float * x,
float * y,
size_t n_samples) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
BW_ASSERT(state != NULL);
BW_ASSERT_DEEP(bw_phaser_state_is_valid(coeffs, state));
BW_ASSERT(x != NULL);
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
BW_ASSERT(y != NULL);
bw_phaser_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_phaser_update_coeffs_audio(coeffs);
y[i] = bw_phaser_process1(coeffs, state, x[i]);
}
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(bw_phaser_state_is_valid(coeffs, state));
BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
}
static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT const *BW_RESTRICT state, const float * const *x, float * const *y, size_t n_channels, size_t n_samples) {
static inline void bw_phaser_process_multi(
bw_phaser_coeffs * BW_RESTRICT coeffs,
bw_phaser_state * BW_RESTRICT const * BW_RESTRICT state,
const float * const * x,
float * const * y,
size_t n_channels,
size_t n_samples) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
BW_ASSERT_DEEP(coeffs->center * bw_pow2f(coeffs->amount) >= 1e-6f && coeffs->center * bw_pow2f(coeffs->amount) <= 1e12f);
BW_ASSERT(state != NULL);
BW_ASSERT(x != NULL);
BW_ASSERT(y != NULL);
bw_phaser_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_phaser_update_coeffs_audio(coeffs);
for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_phaser_process1(coeffs, state[j], x[j][i]);
}
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_reset_coeffs);
}
static inline void bw_phaser_set_rate(bw_phaser_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_phaser_set_rate(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
BW_ASSERT(bw_is_finite(value));
bw_phase_gen_set_frequency(&coeffs->phase_gen_coeffs, value);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
}
static inline void bw_phaser_set_center(bw_phaser_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_phaser_set_center(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
BW_ASSERT(bw_is_finite(value));
BW_ASSERT(value >= 1e-6f && value <= 1e12f);
coeffs->center = value;
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
}
static inline void bw_phaser_set_amount(bw_phaser_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_phaser_set_amount(
bw_phaser_coeffs * BW_RESTRICT coeffs,
float value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
BW_ASSERT(bw_is_finite(value));
BW_ASSERT(value >= 0.f);
coeffs->amount = value;
BW_ASSERT_DEEP(bw_phaser_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_phaser_coeffs_state_init);
}
#include <stdio.h>
static inline char bw_phaser_coeffs_is_valid(
const bw_phaser_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
#ifdef BW_DEBUG_DEEP
if (coeffs->hash != bw_hash_sdbm("bw_phaser_coeffs"))
return 0;
if (coeffs->state < bw_phaser_coeffs_state_init || coeffs->state > bw_phaser_coeffs_state_reset_coeffs)
return 0;
#endif
if (!bw_is_finite(coeffs->center) || coeffs->center < 1e-6f || coeffs->center > 1e12f)
return 0;
if (!bw_is_finite(coeffs->amount) || coeffs->amount < 0.f)
return 0;
if (!bw_phase_gen_coeffs_is_valid(&coeffs->phase_gen_coeffs))
return 0;
#ifdef BW_DEBUG_DEEP
if (coeffs->state >= bw_phaser_coeffs_state_reset_coeffs && !bw_phase_gen_state_is_valid(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state))
return 0;
#endif
return bw_ap1_coeffs_is_valid(&coeffs->ap1_coeffs);
}
static inline char bw_phaser_state_is_valid(
const bw_phaser_coeffs * BW_RESTRICT coeffs,
const bw_phaser_state * BW_RESTRICT state) {
BW_ASSERT(state != NULL);
#ifdef BW_DEBUG_DEEP
if (state->hash != bw_hash_sdbm("bw_phaser_state"))
return 0;
if (coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
return 0;
#endif
return bw_ap1_state_is_valid(coeffs ? &coeffs->ap1_coeffs : NULL, &state->ap1_state[0])
&& bw_ap1_state_is_valid(coeffs ? &coeffs->ap1_coeffs : NULL, &state->ap1_state[1])
&& bw_ap1_state_is_valid(coeffs ? &coeffs->ap1_coeffs : NULL, &state->ap1_state[2])
&& bw_ap1_state_is_valid(coeffs ? &coeffs->ap1_coeffs : NULL, &state->ap1_state[3]);
}
#ifdef __cplusplus
@ -301,20 +655,43 @@ class Phaser {
public:
Phaser();
void setSampleRate(float sampleRate);
void reset();
void setSampleRate(
float sampleRate);
void reset(
float x0 = 0.f,
float * BW_RESTRICT y0 = nullptr);
void reset(
float x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0);
void reset(
const float * x0,
float * y0 = nullptr);
void reset(
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = nullptr);
void process(
const float * const *x,
float * const *y,
const float * const * x,
float * const * y,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setRate(float value);
void setCenter(float value);
void setAmount(float value);
void setRate(
float value);
void setCenter(
float value);
void setAmount(
float value);
/*! <<<...
* }
* ```
@ -328,7 +705,7 @@ public:
private:
bw_phaser_coeffs coeffs;
bw_phaser_state states[N_CHANNELS];
bw_phaser_state *BW_RESTRICT statesP[N_CHANNELS];
bw_phaser_state * BW_RESTRICT statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
@ -339,21 +716,50 @@ inline Phaser<N_CHANNELS>::Phaser() {
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setSampleRate(float sampleRate) {
inline void Phaser<N_CHANNELS>::setSampleRate(
float sampleRate) {
bw_phaser_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset() {
inline void Phaser<N_CHANNELS>::reset(
float x0,
float * BW_RESTRICT y0) {
bw_phaser_reset_coeffs(&coeffs);
if (y0 != nullptr)
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phaser_reset_state(&coeffs, states + i);
y0[i] = bw_phaser_reset_state(&coeffs, states + i, x0);
else
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phaser_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset(
float x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0) {
reset(x0, y0 != nullptr ? y0->data() : nullptr);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset(
const float * x0,
float * y0) {
bw_phaser_reset_coeffs(&coeffs);
bw_phaser_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset(
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0) {
reset(x0.data(), y0 != nullptr ? y0->data() : nullptr);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::process(
const float * const *x,
float * const *y,
const float * const * x,
float * const * y,
size_t nSamples) {
bw_phaser_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
@ -367,17 +773,20 @@ inline void Phaser<N_CHANNELS>::process(
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setRate(float value) {
inline void Phaser<N_CHANNELS>::setRate(
float value) {
bw_phaser_set_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setCenter(float value) {
inline void Phaser<N_CHANNELS>::setCenter(
float value) {
bw_phaser_set_center(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setAmount(float value) {
inline void Phaser<N_CHANNELS>::setAmount(
float value) {
bw_phaser_set_amount(&coeffs, value);
}