refactored bw_wah to new API + fixed fx examples

This commit is contained in:
Stefano D'Angelo 2022-11-23 11:38:41 +01:00
parent 3b8a4d7186
commit 6202235c48
11 changed files with 113 additions and 100 deletions

View File

@ -5,8 +5,8 @@
* Added bw_wah and bw_example_fx_wah. * Added bw_wah and bw_example_fx_wah.
* Added BW_RESTRICT and removed BW_MALLOC, BW_REALLOC, and BW_FREE from * Added BW_RESTRICT and removed BW_MALLOC, BW_REALLOC, and BW_FREE from
bw_common. bw_common.
* Renamed bw_example_fx to bw_example_fx_svf. * Renamed bw_example_fx to bw_example_fx_svf are removed output "Level"
* Removed output "Level" parameter from bw_example_fx_svf. parameter from it.
* Using correct "Fx|Filter" VST3 subcategory for bw_example_fx_svf. * Using correct "Fx|Filter" VST3 subcategory for bw_example_fx_svf.
* Using official logo as VST3 plugin icon. * Using official logo as VST3 plugin icon.

View File

@ -20,12 +20,6 @@
#ifndef _BW_CONFIG_H #ifndef _BW_CONFIG_H
#define _BW_CONFIG_H #define _BW_CONFIG_H
#include "walloc.h"
#define BW_MALLOC malloc
#define BW_REALLOC realloc
#define BW_FREE free
#define INFINITY (__builtin_inff()) #define INFINITY (__builtin_inff())
#endif #endif

View File

@ -20,7 +20,11 @@
#include "bw_example_fx_svf.h" #include "bw_example_fx_svf.h"
#include <bw_svf.h> #include <bw_svf.h>
#include <stdlib.h> #ifdef __WASM__
# include "walloc.h"
#else
# include <stdlib.h>
#endif
enum { enum {
p_cutoff, p_cutoff,

View File

@ -1,5 +1,6 @@
CC=clang CC=clang
CFLAGS= \ CFLAGS= \
-D__WASM__ \
-I${ROOT_DIR}/../src \ -I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/web \ -I${ROOT_DIR}/../../common/web \
-I${ROOT_DIR}/../../../include \ -I${ROOT_DIR}/../../../include \

View File

@ -19,8 +19,13 @@
#include "bw_example_fx_wah.h" #include "bw_example_fx_wah.h"
#include <bw_common.h>
#include <bw_wah.h> #include <bw_wah.h>
#ifdef __WASM__
# include "walloc.h"
#else
# include <stdlib.h>
#endif
enum { enum {
p_wah, p_wah,
@ -29,37 +34,39 @@ enum {
struct _bw_example_fx_wah { struct _bw_example_fx_wah {
// Sub-components // Sub-components
bw_wah wah; bw_wah_coeffs wah_coeffs;
bw_wah_state wah_state;
// Parameters // Parameters
float params[p_n]; float params[p_n];
}; };
bw_example_fx_wah bw_example_fx_wah_new() { bw_example_fx_wah bw_example_fx_wah_new() {
bw_example_fx_wah instance = (bw_example_fx_wah)BW_MALLOC(sizeof(struct _bw_example_fx_wah)); bw_example_fx_wah instance = (bw_example_fx_wah)malloc(sizeof(struct _bw_example_fx_wah));
if (instance != NULL) if (instance != NULL)
bw_wah_init(&instance->wah); bw_wah_init(&instance->wah_coeffs);
return instance; return instance;
} }
void bw_example_fx_wah_free(bw_example_fx_wah instance) { void bw_example_fx_wah_free(bw_example_fx_wah instance) {
BW_FREE(instance); free(instance);
} }
void bw_example_fx_wah_set_sample_rate(bw_example_fx_wah instance, float sample_rate) { void bw_example_fx_wah_set_sample_rate(bw_example_fx_wah instance, float sample_rate) {
bw_wah_set_sample_rate(&instance->wah, sample_rate); bw_wah_set_sample_rate(&instance->wah_coeffs, sample_rate);
} }
void bw_example_fx_wah_reset(bw_example_fx_wah instance) { void bw_example_fx_wah_reset(bw_example_fx_wah instance) {
bw_wah_reset(&instance->wah); bw_wah_reset_coeffs(&instance->wah_coeffs);
bw_wah_reset_state(&instance->wah_coeffs, &instance->wah_state);
} }
void bw_example_fx_wah_process(bw_example_fx_wah instance, const float** x, float** y, int n_samples) { void bw_example_fx_wah_process(bw_example_fx_wah instance, const float** x, float** y, int n_samples) {
bw_wah_process(&instance->wah, x[0], y[0], n_samples); bw_wah_process(&instance->wah_coeffs, &instance->wah_state, x[0], y[0], n_samples);
} }
void bw_example_fx_wah_set_parameter(bw_example_fx_wah instance, int index, float value) { void bw_example_fx_wah_set_parameter(bw_example_fx_wah instance, int index, float value) {
bw_wah_set_wah(&instance->wah, value); bw_wah_set_wah(&instance->wah_coeffs, value);
} }
float bw_example_fx_wah_get_parameter(bw_example_fx_wah instance, int index) { float bw_example_fx_wah_get_parameter(bw_example_fx_wah instance, int index) {

View File

@ -19,8 +19,6 @@ INSTALL_PREFIX=/usr/local
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \ SOURCES= \
${ROOT_DIR}/../../../src/bw_wah.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../src/bw_example_fx_wah.c \ ${ROOT_DIR}/../src/bw_example_fx_wah.c \
\ \
${ROOT_DIR}/../../common/vst3/entry.cpp \ ${ROOT_DIR}/../../common/vst3/entry.cpp \

View File

@ -17,8 +17,6 @@ LDFLAGS= \
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \ SOURCES= \
${ROOT_DIR}/../../../src/bw_wah.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../src/bw_example_fx_wah.c \ ${ROOT_DIR}/../src/bw_example_fx_wah.c \
\ \
${ROOT_DIR}/../../common/vst3/entry.cpp \ ${ROOT_DIR}/../../common/vst3/entry.cpp \

View File

@ -25,8 +25,6 @@ ARCH=x86_64
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \ SOURCES= \
${ROOT_DIR}/../../../src/bw_wah.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../src/bw_example_fx_wah.c \ ${ROOT_DIR}/../src/bw_example_fx_wah.c \
\ \
${ROOT_DIR}/../../common/vst3/entry.cpp \ ${ROOT_DIR}/../../common/vst3/entry.cpp \

View File

@ -1,5 +1,6 @@
CC=clang CC=clang
CFLAGS= \ CFLAGS= \
-D__WASM__ \
-I${ROOT_DIR}/../src \ -I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/web \ -I${ROOT_DIR}/../../common/web \
-I${ROOT_DIR}/../../../include \ -I${ROOT_DIR}/../../../include \
@ -25,8 +26,6 @@ LDFLAGS= \
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \ SOURCES= \
${ROOT_DIR}/../../../src/bw_wah.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../src/bw_example_fx_wah.c \ ${ROOT_DIR}/../src/bw_example_fx_wah.c \
${ROOT_DIR}/../../common/web/walloc.c \ ${ROOT_DIR}/../../common/web/walloc.c \
${ROOT_DIR}/../../common/web/wrapper.c ${ROOT_DIR}/../../common/web/wrapper.c

View File

@ -20,7 +20,7 @@
/*! /*!
* module_type {{{ dsp }}} * module_type {{{ dsp }}}
* version {{{ 0.2.0 }}} * version {{{ 0.2.0 }}}
* requires {{{ bw_config bw_common bw_one_pole bw_math bw_wah }}} * requires {{{ bw_config bw_common bw_one_pole bw_math bw_svf }}}
* description {{{ * description {{{
* Wah effect. * Wah effect.
* *
@ -44,42 +44,51 @@
extern "C" { extern "C" {
#endif #endif
/*! api {{{ #include <bw_common.h>
* #### bw_wah
* ```>>> */
typedef struct _bw_wah bw_wah;
/*! <<<```
* Instance object.
* >>> */
/*! ... /*! api {{{
* #### bw_wah_coeffs
* ```>>> */
typedef struct _bw_wah_coeffs bw_wah_coeffs;
/*! <<<```
* Coefficients.
*
* ### bw_svf_state
* ```>>> */
typedef struct _bw_wah_state bw_wah_state;
/*! <<<```
* State.
*
* #### bw_wah_init() * #### bw_wah_init()
* ```>>> */ * ```>>> */
void bw_wah_init(bw_wah *instance); static inline void bw_wah_init(bw_wah_coeffs *BW_RESTRICT coeffs);
/*! <<<``` /*! <<<```
* Initializes the `instance` object. * Initializes `coeffs`.
* >>> */ *
/*! ...
* #### bw_wah_set_sample_rate() * #### bw_wah_set_sample_rate()
* ```>>> */ * ```>>> */
void bw_wah_set_sample_rate(bw_wah *instance, float sample_rate); static inline void bw_wah_set_sample_rate(bw_wah_coeffs *BW_RESTRICT coeffs, float sample_rate);
/*! <<<``` /*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`. * Sets the `sample_rate` (Hz) value for the given `coeffs`.
*
* #### bw_wah_reset_state()
* ```>>> */
static inline void bw_wah_reset_state(const bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state);
/*! <<<```
* Resets the given `state` to the initial state using the given `coeffs`.
* >>> */ * >>> */
/*! ... static inline void bw_wah_reset_coeffs(bw_wah_coeffs *BW_RESTRICT coeffs);
* #### bw_wah_reset()
* ```>>> */ static inline void bw_wah_update_coeffs_ctrl(bw_wah_coeffs *BW_RESTRICT coeffs);
void bw_wah_reset(bw_wah *instance); static inline void bw_wah_update_coeffs_audio(bw_wah_coeffs *BW_RESTRICT coeffs);
/*! <<<```
* Resets the given `instance` to its initial state. static inline float bw_wah_process1(const bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state, float x);
* >>> */
/*! ... /*! ...
* #### bw_wah_process() * #### bw_wah_process()
* ```>>> */ * ```>>> */
void bw_wah_process(bw_wah *instance, const float *x, float *y, int n_samples); static inline void bw_wah_process(bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
/*! <<<``` /*! <<<```
* Lets the given `instance` process `n_samples` samples from the input * Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output * buffer `x` and fills the corresponding `n_samples` samples in the output
@ -89,7 +98,7 @@ void bw_wah_process(bw_wah *instance, const float *x, float *y, int n_samples);
/*! ... /*! ...
* #### bw_wah_set_wah() * #### bw_wah_set_wah()
* ```>>> */ * ```>>> */
void bw_wah_set_wah(bw_wah *instance, float value); static inline void bw_wah_set_wah(bw_wah_coeffs *BW_RESTRICT coeffs, float value);
/*! <<<``` /*! <<<```
* Sets the wah pedal position to the given `value` in [`0.f` (low cutoff), * Sets the wah pedal position to the given `value` in [`0.f` (low cutoff),
* `1.f` (high cutoff)]. * `1.f` (high cutoff)].
@ -97,16 +106,65 @@ void bw_wah_set_wah(bw_wah *instance, float value);
* Default value: `0.5f`. * Default value: `0.5f`.
* }}} */ * }}} */
/*** Implementation ***/
/* 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. */
#include <bw_svf.h> #include <bw_svf.h>
/* WARNING: the internal definition of this struct is not part of the public struct _bw_wah_coeffs {
* API. Its content may change at any time in future versions. Please, do not
* access its members directly. */
struct _bw_wah {
// Sub-components // Sub-components
bw_svf svf; bw_svf_coeffs svf_coeffs;
}; };
struct _bw_wah_state {
// Sub-components
bw_svf_state svf_state;
};
static inline void bw_wah_init(bw_wah_coeffs *BW_RESTRICT coeffs) {
bw_svf_init(&coeffs->svf_coeffs);
bw_wah_set_wah(coeffs, 0.5f);
bw_svf_set_Q(&coeffs->svf_coeffs, 9.f);
}
static inline void bw_wah_set_sample_rate(bw_wah_coeffs *BW_RESTRICT coeffs, float sample_rate) {
bw_svf_set_sample_rate(&coeffs->svf_coeffs, sample_rate);
}
static inline void bw_wah_reset_coeffs(bw_wah_coeffs *BW_RESTRICT coeffs) {
bw_svf_reset_coeffs(&coeffs->svf_coeffs);
}
static inline void bw_wah_reset_state(const bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state) {
bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state);
}
static inline void bw_wah_update_coeffs_ctrl(bw_wah_coeffs *BW_RESTRICT coeffs) {
bw_svf_update_coeffs_ctrl(&coeffs->svf_coeffs);
}
static inline void bw_wah_update_coeffs_audio(bw_wah_coeffs *BW_RESTRICT coeffs) {
bw_svf_update_coeffs_audio(&coeffs->svf_coeffs);
}
static inline float bw_wah_process1(const bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state, float x) {
return bw_svf_process1_bp(&coeffs->svf_coeffs, &state->svf_state, x);
}
static inline void bw_wah_process(bw_wah_coeffs *BW_RESTRICT coeffs, bw_wah_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
bw_wah_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
bw_wah_update_coeffs_audio(coeffs);
y[i] = bw_wah_process1(coeffs, state, x[i]);
}
}
static inline void bw_wah_set_wah(bw_wah_coeffs *BW_RESTRICT coeffs, float value) {
bw_svf_set_cutoff(&coeffs->svf_coeffs, 400.f + (2e3f - 400.f) * value * value * value);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #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
*
* File author: Stefano D'Angelo
*/
#include <bw_wah.h>
#include <bw_common.h>
void bw_wah_init(bw_wah *instance) {
bw_svf_init(&instance->svf);
bw_wah_set_wah(instance, 0.5f);
bw_svf_set_Q(&instance->svf, 9.f);
}
void bw_wah_set_sample_rate(bw_wah *instance, float sample_rate) {
bw_svf_set_sample_rate(&instance->svf, sample_rate);
}
void bw_wah_reset(bw_wah *instance) {
bw_svf_reset(&instance->svf);
}
void bw_wah_process(bw_wah *instance, const float *x, float *y, int n_samples) {
bw_svf_process(&instance->svf, x, NULL, y, NULL, n_samples);
}
void bw_wah_set_wah(bw_wah *instance, float value) {
bw_svf_set_cutoff(&instance->svf, 400.f + (2e3f - 400.f) * value * value * value);
}