renamed bw_{drywet,ringmod} -> bw_{dry_wet,ring_mod}

This commit is contained in:
Stefano D'Angelo 2023-08-14 06:05:21 +02:00
parent 6b38be600e
commit 399325359d
5 changed files with 120 additions and 121 deletions

11
TODO
View File

@ -31,7 +31,6 @@ code:
* mem req -> return value of set sample rate?
* peak gain + Q ???
* sr_reduce reset_coeffs? update_coeffs? process_multi?
* drywet -> dry_wet, ringmod -> ring_mod, etc?
* allow nullptr in C++ wrappers where process_multi arg can be NULL
* better src filter
* c++ get coeffs/state? or public? src nIn/OutSamples case (array vs single value), delay read/write, process1? process single?
@ -39,6 +38,8 @@ code:
* clearly specify that state is tied to a particular set of coeffs (1:N)
* modulation vs process (multi) no update (post 1.0.0)???
* check assumptions w.r.t. usage of math functions
* sample rate-constant coeffs? (pan case)
* sr-dependent vs cr-dependent coeffs? see synth poly example
build system:
* single header generation (vs modules in bwp... to think about)
@ -68,6 +69,8 @@ code:
* process (multi) no update
* examples cpu usage
* bw_math: review types in implementation
* way to detect extern "C"? perhaps hidden "trap" preprocessor definition?
* any chance to avoid casts in C for const X * const * input arguments?
build system:
* make makefiles handle paths with spaces etc
@ -81,9 +84,3 @@ build system:
* cross compile (rpi etc.)
* better use of xcodegen (see xcode warnings) and/or consider tuist (https://tuist.io/), bazel (https://bazel.build/), pants (https://www.pantsbuild.org/), buck (https://buck2.build/), please (https://please.build/index.html) for mobile apps
* homogenize android and ios common code (e.g., same index)
--
code:
* sample rate-constant coeffs? (pan case)
* sr-dependent vs cr-dependent coeffs? see synth poly example

View File

@ -29,8 +29,9 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li><code>bw_drywet_process()</code> and
* <code>bw_drywet_process_multi()</code> now use
* <li>Module renamed as bw_dry_wet.</li>
* <li><code>bw_dry_wet_process()</code> and
* <code>bw_dry_wet_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
@ -54,8 +55,8 @@
* }}}
*/
#ifndef BW_DRYWET_H
#define BW_DRYWET_H
#ifndef BW_DRY_WET_H
#define BW_DRY_WET_H
#include <bw_common.h>
@ -64,77 +65,77 @@ extern "C" {
#endif
/*! api {{{
* #### bw_drywet_coeffs
* #### bw_dry_wet_coeffs
* ```>>> */
typedef struct bw_drywet_coeffs bw_drywet_coeffs;
typedef struct bw_dry_wet_coeffs bw_dry_wet_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_drywet_init()
* #### bw_dry_wet_init()
* ```>>> */
static inline void bw_drywet_init(bw_drywet_coeffs *BW_RESTRICT coeffs);
static inline void bw_dry_wet_init(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Initializes input parameter values in `coeffs`.
*
* #### bw_drywet_set_sample_rate()
* #### bw_dry_wet_set_sample_rate()
* ```>>> */
static inline void bw_drywet_set_sample_rate(bw_drywet_coeffs *BW_RESTRICT coeffs, float sample_rate);
static inline void bw_dry_wet_set_sample_rate(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value in `coeffs`.
*
* #### bw_drywet_reset_coeffs()
* #### bw_dry_wet_reset_coeffs()
* ```>>> */
static inline void bw_drywet_reset_coeffs(bw_drywet_coeffs *BW_RESTRICT coeffs);
static inline void bw_dry_wet_reset_coeffs(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Resets coefficients in `coeffs` to assume their target values.
*
* #### bw_drywet_update_coeffs_ctrl()
* #### bw_dry_wet_update_coeffs_ctrl()
* ```>>> */
static inline void bw_drywet_update_coeffs_ctrl(bw_drywet_coeffs *BW_RESTRICT coeffs);
static inline void bw_dry_wet_update_coeffs_ctrl(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Triggers control-rate update of coefficients in `coeffs`.
*
* #### bw_drywet_update_coeffs_audio()
* #### bw_dry_wet_update_coeffs_audio()
* ```>>> */
static inline void bw_drywet_update_coeffs_audio(bw_drywet_coeffs *BW_RESTRICT coeffs);
static inline void bw_dry_wet_update_coeffs_audio(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Triggers audio-rate update of coefficients in `coeffs`.
*
* #### bw_drywet_process1()
* #### bw_dry_wet_process1()
* ```>>> */
static inline float bw_drywet_process1(const bw_drywet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet);
static inline float bw_dry_wet_process1(const bw_dry_wet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet);
/*! <<<```
* Processes one dry input sample `x_dry` and one wet input sample `x_wet`
* using `coeffs` and returns the corresponding output sample.
*
* #### bw_drywet_process()
* #### bw_dry_wet_process()
* ```>>> */
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples);
static inline void bw_dry_wet_process(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the dry input buffer `x_dry` and of the
* wet input buffer `x_wet` and fills the first `n_samples` of the output
* buffer `y`, while using and updating `coeffs` (control and audio rate).
*
* #### bw_drywet_process_multi()
* #### bw_dry_wet_process_multi()
* ```>>> */
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples);
static inline void bw_dry_wet_process_multi(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` dry input buffers
* `x_dry` and of the `n_channels` wet input buffers `x_wet`, and fills the
* first `n_samples` of the `n_channels` output buffers `y`, while using and
* updating the common `coeffs` (control and audio rate).
*
* #### bw_drywet_set_wet()
* #### bw_dry_wet_set_wet()
* ```>>> */
static inline void bw_drywet_set_wet(bw_drywet_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_dry_wet_set_wet(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<```
* Sets the wet gain parameter to the given `value` (linear gain) in `coeffs`.
*
* Default value: `1.f`.
*
* #### bw_drywet_set_smooth_tau()
* #### bw_dry_wet_set_smooth_tau()
* ```>>> */
static inline void bw_drywet_set_smooth_tau(bw_drywet_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_dry_wet_set_smooth_tau(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<```
* Sets the smoothing time constant `value` (s) in `coeffs`.
*
@ -156,57 +157,57 @@ static inline void bw_drywet_set_smooth_tau(bw_drywet_coeffs *BW_RESTRICT coeffs
extern "C" {
#endif
struct bw_drywet_coeffs {
struct bw_dry_wet_coeffs {
// Sub-components
bw_gain_coeffs gain_coeffs;
};
static inline void bw_drywet_init(bw_drywet_coeffs *BW_RESTRICT coeffs) {
static inline void bw_dry_wet_init(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
bw_gain_init(&coeffs->gain_coeffs);
}
static inline void bw_drywet_set_sample_rate(bw_drywet_coeffs *BW_RESTRICT coeffs, float sample_rate) {
static inline void bw_dry_wet_set_sample_rate(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float sample_rate) {
bw_gain_set_sample_rate(&coeffs->gain_coeffs, sample_rate);
}
static inline void bw_drywet_reset_coeffs(bw_drywet_coeffs *BW_RESTRICT coeffs) {
static inline void bw_dry_wet_reset_coeffs(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
bw_gain_reset_coeffs(&coeffs->gain_coeffs);
}
static inline void bw_drywet_update_coeffs_ctrl(bw_drywet_coeffs *BW_RESTRICT coeffs) {
static inline void bw_dry_wet_update_coeffs_ctrl(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
bw_gain_update_coeffs_ctrl(&coeffs->gain_coeffs);
}
static inline void bw_drywet_update_coeffs_audio(bw_drywet_coeffs *BW_RESTRICT coeffs) {
static inline void bw_dry_wet_update_coeffs_audio(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
bw_gain_update_coeffs_audio(&coeffs->gain_coeffs);
}
static inline float bw_drywet_process1(const bw_drywet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet) {
static inline float bw_dry_wet_process1(const bw_dry_wet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet) {
return bw_gain_get_gain(&coeffs->gain_coeffs) * (x_wet - x_dry) + x_dry;
}
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples) {
bw_drywet_update_coeffs_ctrl(coeffs);
static inline void bw_dry_wet_process(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples) {
bw_dry_wet_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_drywet_update_coeffs_audio(coeffs);
y[i] = bw_drywet_process1(coeffs, x_dry[i], x_wet[i]);
bw_dry_wet_update_coeffs_audio(coeffs);
y[i] = bw_dry_wet_process1(coeffs, x_dry[i], x_wet[i]);
}
}
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples) {
bw_drywet_update_coeffs_ctrl(coeffs);
static inline void bw_dry_wet_process_multi(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples) {
bw_dry_wet_update_coeffs_ctrl(coeffs);
for (size_t i = 0; i < n_samples; i++) {
bw_drywet_update_coeffs_audio(coeffs);
bw_dry_wet_update_coeffs_audio(coeffs);
for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_drywet_process1(coeffs, x_dry[j][i], x_wet[j][i]);
y[j][i] = bw_dry_wet_process1(coeffs, x_dry[j][i], x_wet[j][i]);
}
}
static inline void bw_drywet_set_wet(bw_drywet_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_dry_wet_set_wet(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value) {
bw_gain_set_gain_lin(&coeffs->gain_coeffs, value);
}
static inline void bw_drywet_set_smooth_tau(bw_drywet_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_dry_wet_set_smooth_tau(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value) {
bw_gain_set_smooth_tau(&coeffs->gain_coeffs, value);
}
@ -253,22 +254,22 @@ public:
* change at any time in future versions. Please, do not use it directly. */
private:
bw_drywet_coeffs coeffs;
bw_dry_wet_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline DryWet<N_CHANNELS>::DryWet() {
bw_drywet_init(&coeffs);
bw_dry_wet_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_drywet_set_sample_rate(&coeffs, sampleRate);
bw_dry_wet_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::reset() {
bw_drywet_reset_coeffs(&coeffs);
bw_dry_wet_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
@ -277,7 +278,7 @@ inline void DryWet<N_CHANNELS>::process(
const float * const *x_wet,
float * const *y,
size_t nSamples) {
bw_drywet_process_multi(&coeffs, x_dry, x_wet, y, N_CHANNELS, nSamples);
bw_dry_wet_process_multi(&coeffs, x_dry, x_wet, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
@ -291,12 +292,12 @@ inline void DryWet<N_CHANNELS>::process(
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setWet(float value) {
bw_drywet_set_wet(&coeffs, value);
bw_dry_wet_set_wet(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSmoothTau(float value) {
bw_drywet_set_smooth_tau(&coeffs, value);
bw_dry_wet_set_smooth_tau(&coeffs, value);
}
}

View File

@ -22,7 +22,7 @@
* module_type {{{ dsp }}}
* version {{{ 1.0.0 }}}
* requires {{{
* bw_buf bw_common bw_delay bw_drywet bw_gain bw_lp1 bw_math bw_one_pole
* bw_buf bw_common bw_delay bw_dry_wet bw_gain bw_lp1 bw_math bw_one_pole
* bw_osc_sin bw_phase_gen
* }}}
* description {{{
@ -221,7 +221,7 @@ static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float
#include <bw_phase_gen.h>
#include <bw_osc_sin.h>
#include <bw_gain.h>
#include <bw_drywet.h>
#include <bw_dry_wet.h>
#include <bw_one_pole.h>
#include <bw_math.h>
@ -249,7 +249,7 @@ struct bw_reverb_coeffs {
bw_phase_gen_coeffs phase_gen_coeffs;
bw_phase_gen_state phase_gen_state;
bw_lp1_coeffs damping_coeffs;
bw_drywet_coeffs drywet_coeffs;
bw_dry_wet_coeffs dry_wet_coeffs;
bw_one_pole_coeffs smooth_coeffs;
bw_one_pole_state smooth_predelay_state;
@ -325,13 +325,13 @@ static inline void bw_reverb_init(bw_reverb_coeffs *BW_RESTRICT coeffs) {
bw_gain_init(&coeffs->decay_coeffs);
bw_phase_gen_init(&coeffs->phase_gen_coeffs);
bw_lp1_init(&coeffs->damping_coeffs);
bw_drywet_init(&coeffs->drywet_coeffs);
bw_dry_wet_init(&coeffs->dry_wet_coeffs);
bw_one_pole_init(&coeffs->smooth_coeffs);
bw_lp1_set_cutoff(&coeffs->bandwidth_coeffs, 20e3f);
bw_lp1_set_cutoff(&coeffs->damping_coeffs, 20e3f);
bw_gain_set_gain_lin(&coeffs->decay_coeffs, 0.5f);
bw_drywet_set_wet(&coeffs->drywet_coeffs, 0.5f);
bw_dry_wet_set_wet(&coeffs->dry_wet_coeffs, 0.5f);
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f);
bw_one_pole_set_sticky_thresh(&coeffs->smooth_coeffs, 1e-6f);
@ -356,7 +356,7 @@ static inline void bw_reverb_set_sample_rate(bw_reverb_coeffs *BW_RESTRICT coeff
bw_gain_set_sample_rate(&coeffs->decay_coeffs, sample_rate);
bw_phase_gen_set_sample_rate(&coeffs->phase_gen_coeffs, sample_rate);
bw_lp1_set_sample_rate(&coeffs->damping_coeffs, sample_rate);
bw_drywet_set_sample_rate(&coeffs->drywet_coeffs, sample_rate);
bw_dry_wet_set_sample_rate(&coeffs->dry_wet_coeffs, sample_rate);
bw_one_pole_set_sample_rate(&coeffs->smooth_coeffs, sample_rate);
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
coeffs->fs = sample_rate;
@ -451,7 +451,7 @@ static inline void bw_reverb_reset_coeffs(bw_reverb_coeffs *BW_RESTRICT coeffs)
bw_phase_gen_reset_coeffs(&coeffs->phase_gen_coeffs);
bw_phase_gen_reset_state(&coeffs->phase_gen_coeffs, &coeffs->phase_gen_state, 0.f);
bw_lp1_reset_coeffs(&coeffs->damping_coeffs);
bw_drywet_reset_coeffs(&coeffs->drywet_coeffs);
bw_dry_wet_reset_coeffs(&coeffs->dry_wet_coeffs);
bw_reverb_set_predelay(coeffs, coeffs->predelay); // to get it rounded
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_predelay_state, coeffs->predelay);
}
@ -479,7 +479,7 @@ static inline void bw_reverb_update_coeffs_ctrl(bw_reverb_coeffs *BW_RESTRICT co
bw_lp1_update_coeffs_ctrl(&coeffs->bandwidth_coeffs);
bw_gain_update_coeffs_ctrl(&coeffs->decay_coeffs);
bw_phase_gen_update_coeffs_ctrl(&coeffs->phase_gen_coeffs);
bw_drywet_update_coeffs_ctrl(&coeffs->drywet_coeffs);
bw_dry_wet_update_coeffs_ctrl(&coeffs->dry_wet_coeffs);
bw_lp1_update_coeffs_ctrl(&coeffs->damping_coeffs);
}
@ -497,7 +497,7 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c
coeffs->s = (8.f / 29761.f) * bw_osc_sin_process1(p);
bw_lp1_update_coeffs_audio(&coeffs->damping_coeffs);
coeffs->diff2 = bw_clipf(bw_gain_get_gain(&coeffs->decay_coeffs) + 0.15f, 0.25f, 0.5f);
bw_drywet_update_coeffs_audio(&coeffs->drywet_coeffs);
bw_dry_wet_update_coeffs_audio(&coeffs->dry_wet_coeffs);
}
static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float x_l, float x_r, float *y_l, float *y_r) {
@ -579,8 +579,8 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs
- bw_delay_read(&coeffs->delay_dd4_coeffs, &state->delay_dd4_state, coeffs->dr6, 0.f)
- bw_delay_read(&coeffs->delay_d4_coeffs, &state->delay_d4_state, coeffs->dr7, 0.f)
);
*y_l = bw_drywet_process1(&coeffs->drywet_coeffs, x_l, *y_l);
*y_r = bw_drywet_process1(&coeffs->drywet_coeffs, x_r, *y_r);
*y_l = bw_dry_wet_process1(&coeffs->dry_wet_coeffs, x_l, *y_l);
*y_r = bw_dry_wet_process1(&coeffs->dry_wet_coeffs, x_r, *y_r);
}
static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *x_l, const float *x_r, float *y_l, float *y_r, size_t n_samples) {
@ -617,7 +617,7 @@ static inline void bw_reverb_set_decay(bw_reverb_coeffs *BW_RESTRICT coeffs, flo
}
static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float value) {
bw_drywet_set_wet(&coeffs->drywet_coeffs, value);
bw_dry_wet_set_wet(&coeffs->dry_wet_coeffs, value);
}
#ifdef __cplusplus

View File

@ -29,8 +29,9 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li><code>bw_ringmod_process()</code> and
* <code>bw_ringmod_process_multi()</code> now use
* <li>Module renamed as bw_ring_mod.</li>
* <li><code>bw_ring_mod_process()</code> and
* <code>bw_ring_mod_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
@ -72,70 +73,70 @@ extern "C" {
#endif
/*! api {{{
* #### bw_ringmod_coeffs
* #### bw_ring_mod_coeffs
* ```>>> */
typedef struct bw_ringmod_coeffs bw_ringmod_coeffs;
typedef struct bw_ring_mod_coeffs bw_ring_mod_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_ringmod_init()
* #### bw_ring_mod_init()
* ```>>> */
static inline void bw_ringmod_init(bw_ringmod_coeffs *BW_RESTRICT coeffs);
static inline void bw_ring_mod_init(bw_ring_mod_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Initializes input parameter values in `coeffs`.
*
* #### bw_ringmod_set_sample_rate()
* #### bw_ring_mod_set_sample_rate()
* ```>>> */
static inline void bw_ringmod_set_sample_rate(bw_ringmod_coeffs *BW_RESTRICT coeffs, float sample_rate);
static inline void bw_ring_mod_set_sample_rate(bw_ring_mod_coeffs *BW_RESTRICT coeffs, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value in `coeffs`.
*
* #### bw_ringmod_reset_coeffs()
* #### bw_ring_mod_reset_coeffs()
* ```>>> */
static inline void bw_ringmod_reset_coeffs(bw_ringmod_coeffs *BW_RESTRICT coeffs);
static inline void bw_ring_mod_reset_coeffs(bw_ring_mod_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Resets coefficients in `coeffs` to assume their target values.
*
* #### bw_ringmod_update_coeffs_ctrl()
* #### bw_ring_mod_update_coeffs_ctrl()
* ```>>> */
static inline void bw_ringmod_update_coeffs_ctrl(bw_ringmod_coeffs *BW_RESTRICT coeffs);
static inline void bw_ring_mod_update_coeffs_ctrl(bw_ring_mod_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Triggers control-rate update of coefficients in `coeffs`.
*
* #### bw_ringmod_update_coeffs_audio()
* #### bw_ring_mod_update_coeffs_audio()
* ```>>> */
static inline void bw_ringmod_update_coeffs_audio(bw_ringmod_coeffs *BW_RESTRICT coeffs);
static inline void bw_ring_mod_update_coeffs_audio(bw_ring_mod_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Triggers audio-rate update of coefficients in `coeffs`.
*
* #### bw_ringmod_process1()
* #### bw_ring_mod_process1()
* ```>>> */
static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coeffs, float x_mod, float x_car);
static inline float bw_ring_mod_process1(const bw_ring_mod_coeffs *BW_RESTRICT coeffs, float x_mod, float x_car);
/*! <<<```
* Processes one modulation input sample `x_mod` and one carrier input sample
* `x_car` using `coeffs` and returns the corresponding output sample.
*
* #### bw_ringmod_process()
* #### bw_ring_mod_process()
* ```>>> */
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples);
static inline void bw_ring_mod_process(bw_ring_mod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the modulation input buffer `x_mod` and
* of the carrier input buffer `x_car` and fills the first `n_samples` of the
* output buffer `y`, while using and updating `coeffs` (control and audio
* rate).
*
* #### bw_ringmod_process_multi()
* #### bw_ring_mod_process_multi()
* ```>>> */
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float * const *y, size_t n_channels, size_t n_samples);
static inline void bw_ring_mod_process_multi(bw_ring_mod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float * const *y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` modulation input
* buffers `x_mod` and of the `n_channels` carrier input buffers `x_car`, and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while
* using and updating the common `coeffs` (control and audio rate).
*
* #### bw_ringmod_set_amount()
* #### bw_ring_mod_set_amount()
* ```>>> */
static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs, float value);
static inline void bw_ring_mod_set_amount(bw_ring_mod_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<```
* Sets the modulation amount parameter to the given `value` (`0.f` = no
* modulation, `1.f` = full modulation, `-1.f` = full modulation with
@ -160,7 +161,7 @@ static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs,
extern "C" {
#endif
struct bw_ringmod_coeffs {
struct bw_ring_mod_coeffs {
// Sub-components
bw_one_pole_coeffs smooth_coeffs;
bw_one_pole_state smooth_state;
@ -169,50 +170,50 @@ struct bw_ringmod_coeffs {
float mod_amount;
};
static inline void bw_ringmod_init(bw_ringmod_coeffs *BW_RESTRICT coeffs) {
static inline void bw_ring_mod_init(bw_ring_mod_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_init(&coeffs->smooth_coeffs);
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f);
coeffs->mod_amount = 1.f;
}
static inline void bw_ringmod_set_sample_rate(bw_ringmod_coeffs *BW_RESTRICT coeffs, float sample_rate) {
static inline void bw_ring_mod_set_sample_rate(bw_ring_mod_coeffs *BW_RESTRICT coeffs, float sample_rate) {
bw_one_pole_set_sample_rate(&coeffs->smooth_coeffs, sample_rate);
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
}
static inline void bw_ringmod_reset_coeffs(bw_ringmod_coeffs *BW_RESTRICT coeffs) {
static inline void bw_ring_mod_reset_coeffs(bw_ring_mod_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_state, coeffs->mod_amount);
}
static inline void bw_ringmod_update_coeffs_ctrl(bw_ringmod_coeffs *BW_RESTRICT coeffs) {
static inline void bw_ring_mod_update_coeffs_ctrl(bw_ring_mod_coeffs *BW_RESTRICT coeffs) {
(void)coeffs;
}
static inline void bw_ringmod_update_coeffs_audio(bw_ringmod_coeffs *BW_RESTRICT coeffs) {
static inline void bw_ring_mod_update_coeffs_audio(bw_ring_mod_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_process1(&coeffs->smooth_coeffs, &coeffs->smooth_state, coeffs->mod_amount);
}
static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coeffs, float x_mod, float x_car) {
static inline float bw_ring_mod_process1(const bw_ring_mod_coeffs *BW_RESTRICT coeffs, float x_mod, float x_car) {
const float k = bw_one_pole_get_y_z1(&coeffs->smooth_state);
return k * x_car * x_mod + bw_absf(1.f - k) * x_mod;
}
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples) {
static inline void bw_ring_mod_process(bw_ring_mod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples) {
for (size_t i = 0; i < n_samples; i++) {
bw_ringmod_update_coeffs_audio(coeffs);
y[i] = bw_ringmod_process1(coeffs, x_mod[i], x_car[i]);
bw_ring_mod_update_coeffs_audio(coeffs);
y[i] = bw_ring_mod_process1(coeffs, x_mod[i], x_car[i]);
}
}
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float * const *y, size_t n_channels, size_t n_samples) {
static inline void bw_ring_mod_process_multi(bw_ring_mod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float * const *y, size_t n_channels, size_t n_samples) {
for (size_t i = 0; i < n_samples; i++) {
bw_ringmod_update_coeffs_audio(coeffs);
bw_ring_mod_update_coeffs_audio(coeffs);
for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_ringmod_process1(coeffs, x_mod[j][i], x_car[j][i]);
y[j][i] = bw_ring_mod_process1(coeffs, x_mod[j][i], x_car[j][i]);
}
}
static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs, float value) {
static inline void bw_ring_mod_set_amount(bw_ring_mod_coeffs *BW_RESTRICT coeffs, float value) {
coeffs->mod_amount = value;
}
@ -258,22 +259,22 @@ public:
* change at any time in future versions. Please, do not use it directly. */
private:
bw_ringmod_coeffs coeffs;
bw_ring_mod_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline RingMod<N_CHANNELS>::RingMod() {
bw_ringmod_init(&coeffs);
bw_ring_mod_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ringmod_set_sample_rate(&coeffs, sampleRate);
bw_ring_mod_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::reset() {
bw_ringmod_reset_coeffs(&coeffs);
bw_ring_mod_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
@ -282,7 +283,7 @@ inline void RingMod<N_CHANNELS>::process(
const float * const *x_car,
float * const *y,
size_t nSamples) {
bw_ringmod_process_multi(&coeffs, x_mod, x_car, y, N_CHANNELS, nSamples);
bw_ring_mod_process_multi(&coeffs, x_mod, x_car, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
@ -296,7 +297,7 @@ inline void RingMod<N_CHANNELS>::process(
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setAmount(float value) {
bw_ringmod_set_amount(&coeffs, value);
bw_ring_mod_set_amount(&coeffs, value);
}
}

View File

@ -22,7 +22,7 @@
* module_type {{{ dsp }}}
* version {{{ 1.0.0 }}}
* requires {{{
* bw_common bw_math bw_one_pole bw_osc_sin bw_phase_gen bw_ringmod
* bw_common bw_math bw_one_pole bw_osc_sin bw_phase_gen bw_ring_mod
* }}}
* description {{{
* Tremolo with variable speed and amount.
@ -173,7 +173,7 @@ static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float
#include <bw_phase_gen.h>
#include <bw_osc_sin.h>
#include <bw_ringmod.h>
#include <bw_ring_mod.h>
#ifdef __cplusplus
extern "C" {
@ -182,7 +182,7 @@ extern "C" {
struct bw_trem_coeffs {
// Sub-components
bw_phase_gen_coeffs phase_gen_coeffs;
bw_ringmod_coeffs ringmod_coeffs;
bw_ring_mod_coeffs ring_mod_coeffs;
};
struct bw_trem_state {
@ -191,17 +191,17 @@ struct bw_trem_state {
static inline void bw_trem_init(bw_trem_coeffs *BW_RESTRICT coeffs) {
bw_phase_gen_init(&coeffs->phase_gen_coeffs);
bw_ringmod_init(&coeffs->ringmod_coeffs);
bw_ring_mod_init(&coeffs->ring_mod_coeffs);
}
static inline void bw_trem_set_sample_rate(bw_trem_coeffs *BW_RESTRICT coeffs, float sample_rate) {
bw_phase_gen_set_sample_rate(&coeffs->phase_gen_coeffs, sample_rate);
bw_ringmod_set_sample_rate(&coeffs->ringmod_coeffs, sample_rate);
bw_ring_mod_set_sample_rate(&coeffs->ring_mod_coeffs, sample_rate);
}
static inline void bw_trem_reset_coeffs(bw_trem_coeffs *BW_RESTRICT coeffs) {
bw_phase_gen_reset_coeffs(&coeffs->phase_gen_coeffs);
bw_ringmod_reset_coeffs(&coeffs->ringmod_coeffs);
bw_ring_mod_reset_coeffs(&coeffs->ring_mod_coeffs);
}
static inline void bw_trem_reset_state(const bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state) {
@ -210,19 +210,19 @@ static inline void bw_trem_reset_state(const bw_trem_coeffs *BW_RESTRICT coeffs,
static inline void bw_trem_update_coeffs_ctrl(bw_trem_coeffs *BW_RESTRICT coeffs) {
bw_phase_gen_update_coeffs_ctrl(&coeffs->phase_gen_coeffs);
bw_ringmod_update_coeffs_ctrl(&coeffs->ringmod_coeffs);
bw_ring_mod_update_coeffs_ctrl(&coeffs->ring_mod_coeffs);
}
static inline void bw_trem_update_coeffs_audio(bw_trem_coeffs *BW_RESTRICT coeffs) {
bw_phase_gen_update_coeffs_audio(&coeffs->phase_gen_coeffs);
bw_ringmod_update_coeffs_audio(&coeffs->ringmod_coeffs);
bw_ring_mod_update_coeffs_audio(&coeffs->ring_mod_coeffs);
}
static inline float bw_trem_process1(const bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, float x) {
float p, pi;
bw_phase_gen_process1(&coeffs->phase_gen_coeffs, &state->phase_gen_state, &p, &pi);
const float c = bw_osc_sin_process1(p);
return bw_ringmod_process1(&coeffs->ringmod_coeffs, x, 1.f + c);
return bw_ring_mod_process1(&coeffs->ring_mod_coeffs, x, 1.f + c);
}
static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
@ -247,7 +247,7 @@ static inline void bw_trem_set_rate(bw_trem_coeffs *BW_RESTRICT coeffs, float va
}
static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float value) {
bw_ringmod_set_amount(&coeffs->ringmod_coeffs, value);
bw_ring_mod_set_amount(&coeffs->ring_mod_coeffs, value);
}
#ifdef __cplusplus