new bwpp_svf, fxpp_svf + free mem, stronger, cleaner vst3 and web wrappers

This commit is contained in:
Stefano D'Angelo 2023-06-19 15:26:21 +02:00
parent 4037735123
commit c1f58ba76d
13 changed files with 411 additions and 0 deletions

1
TODO
View File

@ -52,6 +52,7 @@ code:
* x_y vs xy var names
* don't use reserved identifiers (https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=107685)
* update state ctrl -> process ctrl?
* mem req -> return value of set sample rate?
build system:
* make makefiles handle paths with spaces etc

View File

@ -36,6 +36,7 @@ class Controller : EditController {
#endif
public:
static FUnknown *createInstance(void *context) {
(void)context;
return (IEditController *) new Controller();
}

View File

@ -150,6 +150,16 @@ static inline void _sse2neon_mm_set_flush_zero_mode(unsigned int flag)
Plugin::Plugin() {
setControllerClass(FUID(CTRL_GUID_1, CTRL_GUID_2, CTRL_GUID_3, CTRL_GUID_4));
#ifdef P_MEM_REQ
this->mem = NULL;
#endif
}
Plugin::~Plugin() {
#ifdef P_MEM_REQ
if (this->mem)
free(this->mem);
#endif
}
tresult PLUGIN_API Plugin::initialize(FUnknown *context) {
@ -194,6 +204,8 @@ tresult PLUGIN_API Plugin::initialize(FUnknown *context) {
#endif
#ifdef P_MEM_REQ
if (this->mem)
free(this->mem);
this->mem = NULL;
#endif
@ -201,6 +213,15 @@ tresult PLUGIN_API Plugin::initialize(FUnknown *context) {
}
tresult PLUGIN_API Plugin::terminate() {
#ifdef P_MEM_REQ
if (this->mem) {
free(this->mem);
this->mem = NULL;
}
#endif
#ifdef P_FINI
P_FINI(&instance);
#endif
return AudioEffect::terminate();
}

View File

@ -32,8 +32,10 @@ using namespace Steinberg::Vst;
class Plugin : AudioEffect {
public:
Plugin();
~Plugin();
static FUnknown *createInstance(void *context) {
(void)context;
return (IAudioProcessor *) new Plugin();
}

View File

@ -107,6 +107,9 @@ void wrapper_free(wrapper w) {
#ifdef P_MEM_REQ
if (w->mem)
free(w->mem);
#endif
#ifdef P_FINI
P_FINI(&w->instance);
#endif
free(w);
}

View File

@ -0,0 +1,7 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TARGET = bw_example_fxpp_svf
CPP_SOURCES_EXTRA = ${ROOT_DIR}/../src/bw_example_fxpp_svf.cpp
include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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 2
static struct config_pin config_pins[NUM_PINS] = {
{ 0, 15 },
{ 1, 16 }
};
#endif

View File

@ -0,0 +1,53 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#include "bw_example_fxpp_svf.h"
void bw_example_fxpp_svf_init(bw_example_fxpp_svf *instance) {
(void)instance;
}
void bw_example_fxpp_svf_set_sample_rate(bw_example_fxpp_svf *instance, float sample_rate) {
instance->svf.setSampleRate(sample_rate);
}
void bw_example_fxpp_svf_reset(bw_example_fxpp_svf *instance) {
instance->svf.reset();
}
void bw_example_fxpp_svf_process(bw_example_fxpp_svf *instance, const float** x, float** y, int n_samples) {
instance->svf.process({x[0]}, {y[0]}, {nullptr}, {nullptr}, n_samples);
}
void bw_example_fxpp_svf_set_parameter(bw_example_fxpp_svf *instance, int index, float value) {
instance->params[index] = value;
switch (index) {
case p_cutoff:
instance->svf.setCutoff((20e3f - 20.f) * value * value * value + 20.f);
break;
case p_Q:
instance->svf.setQ(0.5f + 9.5f * value);
break;
}
}
float bw_example_fxpp_svf_get_parameter(bw_example_fxpp_svf *instance, int index) {
return instance->params[index];
}

View File

@ -0,0 +1,54 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef _BW_EXAMPLE_FXPP_SVF_H
#define _BW_EXAMPLE_FXPP_SVF_H
#include <bwpp_svf.h>
using namespace Brickworks;
extern "C" {
enum {
p_cutoff,
p_Q,
p_n
};
struct _bw_example_fxpp_svf {
// Sub-components
SVF<1> svf;
// Parameters
float params[p_n];
};
typedef struct _bw_example_fxpp_svf bw_example_fxpp_svf;
void bw_example_fxpp_svf_init(bw_example_fxpp_svf *instance);
void bw_example_fxpp_svf_set_sample_rate(bw_example_fxpp_svf *instance, float sample_rate);
void bw_example_fxpp_svf_reset(bw_example_fxpp_svf *instance);
void bw_example_fxpp_svf_process(bw_example_fxpp_svf *instance, const float** x, float** y, int n_samples);
void bw_example_fxpp_svf_set_parameter(bw_example_fxpp_svf *instance, int index, float value);
float bw_example_fxpp_svf_get_parameter(bw_example_fxpp_svf *instance, int index);
}
#endif

View File

@ -0,0 +1,88 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* 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_svf"
#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 1
static struct config_io_bus config_buses_in[NUM_BUSES_IN] = {
{ "Audio in", 0, 0, 0, IO_MONO }
};
static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = {
{ "Audio out", 1, 0, 0, IO_MONO }
};
#define NUM_PARAMETERS 2
static struct config_parameter config_parameters[NUM_PARAMETERS] = {
{ "Cutoff", "Cutoff", "", 0, 0, 0, 0.5f },
{ "Q", "Q", "", 0, 0, 0, 0.f }
};
// Internal API
#include "bw_example_fxpp_svf.h"
#define P_TYPE bw_example_fxpp_svf
#define P_INIT bw_example_fxpp_svf_init
#define P_SET_SAMPLE_RATE bw_example_fxpp_svf_set_sample_rate
#define P_RESET bw_example_fxpp_svf_reset
#define P_PROCESS bw_example_fxpp_svf_process
#define P_SET_PARAMETER bw_example_fxpp_svf_set_parameter
#define P_GET_PARAMETER bw_example_fxpp_svf_get_parameter
#endif

View File

@ -0,0 +1,6 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
NAME := bw_example_fxpp_svf
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_svf.cpp
include ${ROOT_DIR}/../../common/vst3/vst3.mk

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File authors: Stefano D'Angelo, Paolo Marrone
*/
#ifndef _VST3_CONFIG_H
#define _VST3_CONFIG_H
#define PLUGIN_SUBCATEGORY "Fx|Filter"
#define PLUGIN_GUID_1 0xf0b3ea08
#define PLUGIN_GUID_2 0xa3ab4e7c
#define PLUGIN_GUID_3 0xa2b56d64
#define PLUGIN_GUID_4 0x97cb49b3
#define CTRL_GUID_1 0xfdc70e14
#define CTRL_GUID_2 0x01114f17
#define CTRL_GUID_3 0x8d1cccd6
#define CTRL_GUID_4 0x9988f6df
#endif

103
include/bwpp_svf.h Normal file
View File

@ -0,0 +1,103 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_SVF_H
#define BWPP_SVF_H
#include <bw_svf.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class SVF {
public:
SVF();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_lp,
std::array<float *, N_CHANNELS> y_bp,
std::array<float *, N_CHANNELS> y_hp,
int nSamples);
void setCutoff(float value);
void setQ(float value);
void setPrewarpAtCutoff(bool value);
void setPrewarpFreq(float value);
private:
bw_svf_coeffs coeffs;
bw_svf_state states[N_CHANNELS];
bw_svf_state *statesP[N_CHANNELS];
};
template<BW_SIZE_T N_CHANNELS>
SVF<N_CHANNELS>::SVF() {
bw_svf_init(&coeffs);
for (unsigned int i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_svf_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::reset(float x0) {
bw_svf_reset_coeffs(&coeffs);
for (unsigned int i = 0; i < N_CHANNELS; i++)
bw_svf_reset_state(&coeffs, states + i, x0);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_lp,
std::array<float *, N_CHANNELS> y_bp,
std::array<float *, N_CHANNELS> y_hp,
int nSamples) {
bw_svf_process_multi(&coeffs, statesP, x.data(), y_lp.data(), y_bp.data(), y_hp.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::setCutoff(float value) {
bw_svf_set_cutoff(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::setQ(float value) {
bw_svf_set_Q(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::setPrewarpAtCutoff(bool value) {
bw_svf_set_prewarp_at_cutoff(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void SVF<N_CHANNELS>::setPrewarpFreq(float value) {
bw_svf_set_prewarp_freq(&coeffs, value);
}
}
#endif