bwpp_{ppm,balance} + fxpp_balance

This commit is contained in:
Stefano D'Angelo 2023-06-22 16:29:06 +02:00
parent bfee4340a4
commit 063d4ffb02
9 changed files with 466 additions and 0 deletions

View File

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

View File

@ -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 <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 1
static struct config_pin config_pins[NUM_PINS] = {
{ 0, 15 }
};
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#include "bw_example_fxpp_balance.h"
void bw_example_fxpp_balance_init(bw_example_fxpp_balance *instance) {
(void)instance;
}
void bw_example_fxpp_balance_set_sample_rate(bw_example_fxpp_balance *instance, float sample_rate) {
instance->balance.setSampleRate(sample_rate);
instance->ppm.setSampleRate(sample_rate);
}
void bw_example_fxpp_balance_reset(bw_example_fxpp_balance *instance) {
instance->balance.reset();
instance->ppm.reset();
}
void bw_example_fxpp_balance_process(bw_example_fxpp_balance *instance, const float** x, float** y, int n_samples) {
instance->balance.process({x[0]}, {x[1]}, {y[0]}, {y[1]}, n_samples);
instance->ppm.process({y[0], y[1]}, {nullptr, nullptr}, n_samples);
}
void bw_example_fxpp_balance_set_parameter(bw_example_fxpp_balance *instance, int index, float value) {
instance->params[index] = value;
switch (index) {
case p_balance:
instance->balance.setBalance(value + value - 1.f);
break;
}
}
float bw_example_fxpp_balance_get_parameter(bw_example_fxpp_balance *instance, int index) {
float r = 0.f;
switch (index) {
case p_balance:
r = instance->params[p_balance];
break;
case p_balance + 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_balance + 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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef _BW_EXAMPLE_FXPP_BALANCE_H
#define _BW_EXAMPLE_FXPP_BALANCE_H
#include <bwpp_balance.h>
#include <bwpp_ppm.h>
using namespace Brickworks;
extern "C" {
enum {
p_balance,
p_n
};
struct _bw_example_fxpp_balance {
// Sub-components
Balance<1> balance;
PPM<2> ppm;
// Parameters
float params[p_n];
};
typedef struct _bw_example_fxpp_balance bw_example_fxpp_balance;
void bw_example_fxpp_balance_init(bw_example_fxpp_balance *instance);
void bw_example_fxpp_balance_set_sample_rate(bw_example_fxpp_balance *instance, float sample_rate);
void bw_example_fxpp_balance_reset(bw_example_fxpp_balance *instance);
void bw_example_fxpp_balance_process(bw_example_fxpp_balance *instance, const float** x, float** y, int n_samples);
void bw_example_fxpp_balance_set_parameter(bw_example_fxpp_balance *instance, int index, float value);
float bw_example_fxpp_balance_get_parameter(bw_example_fxpp_balance *instance, int index);
}
#endif

View File

@ -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 <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_balance"
#define PLUGIN_VERSION "0.5.0"
#define NUM_BUSES_IN 1
#define NUM_BUSES_OUT 1
#define NUM_CHANNELS_IN 2
#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] = {
{ "Balance", "Balance", "", 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_balance.h"
#define P_TYPE bw_example_fxpp_balance
#define P_INIT bw_example_fxpp_balance_init
#define P_SET_SAMPLE_RATE bw_example_fxpp_balance_set_sample_rate
#define P_RESET bw_example_fxpp_balance_reset
#define P_PROCESS bw_example_fxpp_balance_process
#define P_SET_PARAMETER bw_example_fxpp_balance_set_parameter
#define P_GET_PARAMETER bw_example_fxpp_balance_get_parameter
#endif

View File

@ -0,0 +1,6 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
NAME := bw_example_fxpp_balance
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fxpp_balance.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|Spatial"
#define PLUGIN_GUID_1 0x2c5793c7
#define PLUGIN_GUID_2 0xeae0488e
#define PLUGIN_GUID_3 0x8c7820af
#define PLUGIN_GUID_4 0xbcd6ee17
#define CTRL_GUID_1 0xc67e0faf
#define CTRL_GUID_2 0x04f54fdf
#define CTRL_GUID_3 0x8019eb05
#define CTRL_GUID_4 0x5f44b1b0
#endif

79
include/bwpp_balance.h Normal file
View File

@ -0,0 +1,79 @@
/*
* 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_BALANCE_H
#define BWPP_BALANCE_H
#include <bw_balance.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class Balance {
public:
Balance();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x_l,
std::array<const float *, N_CHANNELS> x_r,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
int nSamples);
void setBalance(float value);
private:
bw_balance_coeffs coeffs;
};
template<BW_SIZE_T N_CHANNELS>
Balance<N_CHANNELS>::Balance() {
bw_balance_init(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void Balance<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_balance_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void Balance<N_CHANNELS>::reset() {
bw_balance_reset_coeffs(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void Balance<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_l,
std::array<const float *, N_CHANNELS> x_r,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
int nSamples) {
bw_balance_process_multi(&coeffs, x_l.data(), x_r.data(), y_l.data(), y_r.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void Balance<N_CHANNELS>::setBalance(float value) {
bw_balance_set_balance(&coeffs, value);
}
}
#endif

88
include/bwpp_ppm.h Normal file
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 author: Stefano D'Angelo
*/
#ifndef BWPP_PPM_H
#define BWPP_PPM_H
#include <bw_ppm.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class PPM {
public:
PPM();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setIntegrationTau(float value);
float getYZ1(BW_SIZE_T channel);
private:
bw_ppm_coeffs coeffs;
bw_ppm_state states[N_CHANNELS];
bw_ppm_state *statesP[N_CHANNELS];
};
template<BW_SIZE_T N_CHANNELS>
PPM<N_CHANNELS>::PPM() {
bw_ppm_init(&coeffs);
for (unsigned int i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<BW_SIZE_T N_CHANNELS>
void PPM<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ppm_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void PPM<N_CHANNELS>::reset() {
bw_ppm_reset_coeffs(&coeffs);
for (unsigned int i = 0; i < N_CHANNELS; i++)
bw_ppm_reset_state(&coeffs, states + i);
}
template<BW_SIZE_T N_CHANNELS>
void PPM<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_ppm_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void PPM<N_CHANNELS>::setIntegrationTau(float value) {
bw_ppm_set_integration_tau(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
float PPM<N_CHANNELS>::getYZ1(BW_SIZE_T channel) {
return bw_ppm_get_y_z1(states + channel);
}
}
#endif