From 768aa6d81ede3c4d676f92973467744301719792 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Tue, 27 Jun 2023 15:55:37 +0200 Subject: [PATCH] bwpp_pan + fxpp_pan + use process_multi in fx_balance, fx_pan --- TODO | 1 + .../fx_balance/src/bw_example_fx_balance.c | 8 +- examples/fx_pan/src/bw_example_fx_pan.c | 8 +- examples/fxpp_pan/daisy-seed/Makefile | 7 ++ .../fxpp_pan/daisy-seed/config_daisy_seed.h | 35 ++++++++ examples/fxpp_pan/src/bw_example_fxpp_pan.cpp | 71 +++++++++++++++ examples/fxpp_pan/src/bw_example_fxpp_pan.h | 55 ++++++++++++ examples/fxpp_pan/src/config.h | 89 +++++++++++++++++++ examples/fxpp_pan/vst3/Makefile | 6 ++ examples/fxpp_pan/vst3/config_vst3.h | 36 ++++++++ include/bwpp_pan.h | 77 ++++++++++++++++ 11 files changed, 381 insertions(+), 12 deletions(-) create mode 100644 examples/fxpp_pan/daisy-seed/Makefile create mode 100644 examples/fxpp_pan/daisy-seed/config_daisy_seed.h create mode 100644 examples/fxpp_pan/src/bw_example_fxpp_pan.cpp create mode 100644 examples/fxpp_pan/src/bw_example_fxpp_pan.h create mode 100644 examples/fxpp_pan/src/config.h create mode 100644 examples/fxpp_pan/vst3/Makefile create mode 100644 examples/fxpp_pan/vst3/config_vst3.h create mode 100644 include/bwpp_pan.h diff --git a/TODO b/TODO index 2e84e55..2770d11 100644 --- a/TODO +++ b/TODO @@ -58,6 +58,7 @@ code: * float -> double, etc. ? * sr_reduce reset_coeffs? update_coeffs? process_multi? * src(_int) process_multi? +* fix definitions leading to X ** -> const X ** error https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion, fix fx_balance, fx_pan, synth_poly build system: * make makefiles handle paths with spaces etc diff --git a/examples/fx_balance/src/bw_example_fx_balance.c b/examples/fx_balance/src/bw_example_fx_balance.c index 2850942..1d6ca4d 100644 --- a/examples/fx_balance/src/bw_example_fx_balance.c +++ b/examples/fx_balance/src/bw_example_fx_balance.c @@ -39,12 +39,8 @@ void bw_example_fx_balance_reset(bw_example_fx_balance *instance) { void bw_example_fx_balance_process(bw_example_fx_balance *instance, const float** x, float** y, int n_samples) { bw_balance_process(&instance->balance_coeffs, x[0], x[1], y[0], y[1], n_samples); - bw_ppm_update_coeffs_ctrl(&instance->ppm_coeffs); - for (int i = 0; i < n_samples; i++) { - bw_ppm_update_coeffs_audio(&instance->ppm_coeffs); - bw_ppm_process1(&instance->ppm_coeffs, &instance->ppm_l_state, y[0][i]); - bw_ppm_process1(&instance->ppm_coeffs, &instance->ppm_r_state, y[1][i]); - } + bw_ppm_state *ppm_states[2] = { &instance->ppm_l_state, &instance->ppm_r_state }; + bw_ppm_process_multi(&instance->ppm_coeffs, ppm_states, (const float **)y, NULL, 2, n_samples); } void bw_example_fx_balance_set_parameter(bw_example_fx_balance *instance, int index, float value) { diff --git a/examples/fx_pan/src/bw_example_fx_pan.c b/examples/fx_pan/src/bw_example_fx_pan.c index 3d2903d..a3e76c2 100644 --- a/examples/fx_pan/src/bw_example_fx_pan.c +++ b/examples/fx_pan/src/bw_example_fx_pan.c @@ -39,12 +39,8 @@ void bw_example_fx_pan_reset(bw_example_fx_pan *instance) { void bw_example_fx_pan_process(bw_example_fx_pan *instance, const float** x, float** y, int n_samples) { bw_pan_process(&instance->pan_coeffs, x[0], y[0], y[1], n_samples); - bw_ppm_update_coeffs_ctrl(&instance->ppm_coeffs); - for (int i = 0; i < n_samples; i++) { - bw_ppm_update_coeffs_audio(&instance->ppm_coeffs); - bw_ppm_process1(&instance->ppm_coeffs, &instance->ppm_l_state, y[0][i]); - bw_ppm_process1(&instance->ppm_coeffs, &instance->ppm_r_state, y[1][i]); - } + bw_ppm_state *ppm_states[2] = { &instance->ppm_l_state, &instance->ppm_r_state }; + bw_ppm_process_multi(&instance->ppm_coeffs, ppm_states, (const float **)y, NULL, 2, n_samples); } void bw_example_fx_pan_set_parameter(bw_example_fx_pan *instance, int index, float value) { diff --git a/examples/fxpp_pan/daisy-seed/Makefile b/examples/fxpp_pan/daisy-seed/Makefile new file mode 100644 index 0000000..5b63222 --- /dev/null +++ b/examples/fxpp_pan/daisy-seed/Makefile @@ -0,0 +1,7 @@ +ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + +TARGET = bw_example_fxpp_pan + +CPP_SOURCES_EXTRA = ${ROOT_DIR}/../src/bw_example_fxpp_pan.cpp + +include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk diff --git a/examples/fxpp_pan/daisy-seed/config_daisy_seed.h b/examples/fxpp_pan/daisy-seed/config_daisy_seed.h new file mode 100644 index 0000000..466205b --- /dev/null +++ b/examples/fxpp_pan/daisy-seed/config_daisy_seed.h @@ -0,0 +1,35 @@ +/* + * 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_pin { + int param_index; + int pin; +}; + +#define NUM_PINS 1 + +static struct config_pin config_pins[NUM_PINS] = { + { 0, 15 } +}; + +#endif diff --git a/examples/fxpp_pan/src/bw_example_fxpp_pan.cpp b/examples/fxpp_pan/src/bw_example_fxpp_pan.cpp new file mode 100644 index 0000000..f29d399 --- /dev/null +++ b/examples/fxpp_pan/src/bw_example_fxpp_pan.cpp @@ -0,0 +1,71 @@ +/* + * 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_fxpp_pan.h" + +void bw_example_fxpp_pan_init(bw_example_fxpp_pan *instance) { + (void)instance; +} + +void bw_example_fxpp_pan_set_sample_rate(bw_example_fxpp_pan *instance, float sample_rate) { + instance->pan.setSampleRate(sample_rate); + instance->ppm.setSampleRate(sample_rate); +} + +void bw_example_fxpp_pan_reset(bw_example_fxpp_pan *instance) { + instance->pan.reset(); + instance->ppm.reset(); +} + +void bw_example_fxpp_pan_process(bw_example_fxpp_pan *instance, const float** x, float** y, int n_samples) { + instance->pan.process({x[0]}, {y[0]}, {y[1]}, n_samples); + instance->ppm.process({y[0], y[1]}, {nullptr, nullptr}, n_samples); +} + +void bw_example_fxpp_pan_set_parameter(bw_example_fxpp_pan *instance, int index, float value) { + instance->params[index] = value; + switch (index) { + case p_pan: + instance->pan.setPan(value + value - 1.f); + break; + } +} + +float bw_example_fxpp_pan_get_parameter(bw_example_fxpp_pan *instance, int index) { + float r = 0.f; + switch (index) { + case p_pan: + r = instance->params[p_pan]; + break; + case p_pan + 1: + { + const float v = instance->ppm.getYZ1(0); + r = v < -200.f ? 0.f : bw_clipf(0.01666666666666667f * v + 1.f, 0.f, 1.f); + break; + } + case p_pan + 2: + { + const float v = instance->ppm.getYZ1(1); + r = v < -200.f ? 0.f : bw_clipf(0.01666666666666667f * v + 1.f, 0.f, 1.f); + break; + } + } + return r; +} diff --git a/examples/fxpp_pan/src/bw_example_fxpp_pan.h b/examples/fxpp_pan/src/bw_example_fxpp_pan.h new file mode 100644 index 0000000..e446abe --- /dev/null +++ b/examples/fxpp_pan/src/bw_example_fxpp_pan.h @@ -0,0 +1,55 @@ +/* + * 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_FXPP_PAN_H +#define _BW_EXAMPLE_FXPP_PAN_H + +#include +#include + +using namespace Brickworks; + +extern "C" { + +enum { + p_pan, + p_n +}; + +struct _bw_example_fxpp_pan { + // Sub-components + Pan<1> pan; + PPM<2> ppm; + + // Parameters + float params[p_n]; +}; +typedef struct _bw_example_fxpp_pan bw_example_fxpp_pan; + +void bw_example_fxpp_pan_init(bw_example_fxpp_pan *instance); +void bw_example_fxpp_pan_set_sample_rate(bw_example_fxpp_pan *instance, float sample_rate); +void bw_example_fxpp_pan_reset(bw_example_fxpp_pan *instance); +void bw_example_fxpp_pan_process(bw_example_fxpp_pan *instance, const float** x, float** y, int n_samples); +void bw_example_fxpp_pan_set_parameter(bw_example_fxpp_pan *instance, int index, float value); +float bw_example_fxpp_pan_get_parameter(bw_example_fxpp_pan *instance, int index); + +} + +#endif diff --git a/examples/fxpp_pan/src/config.h b/examples/fxpp_pan/src/config.h new file mode 100644 index 0000000..c757a8c --- /dev/null +++ b/examples/fxpp_pan/src/config.h @@ -0,0 +1,89 @@ +/* + * 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_fxpp_pan" +#define PLUGIN_VERSION "0.5.0" + +#define NUM_BUSES_IN 1 +#define NUM_BUSES_OUT 1 +#define NUM_CHANNELS_IN 1 +#define NUM_CHANNELS_OUT 2 + +static struct config_io_bus config_buses_in[NUM_BUSES_IN] = { + { "Audio in", 0, 0, 0, IO_STEREO } +}; + +static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = { + { "Audio out", 1, 0, 0, IO_STEREO } +}; + +#define NUM_PARAMETERS 3 + +static struct config_parameter config_parameters[NUM_PARAMETERS] = { + { "Pan", "Pan", "", 0, 0, 0, 0.5f }, + { "Left level", "L Level", "", 1, 0, 0, 0.f }, + { "Right level", "R Level", "", 1, 0, 0, 0.f } +}; + +// Internal API + +#include "bw_example_fxpp_pan.h" + +#define P_TYPE bw_example_fxpp_pan +#define P_INIT bw_example_fxpp_pan_init +#define P_SET_SAMPLE_RATE bw_example_fxpp_pan_set_sample_rate +#define P_RESET bw_example_fxpp_pan_reset +#define P_PROCESS bw_example_fxpp_pan_process +#define P_SET_PARAMETER bw_example_fxpp_pan_set_parameter +#define P_GET_PARAMETER bw_example_fxpp_pan_get_parameter + +#endif diff --git a/examples/fxpp_pan/vst3/Makefile b/examples/fxpp_pan/vst3/Makefile new file mode 100644 index 0000000..b90760d --- /dev/null +++ b/examples/fxpp_pan/vst3/Makefile @@ -0,0 +1,6 @@ +ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + +NAME := bw_example_fxpp_pan +SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_pan.cpp + +include ${ROOT_DIR}/../../common/vst3/vst3.mk diff --git a/examples/fxpp_pan/vst3/config_vst3.h b/examples/fxpp_pan/vst3/config_vst3.h new file mode 100644 index 0000000..5644edf --- /dev/null +++ b/examples/fxpp_pan/vst3/config_vst3.h @@ -0,0 +1,36 @@ +/* + * 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, Paolo Marrone + */ + +#ifndef _VST3_CONFIG_H +#define _VST3_CONFIG_H + +#define PLUGIN_SUBCATEGORY "Fx|Spatial" + +#define PLUGIN_GUID_1 0x47d6ebcd +#define PLUGIN_GUID_2 0x744540f2 +#define PLUGIN_GUID_3 0x8ea345d6 +#define PLUGIN_GUID_4 0x89a2a236 + +#define CTRL_GUID_1 0x646c6d37 +#define CTRL_GUID_2 0xfbe846af +#define CTRL_GUID_3 0xa5e16bd7 +#define CTRL_GUID_4 0x6d1676c6 + +#endif diff --git a/include/bwpp_pan.h b/include/bwpp_pan.h new file mode 100644 index 0000000..deb495b --- /dev/null +++ b/include/bwpp_pan.h @@ -0,0 +1,77 @@ +/* + * 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 BWPP_PAN_H +#define BWPP_PAN_H + +#include +#include + +namespace Brickworks { + template + class Pan { + public: + Pan(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + std::array x, + std::array y_l, + std::array y_r, + int nSamples); + + void setPan(float value); + + private: + bw_pan_coeffs coeffs; + }; + + template + Pan::Pan() { + bw_pan_init(&coeffs); + } + + template + void Pan::setSampleRate(float sampleRate) { + bw_pan_set_sample_rate(&coeffs, sampleRate); + } + + template + void Pan::reset() { + bw_pan_reset_coeffs(&coeffs); + } + + template + void Pan::process( + std::array x, + std::array y_l, + std::array y_r, + int nSamples) { + bw_pan_process_multi(&coeffs, x.data(), y_l.data(), y_r.data(), N_CHANNELS, nSamples); + } + + template + void Pan::setPan(float value) { + bw_pan_set_pan(&coeffs, value); + } +} + +#endif