From a5e4fa0c76c44dcbef7efdb14e1a7f3766f44eaa Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sun, 13 Aug 2023 11:18:45 +0200 Subject: [PATCH] polished bw_{reverb,ringmod,satur,slew_lim,sr_reduce,trem} + removed bwpps + fixed examples --- TODO | 1 + .../src/bw_example_fxpp_bitcrush.h | 2 +- .../fxpp_reverb/src/bw_example_fxpp_reverb.h | 2 +- .../fxpp_satur/src/bw_example_fxpp_satur.h | 2 +- .../src/bw_example_fxpp_slew_lim.h | 2 +- examples/fxpp_trem/src/bw_example_fxpp_trem.h | 2 +- include/bw_reverb.h | 195 +++++++++++++++--- include/bw_ringmod.h | 115 +++++++++-- include/bw_satur.h | 147 +++++++++++-- include/bw_slew_lim.h | 182 ++++++++++++---- include/bw_sr_reduce.h | 112 ++++++++-- include/bw_trem.h | 127 ++++++++++-- include/bwpp_reverb.h | 139 ------------- include/bwpp_ringmod.h | 91 -------- include/bwpp_satur.h | 107 ---------- include/bwpp_slew_lim.h | 114 ---------- include/bwpp_sr_reduce.h | 88 -------- include/bwpp_trem.h | 101 --------- 18 files changed, 757 insertions(+), 772 deletions(-) delete mode 100644 include/bwpp_reverb.h delete mode 100644 include/bwpp_ringmod.h delete mode 100644 include/bwpp_satur.h delete mode 100644 include/bwpp_slew_lim.h delete mode 100644 include/bwpp_sr_reduce.h delete mode 100644 include/bwpp_trem.h diff --git a/TODO b/TODO index 52d688d..e465f16 100644 --- a/TODO +++ b/TODO @@ -46,6 +46,7 @@ code: * modulation vs process (multi) no update (post 1.0.0)??? * check assumptions w.r.t. usage of math functions * extern "C" in a macro to be individually applied (easier #include) +* x_0 vs y_z1 (eg svf vs one_pole/slew_lim) build system: * single header generation (vs modules in bwp... to think about) diff --git a/examples/fxpp_bitcrush/src/bw_example_fxpp_bitcrush.h b/examples/fxpp_bitcrush/src/bw_example_fxpp_bitcrush.h index 366a88e..d004279 100644 --- a/examples/fxpp_bitcrush/src/bw_example_fxpp_bitcrush.h +++ b/examples/fxpp_bitcrush/src/bw_example_fxpp_bitcrush.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include #include using namespace Brickworks; diff --git a/examples/fxpp_reverb/src/bw_example_fxpp_reverb.h b/examples/fxpp_reverb/src/bw_example_fxpp_reverb.h index bbafa01..dab6f69 100644 --- a/examples/fxpp_reverb/src/bw_example_fxpp_reverb.h +++ b/examples/fxpp_reverb/src/bw_example_fxpp_reverb.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/fxpp_satur/src/bw_example_fxpp_satur.h b/examples/fxpp_satur/src/bw_example_fxpp_satur.h index 3040757..7d09711 100644 --- a/examples/fxpp_satur/src/bw_example_fxpp_satur.h +++ b/examples/fxpp_satur/src/bw_example_fxpp_satur.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include #include using namespace Brickworks; diff --git a/examples/fxpp_slew_lim/src/bw_example_fxpp_slew_lim.h b/examples/fxpp_slew_lim/src/bw_example_fxpp_slew_lim.h index 6419325..fadd06a 100644 --- a/examples/fxpp_slew_lim/src/bw_example_fxpp_slew_lim.h +++ b/examples/fxpp_slew_lim/src/bw_example_fxpp_slew_lim.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/fxpp_trem/src/bw_example_fxpp_trem.h b/examples/fxpp_trem/src/bw_example_fxpp_trem.h index bf98c16..9542c2f 100644 --- a/examples/fxpp_trem/src/bw_example_fxpp_trem.h +++ b/examples/fxpp_trem/src/bw_example_fxpp_trem.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/include/bw_reverb.h b/include/bw_reverb.h index 3fb4959..5e0945c 100644 --- a/include/bw_reverb.h +++ b/include/bw_reverb.h @@ -39,6 +39,15 @@ *
    *
  • Now using size_t instead of * BW_SIZE_T.
  • + *
  • bw_reverb_process() and + * bw_reverb_process_multi() now use + * size_t to count samples and channels.
  • + *
  • Added more const specifiers to input + * arguments.
  • + *
  • Moved C++ code to C header.
  • + *
  • Added overladed C++ process() function taking + * C-style arrays as arguments.
  • + *
  • Removed usage of reserved identifiers.
  • *
* *
  • Version 0.6.0: @@ -55,8 +64,8 @@ * }}} */ -#ifndef _BW_REVERB_H -#define _BW_REVERB_H +#ifndef BW_REVERB_H +#define BW_REVERB_H #include @@ -67,13 +76,13 @@ extern "C" { /*! api {{{ * #### bw_reverb_coeffs * ```>>> */ -typedef struct _bw_reverb_coeffs bw_reverb_coeffs; +typedef struct bw_reverb_coeffs bw_reverb_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_reverb_state * ```>>> */ -typedef struct _bw_reverb_state bw_reverb_state; +typedef struct bw_reverb_state bw_reverb_state; /*! <<<``` * Internal state and related. * @@ -128,15 +137,15 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c * * #### bw_reverb_process1() * ```>>> */ -static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float xl, float xr, float *yl, float *yr); +static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float x_l, float x_r, float *y_l, float *y_r); /*! <<<``` - * Processes one set of input samples `xl` (left) and `xr` (right) using + * Processes one set of input samples `x_l` (left) and `x_r` (right) using * `coeffs`, while using and updating `state`. The left and right output - * samples are put into `yl` (left) and `yr` (right) respectively. + * samples are put into `y_l` (left) and `y_r` (right) respectively. * * #### bw_reverb_process() * ```>>> */ -static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *xl, const float *xr, float *yl, float *yr, int n_samples); +static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *x_l, const float *x_r, float *y_l, float *y_r, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffers `xl` (left) and `xr` * (right) and fills the first `n_samples` of the output buffers `yl` (left) @@ -145,11 +154,11 @@ static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_re * * #### bw_reverb_process_multi() * ```>>> */ -static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state **BW_RESTRICT state, const float **xl, const float **xr, float **yl, float **yr, int n_channels, int n_samples); +static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state * const *BW_RESTRICT state, const float * const *x_l, const float * const *x_r, float **yl, float **yr, size_t n_channels, size_t n_samples); /*! <<<``` - * Processes the first `n_samples` of the `n_channels` input buffers `xl` - * (left) and `xr` (right) and fills the first `n_samples` of the - * `n_channels` output buffers `yl` (left) and `yr` (right), while using and + * Processes the first `n_samples` of the `n_channels` input buffers `x_l` + * (left) and `x_r` (right) and fills the first `n_samples` of the + * `n_channels` output buffers `y_l` (left) and `y_r` (right), while using and * updating both the common `coeffs` and each of the `n_channels` `state`s * (control and audio rate). * @@ -220,7 +229,7 @@ static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_reverb_coeffs { +struct bw_reverb_coeffs { // Sub-components bw_delay_coeffs predelay_coeffs; bw_lp1_coeffs bandwidth_coeffs; @@ -279,7 +288,7 @@ struct _bw_reverb_coeffs { float predelay; }; -struct _bw_reverb_state { +struct bw_reverb_state { bw_delay_state predelay_state; bw_lp1_state bandwidth_state; bw_delay_state delay_id1_state; @@ -491,8 +500,8 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c bw_drywet_update_coeffs_audio(&coeffs->drywet_coeffs); } -static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float xl, float xr, float *yl, float *yr) { - const float i = 0.5f * (xl + xr); +static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float x_l, float x_r, float *y_l, float *y_r) { + const float i = 0.5f * (x_l + x_r); const float pd = bw_delay_process1(&coeffs->predelay_coeffs, &state->predelay_state, i); const float bw = bw_lp1_process1(&coeffs->bandwidth_coeffs, &state->bandwidth_state, pd); @@ -552,7 +561,7 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs bw_delay_write(&coeffs->delay_d2_coeffs, &state->delay_d2_state, dd2); bw_delay_write(&coeffs->delay_d4_coeffs, &state->delay_d4_state, dd4); - *yl = 0.6f * ( + *y_l = 0.6f * ( bw_delay_read(&coeffs->delay_d3_coeffs, &state->delay_d3_state, coeffs->dl1, 0.f) + bw_delay_read(&coeffs->delay_d3_coeffs, &state->delay_d3_state, coeffs->dl2, 0.f) - bw_delay_read(&coeffs->delay_dd4_coeffs, &state->delay_dd4_state, coeffs->dl3, 0.f) @@ -561,7 +570,7 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs - bw_delay_read(&coeffs->delay_dd2_coeffs, &state->delay_dd2_state, coeffs->dl6, 0.f) - bw_delay_read(&coeffs->delay_d2_coeffs, &state->delay_d2_state, coeffs->dl7, 0.f) ); - *yr = 0.6f * ( + *y_r = 0.6f * ( bw_delay_read(&coeffs->delay_d1_coeffs, &state->delay_d1_state, coeffs->dr1, 0.f) + bw_delay_read(&coeffs->delay_d1_coeffs, &state->delay_d1_state, coeffs->dr2, 0.f) - bw_delay_read(&coeffs->delay_dd2_coeffs, &state->delay_dd2_state, coeffs->dr3, 0.f) @@ -570,24 +579,24 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs - bw_delay_read(&coeffs->delay_dd4_coeffs, &state->delay_dd4_state, coeffs->dr6, 0.f) - bw_delay_read(&coeffs->delay_d4_coeffs, &state->delay_d4_state, coeffs->dr7, 0.f) ); - *yl = bw_drywet_process1(&coeffs->drywet_coeffs, xl, *yl); - *yr = bw_drywet_process1(&coeffs->drywet_coeffs, xr, *yr); + *y_l = bw_drywet_process1(&coeffs->drywet_coeffs, x_l, *y_l); + *y_r = bw_drywet_process1(&coeffs->drywet_coeffs, x_r, *y_r); } -static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *xl, const float *xr, float *yl, float *yr, int n_samples) { +static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *x_l, const float *x_r, float *y_l, float *y_r, size_t n_samples) { bw_reverb_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_reverb_update_coeffs_audio(coeffs); - bw_reverb_process1(coeffs, state, xl[i], xr[i], yl + i, yr + i); + bw_reverb_process1(coeffs, state, x_l[i], x_r[i], y_l + i, y_r + i); } } -static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state **BW_RESTRICT state, const float **xl, const float **xr, float **yl, float **yr, int n_channels, int n_samples) { +static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state * const *BW_RESTRICT state, const float * const *x_l, const float * const *x_r, float **y_l, float **y_r, size_t n_channels, size_t n_samples) { bw_reverb_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_reverb_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) - bw_reverb_process1(coeffs, state[j], xl[j][i], xr[j][i], yl[j] + i, yr[j] + i); + for (size_t j = 0; j < n_channels; j++) + bw_reverb_process1(coeffs, state[j], x_l[j][i], x_r[j][i], y_l[j] + i, y_r[j] + i); } } @@ -612,6 +621,138 @@ static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Reverb + * ```>>> */ +template +class Reverb { +public: + Reverb(); + ~Reverb(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const float * const *x_l, + const float * const *x_r, + float **y_l, + float **y_r, + size_t nSamples); + void process( + std::array x_l, + std::array x_r, + std::array y_l, + std::array y_r, + size_t nSamples); + + void setPredelay(float value); + void setBandwidth(float value); + void setDamping(float value); + void setDecay(float value); + void setWet(float value); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_reverb_coeffs coeffs; + bw_reverb_state states[N_CHANNELS]; + bw_reverb_state *statesP[N_CHANNELS]; + void *mem; +}; + +template +inline Reverb::Reverb() { + bw_reverb_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; + mem = nullptr; +} + +template +inline Reverb::~Reverb() { + if (mem != nullptr) + operator delete(mem); +} + +template +inline void Reverb::setSampleRate(float sampleRate) { + bw_reverb_set_sample_rate(&coeffs, sampleRate); + size_t req = bw_reverb_mem_req(&coeffs); + if (mem != nullptr) + operator delete(mem); + mem = operator new(req * N_CHANNELS); + void *m = mem; + for (size_t i = 0; i < N_CHANNELS; i++, m = static_cast(m) + req) + bw_reverb_mem_set(&coeffs, states + i, m); +} + +template +inline void Reverb::reset() { + bw_reverb_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_reverb_reset_state(&coeffs, states + i); +} + +template +inline void Reverb::process( + const float * const *x_l, + const float * const *x_r, + float **y_l, + float **y_r, + size_t nSamples) { + bw_reverb_process_multi(&coeffs, statesP, x_l, x_r, y_l, y_r, N_CHANNELS, nSamples); +} + +template +inline void Reverb::process( + std::array x_l, + std::array x_r, + std::array y_l, + std::array y_r, + size_t nSamples) { + process(x_l.data(), x_r.data(), y_l.data(), y_r.data(), nSamples); +} + +template +inline void Reverb::setPredelay(float value) { + bw_reverb_set_predelay(&coeffs, value); +} + +template +inline void Reverb::setBandwidth(float value) { + bw_reverb_set_bandwidth(&coeffs, value); +} + +template +inline void Reverb::setDamping(float value) { + bw_reverb_set_damping(&coeffs, value); +} + +template +inline void Reverb::setDecay(float value) { + bw_reverb_set_decay(&coeffs, value); +} + +template +inline void Reverb::setWet(float value) { + bw_reverb_set_wet(&coeffs, value); +} + } #endif diff --git a/include/bw_ringmod.h b/include/bw_ringmod.h index 42d4389..9e31ce1 100644 --- a/include/bw_ringmod.h +++ b/include/bw_ringmod.h @@ -29,8 +29,15 @@ *
      *
    • Version 1.0.0: *
        - *
      • Now using size_t instead of - * BW_SIZE_T.
      • + *
      • bw_ringmod_process() and + * bw_ringmod_process_multi() now use + * size_t to count samples and channels.
      • + *
      • Added more const specifiers to input + * arguments.
      • + *
      • Moved C++ code to C header.
      • + *
      • Added overladed C++ process() function taking + * C-style arrays as arguments.
      • + *
      • Removed usage of reserved identifiers.
      • *
      *
    • *
    • Version 0.6.0: @@ -55,8 +62,8 @@ * }}} */ -#ifndef _BW_RINGMOD_H -#define _BW_RINGMOD_H +#ifndef BW_RINGMOD_H +#define BW_RINGMOD_H #include @@ -67,7 +74,7 @@ extern "C" { /*! api {{{ * #### bw_ringmod_coeffs * ```>>> */ -typedef struct _bw_ringmod_coeffs bw_ringmod_coeffs; +typedef struct bw_ringmod_coeffs bw_ringmod_coeffs; /*! <<<``` * Coefficients and related. * @@ -110,7 +117,7 @@ static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coe * * #### bw_ringmod_process() * ```>>> */ -static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, int n_samples); +static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the modulation input buffer `x_mod` and * of the carrier input buffer `x_car` and fills the first `n_samples` of the @@ -119,7 +126,7 @@ static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, con * * #### bw_ringmod_process_multi() * ```>>> */ -static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float **x_mod, const float **x_car, float **y, int n_channels, int n_samples); +static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` modulation input * buffers `x_mod` and of the `n_channels` carrier input buffers `x_car`, and @@ -153,7 +160,7 @@ static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs, extern "C" { #endif -struct _bw_ringmod_coeffs { +struct bw_ringmod_coeffs { // Sub-components bw_one_pole_coeffs smooth_coeffs; bw_one_pole_state smooth_state; @@ -190,17 +197,17 @@ static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coe return k * x_car * x_mod + bw_absf(1.f - k) * x_mod; } -static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, int n_samples) { - for (int i = 0; i < n_samples; i++) { +static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples) { + for (size_t i = 0; i < n_samples; i++) { bw_ringmod_update_coeffs_audio(coeffs); y[i] = bw_ringmod_process1(coeffs, x_mod[i], x_car[i]); } } -static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float **x_mod, const float **x_car, float **y, int n_channels, int n_samples) { - for (int i = 0; i < n_samples; i++) { +static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float **y, size_t n_channels, size_t n_samples) { + for (size_t i = 0; i < n_samples; i++) { bw_ringmod_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) y[j][i] = bw_ringmod_process1(coeffs, x_mod[j][i], x_car[j][i]); } } @@ -210,6 +217,88 @@ static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs, } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::RingMod + * ```>>> */ +template +class RingMod { +public: + RingMod(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const float * const *x_mod, + const float * const *x_car, + float **y, + size_t nSamples); + void process( + std::array x_mod, + std::array x_car, + std::array y, + size_t nSamples); + + void setAmount(float value); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_ringmod_coeffs coeffs; +}; + +template +inline RingMod::RingMod() { + bw_ringmod_init(&coeffs); +} + +template +inline void RingMod::setSampleRate(float sampleRate) { + bw_ringmod_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void RingMod::reset() { + bw_ringmod_reset_coeffs(&coeffs); +} + +template +inline void RingMod::process( + const float * const *x_mod, + const float * const *x_car, + float **y, + size_t nSamples) { + bw_ringmod_process_multi(&coeffs, x_mod, x_car, y, N_CHANNELS, nSamples); +} + +template +inline void RingMod::process( + std::array x_mod, + std::array x_car, + std::array y, + size_t nSamples) { + process(x_mod.data(), x_car.data(), y.data(), nSamples); +} + +template +inline void RingMod::setAmount(float value) { + bw_ringmod_set_amount(&coeffs, value); +} + } #endif diff --git a/include/bw_satur.h b/include/bw_satur.h index 9a4d274..10ebdc6 100644 --- a/include/bw_satur.h +++ b/include/bw_satur.h @@ -40,8 +40,15 @@ *
        *
      • Version 1.0.0: *
          - *
        • Now using size_t instead of - * BW_SIZE_T.
        • + *
        • bw_satur_process() and + * bw_satur_process_multi() now use + * size_t to count samples and channels.
        • + *
        • Added more const specifiers to input + * arguments.
        • + *
        • Moved C++ code to C header.
        • + *
        • Added overladed C++ process() function taking + * C-style arrays as arguments.
        • + *
        • Removed usage of reserved identifiers.
        • *
        *
      • *
      • Version 0.6.0: @@ -71,8 +78,8 @@ * }}} */ -#ifndef _BW_SATUR_H -#define _BW_SATUR_H +#ifndef BW_SATUR_H +#define BW_SATUR_H #include @@ -83,13 +90,13 @@ extern "C" { /*! api {{{ * #### bw_satur_coeffs * ```>>> */ -typedef struct _bw_satur_coeffs bw_satur_coeffs; +typedef struct bw_satur_coeffs bw_satur_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_satur_state * ```>>> */ -typedef struct _bw_satur_state bw_satur_state; +typedef struct bw_satur_state bw_satur_state; /*! <<<``` * Internal state and related. * @@ -143,7 +150,7 @@ static inline float bw_satur_process1_comp(const bw_satur_coeffs *BW_RESTRICT co * * #### bw_satur_process() * ```>>> */ -static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffer `x` and fills the * first `n_samples` of the output buffer `y`, while using and updating both @@ -151,7 +158,7 @@ static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satu * * #### bw_satur_process_multi() * ```>>> */ -static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` input buffers `x` and * fills the first `n_samples` of the `n_channels` output buffers `y`, while @@ -202,7 +209,7 @@ static inline void bw_satur_set_gain_compensation(bw_satur_coeffs *BW_RESTRICT c extern "C" { #endif -struct _bw_satur_coeffs { +struct bw_satur_coeffs { // Sub-components bw_one_pole_coeffs smooth_coeffs; bw_one_pole_state smooth_bias_state; @@ -218,12 +225,12 @@ struct _bw_satur_coeffs { char gain_compensation; }; -struct _bw_satur_state { +struct bw_satur_state { float x_z1; float F_z1; }; -static inline float _bw_satur_tanhf(float x) { +static inline float bw_satur_tanhf(float x) { const float xm = bw_clipf(x, -2.115287308554551f, 2.115287308554551f); const float axm = bw_absf(xm); return xm * axm * (0.01218073260037716f * axm - 0.2750231331124371f) + xm; @@ -243,11 +250,11 @@ static inline void bw_satur_set_sample_rate(bw_satur_coeffs *BW_RESTRICT coeffs, bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs); } -static inline void _bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs, char force) { +static inline void bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs, char force) { float bias_cur = bw_one_pole_get_y_z1(&coeffs->smooth_bias_state); if (force || coeffs->bias != bias_cur) { bias_cur = bw_one_pole_process1_sticky_abs(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias); - coeffs->bias_dc = _bw_satur_tanhf(bias_cur); + coeffs->bias_dc = bw_satur_tanhf(bias_cur); } float gain_cur = bw_one_pole_get_y_z1(&coeffs->smooth_gain_state); if (force || coeffs->gain != gain_cur) { @@ -259,7 +266,7 @@ static inline void _bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeff static inline void bw_satur_reset_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs) { bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_gain_state, coeffs->gain); - _bw_satur_do_update_coeffs(coeffs, 1); + bw_satur_do_update_coeffs(coeffs, 1); } static inline void bw_satur_reset_state(const bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state) { @@ -273,7 +280,7 @@ static inline void bw_satur_update_coeffs_ctrl(bw_satur_coeffs *BW_RESTRICT coef } static inline void bw_satur_update_coeffs_audio(bw_satur_coeffs *BW_RESTRICT coeffs) { - _bw_satur_do_update_coeffs(coeffs, 0); + bw_satur_do_update_coeffs(coeffs, 0); } static inline float bw_satur_process1(const bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, float x) { @@ -281,7 +288,7 @@ static inline float bw_satur_process1(const bw_satur_coeffs *BW_RESTRICT coeffs, const float ax = bw_absf(x); const float F = ax >= 2.115287308554551f ? ax - 0.6847736211329452f : ax * ax * ((0.00304518315009429f * ax - 0.09167437770414569f) * ax + 0.5f); const float d = x - state->x_z1; - const float y = d * d < 1e-6f ? _bw_satur_tanhf(0.5f * (x + state->x_z1)) : (F - state->F_z1) * bw_rcpf(d); + const float y = d * d < 1e-6f ? bw_satur_tanhf(0.5f * (x + state->x_z1)) : (F - state->F_z1) * bw_rcpf(d); state->x_z1 = x; state->F_z1 = F; return y - coeffs->bias_dc; @@ -292,24 +299,24 @@ static inline float bw_satur_process1_comp(const bw_satur_coeffs *BW_RESTRICT co return coeffs->inv_gain * y; } -static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { if (coeffs->gain_compensation) - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_satur_update_coeffs_audio(coeffs); y[i] = bw_satur_process1_comp(coeffs, state, x[i]); } else - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_satur_update_coeffs_audio(coeffs); y[i] = bw_satur_process1(coeffs, state, x[i]); } } -static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_satur_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_satur_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) y[j][i] = bw_satur_process1(coeffs, state[j], x[j][i]); } } @@ -327,6 +334,102 @@ static inline void bw_satur_set_gain_compensation(bw_satur_coeffs *BW_RESTRICT c } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Satur + * ```>>> */ +template +class Satur { +public: + Satur(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const float * const *x, + float **y, + size_t nSamples); + void process( + std::array x, + std::array y, + size_t nSamples); + + void setBias(float value); + void setGain(float value); + void setGainCompensation(bool value); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_satur_coeffs coeffs; + bw_satur_state states[N_CHANNELS]; + bw_satur_state *statesP[N_CHANNELS]; +}; + +template +inline Satur::Satur() { + bw_satur_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void Satur::setSampleRate(float sampleRate) { + bw_satur_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Satur::reset() { + bw_satur_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_satur_reset_state(&coeffs, states + i); +} + +template +inline void Satur::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_satur_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void Satur::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Satur::setBias(float value) { + bw_satur_set_bias(&coeffs, value); +} + +template +inline void Satur::setGain(float value) { + bw_satur_set_gain(&coeffs, value); +} + +template +inline void Satur::setGainCompensation(bool value) { + bw_satur_set_gain_compensation(&coeffs, value); +} + } #endif diff --git a/include/bw_slew_lim.h b/include/bw_slew_lim.h index 1150ea5..cde986a 100644 --- a/include/bw_slew_lim.h +++ b/include/bw_slew_lim.h @@ -29,8 +29,15 @@ *
          *
        • Version 1.0.0: *
            - *
          • Now using size_t instead of - * BW_SIZE_T.
          • + *
          • bw_slew_lim_process() and + * bw_slew_lim_process_multi() now use + * size_t to count samples and channels.
          • + *
          • Added more const specifiers to input + * arguments.
          • + *
          • Moved C++ code to C header.
          • + *
          • Added overladed C++ process() function taking + * C-style arrays as arguments.
          • + *
          • Removed usage of reserved identifiers.
          • *
          *
        • *
        • Version 0.6.0: @@ -60,8 +67,8 @@ * }}} */ -#ifndef _BW_SLEW_LIM_H -#define _BW_SLEW_LIM_H +#ifndef BW_SLEW_LIM_H +#define BW_SLEW_LIM_H #include @@ -72,13 +79,13 @@ extern "C" { /*! api {{{ * #### bw_slew_lim_coeffs * ```>>> */ -typedef struct _bw_slew_lim_coeffs bw_slew_lim_coeffs; +typedef struct bw_slew_lim_coeffs bw_slew_lim_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_slew_lim_state * ```>>> */ -typedef struct _bw_slew_lim_state bw_slew_lim_state; +typedef struct bw_slew_lim_state bw_slew_lim_state; /*! <<<``` * Internal state and related. * @@ -140,7 +147,7 @@ static inline float bw_slew_lim_process1_down(const bw_slew_lim_coeffs *BW_RESTR * * #### bw_slew_lim_process() * ```>>> */ -static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffer `x` and fills the * first `n_samples` of the output buffer `y`, while using and updating both @@ -150,7 +157,7 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b * * #### bw_slew_lim_process_multi() * ```>>> */ -static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` input buffers `x` and * fills the first `n_samples` of the `n_channels` output buffers `y`, while @@ -220,7 +227,7 @@ static inline float bw_slew_lim_get_y_z1(const bw_slew_lim_state *BW_RESTRICT st extern "C" { #endif -struct _bw_slew_lim_coeffs { +struct bw_slew_lim_coeffs { // Coefficients float T; @@ -232,7 +239,7 @@ struct _bw_slew_lim_coeffs { float max_rate_down; }; -struct _bw_slew_lim_state { +struct bw_slew_lim_state { float y_z1; }; @@ -282,22 +289,22 @@ static inline float bw_slew_lim_process1_down(const bw_slew_lim_coeffs *BW_RESTR return y; } -static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_slew_lim_update_coeffs_ctrl(coeffs); if (y != NULL) { if (coeffs->max_rate_up != INFINITY) { if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_slew_lim_process1(coeffs, state, x[i]); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_slew_lim_process1_up(coeffs, state, x[i]); } else { if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_slew_lim_process1_down(coeffs, state, x[i]); else { - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = x[i]; state->y_z1 = x[n_samples - 1]; } @@ -305,14 +312,14 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b } else { if (coeffs->max_rate_up != INFINITY) { if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1(coeffs, state, x[i]); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1_up(coeffs, state, x[i]); } else { if (coeffs->max_rate_down != INFINITY) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1_down(coeffs, state, x[i]); else state->y_z1 = x[n_samples - 1]; @@ -320,38 +327,38 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b } } -static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_slew_lim_update_coeffs_ctrl(coeffs); if (y != NULL) { if (coeffs->max_rate_up != INFINITY) { if (coeffs->max_rate_down != INFINITY) - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) if (y[j] != NULL) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[j][i] = bw_slew_lim_process1(coeffs, state[j], x[j][i]); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1(coeffs, state[j], x[j][i]); else - for (int j = 0; j < n_channels; j++) - for (int i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) + for (size_t i = 0; i < n_samples; i++) if (y[j] != NULL) y[j][i] = bw_slew_lim_process1_up(coeffs, state[j], x[j][i]); else bw_slew_lim_process1_up(coeffs, state[j], x[j][i]); } else { if (coeffs->max_rate_down != INFINITY) - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) if (y[j] != NULL) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[j][i] = bw_slew_lim_process1_down(coeffs, state[j], x[j][i]); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1_down(coeffs, state[j], x[j][i]); else - for (int j = 0; j < n_channels; j++) { + for (size_t j = 0; j < n_channels; j++) { if (y[j] != NULL) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[j][i] = x[j][i]; state[j]->y_z1 = x[j][n_samples - 1]; } @@ -359,20 +366,20 @@ static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coe } else { if (coeffs->max_rate_up != INFINITY) { if (coeffs->max_rate_down != INFINITY) - for (int j = 0; j < n_channels; j++) - for (int i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1(coeffs, state[j], x[j][i]); else - for (int j = 0; j < n_channels; j++) - for (int i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1_up(coeffs, state[j], x[j][i]); } else { if (coeffs->max_rate_down != INFINITY) - for (int j = 0; j < n_channels; j++) - for (int i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) + for (size_t i = 0; i < n_samples; i++) bw_slew_lim_process1_down(coeffs, state[j], x[j][i]); else - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) state[j]->y_z1 = x[j][n_samples - 1]; } } @@ -396,6 +403,109 @@ static inline float bw_slew_lim_get_y_z1(const bw_slew_lim_state *BW_RESTRICT st } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::SlewLim + * ```>>> */ +template +class SlewLim { +public: + SlewLim(); + + void setSampleRate(float sampleRate); + void reset(float y_z1 = 0.f); + void process( + const float * const *x, + float **y, + size_t nSamples); + void process( + std::array x, + std::array y, + size_t nSamples); + + void setMaxRate(float value); + void setMaxRateUp(float value); + void setMaxRateDown(float value); + + float getYZ1(size_t channel); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_slew_lim_coeffs coeffs; + bw_slew_lim_state states[N_CHANNELS]; + bw_slew_lim_state *statesP[N_CHANNELS]; +}; + +template +inline SlewLim::SlewLim() { + bw_slew_lim_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void SlewLim::setSampleRate(float sampleRate) { + bw_slew_lim_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void SlewLim::reset(float y_z1) { + bw_slew_lim_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_slew_lim_reset_state(&coeffs, states + i, y_z1); +} + +template +inline void SlewLim::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_slew_lim_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void SlewLim::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void SlewLim::setMaxRate(float value) { + bw_slew_lim_set_max_rate(&coeffs, value); +} + +template +inline void SlewLim::setMaxRateUp(float value) { + bw_slew_lim_set_max_rate_up(&coeffs, value); +} + +template +inline void SlewLim::setMaxRateDown(float value) { + bw_slew_lim_set_max_rate_down(&coeffs, value); +} + +template +inline float SlewLim::getYZ1(size_t channel) { + return bw_slew_lim_get_y_z1(states + channel); +} + } #endif diff --git a/include/bw_sr_reduce.h b/include/bw_sr_reduce.h index 6791b61..45e9366 100644 --- a/include/bw_sr_reduce.h +++ b/include/bw_sr_reduce.h @@ -33,8 +33,15 @@ *
            *
          • Version 1.0.0: *
              - *
            • Now using size_t instead of - * BW_SIZE_T.
            • + *
            • bw_sr_reduce_lim_process() and + * bw_sr_reduce_lim_process_multi() now use + * size_t to count samples and channels.
            • + *
            • Added more const specifiers to input + * arguments.
            • + *
            • Moved C++ code to C header.
            • + *
            • Added overladed C++ process() function taking + * C-style arrays as arguments.
            • + *
            • Removed usage of reserved identifiers.
            • *
            *
          • *
          • Version 0.6.0: @@ -62,8 +69,8 @@ * }}} */ -#ifndef _BW_SR_REDUCE_H -#define _BW_SR_REDUCE_H +#ifndef BW_SR_REDUCE_H +#define BW_SR_REDUCE_H #include @@ -74,13 +81,13 @@ extern "C" { /*! api {{{ * #### bw_sr_reduce_coeffs * ```>>> */ -typedef struct _bw_sr_reduce_coeffs bw_sr_reduce_coeffs; +typedef struct bw_sr_reduce_coeffs bw_sr_reduce_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_sr_reduce_state * ```>>> */ -typedef struct _bw_sr_reduce_state bw_sr_reduce_state; +typedef struct bw_sr_reduce_state bw_sr_reduce_state; /*! <<<``` * Internal state and related. * @@ -105,7 +112,7 @@ static inline float bw_sr_reduce_process1(const bw_sr_reduce_coeffs *BW_RESTRICT * * #### bw_sr_reduce_process() * ```>>> */ -static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffer `x` and fills the * first `n_samples` of the output buffer `y`, while using `coeffs` and @@ -113,7 +120,7 @@ static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, * * #### bw_sr_reduce_process_multi() * ```>>> */ -static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` input buffers `x` and * fills the first `n_samples` of the `n_channels` output buffers `y`, while @@ -146,12 +153,12 @@ static inline void bw_sr_reduce_set_ratio(bw_sr_reduce_coeffs *BW_RESTRICT coeff extern "C" { #endif -struct _bw_sr_reduce_coeffs { +struct bw_sr_reduce_coeffs { // Parameters float ratio; }; -struct _bw_sr_reduce_state { +struct bw_sr_reduce_state { float phase; float y_z1; }; @@ -174,13 +181,13 @@ static inline float bw_sr_reduce_process1(const bw_sr_reduce_coeffs *BW_RESTRICT return state->y_z1; } -static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { - for (int i = 0; i < n_samples; i++) +static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { + for (size_t i = 0; i < n_samples; i++) y[i] = bw_sr_reduce_process1(coeffs, state, x[i]); } -static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { - for (int i = 0; i < n_channels; i++) +static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { + for (size_t i = 0; i < n_channels; i++) bw_sr_reduce_process(coeffs, state[i], x[i], y[i], n_samples); } @@ -189,6 +196,83 @@ static inline void bw_sr_reduce_set_ratio(bw_sr_reduce_coeffs *BW_RESTRICT coeff } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::SRReduce + * ```>>> */ +template +class SRReduce { +public: + SRReduce(); + + void reset(); + void process( + const float * const *x, + float **y, + size_t nSamples); + void process( + std::array x, + std::array y, + size_t nSamples); + + void setRatio(float value); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_sr_reduce_coeffs coeffs; + bw_sr_reduce_state states[N_CHANNELS]; + bw_sr_reduce_state *statesP[N_CHANNELS]; +}; + +template +inline SRReduce::SRReduce() { + bw_sr_reduce_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void SRReduce::reset() { + for (size_t i = 0; i < N_CHANNELS; i++) + bw_sr_reduce_reset_state(&coeffs, states + i); +} + +template +inline void SRReduce::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_sr_reduce_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void SRReduce::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void SRReduce::setRatio(float value) { + bw_sr_reduce_set_ratio(&coeffs, value); +} + } #endif diff --git a/include/bw_trem.h b/include/bw_trem.h index bf15282..b51daaa 100644 --- a/include/bw_trem.h +++ b/include/bw_trem.h @@ -31,8 +31,15 @@ *
              *
            • Version 1.0.0: *
                - *
              • Now using size_t instead of - * BW_SIZE_T.
              • + *
              • bw_trem_process() and + * bw_trem_process_multi() now use size_t + * to count samples and channels.
              • + *
              • Added more const specifiers to input + * arguments.
              • + *
              • Moved C++ code to C header.
              • + *
              • Added overladed C++ process() function taking + * C-style arrays as arguments.
              • + *
              • Removed usage of reserved identifiers.
              • *
              *
            • *
            • Version 0.6.0: @@ -55,8 +62,8 @@ * }}} */ -#ifndef _BW_TREM_H -#define _BW_TREM_H +#ifndef BW_TREM_H +#define BW_TREM_H #include @@ -67,13 +74,13 @@ extern "C" { /*! api {{{ * #### bw_trem_coeffs * ```>>> */ -typedef struct _bw_trem_coeffs bw_trem_coeffs; +typedef struct bw_trem_coeffs bw_trem_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_trem_state * ```>>> */ -typedef struct _bw_trem_state bw_trem_state; +typedef struct bw_trem_state bw_trem_state; /*! <<<``` * Internal state and related. * @@ -122,7 +129,7 @@ static inline float bw_trem_process1(const bw_trem_coeffs *BW_RESTRICT coeffs, b * * #### bw_trem_process() * ```>>> */ -static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffer `x` and fills the * first `n_samples` of the output buffer `y`, while using and updating both @@ -130,7 +137,7 @@ static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_s * * #### bw_trem_process_multi() * ```>>> */ -static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` input buffers `x` and * fills the first `n_samples` of the `n_channels` output buffers `y`, while @@ -172,13 +179,13 @@ static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_trem_coeffs { +struct bw_trem_coeffs { // Sub-components bw_phase_gen_coeffs phase_gen_coeffs; bw_ringmod_coeffs ringmod_coeffs; }; -struct _bw_trem_state { +struct bw_trem_state { bw_phase_gen_state phase_gen_state; }; @@ -218,19 +225,19 @@ static inline float bw_trem_process1(const bw_trem_coeffs *BW_RESTRICT coeffs, b return bw_ringmod_process1(&coeffs->ringmod_coeffs, x, 1.f + c); } -static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_trem_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_trem_update_coeffs_audio(coeffs); y[i] = bw_trem_process1(coeffs, state, x[i]); } } -static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_trem_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_trem_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) y[j][i] = bw_trem_process1(coeffs, state[j], x[j][i]); } } @@ -244,6 +251,96 @@ static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Trem + * ```>>> */ +template +class Trem { +public: + Trem(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const float * const *x, + float **y, + size_t nSamples); + void process( + std::array x, + std::array y, + size_t nSamples); + + void setRate(float value); + void setAmount(float value); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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. */ + +private: + bw_trem_coeffs coeffs; + bw_trem_state states[N_CHANNELS]; + bw_trem_state *statesP[N_CHANNELS]; +}; + +template +inline Trem::Trem() { + bw_trem_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void Trem::setSampleRate(float sampleRate) { + bw_trem_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Trem::reset() { + bw_trem_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_trem_reset_state(&coeffs, states + i); +} + +template +inline void Trem::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_trem_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void Trem::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Trem::setRate(float value) { + bw_trem_set_rate(&coeffs, value); +} + +template +inline void Trem::setAmount(float value) { + bw_trem_set_amount(&coeffs, value); +} + } #endif diff --git a/include/bwpp_reverb.h b/include/bwpp_reverb.h deleted file mode 100644 index 8840b00..0000000 --- a/include/bwpp_reverb.h +++ /dev/null @@ -1,139 +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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_REVERB_H -#define BWPP_REVERB_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Reverb - * ```>>> */ -template -class Reverb { -public: - Reverb(); - ~Reverb(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array xl, - std::array xr, - std::array yl, - std::array yr, - int nSamples); - - void setPredelay(float value); - void setBandwidth(float value); - void setDamping(float value); - void setDecay(float value); - void setWet(float value); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_reverb_coeffs coeffs; - bw_reverb_state states[N_CHANNELS]; - bw_reverb_state *statesP[N_CHANNELS]; - void *mem; -}; - -template -inline Reverb::Reverb() { - bw_reverb_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; - mem = nullptr; -} - -template -inline Reverb::~Reverb() { - if (mem != nullptr) - operator delete(mem); -} - -template -inline void Reverb::setSampleRate(float sampleRate) { - bw_reverb_set_sample_rate(&coeffs, sampleRate); - size_t req = bw_reverb_mem_req(&coeffs); - if (mem != nullptr) - operator delete(mem); - mem = operator new(req * N_CHANNELS); - void *m = mem; - for (size_t i = 0; i < N_CHANNELS; i++, m = static_cast(m) + req) - bw_reverb_mem_set(&coeffs, states + i, m); -} - -template -inline void Reverb::reset() { - bw_reverb_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_reverb_reset_state(&coeffs, states + i); -} - -template -inline void Reverb::process( - std::array xl, - std::array xr, - std::array yl, - std::array yr, - int nSamples) { - bw_reverb_process_multi(&coeffs, statesP, xl.data(), xr.data(), yl.data(), yr.data(), N_CHANNELS, nSamples); -} - -template -inline void Reverb::setPredelay(float value) { - bw_reverb_set_predelay(&coeffs, value); -} - -template -inline void Reverb::setBandwidth(float value) { - bw_reverb_set_bandwidth(&coeffs, value); -} - -template -inline void Reverb::setDamping(float value) { - bw_reverb_set_damping(&coeffs, value); -} - -template -inline void Reverb::setDecay(float value) { - bw_reverb_set_decay(&coeffs, value); -} - -template -inline void Reverb::setWet(float value) { - bw_reverb_set_wet(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_ringmod.h b/include/bwpp_ringmod.h deleted file mode 100644 index dd8ca70..0000000 --- a/include/bwpp_ringmod.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Brickworks - * - * Copyright (C) 2023 Orastron Srl unipersonale - * - * Brickworks is free software: you can reringmodribute 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 ringmodributed 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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_RINGMOD_H -#define BWPP_RINGMOD_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::RingMod - * ```>>> */ -template -class RingMod { -public: - RingMod(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x_mod, - std::array x_car, - std::array y, - int nSamples); - - void setAmount(float value); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_ringmod_coeffs coeffs; -}; - -template -inline RingMod::RingMod() { - bw_ringmod_init(&coeffs); -} - -template -inline void RingMod::setSampleRate(float sampleRate) { - bw_ringmod_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void RingMod::reset() { - bw_ringmod_reset_coeffs(&coeffs); -} - -template -inline void RingMod::process( - std::array x_mod, - std::array x_car, - std::array y, - int nSamples) { - bw_ringmod_process_multi(&coeffs, statesP, x_mod.data(), x_car.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void RingMod::setAmount(float value) { - bw_ringmod_set_amount(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_satur.h b/include/bwpp_satur.h deleted file mode 100644 index 5bbdf7b..0000000 --- a/include/bwpp_satur.h +++ /dev/null @@ -1,107 +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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_SATUR_H -#define BWPP_SATUR_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Satur - * ```>>> */ -template -class Satur { -public: - Satur(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setBias(float value); - void setGain(float value); - void setGainCompensation(bool value); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_satur_coeffs coeffs; - bw_satur_state states[N_CHANNELS]; - bw_satur_state *statesP[N_CHANNELS]; -}; - -template -inline Satur::Satur() { - bw_satur_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void Satur::setSampleRate(float sampleRate) { - bw_satur_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Satur::reset() { - bw_satur_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_satur_reset_state(&coeffs, states + i); -} - -template -inline void Satur::process( - std::array x, - std::array y, - int nSamples) { - bw_satur_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Satur::setBias(float value) { - bw_satur_set_bias(&coeffs, value); -} - -template -inline void Satur::setGain(float value) { - bw_satur_set_gain(&coeffs, value); -} - -template -inline void Satur::setGainCompensation(bool value) { - bw_satur_set_gain_compensation(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_slew_lim.h b/include/bwpp_slew_lim.h deleted file mode 100644 index 4416ae5..0000000 --- a/include/bwpp_slew_lim.h +++ /dev/null @@ -1,114 +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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_SLEW_LIM_H -#define BWPP_SLEW_LIM_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::SlewLim - * ```>>> */ -template -class SlewLim { -public: - SlewLim(); - - void setSampleRate(float sampleRate); - void reset(float y_z1 = 0.f); - void process( - std::array x, - std::array y, - int nSamples); - - void setMaxRate(float value); - void setMaxRateUp(float value); - void setMaxRateDown(float value); - - float getYZ1(size_t channel); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_slew_lim_coeffs coeffs; - bw_slew_lim_state states[N_CHANNELS]; - bw_slew_lim_state *statesP[N_CHANNELS]; -}; - -template -inline SlewLim::SlewLim() { - bw_slew_lim_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void SlewLim::setSampleRate(float sampleRate) { - bw_slew_lim_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void SlewLim::reset(float y_z1) { - bw_slew_lim_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_slew_lim_reset_state(&coeffs, states + i, y_z1); -} - -template -inline void SlewLim::process( - std::array x, - std::array y, - int nSamples) { - bw_slew_lim_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void SlewLim::setMaxRate(float value) { - bw_slew_lim_set_max_rate(&coeffs, value); -} - -template -inline void SlewLim::setMaxRateUp(float value) { - bw_slew_lim_set_max_rate_up(&coeffs, value); -} - -template -inline void SlewLim::setMaxRateDown(float value) { - bw_slew_lim_set_max_rate_down(&coeffs, value); -} - -template -inline float SlewLim::getYZ1(size_t channel) { - return bw_slew_lim_get_y_z1(states + channel); -} - -} - -#endif diff --git a/include/bwpp_sr_reduce.h b/include/bwpp_sr_reduce.h deleted file mode 100644 index ac93a09..0000000 --- a/include/bwpp_sr_reduce.h +++ /dev/null @@ -1,88 +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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_SR_REDUCE_H -#define BWPP_SR_REDUCE_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::SRReduce - * ```>>> */ -template -class SRReduce { -public: - SRReduce(); - - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setRatio(float value); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_sr_reduce_coeffs coeffs; - bw_sr_reduce_state states[N_CHANNELS]; - bw_sr_reduce_state *statesP[N_CHANNELS]; -}; - -template -inline SRReduce::SRReduce() { - bw_sr_reduce_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void SRReduce::reset() { - for (size_t i = 0; i < N_CHANNELS; i++) - bw_sr_reduce_reset_state(&coeffs, states + i); -} - -template -inline void SRReduce::process( - std::array x, - std::array y, - int nSamples) { - bw_sr_reduce_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void SRReduce::setRatio(float value) { - bw_sr_reduce_set_ratio(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_trem.h b/include/bwpp_trem.h deleted file mode 100644 index fce86b3..0000000 --- a/include/bwpp_trem.h +++ /dev/null @@ -1,101 +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 . - * - * File author: Stefano D'Angelo - */ - -#ifndef BWPP_TREM_H -#define BWPP_TREM_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Trem - * ```>>> */ -template -class Trem { -public: - Trem(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setRate(float value); - void setAmount(float value); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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. */ - -private: - bw_trem_coeffs coeffs; - bw_trem_state states[N_CHANNELS]; - bw_trem_state *statesP[N_CHANNELS]; -}; - -template -inline Trem::Trem() { - bw_trem_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void Trem::setSampleRate(float sampleRate) { - bw_trem_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Trem::reset() { - bw_trem_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_trem_reset_state(&coeffs, states + i); -} - -template -inline void Trem::process( - std::array x, - std::array y, - int nSamples) { - bw_trem_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Trem::setRate(float value) { - bw_trem_set_rate(&coeffs, value); -} - -template -inline void Trem::setAmount(float value) { - bw_trem_set_amount(&coeffs, value); -} - -} - -#endif