From 4ff4ceed7032ffcab8b488233bccf4830d24808d Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sat, 3 Feb 2024 08:09:18 +0100 Subject: [PATCH] add fxpp_{ap2,balance}, fix fx_balance daisy seed, c++ array in non-wasm --- examples/common/src/common.h | 2 +- examples/common/src/cxx/impl.h | 14 ++--- examples/fx_balance/src/daisy-seed.json | 2 +- examples/fxpp_ap1/src/impl.cpp | 36 ++++++------- examples/fxpp_ap2/src/android.json | 5 ++ examples/fxpp_ap2/src/cmd.json | 6 +++ examples/fxpp_ap2/src/daisy-seed.json | 5 ++ examples/fxpp_ap2/src/impl.cpp | 52 ++++++++++++++++++ examples/fxpp_ap2/src/lv2.json | 12 +++++ examples/fxpp_ap2/src/product.json | 45 ++++++++++++++++ examples/fxpp_ap2/src/vst3.json | 11 ++++ examples/fxpp_balance/src/android.json | 5 ++ examples/fxpp_balance/src/cmd.json | 6 +++ examples/fxpp_balance/src/daisy-seed.json | 5 ++ examples/fxpp_balance/src/impl.cpp | 66 +++++++++++++++++++++++ examples/fxpp_balance/src/lv2.json | 12 +++++ examples/fxpp_balance/src/product.json | 56 +++++++++++++++++++ examples/fxpp_balance/src/vst3.json | 11 ++++ examples/gen.sh | 2 +- examples/genClean.sh | 2 +- 20 files changed, 326 insertions(+), 29 deletions(-) create mode 100644 examples/fxpp_ap2/src/android.json create mode 100644 examples/fxpp_ap2/src/cmd.json create mode 100644 examples/fxpp_ap2/src/daisy-seed.json create mode 100644 examples/fxpp_ap2/src/impl.cpp create mode 100644 examples/fxpp_ap2/src/lv2.json create mode 100644 examples/fxpp_ap2/src/product.json create mode 100644 examples/fxpp_ap2/src/vst3.json create mode 100644 examples/fxpp_balance/src/android.json create mode 100644 examples/fxpp_balance/src/cmd.json create mode 100644 examples/fxpp_balance/src/daisy-seed.json create mode 100644 examples/fxpp_balance/src/impl.cpp create mode 100644 examples/fxpp_balance/src/lv2.json create mode 100644 examples/fxpp_balance/src/product.json create mode 100644 examples/fxpp_balance/src/vst3.json diff --git a/examples/common/src/common.h b/examples/common/src/common.h index e3465eb..7282b88 100644 --- a/examples/common/src/common.h +++ b/examples/common/src/common.h @@ -1,6 +1,6 @@ #ifdef WASM +# define BW_CXX_NO_ARRAY # define BW_NO_MATH_H # define INFINITY (__builtin_inff()) #endif #define BW_NO_DEBUG -#define BW_CXX_NO_ARRAY diff --git a/examples/common/src/cxx/impl.h b/examples/common/src/cxx/impl.h index caff524..98a180e 100644 --- a/examples/common/src/cxx/impl.h +++ b/examples/common/src/cxx/impl.h @@ -6,13 +6,13 @@ extern "C" { typedef void * impl; -impl impl_new(); -void impl_free(impl instance); -void impl_set_sample_rate(impl instance, float sample_rate); -void impl_reset(impl instance); -void impl_set_parameter(impl instance, size_t index, float value); -float impl_get_parameter(impl instance, size_t index); -void impl_process(impl instance, const float **inputs, float **outputs, size_t n_samples); +impl impl_new(void); +void impl_free(impl handle); +void impl_set_sample_rate(impl handle, float sample_rate); +void impl_reset(impl handle); +void impl_set_parameter(impl handle, size_t index, float value); +float impl_get_parameter(impl handle, size_t index); +void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples); #ifdef __cplusplus } diff --git a/examples/fx_balance/src/daisy-seed.json b/examples/fx_balance/src/daisy-seed.json index 58cd7bf..19cad82 100644 --- a/examples/fx_balance/src/daisy-seed.json +++ b/examples/fx_balance/src/daisy-seed.json @@ -1,5 +1,5 @@ { "daisy_seed": { - "parameterPins": [ 22, 23, 15 ] + "parameterPins": [ 15, 22, 23 ] } } diff --git a/examples/fxpp_ap1/src/impl.cpp b/examples/fxpp_ap1/src/impl.cpp index b670308..09738fa 100644 --- a/examples/fxpp_ap1/src/impl.cpp +++ b/examples/fxpp_ap1/src/impl.cpp @@ -7,40 +7,40 @@ using namespace Brickworks; extern "C" { -impl impl_new() { +impl impl_new(void) { return reinterpret_cast(new AP1<1>()); } -void impl_free(impl instance) { - AP1<1> *ap1 = reinterpret_cast *>(instance); - delete ap1; +void impl_free(impl handle) { + AP1<1> *instance = reinterpret_cast *>(handle); + delete instance; } -void impl_set_sample_rate(impl instance, float sample_rate) { - AP1<1> *ap1 = reinterpret_cast *>(instance); - ap1->setSampleRate(sample_rate); +void impl_set_sample_rate(impl handle, float sample_rate) { + AP1<1> *instance = reinterpret_cast *>(handle); + instance->setSampleRate(sample_rate); } -void impl_reset(impl instance) { - AP1<1> *ap1 = reinterpret_cast *>(instance); - ap1->reset(); +void impl_reset(impl handle) { + AP1<1> *instance = reinterpret_cast *>(handle); + instance->reset(); } -void impl_set_parameter(impl instance, size_t index, float value) { +void impl_set_parameter(impl handle, size_t index, float value) { (void)index; - AP1<1> *ap1 = reinterpret_cast *>(instance); - ap1->setCutoff(value); + AP1<1> *instance = reinterpret_cast *>(handle); + instance->setCutoff(value); } -float impl_get_parameter(impl instance, size_t index) { - (void)instance; +float impl_get_parameter(impl handle, size_t index) { + (void)handle; (void)index; return 0.f; } -void impl_process(impl instance, const float **inputs, float **outputs, size_t n_samples) { - AP1<1> *ap1 = reinterpret_cast *>(instance); - ap1->process(inputs, outputs, n_samples); +void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples) { + AP1<1> *instance = reinterpret_cast *>(handle); + instance->process(inputs, outputs, n_samples); } } diff --git a/examples/fxpp_ap2/src/android.json b/examples/fxpp_ap2/src/android.json new file mode 100644 index 0000000..ef77d48 --- /dev/null +++ b/examples/fxpp_ap2/src/android.json @@ -0,0 +1,5 @@ +{ + "android": { + "javaPackageName": "com.orastron.bw_example_fxpp_ap2" + } +} diff --git a/examples/fxpp_ap2/src/cmd.json b/examples/fxpp_ap2/src/cmd.json new file mode 100644 index 0000000..1de49bf --- /dev/null +++ b/examples/fxpp_ap2/src/cmd.json @@ -0,0 +1,6 @@ +{ + "cmd": { + "busIds": [ "input", "output" ], + "parameterIds": [ "cutoff", "q" ] + } +} diff --git a/examples/fxpp_ap2/src/daisy-seed.json b/examples/fxpp_ap2/src/daisy-seed.json new file mode 100644 index 0000000..00367a0 --- /dev/null +++ b/examples/fxpp_ap2/src/daisy-seed.json @@ -0,0 +1,5 @@ +{ + "daisy_seed": { + "parameterPins": [ 15, 16 ] + } +} diff --git a/examples/fxpp_ap2/src/impl.cpp b/examples/fxpp_ap2/src/impl.cpp new file mode 100644 index 0000000..51139de --- /dev/null +++ b/examples/fxpp_ap2/src/impl.cpp @@ -0,0 +1,52 @@ +#include "impl.h" + +#include "common.h" +#include + +using namespace Brickworks; + +extern "C" { + +impl impl_new(void) { + return reinterpret_cast(new AP2<1>()); +} + +void impl_free(impl handle) { + AP2<1> *instance = reinterpret_cast *>(handle); + delete instance; +} + +void impl_set_sample_rate(impl handle, float sample_rate) { + AP2<1> *instance = reinterpret_cast *>(handle); + instance->setSampleRate(sample_rate); +} + +void impl_reset(impl handle) { + AP2<1> *instance = reinterpret_cast *>(handle); + instance->reset(); +} + +void impl_set_parameter(impl handle, size_t index, float value) { + AP2<1> *instance = reinterpret_cast *>(handle); + switch (index) { + case 0: + instance->setCutoff(value); + break; + case 1: + instance->setQ(value); + break; + } +} + +float impl_get_parameter(impl handle, size_t index) { + (void)handle; + (void)index; + return 0.f; +} + +void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples) { + AP2<1> *instance = reinterpret_cast *>(handle); + instance->process(inputs, outputs, n_samples); +} + +} diff --git a/examples/fxpp_ap2/src/lv2.json b/examples/fxpp_ap2/src/lv2.json new file mode 100644 index 0000000..bba4298 --- /dev/null +++ b/examples/fxpp_ap2/src/lv2.json @@ -0,0 +1,12 @@ +{ + "lv2": { + "prefixes": { + "bw_examples": "https://www.orastron.com/brickworks/examples/" + }, + "uri": "@bw_examples:fxpp_ap2", + "types": [ "@lv2:AllpassPlugin" ], + "version": "1.0", + "busSymbols": [ "input", "output" ], + "parameterSymbols": [ "cutoff", "q" ] + } +} diff --git a/examples/fxpp_ap2/src/product.json b/examples/fxpp_ap2/src/product.json new file mode 100644 index 0000000..d252ced --- /dev/null +++ b/examples/fxpp_ap2/src/product.json @@ -0,0 +1,45 @@ +{ + "product": { + "name": "Brickworks 2nd-order allpass example (C++)", + "version": "1.1.0", + "buildVersion": "1", + "bundleName": "bw_example_fxpp_ap2", + "buses": [ + { + "type": "audio", + "direction": "input", + "channels": "mono", + "name": "Input", + "shortName": "Input" + }, + { + "type": "audio", + "direction": "output", + "channels": "mono", + "name": "Output", + "shortName": "Output" + } + ], + "parameters": [ + { + "name": "Cutoff", + "shortName": "Cutoff", + "direction": "input", + "defaultValue": 1000.0, + "minimum": 20.0, + "maximum": 20000.0, + "unit": "hz", + "map": "logarithmic" + }, + { + "name": "Q", + "shortName": "Q", + "direction": "input", + "defaultValue": 0.5, + "minimum": 0.5, + "maximum": 10.0, + "map": "linear" + } + ] + } +} diff --git a/examples/fxpp_ap2/src/vst3.json b/examples/fxpp_ap2/src/vst3.json new file mode 100644 index 0000000..58f4715 --- /dev/null +++ b/examples/fxpp_ap2/src/vst3.json @@ -0,0 +1,11 @@ +{ + "vst3": { + "plugin": { + "cid": "32fc0150b5e4473286c506af49a9e7ec" + }, + "controller": { + "cid": "628219485d3748e2865579ede52e66bb" + }, + "subCategory": "Fx|Filter" + } +} diff --git a/examples/fxpp_balance/src/android.json b/examples/fxpp_balance/src/android.json new file mode 100644 index 0000000..e7ed53c --- /dev/null +++ b/examples/fxpp_balance/src/android.json @@ -0,0 +1,5 @@ +{ + "android": { + "javaPackageName": "com.orastron.bw_example_fxpp_balance" + } +} diff --git a/examples/fxpp_balance/src/cmd.json b/examples/fxpp_balance/src/cmd.json new file mode 100644 index 0000000..5584a39 --- /dev/null +++ b/examples/fxpp_balance/src/cmd.json @@ -0,0 +1,6 @@ +{ + "cmd": { + "busIds": [ "input", "output" ], + "parameterIds": [ "balance", "l_level", "r_level" ] + } +} diff --git a/examples/fxpp_balance/src/daisy-seed.json b/examples/fxpp_balance/src/daisy-seed.json new file mode 100644 index 0000000..19cad82 --- /dev/null +++ b/examples/fxpp_balance/src/daisy-seed.json @@ -0,0 +1,5 @@ +{ + "daisy_seed": { + "parameterPins": [ 15, 22, 23 ] + } +} diff --git a/examples/fxpp_balance/src/impl.cpp b/examples/fxpp_balance/src/impl.cpp new file mode 100644 index 0000000..b76fad5 --- /dev/null +++ b/examples/fxpp_balance/src/impl.cpp @@ -0,0 +1,66 @@ +#include "impl.h" + +#include "common.h" +#include +#include + +using namespace Brickworks; + +class Engine { +public: + Balance<1> balance; + PPM<2> ppm; +}; + +extern "C" { + +impl impl_new(void) { + return reinterpret_cast(new Engine()); +} + +void impl_free(impl handle) { + Engine *instance = reinterpret_cast(handle); + delete instance; +} + +void impl_set_sample_rate(impl handle, float sample_rate) { + Engine *instance = reinterpret_cast(handle); + instance->balance.setSampleRate(sample_rate); + instance->ppm.setSampleRate(sample_rate); +} + +void impl_reset(impl handle) { + Engine *instance = reinterpret_cast(handle); + instance->balance.reset(); + instance->ppm.reset(); +} + +void impl_set_parameter(impl handle, size_t index, float value) { + (void)index; + + Engine *instance = reinterpret_cast(handle); + instance->balance.setBalance(0.01f * value); +} + +float impl_get_parameter(impl handle, size_t index) { + Engine *instance = reinterpret_cast(handle); + float v = instance->ppm.getYZ1(index - 1); + return v < -60.f ? -60.f : (v > 0.f ? 0.f : v); +} + +void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples) { + Engine *instance = reinterpret_cast(handle); +#ifdef WASM + const float *xL[1] = {inputs[0]}; + const float *xR[1] = {inputs[1]}; + float *yL[1] = {outputs[0]}; + float *yR[1] = {outputs[1]}; + instance->balance.process(xL, xR, yL, yR, n_samples); + instance->ppm.process(outputs, nullptr, n_samples); +#else + instance->balance.process({inputs[0]}, {inputs[1]}, {outputs[0]}, {outputs[1]}, n_samples); + instance->ppm.process({outputs[0], outputs[1]}, {nullptr, nullptr}, n_samples); +#endif +} + +} diff --git a/examples/fxpp_balance/src/lv2.json b/examples/fxpp_balance/src/lv2.json new file mode 100644 index 0000000..6d02be5 --- /dev/null +++ b/examples/fxpp_balance/src/lv2.json @@ -0,0 +1,12 @@ +{ + "lv2": { + "prefixes": { + "bw_examples": "https://www.orastron.com/brickworks/examples/" + }, + "uri": "@bw_examples:fxpp_balance", + "types": [ "@lv2:SpatialPlugin" ], + "version": "1.0", + "busSymbols": [ "input", "output" ], + "parameterSymbols": [ "balance", "l_level", "r_level" ] + } +} diff --git a/examples/fxpp_balance/src/product.json b/examples/fxpp_balance/src/product.json new file mode 100644 index 0000000..15a0681 --- /dev/null +++ b/examples/fxpp_balance/src/product.json @@ -0,0 +1,56 @@ +{ + "product": { + "name": "Brickworks stereo balance example", + "version": "1.1.0", + "buildVersion": "1", + "bundleName": "bw_example_fx_balance", + "buses": [ + { + "type": "audio", + "direction": "input", + "channels": "stereo", + "name": "Input", + "shortName": "Input" + }, + { + "type": "audio", + "direction": "output", + "channels": "stereo", + "name": "Output", + "shortName": "Output" + } + ], + "parameters": [ + { + "name": "Balance", + "shortName": "Balance", + "direction": "input", + "defaultValue": 0.0, + "minimum": -100.0, + "maximum": 100.0, + "unit": "pc", + "map": "linear" + }, + { + "name": "Left level", + "shortName": "L level", + "direction": "output", + "defaultValue": -60.0, + "minimum": -60.0, + "maximum": 0.0, + "unit": "db", + "map": "linear" + }, + { + "name": "Right level", + "shortName": "R level", + "direction": "output", + "defaultValue": -60.0, + "minimum": -60.0, + "maximum": 0.0, + "unit": "db", + "map": "linear" + } + ] + } +} diff --git a/examples/fxpp_balance/src/vst3.json b/examples/fxpp_balance/src/vst3.json new file mode 100644 index 0000000..9dac61d --- /dev/null +++ b/examples/fxpp_balance/src/vst3.json @@ -0,0 +1,11 @@ +{ + "vst3": { + "plugin": { + "cid": "2c5793c7eae0488e8c7820afbcd6ee17" + }, + "controller": { + "cid": "c67e0faf04f54fdf8019eb055f44b1b0" + }, + "subCategory": "Fx|Spatial" + } +} diff --git a/examples/gen.sh b/examples/gen.sh index 4ee9dfa..b4e12a2 100755 --- a/examples/gen.sh +++ b/examples/gen.sh @@ -23,7 +23,7 @@ cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/vst3-make vst3 && cd cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/android android && cd .. cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/android-make android && cd .. -dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1" +dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1 fxpp_ap2 fxpp_balance" for d in $dirs; do echo Generating data files for $d diff --git a/examples/genClean.sh b/examples/genClean.sh index 04a8b98..3a7bb5b 100755 --- a/examples/genClean.sh +++ b/examples/genClean.sh @@ -4,7 +4,7 @@ echo Removing common files rm -fr common/cmd common/web common/daisy-seed common/lv2 common/vst3 common/android -dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1" +dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1 fxpp_ap2 fxpp_balance" for d in $dirs; do echo Removing data files for $d