From 767c4f649af8e101d8dbedbb26f040fb65c5a057 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Mon, 20 Feb 2023 13:43:10 +0100 Subject: [PATCH] use bw_ppm in synth_mono + cosmetic changes --- ChangeLog | 2 +- .../synth_mono/src/bw_example_synth_mono.c | 18 +++++++++++------- .../synth_mono/src/bw_example_synth_mono.h | 7 +++---- .../synth_simple/src/bw_example_synth_simple.c | 2 ++ .../synth_simple/src/bw_example_synth_simple.h | 1 - 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 318e098..ce91d13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,10 +23,10 @@ * Adjusted noise levels in synth_mono example. * Added BW_RESTRICT to bw_svf_process1() arguments. * Fixed bad defintion of bw_pink_filt_set_sample_rate_scaling(). + * Now using bw_ppm in synth_mono and synth_simple examples. * Moved header inclusions where most appropriate in bw_env_follow. * Added missing API documentation in bw_pink_filt. * Fixed typo in the documentation of bw_svf_set_Q(). - * Now using bw_ppm in synth_simple example. * Fixed license headers in all source files. 0.2.0 diff --git a/examples/synth_mono/src/bw_example_synth_mono.c b/examples/synth_mono/src/bw_example_synth_mono.c index f918821..2a9ef8a 100644 --- a/examples/synth_mono/src/bw_example_synth_mono.c +++ b/examples/synth_mono/src/bw_example_synth_mono.c @@ -20,6 +20,8 @@ #include "bw_example_synth_mono.h" +#include + void bw_example_synth_mono_init(bw_example_synth_mono *instance) { bw_osc_saw_init(&instance->vco_saw_coeffs); bw_phase_gen_init(&instance->vco1_phase_gen_coeffs); @@ -42,7 +44,7 @@ void bw_example_synth_mono_init(bw_example_synth_mono *instance) { bw_env_gen_init(&instance->vca_env_gen_coeffs); bw_phase_gen_init(&instance->a440_phase_gen_coeffs); bw_gain_init(&instance->gain_coeffs); - bw_env_follow_init(&instance->env_follow_coeffs); + bw_ppm_init(&instance->ppm_coeffs); bw_osc_saw_set_antialiasing(&instance->vco_saw_coeffs, 1); bw_osc_pulse_set_antialiasing(&instance->vco1_pulse_coeffs, 1); @@ -55,7 +57,6 @@ void bw_example_synth_mono_init(bw_example_synth_mono *instance) { bw_gain_set_gain_lin(&instance->vco3_gain_coeffs, 0.f); bw_gain_set_gain_lin(&instance->noise_gain_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); instance->rand_state = 0xbaddecaf600dfeed; } @@ -81,7 +82,7 @@ void bw_example_synth_mono_set_sample_rate(bw_example_synth_mono *instance, floa bw_env_gen_set_sample_rate(&instance->vca_env_gen_coeffs, sample_rate); bw_phase_gen_set_sample_rate(&instance->a440_phase_gen_coeffs, sample_rate); bw_gain_set_sample_rate(&instance->gain_coeffs, sample_rate); - bw_env_follow_set_sample_rate(&instance->env_follow_coeffs, sample_rate); + bw_ppm_set_sample_rate(&instance->ppm_coeffs, sample_rate); } void bw_example_synth_mono_reset(bw_example_synth_mono *instance) { @@ -116,8 +117,8 @@ void bw_example_synth_mono_reset(bw_example_synth_mono *instance) { bw_phase_gen_reset_coeffs(&instance->a440_phase_gen_coeffs); bw_phase_gen_reset_state(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, 0.f); bw_gain_reset_coeffs(&instance->gain_coeffs); - bw_env_follow_reset_coeffs(&instance->env_follow_coeffs); - bw_env_follow_reset_state(&instance->env_follow_coeffs, &instance->env_follow_state); + bw_ppm_reset_coeffs(&instance->ppm_coeffs); + bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_state); instance->note = 60; instance->gate = 0; instance->pitch_bend = 0.f; @@ -241,7 +242,7 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float* bw_buf_mix(out, out, instance->buf[0], n); bw_gain_process(&instance->gain_coeffs, out, out, n); - bw_env_follow_process(&instance->env_follow_coeffs, &instance->env_follow_state, out, NULL, n); + bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n); } } @@ -313,7 +314,10 @@ void bw_example_synth_mono_set_parameter(bw_example_synth_mono *instance, int in } float bw_example_synth_mono_get_parameter(bw_example_synth_mono *instance, int index) { - return index < p_n ? instance->params[index] : bw_clipf(bw_env_follow_get_y_z1(&instance->env_follow_state), 0.f, 1.f); + if (index < p_n) + return instance->params[index]; + const float v = bw_ppm_get_y_z1(&instance->ppm_state); + return v < -200.f ? 0.f : bw_clipf(0.01666666666666666f * v + 1.f, 0.f, 1.f); } static void update_note_gate(bw_example_synth_mono *instance) { diff --git a/examples/synth_mono/src/bw_example_synth_mono.h b/examples/synth_mono/src/bw_example_synth_mono.h index ac54eeb..b443627 100644 --- a/examples/synth_mono/src/bw_example_synth_mono.h +++ b/examples/synth_mono/src/bw_example_synth_mono.h @@ -37,8 +37,7 @@ extern "C" { #include #include #include -#include -#include +#include enum { p_volume, @@ -116,8 +115,8 @@ struct _bw_example_synth_mono { bw_phase_gen_coeffs a440_phase_gen_coeffs; bw_phase_gen_state a440_phase_gen_state; bw_gain_coeffs gain_coeffs; - bw_env_follow_coeffs env_follow_coeffs; - bw_env_follow_state env_follow_state; + bw_ppm_coeffs ppm_coeffs; + bw_ppm_state ppm_state; // Parameters float params[p_n]; diff --git a/examples/synth_simple/src/bw_example_synth_simple.c b/examples/synth_simple/src/bw_example_synth_simple.c index e64c55e..3242a95 100644 --- a/examples/synth_simple/src/bw_example_synth_simple.c +++ b/examples/synth_simple/src/bw_example_synth_simple.c @@ -20,6 +20,8 @@ #include "bw_example_synth_simple.h" +#include + void bw_example_synth_simple_init(bw_example_synth_simple *instance) { bw_phase_gen_init(&instance->phase_gen_coeffs); bw_osc_pulse_init(&instance->osc_pulse_coeffs); diff --git a/examples/synth_simple/src/bw_example_synth_simple.h b/examples/synth_simple/src/bw_example_synth_simple.h index 2e215cd..4701565 100644 --- a/examples/synth_simple/src/bw_example_synth_simple.h +++ b/examples/synth_simple/src/bw_example_synth_simple.h @@ -33,7 +33,6 @@ extern "C" { #include #include #include -#include enum { p_volume,