2022-11-15 23:49:51 +00:00
|
|
|
/*
|
|
|
|
* Brickworks
|
|
|
|
*
|
2023-01-12 19:22:37 +00:00
|
|
|
* Copyright (C) 2022, 2023 Orastron Srl unipersonale
|
2022-11-15 23:49:51 +00:00
|
|
|
*
|
|
|
|
* Brickworks is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3 of the License.
|
|
|
|
*
|
|
|
|
* Brickworks is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2022-12-06 08:01:34 +00:00
|
|
|
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
2022-11-15 23:49:51 +00:00
|
|
|
*
|
|
|
|
* File author: Stefano D'Angelo
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* module_type {{{ dsp }}}
|
2023-01-12 19:22:37 +00:00
|
|
|
* version {{{ 0.3.0 }}}
|
2023-03-14 14:50:00 +00:00
|
|
|
* requires {{{ bw_config bw_common bw_math bw_one_pole }}}
|
2022-11-15 23:49:51 +00:00
|
|
|
* description {{{
|
|
|
|
* State variable filter (2nd order, 12 dB/oct) model with separated lowpass,
|
|
|
|
* bandpass, and highpass outputs.
|
|
|
|
* }}}
|
|
|
|
* changelog {{{
|
|
|
|
* <ul>
|
2023-01-12 19:22:37 +00:00
|
|
|
* <li>Version <strong>0.3.0</strong>:
|
|
|
|
* <ul>
|
2023-02-20 08:40:04 +00:00
|
|
|
* <li>Strenghtened algorithm for modulation.</li>
|
|
|
|
* <li>Added prewarping control parameters (prewarp_at_cutoff and
|
|
|
|
* prewarp_freq).</li>
|
2023-01-16 18:50:27 +00:00
|
|
|
* <li>Added `BW_RESTRICT` to `bw_svf_process1()`.</li>
|
2023-02-20 08:40:04 +00:00
|
|
|
* <li>Fixed typo in `bw_svf_set_Q()` documentation.</li>
|
2023-01-12 19:22:37 +00:00
|
|
|
* </ul>
|
|
|
|
* </li>
|
2022-11-19 01:25:38 +00:00
|
|
|
* <li>Version <strong>0.2.0</strong>:
|
|
|
|
* <ul>
|
2022-11-22 14:28:16 +00:00
|
|
|
* <li>Refactored API.</li>
|
2022-11-19 01:25:38 +00:00
|
|
|
* </ul>
|
|
|
|
* </li>
|
2022-11-15 23:49:51 +00:00
|
|
|
* <li>Version <strong>0.1.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>First release.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* }}}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BW_SVF_H
|
|
|
|
#define _BW_SVF_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-11-23 09:54:48 +00:00
|
|
|
#include <bw_common.h>
|
|
|
|
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! api {{{
|
2022-11-23 09:54:48 +00:00
|
|
|
* #### bw_svf_coeffs
|
2022-11-15 23:49:51 +00:00
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
typedef struct _bw_svf_coeffs bw_svf_coeffs;
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Coefficients and related.
|
2022-11-23 09:54:48 +00:00
|
|
|
*
|
|
|
|
* ### bw_svf_state
|
|
|
|
* ```>>> */
|
|
|
|
typedef struct _bw_svf_state bw_svf_state;
|
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Internal state and related.
|
2022-11-23 09:54:48 +00:00
|
|
|
*
|
2022-11-19 01:25:38 +00:00
|
|
|
* #### bw_svf_init()
|
2022-11-15 23:49:51 +00:00
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_init(bw_svf_coeffs *BW_RESTRICT coeffs);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Initializes input parameter values in `coeffs`.
|
2022-11-23 09:54:48 +00:00
|
|
|
*
|
2022-11-15 23:49:51 +00:00
|
|
|
* #### bw_svf_set_sample_rate()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_set_sample_rate(bw_svf_coeffs *BW_RESTRICT coeffs, float sample_rate);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
|
|
|
*
|
|
|
|
* #### bw_svf_reset_coeffs()
|
|
|
|
* ```>>> */
|
|
|
|
static inline void bw_svf_reset_coeffs(bw_svf_coeffs *BW_RESTRICT coeffs);
|
|
|
|
/*! <<<```
|
|
|
|
* Resets coefficients in `coeffs` to assume their target values.
|
2022-11-23 09:54:48 +00:00
|
|
|
*
|
|
|
|
* #### bw_svf_reset_state()
|
2022-11-15 23:49:51 +00:00
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Resets the given `state` to its initial values using the given `coeffs`.
|
|
|
|
*
|
|
|
|
* #### bw_svf_update_coeffs_ctrl()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_update_coeffs_ctrl(bw_svf_coeffs *BW_RESTRICT coeffs);
|
2022-12-04 17:57:49 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Triggers control-rate update of coefficients in `coeffs`.
|
|
|
|
*
|
|
|
|
* #### bw_svf_update_coeffs_audio()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_update_coeffs_audio(bw_svf_coeffs *BW_RESTRICT coeffs);
|
2022-12-04 17:57:49 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Triggers audio-rate update of coefficients in `coeffs`.
|
|
|
|
*
|
|
|
|
* #### bw_svf_process1()
|
|
|
|
* ```>>> */
|
2023-01-16 18:50:27 +00:00
|
|
|
static inline void bw_svf_process1(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, float x, float *BW_RESTRICT y_lp, float *BW_RESTRICT y_bp, float *BW_RESTRICT y_hp);
|
2022-12-04 17:57:49 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Processes one input sample `x` using `coeffs`, while using and updating
|
|
|
|
* `state`. The lowpass, bandpass, and highpass output samples are put into
|
|
|
|
* `y_lp`, `y_bp`, and `y_hp` respectively.
|
|
|
|
*
|
2022-11-15 23:49:51 +00:00
|
|
|
* #### bw_svf_process()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_process(bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, const float *x, float *y_lp, float *y_bp, float *y_hp, int n_samples);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Processes the first `n_samples` of the input buffer `x` and fills the
|
|
|
|
* first `n_samples` of the output buffers `y_lp` (lowpass), `y_bp`
|
|
|
|
* (bandpass), and `y_hp` (highpass), if they are not `NULL`, while using and
|
|
|
|
* updating both `coeffs` and `state` (control and audio rate).
|
|
|
|
*
|
2022-11-15 23:49:51 +00:00
|
|
|
* #### bw_svf_set_cutoff()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_set_cutoff(bw_svf_coeffs *BW_RESTRICT coeffs, float value);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-04 17:57:49 +00:00
|
|
|
* Sets the cutoff frequency to the given `value` (Hz) in `coeffs`.
|
|
|
|
*
|
|
|
|
* `value` must be positive and smaller than the Nyquist frequency (half the
|
|
|
|
* sample rate).
|
2022-11-15 23:49:51 +00:00
|
|
|
*
|
|
|
|
* Default value: `1e3f`.
|
2022-12-04 17:57:49 +00:00
|
|
|
*
|
2022-11-15 23:49:51 +00:00
|
|
|
* #### bw_svf_set_Q()
|
|
|
|
* ```>>> */
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_set_Q(bw_svf_coeffs *BW_RESTRICT coeffs, float value);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-12-13 21:41:18 +00:00
|
|
|
* Sets the quality factor to the given `value` in `coeffs`.
|
2022-12-04 17:57:49 +00:00
|
|
|
*
|
|
|
|
* `value` must be equal or bigger than `0.5f`.
|
2022-11-15 23:49:51 +00:00
|
|
|
*
|
|
|
|
* Default value: `0.5f`.
|
2023-01-12 19:18:57 +00:00
|
|
|
*
|
|
|
|
* #### bw_svf_set_prewarp_at_cutoff()
|
|
|
|
* ```>>> */
|
|
|
|
static inline void bw_svf_set_prewarp_at_cutoff(bw_svf_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_svf_set_prewarp_freq()
|
|
|
|
* ```>>> */
|
|
|
|
static inline void bw_svf_set_prewarp_freq(bw_svf_coeffs *BW_RESTRICT coeffs, float value);
|
|
|
|
/*! <<<```
|
|
|
|
* Sets the prewarping frequency `value` (Hz) in `coeffs`.
|
|
|
|
*
|
|
|
|
* Only used when the prewarp\_at\_cutoff parameter is off.
|
|
|
|
*
|
|
|
|
* Default value: `1e3f`.
|
2022-11-15 23:49:51 +00:00
|
|
|
* }}} */
|
|
|
|
|
2022-11-23 09:54:48 +00:00
|
|
|
/*** 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. */
|
|
|
|
|
2022-11-28 09:31:07 +00:00
|
|
|
#include <bw_math.h>
|
2022-11-22 14:28:16 +00:00
|
|
|
#include <bw_one_pole.h>
|
|
|
|
|
2022-11-23 09:54:48 +00:00
|
|
|
struct _bw_svf_coeffs {
|
2022-11-22 14:28:16 +00:00
|
|
|
// Sub-components
|
2022-11-26 10:40:42 +00:00
|
|
|
bw_one_pole_coeffs smooth_coeffs;
|
2022-11-22 14:28:16 +00:00
|
|
|
bw_one_pole_state smooth_cutoff_state;
|
|
|
|
bw_one_pole_state smooth_Q_state;
|
2023-01-12 19:18:57 +00:00
|
|
|
bw_one_pole_state smooth_prewarp_freq_state;
|
2022-11-22 14:28:16 +00:00
|
|
|
|
2022-11-19 01:25:38 +00:00
|
|
|
// Coefficients
|
2022-11-23 09:54:48 +00:00
|
|
|
float t_k;
|
2022-11-19 01:25:38 +00:00
|
|
|
|
2023-01-12 19:18:57 +00:00
|
|
|
float prewarp_k;
|
2022-11-23 09:54:48 +00:00
|
|
|
float t;
|
2022-12-13 14:11:08 +00:00
|
|
|
float kf;
|
2022-11-23 09:54:48 +00:00
|
|
|
float k;
|
2022-12-13 14:11:08 +00:00
|
|
|
float kt;
|
2022-11-23 09:54:48 +00:00
|
|
|
float hp_x;
|
2022-11-19 01:25:38 +00:00
|
|
|
|
|
|
|
// Parameters
|
2022-11-23 09:54:48 +00:00
|
|
|
float cutoff;
|
|
|
|
float Q;
|
2023-01-12 19:18:57 +00:00
|
|
|
float prewarp_freq;
|
2022-11-23 09:54:48 +00:00
|
|
|
};
|
2022-11-19 01:25:38 +00:00
|
|
|
|
2022-11-23 09:54:48 +00:00
|
|
|
struct _bw_svf_state {
|
2022-11-30 15:31:20 +00:00
|
|
|
float hp_z1;
|
|
|
|
float lp_z1;
|
|
|
|
float bp_z1;
|
2022-12-13 14:11:08 +00:00
|
|
|
float cutoff_z1;
|
2022-11-19 01:25:38 +00:00
|
|
|
};
|
|
|
|
|
2022-11-23 09:54:48 +00:00
|
|
|
static inline void bw_svf_init(bw_svf_coeffs *BW_RESTRICT coeffs) {
|
2022-11-26 10:40:42 +00:00
|
|
|
bw_one_pole_init(&coeffs->smooth_coeffs);
|
2022-11-30 10:55:25 +00:00
|
|
|
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.005f);
|
2022-11-26 10:40:42 +00:00
|
|
|
bw_one_pole_set_sticky_thresh(&coeffs->smooth_coeffs, 1e-3f);
|
2022-11-23 09:54:48 +00:00
|
|
|
coeffs->cutoff = 1e3f;
|
|
|
|
coeffs->Q = 0.5f;
|
2023-01-12 19:18:57 +00:00
|
|
|
coeffs->prewarp_freq = 1e3f;
|
|
|
|
coeffs->prewarp_k = 1.f;
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_set_sample_rate(bw_svf_coeffs *BW_RESTRICT coeffs, float sample_rate) {
|
2022-11-26 10:40:42 +00:00
|
|
|
bw_one_pole_set_sample_rate(&coeffs->smooth_coeffs, sample_rate);
|
2022-11-26 17:16:28 +00:00
|
|
|
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
|
2022-11-23 09:54:48 +00:00
|
|
|
coeffs->t_k = 3.141592653589793f / sample_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _bw_svf_do_update_coeffs(bw_svf_coeffs *BW_RESTRICT coeffs, char force) {
|
2023-01-12 19:18:57 +00:00
|
|
|
const float prewarp_freq = coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq);
|
|
|
|
float prewarp_freq_cur = bw_one_pole_get_y_z1(&coeffs->smooth_prewarp_freq_state);
|
2022-11-25 18:17:47 +00:00
|
|
|
float Q_cur = bw_one_pole_get_y_z1(&coeffs->smooth_Q_state);
|
2023-01-12 19:18:57 +00:00
|
|
|
const char prewarp_freq_changed = force || prewarp_freq != prewarp_freq_cur;
|
2022-11-25 18:17:47 +00:00
|
|
|
const char Q_changed = force || coeffs->Q != Q_cur;
|
2023-01-12 19:18:57 +00:00
|
|
|
if (prewarp_freq_changed || Q_changed) {
|
|
|
|
if (prewarp_freq_changed) {
|
|
|
|
prewarp_freq_cur = bw_one_pole_process1_sticky_rel(&coeffs->smooth_coeffs, &coeffs->smooth_prewarp_freq_state, prewarp_freq);
|
|
|
|
coeffs->t = bw_tanf_3(coeffs->t_k * prewarp_freq_cur);
|
|
|
|
coeffs->kf = coeffs->t * bw_rcpf_2(prewarp_freq_cur);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
if (Q_changed) {
|
2022-11-26 10:40:42 +00:00
|
|
|
Q_cur = bw_one_pole_process1_sticky_abs(&coeffs->smooth_coeffs, &coeffs->smooth_Q_state, coeffs->Q);
|
2022-11-25 18:17:47 +00:00
|
|
|
coeffs->k = bw_rcpf_2(Q_cur);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
2022-12-13 14:11:08 +00:00
|
|
|
coeffs->kt = coeffs->k + coeffs->t;
|
|
|
|
coeffs->hp_x = bw_rcpf_2(1.f + coeffs->t * coeffs->kt);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
2023-01-12 19:18:57 +00:00
|
|
|
bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_cutoff_state, coeffs->cutoff);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_reset_coeffs(bw_svf_coeffs *BW_RESTRICT coeffs) {
|
2022-11-26 10:40:42 +00:00
|
|
|
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_cutoff_state, coeffs->cutoff);
|
|
|
|
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_Q_state, coeffs->Q);
|
2023-01-12 19:18:57 +00:00
|
|
|
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_prewarp_freq_state, coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq));
|
2022-11-23 09:54:48 +00:00
|
|
|
_bw_svf_do_update_coeffs(coeffs, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_reset_state(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state) {
|
|
|
|
state->hp_z1 = 0.f;
|
|
|
|
state->lp_z1 = 0.f;
|
|
|
|
state->bp_z1 = 0.f;
|
2022-12-13 14:11:08 +00:00
|
|
|
state->cutoff_z1 = coeffs->cutoff;
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_update_coeffs_ctrl(bw_svf_coeffs *BW_RESTRICT coeffs) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_update_coeffs_audio(bw_svf_coeffs *BW_RESTRICT coeffs) {
|
|
|
|
_bw_svf_do_update_coeffs(coeffs, 0);
|
|
|
|
}
|
|
|
|
|
2023-01-16 18:50:27 +00:00
|
|
|
static inline void bw_svf_process1(const bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, float x, float *BW_RESTRICT y_lp, float *BW_RESTRICT y_bp, float *BW_RESTRICT y_hp) {
|
2022-12-13 14:11:08 +00:00
|
|
|
const float kk = coeffs->kf * state->cutoff_z1;
|
|
|
|
const float lp_xz1 = state->lp_z1 - kk * state->bp_z1;
|
|
|
|
const float bp_xz1 = state->bp_z1 - kk * state->hp_z1;
|
|
|
|
*y_hp = coeffs->hp_x * (x + coeffs->kt * bp_xz1 - lp_xz1);
|
|
|
|
*y_bp = bp_xz1 - coeffs->t * *y_hp;
|
|
|
|
*y_lp = lp_xz1 - coeffs->t * *y_bp;
|
2022-11-23 09:54:48 +00:00
|
|
|
state->hp_z1 = *y_hp;
|
|
|
|
state->lp_z1 = *y_lp;
|
|
|
|
state->bp_z1 = *y_bp;
|
2022-12-13 14:11:08 +00:00
|
|
|
state->cutoff_z1 = bw_one_pole_get_y_z1(&coeffs->smooth_cutoff_state);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_process(bw_svf_coeffs *BW_RESTRICT coeffs, bw_svf_state *BW_RESTRICT state, const float *x, float *y_lp, float *y_bp, float *y_hp, int n_samples) {
|
|
|
|
if (y_lp != NULL) {
|
|
|
|
if (y_bp != NULL) {
|
|
|
|
if (y_hp != NULL) {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
bw_svf_process1(coeffs, state, x[i], y_lp + i, y_bp + i, y_hp + i);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_lp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], &v_lp, y_bp + i, y_hp + i);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (y_hp != NULL) {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_bp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], y_lp + i, &v_bp, y_hp + i);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_bp, v_hp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], y_lp + i, &v_bp, &v_hp);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (y_bp != NULL) {
|
|
|
|
if (y_hp != NULL) {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_lp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], &v_lp, y_bp + i, y_hp + i);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_lp, v_hp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], &v_lp, y_bp + i, &v_hp);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (y_hp != NULL) {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_lp, v_bp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], &v_lp, &v_bp, y_hp + i);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
bw_svf_update_coeffs_audio(coeffs);
|
2022-11-25 18:17:47 +00:00
|
|
|
float v_lp, v_bp, v_hp;
|
|
|
|
bw_svf_process1(coeffs, state, x[i], &v_lp, &v_bp, &v_hp);
|
2022-11-23 09:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_set_cutoff(bw_svf_coeffs *BW_RESTRICT coeffs, float value) {
|
|
|
|
coeffs->cutoff = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_set_Q(bw_svf_coeffs *BW_RESTRICT coeffs, float value) {
|
|
|
|
coeffs->Q = value;
|
|
|
|
}
|
|
|
|
|
2023-01-12 19:18:57 +00:00
|
|
|
static inline void bw_svf_set_prewarp_at_cutoff(bw_svf_coeffs *BW_RESTRICT coeffs, char value) {
|
|
|
|
coeffs->prewarp_k = value ? 1.f : 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_svf_set_prewarp_freq(bw_svf_coeffs *BW_RESTRICT coeffs, float value) {
|
|
|
|
coeffs->prewarp_freq = value;
|
|
|
|
}
|
|
|
|
|
2022-11-15 23:49:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|