finalize bw_hp1 + examples + fix bw_slew_lim + ChangeLogs/cosmetics

This commit is contained in:
Stefano D'Angelo 2023-08-30 17:12:27 +02:00
parent 637cefb636
commit d15e7951f7
6 changed files with 369 additions and 44 deletions

View File

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

View File

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

View File

@ -30,6 +30,7 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Added prewarp_at_cutoff and prewarp_freq parameters.</li>
* <li><code>bw_hp1_process()</code> and * <li><code>bw_hp1_process()</code> and
* <code>bw_hp1_process_multi()</code> now use <code>size_t</code> * <code>bw_hp1_process_multi()</code> now use <code>size_t</code>
* to count samples and channels.</li> * to count samples and channels.</li>
@ -39,6 +40,8 @@
* <li>Added overladed C++ <code>process()</code> function taking * <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li> * C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li> * <li>Removed usage of reserved identifiers.</li>
* <li>Clearly specificed parameter validity ranges.</li>
* <li>Added debugging code.</li>
* </ul> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -91,51 +94,68 @@ typedef struct bw_hp1_state bw_hp1_state;
* *
* #### bw_hp1_init() * #### bw_hp1_init()
* ```>>> */ * ```>>> */
static inline void bw_hp1_init(bw_hp1_coeffs *BW_RESTRICT coeffs); static inline void bw_hp1_init(
bw_hp1_coeffs * BW_RESTRICT coeffs);
/*! <<<``` /*! <<<```
* Initializes input parameter values in `coeffs`. * Initializes input parameter values in `coeffs`.
* *
* #### bw_hp1_set_sample_rate() * #### bw_hp1_set_sample_rate()
* ```>>> */ * ```>>> */
static inline void bw_hp1_set_sample_rate(bw_hp1_coeffs *BW_RESTRICT coeffs, float sample_rate); static inline void bw_hp1_set_sample_rate(
bw_hp1_coeffs * BW_RESTRICT coeffs,
float sample_rate);
/*! <<<``` /*! <<<```
* Sets the `sample_rate` (Hz) value in `coeffs`. * Sets the `sample_rate` (Hz) value in `coeffs`.
* *
* #### bw_hp1_reset_coeffs() * #### bw_hp1_reset_coeffs()
* ```>>> */ * ```>>> */
static inline void bw_hp1_reset_coeffs(bw_hp1_coeffs *BW_RESTRICT coeffs); static inline void bw_hp1_reset_coeffs(
bw_hp1_coeffs * BW_RESTRICT coeffs);
/*! <<<``` /*! <<<```
* Resets coefficients in `coeffs` to assume their target values. * Resets coefficients in `coeffs` to assume their target values.
* *
* #### bw_hp1_reset_state() * #### bw_hp1_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x_0); static inline void bw_hp1_reset_state(
const bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_state * BW_RESTRICT state,
float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x_0`. * and the quiescent/initial input value `x_0`.
* *
* #### bw_hp1_update_coeffs_ctrl() * #### bw_hp1_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
static inline void bw_hp1_update_coeffs_ctrl(bw_hp1_coeffs *BW_RESTRICT coeffs); static inline void bw_hp1_update_coeffs_ctrl(
bw_hp1_coeffs * BW_RESTRICT coeffs);
/*! <<<``` /*! <<<```
* Triggers control-rate update of coefficients in `coeffs`. * Triggers control-rate update of coefficients in `coeffs`.
* *
* #### bw_hp1_update_coeffs_audio() * #### bw_hp1_update_coeffs_audio()
* ```>>> */ * ```>>> */
static inline void bw_hp1_update_coeffs_audio(bw_hp1_coeffs *BW_RESTRICT coeffs); static inline void bw_hp1_update_coeffs_audio(
bw_hp1_coeffs * BW_RESTRICT coeffs);
/*! <<<``` /*! <<<```
* Triggers audio-rate update of coefficients in `coeffs`. * Triggers audio-rate update of coefficients in `coeffs`.
* *
* #### bw_hp1_process1() * #### bw_hp1_process1()
* ```>>> */ * ```>>> */
static inline float bw_hp1_process1(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x); static inline float bw_hp1_process1(
const bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_state * BW_RESTRICT state,
float x);
/*! <<<``` /*! <<<```
* Processes one input sample `x` using `coeffs`, while using and updating * Processes one input sample `x` using `coeffs`, while using and updating
* `state`. Returns the corresponding output sample. * `state`. Returns the corresponding output sample.
* *
* #### bw_hp1_process() * #### bw_hp1_process()
* ```>>> */ * ```>>> */
static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples); static inline void bw_hp1_process(
bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -143,7 +163,13 @@ static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_stat
* *
* #### bw_hp1_process_multi() * #### bw_hp1_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_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_hp1_process_multi(
bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -152,11 +178,65 @@ static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp
* *
* #### bw_hp1_set_cutoff() * #### bw_hp1_set_cutoff()
* ```>>> */ * ```>>> */
static inline void bw_hp1_set_cutoff(bw_hp1_coeffs *BW_RESTRICT coeffs, float value); static inline void bw_hp1_set_cutoff(
bw_hp1_coeffs * BW_RESTRICT coeffs,
float value);
/*! <<<``` /*! <<<```
* Sets the cutoff frequency `value` (Hz) in `coeffs`. * Sets the cutoff frequency `value` (Hz) in `coeffs`.
* *
* Valid range: [`1e-6f`, `1e6f`].
*
* Default value: `1e3f`. * Default value: `1e3f`.
*
* #### bw_hp1_set_prewarp_at_cutoff()
* ```>>> */
static inline void bw_hp1_set_prewarp_at_cutoff(
bw_hp1_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_hp1_set_prewarp_freq()
* ```>>> */
static inline void bw_hp1_set_prewarp_freq(
bw_hp1_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_hp1_coeffs_is_valid()
* ```>>> */
static inline char bw_hp1_coeffs_is_valid(
const bw_hp1_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_hp1_coeffs`.
*
* #### bw_hp1_state_is_valid()
* ```>>> */
static inline char bw_hp1_state_is_valid(
const bw_hp1_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.
*
* `state` must at least point to a readable memory block of size greater
* than or equal to that of `bw_hp1_state`.
* }}} */ * }}} */
#ifdef __cplusplus #ifdef __cplusplus
@ -174,63 +254,273 @@ static inline void bw_hp1_set_cutoff(bw_hp1_coeffs *BW_RESTRICT coeffs, float va
extern "C" { extern "C" {
#endif #endif
#ifdef BW_DEBUG_DEEP
enum bw_hp1_coeffs_state {
bw_hp1_coeffs_state_invalid,
bw_hp1_coeffs_state_init,
bw_hp1_coeffs_state_set_sample_rate,
bw_hp1_coeffs_state_reset_coeffs
};
#endif
struct bw_hp1_coeffs { struct bw_hp1_coeffs {
#ifdef BW_DEBUG_DEEP
uint32_t hash;
enum bw_hp1_coeffs_state state;
uint32_t reset_id;
#endif
// Sub-components // Sub-components
bw_lp1_coeffs lp1_coeffs; bw_lp1_coeffs lp1_coeffs;
}; };
struct bw_hp1_state { struct bw_hp1_state {
#ifdef BW_DEBUG_DEEP
uint32_t hash;
uint32_t coeffs_reset_id;
#endif
bw_lp1_state lp1_state; bw_lp1_state lp1_state;
}; };
static inline void bw_hp1_init(bw_hp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hp1_init(
bw_hp1_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
bw_lp1_init(&coeffs->lp1_coeffs); bw_lp1_init(&coeffs->lp1_coeffs);
#ifdef BW_DEBUG_DEEP
coeffs->hash = bw_hash_sdbm("bw_hp1_coeffs");
coeffs->state = bw_hp1_coeffs_state_init;
coeffs->reset_id = coeffs->hash + 1;
#endif
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_hp1_coeffs_state_init);
} }
static inline void bw_hp1_set_sample_rate(bw_hp1_coeffs *BW_RESTRICT coeffs, float sample_rate) { static inline void bw_hp1_set_sample_rate(
bw_hp1_coeffs * BW_RESTRICT coeffs,
float sample_rate) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
bw_lp1_set_sample_rate(&coeffs->lp1_coeffs, sample_rate); bw_lp1_set_sample_rate(&coeffs->lp1_coeffs, sample_rate);
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_hp1_coeffs_state_set_sample_rate;
#endif
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_hp1_coeffs_state_set_sample_rate);
} }
static inline void bw_hp1_reset_coeffs(bw_hp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hp1_reset_coeffs(
bw_hp1_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_set_sample_rate);
bw_lp1_reset_coeffs(&coeffs->lp1_coeffs); bw_lp1_reset_coeffs(&coeffs->lp1_coeffs);
#ifdef BW_DEBUG_DEEP
coeffs->state = bw_hp1_coeffs_state_reset_coeffs;
coeffs->reset_id++;
#endif
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state == bw_hp1_coeffs_state_reset_coeffs);
} }
static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x_0) { static inline void bw_hp1_reset_state(
const bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_state * BW_RESTRICT state,
float x_0) {
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(bw_is_finite(x_0));
bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0);
#ifdef BW_DEBUG_DEEP
state->hash = bw_hash_sdbm("bw_hp1_state");
state->coeffs_reset_id = coeffs->reset_id;
#endif
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(state));
BW_ASSERT_DEEP(coeffs->reset_id == state->coeffs_reset_id);
} }
static inline void bw_hp1_update_coeffs_ctrl(bw_hp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hp1_update_coeffs_ctrl(
bw_hp1_coeffs * BW_RESTRICT coeffs) {
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_lp1_update_coeffs_ctrl(&coeffs->lp1_coeffs); bw_lp1_update_coeffs_ctrl(&coeffs->lp1_coeffs);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
} }
static inline void bw_hp1_update_coeffs_audio(bw_hp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hp1_update_coeffs_audio(
bw_hp1_coeffs * BW_RESTRICT coeffs) {
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_lp1_update_coeffs_audio(&coeffs->lp1_coeffs); bw_lp1_update_coeffs_audio(&coeffs->lp1_coeffs);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
} }
static inline float bw_hp1_process1(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x) { static inline float bw_hp1_process1(
const bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_state * BW_RESTRICT state,
float x) {
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_DEEP(bw_hp1_state_is_valid(state));
BW_ASSERT_DEEP(coeffs->reset_id == state->coeffs_reset_id);
BW_ASSERT(bw_is_finite(x));
const float lp = bw_lp1_process1(&coeffs->lp1_coeffs, &state->lp1_state, x); const float lp = bw_lp1_process1(&coeffs->lp1_coeffs, &state->lp1_state, x);
return x - lp; const float y = x - lp;
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(state));
BW_ASSERT_DEEP(coeffs->reset_id == state->coeffs_reset_id);
BW_ASSERT(bw_is_finite(y));
return y;
} }
static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { static inline void bw_hp1_process(
bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_state * BW_RESTRICT state,
const float * x,
float * y,
size_t n_samples) {
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_DEEP(bw_hp1_state_is_valid(state));
BW_ASSERT_DEEP(coeffs->reset_id == state->coeffs_reset_id);
BW_ASSERT(x != NULL);
BW_ASSERT_DEEP(!bw_has_nan(x, n_samples));
BW_ASSERT(y != NULL);
bw_hp1_update_coeffs_ctrl(coeffs); bw_hp1_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hp1_update_coeffs_audio(coeffs); bw_hp1_update_coeffs_audio(coeffs);
y[i] = bw_hp1_process1(coeffs, state, x[i]); y[i] = bw_hp1_process1(coeffs, state, x[i]);
} }
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(state));
BW_ASSERT_DEEP(coeffs->reset_id == state->coeffs_reset_id);
BW_ASSERT_DEEP(!bw_has_nan(y, n_samples));
} }
static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_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_hp1_process_multi(
bw_hp1_coeffs * BW_RESTRICT coeffs,
bw_hp1_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_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
BW_ASSERT(state != NULL);
BW_ASSERT(x != NULL);
BW_ASSERT(y != NULL);
bw_hp1_update_coeffs_ctrl(coeffs); bw_hp1_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hp1_update_coeffs_audio(coeffs); bw_hp1_update_coeffs_audio(coeffs);
for (size_t j = 0; j < n_channels; j++) for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_hp1_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_hp1_process1(coeffs, state[j], x[j][i]);
} }
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_reset_coeffs);
} }
static inline void bw_hp1_set_cutoff(bw_hp1_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_hp1_set_cutoff(
bw_hp1_coeffs * BW_RESTRICT coeffs,
float value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
BW_ASSERT(!bw_is_nan(value));
BW_ASSERT(value >= 1e-6f && value <= 1e6f);
bw_lp1_set_cutoff(&coeffs->lp1_coeffs, value); bw_lp1_set_cutoff(&coeffs->lp1_coeffs, value);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
}
static inline void bw_hp1_set_prewarp_at_cutoff(
bw_hp1_coeffs * BW_RESTRICT coeffs,
char value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
bw_lp1_set_prewarp_at_cutoff(&coeffs->lp1_coeffs, value);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
}
static inline void bw_hp1_set_prewarp_freq(
bw_hp1_coeffs * BW_RESTRICT coeffs,
float value) {
BW_ASSERT(coeffs != NULL);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
BW_ASSERT(value >= 1e-6f && value <= 1e6f);
bw_lp1_set_prewarp_freq(&coeffs->lp1_coeffs, value);
BW_ASSERT_DEEP(bw_hp1_coeffs_is_valid(coeffs));
BW_ASSERT_DEEP(coeffs->state >= bw_hp1_coeffs_state_init);
}
static inline char bw_hp1_coeffs_is_valid(
const bw_hp1_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL);
#ifdef BW_DEBUG_DEEP
if (coeffs->hash != bw_hash_sdbm("bw_hp1_coeffs"))
return 0;
if (coeffs->state < bw_hp1_coeffs_state_init || coeffs->state > bw_hp1_coeffs_state_reset_coeffs)
return 0;
#endif
return bw_lp1_coeffs_is_valid(&coeffs->lp1_coeffs);
}
static inline char bw_hp1_state_is_valid(
const bw_hp1_state * BW_RESTRICT state) {
BW_ASSERT(state != NULL);
#ifdef BW_DEBUG_DEEP
if (state->hash != bw_hash_sdbm("bw_hp1_state"))
return 0;
#endif
return bw_lp1_state_is_valid(&state->lp1_state);
} }
#ifdef __cplusplus #ifdef __cplusplus
@ -250,18 +540,30 @@ class HP1 {
public: public:
HP1(); HP1();
void setSampleRate(float sampleRate); void setSampleRate(
void reset(float x_0 = 0.f); float sampleRate);
void reset(
float x0 = 0.f);
void process( void process(
const float * const *x, const float * const * x,
float * const *y, float * const * y,
size_t nSamples); size_t nSamples);
void process( void process(
std::array<const float *, N_CHANNELS> x, std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y, std::array<float *, N_CHANNELS> y,
size_t nSamples); size_t nSamples);
void setCutoff(float value); void setCutoff(
float value);
void setPrewarpAtCutoff(
bool value);
void setPrewarpFreq(
float value);
/*! <<<... /*! <<<...
* } * }
* ``` * ```
@ -286,38 +588,53 @@ inline HP1<N_CHANNELS>::HP1() {
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setSampleRate(float sampleRate) { inline void HP1<N_CHANNELS>::setSampleRate(
float sampleRate) {
bw_hp1_set_sample_rate(&coeffs, sampleRate); bw_hp1_set_sample_rate(&coeffs, sampleRate);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::reset(float x_0) { inline void HP1<N_CHANNELS>::reset(
float x0) {
bw_hp1_reset_coeffs(&coeffs); bw_hp1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++) for (size_t i = 0; i < N_CHANNELS; i++)
bw_hp1_reset_state(&coeffs, states + i, x_0); bw_hp1_reset_state(&coeffs, states + i, x0);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::process( inline void HP1<N_CHANNELS>::process(
const float * const *x, const float * const * x,
float * const *y, float * const * y,
size_t nSamples) { size_t nSamples) {
bw_hp1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); bw_hp1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::process( inline void HP1<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x, std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y, std::array<float *, N_CHANNELS> y,
size_t nSamples) { size_t nSamples) {
process(x.data(), y.data(), nSamples); process(x.data(), y.data(), nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setCutoff(float value) { inline void HP1<N_CHANNELS>::setCutoff(
float value) {
bw_hp1_set_cutoff(&coeffs, value); bw_hp1_set_cutoff(&coeffs, value);
} }
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setPrewarpAtCutoff(
bool value) {
bw_hp1_set_prewarp_at_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setPrewarpFreq(
float value) {
bw_hp1_set_prewarp_freq(&coeffs, value);
}
} }
#endif #endif

View File

@ -42,6 +42,7 @@
* C-style arrays as arguments.</li> * C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li> * <li>Removed usage of reserved identifiers.</li>
* <li>Fixed theoretical bug in <code>bw_lp1_init()</code>.</li> * <li>Fixed theoretical bug in <code>bw_lp1_init()</code>.</li>
* <li>Clearly specificed parameter validity ranges.</li>
* <li>Added debugging code.</li> * <li>Added debugging code.</li>
* </ul> * </ul>
* </li> * </li>
@ -549,7 +550,7 @@ static inline void bw_lp1_set_prewarp_freq(
} }
static inline char bw_lp1_coeffs_is_valid( static inline char bw_lp1_coeffs_is_valid(
const bw_lp1_coeffs * BW_RESTRICT coeffs) { const bw_lp1_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL); BW_ASSERT(coeffs != NULL);
#ifdef BW_DEBUG_DEEP #ifdef BW_DEBUG_DEEP
@ -588,7 +589,7 @@ static inline char bw_lp1_coeffs_is_valid(
} }
static inline char bw_lp1_state_is_valid( static inline char bw_lp1_state_is_valid(
const bw_lp1_state * BW_RESTRICT state) { const bw_lp1_state * BW_RESTRICT state) {
BW_ASSERT(state != NULL); BW_ASSERT(state != NULL);
#ifdef BW_DEBUG_DEEP #ifdef BW_DEBUG_DEEP
@ -596,8 +597,7 @@ static inline char bw_lp1_state_is_valid(
return 0; return 0;
#endif #endif
return bw_is_finite(state->y_z1); return bw_is_finite(state->y_z1) && bw_is_finite(state->X_z1);
return bw_is_finite(state->X_z1);
} }
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -42,6 +42,7 @@
* <li>Removed usage of reserved identifiers.</li> * <li>Removed usage of reserved identifiers.</li>
* <li>Now using backward Euler rather than impulse invariant * <li>Now using backward Euler rather than impulse invariant
* method.</li> * method.</li>
* <li>Clearly specificed parameter validity ranges.</li>
* <li>Added more debugging code.</li> * <li>Added more debugging code.</li>
* <li>Added pragmas to silence bogus GCC uninitialized variable * <li>Added pragmas to silence bogus GCC uninitialized variable
* warnings.</li> * warnings.</li>

View File

@ -43,6 +43,7 @@
* <code>bw_slew_lim_init()</code>.</li> * <code>bw_slew_lim_init()</code>.</li>
* <li>Fixed documentation of * <li>Fixed documentation of
* <code>bw_slew_lim_update_coeffs_audio()</code>.</li> * <code>bw_slew_lim_update_coeffs_audio()</code>.</li>
* <li>Clearly specificed parameter validity ranges.</li>
* <li>Added debugging code.</li> * <li>Added debugging code.</li>
* </ul> * </ul>
* </li> * </li>
@ -747,7 +748,7 @@ static inline float bw_slew_lim_get_y_z1(
} }
static inline char bw_slew_lim_coeffs_is_valid( static inline char bw_slew_lim_coeffs_is_valid(
const bw_slew_lim_coeffs * BW_RESTRICT coeffs) { const bw_slew_lim_coeffs * BW_RESTRICT coeffs) {
BW_ASSERT(coeffs != NULL); BW_ASSERT(coeffs != NULL);
#ifdef BW_DEBUG_DEEP #ifdef BW_DEBUG_DEEP
@ -780,7 +781,7 @@ static inline char bw_slew_lim_coeffs_is_valid(
} }
static inline char bw_slew_lim_state_is_valid( static inline char bw_slew_lim_state_is_valid(
const bw_slew_lim_state * BW_RESTRICT state) { const bw_slew_lim_state * BW_RESTRICT state) {
BW_ASSERT(state != NULL); BW_ASSERT(state != NULL);
#ifdef BW_DEBUG_DEEP #ifdef BW_DEBUG_DEEP