bw_iir{1,2} fixes + fx_iir{1,2} examples

This commit is contained in:
Stefano D'Angelo 2025-01-28 09:33:51 +01:00
parent 1be6e06699
commit f58353bc20
16 changed files with 431 additions and 8 deletions

View File

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

View File

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

View File

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

View File

@ -0,0 +1,10 @@
{
"lv2": {
"prefixes": {
"bw_examples": "https://www.orastron.com/brickworks/examples/"
},
"uri": "@bw_examples:fx_iir1",
"types": [ "@lv2:FilterPlugin" ],
"version": "0.0"
}
}

View File

@ -0,0 +1,93 @@
/*
* Brickworks
*
* Copyright (C) 2025 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 "common.h"
#include <bw_iir1.h>
typedef struct plugin {
float sample_rate;
float cutoff;
float coeff_x;
float coeff_lp;
float s;
float b0;
float b1;
float a1;
char to_reset;
} plugin;
static void plugin_init(plugin *instance, plugin_callbacks *cbs) {
(void)instance;
(void)cbs;
}
static void plugin_fini(plugin *instance) {
(void)instance;
}
static void plugin_set_sample_rate(plugin *instance, float sample_rate) {
instance->sample_rate = 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_iir1_coeffs_mm1(instance->sample_rate, instance->cutoff, instance->cutoff, instance->coeff_x, instance->coeff_lp, &instance->b0, &instance->b1, &instance->a1);
float y;
bw_iir1_reset(0.f, &y, &instance->s, instance->b0, instance->b1, instance->a1);
instance->to_reset = 0;
}
static void plugin_set_parameter(plugin *instance, size_t index, float value) {
switch (index) {
case plugin_parameter_cutoff:
instance->cutoff = value;
instance->to_reset = 1;
break;
case plugin_parameter_in:
instance->coeff_x = value;
instance->to_reset = 1;
break;
case plugin_parameter_lp:
instance->coeff_lp = value;
instance->to_reset = 1;
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) {
if (instance->to_reset)
plugin_reset(instance);
bw_iir1_process(inputs[0], outputs[0], &instance->s, instance->b0, instance->b1, instance->a1, n_samples);
}

View File

@ -0,0 +1,59 @@
{
"product": {
"name": "Brickworks 1st-order IIR filter example",
"version": "1.0.0",
"buildVersion": "1",
"bundleName": "bw_example_fx_iir1",
"buses": [
{
"type": "audio",
"direction": "input",
"channels": "mono",
"name": "Input",
"shortName": "Input",
"id": "input"
},
{
"type": "audio",
"direction": "output",
"channels": "mono",
"name": "Output",
"shortName": "Output",
"id": "output"
}
],
"parameters": [
{
"name": "Cutoff",
"shortName": "Cutoff",
"id": "cutoff",
"direction": "input",
"defaultValue": 1000.0,
"minimum": 20.0,
"maximum": 20000.0,
"unit": "hz",
"map": "logarithmic"
},
{
"name": "Input coefficient",
"shortName": "In coeff",
"id": "in",
"direction": "input",
"defaultValue": 1.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
},
{
"name": "Lowpass coefficient",
"shortName": "LP coeff",
"id": "lp",
"direction": "input",
"defaultValue": 0.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
}
]
}
}

View File

@ -0,0 +1,11 @@
{
"vst3": {
"plugin": {
"cid": "0c511d73a6de41dabd8b3658c0b10ad9"
},
"controller": {
"cid": "dfc802ba451349e48c2166fbb624113a"
},
"subCategory": "Fx|Filter"
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,10 @@
{
"lv2": {
"prefixes": {
"bw_examples": "https://www.orastron.com/brickworks/examples/"
},
"uri": "@bw_examples:fx_iir2",
"types": [ "@lv2:FilterPlugin" ],
"version": "0.0"
}
}

View File

@ -0,0 +1,110 @@
/*
* Brickworks
*
* Copyright (C) 2025 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 "common.h"
#include <bw_iir2.h>
typedef struct plugin {
float sample_rate;
float cutoff;
float q;
float coeff_x;
float coeff_lp;
float coeff_bp;
float coeff_hp;
float s1;
float s2;
float b0;
float b1;
float b2;
float a1;
float a2;
char to_reset;
} plugin;
static void plugin_init(plugin *instance, plugin_callbacks *cbs) {
(void)instance;
(void)cbs;
}
static void plugin_fini(plugin *instance) {
(void)instance;
}
static void plugin_set_sample_rate(plugin *instance, float sample_rate) {
instance->sample_rate = 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_iir2_coeffs_mm2(instance->sample_rate, instance->cutoff, instance->q, instance->cutoff, instance->coeff_x, instance->coeff_lp, instance->coeff_bp, instance->coeff_hp, &instance->b0, &instance->b1, &instance->b2, &instance->a1, &instance->a2);
float y;
bw_iir2_reset(0.f, &y, &instance->s1, &instance->s2, instance->b0, instance->b1, instance->b2, instance->a1, instance->a2);
}
static void plugin_set_parameter(plugin *instance, size_t index, float value) {
switch (index) {
case plugin_parameter_cutoff:
instance->cutoff = value;
instance->to_reset = 1;
break;
case plugin_parameter_q:
instance->q = value;
instance->to_reset = 1;
break;
case plugin_parameter_in:
instance->coeff_x = value;
instance->to_reset = 1;
break;
case plugin_parameter_lp:
instance->coeff_lp = value;
instance->to_reset = 1;
break;
case plugin_parameter_bp:
instance->coeff_bp = value;
instance->to_reset = 1;
break;
case plugin_parameter_hp:
instance->coeff_hp = value;
instance->to_reset = 1;
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) {
if (instance->to_reset)
plugin_reset(instance);
bw_iir2_process(inputs[0], outputs[0], &instance->s1, &instance->s2, instance->b0, instance->b1, instance->b2, instance->a1, instance->a2, n_samples);
}

View File

@ -0,0 +1,89 @@
{
"product": {
"name": "Brickworks 2nd-order IIR filter example",
"version": "1.0.0",
"buildVersion": "1",
"bundleName": "bw_example_fx_iir2",
"buses": [
{
"type": "audio",
"direction": "input",
"channels": "mono",
"name": "Input",
"shortName": "Input",
"id": "input"
},
{
"type": "audio",
"direction": "output",
"channels": "mono",
"name": "Output",
"shortName": "Output",
"id": "output"
}
],
"parameters": [
{
"name": "Cutoff",
"shortName": "Cutoff",
"id": "cutoff",
"direction": "input",
"defaultValue": 1000.0,
"minimum": 20.0,
"maximum": 20000.0,
"unit": "hz",
"map": "logarithmic"
},
{
"name": "Q",
"shortName": "Q",
"id": "q",
"direction": "input",
"defaultValue": 0.5,
"minimum": 0.5,
"maximum": 10.0,
"map": "linear"
},
{
"name": "Input coefficient",
"shortName": "In coeff",
"id": "in",
"direction": "input",
"defaultValue": 1.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
},
{
"name": "Lowpass coefficient",
"shortName": "LP coeff",
"id": "lp",
"direction": "input",
"defaultValue": 0.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
},
{
"name": "Bandpass coefficient",
"shortName": "BP coeff",
"id": "bp",
"direction": "input",
"defaultValue": 0.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
},
{
"name": "Highpass coefficient",
"shortName": "HP coeff",
"id": "hp",
"direction": "input",
"defaultValue": 0.0,
"minimum": -1.0,
"maximum": 1.0,
"map": "linear"
}
]
}
}

View File

@ -0,0 +1,11 @@
{
"vst3": {
"plugin": {
"cid": "b7c897b2e3984dc7b13c6d6507c766a5"
},
"controller": {
"cid": "00f0578ef0894a90a02427cbde067b8c"
},
"subCategory": "Fx|Filter"
}
}

View File

@ -263,11 +263,11 @@ static inline void bw_iir1_reset_multi(
if (y_0 != BW_NULL) {
if (s_0 != BW_NULL)
for (size_t i = 0; i < n_channels; i++)
bw_iir1_reset(x_0[i], y0 + i, s_0 + i, b0, b1, a1);
bw_iir1_reset(x_0[i], y_0 + i, s_0 + i, b0, b1, a1);
else
for (size_t i = 0; i < n_channels; i++) {
float v_s;
bw_iir1_reset(x_0[i], y0 + i, &v_s, b0, b1, a1);
bw_iir1_reset(x_0[i], y_0 + i, &v_s, b0, b1, a1);
}
} else {
if (s_0 != BW_NULL)
@ -276,7 +276,7 @@ static inline void bw_iir1_reset_multi(
bw_iir1_reset(x_0[i], &v_y, s_0 + i, b0, b1, a1);
}
else
; // no need to do anything
{} // no need to do anything
}
}
@ -343,7 +343,7 @@ static inline void bw_iir1_coeffs_hp1(
float * BW_RESTRICT b1,
float * BW_RESTRICT a1) {
BW_IIR1_COEFFS_COMMON
*b0 = d * prewarp_freq;
*b0 = d * (k - prewarp_freq);
*b1 = -*b0;
}
@ -421,8 +421,8 @@ static inline void bw_iir1_coeffs_mm1(
float * BW_RESTRICT b1,
float * BW_RESTRICT a1) {
BW_IIR1_COEFFS_COMMON
const float k2 = coeff_x * prewarp_freq;
const float k3 = coeff_lp * k;
const float k2 = prewarp_freq * coeff_x;
const float k3 = k * (coeff_lp + coeff_x);
*b0 = d * (k3 + k2);
*b1 = d * (k3 - k2);
}

View File

@ -443,7 +443,7 @@ static inline void bw_iir2_reset_multi(
bw_iir2_reset(x_0[i], &v_y, &v_s1, s2_0 + i, b0, b1, b2, a1, a2);
}
else
; // no need to do anything
{} // no need to do anything
}
}
}
@ -625,7 +625,7 @@ static inline void bw_iir2_coeffs_ls2_lin(
BW_IIR2_COEFFS_COMMON
const float k6 = k3 * (dc_gain_lin - sg);
const float k7 = Q * (k6 + k1);
const float k8 = k4 * sg
const float k8 = k4 * sg;
*b0 = d * (k7 + k8);
*b1 = d * (Q + Q) * (k6 - k1);
*b2 = d * (k7 - k8);