finalize bw_{pan,ppm} + examples + fix bw_env_follow debug, bw_wah reset
This commit is contained in:
parent
7b65b75d92
commit
99fc95a693
5
TODO
5
TODO
@ -19,9 +19,6 @@ code:
|
|||||||
specific:
|
specific:
|
||||||
* bw_comb: should also modulate feedback?
|
* bw_comb: should also modulate feedback?
|
||||||
* bw_comb: integer target delay values?
|
* bw_comb: integer target delay values?
|
||||||
* prewarp control in all derived filtering modules
|
|
||||||
* src inside distortions? w/ control from outside?
|
|
||||||
* better src filter
|
|
||||||
finally:
|
finally:
|
||||||
* debugging - also check outputs different (incl bw_buf)
|
* debugging - also check outputs different (incl bw_buf)
|
||||||
* check all examples again
|
* check all examples again
|
||||||
@ -76,6 +73,8 @@ code:
|
|||||||
* process allow NULL output?
|
* process allow NULL output?
|
||||||
* #if __cplusplus >= 201103L ? - see https://stackoverflow.com/questions/5047971/how-do-i-check-for-c11-support
|
* #if __cplusplus >= 201103L ? - see https://stackoverflow.com/questions/5047971/how-do-i-check-for-c11-support
|
||||||
* get current compression level, knee
|
* get current compression level, knee
|
||||||
|
* src inside distortions? w/ control from outside?
|
||||||
|
* make all outs nullable?
|
||||||
|
|
||||||
build system:
|
build system:
|
||||||
* make makefiles handle paths with spaces etc
|
* make makefiles handle paths with spaces etc
|
||||||
|
@ -33,8 +33,8 @@ void bw_example_fx_pan_set_sample_rate(bw_example_fx_pan *instance, float sample
|
|||||||
void bw_example_fx_pan_reset(bw_example_fx_pan *instance) {
|
void bw_example_fx_pan_reset(bw_example_fx_pan *instance) {
|
||||||
bw_pan_reset_coeffs(&instance->pan_coeffs);
|
bw_pan_reset_coeffs(&instance->pan_coeffs);
|
||||||
bw_ppm_reset_coeffs(&instance->ppm_coeffs);
|
bw_ppm_reset_coeffs(&instance->ppm_coeffs);
|
||||||
bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_l_state);
|
bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_l_state, 0.f);
|
||||||
bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_r_state);
|
bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_r_state, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bw_example_fx_pan_process(bw_example_fx_pan *instance, const float** x, float** y, int n_samples) {
|
void bw_example_fx_pan_process(bw_example_fx_pan *instance, const float** x, float** y, int n_samples) {
|
||||||
|
@ -4,3 +4,6 @@ NAME := bw_example_fx_pan
|
|||||||
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_pan.c
|
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_pan.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
|
||||||
|
@ -4,3 +4,6 @@ NAME := bw_example_fxpp_pan
|
|||||||
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_pan.cpp
|
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_pan.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
|
||||||
|
@ -589,9 +589,7 @@ static inline char bw_env_follow_state_is_valid(
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)coeffs;
|
return bw_one_pole_state_is_valid(coeffs ? &coeffs->one_pole_coeffs : NULL, &state->one_pole_state);
|
||||||
|
|
||||||
return bw_one_pole_state_is_valid(&coeffs->one_pole_coeffs, &state->one_pole_state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
283
include/bw_pan.h
283
include/bw_pan.h
@ -39,6 +39,8 @@
|
|||||||
* <li>Added overloaded C++ <code>process()</code> function taking
|
* <li>Added overloaded 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 specified 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>:
|
||||||
@ -81,37 +83,47 @@ typedef struct bw_pan_coeffs bw_pan_coeffs;
|
|||||||
*
|
*
|
||||||
* #### bw_pan_init()
|
* #### bw_pan_init()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_init(bw_pan_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_pan_init(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Initializes input parameter values in `coeffs`.
|
* Initializes input parameter values in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_pan_set_sample_rate()
|
* #### bw_pan_set_sample_rate()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_set_sample_rate(bw_pan_coeffs *BW_RESTRICT coeffs, float sample_rate);
|
static inline void bw_pan_set_sample_rate(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float sample_rate);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_pan_reset_coeffs()
|
* #### bw_pan_reset_coeffs()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_reset_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_pan_reset_coeffs(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Resets coefficients in `coeffs` to assume their target values.
|
* Resets coefficients in `coeffs` to assume their target values.
|
||||||
*
|
*
|
||||||
* #### bw_pan_update_coeffs_ctrl()
|
* #### bw_pan_update_coeffs_ctrl()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_update_coeffs_ctrl(bw_pan_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_pan_update_coeffs_ctrl(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Triggers control-rate update of coefficients in `coeffs`.
|
* Triggers control-rate update of coefficients in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_pan_update_coeffs_audio()
|
* #### bw_pan_update_coeffs_audio()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_update_coeffs_audio(bw_pan_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_pan_update_coeffs_audio(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Triggers audio-rate update of coefficients in `coeffs`.
|
* Triggers audio-rate update of coefficients in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_pan_process1()
|
* #### bw_pan_process1()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_process1(const bw_pan_coeffs *BW_RESTRICT coeffs, float x, float *BW_RESTRICT y_l, float *BW_RESTRICT y_r);
|
static inline void bw_pan_process1(
|
||||||
|
const bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float x,
|
||||||
|
float * BW_RESTRICT y_l,
|
||||||
|
float * BW_RESTRICT y_r);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Processes one input sample `x` using `coeffs`, while using and updating
|
* Processes one input sample `x` using `coeffs`, while using and updating
|
||||||
* `state`. The left and right output samples are put into `y_l` (left) and
|
* `state`. The left and right output samples are put into `y_l` (left) and
|
||||||
@ -119,7 +131,12 @@ static inline void bw_pan_process1(const bw_pan_coeffs *BW_RESTRICT coeffs, floa
|
|||||||
*
|
*
|
||||||
* #### bw_pan_process()
|
* #### bw_pan_process()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, size_t n_samples);
|
static inline void bw_pan_process(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const float * x,
|
||||||
|
float * y_l,
|
||||||
|
float * y_r,
|
||||||
|
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 buffers `y_l` (left) and `y_r` (right),
|
* first `n_samples` of the output buffers `y_l` (left) and `y_r` (right),
|
||||||
@ -127,7 +144,13 @@ static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float
|
|||||||
*
|
*
|
||||||
* #### bw_pan_process_multi()
|
* #### bw_pan_process_multi()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float * const *x, float * const *y_l, float * const *y_r, size_t n_channels, size_t n_samples);
|
static inline void bw_pan_process_multi(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const float * const * x,
|
||||||
|
float * const * y_l,
|
||||||
|
float * const * y_r,
|
||||||
|
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_l`
|
* fills the first `n_samples` of the `n_channels` output buffers `y_l`
|
||||||
@ -136,12 +159,28 @@ static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const
|
|||||||
*
|
*
|
||||||
* #### bw_pan_set_pan()
|
* #### bw_pan_set_pan()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_pan_set_pan(bw_pan_coeffs *BW_RESTRICT coeffs, float value);
|
static inline void bw_pan_set_pan(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float value);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Sets the panning `value`, where `-1.f` corresponds to hard left pan, `0.f`
|
* Sets the panning `value`, where `-1.f` corresponds to hard left pan, `0.f`
|
||||||
* to center pan, and `1.f` to hard right pan.
|
* to center pan, and `1.f` to hard right pan.
|
||||||
*
|
*
|
||||||
|
* Valid range: [`-1.f` (hard left pan), `1.f` (hard right pan)].
|
||||||
|
*
|
||||||
* Default value: `0.f`.
|
* Default value: `0.f`.
|
||||||
|
*
|
||||||
|
* #### bw_pan_coeffs_is_valid()
|
||||||
|
* ```>>> */
|
||||||
|
static inline char bw_pan_coeffs_is_valid(
|
||||||
|
const bw_pan_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_pan_coeffs`.
|
||||||
* }}} */
|
* }}} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -160,28 +199,67 @@ static inline void bw_pan_set_pan(bw_pan_coeffs *BW_RESTRICT coeffs, float value
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
enum bw_pan_coeffs_state {
|
||||||
|
bw_pan_coeffs_state_invalid,
|
||||||
|
bw_pan_coeffs_state_init,
|
||||||
|
bw_pan_coeffs_state_set_sample_rate,
|
||||||
|
bw_pan_coeffs_state_reset_coeffs
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct bw_pan_coeffs {
|
struct bw_pan_coeffs {
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
uint32_t hash;
|
||||||
|
enum bw_pan_coeffs_state state;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Sub-components
|
// Sub-components
|
||||||
bw_gain_coeffs l_coeffs;
|
bw_gain_coeffs l_coeffs;
|
||||||
bw_gain_coeffs r_coeffs;
|
bw_gain_coeffs r_coeffs;
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
float pan;
|
float pan;
|
||||||
float pan_prev;
|
float pan_prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void bw_pan_init(bw_pan_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_pan_init(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
|
||||||
bw_gain_init(&coeffs->l_coeffs);
|
bw_gain_init(&coeffs->l_coeffs);
|
||||||
bw_gain_init(&coeffs->r_coeffs);
|
bw_gain_init(&coeffs->r_coeffs);
|
||||||
coeffs->pan = 0.f;
|
coeffs->pan = 0.f;
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->hash = bw_hash_sdbm("bw_pan_coeffs");
|
||||||
|
coeffs->state = bw_pan_coeffs_state_init;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_pan_coeffs_state_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_set_sample_rate(bw_pan_coeffs *BW_RESTRICT coeffs, float sample_rate) {
|
static inline void bw_pan_set_sample_rate(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float sample_rate) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_init);
|
||||||
|
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
|
||||||
|
|
||||||
bw_gain_set_sample_rate(&coeffs->l_coeffs, sample_rate);
|
bw_gain_set_sample_rate(&coeffs->l_coeffs, sample_rate);
|
||||||
bw_gain_set_sample_rate(&coeffs->r_coeffs, sample_rate);
|
bw_gain_set_sample_rate(&coeffs->r_coeffs, sample_rate);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->state = bw_pan_coeffs_state_set_sample_rate;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_pan_coeffs_state_set_sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_do_update_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs, char force) {
|
static inline void bw_pan_do_update_coeffs(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
char force) {
|
||||||
if (force || coeffs->pan != coeffs->pan_prev) {
|
if (force || coeffs->pan != coeffs->pan_prev) {
|
||||||
const float l = 0.7071067811865477f + coeffs->pan * (-0.5f + coeffs->pan * -0.20710678118654768f);
|
const float l = 0.7071067811865477f + coeffs->pan * (-0.5f + coeffs->pan * -0.20710678118654768f);
|
||||||
bw_gain_set_gain_lin(&coeffs->l_coeffs, l);
|
bw_gain_set_gain_lin(&coeffs->l_coeffs, l);
|
||||||
@ -190,47 +268,157 @@ static inline void bw_pan_do_update_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs, ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_reset_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_pan_reset_coeffs(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_set_sample_rate);
|
||||||
|
|
||||||
bw_pan_do_update_coeffs(coeffs, 1);
|
bw_pan_do_update_coeffs(coeffs, 1);
|
||||||
bw_gain_reset_coeffs(&coeffs->l_coeffs);
|
bw_gain_reset_coeffs(&coeffs->l_coeffs);
|
||||||
bw_gain_reset_coeffs(&coeffs->r_coeffs);
|
bw_gain_reset_coeffs(&coeffs->r_coeffs);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->state = bw_pan_coeffs_state_reset_coeffs;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_pan_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_update_coeffs_ctrl(bw_pan_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_pan_update_coeffs_ctrl(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
|
||||||
bw_pan_do_update_coeffs(coeffs, 0);
|
bw_pan_do_update_coeffs(coeffs, 0);
|
||||||
bw_gain_update_coeffs_ctrl(&coeffs->l_coeffs);
|
bw_gain_update_coeffs_ctrl(&coeffs->l_coeffs);
|
||||||
bw_gain_update_coeffs_ctrl(&coeffs->r_coeffs);
|
bw_gain_update_coeffs_ctrl(&coeffs->r_coeffs);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_update_coeffs_audio(bw_pan_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_pan_update_coeffs_audio(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
|
||||||
bw_gain_update_coeffs_audio(&coeffs->l_coeffs);
|
bw_gain_update_coeffs_audio(&coeffs->l_coeffs);
|
||||||
bw_gain_update_coeffs_audio(&coeffs->r_coeffs);
|
bw_gain_update_coeffs_audio(&coeffs->r_coeffs);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_process1(const bw_pan_coeffs *BW_RESTRICT coeffs, float x, float *BW_RESTRICT y_l, float *BW_RESTRICT y_r) {
|
static inline void bw_pan_process1(
|
||||||
|
const bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float x,
|
||||||
|
float * BW_RESTRICT y_l,
|
||||||
|
float * BW_RESTRICT y_r) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(bw_is_finite(x));
|
||||||
|
|
||||||
*y_l = bw_gain_process1(&coeffs->l_coeffs, x);
|
*y_l = bw_gain_process1(&coeffs->l_coeffs, x);
|
||||||
*y_r = bw_gain_process1(&coeffs->r_coeffs, x);
|
*y_r = bw_gain_process1(&coeffs->r_coeffs, x);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(bw_is_finite(*y_l));
|
||||||
|
BW_ASSERT(bw_is_finite(*y_r));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, size_t n_samples) {
|
static inline void bw_pan_process(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const float * x,
|
||||||
|
float * y_l,
|
||||||
|
float * y_r,
|
||||||
|
size_t n_samples) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(x != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
|
||||||
|
BW_ASSERT(y_l != NULL);
|
||||||
|
BW_ASSERT(y_r != NULL);
|
||||||
|
|
||||||
bw_pan_update_coeffs_ctrl(coeffs);
|
bw_pan_update_coeffs_ctrl(coeffs);
|
||||||
for (size_t i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_pan_update_coeffs_audio(coeffs);
|
bw_pan_update_coeffs_audio(coeffs);
|
||||||
bw_pan_process1(coeffs, x[i], y_l + i, y_r + i);
|
bw_pan_process1(coeffs, x[i], y_l + i, y_r + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT_DEEP(bw_has_only_finite(y_l, n_samples));
|
||||||
|
BW_ASSERT_DEEP(bw_has_only_finite(y_r, n_samples));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float * const *x, float * const *y_l, float * const *y_r, size_t n_channels, size_t n_samples) {
|
static inline void bw_pan_process_multi(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const float * const * x,
|
||||||
|
float * const * y_l,
|
||||||
|
float * const * y_r,
|
||||||
|
size_t n_channels,
|
||||||
|
size_t n_samples) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(x != NULL);
|
||||||
|
BW_ASSERT(y_l != NULL);
|
||||||
|
BW_ASSERT(y_r != NULL);
|
||||||
|
|
||||||
bw_pan_update_coeffs_ctrl(coeffs);
|
bw_pan_update_coeffs_ctrl(coeffs);
|
||||||
for (size_t i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_pan_update_coeffs_audio(coeffs);
|
bw_pan_update_coeffs_audio(coeffs);
|
||||||
for (size_t j = 0; j < n_channels; j++)
|
for (size_t j = 0; j < n_channels; j++)
|
||||||
bw_pan_process1(coeffs, x[j][i], y_l[j] + i, y_r[j] + i);
|
bw_pan_process1(coeffs, x[j][i], y_l[j] + i, y_r[j] + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_pan_set_pan(bw_pan_coeffs *BW_RESTRICT coeffs, float value) {
|
static inline void bw_pan_set_pan(
|
||||||
|
bw_pan_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float value) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_init);
|
||||||
|
BW_ASSERT(bw_is_finite(value));
|
||||||
|
BW_ASSERT(value >= -1.f && value <= 1.f);
|
||||||
|
|
||||||
coeffs->pan = value;
|
coeffs->pan = value;
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_pan_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_pan_coeffs_state_init);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char bw_pan_coeffs_is_valid(
|
||||||
|
const bw_pan_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
if (coeffs->hash != bw_hash_sdbm("bw_pan_coeffs"))
|
||||||
|
return 0;
|
||||||
|
if (coeffs->state < bw_pan_coeffs_state_init || coeffs->state > bw_pan_coeffs_state_reset_coeffs)
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!bw_is_finite(coeffs->pan) || coeffs->pan < -1.f || coeffs->pan > 1.f)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
if (coeffs->state >= bw_pan_coeffs_state_reset_coeffs) {
|
||||||
|
if (!bw_is_finite(coeffs->pan_prev) || coeffs->pan_prev < -1.f || coeffs->pan_prev > 1.f)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return bw_gain_coeffs_is_valid(&coeffs->l_coeffs) && bw_gain_coeffs_is_valid(&coeffs->r_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -250,20 +438,25 @@ class Pan {
|
|||||||
public:
|
public:
|
||||||
Pan();
|
Pan();
|
||||||
|
|
||||||
void setSampleRate(float sampleRate);
|
void setSampleRate(
|
||||||
|
float sampleRate);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void process(
|
void process(
|
||||||
const float * const *x,
|
const float * const * x,
|
||||||
float * const *y_l,
|
float * const * yL,
|
||||||
float * const *y_r,
|
float * const * yR,
|
||||||
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_l,
|
std::array<float *, N_CHANNELS> yL,
|
||||||
std::array<float *, N_CHANNELS> y_r,
|
std::array<float *, N_CHANNELS> yR,
|
||||||
size_t nSamples);
|
size_t nSamples);
|
||||||
|
|
||||||
void setPan(float value);
|
void setPan(
|
||||||
|
float value);
|
||||||
/*! <<<...
|
/*! <<<...
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
@ -275,7 +468,7 @@ public:
|
|||||||
* change at any time in future versions. Please, do not use it directly. */
|
* change at any time in future versions. Please, do not use it directly. */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bw_pan_coeffs coeffs;
|
bw_pan_coeffs coeffs;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
@ -284,7 +477,8 @@ inline Pan<N_CHANNELS>::Pan() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void Pan<N_CHANNELS>::setSampleRate(float sampleRate) {
|
inline void Pan<N_CHANNELS>::setSampleRate(
|
||||||
|
float sampleRate) {
|
||||||
bw_pan_set_sample_rate(&coeffs, sampleRate);
|
bw_pan_set_sample_rate(&coeffs, sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,24 +489,25 @@ inline void Pan<N_CHANNELS>::reset() {
|
|||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void Pan<N_CHANNELS>::process(
|
inline void Pan<N_CHANNELS>::process(
|
||||||
const float * const *x,
|
const float * const * x,
|
||||||
float * const *y_l,
|
float * const * yL,
|
||||||
float * const *y_r,
|
float * const * yR,
|
||||||
size_t nSamples) {
|
size_t nSamples) {
|
||||||
bw_pan_process_multi(&coeffs, x, y_l, y_r, N_CHANNELS, nSamples);
|
bw_pan_process_multi(&coeffs, x, yL, yR, N_CHANNELS, nSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void Pan<N_CHANNELS>::process(
|
inline void Pan<N_CHANNELS>::process(
|
||||||
std::array<const float *, N_CHANNELS> x,
|
std::array<const float *, N_CHANNELS> x,
|
||||||
std::array<float *, N_CHANNELS> y_l,
|
std::array<float *, N_CHANNELS> yL,
|
||||||
std::array<float *, N_CHANNELS> y_r,
|
std::array<float *, N_CHANNELS> yR,
|
||||||
size_t nSamples) {
|
size_t nSamples) {
|
||||||
process(x.data(), y_l.data(), y_r.data(), nSamples);
|
process(x.data(), yL.data(), yR.data(), nSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void Pan<N_CHANNELS>::setPan(float value) {
|
inline void Pan<N_CHANNELS>::setPan(
|
||||||
|
float value) {
|
||||||
bw_pan_set_pan(&coeffs, value);
|
bw_pan_set_pan(&coeffs, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
469
include/bw_ppm.h
469
include/bw_ppm.h
@ -32,7 +32,15 @@
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>Version <strong>1.0.0</strong>:
|
* <li>Version <strong>1.0.0</strong>:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Enforced minimum output value `-600.f`.</li>
|
* <li>Enforced minimum output value <code>-600.f</code>.</li>
|
||||||
|
* <li>Added initial input value to
|
||||||
|
* <code>bw_ppm_reset_state()</code>.</li>
|
||||||
|
* <li>Added <code>bw_ppm_reset_state_multi()</code> and updated C++
|
||||||
|
* API in this regard.</li>
|
||||||
|
* <li>Now <code>bw_ppm_reset_state()</code> returns the initial output
|
||||||
|
* value.</li>
|
||||||
|
* <li>Added overloaded C++ <code>reset()</code> functions taking
|
||||||
|
* arrays as arguments.</li>
|
||||||
* <li><code>bw_ppm_process()</code> and
|
* <li><code>bw_ppm_process()</code> and
|
||||||
* <code>bw_ppm_process_multi()</code> now use <code>size_t</code>
|
* <code>bw_ppm_process_multi()</code> now use <code>size_t</code>
|
||||||
* to count samples and channels.</li>
|
* to count samples and channels.</li>
|
||||||
@ -90,43 +98,74 @@ typedef struct bw_ppm_state bw_ppm_state;
|
|||||||
*
|
*
|
||||||
* #### bw_ppm_init()
|
* #### bw_ppm_init()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_init(bw_ppm_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_ppm_init(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Initializes input parameter values in `coeffs`.
|
* Initializes input parameter values in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_set_sample_rate()
|
* #### bw_ppm_set_sample_rate()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_set_sample_rate(bw_ppm_coeffs *BW_RESTRICT coeffs, float sample_rate);
|
static inline void bw_ppm_set_sample_rate(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float sample_rate);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_reset_coeffs()
|
* #### bw_ppm_reset_coeffs()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_reset_coeffs(bw_ppm_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_ppm_reset_coeffs(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Resets coefficients in `coeffs` to assume their target values.
|
* Resets coefficients in `coeffs` to assume their target values.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_reset_state()
|
* #### bw_ppm_reset_state()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_reset_state(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state);
|
static inline float bw_ppm_reset_state(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_state * BW_RESTRICT state,
|
||||||
|
float x_0);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Resets the given `state` to its initial values using the given `coeffs`.
|
* Resets the given `state` to its initial values using the given `coeffs`
|
||||||
|
* and the initial input value `x_0`.
|
||||||
|
*
|
||||||
|
* Returns the corresponding initial output value.
|
||||||
|
*
|
||||||
|
* #### bw_ppm_reset_state_multi()
|
||||||
|
* ```>>> */
|
||||||
|
static inline void bw_ppm_reset_state_multi(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_state * BW_RESTRICT const * BW_RESTRICT state,
|
||||||
|
const float * x_0,
|
||||||
|
float * y_0,
|
||||||
|
size_t n_channels);
|
||||||
|
/*! <<<```
|
||||||
|
* Resets each of the `n_channels` `state`s to its initial values using the
|
||||||
|
* given `coeffs` and the corresponding initial input value in the `x_0`
|
||||||
|
* array.
|
||||||
|
*
|
||||||
|
* The corresponding initial output values are written into the `y_0` array,
|
||||||
|
* if not `NULL`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_update_coeffs_ctrl()
|
* #### bw_ppm_update_coeffs_ctrl()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_update_coeffs_ctrl(bw_ppm_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_ppm_update_coeffs_ctrl(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Triggers control-rate update of coefficients in `coeffs`.
|
* Triggers control-rate update of coefficients in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_update_coeffs_audio()
|
* #### bw_ppm_update_coeffs_audio()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_update_coeffs_audio(bw_ppm_coeffs *BW_RESTRICT coeffs);
|
static inline void bw_ppm_update_coeffs_audio(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Triggers audio-rate update of coefficients in `coeffs`.
|
* Triggers audio-rate update of coefficients in `coeffs`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_process1()
|
* #### bw_ppm_process1()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline float bw_ppm_process1(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, float x);
|
static inline float bw_ppm_process1(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_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 value in dBSF (minimum
|
* `state`. Returns the corresponding output sample value in dBSF (minimum
|
||||||
@ -134,7 +173,12 @@ static inline float bw_ppm_process1(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_
|
|||||||
*
|
*
|
||||||
* #### bw_ppm_process()
|
* #### bw_ppm_process()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
|
static inline void bw_ppm_process(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_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
|
||||||
@ -146,30 +190,69 @@ static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_stat
|
|||||||
*
|
*
|
||||||
* #### bw_ppm_process_multi()
|
* #### bw_ppm_process_multi()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_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_ppm_process_multi(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_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
|
||||||
* using and updating both the common `coeffs` and each of the `n_channels`
|
* using and updating both the common `coeffs` and each of the `n_channels`
|
||||||
* `state`s (control and audio rate).
|
* `state`s (control and audio rate).
|
||||||
*
|
*
|
||||||
* Output sample values are in dBFS (minimum `-600.f`).
|
* Output sample values are in dBFS (minimum `-600.f`).
|
||||||
*
|
*
|
||||||
* `y` or any element of `y` may be `NULL`.
|
* `y` or any element of `y` may be `NULL`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_set_integration_time()
|
* #### bw_ppm_set_integration_time()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_ppm_set_integration_tau(bw_ppm_coeffs *BW_RESTRICT coeffs, float value);
|
static inline void bw_ppm_set_integration_tau(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float value);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Sets the upgoing (integration) time constant in `coeffs` to `value` (s).
|
* Sets the upgoing (integration) time constant in `coeffs` to `value` (s).
|
||||||
*
|
*
|
||||||
|
* `value` must be non-negative.
|
||||||
|
*
|
||||||
* Default value: `0.f`.
|
* Default value: `0.f`.
|
||||||
*
|
*
|
||||||
* #### bw_ppm_get_y_z1()
|
* #### bw_ppm_get_y_z1()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state);
|
static inline float bw_ppm_get_y_z1(
|
||||||
|
const bw_ppm_state * BW_RESTRICT state);
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Returns the last output sample as stored in `state`.
|
* Returns the last output sample as stored in `state`.
|
||||||
|
*
|
||||||
|
* #### bw_ppm_coeffs_is_valid()
|
||||||
|
* ```>>> */
|
||||||
|
static inline char bw_ppm_coeffs_is_valid(
|
||||||
|
const bw_ppm_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_ppm_coeffs`.
|
||||||
|
*
|
||||||
|
* #### bw_ppm_state_is_valid()
|
||||||
|
* ```>>> */
|
||||||
|
static inline char bw_ppm_state_is_valid(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const bw_ppm_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_ppm_state`.
|
||||||
* }}} */
|
* }}} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -187,50 +270,198 @@ static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state);
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
enum bw_ppm_coeffs_state {
|
||||||
|
bw_ppm_coeffs_state_invalid,
|
||||||
|
bw_ppm_coeffs_state_init,
|
||||||
|
bw_ppm_coeffs_state_set_sample_rate,
|
||||||
|
bw_ppm_coeffs_state_reset_coeffs
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct bw_ppm_coeffs {
|
struct bw_ppm_coeffs {
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
uint32_t hash;
|
||||||
|
enum bw_ppm_coeffs_state state;
|
||||||
|
uint32_t reset_id;
|
||||||
|
#endif
|
||||||
// Sub-components
|
// Sub-components
|
||||||
bw_env_follow_coeffs env_follow_coeffs;
|
bw_env_follow_coeffs env_follow_coeffs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bw_ppm_state {
|
struct bw_ppm_state {
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
uint32_t hash;
|
||||||
|
uint32_t coeffs_reset_id;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sub-components
|
||||||
bw_env_follow_state env_follow_state;
|
bw_env_follow_state env_follow_state;
|
||||||
|
|
||||||
|
// States
|
||||||
float y_z1;
|
float y_z1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void bw_ppm_init(bw_ppm_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_ppm_init(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
|
||||||
bw_env_follow_init(&coeffs->env_follow_coeffs);
|
bw_env_follow_init(&coeffs->env_follow_coeffs);
|
||||||
bw_env_follow_set_release_tau(&coeffs->env_follow_coeffs, 0.738300619235528f);
|
bw_env_follow_set_release_tau(&coeffs->env_follow_coeffs, 0.738300619235528f);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->hash = bw_hash_sdbm("bw_ppm_coeffs");
|
||||||
|
coeffs->state = bw_ppm_coeffs_state_init;
|
||||||
|
coeffs->reset_id = coeffs->hash + 1;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_ppm_coeffs_state_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_set_sample_rate(bw_ppm_coeffs *BW_RESTRICT coeffs, float sample_rate) {
|
static inline void bw_ppm_set_sample_rate(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float sample_rate) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_init);
|
||||||
|
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
|
||||||
|
|
||||||
bw_env_follow_set_sample_rate(&coeffs->env_follow_coeffs, sample_rate);
|
bw_env_follow_set_sample_rate(&coeffs->env_follow_coeffs, sample_rate);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->state = bw_ppm_coeffs_state_set_sample_rate;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_ppm_coeffs_state_set_sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_reset_coeffs(bw_ppm_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_ppm_reset_coeffs(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_set_sample_rate);
|
||||||
|
|
||||||
bw_env_follow_reset_coeffs(&coeffs->env_follow_coeffs);
|
bw_env_follow_reset_coeffs(&coeffs->env_follow_coeffs);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
coeffs->state = bw_ppm_coeffs_state_reset_coeffs;
|
||||||
|
coeffs->reset_id++;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state == bw_ppm_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_reset_state(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state) {
|
static inline float bw_ppm_reset_state(
|
||||||
bw_env_follow_reset_state(&coeffs->env_follow_coeffs, &state->env_follow_state);
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
state->y_z1 = -600.f; // minimum, see below
|
bw_ppm_state * BW_RESTRICT state,
|
||||||
}
|
float x_0) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
BW_ASSERT(bw_is_finite(x_0));
|
||||||
|
|
||||||
static inline void bw_ppm_update_coeffs_ctrl(bw_ppm_coeffs *BW_RESTRICT coeffs) {
|
const float yl = bw_env_follow_reset_state(&coeffs->env_follow_coeffs, &state->env_follow_state, x_0);
|
||||||
bw_env_follow_update_coeffs_ctrl(&coeffs->env_follow_coeffs);
|
const float y = yl >= 1e-30f ? bw_lin2dBf(yl) : -600.f;
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bw_ppm_update_coeffs_audio(bw_ppm_coeffs *BW_RESTRICT coeffs) {
|
|
||||||
bw_env_follow_update_coeffs_audio(&coeffs->env_follow_coeffs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float bw_ppm_process1(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, float x) {
|
|
||||||
const float yl = bw_env_follow_process1(&coeffs->env_follow_coeffs, &state->env_follow_state, x);
|
|
||||||
const float y = yl >= 1e-30f ? bw_lin2dBf(yl) : -600.f; // -600 dB is quiet enough
|
|
||||||
state->y_z1 = y;
|
state->y_z1 = y;
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
state->hash = bw_hash_sdbm("bw_ppm_state");
|
||||||
|
state->coeffs_reset_id = coeffs->reset_id;
|
||||||
|
#endif
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT(bw_is_finite(y));
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
|
static inline void bw_ppm_reset_state_multi(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_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_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_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_ppm_reset_state(coeffs, state[i], x_0[i]);
|
||||||
|
else
|
||||||
|
for (size_t i = 0; i < n_channels; i++)
|
||||||
|
bw_ppm_reset_state(coeffs, state[i], x_0[i]);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT_DEEP(y_0 != NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bw_ppm_update_coeffs_ctrl(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
|
||||||
|
bw_env_follow_update_coeffs_ctrl(&coeffs->env_follow_coeffs);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bw_ppm_update_coeffs_audio(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
|
||||||
|
bw_env_follow_update_coeffs_audio(&coeffs->env_follow_coeffs);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float bw_ppm_process1(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_state * BW_RESTRICT state,
|
||||||
|
float x) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT(bw_is_finite(x));
|
||||||
|
|
||||||
|
const float yl = bw_env_follow_process1(&coeffs->env_follow_coeffs, &state->env_follow_state, x);
|
||||||
|
const float y = yl >= 1e-30f ? bw_lin2dBf(yl) : -600.f; // -600 dB is quiet enough
|
||||||
|
state->y_z1 = y;
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT(bw_is_finite(y));
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bw_ppm_process(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_state * BW_RESTRICT state,
|
||||||
|
const float * x,
|
||||||
|
float * y,
|
||||||
|
size_t n_samples) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT(x != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_has_only_finite(x, n_samples));
|
||||||
|
|
||||||
bw_ppm_update_coeffs_ctrl(coeffs);
|
bw_ppm_update_coeffs_ctrl(coeffs);
|
||||||
if (y != NULL)
|
if (y != NULL)
|
||||||
for (size_t i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
@ -242,9 +473,26 @@ static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_stat
|
|||||||
bw_ppm_update_coeffs_audio(coeffs);
|
bw_ppm_update_coeffs_audio(coeffs);
|
||||||
bw_ppm_process1(coeffs, state, x[i]);
|
bw_ppm_process1(coeffs, state, x[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT_DEEP(y != NULL ? bw_has_only_finite(y, n_samples) : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_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_ppm_process_multi(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
bw_ppm_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_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
BW_ASSERT(x != NULL);
|
||||||
|
|
||||||
bw_ppm_update_coeffs_ctrl(coeffs);
|
bw_ppm_update_coeffs_ctrl(coeffs);
|
||||||
if (y != NULL)
|
if (y != NULL)
|
||||||
for (size_t i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
@ -261,16 +509,66 @@ static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_pp
|
|||||||
for (size_t j = 0; j < n_channels; j++)
|
for (size_t j = 0; j < n_channels; j++)
|
||||||
bw_ppm_process1(coeffs, state[j], x[j][i]);
|
bw_ppm_process1(coeffs, state[j], x[j][i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_reset_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_ppm_set_integration_tau(bw_ppm_coeffs *BW_RESTRICT coeffs, float value) {
|
static inline void bw_ppm_set_integration_tau(
|
||||||
|
bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
float value) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_init);
|
||||||
|
BW_ASSERT(!bw_is_nan(value));
|
||||||
|
BW_ASSERT(value >= 0.f);
|
||||||
|
|
||||||
bw_env_follow_set_attack_tau(&coeffs->env_follow_coeffs, value);
|
bw_env_follow_set_attack_tau(&coeffs->env_follow_coeffs, value);
|
||||||
|
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_coeffs_is_valid(coeffs));
|
||||||
|
BW_ASSERT_DEEP(coeffs->state >= bw_ppm_coeffs_state_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state) {
|
static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state) {
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
BW_ASSERT_DEEP(bw_ppm_state_is_valid(NULL, state));
|
||||||
|
|
||||||
return state->y_z1;
|
return state->y_z1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline char bw_ppm_coeffs_is_valid(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs) {
|
||||||
|
BW_ASSERT(coeffs != NULL);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
if (coeffs->hash != bw_hash_sdbm("bw_ppm_coeffs"))
|
||||||
|
return 0;
|
||||||
|
if (coeffs->state < bw_ppm_coeffs_state_init || coeffs->state > bw_ppm_coeffs_state_reset_coeffs)
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return bw_env_follow_coeffs_is_valid(&coeffs->env_follow_coeffs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char bw_ppm_state_is_valid(
|
||||||
|
const bw_ppm_coeffs * BW_RESTRICT coeffs,
|
||||||
|
const bw_ppm_state * BW_RESTRICT state) {
|
||||||
|
BW_ASSERT(state != NULL);
|
||||||
|
|
||||||
|
#ifdef BW_DEBUG_DEEP
|
||||||
|
if (state->hash != bw_hash_sdbm("bw_ppm_state"))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (coeffs != NULL && coeffs->reset_id != state->coeffs_reset_id)
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!bw_is_finite(state->y_z1) || state->y_z1 < -600.f)
|
||||||
|
return 0.f;
|
||||||
|
|
||||||
|
return bw_env_follow_state_is_valid(coeffs ? &coeffs->env_follow_coeffs : NULL, &state->env_follow_state);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,20 +586,40 @@ class PPM {
|
|||||||
public:
|
public:
|
||||||
PPM();
|
PPM();
|
||||||
|
|
||||||
void setSampleRate(float sampleRate);
|
void setSampleRate(
|
||||||
void reset();
|
float sampleRate);
|
||||||
|
|
||||||
|
void reset(
|
||||||
|
float x0 = 0.f,
|
||||||
|
float * BW_RESTRICT y0 = nullptr);
|
||||||
|
|
||||||
|
void reset(
|
||||||
|
float x0,
|
||||||
|
std::array<float, N_CHANNELS> * BW_RESTRICT y0);
|
||||||
|
|
||||||
|
void reset(
|
||||||
|
const float * x0,
|
||||||
|
float * y0 = nullptr);
|
||||||
|
|
||||||
|
void reset(
|
||||||
|
std::array<float, N_CHANNELS> x0,
|
||||||
|
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = nullptr);
|
||||||
|
|
||||||
void process(
|
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 setIntegrationTau(float value);
|
void setIntegrationTau(
|
||||||
|
float value);
|
||||||
float getYZ1(size_t channel);
|
|
||||||
|
float getYZ1(
|
||||||
|
size_t channel);
|
||||||
/*! <<<...
|
/*! <<<...
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
@ -313,9 +631,9 @@ public:
|
|||||||
* change at any time in future versions. Please, do not use it directly. */
|
* change at any time in future versions. Please, do not use it directly. */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bw_ppm_coeffs coeffs;
|
bw_ppm_coeffs coeffs;
|
||||||
bw_ppm_state states[N_CHANNELS];
|
bw_ppm_state states[N_CHANNELS];
|
||||||
bw_ppm_state *BW_RESTRICT statesP[N_CHANNELS];
|
bw_ppm_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
@ -326,40 +644,71 @@ inline PPM<N_CHANNELS>::PPM() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void PPM<N_CHANNELS>::setSampleRate(float sampleRate) {
|
inline void PPM<N_CHANNELS>::setSampleRate(
|
||||||
|
float sampleRate) {
|
||||||
bw_ppm_set_sample_rate(&coeffs, sampleRate);
|
bw_ppm_set_sample_rate(&coeffs, sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void PPM<N_CHANNELS>::reset() {
|
inline void PPM<N_CHANNELS>::reset(
|
||||||
|
float x0,
|
||||||
|
float * BW_RESTRICT y0) {
|
||||||
bw_ppm_reset_coeffs(&coeffs);
|
bw_ppm_reset_coeffs(&coeffs);
|
||||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
if (y0 != nullptr)
|
||||||
bw_ppm_reset_state(&coeffs, states + i);
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
y0[i] = bw_ppm_reset_state(&coeffs, states + i, x0);
|
||||||
|
else
|
||||||
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
bw_ppm_reset_state(&coeffs, states + i, x0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void PPM<N_CHANNELS>::reset(
|
||||||
|
float x0,
|
||||||
|
std::array<float, N_CHANNELS> * BW_RESTRICT y0) {
|
||||||
|
reset(x0, y0 != nullptr ? y0->data() : nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void PPM<N_CHANNELS>::reset(
|
||||||
|
const float * x0,
|
||||||
|
float * y0) {
|
||||||
|
bw_ppm_reset_coeffs(&coeffs);
|
||||||
|
bw_ppm_reset_state_multi(&coeffs, statesP, x0, y0, N_CHANNELS);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void PPM<N_CHANNELS>::reset(
|
||||||
|
std::array<float, N_CHANNELS> x0,
|
||||||
|
std::array<float, N_CHANNELS> * BW_RESTRICT y0) {
|
||||||
|
reset(x0.data(), y0 != nullptr ? y0->data() : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void PPM<N_CHANNELS>::process(
|
inline void PPM<N_CHANNELS>::process(
|
||||||
const float * const *x,
|
const float * const * x,
|
||||||
float * const *y,
|
float * const * y,
|
||||||
size_t nSamples) {
|
size_t nSamples) {
|
||||||
bw_ppm_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
bw_ppm_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline void PPM<N_CHANNELS>::process(
|
inline void PPM<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 PPM<N_CHANNELS>::setIntegrationTau(float value) {
|
inline void PPM<N_CHANNELS>::setIntegrationTau(
|
||||||
|
float value) {
|
||||||
bw_ppm_set_integration_tau(&coeffs, value);
|
bw_ppm_set_integration_tau(&coeffs, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
inline float PPM<N_CHANNELS>::getYZ1(size_t channel) {
|
inline float PPM<N_CHANNELS>::getYZ1(
|
||||||
|
size_t channel) {
|
||||||
return bw_ppm_get_y_z1(states + channel);
|
return bw_ppm_get_y_z1(states + channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,8 +366,9 @@ static inline float bw_wah_reset_state(
|
|||||||
BW_ASSERT_DEEP(bw_wah_coeffs_is_valid(coeffs));
|
BW_ASSERT_DEEP(bw_wah_coeffs_is_valid(coeffs));
|
||||||
BW_ASSERT_DEEP(coeffs->state >= bw_wah_coeffs_state_reset_coeffs);
|
BW_ASSERT_DEEP(coeffs->state >= bw_wah_coeffs_state_reset_coeffs);
|
||||||
BW_ASSERT_DEEP(bw_wah_state_is_valid(coeffs, state));
|
BW_ASSERT_DEEP(bw_wah_state_is_valid(coeffs, state));
|
||||||
|
BW_ASSERT(bw_is_finite(bp));
|
||||||
|
|
||||||
return 0.f;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_wah_reset_state_multi(
|
static inline void bw_wah_reset_state_multi(
|
||||||
|
Loading…
Reference in New Issue
Block a user