finalized bw_comb + examples + better debug in bw_delay
This commit is contained in:
parent
49a06b52eb
commit
07ff65597f
1
TODO
1
TODO
@ -18,6 +18,7 @@ finally:
|
||||
* thank scientific paper authors
|
||||
* change config.h in examples version 1.0.0
|
||||
* "Templates must have C++ linkage"?
|
||||
* state that mem_set() can/must be called on uninitialized state (before reset_state)
|
||||
|
||||
build system:
|
||||
* single header generation (vs modules in bwp... to think about)
|
||||
|
@ -38,7 +38,7 @@ void bw_example_fx_comb_mem_set(bw_example_fx_comb *instance, void *mem) {
|
||||
|
||||
void bw_example_fx_comb_reset(bw_example_fx_comb *instance) {
|
||||
bw_comb_reset_coeffs(&instance->comb_coeffs);
|
||||
bw_comb_reset_state(&instance->comb_coeffs, &instance->comb_state);
|
||||
bw_comb_reset_state(&instance->comb_coeffs, &instance->comb_state, 0.f);
|
||||
}
|
||||
|
||||
void bw_example_fx_comb_process(bw_example_fx_comb *instance, const float** x, float** y, int n_samples) {
|
||||
|
@ -4,3 +4,6 @@ NAME := bw_example_fx_comb
|
||||
SOURCE := bw_example_fx_comb.c
|
||||
|
||||
include ${ROOT_DIR}/../../common/vst3/vst3.mk
|
||||
|
||||
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
|
||||
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP
|
||||
|
@ -4,3 +4,6 @@ NAME := bw_example_fxpp_comb
|
||||
SOURCE := bw_example_fxpp_comb.cpp
|
||||
|
||||
include ${ROOT_DIR}/../../common/vst3/vst3.mk
|
||||
|
||||
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
|
||||
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP
|
||||
|
@ -33,7 +33,7 @@
|
||||
* J. Audio Eng. Soc., vol. 45, no. 10, pp. 764-788, October 1997.
|
||||
*
|
||||
* Unlike in the original paper, the feedback signal is not subtracted but
|
||||
* rather added to the input.
|
||||
* rather added to the input.
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
@ -41,6 +41,10 @@
|
||||
* <ul>
|
||||
* <li>Added initial value argument in
|
||||
* <code>bw_chorus_reset_state()</code>.</li>
|
||||
* <li>Added <code>bw_comb_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_comb_reset_state()</code> returns the initial
|
||||
* output value.</li>
|
||||
* <li>Added overloaded C++ <code>reset()</code> functions taking
|
||||
* arrays as arguments.</li>
|
||||
* <li>Now using <code>size_t</code> instead of
|
||||
@ -54,6 +58,8 @@
|
||||
* <li>Added overloaded C++ <code>process()</code> function taking
|
||||
* C-style arrays as arguments.</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>:
|
||||
@ -102,65 +108,113 @@ typedef struct bw_comb_state bw_comb_state;
|
||||
*
|
||||
* #### bw_comb_init()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_init(bw_comb_coeffs *BW_RESTRICT coeffs, float max_delay);
|
||||
static inline void bw_comb_init(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float max_delay);
|
||||
/*! <<<```
|
||||
* Initializes input parameter values in `coeffs` using `max_delay` (s) as
|
||||
* the maximum delay time.
|
||||
*
|
||||
* `max_delay` must be finite and non-negative.
|
||||
*
|
||||
* #### bw_comb_set_sample_rate()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_sample_rate(bw_comb_coeffs *BW_RESTRICT coeffs, float sample_rate);
|
||||
static inline void bw_comb_set_sample_rate(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float sample_rate);
|
||||
/*! <<<```
|
||||
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
||||
*
|
||||
* #### bw_comb_mem_req()
|
||||
* ```>>> */
|
||||
static inline size_t bw_comb_mem_req(const bw_comb_coeffs *BW_RESTRICT coeffs);
|
||||
static inline size_t bw_comb_mem_req(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Returns the size, in bytes, of contiguous memory to be supplied to
|
||||
* `bw_comb_mem_set()` using `coeffs`.
|
||||
*
|
||||
* #### bw_comb_mem_set()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_mem_set(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, void *BW_RESTRICT mem);
|
||||
static inline void bw_comb_mem_set(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
void * BW_RESTRICT mem);
|
||||
/*! <<<```
|
||||
* Associates the contiguous memory block `mem` to the given `state`.
|
||||
* Associates the contiguous memory block `mem` to the given `state` using
|
||||
* `coeffs`.
|
||||
*
|
||||
* #### bw_comb_reset_coeffs()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_reset_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs);
|
||||
static inline void bw_comb_reset_coeffs(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Resets coefficients in `coeffs` to assume their target values.
|
||||
*
|
||||
* #### bw_comb_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_reset_state(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, float x_0);
|
||||
static inline float bw_comb_reset_state(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
/*! <<<```
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
* and the initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding initial output value.
|
||||
*
|
||||
* If parameter `fb` has value `-1.f` or `1.f`, then `x_0` must be `0.f`.
|
||||
*
|
||||
* #### bw_comb_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_reset_state_multi(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_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`.
|
||||
*
|
||||
* If parameter `fb` has value `-1.f` or `1.f`, then `x_0` must only contain
|
||||
* `0.f`.
|
||||
*
|
||||
* #### bw_comb_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_update_coeffs_ctrl(bw_comb_coeffs *BW_RESTRICT coeffs);
|
||||
static inline void bw_comb_update_coeffs_ctrl(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers control-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_comb_update_coeffs_audio()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_update_coeffs_audio(bw_comb_coeffs *BW_RESTRICT coeffs);
|
||||
static inline void bw_comb_update_coeffs_audio(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers audio-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_comb_process1()
|
||||
* ```>>> */
|
||||
static inline float bw_comb_process1(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, float x);
|
||||
static inline float bw_comb_process1(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Processes one input sample `x` using `coeffs`, while using and updating
|
||||
* `state`. Returns the corresponding output sample.
|
||||
*
|
||||
* #### bw_comb_process()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
|
||||
static inline void bw_comb_process(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_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
|
||||
@ -168,7 +222,13 @@ static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_s
|
||||
*
|
||||
* #### bw_comb_process_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_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_comb_process_multi(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_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
|
||||
@ -177,43 +237,95 @@ static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_
|
||||
*
|
||||
* #### bw_comb_set_delay_ff()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_delay_ff(bw_comb_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comb_set_delay_ff(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the feedforward delay time `value` (s) in `coeffs`.
|
||||
*
|
||||
* This parameter is internally limited to avoid buffer overflows.
|
||||
*
|
||||
* `value` must be finite.
|
||||
*
|
||||
* Default value: `0.f`.
|
||||
*
|
||||
* #### bw_comb_set_delay_fb()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_delay_fb(bw_comb_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comb_set_delay_fb(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the feedback delay time `value` (s) in `coeffs`.
|
||||
*
|
||||
* This parameter is internally limited to avoid buffer overflows.
|
||||
*
|
||||
* `value` must be finite.
|
||||
*
|
||||
* Default value: `0.f`.
|
||||
*
|
||||
* #### bw_comb_set_coeff_blend()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_coeff_blend(bw_comb_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comb_set_coeff_blend(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the blend coefficient `value` in `coeffs`.
|
||||
*
|
||||
* `value` must be finite.
|
||||
*
|
||||
* Default value: `1.f`.
|
||||
*
|
||||
* #### bw_comb_set_coeff_ff()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_coeff_ff(bw_comb_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comb_set_coeff_ff(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the feedforward coefficient `value` in `coeffs`.
|
||||
*
|
||||
* `value` must be finite.
|
||||
*
|
||||
* Default value: `0.f`.
|
||||
*
|
||||
* #### bw_comb_set_coeff_fb()
|
||||
* ```>>> */
|
||||
static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comb_set_coeff_fb(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the feedback coefficient `value` in `coeffs`.
|
||||
*
|
||||
* Valid range: [`-1.f`, `1.f`].
|
||||
*
|
||||
* Default value: `0.f`.
|
||||
*
|
||||
* #### bw_comb_coeffs_is_valid()
|
||||
* ```>>> */
|
||||
static inline char bw_comb_coeffs_is_valid(
|
||||
const bw_comb_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_comb_coeffs`.
|
||||
*
|
||||
* #### bw_comb_state_is_valid()
|
||||
* ```>>> */
|
||||
static inline char bw_comb_state_is_valid(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
const bw_comb_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_comb_state`.
|
||||
* }}} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -234,35 +346,70 @@ static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, floa
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
enum bw_comb_coeffs_state {
|
||||
bw_comb_coeffs_state_invalid,
|
||||
bw_comb_coeffs_state_init,
|
||||
bw_comb_coeffs_state_set_sample_rate,
|
||||
bw_comb_coeffs_state_reset_coeffs
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
enum bw_comb_state_state {
|
||||
bw_comb_state_state_invalid,
|
||||
bw_comb_state_state_mem_set,
|
||||
bw_comb_state_state_reset_state
|
||||
};
|
||||
#endif
|
||||
|
||||
struct bw_comb_coeffs {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
enum bw_comb_coeffs_state state;
|
||||
uint32_t reset_id;
|
||||
#endif
|
||||
|
||||
// Sub-components
|
||||
bw_delay_coeffs delay_coeffs;
|
||||
bw_gain_coeffs blend_coeffs;
|
||||
bw_gain_coeffs ff_coeffs;
|
||||
bw_gain_coeffs fb_coeffs;
|
||||
bw_one_pole_coeffs smooth_coeffs;
|
||||
bw_one_pole_state smooth_delay_ff_state;
|
||||
bw_one_pole_state smooth_delay_fb_state;
|
||||
bw_delay_coeffs delay_coeffs;
|
||||
bw_gain_coeffs blend_coeffs;
|
||||
bw_gain_coeffs ff_coeffs;
|
||||
bw_gain_coeffs fb_coeffs;
|
||||
bw_one_pole_coeffs smooth_coeffs;
|
||||
bw_one_pole_state smooth_delay_ff_state;
|
||||
bw_one_pole_state smooth_delay_fb_state;
|
||||
|
||||
// Coefficients
|
||||
float fs;
|
||||
float fs;
|
||||
|
||||
size_t dffi;
|
||||
float dfff;
|
||||
size_t dfbi;
|
||||
float dfbf;
|
||||
size_t dffi;
|
||||
float dfff;
|
||||
size_t dfbi;
|
||||
float dfbf;
|
||||
|
||||
// Parameters
|
||||
float delay_ff;
|
||||
float delay_fb;
|
||||
float delay_ff;
|
||||
float delay_fb;
|
||||
};
|
||||
|
||||
struct bw_comb_state {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
enum bw_comb_state_state state;
|
||||
uint32_t coeffs_reset_id;
|
||||
#endif
|
||||
|
||||
// Sub-components
|
||||
bw_delay_state delay_state;
|
||||
bw_delay_state delay_state;
|
||||
};
|
||||
|
||||
static inline void bw_comb_init(bw_comb_coeffs *BW_RESTRICT coeffs, float max_delay) {
|
||||
static inline void bw_comb_init(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float max_delay) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT(bw_is_finite(max_delay));
|
||||
BW_ASSERT(max_delay >= 0.f);
|
||||
|
||||
bw_delay_init(&coeffs->delay_coeffs, max_delay);
|
||||
bw_gain_init(&coeffs->blend_coeffs);
|
||||
bw_gain_init(&coeffs->ff_coeffs);
|
||||
@ -274,27 +421,73 @@ static inline void bw_comb_init(bw_comb_coeffs *BW_RESTRICT coeffs, float max_de
|
||||
bw_gain_set_gain_lin(&coeffs->fb_coeffs, 0.f);
|
||||
coeffs->delay_ff = 0.f;
|
||||
coeffs->delay_fb = 0.f;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->hash = bw_hash_sdbm("bw_comb_coeffs");
|
||||
coeffs->state = bw_comb_coeffs_state_init;
|
||||
coeffs->reset_id = coeffs->hash + 1;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_sample_rate(bw_comb_coeffs *BW_RESTRICT coeffs, float sample_rate) {
|
||||
static inline void bw_comb_set_sample_rate(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float sample_rate) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
|
||||
|
||||
bw_delay_set_sample_rate(&coeffs->delay_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->blend_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->ff_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->fb_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->blend_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->ff_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&coeffs->fb_coeffs, sample_rate);
|
||||
bw_one_pole_set_sample_rate(&coeffs->smooth_coeffs, sample_rate);
|
||||
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
|
||||
coeffs->fs = sample_rate;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_comb_coeffs_state_set_sample_rate;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_comb_coeffs_state_set_sample_rate);
|
||||
}
|
||||
|
||||
static inline size_t bw_comb_mem_req(const bw_comb_coeffs *BW_RESTRICT coeffs) {
|
||||
static inline size_t bw_comb_mem_req(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_set_sample_rate);
|
||||
|
||||
return bw_delay_mem_req(&coeffs->delay_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_comb_mem_set(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, void *BW_RESTRICT mem) {
|
||||
static inline void bw_comb_mem_set(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
void * BW_RESTRICT mem) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_set_sample_rate);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(mem != NULL);
|
||||
|
||||
bw_delay_mem_set(&coeffs->delay_coeffs, &state->delay_state, mem);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_comb_state");
|
||||
state->state = bw_comb_state_state_mem_set;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_set_sample_rate);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state == bw_comb_state_state_mem_set);
|
||||
}
|
||||
|
||||
static inline void bw_comb_do_update_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs, char force) {
|
||||
static inline void bw_comb_do_update_coeffs(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
char force) {
|
||||
float delay_ff_cur = bw_one_pole_get_y_z1(&coeffs->smooth_delay_ff_state);
|
||||
float delay_fb_cur = bw_one_pole_get_y_z1(&coeffs->smooth_delay_fb_state);
|
||||
if (force || delay_ff_cur != coeffs->delay_ff) {
|
||||
@ -323,7 +516,12 @@ static inline void bw_comb_do_update_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs,
|
||||
}
|
||||
}
|
||||
|
||||
static inline void bw_comb_reset_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs) {
|
||||
static inline void bw_comb_reset_coeffs(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_set_sample_rate);
|
||||
|
||||
bw_delay_reset_coeffs(&coeffs->delay_coeffs);
|
||||
bw_gain_reset_coeffs(&coeffs->blend_coeffs);
|
||||
bw_gain_reset_coeffs(&coeffs->ff_coeffs);
|
||||
@ -331,68 +529,323 @@ static inline void bw_comb_reset_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs) {
|
||||
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_delay_ff_state, coeffs->delay_ff);
|
||||
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_delay_fb_state, coeffs->delay_fb);
|
||||
bw_comb_do_update_coeffs(coeffs, 1);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_comb_coeffs_state_reset_coeffs;
|
||||
coeffs->reset_id++;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_comb_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_comb_reset_state(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, float x_0) {
|
||||
bw_delay_reset_state(&coeffs->delay_coeffs, &state->delay_state, x_0);
|
||||
static inline float bw_comb_reset_state(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_mem_set);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
BW_ASSERT(bw_gain_get_gain_cur(&coeffs->fb_coeffs) == -1.f || bw_gain_get_gain_cur(&coeffs->fb_coeffs) == 1.f ? x_0 == 0.f : 1);
|
||||
|
||||
const float fb = bw_gain_get_gain_cur(&coeffs->fb_coeffs);
|
||||
float y;
|
||||
if (fb == -1.f || fb == 1.f) {
|
||||
bw_delay_reset_state(&coeffs->delay_coeffs, &state->delay_state, 0.f);
|
||||
y = 0.f;
|
||||
} else {
|
||||
const float v = x_0 / (1.f - fb);
|
||||
bw_delay_reset_state(&coeffs->delay_coeffs, &state->delay_state, v);
|
||||
y = (bw_gain_get_gain_cur(&coeffs->ff_coeffs) + bw_gain_get_gain_cur(&coeffs->blend_coeffs)) * v;
|
||||
}
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->state = bw_comb_state_state_reset_state;
|
||||
state->coeffs_reset_id = coeffs->reset_id;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_comb_update_coeffs_ctrl(bw_comb_coeffs *BW_RESTRICT coeffs) {
|
||||
static inline void bw_comb_reset_state_multi(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_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_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_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_comb_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_comb_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_comb_update_coeffs_ctrl(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
|
||||
bw_gain_update_coeffs_ctrl(&coeffs->blend_coeffs);
|
||||
bw_gain_update_coeffs_ctrl(&coeffs->ff_coeffs);
|
||||
bw_gain_update_coeffs_ctrl(&coeffs->fb_coeffs);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_comb_update_coeffs_audio(bw_comb_coeffs *BW_RESTRICT coeffs) {
|
||||
static inline void bw_comb_update_coeffs_audio(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
|
||||
bw_gain_update_coeffs_audio(&coeffs->blend_coeffs);
|
||||
bw_gain_update_coeffs_audio(&coeffs->ff_coeffs);
|
||||
bw_gain_update_coeffs_audio(&coeffs->fb_coeffs);
|
||||
bw_comb_do_update_coeffs(coeffs, 0);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline float bw_comb_process1(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, float x) {
|
||||
static inline float bw_comb_process1(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
float x) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
|
||||
const float fb = bw_delay_read(&coeffs->delay_coeffs, &state->delay_state, coeffs->dfbi, coeffs->dfbf);
|
||||
const float v = x + bw_gain_process1(&coeffs->fb_coeffs, fb);
|
||||
bw_delay_write(&coeffs->delay_coeffs, &state->delay_state, v);
|
||||
const float ff = bw_delay_read(&coeffs->delay_coeffs, &state->delay_state, coeffs->dffi, coeffs->dfff);
|
||||
return bw_gain_process1(&coeffs->blend_coeffs, v) + bw_gain_process1(&coeffs->ff_coeffs, ff);
|
||||
const float y = bw_gain_process1(&coeffs->blend_coeffs, v) + bw_gain_process1(&coeffs->ff_coeffs, ff);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
|
||||
static inline void bw_comb_process(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_state * BW_RESTRICT state,
|
||||
const float * x,
|
||||
float * y,
|
||||
size_t n_samples) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_reset_state);
|
||||
BW_ASSERT(x != NULL);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
|
||||
BW_ASSERT(y != NULL);
|
||||
|
||||
bw_comb_update_coeffs_ctrl(coeffs);
|
||||
for (size_t i = 0; i < n_samples; i++) {
|
||||
bw_comb_update_coeffs_audio(coeffs);
|
||||
y[i] = bw_comb_process1(coeffs, state, x[i]);
|
||||
}
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_comb_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_comb_state_state_reset_state);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
|
||||
}
|
||||
|
||||
static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_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_comb_process_multi(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
bw_comb_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_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(x != NULL);
|
||||
BW_ASSERT(y != NULL);
|
||||
|
||||
bw_comb_update_coeffs_ctrl(coeffs);
|
||||
for (size_t i = 0; i < n_samples; i++) {
|
||||
bw_comb_update_coeffs_audio(coeffs);
|
||||
for (size_t j = 0; j < n_channels; j++)
|
||||
y[j][i] = bw_comb_process1(coeffs, state[j], x[j][i]);
|
||||
}
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_delay_ff(bw_comb_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comb_set_delay_ff(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
|
||||
coeffs->delay_ff = value;
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_delay_fb(bw_comb_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comb_set_delay_fb(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
|
||||
coeffs->delay_fb = value;
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_coeff_blend(bw_comb_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comb_set_coeff_blend(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
|
||||
bw_gain_set_gain_lin(&coeffs->blend_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_coeff_ff(bw_comb_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comb_set_coeff_ff(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
|
||||
bw_gain_set_gain_lin(&coeffs->ff_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comb_set_coeff_fb(
|
||||
bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
BW_ASSERT(value >= -1.f && value <= 1.f);
|
||||
|
||||
bw_gain_set_gain_lin(&coeffs->fb_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_comb_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_comb_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline char bw_comb_coeffs_is_valid(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs->hash != bw_hash_sdbm("bw_comb_coeffs"))
|
||||
return 0;
|
||||
if (coeffs->state < bw_comb_coeffs_state_init || coeffs->state > bw_comb_coeffs_state_reset_coeffs)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (!bw_is_finite(coeffs->delay_ff))
|
||||
return 0;
|
||||
if (!bw_is_finite(coeffs->delay_fb))
|
||||
return 0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs->state >= bw_comb_coeffs_state_set_sample_rate && (!bw_is_finite(coeffs->fs) || coeffs->fs <= 0.f))
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (!bw_delay_coeffs_is_valid(&coeffs->delay_coeffs)
|
||||
|| !bw_one_pole_coeffs_is_valid(&coeffs->smooth_coeffs))
|
||||
return 0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs->state >= bw_comb_coeffs_state_reset_coeffs) {
|
||||
const size_t len = bw_delay_get_length(&coeffs->delay_coeffs);
|
||||
|
||||
if (!bw_is_finite(coeffs->dfff) || coeffs->dfff < 0.f || coeffs->dfff >= 1.f)
|
||||
return 0;
|
||||
if (coeffs->dffi + coeffs->dfff > len)
|
||||
return 0;
|
||||
|
||||
if (!bw_is_finite(coeffs->dfbf) || coeffs->dfbf < 0.f || coeffs->dfbf >= 1.f)
|
||||
return 0;
|
||||
if (coeffs->dfbi + coeffs->dfbf > len)
|
||||
return 0;
|
||||
|
||||
if (!bw_one_pole_state_is_valid(&coeffs->smooth_coeffs, &coeffs->smooth_delay_ff_state)
|
||||
|| !bw_one_pole_state_is_valid(&coeffs->smooth_coeffs, &coeffs->smooth_delay_fb_state))
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return bw_gain_coeffs_is_valid(&coeffs->blend_coeffs)
|
||||
&& bw_gain_coeffs_is_valid(&coeffs->ff_coeffs)
|
||||
&& bw_gain_coeffs_is_valid(&coeffs->fb_coeffs);
|
||||
}
|
||||
|
||||
static inline char bw_comb_state_is_valid(
|
||||
const bw_comb_coeffs * BW_RESTRICT coeffs,
|
||||
const bw_comb_state * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (state->hash != bw_hash_sdbm("bw_comb_state"))
|
||||
return 0;
|
||||
if (state->state < bw_comb_state_state_mem_set || state->state > bw_comb_state_state_reset_state)
|
||||
return 0;
|
||||
|
||||
if (state->state >= bw_comb_state_state_reset_state && coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return bw_delay_state_is_valid(coeffs ? &coeffs->delay_coeffs : NULL, &state->delay_state);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -410,27 +863,54 @@ namespace Brickworks {
|
||||
template<size_t N_CHANNELS>
|
||||
class Comb {
|
||||
public:
|
||||
Comb(float maxDelay = 1.f);
|
||||
Comb(
|
||||
float maxDelay = 1.f);
|
||||
|
||||
~Comb();
|
||||
|
||||
void setSampleRate(float sampleRate);
|
||||
void reset(float x_0 = 0.f);
|
||||
void reset(const float *BW_RESTRICT x_0);
|
||||
void reset(const std::array<float, N_CHANNELS> x_0);
|
||||
void process(
|
||||
const float * const *x,
|
||||
float * const *y,
|
||||
size_t nSamples);
|
||||
void process(
|
||||
const std::array<const float *, N_CHANNELS> x,
|
||||
const std::array<float *, N_CHANNELS> y,
|
||||
size_t nSamples);
|
||||
void setSampleRate(
|
||||
float sampleRate);
|
||||
|
||||
void setDelayFF(float value);
|
||||
void setDelayFB(float value);
|
||||
void setCoeffBlend(float value);
|
||||
void setCoeffFF(float value);
|
||||
void setCoeffFB(float value);
|
||||
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,
|
||||
size_t nSamples);
|
||||
|
||||
void process(
|
||||
std::array<const float *, N_CHANNELS> x,
|
||||
std::array<float *, N_CHANNELS> y,
|
||||
size_t nSamples);
|
||||
|
||||
void setDelayFF(
|
||||
float value);
|
||||
|
||||
void setDelayFB(
|
||||
float value);
|
||||
|
||||
void setCoeffBlend(
|
||||
float value);
|
||||
|
||||
void setCoeffFF(
|
||||
float value);
|
||||
|
||||
void setCoeffFB(
|
||||
float value);
|
||||
/*! <<<...
|
||||
* }
|
||||
* ```
|
||||
@ -442,14 +922,15 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_comb_coeffs coeffs;
|
||||
bw_comb_state states[N_CHANNELS];
|
||||
bw_comb_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
void *BW_RESTRICT mem;
|
||||
bw_comb_coeffs coeffs;
|
||||
bw_comb_state states[N_CHANNELS];
|
||||
bw_comb_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
void * BW_RESTRICT mem;
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline Comb<N_CHANNELS>::Comb(float maxDelay) {
|
||||
inline Comb<N_CHANNELS>::Comb(
|
||||
float maxDelay) {
|
||||
bw_comb_init(&coeffs, maxDelay);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
statesP[i] = states + i;
|
||||
@ -463,7 +944,8 @@ inline Comb<N_CHANNELS>::~Comb() {
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setSampleRate(float sampleRate) {
|
||||
inline void Comb<N_CHANNELS>::setSampleRate(
|
||||
float sampleRate) {
|
||||
bw_comb_set_sample_rate(&coeffs, sampleRate);
|
||||
size_t req = bw_comb_mem_req(&coeffs);
|
||||
if (mem != nullptr)
|
||||
@ -475,62 +957,83 @@ inline void Comb<N_CHANNELS>::setSampleRate(float sampleRate) {
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::reset(float x_0) {
|
||||
inline void Comb<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
float * BW_RESTRICT y0) {
|
||||
bw_comb_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_comb_reset_state(&coeffs, states + i, x_0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_comb_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_comb_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::reset(const float *BW_RESTRICT x_0) {
|
||||
bw_comb_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_comb_reset_state(&coeffs, states + i, x_0[i]);
|
||||
inline void Comb<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 Comb<N_CHANNELS>::reset(const std::array<float, N_CHANNELS> x_0) {
|
||||
reset(x_0.data());
|
||||
inline void Comb<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_comb_reset_coeffs(&coeffs);
|
||||
bw_comb_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<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 Comb<N_CHANNELS>::process(
|
||||
const float * const *x,
|
||||
float * const *y,
|
||||
size_t nSamples) {
|
||||
const float * const * x,
|
||||
float * const * y,
|
||||
size_t nSamples) {
|
||||
bw_comb_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::process(
|
||||
const std::array<const float *, N_CHANNELS> x,
|
||||
const std::array<float *, N_CHANNELS> y,
|
||||
size_t nSamples) {
|
||||
std::array<const float *, N_CHANNELS> x,
|
||||
std::array<float *, N_CHANNELS> y,
|
||||
size_t nSamples) {
|
||||
process(x.data(), y.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setDelayFF(float value) {
|
||||
inline void Comb<N_CHANNELS>::setDelayFF(
|
||||
float value) {
|
||||
bw_comb_set_delay_ff(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setDelayFB(float value) {
|
||||
inline void Comb<N_CHANNELS>::setDelayFB(
|
||||
float value) {
|
||||
bw_comb_set_delay_fb(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setCoeffBlend(float value) {
|
||||
inline void Comb<N_CHANNELS>::setCoeffBlend(
|
||||
float value) {
|
||||
bw_comb_set_coeff_blend(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setCoeffFF(float value) {
|
||||
inline void Comb<N_CHANNELS>::setCoeffFF(
|
||||
float value) {
|
||||
bw_comb_set_coeff_ff(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Comb<N_CHANNELS>::setCoeffFB(float value) {
|
||||
inline void Comb<N_CHANNELS>::setCoeffFB(
|
||||
float value) {
|
||||
bw_comb_set_coeff_fb(&coeffs, value);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,8 @@ static inline void bw_delay_mem_set(
|
||||
bw_delay_state * BW_RESTRICT state,
|
||||
void * BW_RESTRICT mem);
|
||||
/*! <<<```
|
||||
* Associates the contiguous memory block `mem` to the given `state`.
|
||||
* Associates the contiguous memory block `mem` to the given `state` using
|
||||
* `coeffs`.
|
||||
*
|
||||
* #### bw_delay_reset_coeffs()
|
||||
* ```>>> */
|
||||
@ -321,6 +322,14 @@ enum bw_delay_coeffs_state {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
enum bw_delay_state_state {
|
||||
bw_delay_state_state_invalid,
|
||||
bw_delay_state_state_mem_set,
|
||||
bw_delay_state_state_reset_state
|
||||
};
|
||||
#endif
|
||||
|
||||
struct bw_delay_coeffs {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
@ -343,13 +352,14 @@ struct bw_delay_coeffs {
|
||||
|
||||
struct bw_delay_state {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
uint32_t coeffs_reset_id;
|
||||
uint32_t hash;
|
||||
enum bw_delay_state_state state;
|
||||
uint32_t coeffs_reset_id;
|
||||
#endif
|
||||
|
||||
// States
|
||||
float * BW_RESTRICT buf;
|
||||
size_t idx;
|
||||
float * BW_RESTRICT buf;
|
||||
size_t idx;
|
||||
};
|
||||
|
||||
static inline void bw_delay_init(
|
||||
@ -410,6 +420,15 @@ static inline void bw_delay_mem_set(
|
||||
|
||||
(void)coeffs;
|
||||
state->buf = (float *)mem;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_delay_state");
|
||||
state->state = bw_delay_state_state_mem_set;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_set_sample_rate);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state == bw_delay_state_state_mem_set);
|
||||
}
|
||||
|
||||
static inline void bw_delay_do_update_coeffs_ctrl(bw_delay_coeffs *BW_RESTRICT coeffs) {
|
||||
@ -446,6 +465,8 @@ static inline float bw_delay_reset_state(
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_mem_set);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
bw_buf_fill(x_0, state->buf, coeffs->len);
|
||||
@ -453,12 +474,13 @@ static inline float bw_delay_reset_state(
|
||||
const float y = x_0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_delay_state");
|
||||
state->state = bw_delay_state_state_reset_state;
|
||||
state->coeffs_reset_id = coeffs->reset_id;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
@ -498,6 +520,7 @@ static float bw_delay_read(
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(df));
|
||||
BW_ASSERT(df >= 0.f && df < 1.f);
|
||||
BW_ASSERT(di + df <= coeffs->len);
|
||||
@ -509,6 +532,7 @@ static float bw_delay_read(
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
@ -523,6 +547,7 @@ static void bw_delay_write(
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
|
||||
state->idx++;
|
||||
@ -532,6 +557,7 @@ static void bw_delay_write(
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
}
|
||||
|
||||
static inline void bw_delay_update_coeffs_ctrl(
|
||||
@ -564,6 +590,7 @@ static inline float bw_delay_process1(
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
|
||||
bw_delay_write(coeffs, state, x);
|
||||
@ -572,6 +599,7 @@ static inline float bw_delay_process1(
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
@ -588,6 +616,7 @@ static inline void bw_delay_process(
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT(x != NULL);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
|
||||
BW_ASSERT(y != NULL);
|
||||
@ -599,6 +628,7 @@ static inline void bw_delay_process(
|
||||
BW_ASSERT_DEEP(bw_delay_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_delay_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_delay_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(state->state >= bw_delay_state_state_reset_state);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
|
||||
}
|
||||
|
||||
@ -694,8 +724,7 @@ static inline char bw_delay_state_is_valid(
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (state->hash != bw_hash_sdbm("bw_delay_state"))
|
||||
return 0;
|
||||
|
||||
if (coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
|
||||
if (state->state < bw_delay_state_state_mem_set || state->state > bw_delay_state_state_reset_state)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@ -705,8 +734,13 @@ static inline char bw_delay_state_is_valid(
|
||||
return 0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs != NULL && coeffs->state >= bw_delay_coeffs_state_set_sample_rate && state->idx >= coeffs->len)
|
||||
return 0;
|
||||
if (state->state >= bw_delay_state_state_reset_state && coeffs != NULL) {
|
||||
if (coeffs->reset_id != state->coeffs_reset_id)
|
||||
return 0;
|
||||
|
||||
if (state->idx >= coeffs->len)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user