added in pow10, log10, lin2dB and dB2lin in bw_math
This commit is contained in:
parent
f55a0e53a2
commit
747b6322d4
@ -166,11 +166,11 @@ bw_example_synth_mono bw_example_synth_mono_new() {
|
||||
bw_osc_tri_set_antialiasing(&instance->vco1_tri_coeffs, 1);
|
||||
bw_osc_pulse_set_antialiasing(&instance->vco2_pulse_coeffs, 1);
|
||||
bw_osc_tri_set_antialiasing(&instance->vco2_tri_coeffs, 1);
|
||||
bw_vol_set_volume(&instance->vco2_vol_coeffs, 0.f);
|
||||
bw_vol_set_volume_lin(&instance->vco2_vol_coeffs, 0.f);
|
||||
bw_osc_pulse_set_antialiasing(&instance->vco3_pulse_coeffs, 1);
|
||||
bw_osc_tri_set_antialiasing(&instance->vco3_tri_coeffs, 1);
|
||||
bw_vol_set_volume(&instance->vco3_vol_coeffs, 0.f);
|
||||
bw_vol_set_volume(&instance->noise_vol_coeffs, 0.f);
|
||||
bw_vol_set_volume_lin(&instance->vco3_vol_coeffs, 0.f);
|
||||
bw_vol_set_volume_lin(&instance->noise_vol_coeffs, 0.f);
|
||||
bw_phase_gen_set_frequency(&instance->a440_phase_gen_coeffs, 440.f);
|
||||
bw_env_follow_set_release_tau(&instance->env_follow_coeffs, 1.f);
|
||||
|
||||
@ -377,7 +377,7 @@ void bw_example_synth_mono_set_parameter(bw_example_synth_mono instance, int ind
|
||||
instance->params[index] = value;
|
||||
switch (index) {
|
||||
case p_volume:
|
||||
bw_vol_set_volume(&instance->vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_portamento:
|
||||
bw_phase_gen_set_portamento_tau(&instance->vco1_phase_gen_coeffs, value);
|
||||
@ -389,24 +389,24 @@ void bw_example_synth_mono_set_parameter(bw_example_synth_mono instance, int ind
|
||||
bw_osc_tri_set_slope(&instance->vco1_tri_coeffs, bw_clipf(value, 0.001f, 0.999f));
|
||||
break;
|
||||
case p_vco1_volume:
|
||||
bw_vol_set_volume(&instance->vco1_vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->vco1_vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_vco2_pw_slope:
|
||||
bw_osc_pulse_set_pulse_width(&instance->vco2_pulse_coeffs, value);
|
||||
bw_osc_tri_set_slope(&instance->vco2_tri_coeffs, bw_clipf(value, 0.001f, 0.999f));
|
||||
break;
|
||||
case p_vco2_volume:
|
||||
bw_vol_set_volume(&instance->vco2_vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->vco2_vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_vco3_pw_slope:
|
||||
bw_osc_pulse_set_pulse_width(&instance->vco3_pulse_coeffs, value);
|
||||
bw_osc_tri_set_slope(&instance->vco3_tri_coeffs, bw_clipf(value, 0.001f, 0.999f));
|
||||
break;
|
||||
case p_vco3_volume:
|
||||
bw_vol_set_volume(&instance->vco3_vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->vco3_vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_noise_volume:
|
||||
bw_vol_set_volume(&instance->noise_vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->noise_vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_vcf_Q:
|
||||
bw_svf_set_Q(&instance->vcf_coeffs, 0.5f + 9.5f * value);
|
||||
|
@ -152,7 +152,7 @@ void bw_example_synth_simple_set_parameter(bw_example_synth_simple instance, int
|
||||
instance->params[index] = value;
|
||||
switch (index) {
|
||||
case p_volume:
|
||||
bw_vol_set_volume(&instance->vol_coeffs, value);
|
||||
bw_vol_set_volume_lin(&instance->vol_coeffs, value * value * value);
|
||||
break;
|
||||
case p_portamento:
|
||||
bw_phase_gen_set_portamento_tau(&instance->phase_gen_coeffs, value);
|
||||
|
@ -116,12 +116,14 @@ static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_s
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* #### bw_comp_set_bias()
|
||||
* #### bw_comp_set_...()
|
||||
* ```>>> */
|
||||
static inline void bw_comp_set_thresh(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_thresh_lin(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_thresh_dBFS(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_ratio(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_attack_tau(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_release_tau(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_gain_lin(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_comp_set_gain_dB(bw_comp_coeffs *BW_RESTRICT coeffs, float value);
|
||||
/*! <<<```
|
||||
* Sets the input bias `value` in `coeffs`.
|
||||
@ -219,10 +221,14 @@ static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_s
|
||||
}
|
||||
}
|
||||
|
||||
static inline void bw_comp_set_thresh(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
static inline void bw_comp_set_thresh_lin(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->thresh = value;
|
||||
}
|
||||
|
||||
static inline void bw_comp_set_thresh_dBFS(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->thresh = bw_lin2dBf_3(value);
|
||||
}
|
||||
|
||||
static inline void bw_comp_set_ratio(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->ratio = value;
|
||||
}
|
||||
@ -235,6 +241,10 @@ static inline void bw_comp_set_release_tau(bw_comp_coeffs *BW_RESTRICT coeffs, f
|
||||
bw_env_follow_set_release_tau(&coeffs->env_follow_coeffs, value);
|
||||
}
|
||||
|
||||
static inline void bw_comp_set_gain_lin(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
bw_vol_set_volume_lin(&coeffs->vol_coeffs, value);
|
||||
}
|
||||
|
||||
static inline void bw_comp_set_gain_dB(bw_comp_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
bw_vol_set_volume_dB(&coeffs->vol_coeffs, value);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ utility }}}
|
||||
* version {{{ 0.1.0 }}}
|
||||
* version {{{ 0.3.0 }}}
|
||||
* requires {{{ bw_common bw_config }}}
|
||||
* description {{{
|
||||
* A collection of mathematical routines that strive to be better suited to
|
||||
@ -69,6 +69,18 @@
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>0.3.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added bw_log10f_3(), bw_pow10f_3(), bw_dB2linf_3(), and
|
||||
* bw_lin2dBf_3().</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>0.2.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added bw_sin2pif_3(), bw_cos2pif_3(), bw_tan2pif_3(),
|
||||
* bw_omega_3lognr(), and bw_tanhf_3().</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>0.1.0</strong>:
|
||||
* <ul>
|
||||
* <li>First release.</li>
|
||||
@ -303,6 +315,14 @@ static inline float bw_logf_3(float x);
|
||||
*
|
||||
* Absolute error < 0.0039, relative error < 1.5%.
|
||||
*
|
||||
* #### bw_log10f_3()
|
||||
* ```>>> */
|
||||
static inline float bw_log10f_3(float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the base-10 logarithm of `x`.
|
||||
*
|
||||
* Absolute error < 0.0017, relative error < 1.5%.
|
||||
*
|
||||
* #### bw_pow2f_3()
|
||||
* ```>>> */
|
||||
static inline float bw_pow2f_3(float x);
|
||||
@ -319,6 +339,32 @@ static inline float bw_expf_3(float x);
|
||||
*
|
||||
* Relative error < 0.062%.
|
||||
*
|
||||
* #### bw_pow10f_3()
|
||||
* ```>>> */
|
||||
static inline float bw_pow10f_3(float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 10 raised to the power of `x`.
|
||||
*
|
||||
* Relative error < 0.062%.
|
||||
*
|
||||
* #### bw_dB2linf_3()
|
||||
* ```>>> */
|
||||
static inline float bw_dB2linf_3(float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 10 raised to the power of `x` / 20 (dB to
|
||||
* linear ratio conversion).
|
||||
*
|
||||
* Relative error < 0.062%.
|
||||
*
|
||||
* #### bw_lin2dBf_3()
|
||||
* ```>>> */
|
||||
static inline float bw_lin2dBf_3(float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 20 times the base-10 logarithm of `x` (linear
|
||||
* ratio to dB conversion).
|
||||
*
|
||||
* Absolute error < 0.032, relative error < 1.5%.
|
||||
*
|
||||
* #### bw_omega_3log()
|
||||
* ```>>> */
|
||||
static inline float bw_omega_3log(float x);
|
||||
@ -521,6 +567,10 @@ static inline float bw_logf_3(float x) {
|
||||
return 0.693147180559945f * bw_log2f_3(x);
|
||||
}
|
||||
|
||||
static inline float bw_log10f_3(float x) {
|
||||
return 0.3010299956639811f * bw_log2f_3(x);
|
||||
}
|
||||
|
||||
static inline float bw_pow2f_3(float x) {
|
||||
if (x < -126.f)
|
||||
return 0.f;
|
||||
@ -536,6 +586,18 @@ static inline float bw_expf_3(float x) {
|
||||
return bw_pow2f_3(1.442695040888963f * x);
|
||||
}
|
||||
|
||||
static inline float bw_pow10f_3(float x) {
|
||||
return 3.321928094887363f * bw_pow2f_3(x);
|
||||
}
|
||||
|
||||
static inline float bw_dB2linf_3(float x) {
|
||||
return bw_pow2f_3(0.1660964047443682f * x);
|
||||
}
|
||||
|
||||
static inline float bw_lin2dBf_3(float x) {
|
||||
return 20.f * bw_log10f_3(x);
|
||||
}
|
||||
|
||||
static inline float bw_omega_3log(float x) {
|
||||
static const float x1 = -3.341459552768620f;
|
||||
static const float x2 = 8.f;
|
||||
|
@ -28,7 +28,8 @@
|
||||
* <ul>
|
||||
* <li>Version <strong>0.3.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added bw_vol_set_volume_dB().</li>
|
||||
* <li>Changed volume parameter API to express values in linear gain
|
||||
* and dB.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>0.2.0</strong>:
|
||||
@ -106,19 +107,16 @@ static inline void bw_vol_process(bw_vol_coeffs *BW_RESTRICT coeffs, const float
|
||||
* first `n_samples` of the output buffer `y`, while using and updating
|
||||
* `coeffs` (control and audio rate).
|
||||
*
|
||||
* #### bw_vol_set_volume()
|
||||
* #### bw_vol_set_volume_lin()
|
||||
* ```>>> */
|
||||
static inline void bw_vol_set_volume(bw_vol_coeffs *BW_RESTRICT coeffs, float value);
|
||||
static inline void bw_vol_set_volume_lin(bw_vol_coeffs *BW_RESTRICT coeffs, float value);
|
||||
/*! <<<```
|
||||
* Sets the volume parameter to the given `value` (range [`0.f`, `1.f`]) in
|
||||
* Sets the volume parameter to the given `value` (linear gain) in
|
||||
* `coeffs`.
|
||||
*
|
||||
* This parameter is not linearly mapped, but the range extremes correspond
|
||||
* to silence (gain = `0.f`) and bypass (gain = `1.f`).
|
||||
*
|
||||
* Default value: `1.f`.
|
||||
*
|
||||
* #### bw_vol_set_volume()
|
||||
* #### bw_vol_set_volume_dB()
|
||||
* ```>>> */
|
||||
static inline void bw_vol_set_volume_dB(bw_vol_coeffs *BW_RESTRICT coeffs, float value);
|
||||
/*! <<<```
|
||||
@ -177,12 +175,12 @@ static inline void bw_vol_process(bw_vol_coeffs *BW_RESTRICT coeffs, const float
|
||||
}
|
||||
}
|
||||
|
||||
static inline void bw_vol_set_volume(bw_vol_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->volume = value * value * value;
|
||||
static inline void bw_vol_set_volume_lin(bw_vol_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->volume = value;
|
||||
}
|
||||
|
||||
static inline void bw_vol_set_volume_dB(bw_vol_coeffs *BW_RESTRICT coeffs, float value) {
|
||||
coeffs->volume = bw_pow2f_3(0.1660964047443682f * x);
|
||||
coeffs->volume = bw_dB2linf_3(value);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user