finalize all 1st order filter modules and examples + bw_*_reset_state_multi() and init values + bw_gain get gain improv + use bw_gain_process1() in bw_dry_wet
This commit is contained in:
parent
2d653f471f
commit
72ba53385c
1
TODO
1
TODO
@ -41,6 +41,7 @@ post 1.0.0
|
||||
----------
|
||||
|
||||
code:
|
||||
* get() parameters?
|
||||
* blep etc in a module?
|
||||
* optimize triangle generation for constant pulse width
|
||||
* compute bit depth reduction only when input changes? (state, option?)
|
||||
|
@ -4,3 +4,6 @@ NAME := bw_example_fx_ap1
|
||||
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_ap1.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_ap1
|
||||
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_ap1.cpp
|
||||
|
||||
include ${ROOT_DIR}/../../common/vst3/vst3.mk
|
||||
|
||||
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
|
||||
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP
|
||||
|
503
include/bw_ap1.h
503
include/bw_ap1.h
@ -30,6 +30,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_ap1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_ap1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li>Added overladed C++ <code>reset()</code> functions taking arrays
|
||||
* as arguments.</li>
|
||||
* <li><code>bw_ap1_process()</code> and
|
||||
@ -41,6 +45,8 @@
|
||||
* <li>Added overladed 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>:
|
||||
@ -96,56 +102,73 @@ typedef struct bw_ap1_state bw_ap1_state;
|
||||
* #### bw_ap1_init()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_init(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Initializes input parameter values in `coeffs`.
|
||||
*
|
||||
* #### bw_ap1_set_sample_rate()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_set_sample_rate(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
float sample_rate);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float sample_rate);
|
||||
/*! <<<```
|
||||
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
||||
*
|
||||
* #### bw_ap1_reset_coeffs()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_reset_coeffs(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Resets coefficients in `coeffs` to assume their target values.
|
||||
*
|
||||
* #### bw_ap1_reset_state()
|
||||
* ```>>> */
|
||||
static inline float bw_ap1_reset_state(
|
||||
const bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
float x_0);
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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`. Returns the corresponding
|
||||
* quiescent/initial output value.
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_ap1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_reset_state_multi(
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_ap1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_update_coeffs_ctrl(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers control-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_ap1_update_coeffs_audio()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_update_coeffs_audio(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers audio-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_ap1_process1()
|
||||
* ```>>> */
|
||||
static inline float bw_ap1_process1(
|
||||
const bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
float x);
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_state * BW_RESTRICT state,
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Processes one input sample `x` using `coeffs`, while using and updating
|
||||
* `state`. Returns the corresponding output sample.
|
||||
@ -153,11 +176,11 @@ static inline float bw_ap1_process1(
|
||||
* #### bw_ap1_process()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_process(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
const float * x,
|
||||
float * y,
|
||||
size_t n_samples);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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
|
||||
@ -166,12 +189,12 @@ static inline void bw_ap1_process(
|
||||
* #### bw_ap1_process_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_process_multi(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT const *BW_RESTRICT state,
|
||||
const float * const * x,
|
||||
float * const * y,
|
||||
size_t n_channels,
|
||||
size_t n_samples);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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
|
||||
@ -181,12 +204,68 @@ static inline void bw_ap1_process_multi(
|
||||
* #### bw_ap1_set_cutoff()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_set_cutoff(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
float value);
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the cutoff frequency `value` (Hz) in `coeffs`.
|
||||
*
|
||||
* Valid range: [`1e-6f`, `1e6f`].
|
||||
*
|
||||
* Default value: `1e3f`.
|
||||
*
|
||||
* #### bw_ap1_set_prewarp_at_cutoff()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_set_prewarp_at_cutoff(
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
char value);
|
||||
/*! <<<```
|
||||
* Sets whether bilinear transform prewarping frequency should match the
|
||||
* cutoff frequency (non-`0`) or not (`0`).
|
||||
*
|
||||
* Default value: non-`0` (on).
|
||||
*
|
||||
* #### bw_ap1_set_prewarp_freq()
|
||||
* ```>>> */
|
||||
static inline void bw_ap1_set_prewarp_freq(
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float value);
|
||||
/*! <<<```
|
||||
* Sets the prewarping frequency `value` (Hz) in `coeffs`.
|
||||
*
|
||||
* Only used when the prewarp\_at\_cutoff parameter is off and however
|
||||
* internally limited to avoid instability.
|
||||
*
|
||||
* Valid range: [`1e-6f`, `1e6f`].
|
||||
*
|
||||
* Default value: `1e3f`.
|
||||
*
|
||||
* #### bw_ap1_coeffs_is_valid()
|
||||
* ```>>> */
|
||||
static inline char bw_ap1_coeffs_is_valid(
|
||||
const bw_ap1_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_ap1_coeffs`.
|
||||
*
|
||||
* #### bw_ap1_state_is_valid()
|
||||
* ```>>> */
|
||||
static inline char bw_ap1_state_is_valid(
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
const bw_ap1_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_ap1_state`.
|
||||
* }}} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -204,89 +283,303 @@ static inline void bw_ap1_set_cutoff(
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
enum bw_ap1_coeffs_state {
|
||||
bw_ap1_coeffs_state_invalid,
|
||||
bw_ap1_coeffs_state_init,
|
||||
bw_ap1_coeffs_state_set_sample_rate,
|
||||
bw_ap1_coeffs_state_reset_coeffs
|
||||
};
|
||||
#endif
|
||||
|
||||
struct bw_ap1_coeffs {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
enum bw_ap1_coeffs_state state;
|
||||
uint32_t reset_id;
|
||||
#endif
|
||||
|
||||
// Sub-components
|
||||
bw_lp1_coeffs lp1_coeffs;
|
||||
};
|
||||
|
||||
struct bw_ap1_state {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
uint32_t coeffs_reset_id;
|
||||
#endif
|
||||
|
||||
bw_lp1_state lp1_state;
|
||||
};
|
||||
|
||||
static inline void bw_ap1_init(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
|
||||
bw_lp1_init(&coeffs->lp1_coeffs);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->hash = bw_hash_sdbm("bw_ap1_coeffs");
|
||||
coeffs->state = bw_ap1_coeffs_state_init;
|
||||
coeffs->reset_id = coeffs->hash + 1;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_ap1_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_set_sample_rate(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
float sample_rate) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float sample_rate) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
|
||||
|
||||
bw_lp1_set_sample_rate(&coeffs->lp1_coeffs, sample_rate);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_ap1_coeffs_state_set_sample_rate;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_ap1_coeffs_state_set_sample_rate);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_reset_coeffs(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_set_sample_rate);
|
||||
|
||||
bw_lp1_reset_coeffs(&coeffs->lp1_coeffs);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_ap1_coeffs_state_reset_coeffs;
|
||||
coeffs->reset_id++;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_ap1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline float bw_ap1_reset_state(
|
||||
const bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
float x_0) {
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
const float lp = bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0);
|
||||
return x_0 - lp - lp;
|
||||
const float y = x_0 - lp - lp;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_ap1_state");
|
||||
state->coeffs_reset_id = coeffs->reset_id;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_ap1_state_is_valid(coeffs, state));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_ap1_reset_state_multi(
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_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_ap1_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_ap1_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_update_coeffs_ctrl(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
|
||||
bw_lp1_update_coeffs_ctrl(&coeffs->lp1_coeffs);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_update_coeffs_audio(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
|
||||
bw_lp1_update_coeffs_audio(&coeffs->lp1_coeffs);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline float bw_ap1_process1(
|
||||
const bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
float x) {
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_state * BW_RESTRICT state,
|
||||
float x) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
|
||||
const float lp = bw_lp1_process1(&coeffs->lp1_coeffs, &state->lp1_state, x);
|
||||
return x - lp - lp;
|
||||
const float y = x - lp - lp;
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_ap1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_ap1_process(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT state,
|
||||
const float * x,
|
||||
float * y,
|
||||
size_t n_samples) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_state * BW_RESTRICT state,
|
||||
const float * x,
|
||||
float * y,
|
||||
size_t n_samples) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(x != NULL);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
|
||||
BW_ASSERT(y != NULL);
|
||||
|
||||
bw_ap1_update_coeffs_ctrl(coeffs);
|
||||
for (size_t i = 0; i < n_samples; i++) {
|
||||
bw_ap1_update_coeffs_audio(coeffs);
|
||||
y[i] = bw_ap1_process1(coeffs, state, x[i]);
|
||||
}
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_ap1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
|
||||
}
|
||||
|
||||
|
||||
static inline void bw_ap1_process_multi(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
bw_ap1_state *BW_RESTRICT const *BW_RESTRICT state,
|
||||
const float * const * x,
|
||||
float * const * y,
|
||||
size_t n_channels,
|
||||
size_t n_samples) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ap1_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_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(x != NULL);
|
||||
BW_ASSERT(y != NULL);
|
||||
|
||||
bw_ap1_update_coeffs_ctrl(coeffs);
|
||||
for (size_t i = 0; i < n_samples; i++) {
|
||||
bw_ap1_update_coeffs_audio(coeffs);
|
||||
for (size_t j = 0; j < n_channels; j++)
|
||||
y[j][i] = bw_ap1_process1(coeffs, state[j], x[j][i]);
|
||||
}
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_set_cutoff(
|
||||
bw_ap1_coeffs *BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
BW_ASSERT(value >= 1e-6f && value <= 1e6f);
|
||||
|
||||
bw_lp1_set_cutoff(&coeffs->lp1_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_set_prewarp_at_cutoff(
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
char value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
|
||||
bw_lp1_set_prewarp_at_cutoff(&coeffs->lp1_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_ap1_set_prewarp_freq(
|
||||
bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
BW_ASSERT(value >= 1e-6f && value <= 1e6f);
|
||||
|
||||
bw_lp1_set_prewarp_freq(&coeffs->lp1_coeffs, value);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ap1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ap1_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline char bw_ap1_coeffs_is_valid(
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs->hash != bw_hash_sdbm("bw_ap1_coeffs"))
|
||||
return 0;
|
||||
if (coeffs->state < bw_ap1_coeffs_state_init || coeffs->state > bw_ap1_coeffs_state_reset_coeffs)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return bw_lp1_coeffs_is_valid(&coeffs->lp1_coeffs);
|
||||
}
|
||||
|
||||
static inline char bw_ap1_state_is_valid(
|
||||
const bw_ap1_coeffs * BW_RESTRICT coeffs,
|
||||
const bw_ap1_state * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (state->hash != bw_hash_sdbm("bw_ap1_state"))
|
||||
return 0;
|
||||
|
||||
if (coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
(void)coeffs;
|
||||
|
||||
return bw_lp1_state_is_valid(&coeffs->lp1_coeffs, &state->lp1_state);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -308,42 +601,55 @@ public:
|
||||
|
||||
void setSampleRate(
|
||||
float sampleRate);
|
||||
|
||||
|
||||
void reset(
|
||||
float x_0 = 0.f,
|
||||
float *BW_RESTRICT y_0 = nullptr);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
const float * x_0,
|
||||
float * y_0);
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const std::array<float, N_CHANNELS> x_0
|
||||
const std::array<float, N_CHANNELS> y_0);
|
||||
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
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);
|
||||
std::array<const float *, N_CHANNELS> x,
|
||||
std::array<float *, N_CHANNELS> y,
|
||||
size_t nSamples);
|
||||
|
||||
void setCutoff(
|
||||
float value);
|
||||
|
||||
void setPrewarpAtCutoff(
|
||||
bool value);
|
||||
|
||||
void setPrewarpFreq(
|
||||
float value);
|
||||
/*! <<<...
|
||||
* }
|
||||
* ```
|
||||
* }}} */
|
||||
|
||||
|
||||
/*** Implementation ***/
|
||||
|
||||
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_ap1_coeffs coeffs;
|
||||
bw_ap1_state states[N_CHANNELS];
|
||||
bw_ap1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_ap1_coeffs coeffs;
|
||||
bw_ap1_state states[N_CHANNELS];
|
||||
bw_ap1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -355,54 +661,79 @@ inline AP1<N_CHANNELS>::AP1() {
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::setSampleRate(
|
||||
float sampleRate) {
|
||||
float sampleRate) {
|
||||
bw_ap1_set_sample_rate(&coeffs, sampleRate);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::reset(
|
||||
float x_0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_ap1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_ap1_reset_state(&coeffs, states + i, x_0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_ap1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_ap1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::reset(
|
||||
const float *BW_RESTRICT x_0) {
|
||||
bw_ap1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_ap1_reset_state(&coeffs, states + i, x_0[i]);
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::reset(
|
||||
const std::array<float, N_CHANNELS> x_0) {
|
||||
reset(x_0.data());
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_ap1_reset_coeffs(&coeffs);
|
||||
bw_ap1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::process(
|
||||
const float * const * x,
|
||||
float * const * y,
|
||||
size_t nSamples) {
|
||||
const float * const * x,
|
||||
float * const * y,
|
||||
size_t nSamples) {
|
||||
bw_ap1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<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 AP1<N_CHANNELS>::setCutoff(
|
||||
float value) {
|
||||
float value) {
|
||||
bw_ap1_set_cutoff(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::setPrewarpAtCutoff(
|
||||
bool value) {
|
||||
bw_ap1_set_prewarp_at_cutoff(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void AP1<N_CHANNELS>::setPrewarpFreq(
|
||||
float value) {
|
||||
bw_ap1_set_prewarp_freq(&coeffs, value);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -183,7 +183,7 @@ static inline void bw_dry_wet_update_coeffs_audio(bw_dry_wet_coeffs *BW_RESTRICT
|
||||
}
|
||||
|
||||
static inline float bw_dry_wet_process1(const bw_dry_wet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet) {
|
||||
return bw_gain_get_gain(&coeffs->gain_coeffs) * (x_wet - x_dry) + x_dry;
|
||||
return bw_gain_process1(&coeffs->gain_coeffs, x_wet - x_dry) + x_dry;
|
||||
}
|
||||
|
||||
static inline void bw_dry_wet_process(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples) {
|
||||
|
@ -29,6 +29,9 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_gain_get_gain_lin()</code>.</li>
|
||||
* <li>Renamed <code>bw_gain_get_gain()</code> as
|
||||
* <code>bw_gain_get_gain_cur()</code>.</li>
|
||||
* <li>Simplified implementation to use less memory.</li>
|
||||
* <li><code>bw_gain_process()</code> and
|
||||
* <code>bw_gain_process_multi()</code> now use <code>size_t</code>
|
||||
@ -39,7 +42,7 @@
|
||||
* <li>Added overladed C++ <code>process()</code> function taking
|
||||
* C-style arrays as arguments.</li>
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -199,9 +202,16 @@ static inline void bw_gain_set_smooth_tau(
|
||||
*
|
||||
* Default value: `0.05f`.
|
||||
*
|
||||
* #### bw_gain_get_gain()
|
||||
* #### bw_gain_get_gain_lin()
|
||||
* ```>>> */
|
||||
static inline float bw_gain_get_gain(
|
||||
static inline float bw_gain_get_gain_lin(
|
||||
const bw_gain_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Returns the current gain parameter value (linear gain) in `coeffs`.
|
||||
*
|
||||
* #### bw_gain_get_gain_cur()
|
||||
* ```>>> */
|
||||
static inline float bw_gain_get_gain_cur(
|
||||
const bw_gain_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Returns the actual current gain coefficient (linear gain) in `coeffs`.
|
||||
@ -439,7 +449,15 @@ static inline void bw_gain_set_smooth_tau(
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_gain_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline float bw_gain_get_gain(
|
||||
static inline float bw_gain_get_gain_lin(
|
||||
const bw_gain_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_gain_coeffs_is_valid(coeffs));
|
||||
|
||||
return coeffs->gain;
|
||||
}
|
||||
|
||||
static inline float bw_gain_get_gain_cur(
|
||||
const bw_gain_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != NULL);
|
||||
BW_ASSERT_DEEP(bw_gain_coeffs_is_valid(coeffs));
|
||||
@ -513,7 +531,9 @@ public:
|
||||
void setSmoothTau(
|
||||
float value);
|
||||
|
||||
float getGain();
|
||||
float getGainLin();
|
||||
|
||||
float getGainCur();
|
||||
/*! <<<...
|
||||
* }
|
||||
* ```
|
||||
@ -579,8 +599,13 @@ inline void Gain<N_CHANNELS>::setSmoothTau(
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline float Gain<N_CHANNELS>::getGain() {
|
||||
return bw_gain_get_gain(&coeffs);
|
||||
inline float Gain<N_CHANNELS>::getGainLin() {
|
||||
return bw_gain_get_gain_lin(&coeffs);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline float Gain<N_CHANNELS>::getGainCur() {
|
||||
return bw_gain_get_gain_cur(&coeffs);
|
||||
}
|
||||
|
||||
}
|
||||
|
107
include/bw_hp1.h
107
include/bw_hp1.h
@ -30,6 +30,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_hp1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_hp1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li>Added prewarp_at_cutoff and prewarp_freq parameters.</li>
|
||||
* <li><code>bw_hp1_process()</code> and
|
||||
* <code>bw_hp1_process_multi()</code> now use <code>size_t</code>
|
||||
@ -40,7 +44,7 @@
|
||||
* <li>Added overladed C++ <code>process()</code> function taking
|
||||
* C-style arrays as arguments.</li>
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -116,7 +120,7 @@ static inline void bw_hp1_reset_coeffs(
|
||||
*
|
||||
* #### bw_hp1_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_hp1_reset_state(
|
||||
static inline float bw_hp1_reset_state(
|
||||
const bw_hp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hp1_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -124,6 +128,24 @@ static inline void bw_hp1_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_hp1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_hp1_reset_state_multi(
|
||||
const bw_hp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hp1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_hp1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_hp1_update_coeffs_ctrl(
|
||||
@ -335,7 +357,7 @@ static inline void bw_hp1_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_hp1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_hp1_reset_state(
|
||||
static inline float bw_hp1_reset_state(
|
||||
const bw_hp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hp1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -354,6 +376,31 @@ static inline void bw_hp1_reset_state(
|
||||
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_hp1_state_is_valid(coeffs, state));
|
||||
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
static inline void bw_hp1_reset_state_multi(
|
||||
const bw_hp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hp1_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_hp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(x_0 != NULL);
|
||||
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_hp1_reset_state(coeffs, state[i], x_0[i]);
|
||||
if (y_0 != NULL)
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
y_0[i] = 0.f;
|
||||
|
||||
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_hp1_update_coeffs_ctrl(
|
||||
@ -550,7 +597,20 @@ public:
|
||||
float sampleRate);
|
||||
|
||||
void reset(
|
||||
float x0 = 0.f);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -581,9 +641,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_hp1_coeffs coeffs;
|
||||
bw_hp1_state states[N_CHANNELS];
|
||||
bw_hp1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_hp1_coeffs coeffs;
|
||||
bw_hp1_state states[N_CHANNELS];
|
||||
bw_hp1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -601,10 +661,37 @@ inline void HP1<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HP1<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_hp1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_hp1_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_hp1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_hp1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HP1<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HP1<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_hp1_reset_coeffs(&coeffs);
|
||||
bw_hp1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HP1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
111
include/bw_hs1.h
111
include/bw_hs1.h
@ -29,6 +29,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_hs1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_hs1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li>Added prewarp_at_cutoff and prewarp_freq parameters.</li>
|
||||
* <li><code>bw_hs1_process()</code> and
|
||||
* <code>bw_hs1_process_multi()</code> now use <code>size_t</code>
|
||||
@ -43,7 +47,7 @@
|
||||
* <code>bw_hs1_init()</code>.</li>
|
||||
* <li>Fixed documentation to indicate correct default parameter
|
||||
* values.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -119,7 +123,7 @@ static inline void bw_hs1_reset_coeffs(
|
||||
*
|
||||
* #### bw_hs1_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_hs1_reset_state(
|
||||
static inline float bw_hs1_reset_state(
|
||||
const bw_hs1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hs1_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -127,6 +131,24 @@ static inline void bw_hs1_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_hs1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_hs1_reset_state_multi(
|
||||
const bw_hs1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hs1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_hs1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_hs1_update_coeffs_ctrl(
|
||||
@ -406,7 +428,7 @@ static inline void bw_hs1_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_hs1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_hs1_reset_state(
|
||||
static inline float bw_hs1_reset_state(
|
||||
const bw_hs1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hs1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -416,7 +438,7 @@ static inline void bw_hs1_reset_state(
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
|
||||
const float y = bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_hs1_state");
|
||||
@ -425,6 +447,33 @@ static inline void bw_hs1_reset_state(
|
||||
BW_ASSERT_DEEP(bw_hs1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hs1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_hs1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_hs1_reset_state_multi(
|
||||
const bw_hs1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_hs1_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_hs1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hs1_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_hs1_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_hs1_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_hs1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_hs1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_hs1_update_coeffs_ctrl(
|
||||
@ -668,7 +717,20 @@ public:
|
||||
float sampleRate);
|
||||
|
||||
void reset(
|
||||
float x0 = 0.f);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -705,9 +767,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_hs1_coeffs coeffs;
|
||||
bw_hs1_state states[N_CHANNELS];
|
||||
bw_hs1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_hs1_coeffs coeffs;
|
||||
bw_hs1_state states[N_CHANNELS];
|
||||
bw_hs1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -725,10 +787,37 @@ inline void HS1<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HS1<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_hs1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_hs1_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_hs1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_hs1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HS1<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HS1<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_hs1_reset_coeffs(&coeffs);
|
||||
bw_hs1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void HS1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
111
include/bw_lp1.h
111
include/bw_lp1.h
@ -32,6 +32,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_lp1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_lp1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li><code>bw_lp1_process()</code> and
|
||||
* <code>bw_lp1_process_multi()</code> now use <code>size_t</code>
|
||||
* to count samples and channels.</li>
|
||||
@ -42,7 +46,7 @@
|
||||
* C-style arrays as arguments.</li>
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Fixed theoretical bug in <code>bw_lp1_init()</code>.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -119,7 +123,7 @@ static inline void bw_lp1_reset_coeffs(
|
||||
*
|
||||
* #### bw_lp1_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_lp1_reset_state(
|
||||
static inline float bw_lp1_reset_state(
|
||||
const bw_lp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_lp1_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -127,6 +131,24 @@ static inline void bw_lp1_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_lp1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_lp1_reset_state_multi(
|
||||
const bw_lp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_lp1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_lp1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_lp1_update_coeffs_ctrl(
|
||||
@ -388,7 +410,7 @@ static inline void bw_lp1_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_lp1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_lp1_reset_state(
|
||||
static inline float bw_lp1_reset_state(
|
||||
const bw_lp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_lp1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -399,6 +421,7 @@ static inline void bw_lp1_reset_state(
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
(void)coeffs;
|
||||
const float y = x_0;
|
||||
state->y_z1 = x_0;
|
||||
state->X_z1 = 0.f;
|
||||
|
||||
@ -409,6 +432,33 @@ static inline void bw_lp1_reset_state(
|
||||
BW_ASSERT_DEEP(bw_lp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_lp1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_lp1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_lp1_reset_state_multi(
|
||||
const bw_lp1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_lp1_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_lp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_lp1_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_lp1_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_lp1_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_lp1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_lp1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_lp1_update_coeffs_ctrl(
|
||||
@ -626,7 +676,21 @@ public:
|
||||
void setSampleRate(
|
||||
float sampleRate);
|
||||
|
||||
void reset(float x0 = 0.f);
|
||||
void reset(
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -657,9 +721,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_lp1_coeffs coeffs;
|
||||
bw_lp1_state states[N_CHANNELS];
|
||||
bw_lp1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_lp1_coeffs coeffs;
|
||||
bw_lp1_state states[N_CHANNELS];
|
||||
bw_lp1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -677,10 +741,37 @@ inline void LP1<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LP1<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_lp1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_lp1_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_lp1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_lp1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LP1<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LP1<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_lp1_reset_coeffs(&coeffs);
|
||||
bw_lp1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LP1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
112
include/bw_ls1.h
112
include/bw_ls1.h
@ -30,6 +30,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_ls1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_ls1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li>Added prewarp_at_cutoff and prewarp_freq parameters.</li>
|
||||
* <li><code>bw_ls1_process()</code> and
|
||||
* <code>bw_ls1_process_multi()</code> now use <code>size_t</code>
|
||||
@ -42,7 +46,7 @@
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Fixed documentation to indicate correct default parameter
|
||||
* values.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -118,7 +122,7 @@ static inline void bw_ls1_reset_coeffs(
|
||||
*
|
||||
* #### bw_ls1_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_ls1_reset_state(
|
||||
static inline float bw_ls1_reset_state(
|
||||
const bw_ls1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ls1_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -126,6 +130,24 @@ static inline void bw_ls1_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_ls1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_ls1_reset_state_multi(
|
||||
const bw_ls1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ls1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_ls1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_ls1_update_coeffs_ctrl(
|
||||
@ -400,7 +422,7 @@ static inline void bw_ls1_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_ls1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_ls1_reset_state(
|
||||
static inline float bw_ls1_reset_state(
|
||||
const bw_ls1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ls1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -410,7 +432,7 @@ static inline void bw_ls1_reset_state(
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
|
||||
const float y = bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_ls1_state");
|
||||
@ -419,6 +441,33 @@ static inline void bw_ls1_reset_state(
|
||||
BW_ASSERT_DEEP(bw_ls1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ls1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_ls1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_ls1_reset_state_multi(
|
||||
const bw_ls1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_ls1_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_ls1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ls1_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_ls1_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_ls1_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_ls1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_ls1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_ls1_update_coeffs_ctrl(
|
||||
@ -661,7 +710,21 @@ public:
|
||||
void setSampleRate(
|
||||
float sampleRate);
|
||||
|
||||
void reset(float x0 = 0.f);
|
||||
void reset(
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -698,9 +761,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_ls1_coeffs coeffs;
|
||||
bw_ls1_state states[N_CHANNELS];
|
||||
bw_ls1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_ls1_coeffs coeffs;
|
||||
bw_ls1_state states[N_CHANNELS];
|
||||
bw_ls1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -718,10 +781,37 @@ inline void LS1<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LS1<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_ls1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_ls1_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_ls1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_ls1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LS1<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LS1<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_ls1_reset_coeffs(&coeffs);
|
||||
bw_ls1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void LS1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
110
include/bw_mm1.h
110
include/bw_mm1.h
@ -29,6 +29,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_mm1_reset_state_multi()</code> and updated C++
|
||||
* API in this regard.</li>
|
||||
* <li>Now <code>bw_mm1_reset_state()</code> returns the initial output
|
||||
* value.</li>
|
||||
* <li><code>bw_mm1_process()</code> and
|
||||
* <code>bw_mm1_process_multi()</code> now use <code>size_t</code>
|
||||
* to count samples and channels.</li>
|
||||
@ -38,7 +42,7 @@
|
||||
* <li>Added overladed C++ <code>process()</code> function taking
|
||||
* C-style arrays as arguments.</li>
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -114,7 +118,7 @@ static inline void bw_mm1_reset_coeffs(
|
||||
*
|
||||
* #### bw_mm1_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_mm1_reset_state(
|
||||
static inline float bw_mm1_reset_state(
|
||||
const bw_mm1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_mm1_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -122,6 +126,24 @@ static inline void bw_mm1_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_mm1_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_mm1_reset_state_multi(
|
||||
const bw_mm1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_mm1_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_mm1_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_mm1_update_coeffs_ctrl(
|
||||
@ -369,7 +391,7 @@ static inline void bw_mm1_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_mm1_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_mm1_reset_state(
|
||||
static inline float bw_mm1_reset_state(
|
||||
const bw_mm1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_mm1_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -379,6 +401,7 @@ static inline void bw_mm1_reset_state(
|
||||
BW_ASSERT(state != NULL);
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
const float y = (bw_gain_get_gain_lin(&coeffs->gain_x_coeffs) + bw_gain_get_gain_lin(&coeffs->gain_lp_coeffs)) * x_0;
|
||||
bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
@ -388,6 +411,33 @@ static inline void bw_mm1_reset_state(
|
||||
BW_ASSERT_DEEP(bw_mm1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_mm1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_mm1_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_mm1_reset_state_multi(
|
||||
const bw_mm1_coeffs * BW_RESTRICT coeffs,
|
||||
bw_mm1_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_mm1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_mm1_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_mm1_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_mm1_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_mm1_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_mm1_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_mm1_update_coeffs_ctrl(
|
||||
@ -618,7 +668,20 @@ public:
|
||||
float sampleRate);
|
||||
|
||||
void reset(
|
||||
float x0 = 0.f);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -655,9 +718,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_mm1_coeffs coeffs;
|
||||
bw_mm1_state states[N_CHANNELS];
|
||||
bw_mm1_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_mm1_coeffs coeffs;
|
||||
bw_mm1_state states[N_CHANNELS];
|
||||
bw_mm1_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -675,10 +738,37 @@ inline void MM1<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void MM1<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_mm1_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_mm1_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_mm1_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_mm1_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void MM1<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void MM1<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_mm1_reset_coeffs(&coeffs);
|
||||
bw_mm1_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void MM1<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
@ -32,6 +32,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_one_pole_reset_state_multi()</code> and updated
|
||||
* C++ API in this regard.</li>
|
||||
* <li>Now <code>bw_one_pole_reset_state()</code> returns the initial
|
||||
* output value.</li>
|
||||
* <li>Now using <code>size_t</code> instead of
|
||||
* <code>BW_SIZE_T</code>.</li>
|
||||
* <li>Added more <code>const</code> and <code>BW_RESTRICT</code>
|
||||
@ -42,7 +46,7 @@
|
||||
* <li>Removed usage of reserved identifiers.</li>
|
||||
* <li>Now using backward Euler rather than impulse invariant
|
||||
* method.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added more debugging code and added `coeffs` argument to
|
||||
* <code>bw_one_pole_state_is_valid()</code>.</li>
|
||||
* <li>Added pragmas to silence bogus GCC uninitialized variable
|
||||
@ -144,7 +148,7 @@ static inline void bw_one_pole_reset_coeffs(
|
||||
*
|
||||
* #### bw_one_pole_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_one_pole_reset_state(
|
||||
static inline float bw_one_pole_reset_state(
|
||||
const bw_one_pole_coeffs * BW_RESTRICT coeffs,
|
||||
bw_one_pole_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -152,6 +156,24 @@ static inline void bw_one_pole_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/initial input value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_one_pole_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_one_pole_reset_state_multi(
|
||||
const bw_one_pole_coeffs * BW_RESTRICT coeffs,
|
||||
bw_one_pole_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_one_pole_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_one_pole_update_coeffs_ctrl(
|
||||
@ -545,7 +567,7 @@ static inline void bw_one_pole_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_one_pole_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_one_pole_reset_state(
|
||||
static inline float bw_one_pole_reset_state(
|
||||
const bw_one_pole_coeffs * BW_RESTRICT coeffs,
|
||||
bw_one_pole_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -556,6 +578,7 @@ static inline void bw_one_pole_reset_state(
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
(void)coeffs;
|
||||
const float y = x_0;
|
||||
state->y_z1 = x_0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
@ -565,6 +588,33 @@ static inline void bw_one_pole_reset_state(
|
||||
BW_ASSERT_DEEP(bw_one_pole_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_one_pole_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_one_pole_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_one_pole_reset_state_multi(
|
||||
const bw_one_pole_coeffs * BW_RESTRICT coeffs,
|
||||
bw_one_pole_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_one_pole_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_one_pole_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_one_pole_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_one_pole_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_one_pole_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_one_pole_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_one_pole_update_coeffs_ctrl(
|
||||
@ -1163,7 +1213,20 @@ public:
|
||||
float sampleRate);
|
||||
|
||||
void reset(
|
||||
float x0 = 0.f);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS>& y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS>& y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -1232,10 +1295,37 @@ inline void OnePole<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void OnePole<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_one_pole_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_one_pole_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_one_pole_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_one_pole_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void OnePole<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS>& y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void OnePole<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_one_pole_reset_coeffs(&coeffs);
|
||||
bw_one_pole_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void OnePole<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS>& y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
@ -496,7 +496,7 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c
|
||||
bw_phase_gen_process1(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state, &p, &pi);
|
||||
coeffs->s = (8.f / 29761.f) * bw_osc_sin_process1(p);
|
||||
bw_lp1_update_coeffs_audio(&coeffs->damping_coeffs);
|
||||
coeffs->diff2 = bw_clipf(bw_gain_get_gain(&coeffs->decay_coeffs) + 0.15f, 0.25f, 0.5f);
|
||||
coeffs->diff2 = bw_clipf(bw_gain_get_gain_lin(&coeffs->decay_coeffs) + 0.15f, 0.25f, 0.5f);
|
||||
bw_dry_wet_update_coeffs_audio(&coeffs->dry_wet_coeffs);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,10 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_slew_lim_reset_state_multi()</code> and updated
|
||||
* C++ API in this regard.</li>
|
||||
* <li>Now <code>bw_slew_lim_reset_state()</code> returns the initial
|
||||
* output value.</li>
|
||||
* <li>Added <code>bw_slew_lim_process1_none()</code>.</li>
|
||||
* <li><code>bw_slew_lim_process()</code> and
|
||||
* <code>bw_slew_lim_process_multi()</code> now use
|
||||
@ -43,7 +47,7 @@
|
||||
* <code>bw_slew_lim_init()</code>.</li>
|
||||
* <li>Fixed documentation of
|
||||
* <code>bw_slew_lim_update_coeffs_audio()</code>.</li>
|
||||
* <li>Clearly specificed parameter validity ranges.</li>
|
||||
* <li>Clearly specified parameter validity ranges.</li>
|
||||
* <li>Added debugging code.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
@ -120,7 +124,7 @@ static inline void bw_slew_lim_reset_coeffs(
|
||||
*
|
||||
* #### bw_slew_lim_reset_state()
|
||||
* ```>>> */
|
||||
static inline void bw_slew_lim_reset_state(
|
||||
static inline float bw_slew_lim_reset_state(
|
||||
const bw_slew_lim_coeffs * BW_RESTRICT coeffs,
|
||||
bw_slew_lim_state * BW_RESTRICT state,
|
||||
float x_0);
|
||||
@ -128,6 +132,24 @@ static inline void bw_slew_lim_reset_state(
|
||||
* Resets the given `state` to its initial values using the given `coeffs`
|
||||
* and the quiescent/equilibrium value `x_0`.
|
||||
*
|
||||
* Returns the corresponding quiescent/initial output value.
|
||||
*
|
||||
* #### bw_slew_lim_reset_state_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_slew_lim_reset_state_multi(
|
||||
const bw_slew_lim_coeffs * BW_RESTRICT coeffs,
|
||||
bw_slew_lim_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 quiescent/initial input value in the
|
||||
* `x_0` array.
|
||||
*
|
||||
* The corresponding quiescent/initial output values are written into the
|
||||
* `y_0` array, if not `NULL`.
|
||||
*
|
||||
* #### bw_slew_lim_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_slew_lim_update_coeffs_ctrl(
|
||||
@ -403,7 +425,7 @@ static inline void bw_slew_lim_reset_coeffs(
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_slew_lim_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline void bw_slew_lim_reset_state(
|
||||
static inline float bw_slew_lim_reset_state(
|
||||
const bw_slew_lim_coeffs * BW_RESTRICT coeffs,
|
||||
bw_slew_lim_state * BW_RESTRICT state,
|
||||
float x_0) {
|
||||
@ -414,6 +436,7 @@ static inline void bw_slew_lim_reset_state(
|
||||
BW_ASSERT(bw_is_finite(x_0));
|
||||
|
||||
(void)coeffs;
|
||||
const float y = x_0;
|
||||
state->y_z1 = x_0;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
@ -423,6 +446,33 @@ static inline void bw_slew_lim_reset_state(
|
||||
BW_ASSERT_DEEP(bw_slew_lim_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_slew_lim_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_slew_lim_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline void bw_slew_lim_reset_state_multi(
|
||||
const bw_slew_lim_coeffs * BW_RESTRICT coeffs,
|
||||
bw_slew_lim_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_slew_lim_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_slew_lim_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_slew_lim_reset_state(coeffs, state[i], x_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_slew_lim_reset_state(coeffs, state[i], x_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_slew_lim_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_slew_lim_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_slew_lim_update_coeffs_ctrl(
|
||||
@ -808,7 +858,20 @@ public:
|
||||
float sampleRate);
|
||||
|
||||
void reset(
|
||||
float x0 = 0.f);
|
||||
float x0 = 0.f,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void reset(
|
||||
const float * x0,
|
||||
float * y0 = nullptr);
|
||||
|
||||
void reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0);
|
||||
|
||||
void process(
|
||||
const float * const * x,
|
||||
@ -842,9 +905,9 @@ public:
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_slew_lim_coeffs coeffs;
|
||||
bw_slew_lim_state states[N_CHANNELS];
|
||||
bw_slew_lim_state *BW_RESTRICT statesP[N_CHANNELS];
|
||||
bw_slew_lim_coeffs coeffs;
|
||||
bw_slew_lim_state states[N_CHANNELS];
|
||||
bw_slew_lim_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
@ -862,10 +925,37 @@ inline void SlewLim<N_CHANNELS>::setSampleRate(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void SlewLim<N_CHANNELS>::reset(
|
||||
float x0) {
|
||||
float x0,
|
||||
float * y0) {
|
||||
bw_slew_lim_reset_coeffs(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_slew_lim_reset_state(&coeffs, states + i, x0);
|
||||
if (y0 != nullptr)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_slew_lim_reset_state(&coeffs, states + i, x0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_slew_lim_reset_state(&coeffs, states + i, x0);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void SlewLim<N_CHANNELS>::reset(
|
||||
float x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0, y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void SlewLim<N_CHANNELS>::reset(
|
||||
const float * x0,
|
||||
float * y0) {
|
||||
bw_slew_lim_reset_coeffs(&coeffs);
|
||||
bw_slew_lim_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void SlewLim<N_CHANNELS>::reset(
|
||||
std::array<float, N_CHANNELS> x0,
|
||||
std::array<float, N_CHANNELS> & y0) {
|
||||
reset(x0.data(), y0.data());
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
|
Loading…
Reference in New Issue
Block a user