From 425aa020e181cc8c7c56e87f645d12ccd93e1a1b Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sat, 12 Aug 2023 18:00:12 +0200 Subject: [PATCH] polished bw_{comb,comp} + removed bwpp_{comb,comp} + fix examples --- TODO | 2 +- examples/fxpp_comb/src/bw_example_fxpp_comb.h | 2 +- examples/fxpp_comp/src/bw_example_fxpp_comp.h | 2 +- include/bw_comb.h | 168 ++++++++++++++++-- include/bw_comp.h | 159 +++++++++++++++-- include/bwpp_comb.h | 135 -------------- include/bwpp_comp.h | 133 -------------- 7 files changed, 296 insertions(+), 305 deletions(-) delete mode 100644 include/bwpp_comb.h delete mode 100644 include/bwpp_comp.h diff --git a/TODO b/TODO index 93bdc61..aa74f1a 100644 --- a/TODO +++ b/TODO @@ -40,7 +40,7 @@ code: * better src filter * bw_env_gen process_multi gate const? * c++ get coeffs/state? or public? src nIn/OutSamples case (array vs single value), delay read/write, process1? process single? -* check unititialized warnings +* check unititialized warnings (check fxpp_comp in particular) * clearly specify that state is tied to a particular set of coeffs (1:N) * modulation vs process (multi) no update (post 1.0.0)??? * check assumptions w.r.t. usage of math functions diff --git a/examples/fxpp_comb/src/bw_example_fxpp_comb.h b/examples/fxpp_comb/src/bw_example_fxpp_comb.h index 3834c1d..386fbe7 100644 --- a/examples/fxpp_comb/src/bw_example_fxpp_comb.h +++ b/examples/fxpp_comb/src/bw_example_fxpp_comb.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/fxpp_comp/src/bw_example_fxpp_comp.h b/examples/fxpp_comp/src/bw_example_fxpp_comp.h index d34978d..8623912 100644 --- a/examples/fxpp_comp/src/bw_example_fxpp_comp.h +++ b/examples/fxpp_comp/src/bw_example_fxpp_comp.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/include/bw_comb.h b/include/bw_comb.h index 8b19fdb..08d02d8 100644 --- a/include/bw_comb.h +++ b/include/bw_comb.h @@ -41,6 +41,15 @@ *
    *
  • Now using size_t instead of * BW_SIZE_T.
  • + *
  • bw_comb_process() and + * bw_comb_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: @@ -65,8 +74,8 @@ * }}} */ -#ifndef _BW_COMB_H -#define _BW_COMB_H +#ifndef BW_COMB_H +#define BW_COMB_H #include @@ -77,13 +86,13 @@ extern "C" { /*! api {{{ * #### bw_comb_coeffs * ```>>> */ -typedef struct _bw_comb_coeffs bw_comb_coeffs; +typedef struct bw_comb_coeffs bw_comb_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_comb_state * ```>>> */ -typedef struct _bw_comb_state bw_comb_state; +typedef struct bw_comb_state bw_comb_state; /*! <<<``` * Internal state and related. * @@ -146,7 +155,7 @@ static inline float bw_comb_process1(const bw_comb_coeffs *BW_RESTRICT coeffs, b * * #### bw_comb_process() * ```>>> */ -static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_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 @@ -154,7 +163,7 @@ static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_s * * #### bw_comb_process_multi() * ```>>> */ -static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_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 +229,7 @@ static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, floa extern "C" { #endif -struct _bw_comb_coeffs { +struct bw_comb_coeffs { // Sub-components bw_delay_coeffs delay_coeffs; bw_gain_coeffs blend_coeffs; @@ -233,9 +242,9 @@ struct _bw_comb_coeffs { // Coefficients float fs; - size_t dffi; + size_t dffi; float dfff; - size_t dfbi; + size_t dfbi; float dfbf; // Parameters @@ -243,7 +252,7 @@ struct _bw_comb_coeffs { float delay_fb; }; -struct _bw_comb_state { +struct bw_comb_state { // Sub-components bw_delay_state delay_state; }; @@ -277,11 +286,10 @@ static inline size_t bw_comb_mem_req(const bw_comb_coeffs *BW_RESTRICT coeffs) { } static inline void bw_comb_mem_set(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, void *mem) { - (void)coeffs; bw_delay_mem_set(&coeffs->delay_coeffs, &state->delay_state, mem); } -static inline void _bw_comb_do_update_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs, char force) { +static inline void bw_comb_do_update_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs, char force) { float delay_ff_cur = bw_one_pole_get_y_z1(&coeffs->smooth_delay_ff_state); float delay_fb_cur = bw_one_pole_get_y_z1(&coeffs->smooth_delay_fb_state); if (force || delay_ff_cur != coeffs->delay_ff) { @@ -317,7 +325,7 @@ static inline void bw_comb_reset_coeffs(bw_comb_coeffs *BW_RESTRICT coeffs) { bw_gain_reset_coeffs(&coeffs->fb_coeffs); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_delay_ff_state, coeffs->delay_ff); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_delay_fb_state, coeffs->delay_fb); - _bw_comb_do_update_coeffs(coeffs, 1); + bw_comb_do_update_coeffs(coeffs, 1); } static inline void bw_comb_reset_state(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state) { @@ -334,7 +342,7 @@ static inline void bw_comb_update_coeffs_audio(bw_comb_coeffs *BW_RESTRICT coeff bw_gain_update_coeffs_audio(&coeffs->blend_coeffs); bw_gain_update_coeffs_audio(&coeffs->ff_coeffs); bw_gain_update_coeffs_audio(&coeffs->fb_coeffs); - _bw_comb_do_update_coeffs(coeffs, 0); + bw_comb_do_update_coeffs(coeffs, 0); } static inline float bw_comb_process1(const bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, float x) { @@ -345,19 +353,19 @@ static inline float bw_comb_process1(const bw_comb_coeffs *BW_RESTRICT coeffs, b return bw_gain_process1(&coeffs->blend_coeffs, v) + bw_gain_process1(&coeffs->ff_coeffs, ff); } -static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_comb_process(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_comb_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_comb_update_coeffs_audio(coeffs); y[i] = bw_comb_process1(coeffs, state, x[i]); } } -static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_comb_process_multi(bw_comb_coeffs *BW_RESTRICT coeffs, bw_comb_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_comb_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_comb_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_comb_process1(coeffs, state[j], x[j][i]); } } @@ -383,6 +391,128 @@ static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, floa } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*! api {{{ + * ##### Brickworks::Comb + * ```>>> */ +template +class Comb { +public: + Comb(float maxDelay = 1.f); + ~Comb(); + + 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 setDelayFF(float value); + void setDelayFB(float value); + void setCoeffBlend(float value); + void setCoeffFF(float value); + void setCoeffFB(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_comb_coeffs coeffs; + bw_comb_state states[N_CHANNELS]; + bw_comb_state *statesP[N_CHANNELS]; + void *mem; +}; + +template +inline Comb::Comb(float maxDelay) { + bw_comb_init(&coeffs, maxDelay); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; + mem = nullptr; +} + +template +inline Comb::~Comb() { + if (mem != nullptr) + operator delete(mem); +} + +template +inline void Comb::setSampleRate(float sampleRate) { + bw_comb_set_sample_rate(&coeffs, sampleRate); + size_t req = bw_comb_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_comb_mem_set(&coeffs, states + i, m); +} + +template +inline void Comb::reset() { + bw_comb_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_comb_reset_state(&coeffs, states + i); +} + +template +inline void Comb::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_comb_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void Comb::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Comb::setDelayFF(float value) { + bw_comb_set_delay_ff(&coeffs, value); +} + +template +inline void Comb::setDelayFB(float value) { + bw_comb_set_delay_fb(&coeffs, value); +} + +template +inline void Comb::setCoeffBlend(float value) { + bw_comb_set_coeff_blend(&coeffs, value); +} + +template +inline void Comb::setCoeffFF(float value) { + bw_comb_set_coeff_ff(&coeffs, value); +} + +template +inline void Comb::setCoeffFB(float value) { + bw_comb_set_coeff_fb(&coeffs, value); +} + } #endif diff --git a/include/bw_comp.h b/include/bw_comp.h index a05f865..f4c51aa 100644 --- a/include/bw_comp.h +++ b/include/bw_comp.h @@ -31,8 +31,15 @@ *
      *
    • Version 1.0.0: *
        - *
      • Now using size_t instead of - * BW_SIZE_T.
      • + *
      • bw_comb_process() and + * bw_comb_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: @@ -57,8 +64,8 @@ * }}} */ -#ifndef _BW_COMP_H -#define _BW_COMP_H +#ifndef BW_COMP_H +#define BW_COMP_H #include @@ -69,13 +76,13 @@ extern "C" { /*! api {{{ * #### bw_comp_coeffs * ```>>> */ -typedef struct _bw_comp_coeffs bw_comp_coeffs; +typedef struct bw_comp_coeffs bw_comp_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_comp_state * ```>>> */ -typedef struct _bw_comp_state bw_comp_state; +typedef struct bw_comp_state bw_comp_state; /*! <<<``` * Internal state and related. * @@ -125,7 +132,7 @@ static inline float bw_comp_process1(const bw_comp_coeffs *BW_RESTRICT coeffs, b * * #### bw_comp_process() * ```>>> */ -static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, int n_samples); +static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the input buffer `x` and the first * `n_samples` of the sidechain input buffer `x_sc`, and fills the first @@ -134,7 +141,7 @@ static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_s * * #### bw_comp_process_multi() * ```>>> */ -static inline void bw_comp_process_multi(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state **BW_RESTRICT state, const float **x, const float **x_sc, float **y, int n_channels, int n_samples); +static inline void bw_comp_process_multi(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state * const *BW_RESTRICT state, const float * const *x, const float * const *x_sc, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Processes the first `n_samples` of the `n_channels` input buffers `x` and * the first `n_samples` of the `n_channels` sidechain input buffers `x_sc`, @@ -222,7 +229,7 @@ static inline void bw_comp_set_gain_dB(bw_comp_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_comp_coeffs { +struct bw_comp_coeffs { // Sub-components bw_env_follow_coeffs env_follow_coeffs; bw_gain_coeffs gain_coeffs; @@ -238,7 +245,7 @@ struct _bw_comp_coeffs { float ratio; }; -struct _bw_comp_state { +struct bw_comp_state { bw_env_follow_state env_follow_state; }; @@ -287,19 +294,19 @@ static inline float bw_comp_process1(const bw_comp_coeffs *BW_RESTRICT coeffs, b return bw_gain_process1(&coeffs->gain_coeffs, y); } -static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, int n_samples) { +static inline void bw_comp_process(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, size_t n_samples) { bw_comp_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_comp_update_coeffs_audio(coeffs); y[i] = bw_comp_process1(coeffs, state, x[i], x_sc[i]); } } -static inline void bw_comp_process_multi(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state **BW_RESTRICT state, const float **x, const float **x_sc, float **y, int n_channels, int n_samples) { +static inline void bw_comp_process_multi(bw_comp_coeffs *BW_RESTRICT coeffs, bw_comp_state * const *BW_RESTRICT state, const float * const *x, const float * const *x_sc, float **y, size_t n_channels, size_t n_samples) { bw_comp_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_comp_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_comp_process1(coeffs, state[j], x[j][i], x_sc[j][i]); } } @@ -333,6 +340,128 @@ static inline void bw_comp_set_gain_dB(bw_comp_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*! api {{{ + * ##### Brickworks::Comp + * ```>>> */ +template +class Comp { +public: + Comp(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const float * const *x, + const float * const *xSC, + float **y, + size_t nSamples); + void process( + std::array x, + std::array xSC, + std::array y, + size_t nSamples); + + void setTreshLin(float value); + void setTreshDBFS(float value); + void setRatio(float value); + void setAttackTau(float value); + void setReleaseTau(float value); + void setGainLin(float value); + void setGainDB(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_comp_coeffs coeffs; + bw_comp_state states[N_CHANNELS]; + bw_comp_state *statesP[N_CHANNELS]; +}; + +template +inline Comp::Comp() { + bw_comp_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void Comp::setSampleRate(float sampleRate) { + bw_comp_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Comp::reset() { + bw_comp_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_comp_reset_state(&coeffs, states + i); +} + +template +inline void Comp::process( + const float * const *x, + const float * const *xSC, + float **y, + size_t nSamples) { + bw_comp_process_multi(&coeffs, statesP, x, xSC, y, N_CHANNELS, nSamples); +} + +template +inline void Comp::process( + std::array x, + std::array xSC, + std::array y, + size_t nSamples) { + process(x.data(), xSC.data(), y.data(), nSamples); +} + +template +inline void Comp::setTreshLin(float value) { + bw_comp_set_thresh_lin(&coeffs, value); +} + +template +inline void Comp::setTreshDBFS(float value) { + bw_comp_set_thresh_dBFS(&coeffs, value); +} + +template +inline void Comp::setRatio(float value) { + bw_comp_set_ratio(&coeffs, value); +} + +template +inline void Comp::setAttackTau(float value) { + bw_comp_set_attack_tau(&coeffs, value); +} + +template +inline void Comp::setReleaseTau(float value) { + bw_comp_set_release_tau(&coeffs, value); +} + +template +inline void Comp::setGainLin(float value) { + bw_comp_set_gain_lin(&coeffs, value); +} + +template +inline void Comp::setGainDB(float value) { + bw_comp_set_gain_dB(&coeffs, value); +} + } #endif diff --git a/include/bwpp_comb.h b/include/bwpp_comb.h deleted file mode 100644 index b722309..0000000 --- a/include/bwpp_comb.h +++ /dev/null @@ -1,135 +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_COMB_H -#define BWPP_COMB_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Comb - * ```>>> */ -template -class Comb { -public: - Comb(float maxDelay = 1.f); - ~Comb(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setDelayFF(float value); - void setDelayFB(float value); - void setCoeffBlend(float value); - void setCoeffFF(float value); - void setCoeffFB(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_comb_coeffs coeffs; - bw_comb_state states[N_CHANNELS]; - bw_comb_state *statesP[N_CHANNELS]; - void *mem; -}; - -template -inline Comb::Comb(float maxDelay) { - bw_comb_init(&coeffs, maxDelay); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; - mem = nullptr; -} - -template -inline Comb::~Comb() { - if (mem != nullptr) - operator delete(mem); -} - -template -inline void Comb::setSampleRate(float sampleRate) { - bw_comb_set_sample_rate(&coeffs, sampleRate); - size_t req = bw_comb_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_comb_mem_set(&coeffs, states + i, m); -} - -template -inline void Comb::reset() { - bw_comb_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_comb_reset_state(&coeffs, states + i); -} - -template -inline void Comb::process( - std::array x, - std::array y, - int nSamples) { - bw_comb_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Comb::setDelayFF(float value) { - bw_comb_set_delay_ff(&coeffs, value); -} - -template -inline void Comb::setDelayFB(float value) { - bw_comb_set_delay_fb(&coeffs, value); -} - -template -inline void Comb::setCoeffBlend(float value) { - bw_comb_set_coeff_blend(&coeffs, value); -} - -template -inline void Comb::setCoeffFF(float value) { - bw_comb_set_coeff_ff(&coeffs, value); -} - -template -inline void Comb::setCoeffFB(float value) { - bw_comb_set_coeff_fb(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_comp.h b/include/bwpp_comp.h deleted file mode 100644 index 64dd5f2..0000000 --- a/include/bwpp_comp.h +++ /dev/null @@ -1,133 +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_COMP_H -#define BWPP_COMP_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Comp - * ```>>> */ -template -class Comp { -public: - Comp(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array xSC, - std::array y, - int nSamples); - - void setTreshLin(float value); - void setTreshDBFS(float value); - void setRatio(float value); - void setAttackTau(float value); - void setReleaseTau(float value); - void setGainLin(float value); - void setGainDB(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_comp_coeffs coeffs; - bw_comp_state states[N_CHANNELS]; - bw_comp_state *statesP[N_CHANNELS]; -}; - -template -inline Comp::Comp() { - bw_comp_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void Comp::setSampleRate(float sampleRate) { - bw_comp_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Comp::reset() { - bw_comp_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_comp_reset_state(&coeffs, states + i); -} - -template -inline void Comp::process( - std::array x, - std::array xSC, - std::array y, - int nSamples) { - bw_comp_process_multi(&coeffs, statesP, x.data(), xSC.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Comp::setTreshLin(float value) { - bw_comp_set_thresh_lin(&coeffs, value); -} - -template -inline void Comp::setTreshDBFS(float value) { - bw_comp_set_thresh_dBFS(&coeffs, value); -} - -template -inline void Comp::setRatio(float value) { - bw_comp_set_ratio(&coeffs, value); -} - -template -inline void Comp::setAttackTau(float value) { - bw_comp_set_attack_tau(&coeffs, value); -} - -template -inline void Comp::setReleaseTau(float value) { - bw_comp_set_release_tau(&coeffs, value); -} - -template -inline void Comp::setGainLin(float value) { - bw_comp_set_gain_lin(&coeffs, value); -} - -template -inline void Comp::setGainDB(float value) { - bw_comp_set_gain_dB(&coeffs, value); -} - -} - -#endif