lots of example-related improvements + fx(pp)_bitcrush

This commit is contained in:
Stefano D'Angelo 2024-02-06 11:19:39 +01:00
parent 684f021476
commit 9b0496474b
37 changed files with 314 additions and 366 deletions

View File

@ -2,7 +2,7 @@
Each subfolder contains an example application, except the `common` folder, which contains common code for all examples.
In order to build an example just `cd` to `*example*/*platofrm*` and use the following platform-specific instructions.
In order to build an example just `cd` to `*example*/*platform*` and use the following platform-specific instructions.
Building for any platform requires a recent enough version of [GNU Make](https://www.gnu.org/software/make/) installed.

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fx_ap1"
"productBundleIdentifier": "com.orastron.bw_example_fx_ap1"
}
}

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fx_ap2"
"productBundleIdentifier": "com.orastron.bw_example_fx_ap2"
}
}

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fx_balance"
"productBundleIdentifier": "com.orastron.bw_example_fx_balance"
}
}

View File

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

View File

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

View File

@ -1,36 +0,0 @@
/*
* 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

@ -1,6 +0,0 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
NAME := bw_example_fx_bitcrush
SOURCE := ${NAME}.c
include ${ROOT_DIR}/../../common/ios/ios.mk

View File

@ -0,0 +1,5 @@
{
"android": {
"javaPackageName": "com.orastron.bw_example_fx_bitcrush"
}
}

View File

@ -1,58 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2022, 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_fx_bitcrush.h"
void bw_example_fx_bitcrush_init(bw_example_fx_bitcrush *instance) {
bw_sr_reduce_init(&instance->sr_reduce_coeffs);
bw_bd_reduce_init(&instance->bd_reduce_coeffs);
}
void bw_example_fx_bitcrush_set_sample_rate(bw_example_fx_bitcrush *instance, float sample_rate) {
bw_sr_reduce_set_sample_rate(&instance->sr_reduce_coeffs, sample_rate);
bw_bd_reduce_set_sample_rate(&instance->bd_reduce_coeffs, sample_rate);
}
void bw_example_fx_bitcrush_reset(bw_example_fx_bitcrush *instance) {
bw_sr_reduce_reset_coeffs(&instance->sr_reduce_coeffs);
bw_sr_reduce_reset_state(&instance->sr_reduce_coeffs, &instance->sr_reduce_state, 0.f);
bw_bd_reduce_reset_coeffs(&instance->bd_reduce_coeffs);
}
void bw_example_fx_bitcrush_process(bw_example_fx_bitcrush *instance, const float** x, float** y, int n_samples) {
bw_sr_reduce_process(&instance->sr_reduce_coeffs, &instance->sr_reduce_state, x[0], y[0], n_samples);
bw_bd_reduce_process(&instance->bd_reduce_coeffs, y[0], y[0], n_samples);
}
void bw_example_fx_bitcrush_set_parameter(bw_example_fx_bitcrush *instance, int index, float value) {
instance->params[index] = value;
switch (index) {
case p_sr_ratio:
bw_sr_reduce_set_ratio(&instance->sr_reduce_coeffs, value);
break;
case p_bit_depth:
bw_bd_reduce_set_bit_depth(&instance->bd_reduce_coeffs, 1 + (int)(15.f * value));
break;
}
}
float bw_example_fx_bitcrush_get_parameter(bw_example_fx_bitcrush *instance, int index) {
return instance->params[index];
}

View File

@ -1,61 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2022, 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_FX_BITCRUSH_H
#define _BW_EXAMPLE_FX_BITCRUSH_H
#include "platform.h"
#include <bw_sr_reduce.h>
#include <bw_bd_reduce.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
p_sr_ratio,
p_bit_depth,
p_n
};
struct _bw_example_fx_bitcrush {
// Sub-components
bw_sr_reduce_coeffs sr_reduce_coeffs;
bw_sr_reduce_state sr_reduce_state;
bw_bd_reduce_coeffs bd_reduce_coeffs;
// Parameters
float params[p_n];
};
typedef struct _bw_example_fx_bitcrush bw_example_fx_bitcrush;
void bw_example_fx_bitcrush_init(bw_example_fx_bitcrush *instance);
void bw_example_fx_bitcrush_set_sample_rate(bw_example_fx_bitcrush *instance, float sample_rate);
void bw_example_fx_bitcrush_reset(bw_example_fx_bitcrush *instance);
void bw_example_fx_bitcrush_process(bw_example_fx_bitcrush *instance, const float** x, float** y, int n_samples);
void bw_example_fx_bitcrush_set_parameter(bw_example_fx_bitcrush *instance, int index, float value);
float bw_example_fx_bitcrush_get_parameter(bw_example_fx_bitcrush *instance, int index);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,6 @@
{
"cmd": {
"busIds": [ "input", "output" ],
"parameterIds": [ "sr_ratio", "bit_depth" ]
}
}

View File

@ -1,88 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2022, 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_fx_bitcrush"
#define PLUGIN_VERSION "1.0.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] = {
{ "Sample rate ratio", "SR ratio", "", 0, 0, 0, 1.f },
{ "Bit depth", "Bit depth", "", 0, 0, 14, 1.f }
};
// Internal API
#include "bw_example_fx_bitcrush.h"
#define P_TYPE bw_example_fx_bitcrush
#define P_INIT bw_example_fx_bitcrush_init
#define P_SET_SAMPLE_RATE bw_example_fx_bitcrush_set_sample_rate
#define P_RESET bw_example_fx_bitcrush_reset
#define P_PROCESS bw_example_fx_bitcrush_process
#define P_SET_PARAMETER bw_example_fx_bitcrush_set_parameter
#define P_GET_PARAMETER bw_example_fx_bitcrush_get_parameter
#endif

View File

@ -1,44 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
var buses = [
{
stereo: false,
output: false
},
{
stereo: false,
output: true
}
];
var parameters = [
{
name: "Sample rate ratio",
output: false,
defaultValue: 1.0
},
{
name: "Bit depth",
output: false,
defaultValue: 1.0,
step: 14
}
];

View File

@ -0,0 +1,5 @@
{
"daisy_seed": {
"parameterPins": [ 15, 16 ]
}
}

View File

@ -0,0 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.bw_example_fx_bitcrush"
}
}

View File

@ -0,0 +1,12 @@
{
"lv2": {
"prefixes": {
"bw_examples": "https://www.orastron.com/brickworks/examples/"
},
"uri": "@bw_examples:fx_bitcrush",
"types": [ "@lv2:DistortionPlugin" ],
"version": "1.0",
"busSymbols": [ "input", "output" ],
"parameterSymbols": [ "sr_ratio", "bit_depth" ]
}
}

View File

@ -0,0 +1,61 @@
#include "common.h"
#include <bw_sr_reduce.h>
#include <bw_bd_reduce.h>
typedef struct plugin {
bw_sr_reduce_coeffs sr_reduce_coeffs;
bw_sr_reduce_state sr_reduce_state;
bw_bd_reduce_coeffs bd_reduce_coeffs;
} plugin;
static void plugin_init(plugin *instance) {
bw_sr_reduce_init(&instance->sr_reduce_coeffs);
bw_bd_reduce_init(&instance->bd_reduce_coeffs);
}
static void plugin_fini(plugin *instance) {
(void)instance;
}
static void plugin_set_sample_rate(plugin *instance, float sample_rate) {
bw_sr_reduce_set_sample_rate(&instance->sr_reduce_coeffs, sample_rate);
bw_bd_reduce_set_sample_rate(&instance->bd_reduce_coeffs, sample_rate);
}
static size_t plugin_mem_req(plugin *instance) {
(void)instance;
return 0;
}
static void plugin_mem_set(plugin *instance, void *mem) {
(void)instance;
(void)mem;
}
static void plugin_reset(plugin *instance) {
bw_sr_reduce_reset_coeffs(&instance->sr_reduce_coeffs);
bw_sr_reduce_reset_state(&instance->sr_reduce_coeffs, &instance->sr_reduce_state, 0.f);
bw_bd_reduce_reset_coeffs(&instance->bd_reduce_coeffs);
}
static void plugin_set_parameter(plugin *instance, size_t index, float value) {
switch (index) {
case 0:
bw_sr_reduce_set_ratio(&instance->sr_reduce_coeffs, 0.01f * value);
break;
case 1:
bw_bd_reduce_set_bit_depth(&instance->bd_reduce_coeffs, (char)value);
break;
}
}
static float plugin_get_parameter(plugin *instance, size_t index) {
(void)instance;
(void)index;
return 0.f;
}
static void plugin_process(plugin *instance, const float **inputs, float **outputs, size_t n_samples) {
bw_sr_reduce_process(&instance->sr_reduce_coeffs, &instance->sr_reduce_state, inputs[0], outputs[0], n_samples);
bw_bd_reduce_process(&instance->bd_reduce_coeffs, outputs[0], outputs[0], n_samples);
}

View File

@ -0,0 +1,46 @@
{
"product": {
"name": "Brickworks bitcrusher example",
"version": "1.1.0",
"buildVersion": "1",
"bundleName": "bw_example_fx_bitcrush",
"buses": [
{
"type": "audio",
"direction": "input",
"channels": "mono",
"name": "Input",
"shortName": "Input"
},
{
"type": "audio",
"direction": "output",
"channels": "mono",
"name": "Output",
"shortName": "Output"
}
],
"parameters": [
{
"name": "Sample rate ratio",
"shortName": "SR ratio",
"direction": "input",
"defaultValue": 100.0,
"minimum": 1.0,
"maximum": 100.0,
"unit": "pc",
"map": "logarithmic"
},
{
"name": "Bit depth",
"shortName": "Bit depth",
"direction": "input",
"defaultValue": 16.0,
"minimum": 1.0,
"maximum": 16.0,
"integer": true,
"map": "linear"
}
]
}
}

View File

@ -0,0 +1,11 @@
{
"vst3": {
"plugin": {
"cid": "507f90bd31784719af91e9e778844400"
},
"controller": {
"cid": "e0f05d405b6c4bf48c4d4b6f5f93b365"
},
"subCategory": "Fx|Distortion"
}
}

View File

@ -1,9 +0,0 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
NAME := bw_example_fx_bitcrush
SOURCE := bw_example_fx_bitcrush.c
include ${ROOT_DIR}/../../common/vst3/vst3.mk
CXXFLAGS += -DRELEASE=1 -DNDEBUG -DBW_NO_DEBUG
#CXXFLAGS += -DDEVELOPMENT=1 -DBW_DEBUG_DEEP

View File

@ -1,36 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* File authors: Stefano D'Angelo, Paolo Marrone
*/
#ifndef _VST3_CONFIG_H
#define _VST3_CONFIG_H
#define PLUGIN_SUBCATEGORY "Fx"
#define PLUGIN_GUID_1 0x507f90bd
#define PLUGIN_GUID_2 0x31784719
#define PLUGIN_GUID_3 0xaf91e9e7
#define PLUGIN_GUID_4 0x78844400
#define CTRL_GUID_1 0xe0f05d40
#define CTRL_GUID_2 0x5b6c4bf4
#define CTRL_GUID_3 0x8c4d4b6f
#define CTRL_GUID_4 0x5f93b365
#endif

View File

@ -1,4 +0,0 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_bitcrush.c
include ${ROOT_DIR}/../../common/web/web.mk

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fxpp_ap1"
"productBundleIdentifier": "com.orastron.bw_example_fxpp_ap1"
}
}

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fxpp_ap2"
"productBundleIdentifier": "com.orastron.bw_example_fxpp_ap2"
}
}

View File

@ -1,5 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.fxpp_balance"
"productBundleIdentifier": "com.orastron.bw_example_fxpp_balance"
}
}

View File

@ -1,9 +1,9 @@
{
"product": {
"name": "Brickworks stereo balance example",
"name": "Brickworks stereo balance example (C++)",
"version": "1.1.0",
"buildVersion": "1",
"bundleName": "bw_example_fx_balance",
"bundleName": "bw_example_fxpp_balance",
"buses": [
{
"type": "audio",

View File

@ -0,0 +1,5 @@
{
"android": {
"javaPackageName": "com.orastron.bw_example_fxpp_bitcrush"
}
}

View File

@ -0,0 +1,6 @@
{
"cmd": {
"busIds": [ "input", "output" ],
"parameterIds": [ "sr_ratio", "bit_depth" ]
}
}

View File

@ -0,0 +1,5 @@
{
"daisy_seed": {
"parameterPins": [ 15, 16 ]
}
}

View File

@ -0,0 +1,62 @@
#include "impl.h"
#include "common.h"
#include <bw_sr_reduce.h>
#include <bw_bd_reduce.h>
using namespace Brickworks;
class Engine {
public:
SRReduce<1> sr;
BDReduce<1> bd;
};
extern "C" {
impl impl_new(void) {
return reinterpret_cast<impl>(new Engine());
}
void impl_free(impl handle) {
Engine *instance = reinterpret_cast<Engine *>(handle);
delete instance;
}
void impl_set_sample_rate(impl handle, float sample_rate) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->sr.setSampleRate(sample_rate);
instance->bd.setSampleRate(sample_rate);
}
void impl_reset(impl handle) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->sr.reset();
instance->bd.reset();
}
void impl_set_parameter(impl handle, size_t index, float value) {
Engine *instance = reinterpret_cast<Engine *>(handle);
switch (index) {
case 0:
instance->sr.setRatio(0.01f * value);
break;
case 1:
instance->bd.setBitDepth((char)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) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->sr.process(inputs, outputs, n_samples);
instance->bd.process(inputs, outputs, n_samples);
}
}

View File

@ -0,0 +1,5 @@
{
"ios": {
"productBundleIdentifier": "com.orastron.bw_example_fxpp_bitcrush"
}
}

View File

@ -0,0 +1,12 @@
{
"lv2": {
"prefixes": {
"bw_examples": "https://www.orastron.com/brickworks/examples/"
},
"uri": "@bw_examples:fxpp_bitcrush",
"types": [ "@lv2:DistortionPlugin" ],
"version": "1.0",
"busSymbols": [ "input", "output" ],
"parameterSymbols": [ "sr_ratio", "bit_depth" ]
}
}

View File

@ -0,0 +1,46 @@
{
"product": {
"name": "Brickworks bitcrusher example (C++)",
"version": "1.1.0",
"buildVersion": "1",
"bundleName": "bw_example_fxpp_bitcrush",
"buses": [
{
"type": "audio",
"direction": "input",
"channels": "mono",
"name": "Input",
"shortName": "Input"
},
{
"type": "audio",
"direction": "output",
"channels": "mono",
"name": "Output",
"shortName": "Output"
}
],
"parameters": [
{
"name": "Sample rate ratio",
"shortName": "SR ratio",
"direction": "input",
"defaultValue": 100.0,
"minimum": 1.0,
"maximum": 100.0,
"unit": "pc",
"map": "logarithmic"
},
{
"name": "Bit depth",
"shortName": "Bit depth",
"direction": "input",
"defaultValue": 16.0,
"minimum": 1.0,
"maximum": 16.0,
"integer": true,
"map": "linear"
}
]
}
}

View File

@ -0,0 +1,11 @@
{
"vst3": {
"plugin": {
"cid": "4ccc317bcbfd4dc0b2c0e24d00ef876d"
},
"controller": {
"cid": "f4fa2b0d358f4709855f940f76cec704"
},
"subCategory": "Fx|Distortion"
}
}

View File

@ -4,7 +4,7 @@ echo Removing common files
rm -fr common/cmd common/web common/daisy-seed common/lv2 common/vst3 common/android common/ios
dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1 fxpp_ap2 fxpp_balance"
dirs="fx_ap1 fx_ap2 fx_balance fx_bitcrush fxpp_ap1 fxpp_ap2 fxpp_balance fxpp_bitcrush"
for d in $dirs; do
echo Removing data files for $d

View File

@ -26,7 +26,7 @@ cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/android-make android
cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/ios ios && cd ..
cd common && $TIBIA_DIR/tibia --common $TIBIA_DIR/templates/ios-make ios && cd ..
dirs="fx_ap1 fx_ap2 fx_balance fxpp_ap1 fxpp_ap2 fxpp_balance"
dirs="fx_ap1 fx_ap2 fx_balance fx_bitcrush fxpp_ap1 fxpp_ap2 fxpp_balance fxpp_bitcrush"
for d in $dirs; do
echo Generating data files for $d