diff --git a/TODO b/TODO
index eb9e7f2..1f0b9d1 100644
--- a/TODO
+++ b/TODO
@@ -47,6 +47,7 @@ code:
* make gain of distortions homogeneous?
* max_delay -> set sample rate? see reverb
* revise typedef style (see https://stackoverflow.com/questions/54752861/using-an-anonymous-struct-vs-a-named-struct-with-typedef)
+* sr-dependent vs cr-dependent coeffs? see synth poly example
build system:
* make makefiles handle paths with spaces etc
diff --git a/examples/synth_mono/src/bw_example_synth_mono.c b/examples/synth_mono/src/bw_example_synth_mono.c
index 675cedc..8e12fe9 100644
--- a/examples/synth_mono/src/bw_example_synth_mono.c
+++ b/examples/synth_mono/src/bw_example_synth_mono.c
@@ -134,9 +134,6 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
(void)x;
- bw_env_gen_set_gate(&instance->vcf_env_gen_coeffs, instance->gate);
- bw_env_gen_set_gate(&instance->vca_env_gen_coeffs, instance->gate);
-
int n = instance->params[p_vco3_kbd] >= 0.5f ? instance->note : 0;
bw_phase_gen_set_frequency(&instance->vco1_phase_gen_coeffs, 440.f *
bw_pow2f_3(6.f * instance->params[p_vco1_coarse] - 3.f
@@ -222,7 +219,7 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_buf_scale(instance->buf[0], instance->buf[0], k, n);
bw_buf_mix(out, out, instance->buf[0], n);
- bw_env_gen_process(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state, NULL, n);
+ bw_env_gen_process(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state, instance->gate, NULL, n);
float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * bw_env_gen_get_y_z1(&instance->vcf_env_gen_state) + vcf_mod;
float cutoff = 20.f + (20e3f - 20.f) * v * v * v;
if (instance->params[p_vcf_kbd_ctrl] >= (1.f / 6.f + 2.f / 3.f))
@@ -235,7 +232,7 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_svf_set_cutoff(&instance->vcf_coeffs, bw_clipf(cutoff, 20.f, 20e3f));
bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n);
- bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->buf[0], n);
+ bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->gate, instance->buf[0], n);
bw_buf_mul(out, out, instance->buf[0], n);
bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n);
diff --git a/examples/synth_poly/daisy-seed/Makefile b/examples/synth_poly/daisy-seed/Makefile
new file mode 100644
index 0000000..625895a
--- /dev/null
+++ b/examples/synth_poly/daisy-seed/Makefile
@@ -0,0 +1,9 @@
+ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+
+TARGET = bw_example_synth_mono
+
+C_SOURCES += ${ROOT_DIR}/../src/bw_example_synth_mono.c
+
+SYNTH := yes
+
+include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk
diff --git a/examples/synth_poly/daisy-seed/config_daisy_seed.h b/examples/synth_poly/daisy-seed/config_daisy_seed.h
new file mode 100644
index 0000000..d363122
--- /dev/null
+++ b/examples/synth_poly/daisy-seed/config_daisy_seed.h
@@ -0,0 +1,72 @@
+/*
+ * Brickworks
+ *
+ * Copyright (C) 2023 Orastron Srl unipersonale
+ *
+ * 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
+ * along with Brickworks. If not, see .
+ *
+ * File authors: Stefano D'Angelo
+ */
+
+#ifndef _CONFIG_DAISY_SEED_H
+#define _CONFIG_DAISY_SEED_H
+
+struct config_cc {
+ int param_index;
+ unsigned char cc;
+};
+
+#define NUM_CCS 38
+
+static struct config_cc config_ccs[NUM_CCS] = {
+ { 0, 7 }, // Volume
+ { 1, 3 }, // Master tune
+ { 2, 5 }, // Portamento
+ { 3, 9 }, // Modulation mix
+ { 4, 14 }, // VCO1 modulation
+ { 5, 15 }, // VCO1 coarse
+ { 6, 20 }, // VCO1 fine
+ { 7, 21 }, // VCO1 waveform
+ { 8, 22 }, // VCO1 pulse width/slope
+ { 9, 23 }, // VCO1 level
+ { 10, 24 }, // VCO2 modulation
+ { 11, 25 }, // VCO2 coarse
+ { 12, 26 }, // VCO2 fine
+ { 13, 27 }, // VCO2 waveform
+ { 14, 28 }, // VCO2 pulse width/slope
+ { 15, 29 }, // VCO2 level
+ { 16, 30 }, // VCO3 keyboard control
+ { 17, 31 }, // VCO3 coarse
+ { 18, 85 }, // VCO3 fine
+ { 19, 86 }, // VCO3 waveform
+ { 20, 87 }, // VCO3 puslse width/slope
+ { 21, 89 }, // VCO3 level
+ { 22, 90 }, // Noise color
+ { 23, 102 }, // Noise level
+ { 24, 103 }, // VCF modulation
+ { 25, 104 }, // VCF keyboard control
+ { 26, 74 }, // VCF cutoff
+ { 27, 71 }, // VCF Q
+ { 28, 105 }, // VCF contour
+ { 29, 106 }, // VCF attack
+ { 30, 107 }, // VCF decay
+ { 31, 108 }, // VCF sustain
+ { 32, 109 }, // VCF release
+ { 33, 73 }, // VCA attack
+ { 34, 110 }, // VCA decay
+ { 35, 111 }, // VCA sustain
+ { 36, 72 }, // VCA release
+ { 37, 112 } // A440
+};
+
+#endif
diff --git a/examples/synth_poly/src/bw_example_synth_poly.c b/examples/synth_poly/src/bw_example_synth_poly.c
new file mode 100644
index 0000000..146723a
--- /dev/null
+++ b/examples/synth_poly/src/bw_example_synth_poly.c
@@ -0,0 +1,385 @@
+/*
+ * Brickworks
+ *
+ * Copyright (C) 2023 Orastron Srl unipersonale
+ *
+ * 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
+ * along with Brickworks. If not, see .
+ *
+ * File author: Stefano D'Angelo
+ */
+
+#include "bw_example_synth_poly.h"
+
+#include
+#include
+#include
+
+void bw_example_synth_poly_init(bw_example_synth_poly *instance) {
+ bw_osc_saw_init(&instance->vco_saw_coeffs);
+ bw_osc_pulse_init(&instance->vco1_pulse_coeffs);
+ bw_osc_tri_init(&instance->vco1_tri_coeffs);
+ bw_gain_init(&instance->vco1_gain_coeffs);
+ bw_osc_pulse_init(&instance->vco2_pulse_coeffs);
+ bw_osc_tri_init(&instance->vco2_tri_coeffs);
+ bw_gain_init(&instance->vco2_gain_coeffs);
+ bw_osc_pulse_init(&instance->vco3_pulse_coeffs);
+ bw_osc_tri_init(&instance->vco3_tri_coeffs);
+ bw_gain_init(&instance->vco3_gain_coeffs);
+ bw_noise_gen_init(&instance->noise_gen_coeffs, &instance->rand_state);
+ bw_pink_filt_init(&instance->pink_filt_coeffs);
+ bw_gain_init(&instance->noise_gain_coeffs);
+ bw_env_gen_init(&instance->vcf_env_gen_coeffs);
+ 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_ppm_init(&instance->ppm_coeffs);
+
+ for (int i = 0; i < N_VOICES; i++) {
+ bw_phase_gen_init(&instance->voices[i].vco1_phase_gen_coeffs);
+ bw_phase_gen_init(&instance->voices[i].vco2_phase_gen_coeffs);
+ bw_phase_gen_init(&instance->voices[i].vco3_phase_gen_coeffs);
+ bw_svf_init(&instance->voices[i].vcf_coeffs);
+ }
+
+ bw_osc_saw_set_antialiasing(&instance->vco_saw_coeffs, 1);
+ bw_osc_pulse_set_antialiasing(&instance->vco1_pulse_coeffs, 1);
+ 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_gain_set_gain_lin(&instance->vco2_gain_coeffs, 0.f);
+ bw_osc_pulse_set_antialiasing(&instance->vco3_pulse_coeffs, 1);
+ bw_osc_tri_set_antialiasing(&instance->vco3_tri_coeffs, 1);
+ 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);
+
+ instance->rand_state = 0xbaddecaf600dfeed;
+}
+
+void bw_example_synth_poly_set_sample_rate(bw_example_synth_poly *instance, float sample_rate) {
+ bw_osc_pulse_set_sample_rate(&instance->vco1_pulse_coeffs, sample_rate);
+ bw_osc_tri_set_sample_rate(&instance->vco1_tri_coeffs, sample_rate);
+ bw_gain_set_sample_rate(&instance->vco1_gain_coeffs, sample_rate);
+ bw_osc_pulse_set_sample_rate(&instance->vco2_pulse_coeffs, sample_rate);
+ bw_osc_tri_set_sample_rate(&instance->vco2_tri_coeffs, sample_rate);
+ bw_gain_set_sample_rate(&instance->vco2_gain_coeffs, sample_rate);
+ bw_osc_pulse_set_sample_rate(&instance->vco3_pulse_coeffs, sample_rate);
+ bw_osc_tri_set_sample_rate(&instance->vco3_tri_coeffs, sample_rate);
+ bw_gain_set_sample_rate(&instance->vco3_gain_coeffs, sample_rate);
+ bw_noise_gen_set_sample_rate(&instance->noise_gen_coeffs, sample_rate);
+ bw_pink_filt_set_sample_rate(&instance->pink_filt_coeffs, sample_rate);
+ bw_gain_set_sample_rate(&instance->noise_gain_coeffs, sample_rate);
+ bw_env_gen_set_sample_rate(&instance->vcf_env_gen_coeffs, sample_rate);
+ 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_ppm_set_sample_rate(&instance->ppm_coeffs, sample_rate);
+
+ for (int i = 0; i < N_VOICES; i++) {
+ bw_phase_gen_set_sample_rate(&instance->voices[i].vco1_phase_gen_coeffs, sample_rate);
+ bw_phase_gen_set_sample_rate(&instance->voices[i].vco2_phase_gen_coeffs, sample_rate);
+ bw_phase_gen_set_sample_rate(&instance->voices[i].vco3_phase_gen_coeffs, sample_rate);
+ bw_svf_set_sample_rate(&instance->voices[i].vcf_coeffs, sample_rate);
+ voices[i].gate = 0;
+ }
+}
+
+void bw_example_synth_poly_reset(bw_example_synth_poly *instance) {
+ const float v = instance->params[p_vcf_cutoff];
+ const float cutoff = 20.f + (20e3f - 20.f) * v * v * v;
+ bw_svf_set_cutoff(&instance->vcf_coeffs, bw_clipf(cutoff, 20.f, 20e3f));
+
+ bw_note_queue_reset(&instance->note_queue);
+ bw_osc_pulse_reset_coeffs(&instance->vco1_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco1_tri_coeffs);
+ bw_gain_reset_coeffs(&instance->vco1_gain_coeffs);
+ bw_phase_gen_reset_coeffs(&instance->vco2_phase_gen_coeffs);
+ bw_osc_pulse_reset_coeffs(&instance->vco2_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco2_tri_coeffs);
+ bw_gain_reset_coeffs(&instance->vco2_gain_coeffs);
+ bw_phase_gen_reset_coeffs(&instance->vco3_phase_gen_coeffs);
+ bw_osc_pulse_reset_coeffs(&instance->vco3_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco3_tri_coeffs);
+ bw_gain_reset_coeffs(&instance->vco3_gain_coeffs);
+ bw_gain_reset_coeffs(&instance->noise_gain_coeffs);
+ bw_env_gen_reset_coeffs(&instance->vcf_env_gen_coeffs);
+ bw_env_gen_reset_state(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state);
+ bw_svf_reset_coeffs(&instance->vcf_coeffs);
+ bw_env_gen_reset_coeffs(&instance->vca_env_gen_coeffs);
+ bw_env_gen_reset_state(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state);
+ 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_ppm_reset_coeffs(&instance->ppm_coeffs);
+ bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_state);
+
+ for (int i = 0; i < N_VOICES; i++) {
+ bw_phase_gen_reset_state(&instance->vco1_phase_gen_coeffs, &instance->voices[i].vco1_phase_gen_state, 0.f);
+ bw_phase_gen_reset_state(&instance->vco2_phase_gen_coeffs, &instance->voices[i].vco2_phase_gen_state, 0.f);
+ bw_phase_gen_reset_state(&instance->vco3_phase_gen_coeffs, &instance->voices[i].vco3_phase_gen_state, 0.f);
+ bw_osc_filt_reset_state(&instance->voices[i].osc_filt_state);
+ bw_pink_filt_reset_state(&instance->pink_filt_coeffs, &instance->voices[i].pink_filt_state);
+ bw_svf_reset_state(&instance->vcf_coeffs, &instance->voices[i].vcf_state, 0.f);
+ }
+
+ instance->pitch_bend = 0.f;
+ instance->mod_wheel = 0.f;
+}
+
+static void note_on(void *BW_RESTRICT voice, unsigned char note, float velocity) {
+ bw_example_synth_poly_voice *v = (bw_example_synth_poly_voice *)voice;
+ v->note = note;
+ v->gate = 1;
+}
+
+static void note_off(void *BW_RESTRICT voice, float velocity) {
+ bw_example_synth_poly_voice *v = (bw_example_synth_poly_voice *)voice;
+ v->gate = 0;
+}
+
+static unsigned char get_note(void *BW_RESTRICT voice) {
+ bw_example_synth_poly_voice *v = (bw_example_synth_poly_voice *)voice;
+ return v->note;
+}
+
+static char is_free(void *BW_RESTRICT voice) {
+ bw_example_synth_poly_voice *v = (bw_example_synth_poly_voice *)voice;
+ bw_env_gen_phase phase = bw_env_gen_get_phase(&v->vca_env_gen_state);
+ return !v->gate && phase == bw_env_gen_phase_off;
+}
+
+
+void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float** x, float** y, int n_samples) {
+ // FIXME: control-rate modulations are asynchronous here...
+ // it's all good as long as hosts gives us buffers whose length is a multiple of 32,
+ // otherwise it's probably still ok but a bit "swingy"
+
+ (void)x;
+
+ static bw_voice_alloc_opts alloc_opts = { bw_voice_alloc_mode_low, note_on, note_off, get_note, is_free };
+ bw_voice_alloc(&alloc_opts, &instance->note_queue, &instance->voices, N_VOICES);
+ bw_note_queue_clear(&instance->note_queue);
+
+ const float f1 =
+ 6.f * instance->params[p_vco1_coarse] - 3.f
+ + 2.f * instance->pitch_bend - 1.f
+ + 8.333333333333333e-2f * (2.f * (instance->params[p_master_tune] + instance->params[p_vco1_fine]) - 71.f);
+ const float f2 =
+ 6.f * instance->params[p_vco2_coarse] - 3.f
+ + 2.f * instance->pitch_bend - 1.f
+ + 8.333333333333333e-2f * (2.f * (instance->params[p_master_tune] + instance->params[p_vco2_fine]) - 71.f);
+ const float f3 =
+ 6.f * instance->params[p_vco3_coarse] - 3.f
+ + 2.f * instance->pitch_bend - 1.f
+ + 8.333333333333333e-2f * (2.f * (instance->params[p_master_tune] + instance->params[p_vco3_fine]) - 71.f);
+ for (int i = 0; i < N_VOICES; i++) {
+ int n = instance->params[p_vco3_kbd] >= 0.5f ? instance->voices[i].note : 0;
+ bw_phase_gen_set_frequency(&instance->voices[i].vco1_phase_gen_coeffs, 440.f * bw_pow2f_3(f1 + 8.333333333333333e-2f * instance->voices[i].note));
+ bw_phase_gen_set_frequency(&instance->voices[i].vco2_phase_gen_coeffs, 440.f * bw_pow2f_3(f2 + 8.333333333333333e-2f * instance->voices[i].note));
+ bw_phase_gen_set_frequency(&instance->voices[i].vco3_phase_gen_coeffs, 440.f * bw_pow2f_3(f2 + 8.333333333333333e-2f * n));
+ }
+
+ //...
+
+ for (int i = 0; i < n_samples; i += BUFFER_SIZE) {
+ float *out = y[0] + i;
+ int n = bw_minf(n_samples - i, BUFFER_SIZE);
+
+ bw_phase_gen_process(&instance->vco3_phase_gen_coeffs, &instance->vco3_phase_gen_state, NULL, out, instance->buf[0], n);
+ if (instance->params[p_vco3_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
+ bw_osc_tri_process(&instance->vco3_tri_coeffs, out, instance->buf[0], out, n);
+ bw_osc_pulse_reset_coeffs(&instance->vco3_pulse_coeffs);
+ } else if (instance->params[p_vco3_waveform] >= (1.f / 4.f)) {
+ bw_osc_pulse_process(&instance->vco3_pulse_coeffs, out, instance->buf[0], out, n);
+ bw_osc_tri_reset_coeffs(&instance->vco3_tri_coeffs);
+ } else {
+ bw_osc_saw_process(&instance->vco_saw_coeffs, out, instance->buf[0], out, n);
+ bw_osc_pulse_reset_coeffs(&instance->vco3_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco3_tri_coeffs);
+ }
+
+ bw_noise_gen_process(&instance->noise_gen_coeffs, instance->buf[0], n);
+ if (instance->params[p_noise_color] >= 0.5f)
+ bw_pink_filt_process(&instance->pink_filt_coeffs, &instance->pink_filt_state, instance->buf[0], instance->buf[0], n);
+ else
+ bw_pink_filt_reset_state(&instance->pink_filt_coeffs, &instance->pink_filt_state); // FIXME: calling this here is sloppy coding
+ bw_buf_scale(instance->buf[0], instance->buf[0], 5.f, n);
+
+ for (int j = 0; j < n; j++)
+ instance->buf[1][j] = instance->mod_wheel * (out[j] + instance->params[p_mod_mix] * (instance->buf[0][j] - out[j]));
+ const float vcf_mod = 0.3f * instance->params[p_vcf_mod] * instance->buf[1][0];
+
+ bw_buf_scale(instance->buf[2], instance->buf[1], instance->params[p_vco1_mod], n);
+ bw_phase_gen_process(&instance->vco1_phase_gen_coeffs, &instance->vco1_phase_gen_state, instance->buf[2], instance->buf[2], instance->buf[3], n);
+ if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
+ bw_osc_tri_process(&instance->vco1_tri_coeffs, instance->buf[2], instance->buf[3], instance->buf[2], n);
+ bw_osc_pulse_reset_coeffs(&instance->vco1_pulse_coeffs);
+ } else if (instance->params[p_vco1_waveform] >= (1.f / 4.f)) {
+ bw_osc_pulse_process(&instance->vco1_pulse_coeffs, instance->buf[2], instance->buf[3], instance->buf[2], n);
+ bw_osc_tri_reset_coeffs(&instance->vco1_tri_coeffs);
+ } else {
+ bw_osc_saw_process(&instance->vco_saw_coeffs, instance->buf[2], instance->buf[3], instance->buf[2], n);
+ bw_osc_pulse_reset_coeffs(&instance->vco1_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco1_tri_coeffs);
+ }
+
+ bw_buf_scale(instance->buf[1], instance->buf[1], instance->params[p_vco2_mod], n);
+ bw_phase_gen_process(&instance->vco2_phase_gen_coeffs, &instance->vco2_phase_gen_state, instance->buf[1], instance->buf[1], instance->buf[3], n);
+ if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
+ bw_osc_tri_process(&instance->vco2_tri_coeffs, instance->buf[1], instance->buf[3], instance->buf[1], n);
+ bw_osc_pulse_reset_coeffs(&instance->vco2_pulse_coeffs);
+ } else if (instance->params[p_vco2_waveform] >= (1.f / 4.f)) {
+ bw_osc_pulse_process(&instance->vco2_pulse_coeffs, instance->buf[1], instance->buf[3], instance->buf[1], n);
+ bw_osc_tri_reset_coeffs(&instance->vco2_tri_coeffs);
+ } else {
+ bw_osc_saw_process(&instance->vco_saw_coeffs, instance->buf[1], instance->buf[3], instance->buf[1], n);
+ bw_osc_pulse_reset_coeffs(&instance->vco2_pulse_coeffs);
+ bw_osc_tri_reset_coeffs(&instance->vco2_tri_coeffs);
+ }
+
+ bw_gain_process(&instance->vco1_gain_coeffs, instance->buf[2], instance->buf[2], n);
+ bw_gain_process(&instance->vco2_gain_coeffs, instance->buf[1], instance->buf[1], n);
+ bw_gain_process(&instance->vco3_gain_coeffs, out, out, n);
+ bw_gain_process(&instance->noise_gain_coeffs, instance->buf[0], instance->buf[0], n);
+ bw_buf_mix(out, out, instance->buf[1], n);
+ bw_buf_mix(out, out, instance->buf[2], n);
+
+ bw_osc_filt_process(&instance->osc_filt_state, out, out, n);
+
+ const float k = instance->params[p_noise_color] >= 0.5f
+ ? 6.f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs) * bw_pink_filt_get_scaling_k(&instance->pink_filt_coeffs)
+ : 0.1f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs);
+ bw_buf_scale(instance->buf[0], instance->buf[0], k, n);
+ bw_buf_mix(out, out, instance->buf[0], n);
+
+ bw_env_gen_process(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state, NULL, n);
+ float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * bw_env_gen_get_y_z1(&instance->vcf_env_gen_state) + vcf_mod;
+ float cutoff = 20.f + (20e3f - 20.f) * v * v * v;
+ if (instance->params[p_vcf_kbd_ctrl] >= (1.f / 6.f + 2.f / 3.f))
+ cutoff *= bw_pow2f_3(8.333333333333333e-2f * (instance->note - 60));
+ else if (instance->params[p_vcf_kbd_ctrl] >= (1.f / 6.f + 1.f / 3.f))
+ cutoff *= bw_pow2f_3((0.793700525984100f * 8.333333333333333e-2f) * (instance->note - 60));
+ else if (instance->params[p_vcf_kbd_ctrl] >= (1.f / 6.f + 2.f / 3.f))
+ cutoff *= bw_pow2f_3((0.629960524947437f * 8.333333333333333e-2f) * (instance->note - 60));
+ // otherwise no kbd control
+ bw_svf_set_cutoff(&instance->vcf_coeffs, bw_clipf(cutoff, 20.f, 20e3f));
+ bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n);
+
+ bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->buf[0], n);
+ bw_buf_mul(out, out, instance->buf[0], n);
+
+ bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n);
+ bw_osc_sin_process(instance->buf[0], instance->buf[0], n);
+ if (instance->params[p_a440] >= 0.5f)
+ bw_buf_mix(out, out, instance->buf[0], n);
+
+ bw_gain_process(&instance->gain_coeffs, out, out, n);
+ bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n);
+ }
+}
+
+void bw_example_synth_poly_set_parameter(bw_example_synth_poly *instance, int index, float value) {
+ if (instance->params[index] == value)
+ return;
+ instance->params[index] = value;
+ switch (index) {
+ case p_volume:
+ bw_gain_set_gain_lin(&instance->gain_coeffs, value * value * value);
+ break;
+ case p_portamento:
+ for (int i = 0; i < N_VOICES; i++) {
+ bw_phase_gen_set_portamento_tau(&instance->voices[i].vco1_phase_gen_coeffs, value);
+ bw_phase_gen_set_portamento_tau(&instance->voices[i].vco2_phase_gen_coeffs, value);
+ bw_phase_gen_set_portamento_tau(&instance->voices[i].vco3_phase_gen_coeffs, value);
+ }
+ break;
+ case p_vco1_pw_slope:
+ bw_osc_pulse_set_pulse_width(&instance->vco1_pulse_coeffs, value);
+ bw_osc_tri_set_slope(&instance->vco1_tri_coeffs, bw_clipf(value, 0.001f, 0.999f));
+ break;
+ case p_vco1_level:
+ bw_gain_set_gain_lin(&instance->vco1_gain_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_level:
+ bw_gain_set_gain_lin(&instance->vco2_gain_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_level:
+ bw_gain_set_gain_lin(&instance->vco3_gain_coeffs, value * value * value);
+ break;
+ case p_noise_level:
+ bw_gain_set_gain_lin(&instance->noise_gain_coeffs, value * value * value);
+ break;
+ case p_vcf_Q:
+ {
+ const float v = 0.5f + 9.5f * value;
+ for (int i = 0; i < N_VOICES; i++)
+ bw_svf_set_Q(&instance->voices[i].vcf_coeffs, v);
+ }
+ break;
+ case p_vcf_attack:
+ bw_env_gen_set_attack(&instance->vcf_env_gen_coeffs, value);
+ break;
+ case p_vcf_decay:
+ bw_env_gen_set_decay(&instance->vcf_env_gen_coeffs, value);
+ break;
+ case p_vcf_sustain:
+ bw_env_gen_set_sustain(&instance->vcf_env_gen_coeffs, value);
+ break;
+ case p_vcf_release:
+ bw_env_gen_set_release(&instance->vcf_env_gen_coeffs, value);
+ break;
+ case p_vca_attack:
+ bw_env_gen_set_attack(&instance->vca_env_gen_coeffs, value);
+ break;
+ case p_vca_decay:
+ bw_env_gen_set_decay(&instance->vca_env_gen_coeffs, value);
+ break;
+ case p_vca_sustain:
+ bw_env_gen_set_sustain(&instance->vca_env_gen_coeffs, value);
+ break;
+ case p_vca_release:
+ bw_env_gen_set_release(&instance->vca_env_gen_coeffs, value);
+ break;
+ }
+}
+
+float bw_example_synth_poly_get_parameter(bw_example_synth_poly *instance, int index) {
+ 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);
+}
+
+void bw_example_synth_poly_note_on(bw_example_synth_poly *instance, char note, char velocity) {
+ bw_note_queue_add(&instance->note_queue, note, velocity != 0, velocity, 0);
+}
+
+void bw_example_synth_poly_note_off(bw_example_synth_poly *instance, char note) {
+ bw_note_queue_add(&instance->note_queue, note, 0, 0, 0);
+}
+
+void bw_example_synth_poly_pitch_bend(bw_example_synth_poly *instance, int value) {
+ instance->pitch_bend = (value - 0x2000) / (float)0x4000;
+}
+
+void bw_example_synth_poly_mod_wheel(bw_example_synth_poly *instance, char value) {
+ instance->mod_wheel = (float)value / 0x80;
+}
diff --git a/examples/synth_poly/src/bw_example_synth_poly.h b/examples/synth_poly/src/bw_example_synth_poly.h
new file mode 100644
index 0000000..575e805
--- /dev/null
+++ b/examples/synth_poly/src/bw_example_synth_poly.h
@@ -0,0 +1,160 @@
+/*
+ * Brickworks
+ *
+ * Copyright (C) 2023 Orastron Srl unipersonale
+ *
+ * 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
+ * along with Brickworks. If not, see .
+ *
+ * File author: Stefano D'Angelo
+ */
+
+#ifndef _BW_EXAMPLE_SYNTH_POLY_H
+#define _BW_EXAMPLE_SYNTH_POLY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+enum {
+ p_volume,
+ p_master_tune,
+ p_portamento,
+ p_mod_mix,
+ p_vco1_mod,
+ p_vco1_coarse,
+ p_vco1_fine,
+ p_vco1_waveform,
+ p_vco1_pw_slope,
+ p_vco1_level,
+ p_vco2_mod,
+ p_vco2_coarse,
+ p_vco2_fine,
+ p_vco2_waveform,
+ p_vco2_pw_slope,
+ p_vco2_level,
+ p_vco3_kbd,
+ p_vco3_coarse,
+ p_vco3_fine,
+ p_vco3_waveform,
+ p_vco3_pw_slope,
+ p_vco3_level,
+ p_noise_color,
+ p_noise_level,
+ p_vcf_mod,
+ p_vcf_kbd_ctrl,
+ p_vcf_cutoff,
+ p_vcf_Q,
+ p_vcf_contour,
+ p_vcf_attack,
+ p_vcf_decay,
+ p_vcf_sustain,
+ p_vcf_release,
+ p_vca_attack,
+ p_vca_decay,
+ p_vca_sustain,
+ p_vca_release,
+ p_a440,
+ p_n
+};
+
+#define BUFFER_SIZE 32
+#define N_VOICES 8
+
+struct _bw_example_synth_poly_voice {
+ bw_phase_gen_coeffs vco1_phase_gen_coeffs;
+ bw_phase_gen_coeffs vco2_phase_gen_coeffs;
+ bw_phase_gen_coeffs vco3_phase_gen_coeffs;
+ bw_svf_coeffs vcf_coeffs;
+
+ bw_phase_gen_state vco1_phase_gen_state;
+ bw_phase_gen_state vco2_phase_gen_state;
+ bw_phase_gen_state vco3_phase_gen_state;
+ bw_osc_filt_state osc_filt_state;
+ bw_pink_filt_state pink_filt_state;
+ bw_env_gen_state vcf_env_gen_state;
+ bw_svf_state vcf_state;
+ bw_env_gen_state vca_env_gen_state;
+
+ unsigned char note;
+ char gate;
+};
+typedef struct _bw_example_synth_poly_voice bw_example_synth_poly_voice;
+
+struct _bw_example_synth_poly {
+ // Sub-components
+ bw_note_queue note_queue;
+ bw_osc_saw_coeffs vco_saw_coeffs;
+ bw_osc_pulse_coeffs vco1_pulse_coeffs;
+ bw_osc_tri_coeffs vco1_tri_coeffs;
+ bw_gain_coeffs vco1_gain_coeffs;
+ bw_osc_pulse_coeffs vco2_pulse_coeffs;
+ bw_osc_tri_coeffs vco2_tri_coeffs;
+ bw_gain_coeffs vco2_gain_coeffs;
+ bw_osc_pulse_coeffs vco3_pulse_coeffs;
+ bw_osc_tri_coeffs vco3_tri_coeffs;
+ bw_gain_coeffs vco3_gain_coeffs;
+ bw_noise_gen_coeffs noise_gen_coeffs;
+ bw_pink_filt_coeffs pink_filt_coeffs;
+ bw_gain_coeffs noise_gain_coeffs;
+ bw_env_gen_coeffs vcf_env_gen_coeffs;
+ bw_env_gen_coeffs vca_env_gen_coeffs;
+ bw_phase_gen_coeffs a440_phase_gen_coeffs;
+ bw_phase_gen_state a440_phase_gen_state;
+ bw_gain_coeffs gain_coeffs;
+ bw_ppm_coeffs ppm_coeffs;
+ bw_ppm_state ppm_state;
+
+ bw_example_poly_synth_voice voices[N_VOICES];
+
+ // Parameters
+ float params[p_n];
+
+ // States
+ uint64_t rand_state;
+ float pitch_bend;
+ float mod_wheel;
+
+ // Buffers
+ float buf[4][BUFFER_SIZE];
+};
+typedef struct _bw_example_synth_poly bw_example_synth_poly;
+
+void bw_example_synth_poly_init(bw_example_synth_poly *instance);
+void bw_example_synth_poly_set_sample_rate(bw_example_synth_poly *instance, float sample_rate);
+void bw_example_synth_poly_reset(bw_example_synth_poly *instance);
+void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float** x, float** y, int n_samples);
+void bw_example_synth_poly_set_parameter(bw_example_synth_poly *instance, int index, float value);
+float bw_example_synth_poly_get_parameter(bw_example_synth_poly *instance, int index);
+void bw_example_synth_poly_note_on(bw_example_synth_poly *instance, char note, char velocity);
+void bw_example_synth_poly_note_off(bw_example_synth_poly *instance, char note);
+void bw_example_synth_poly_pitch_bend(bw_example_synth_poly *instance, int value);
+void bw_example_synth_poly_mod_wheel(bw_example_synth_poly *instance, char value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/examples/synth_poly/src/config.h b/examples/synth_poly/src/config.h
new file mode 100644
index 0000000..e215159
--- /dev/null
+++ b/examples/synth_poly/src/config.h
@@ -0,0 +1,125 @@
+/*
+ * Brickworks
+ *
+ * Copyright (C) 2023 Orastron Srl unipersonale
+ *
+ * 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
+ * along with Brickworks. If not, see .
+ *
+ * File authors: Stefano D'Angelo
+ */
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+
+// Definitions
+
+#define IO_MONO 1
+#define IO_STEREO (1<<1)
+
+struct config_io_bus {
+ const char *name;
+ char out;
+ char aux;
+ char cv;
+ char configs;
+};
+
+struct config_parameter {
+ const char *name;
+ const char *shortName;
+ const char *units;
+ char out;
+ char bypass;
+ int steps;
+ float defaultValueUnmapped;
+};
+
+// Data
+
+#define COMPANY_NAME "Orastron"
+#define COMPANY_WEBSITE "https://www.orastron.com/"
+#define COMPANY_MAILTO "mailto:info@orastron.com"
+
+#define PLUGIN_NAME "bw_example_synth_poly"
+#define PLUGIN_VERSION "0.5.0"
+
+#define NUM_BUSES_IN 0
+#define NUM_BUSES_OUT 1
+#define NUM_CHANNELS_IN 0
+#define NUM_CHANNELS_OUT 1
+
+static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = {
+ { "Audio out", 1, 0, 0, IO_MONO }
+};
+
+#define NUM_PARAMETERS 39
+
+static struct config_parameter config_parameters[NUM_PARAMETERS] = {
+ { "Volume", "Volume", "", 0, 0, 0, 0.5f },
+ { "Master tune", "Master tune", "st", 0, 0, 0, 0.5f },
+ { "Portamento", "Portamento", "s", 0, 0, 0, 0.f },
+ { "Modulation mix", "Mod mix", "%", 0, 0, 0, 0.f },
+ { "VCO1 modulation", "VCO1 mod", "%", 0, 0, 0, 0.f },
+ { "VCO1 coarse", "VCO1 coarse", "", 0, 0, 6, 0.5f },
+ { "VCO1 fine", "VCO1 fine", "st", 0, 0, 0, 0.5f },
+ { "VCO1 waveform", "VCO1 wave", "", 0, 0, 2, 0.f },
+ { "VCO1 pulse width/slope", "VCO1 pw/slope", "%", 0, 0, 0, 0.5f },
+ { "VCO1 level", "VCO1 level", "%", 0, 0, 0, 1.f },
+ { "VCO2 modulation", "VCO2 mod", "%", 0, 0, 0, 0.f },
+ { "VCO2 coarse", "VCO2 coarse", "", 0, 0, 6, 0.5f },
+ { "VCO2 fine", "VCO2 fine", "st", 0, 0, 0, 0.5f },
+ { "VCO2 waveform", "VCO2 wave", "", 0, 0, 2, 0.f },
+ { "VCO2 pulse width/slope", "VCO2 pw/slope", "%", 0, 0, 0, 0.5f },
+ { "VCO2 level", "VCO2 level", "%", 0, 0, 0, 0.f },
+ { "VCO3 kyboard control", "VCO3 kbd ctrl", "", 0, 0, 1, 1.f },
+ { "VCO3 coarse", "VCO3 coarse", "", 0, 0, 6, 0.5f },
+ { "VCO3 fine", "VCO3 fine", "st", 0, 0, 0, 0.5f },
+ { "VCO3 waveform", "VCO3 wave", "", 0, 0, 2, 0.f },
+ { "VCO3 pulse width/slope", "VCO3 pw/slope", "%", 0, 0, 0, 0.5f },
+ { "VCO3 level", "VCO3 level", "%", 0, 0, 0, 0.f },
+ { "Noise color", "Noise color", "", 0, 0, 1, 0.f },
+ { "Noise level", "Noise level", "%", 0, 0, 0, 0.f },
+ { "VCF modulation", "VCF mod", "%", 0, 0, 0, 0.f },
+ { "VCF keyboard control", "VCF kbd ctrl", "", 0, 0, 3, 0.f },
+ { "VCF cutoff", "VCF cutoff", "Hz", 0, 0, 0, 1.f },
+ { "VCF Q", "VCF Q", "", 0, 0, 0, 0.f },
+ { "VCF contour", "VCF contour", "%", 0, 0, 0, 0.f },
+ { "VCF attack", "VCF attack", "s", 0, 0, 0, 0.f },
+ { "VCF decay", "VCF decay", "s", 0, 0, 0, 0.f },
+ { "VCF sustain", "VCF sustain", "%", 0, 0, 0, 1.f },
+ { "VCF release", "VCF release", "s", 0, 0, 0, 0.f },
+ { "VCA attack", "VCA attack", "s", 0, 0, 0, 0.f },
+ { "VCA decay", "VCA decay", "s", 0, 0, 0, 0.f },
+ { "VCA sustain", "VCA sustain", "%", 0, 0, 0, 1.f },
+ { "VCA release", "VCA release", "s", 0, 0, 0, 0.f },
+ { "A440", "A440", "", 0, 0, 1, 0.f },
+ { "Level", "Level", "", 1, 0, 0, 0.f }
+};
+
+// Internal API
+
+#include "bw_example_synth_poly.h"
+
+#define P_TYPE bw_example_synth_poly
+#define P_INIT bw_example_synth_poly_init
+#define P_SET_SAMPLE_RATE bw_example_synth_poly_set_sample_rate
+#define P_RESET bw_example_synth_poly_reset
+#define P_PROCESS bw_example_synth_poly_process
+#define P_SET_PARAMETER bw_example_synth_poly_set_parameter
+#define P_GET_PARAMETER bw_example_synth_poly_get_parameter
+#define P_NOTE_ON bw_example_synth_poly_note_on
+#define P_NOTE_OFF bw_example_synth_poly_note_off
+#define P_PITCH_BEND bw_example_synth_poly_pitch_bend
+#define P_MOD_WHEEL bw_example_synth_poly_mod_wheel
+
+#endif
diff --git a/examples/synth_poly/vst3/Makefile b/examples/synth_poly/vst3/Makefile
new file mode 100644
index 0000000..4296ac9
--- /dev/null
+++ b/examples/synth_poly/vst3/Makefile
@@ -0,0 +1,6 @@
+ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+
+NAME := bw_example_synth_mono
+SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_synth_mono.c
+
+include ${ROOT_DIR}/../../common/vst3/vst3.mk
diff --git a/include/bw_voice.h b/examples/synth_poly/vst3/config_vst3.h
similarity index 57%
rename from include/bw_voice.h
rename to examples/synth_poly/vst3/config_vst3.h
index d12a386..d823458 100644
--- a/include/bw_voice.h
+++ b/examples/synth_poly/vst3/config_vst3.h
@@ -1,7 +1,7 @@
/*
* Brickworks
*
- * Copyright (C) 2023 Orastron Srl unipersonale
+ * Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,9 +15,22 @@
* You should have received a copy of the GNU General Public License
* along with Brickworks. If not, see .
*
- * File author: Stefano D'Angelo
+ * File authors: Stefano D'Angelo, Paolo Marrone
*/
-struct _bw_voice {
-};
-typedef struct _bw_voice bw_voice;
+#ifndef _VST3_CONFIG_H
+#define _VST3_CONFIG_H
+
+#define PLUGIN_SUBCATEGORY "Instrument|Synth"
+
+#define PLUGIN_GUID_1 0x5af9b172
+#define PLUGIN_GUID_2 0x95ef439c
+#define PLUGIN_GUID_3 0xb10ed6f0
+#define PLUGIN_GUID_4 0xb962eef1
+
+#define CTRL_GUID_1 0xed4990b0
+#define CTRL_GUID_2 0x89894215
+#define CTRL_GUID_3 0x96fc7cda
+#define CTRL_GUID_4 0x5a56cec9
+
+#endif
diff --git a/examples/synth_poly/web/Makefile b/examples/synth_poly/web/Makefile
new file mode 100644
index 0000000..e6d2e53
--- /dev/null
+++ b/examples/synth_poly/web/Makefile
@@ -0,0 +1,6 @@
+ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_synth_mono.c
+SYNTH := yes
+NEEDS_MEMSET := yes
+
+include ${ROOT_DIR}/../../common/web/web.mk
diff --git a/examples/synth_poly/web/config.js b/examples/synth_poly/web/config.js
new file mode 100644
index 0000000..cf29faa
--- /dev/null
+++ b/examples/synth_poly/web/config.js
@@ -0,0 +1,234 @@
+/*
+ * Brickworks
+ *
+ * Copyright (C) 2022 Orastron Srl unipersonale
+ *
+ * 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
+ * along with Brickworks. If not, see .
+ *
+ * File author: Stefano D'Angelo
+ */
+
+var buses = [
+ {
+ stereo: false,
+ output: true
+ }
+];
+
+var parameters = [
+ {
+ name: "Volume",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "Master tune",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "Portamento",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "Modulation mix",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCO1 modulation",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCO1 coarse",
+ output: false,
+ defaultValue: 0.5,
+ step: 6
+ },
+ {
+ name: "VCO1 fine",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO1 waveform",
+ output: false,
+ defaultValue: 0.5,
+ step: 2
+ },
+ {
+ name: "VCO1 pulse width/slope",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO1 level",
+ output: false,
+ defaultValue: 1.0
+ },
+ {
+ name: "VCO2 modulation",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCO2 coarse",
+ output: false,
+ defaultValue: 0.5,
+ step: 6
+ },
+ {
+ name: "VCO2 fine",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO2 waveform",
+ output: false,
+ defaultValue: 0.5,
+ step: 2
+ },
+ {
+ name: "VCO2 pulse width/slope",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO2 level",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCO3 keyboard control",
+ output: false,
+ defaultValue: 1.0,
+ step: 1
+ },
+ {
+ name: "VCO3 coarse",
+ output: false,
+ defaultValue: 0.5,
+ step: 6
+ },
+ {
+ name: "VCO3 fine",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO3 waveform",
+ output: false,
+ defaultValue: 0.5,
+ step: 2
+ },
+ {
+ name: "VCO3 pulse width/slope",
+ output: false,
+ defaultValue: 0.5
+ },
+ {
+ name: "VCO3 level",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "Noise color",
+ output: false,
+ defaultValue: 0.0,
+ step: 1
+ },
+ {
+ name: "Noise level",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF modulation",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF keyboard control",
+ output: false,
+ defaultValue: 0.0,
+ step: 3
+ },
+ {
+ name: "VCF cutoff",
+ output: false,
+ defaultValue: 1.0
+ },
+ {
+ name: "VCF Q",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF contour",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF attack",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF decay",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCF sustain",
+ output: false,
+ defaultValue: 1.0
+ },
+ {
+ name: "VCF release",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCA attack",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCA decay",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "VCA sustain",
+ output: false,
+ defaultValue: 1.0
+ },
+ {
+ name: "VCA release",
+ output: false,
+ defaultValue: 0.0
+ },
+ {
+ name: "A440",
+ output: false,
+ defaultValue: 0.0,
+ step: 1
+ },
+ {
+ name: "Level",
+ output: true,
+ defaultValue: 0.0
+ }
+];
diff --git a/examples/synth_simple/src/bw_example_synth_simple.c b/examples/synth_simple/src/bw_example_synth_simple.c
index ebad610..b91daad 100644
--- a/examples/synth_simple/src/bw_example_synth_simple.c
+++ b/examples/synth_simple/src/bw_example_synth_simple.c
@@ -62,8 +62,6 @@ void bw_example_synth_simple_reset(bw_example_synth_simple *instance) {
void bw_example_synth_simple_process(bw_example_synth_simple *instance, const float** x, float** y, int n_samples) {
(void)x;
- char gate = instance->note >= 0 ? 1 : 0;
- bw_env_gen_set_gate(&instance->env_gen_coeffs, gate);
if (instance->note >= 0)
bw_phase_gen_set_frequency(&instance->phase_gen_coeffs,
440.f * bw_pow2f_3(8.333333333333333e-2f * ((instance->note - 69) + 2.f * instance->params[p_master_tune] - 1.f)));
@@ -76,7 +74,7 @@ void bw_example_synth_simple_process(bw_example_synth_simple *instance, const fl
bw_osc_pulse_process(&instance->osc_pulse_coeffs, out, instance->buf, out, n);
bw_osc_filt_process(&instance->osc_filt_state, out, out, n);
bw_svf_process(&instance->svf_coeffs, &instance->svf_state, out, out, NULL, NULL, n);
- bw_env_gen_process(&instance->env_gen_coeffs, &instance->env_gen_state, instance->buf, n);
+ bw_env_gen_process(&instance->env_gen_coeffs, &instance->env_gen_state, instance->note >= 0, instance->buf, n);
bw_buf_mul(out, out, instance->buf, n);
bw_gain_process(&instance->gain_coeffs, out, out, n);
bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n);
diff --git a/include/bw_env_gen.h b/include/bw_env_gen.h
index ab1f8c6..89aa980 100644
--- a/include/bw_env_gen.h
+++ b/include/bw_env_gen.h
@@ -20,7 +20,7 @@
/*!
* module_type {{{ dsp }}}
- * version {{{ 0.4.0 }}}
+ * version {{{ 0.5.0 }}}
* requires {{{ bw_common bw_config bw_math bw_one_pole }}}
* description {{{
* Linear ADSR envelope generator.
@@ -40,6 +40,14 @@
* }}}
* changelog {{{
*
+ * - Version 0.5.0:
+ *
+ * - Added
gate
argument to
+ * bw_env_gen_update_state_ctrl()
and
+ * bw_env_gen_process()
, and removed gate
+ * parameter.
+ *
+ *
* - Version 0.4.0:
*
* - Fixed unused parameter warnings.
@@ -142,9 +150,10 @@ static inline void bw_env_gen_update_coeffs_audio(bw_env_gen_coeffs *BW_RESTRICT
*
* #### bw_env_gen_update_state_ctrl()
* ```>>> */
-static inline void bw_env_gen_update_state_ctrl(const bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state);
+static inline void bw_env_gen_update_state_ctrl(const bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate);
/*! <<<```
- * Triggers control-rate update of the internal `state` using `coeffs`.
+ * Triggers control-rate update of the internal `state` using `coeffs` and
+ * the given `gate` value (`0` for off, non-`0` for on).
*
* #### bw_env_gen_process1()
* ```>>> */
@@ -155,21 +164,14 @@ static inline float bw_env_gen_process1(const bw_env_gen_coeffs *BW_RESTRICT coe
*
* #### bw_env_gen_process()
* ```>>> */
-static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, float* y, int n_samples);
+static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float* y, int n_samples);
/*! <<<```
- * Generates and fills the first `n_samples` of the output buffer `y`, while
- * using and updating both `coeffs` and `state` (control and audio rate).
+ * Generates and fills the first `n_samples` of the output buffer `y` using
+ * the given `gate` value (`0` for off, non-`0` for on), while using and
+ * updating both `coeffs` and `state` (control and audio rate).
*
* `y` may be `NULL`.
*
- * #### bw_env_gen_set_gate()
- * ```>>> */
-static inline void bw_env_gen_set_gate(bw_env_gen_coeffs *BW_RESTRICT coeffs, char value);
-/*! <<<```
- * Sets the input gate to be either off (`0`) or on (non-`0`) in `coeffs`.
- *
- * Default value: `0` (off).
- *
* #### bw_env_gen_set_attack()
* ```>>> */
static inline void bw_env_gen_set_attack(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value);
@@ -241,7 +243,6 @@ struct _bw_env_gen_coeffs {
float release_inc;
// Parameters
- char gate;
float attack;
float decay;
float sustain;
@@ -263,7 +264,6 @@ struct _bw_env_gen_state {
static inline void bw_env_gen_init(bw_env_gen_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_init(&coeffs->smooth_coeffs);
bw_one_pole_set_tau(&coeffs->smooth_coeffs, 0.05f);
- coeffs->gate = 0;
coeffs->attack = 0.f;
coeffs->decay = 0.f;
coeffs->sustain = 1.f;
@@ -303,8 +303,9 @@ static inline void bw_env_gen_update_coeffs_audio(bw_env_gen_coeffs *BW_RESTRICT
(void)coeffs;
}
-static inline void bw_env_gen_update_state_ctrl(const bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state) {
- if (coeffs->gate) {
+static inline void bw_env_gen_update_state_ctrl(const bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate) {
+ (void)coeffs;
+ if (gate) {
if (state->phase == bw_env_gen_phase_off || state->phase == bw_env_gen_phase_release)
state->phase = bw_env_gen_phase_attack;
} else {
@@ -349,9 +350,9 @@ static inline float bw_env_gen_process1(const bw_env_gen_coeffs *BW_RESTRICT coe
return v;
}
-static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, float* y, int n_samples) {
+static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float* y, int n_samples) {
bw_env_gen_update_coeffs_ctrl(coeffs);
- bw_env_gen_update_state_ctrl(coeffs, state);
+ bw_env_gen_update_state_ctrl(coeffs, state, gate);
if (y != NULL)
for (int i = 0; i < n_samples; i++)
y[i] = bw_env_gen_process1(coeffs, state);
@@ -360,10 +361,6 @@ static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_
bw_env_gen_process1(coeffs, state);
}
-static inline void bw_env_gen_set_gate(bw_env_gen_coeffs *BW_RESTRICT coeffs, char value) {
- coeffs->gate = value;
-}
-
static inline void bw_env_gen_set_attack(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->attack != value) {
coeffs->attack = value;
diff --git a/include/bw_voice_alloc.h b/include/bw_voice_alloc.h
index b1a55c1..f326c8f 100644
--- a/include/bw_voice_alloc.h
+++ b/include/bw_voice_alloc.h
@@ -60,7 +60,6 @@ typedef enum
* ```>>> */
typedef struct {
bw_voice_alloc_mode mode;
- char unison;
void (*note_on)(void *BW_RESTRICT voice, unsigned char note, float velocity);
void (*note_off)(void *BW_RESTRICT voice, float velocity);