improved bw_comb and bw_chorus, simplified fx_chorus

This commit is contained in:
Stefano D'Angelo 2023-04-08 08:25:05 +02:00
parent 02996e72d7
commit 98db248b5b
7 changed files with 35 additions and 50 deletions

View File

@ -26,14 +26,11 @@ struct config_pin {
int pin; int pin;
}; };
#define NUM_PINS 5 #define NUM_PINS 2
static struct config_pin config_pins[NUM_PINS] = { static struct config_pin config_pins[NUM_PINS] = {
{ 0, 15 }, { 0, 15 },
{ 1, 16 }, { 1, 16 }
{ 2, 17 },
{ 3, 18 },
{ 4, 19 },
}; };
#endif #endif

View File

@ -22,6 +22,10 @@
void bw_example_fx_chorus_init(bw_example_fx_chorus *instance) { void bw_example_fx_chorus_init(bw_example_fx_chorus *instance) {
bw_chorus_init(&instance->chorus_coeffs, 0.1f); bw_chorus_init(&instance->chorus_coeffs, 0.1f);
bw_chorus_set_delay(&instance->chorus_coeffs, 0.005f);
bw_chorus_set_coeff_x(&instance->chorus_coeffs, 0.7071f);
bw_chorus_set_coeff_mod(&instance->chorus_coeffs, 1.f);
bw_chorus_set_coeff_fb(&instance->chorus_coeffs, -0.7071f);
} }
void bw_example_fx_chorus_set_sample_rate(bw_example_fx_chorus *instance, float sample_rate) { void bw_example_fx_chorus_set_sample_rate(bw_example_fx_chorus *instance, float sample_rate) {
@ -49,19 +53,10 @@ void bw_example_fx_chorus_set_parameter(bw_example_fx_chorus *instance, int inde
instance->params[index] = value; instance->params[index] = value;
switch (index) { switch (index) {
case p_rate: case p_rate:
bw_chorus_set_rate(&instance->chorus_coeffs, value); bw_chorus_set_rate(&instance->chorus_coeffs, 0.01f + 1.99f * value * value * value);
break;
case p_delay:
bw_chorus_set_delay(&instance->chorus_coeffs, 0.1f * value);
break; break;
case p_amount: case p_amount:
bw_chorus_set_amount(&instance->chorus_coeffs, 0.05f * value); bw_chorus_set_amount(&instance->chorus_coeffs, 0.004f * value);
break;
case p_input:
bw_chorus_set_coeff_x(&instance->chorus_coeffs, value);
break;
case p_mod:
bw_chorus_set_coeff_mod(&instance->chorus_coeffs, value);
break; break;
} }
} }

View File

@ -29,10 +29,7 @@ extern "C" {
enum { enum {
p_rate, p_rate,
p_delay,
p_amount, p_amount,
p_input,
p_mod,
p_n p_n
}; };

View File

@ -66,14 +66,11 @@ static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = {
{ "Audio out", 1, 0, 0, IO_MONO } { "Audio out", 1, 0, 0, IO_MONO }
}; };
#define NUM_PARAMETERS 5 #define NUM_PARAMETERS 2
static struct config_parameter config_parameters[NUM_PARAMETERS] = { static struct config_parameter config_parameters[NUM_PARAMETERS] = {
{ "Modulation rate", "Rate", "", 0, 0, 0, 0.5f }, { "Rate", "Rate", "", 0, 0, 0, 0.5f },
{ "Delay", "Delay", "s", 0, 0, 0, 0.5f }, { "Depth", "Depth", "", 0, 0, 0, 0.5f },
{ "Modulation amount", "Mod amount", "", 0, 0, 0, 0.5f },
{ "Input", "Input", "", 0, 0, 0, 0.5f },
{ "Modulated branch", "Mod branch", "", 0, 0, 0, 0.5f },
}; };
// Internal API // Internal API

View File

@ -31,27 +31,12 @@ var buses = [
var parameters = [ var parameters = [
{ {
name: "Modulation rate", name: "Rate",
output: false, output: false,
defaultValue: 0.5 defaultValue: 0.5
}, },
{ {
name: "Delay", name: "Amount",
output: false,
defaultValue: 0.5
},
{
name: "Modulation amount",
output: false,
defaultValue: 0.5
},
{
name: "Input",
output: false,
defaultValue: 0.5
},
{
name: "Modulated branch",
output: false, output: false,
defaultValue: 0.5 defaultValue: 0.5
} }

View File

@ -26,10 +26,13 @@
* bw_osc_sin bw_phase_gen * bw_osc_sin bw_phase_gen
* }}} * }}}
* description {{{ * description {{{
* Chorus / vibrato with variable speed and amount. * Chorus / vibrato / flanger with variable rate and amount.
* *
* It outputs a mix of the dry input signal with itself going through a * It outputs a mix of the dry input signal with itself going through a
* modulated delay. * modulated delay and an optional feedback, as explained in
*
* J. Dattorro, "Effect Design, Part 2: Delay-Line Modulation and Chorus",
* J. Audio Eng. Soc., vol. 45, no. 10, pp. 764-788, October 1997.
* }}} * }}}
* changelog {{{ * changelog {{{
* <ul> * <ul>
@ -156,9 +159,9 @@ static inline void bw_chorus_set_amount(bw_chorus_coeffs *BW_RESTRICT coeffs, fl
* ```>>> */ * ```>>> */
static inline void bw_chorus_set_coeff_x(bw_chorus_coeffs *BW_RESTRICT coeffs, float value); static inline void bw_chorus_set_coeff_x(bw_chorus_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<``` /*! <<<```
* Sets the dry input coefficient `value` in `coeffs`. * Sets the input coefficient `value` in `coeffs`.
* *
* Default value: `0.f`. * Default value: `1.f`.
* *
* #### bw_chorus_set_coeff_mod() * #### bw_chorus_set_coeff_mod()
* ```>>> */ * ```>>> */
@ -166,7 +169,15 @@ static inline void bw_chorus_set_coeff_mod(bw_chorus_coeffs *BW_RESTRICT coeffs,
/*! <<<``` /*! <<<```
* Sets the modulated branch coefficient `value` in `coeffs`. * Sets the modulated branch coefficient `value` in `coeffs`.
* *
* Default value: `1.f`. * Default value: `0.f`.
*
* #### bw_chorus_set_coeff_fb()
* ```>>> */
static inline void bw_chorus_set_coeff_fb(bw_chorus_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<```
* Sets the feedback branch coefficient `value` in `coeffs`.
*
* Default value: `0.f`.
* }}} */ * }}} */
/*** Implementation ***/ /*** Implementation ***/
@ -197,8 +208,6 @@ struct _bw_chorus_state {
static inline void bw_chorus_init(bw_chorus_coeffs *BW_RESTRICT coeffs, float max_delay) { static inline void bw_chorus_init(bw_chorus_coeffs *BW_RESTRICT coeffs, float max_delay) {
bw_phase_gen_init(&coeffs->phase_gen_coeffs); bw_phase_gen_init(&coeffs->phase_gen_coeffs);
bw_comb_init(&coeffs->comb_coeffs, max_delay); bw_comb_init(&coeffs->comb_coeffs, max_delay);
bw_comb_set_coeff_blend(&coeffs->comb_coeffs, 0.f);
bw_comb_set_coeff_ff(&coeffs->comb_coeffs, 1.f);
coeffs->delay = 0.f; coeffs->delay = 0.f;
coeffs->amount = 0.f; coeffs->amount = 0.f;
} }
@ -258,6 +267,7 @@ static inline void bw_chorus_set_rate(bw_chorus_coeffs *BW_RESTRICT coeffs, floa
} }
static inline void bw_chorus_set_delay(bw_chorus_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_chorus_set_delay(bw_chorus_coeffs *BW_RESTRICT coeffs, float value) {
bw_comb_set_delay_fb(&coeffs->comb_coeffs, value);
coeffs->delay = value; coeffs->delay = value;
} }
@ -273,6 +283,10 @@ static inline void bw_chorus_set_coeff_mod(bw_chorus_coeffs *BW_RESTRICT coeffs,
bw_comb_set_coeff_ff(&coeffs->comb_coeffs, value); bw_comb_set_coeff_ff(&coeffs->comb_coeffs, value);
} }
static inline void bw_chorus_set_coeff_fb(bw_chorus_coeffs *BW_RESTRICT coeffs, float value) {
bw_comb_set_coeff_fb(&coeffs->comb_coeffs, value);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -218,7 +218,7 @@ static inline void bw_comb_init(bw_comb_coeffs *BW_RESTRICT coeffs, float max_de
bw_gain_init(&coeffs->fb_coeffs); bw_gain_init(&coeffs->fb_coeffs);
bw_one_pole_init(&coeffs->smooth_coeffs); bw_one_pole_init(&coeffs->smooth_coeffs);
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f); bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f);
bw_one_pole_set_sticky_thresh(&coeffs->smooth_coeffs, 1e-3f); bw_one_pole_set_sticky_thresh(&coeffs->smooth_coeffs, 1e-6f);
bw_gain_set_gain_lin(&coeffs->ff_coeffs, 0.f); bw_gain_set_gain_lin(&coeffs->ff_coeffs, 0.f);
bw_gain_set_gain_lin(&coeffs->fb_coeffs, 0.f); bw_gain_set_gain_lin(&coeffs->fb_coeffs, 0.f);
coeffs->delay_ff = 0.f; coeffs->delay_ff = 0.f;