bw_delay progress + fx_delay + add dynamic mem to common + bw_buf fix new stuff

This commit is contained in:
Stefano D'Angelo 2023-03-05 08:33:45 +01:00
parent 1f1571177a
commit 9dcfb2de30
17 changed files with 393 additions and 8 deletions

1
TODO
View File

@ -30,6 +30,7 @@ code:
* sqrt(0) and corner cases, common strategy?
* MEM_REQ_ROUGH() macro?
* use BW_SIZE_T, check constant types
* web examples: need to export memset?
build system:
* make makefiles handle paths with spaces etc

View File

@ -68,6 +68,9 @@ int main() {
P_INIT(&instance);
P_SET_SAMPLE_RATE(&instance, sample_rate);
#ifdef P_MEM_REQ
P_MEM_SET(&instance, (void *)0xC0000000);
#endif
hardware.StartLog();

View File

@ -43,6 +43,9 @@ int main() {
P_INIT(&instance);
P_SET_SAMPLE_RATE(&instance, sample_rate);
#ifdef P_MEM_REQ
P_MEM_SET(&instance, (void *)0xC0000000);
#endif
// hardware.StartLog();

View File

@ -50,6 +50,7 @@
#include "base/source/fstreamer.h"
#include "common.h"
#include <stdlib.h>
#include <algorithm>
#if defined(__aarch64__)
@ -192,6 +193,10 @@ tresult PLUGIN_API Plugin::initialize(FUnknown *context) {
}
#endif
#ifdef P_MEM_REQ
this->mem = NULL;
#endif
return kResultTrue;
}
@ -202,8 +207,26 @@ tresult PLUGIN_API Plugin::terminate() {
tresult PLUGIN_API Plugin::setActive(TBool state) {
if (state) {
P_SET_SAMPLE_RATE(&instance, sampleRate);
#ifdef P_MEM_REQ
size_t req = P_MEM_REQ(&instance);
if (req) {
void *mem = malloc(req);
if (mem == NULL)
return kResultFalse;
P_MEM_SET(&instance, mem);
this->mem = mem;
}
#endif
P_RESET(&instance);
}
#ifdef P_MEM_REQ
else {
if (this->mem) {
free(this->mem);
this->mem = NULL;
}
}
#endif
return AudioEffect::setActive(state);
}

View File

@ -60,6 +60,10 @@ private:
#if NUM_BUSES_OUT != 0
float *outputs[NUM_CHANNELS_OUT];
#endif
#ifdef P_MEM_REQ
void *mem;
#endif
};
#endif

View File

@ -35,6 +35,9 @@ struct _wrapper {
#if NUM_PARAMETERS != 0
float param_values[NUM_PARAMETERS];
#endif
#ifdef P_MEM_REQ
void *mem;
#endif
};
typedef struct _wrapper *wrapper;
@ -83,12 +86,28 @@ wrapper wrapper_new(float sample_rate) {
#endif
P_SET_SAMPLE_RATE(&ret->instance, sample_rate);
#ifdef P_MEM_REQ
size_t req = P_MEM_REQ(&ret->instance);
if (req) {
ret->mem = malloc(req);
if (ret->mem == NULL) {
free(ret);
return NULL;
}
P_MEM_SET(&ret->instance, ret->mem);
} else
ret->mem = NULL;
#endif
P_RESET(&ret->instance);
return ret;
}
void wrapper_free(wrapper w) {
#ifdef P_MEM_REQ
if (w->mem)
free(w->mem);
#endif
free(w);
}

View File

@ -0,0 +1,7 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TARGET = bw_example_fx_delay
C_SOURCES += ${ROOT_DIR}/../src/bw_example_fx_delay.c
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,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
*/
#include "bw_example_fx_delay.h"
void bw_example_fx_delay_init(bw_example_fx_delay *instance) {
bw_delay_init(&instance->delay_coeffs);
}
void bw_example_fx_delay_set_sample_rate(bw_example_fx_delay *instance, float sample_rate) {
bw_delay_set_sample_rate(&instance->delay_coeffs, sample_rate);
}
BW_SIZE_T bw_example_fx_delay_mem_req(bw_example_fx_delay *instance) {
return bw_delay_mem_req(&instance->delay_coeffs, 1.f);
}
void bw_example_fx_delay_mem_set(bw_example_fx_delay *instance, void *mem) {
bw_delay_mem_set(&instance->delay_state, mem);
}
void bw_example_fx_delay_reset(bw_example_fx_delay *instance) {
bw_delay_reset_coeffs(&instance->delay_coeffs);
bw_delay_reset_state(&instance->delay_coeffs, &instance->delay_state);
}
void bw_example_fx_delay_process(bw_example_fx_delay *instance, const float** x, float** y, int n_samples) {
bw_delay_process(&instance->delay_coeffs, &instance->delay_state, x[0], y[0], n_samples);
}
void bw_example_fx_delay_set_parameter(bw_example_fx_delay *instance, int index, float value) {
instance->params[index] = value;
bw_delay_set_delay(&instance->delay_coeffs, value);
}
float bw_example_fx_delay_get_parameter(bw_example_fx_delay *instance, int index) {
return instance->params[index];
}

View File

@ -0,0 +1,61 @@
/*
* 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_FX_DELAY_H
#define _BW_EXAMPLE_FX_DELAY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <bw_delay.h>
enum {
p_delay,
p_n
};
struct _bw_example_fx_delay {
// Sub-components
bw_delay_coeffs delay_coeffs;
bw_delay_state delay_state;
// Parameters
float params[p_n];
// Memory
void *mem;
};
typedef struct _bw_example_fx_delay bw_example_fx_delay;
void bw_example_fx_delay_init(bw_example_fx_delay *instance);
void bw_example_fx_delay_set_sample_rate(bw_example_fx_delay *instance, float sample_rate);
BW_SIZE_T bw_example_fx_delay_mem_req(bw_example_fx_delay *instance);
void bw_example_fx_delay_mem_set(bw_example_fx_delay *instance, void *mem);
void bw_example_fx_delay_reset(bw_example_fx_delay *instance);
void bw_example_fx_delay_process(bw_example_fx_delay *instance, const float** x, float** y, int n_samples);
void bw_example_fx_delay_set_parameter(bw_example_fx_delay *instance, int index, float value);
float bw_example_fx_delay_get_parameter(bw_example_fx_delay *instance, int index);
#ifdef __cplusplus
}
#endif
#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_fx_delay"
#define PLUGIN_VERSION "0.4.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 1
static struct config_parameter config_parameters[NUM_PARAMETERS] = {
{ "Delay", "Delay", "", 0, 0, 0, 0.f },
};
// Internal API
#include "bw_example_fx_delay.h"
#define P_TYPE bw_example_fx_delay
#define P_INIT bw_example_fx_delay_init
#define P_SET_SAMPLE_RATE bw_example_fx_delay_set_sample_rate
#define P_MEM_REQ bw_example_fx_delay_mem_req
#define P_MEM_SET bw_example_fx_delay_mem_set
#define P_RESET bw_example_fx_delay_reset
#define P_PROCESS bw_example_fx_delay_process
#define P_SET_PARAMETER bw_example_fx_delay_set_parameter
#define P_GET_PARAMETER bw_example_fx_delay_get_parameter
#endif

View File

@ -0,0 +1,6 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
NAME := bw_example_fx_delay
SOURCES = ${SOURCES_COMMON} ${ROOT_DIR}/../src/bw_example_fx_delay.c
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|Delay"
#define PLUGIN_GUID_1 0x30a47806
#define PLUGIN_GUID_2 0x850f445c
#define PLUGIN_GUID_3 0x9f13660d
#define PLUGIN_GUID_4 0x0e26f2dc
#define CTRL_GUID_1 0xfd1e3d99
#define CTRL_GUID_2 0xd2cb4d57
#define CTRL_GUID_3 0x82e54aaf
#define CTRL_GUID_4 0x5e1a5bd5
#endif

View File

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

View File

@ -0,0 +1,38 @@
/*
* 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
*/
var buses = [
{
stereo: false,
output: false
},
{
stereo: false,
output: true
}
];
var parameters = [
{
name: "Delay",
output: false,
defaultValue: 0.0
}
];

View File

@ -53,7 +53,7 @@ extern "C" {
/*! api {{{
* #### bw_buf_fill()
* ```>>> */
static inline voide bw_buf_fill(float *dest, float k, int n_elems);
static inline void bw_buf_fill(float *dest, float k, int n_elems);
/*! <<<```
* Sets the first `n_elems` in `dest` to `k`.
*
@ -91,7 +91,7 @@ static inline void bw_buf_mul(float *dest, const float *src1, const float *src2,
/* WARNING: This part of the file is not part of the public API. Its content may
* change at any time in future versions. Please, do not use it directly. */
static inline voide bw_buf_fill(float *dest, float k, int n_elems) {
static inline void bw_buf_fill(float *dest, float k, int n_elems) {
for (int i = 0; i < n_elems; i++)
dest[i] = k;
}

View File

@ -161,7 +161,7 @@ static inline void bw_delay_set_sample_rate(bw_delay_coeffs *BW_RESTRICT coeffs,
}
static inline BW_SIZE_T bw_delay_mem_req(bw_delay_coeffs *BW_RESTRICT coeffs, float max_delay) {
return (BW_SIZE_T)bw_ceilf(coeffs->fs * max_delay) + 1;
return ((BW_SIZE_T)bw_ceilf(coeffs->fs * max_delay) + 1) * sizeof(float);
}
static inline void bw_delay_mem_set(bw_delay_state *BW_RESTRICT state, void *mem) {
@ -172,7 +172,7 @@ static inline void bw_delay_reset_coeffs(bw_delay_coeffs *BW_RESTRICT coeffs) {
}
static inline void bw_delay_reset_state(const bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state) {
bw_buf_fill(state->buf, 0.f, size->len);
bw_buf_fill(state->buf, 0.f, state->len);
state->idx = 0;
}
@ -188,18 +188,18 @@ static inline float bw_delay_process1(const bw_delay_coeffs *BW_RESTRICT coeffs,
const float f = bw_floorf(s);
const float d = coeffs->delay - f;
const BW_SIZE_T j = (BW_SIZE_T)d;
const BW_SIZE_T l = (state->idx >= d ? state->idx : state->idx + state->len) - d;
const BW_SIZE_T l = (state->idx >= j ? state->idx : state->idx + state->len) - j;
const BW_SIZE_T h = l == state->len - 1 ? 0 : l + 1;
const BW_SIZE_T n = state->idx == state->len - 1 ? 0 : state->idx + 1;
state->buf[idx] = x;
const float y = state->buf[state->idx] + d * (state->buf[n] - state->buf[state->idx]);
state->buf[state->idx] = x;
const float y = state->buf[l] + d * (state->buf[h] - state->buf[l]);
state->idx = n;
return y;
}
static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
for (int i = 0; i < n_samples; i++)
y[i] = bw_delay_process1(coeffs, state, x[i];
y[i] = bw_delay_process1(coeffs, state, x[i]);
}
static inline void bw_delay_set_delay(bw_delay_coeffs *BW_RESTRICT coeffs, float value) {