From 2a5d1721f83976bc4a5b7e2162b2efe14a55ddf4 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sun, 13 Aug 2023 04:55:29 +0200 Subject: [PATCH] polished bw_{mm1,mm2,noise_gate,noise_gen,notch} + removed corresponding bwpp and bwpp_note_queue + fixed examples --- examples/fxpp_mm2/src/bw_example_fxpp_mm2.h | 2 +- .../src/bw_example_fxpp_noise_gate.h | 2 +- .../fxpp_notch/src/bw_example_fxpp_notch.h | 2 +- .../src/bw_example_synthpp_mono.h | 2 +- .../src/bw_example_synthpp_poly.h | 2 +- include/bw_mm1.h | 153 ++++++++++++++-- include/bw_mm2.h | 171 ++++++++++++++++-- include/bw_noise_gate.h | 149 +++++++++++++-- include/bw_noise_gen.h | 108 +++++++++-- include/bw_notch.h | 135 ++++++++++++-- include/bwpp_mm1.h | 119 ------------ include/bwpp_mm2.h | 137 -------------- include/bwpp_noise_gate.h | 121 ------------- include/bwpp_noise_gen.h | 88 --------- include/bwpp_notch.h | 101 ----------- include/bwpp_note_queue.h | 62 ------- 16 files changed, 636 insertions(+), 718 deletions(-) delete mode 100644 include/bwpp_mm1.h delete mode 100644 include/bwpp_mm2.h delete mode 100644 include/bwpp_noise_gate.h delete mode 100644 include/bwpp_noise_gen.h delete mode 100644 include/bwpp_notch.h delete mode 100644 include/bwpp_note_queue.h diff --git a/examples/fxpp_mm2/src/bw_example_fxpp_mm2.h b/examples/fxpp_mm2/src/bw_example_fxpp_mm2.h index 3dc618f..77c978d 100644 --- a/examples/fxpp_mm2/src/bw_example_fxpp_mm2.h +++ b/examples/fxpp_mm2/src/bw_example_fxpp_mm2.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/fxpp_noise_gate/src/bw_example_fxpp_noise_gate.h b/examples/fxpp_noise_gate/src/bw_example_fxpp_noise_gate.h index 2442dd0..a23d282 100644 --- a/examples/fxpp_noise_gate/src/bw_example_fxpp_noise_gate.h +++ b/examples/fxpp_noise_gate/src/bw_example_fxpp_noise_gate.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/fxpp_notch/src/bw_example_fxpp_notch.h b/examples/fxpp_notch/src/bw_example_fxpp_notch.h index e9a7078..24daf8b 100644 --- a/examples/fxpp_notch/src/bw_example_fxpp_notch.h +++ b/examples/fxpp_notch/src/bw_example_fxpp_notch.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#include using namespace Brickworks; diff --git a/examples/synthpp_mono/src/bw_example_synthpp_mono.h b/examples/synthpp_mono/src/bw_example_synthpp_mono.h index 10c0ee9..c83286e 100644 --- a/examples/synthpp_mono/src/bw_example_synthpp_mono.h +++ b/examples/synthpp_mono/src/bw_example_synthpp_mono.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/synthpp_poly/src/bw_example_synthpp_poly.h b/examples/synthpp_poly/src/bw_example_synthpp_poly.h index 5e85506..37aa57c 100644 --- a/examples/synthpp_poly/src/bw_example_synthpp_poly.h +++ b/examples/synthpp_poly/src/bw_example_synthpp_poly.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/bw_mm1.h b/include/bw_mm1.h index bd7069a..a9e37b7 100644 --- a/include/bw_mm1.h +++ b/include/bw_mm1.h @@ -29,8 +29,15 @@ *
    *
  • Version 1.0.0: *
      - *
    • Now using size_t instead of - * BW_SIZE_T.
    • + *
    • bw_mm1_process() and + * bw_mm1_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: @@ -59,8 +66,8 @@ * }}} */ -#ifndef _BW_MM1_H -#define _BW_MM1_H +#ifndef BW_MM1_H +#define BW_MM1_H #include @@ -71,13 +78,13 @@ extern "C" { /*! api {{{ * #### bw_mm1_coeffs * ```>>> */ -typedef struct _bw_mm1_coeffs bw_mm1_coeffs; +typedef struct bw_mm1_coeffs bw_mm1_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_mm1_state * ```>>> */ -typedef struct _bw_mm1_state bw_mm1_state; +typedef struct bw_mm1_state bw_mm1_state; /*! <<<``` * Internal state and related. * @@ -101,10 +108,10 @@ static inline void bw_mm1_reset_coeffs(bw_mm1_coeffs *BW_RESTRICT coeffs); * * #### bw_mm1_reset_state() * ```>>> */ -static inline void bw_mm1_reset_state(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, float x0); +static inline void bw_mm1_reset_state(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, float x_0); /*! <<<``` * Resets the given `state` to its initial values using the given `coeffs` - * and the quiescent/initial input value `x0`. + * and the quiescent/initial input value `x_0`. * * #### bw_mm1_update_coeffs_ctrl() * ```>>> */ @@ -127,7 +134,7 @@ static inline float bw_mm1_process1(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_ * * #### bw_mm1_process() * ```>>> */ -static inline void bw_mm1_process(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_mm1_process(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_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 @@ -135,7 +142,7 @@ static inline void bw_mm1_process(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_stat * * #### bw_mm1_process_multi() * ```>>> */ -static inline void bw_mm1_process_multi(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_mm1_process_multi(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_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,14 +209,14 @@ static inline void bw_mm1_set_coeff_lp(bw_mm1_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_mm1_coeffs { +struct bw_mm1_coeffs { // Sub-components bw_lp1_coeffs lp1_coeffs; bw_gain_coeffs gain_x_coeffs; bw_gain_coeffs gain_lp_coeffs; }; -struct _bw_mm1_state { +struct bw_mm1_state { bw_lp1_state lp1_state; }; @@ -235,8 +242,8 @@ static inline void bw_mm1_reset_coeffs(bw_mm1_coeffs *BW_RESTRICT coeffs) { bw_gain_reset_coeffs(&coeffs->gain_lp_coeffs); } -static inline void bw_mm1_reset_state(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, float x0) { - bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x0); +static inline void bw_mm1_reset_state(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, float x_0) { + bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0); } static inline void bw_mm1_update_coeffs_ctrl(bw_mm1_coeffs *BW_RESTRICT coeffs) { @@ -258,19 +265,19 @@ static inline float bw_mm1_process1(const bw_mm1_coeffs *BW_RESTRICT coeffs, bw_ return vx + vlp; } -static inline void bw_mm1_process(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_mm1_process(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_mm1_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_mm1_update_coeffs_audio(coeffs); y[i] = bw_mm1_process1(coeffs, state, x[i]); } } -static inline void bw_mm1_process_multi(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_mm1_process_multi(bw_mm1_coeffs *BW_RESTRICT coeffs, bw_mm1_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_mm1_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_mm1_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_mm1_process1(coeffs, state[j], x[j][i]); } } @@ -296,6 +303,114 @@ static inline void bw_mm1_set_coeff_lp(bw_mm1_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::MM1 + * ```>>> */ +template +class MM1 { +public: + MM1(); + + void setSampleRate(float sampleRate); + void reset(float x_0 = 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 setCutoff(float value); + void setPrewarpAtCutoff(bool value); + void setPrewarpFreq(float value); + void setCoeffX(float value); + void setCoeffLp(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_mm1_coeffs coeffs; + bw_mm1_state states[N_CHANNELS]; + bw_mm1_state *statesP[N_CHANNELS]; +}; + +template +inline MM1::MM1() { + bw_mm1_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void MM1::setSampleRate(float sampleRate) { + bw_mm1_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void MM1::reset(float x_0) { + bw_mm1_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_mm1_reset_state(&coeffs, states + i, x_0); +} + +template +inline void MM1::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_mm1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void MM1::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void MM1::setCutoff(float value) { + bw_mm1_set_cutoff(&coeffs, value); +} + +template +inline void MM1::setPrewarpAtCutoff(bool value) { + bw_mm1_set_prewarp_at_cutoff(&coeffs, value); +} + +template +inline void MM1::setPrewarpFreq(float value) { + bw_mm1_set_prewarp_freq(&coeffs, value); +} + +template +inline void MM1::setCoeffX(float value) { + bw_mm1_set_coeff_x(&coeffs, value); +} + +template +inline void MM1::setCoeffLp(float value) { + bw_mm1_set_coeff_lp(&coeffs, value); +} + } #endif diff --git a/include/bw_mm2.h b/include/bw_mm2.h index 41c6f8e..b21253f 100644 --- a/include/bw_mm2.h +++ b/include/bw_mm2.h @@ -29,8 +29,15 @@ *
      *
    • Version 1.0.0: *
        - *
      • Now using size_t instead of - * BW_SIZE_T.
      • + *
      • bw_mm2_process() and + * bw_mm2_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: @@ -59,8 +66,8 @@ * }}} */ -#ifndef _BW_MM2_H -#define _BW_MM2_H +#ifndef BW_MM2_H +#define BW_MM2_H #include @@ -71,13 +78,13 @@ extern "C" { /*! api {{{ * #### bw_mm2_coeffs * ```>>> */ -typedef struct _bw_mm2_coeffs bw_mm2_coeffs; +typedef struct bw_mm2_coeffs bw_mm2_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_mm2_state * ```>>> */ -typedef struct _bw_mm2_state bw_mm2_state; +typedef struct bw_mm2_state bw_mm2_state; /*! <<<``` * Internal state and related. * @@ -101,10 +108,10 @@ static inline void bw_mm2_reset_coeffs(bw_mm2_coeffs *BW_RESTRICT coeffs); * * #### bw_mm2_reset_state() * ```>>> */ -static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x0); +static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x_0); /*! <<<``` * Resets the given `state` to its initial values using the given `coeffs` - * and the quiescent/initial input value `x0`. + * and the quiescent/initial input value `x_0`. * * #### bw_mm2_update_coeffs_ctrl() * ```>>> */ @@ -127,7 +134,7 @@ static inline float bw_mm2_process1(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_ * * #### bw_mm2_process() * ```>>> */ -static inline void bw_mm2_process(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_mm2_process(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_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 @@ -135,7 +142,7 @@ static inline void bw_mm2_process(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_stat * * #### bw_mm2_process_multi() * ```>>> */ -static inline void bw_mm2_process_multi(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_mm2_process_multi(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_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 @@ -228,7 +235,7 @@ static inline void bw_mm2_set_coeff_hp(bw_mm2_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_mm2_coeffs { +struct bw_mm2_coeffs { // Sub-components bw_svf_coeffs svf_coeffs; bw_gain_coeffs gain_x_coeffs; @@ -237,7 +244,7 @@ struct _bw_mm2_coeffs { bw_gain_coeffs gain_hp_coeffs; }; -struct _bw_mm2_state { +struct bw_mm2_state { bw_svf_state svf_state; }; @@ -273,8 +280,8 @@ static inline void bw_mm2_reset_coeffs(bw_mm2_coeffs *BW_RESTRICT coeffs) { bw_gain_reset_coeffs(&coeffs->gain_hp_coeffs); } -static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x0) { - bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x0); +static inline void bw_mm2_reset_state(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, float x_0) { + bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x_0); } static inline void bw_mm2_update_coeffs_ctrl(bw_mm2_coeffs *BW_RESTRICT coeffs) { @@ -303,19 +310,19 @@ static inline float bw_mm2_process1(const bw_mm2_coeffs *BW_RESTRICT coeffs, bw_ return vx + vlp + vbp + vhp; } -static inline void bw_mm2_process(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_mm2_process(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_mm2_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_mm2_update_coeffs_audio(coeffs); y[i] = bw_mm2_process1(coeffs, state, x[i]); } } -static inline void bw_mm2_process_multi(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_mm2_process_multi(bw_mm2_coeffs *BW_RESTRICT coeffs, bw_mm2_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_mm2_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_mm2_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_mm2_process1(coeffs, state[j], x[j][i]); } } @@ -353,6 +360,132 @@ static inline void bw_mm2_set_coeff_hp(bw_mm2_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::MM2 + * ```>>> */ +template +class MM2 { +public: + MM2(); + + void setSampleRate(float sampleRate); + void reset(float x_0 = 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 setCutoff(float value); + void setQ(float value); + void setPrewarpAtCutoff(bool value); + void setPrewarpFreq(float value); + void setCoeffX(float value); + void setCoeffLp(float value); + void setCoeffBp(float value); + void setCoeffHp(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_mm2_coeffs coeffs; + bw_mm2_state states[N_CHANNELS]; + bw_mm2_state *statesP[N_CHANNELS]; +}; + +template +inline MM2::MM2() { + bw_mm2_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void MM2::setSampleRate(float sampleRate) { + bw_mm2_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void MM2::reset(float x_0) { + bw_mm2_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_mm2_reset_state(&coeffs, states + i, x_0); +} + +template +inline void MM2::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_mm2_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void MM2::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void MM2::setCutoff(float value) { + bw_mm2_set_cutoff(&coeffs, value); +} + +template +inline void MM2::setQ(float value) { + bw_mm2_set_Q(&coeffs, value); +} + +template +inline void MM2::setPrewarpAtCutoff(bool value) { + bw_mm2_set_prewarp_at_cutoff(&coeffs, value); +} + +template +inline void MM2::setPrewarpFreq(float value) { + bw_mm2_set_prewarp_freq(&coeffs, value); +} + +template +inline void MM2::setCoeffX(float value) { + bw_mm2_set_coeff_x(&coeffs, value); +} + +template +inline void MM2::setCoeffLp(float value) { + bw_mm2_set_coeff_lp(&coeffs, value); +} + +template +inline void MM2::setCoeffBp(float value) { + bw_mm2_set_coeff_bp(&coeffs, value); +} + +template +inline void MM2::setCoeffHp(float value) { + bw_mm2_set_coeff_hp(&coeffs, value); +} + } #endif diff --git a/include/bw_noise_gate.h b/include/bw_noise_gate.h index ddce819..df71115 100644 --- a/include/bw_noise_gate.h +++ b/include/bw_noise_gate.h @@ -29,8 +29,15 @@ *
        *
      • Version 1.0.0: *
          - *
        • Now using size_t instead of - * BW_SIZE_T.
        • + *
        • bw_noise_gate_process() and + * bw_noise_gate_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: @@ -53,8 +60,8 @@ * }}} */ -#ifndef _BW_NOISE_GATE_H -#define _BW_NOISE_GATE_H +#ifndef BW_NOISE_GATE_H +#define BW_NOISE_GATE_H #include @@ -65,13 +72,13 @@ extern "C" { /*! api {{{ * #### bw_noise_gate_coeffs * ```>>> */ -typedef struct _bw_noise_gate_coeffs bw_noise_gate_coeffs; +typedef struct bw_noise_gate_coeffs bw_noise_gate_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_noise_gate_state * ```>>> */ -typedef struct _bw_noise_gate_state bw_noise_gate_state; +typedef struct bw_noise_gate_state bw_noise_gate_state; /*! <<<``` * Internal state and related. * @@ -121,7 +128,7 @@ static inline float bw_noise_gate_process1(const bw_noise_gate_coeffs *BW_RESTRI * * #### bw_noise_gate_process() * ```>>> */ -static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, int n_samples); +static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_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 @@ -130,7 +137,7 @@ static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeff * * #### bw_noise_gate_process_multi() * ```>>> */ -static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state **BW_RESTRICT state, const float **x, const float **x_sc, float **y, int n_channels, int n_samples); +static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_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`, @@ -201,7 +208,7 @@ static inline void bw_noise_gate_set_release_tau(bw_noise_gate_coeffs *BW_RESTRI extern "C" { #endif -struct _bw_noise_gate_coeffs { +struct bw_noise_gate_coeffs { // Sub-noise_gateonents bw_env_follow_coeffs env_follow_coeffs; bw_one_pole_coeffs smooth_coeffs; @@ -216,7 +223,7 @@ struct _bw_noise_gate_coeffs { float ratio; }; -struct _bw_noise_gate_state { +struct bw_noise_gate_state { bw_env_follow_state env_follow_state; }; @@ -260,19 +267,19 @@ static inline float bw_noise_gate_process1(const bw_noise_gate_coeffs *BW_RESTRI return env < thresh ? bw_pow2f(coeffs->kc * bw_log2f(thresh * bw_rcpf(env))) * x : x; } -static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, int n_samples) { +static inline void bw_noise_gate_process(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state *BW_RESTRICT state, const float *x, const float *x_sc, float *y, size_t n_samples) { bw_noise_gate_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_noise_gate_update_coeffs_audio(coeffs); y[i] = bw_noise_gate_process1(coeffs, state, x[i], x_sc[i]); } } -static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_state **BW_RESTRICT state, const float **x, const float **x_sc, float **y, int n_channels, int n_samples) { +static inline void bw_noise_gate_process_multi(bw_noise_gate_coeffs *BW_RESTRICT coeffs, bw_noise_gate_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_noise_gate_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_noise_gate_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_noise_gate_process1(coeffs, state[j], x[j][i], x_sc[j][i]); } } @@ -298,6 +305,118 @@ static inline void bw_noise_gate_set_release_tau(bw_noise_gate_coeffs *BW_RESTRI } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::NoiseGate + * ```>>> */ +template +class NoiseGate { +public: + NoiseGate(); + + 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); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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_noise_gate_coeffs coeffs; + bw_noise_gate_state states[N_CHANNELS]; + bw_noise_gate_state *statesP[N_CHANNELS]; +}; + +template +inline NoiseGate::NoiseGate() { + bw_noise_gate_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void NoiseGate::setSampleRate(float sampleRate) { + bw_noise_gate_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void NoiseGate::reset() { + bw_noise_gate_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_noise_gate_reset_state(&coeffs, states + i); +} + +template +inline void NoiseGate::process( + const float * const *x, + const float * const *xSC, + float **y, + size_t nSamples) { + bw_noise_gate_process_multi(&coeffs, statesP, x, xSC, y, N_CHANNELS, nSamples); +} + +template +inline void NoiseGate::process( + std::array x, + std::array xSC, + std::array y, + size_t nSamples) { + process(x.data(), xSC.data(), y.data(), nSamples); +} + +template +inline void NoiseGate::setTreshLin(float value) { + bw_noise_gate_set_thresh_lin(&coeffs, value); +} + +template +inline void NoiseGate::setTreshDBFS(float value) { + bw_noise_gate_set_thresh_dBFS(&coeffs, value); +} + +template +inline void NoiseGate::setRatio(float value) { + bw_noise_gate_set_ratio(&coeffs, value); +} + +template +inline void NoiseGate::setAttackTau(float value) { + bw_noise_gate_set_attack_tau(&coeffs, value); +} + +template +inline void NoiseGate::setReleaseTau(float value) { + bw_noise_gate_set_release_tau(&coeffs, value); +} + } #endif diff --git a/include/bw_noise_gen.h b/include/bw_noise_gen.h index e707e0d..52d9e6c 100644 --- a/include/bw_noise_gen.h +++ b/include/bw_noise_gen.h @@ -33,8 +33,15 @@ *
          *
        • Version 1.0.0: *
            - *
          • Now using size_t instead of - * BW_SIZE_T.
          • + *
          • bw_noise_gen_process() and + * bw_noise_gen_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_NOISE_GEN_H -#define _BW_NOISE_GEN_H +#ifndef BW_NOISE_GEN_H +#define BW_NOISE_GEN_H #include @@ -74,7 +81,7 @@ extern "C" { /*! api {{{ * #### bw_noise_gen_coeffs * ```>>> */ -typedef struct _bw_noise_gen_coeffs bw_noise_gen_coeffs; +typedef struct bw_noise_gen_coeffs bw_noise_gen_coeffs; /*! <<<``` * Coefficients and related. * @@ -103,14 +110,14 @@ static inline float bw_noise_gen_process1_scaling(const bw_noise_gen_coeffs *BW_ * * #### bw_noise_gen_process() * ```>>> */ -static inline void bw_noise_gen_process(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float *BW_RESTRICT y, int n_samples); +static inline void bw_noise_gen_process(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float *BW_RESTRICT y, size_t n_samples); /*! <<<``` * Generates and fills the first `n_samples` of the output buffer `y` using * `coeffs`. * * #### bw_noise_gen_process_multi() * ```>>> */ -static inline void bw_noise_gen_process_multi(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float **y, int n_channels, int n_samples); +static inline void bw_noise_gen_process_multi(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float **y, size_t n_channels, size_t n_samples); /*! <<<``` * Generates and fills the first `n_samples` of the `n_channels` output * buffers `y` using `coeffs`. @@ -153,7 +160,7 @@ static inline float bw_noise_gen_get_scaling_k(const bw_noise_gen_coeffs *BW_RES extern "C" { #endif -struct _bw_noise_gen_coeffs { +struct bw_noise_gen_coeffs { // Coefficients float scaling_k; @@ -179,17 +186,17 @@ static inline float bw_noise_gen_process1_scaling(const bw_noise_gen_coeffs *BW_ return coeffs->scaling_k * bw_randf(coeffs->state); } -static inline void bw_noise_gen_process(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float *BW_RESTRICT y, int n_samples) { +static inline void bw_noise_gen_process(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float *BW_RESTRICT y, size_t n_samples) { if (coeffs->sample_rate_scaling) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_noise_gen_process1(coeffs); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_noise_gen_process1_scaling(coeffs); } -static inline void bw_noise_gen_process_multi(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float **y, int n_channels, int n_samples) { - for (int i = 0; i < n_channels; i++) +static inline void bw_noise_gen_process_multi(bw_noise_gen_coeffs *BW_RESTRICT coeffs, float **y, size_t n_channels, size_t n_samples) { + for (size_t i = 0; i < n_channels; i++) bw_noise_gen_process(coeffs, y[i], n_samples); } @@ -202,6 +209,81 @@ static inline float bw_noise_gen_get_scaling_k(const bw_noise_gen_coeffs *BW_RES } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::NoiseGen + * ```>>> */ +template +class NoiseGen { +public: + NoiseGen(uint64_t *BW_RESTRICT state); + + void setSampleRate(float sampleRate); + void process( + float **y, + size_t nSamples); + void process( + std::array y, + size_t nSamples); + + void setSampleRateScaling(bool value); + + float getScalingK(); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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_noise_gen_coeffs coeffs; +}; + +template +inline NoiseGen::NoiseGen(uint64_t *BW_RESTRICT state) { + bw_noise_gen_init(&coeffs, state); +} + +template +inline void NoiseGen::setSampleRate(float sampleRate) { + bw_noise_gen_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void NoiseGen::process( + float **y, + size_t nSamples) { + bw_noise_gen_process_multi(&coeffs, y, N_CHANNELS, nSamples); +} + +template +inline void NoiseGen::process( + std::array y, + size_t nSamples) { + process(y.data(), nSamples); +} + +template +inline void NoiseGen::setSampleRateScaling(bool value) { + bw_noise_gen_set_sample_rate_scaling(&coeffs, value); +} + +template +inline float NoiseGen::getScalingK() { + return bw_noise_gen_get_scaling_k(&coeffs); +} + } #endif diff --git a/include/bw_notch.h b/include/bw_notch.h index 60c07dc..0cd934b 100644 --- a/include/bw_notch.h +++ b/include/bw_notch.h @@ -30,8 +30,15 @@ *
            *
          • Version 1.0.0: *
              - *
            • Now using size_t instead of - * BW_SIZE_T.
            • + *
            • bw_notch_process() and + * bw_notch_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_NOTCH_H -#define _BW_NOTCH_H +#ifndef BW_NOTCH_H +#define BW_NOTCH_H #include @@ -72,13 +79,13 @@ extern "C" { /*! api {{{ * #### bw_notch_coeffs * ```>>> */ -typedef struct _bw_notch_coeffs bw_notch_coeffs; +typedef struct bw_notch_coeffs bw_notch_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_notch_state * ```>>> */ -typedef struct _bw_notch_state bw_notch_state; +typedef struct bw_notch_state bw_notch_state; /*! <<<``` * Internal state and related. * @@ -102,10 +109,10 @@ static inline void bw_notch_reset_coeffs(bw_notch_coeffs *BW_RESTRICT coeffs); * * #### bw_notch_reset_state() * ```>>> */ -static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x0); +static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x_0); /*! <<<``` * Resets the given `state` to its initial values using the given `coeffs` - * and the quiescent/initial input value `x0`. + * and the quiescent/initial input value `x_0`. * * #### bw_notch_update_coeffs_ctrl() * ```>>> */ @@ -128,7 +135,7 @@ static inline float bw_notch_process1(const bw_notch_coeffs *BW_RESTRICT coeffs, * * #### bw_notch_process() * ```>>> */ -static inline void bw_notch_process(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_notch_process(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_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 @@ -136,7 +143,7 @@ static inline void bw_notch_process(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notc * * #### bw_notch_process_multi() * ```>>> */ -static inline void bw_notch_process_multi(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_notch_process_multi(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_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 @@ -177,12 +184,12 @@ static inline void bw_notch_set_Q(bw_notch_coeffs *BW_RESTRICT coeffs, float val extern "C" { #endif -struct _bw_notch_coeffs { +struct bw_notch_coeffs { // Sub-components bw_svf_coeffs svf_coeffs; }; -struct _bw_notch_state { +struct bw_notch_state { bw_svf_state svf_state; }; @@ -198,8 +205,8 @@ static inline void bw_notch_reset_coeffs(bw_notch_coeffs *BW_RESTRICT coeffs) { bw_svf_reset_coeffs(&coeffs->svf_coeffs); } -static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x0) { - bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x0); +static inline void bw_notch_reset_state(const bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, float x_0) { + bw_svf_reset_state(&coeffs->svf_coeffs, &state->svf_state, x_0); } static inline void bw_notch_update_coeffs_ctrl(bw_notch_coeffs *BW_RESTRICT coeffs) { @@ -216,19 +223,19 @@ static inline float bw_notch_process1(const bw_notch_coeffs *BW_RESTRICT coeffs, return lp + hp; } -static inline void bw_notch_process(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_notch_process(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_notch_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_notch_update_coeffs_audio(coeffs); y[i] = bw_notch_process1(coeffs, state, x[i]); } } -static inline void bw_notch_process_multi(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_notch_process_multi(bw_notch_coeffs *BW_RESTRICT coeffs, bw_notch_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_notch_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_notch_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_notch_process1(coeffs, state[j], x[j][i]); } } @@ -242,6 +249,96 @@ static inline void bw_notch_set_Q(bw_notch_coeffs *BW_RESTRICT coeffs, float val } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Notch + * ```>>> */ +template +class Notch { +public: + Notch(); + + void setSampleRate(float sampleRate); + void reset(float x_0 = 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 setCutoff(float value); + void setQ(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_notch_coeffs coeffs; + bw_notch_state states[N_CHANNELS]; + bw_notch_state *statesP[N_CHANNELS]; +}; + +template +inline Notch::Notch() { + bw_notch_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void Notch::setSampleRate(float sampleRate) { + bw_notch_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Notch::reset(float x0) { + bw_notch_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_notch_reset_state(&coeffs, states + i, x0); +} + +template +inline void Notch::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_notch_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void Notch::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Notch::setCutoff(float value) { + bw_notch_set_cutoff(&coeffs, value); +} + +template +inline void Notch::setQ(float value) { + bw_notch_set_Q(&coeffs, value); +} + } #endif diff --git a/include/bwpp_mm1.h b/include/bwpp_mm1.h deleted file mode 100644 index da55b46..0000000 --- a/include/bwpp_mm1.h +++ /dev/null @@ -1,119 +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_MM1_H -#define BWPP_MM1_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::MM1 - * ```>>> */ -template -class MM1 { -public: - MM1(); - - void setSampleRate(float sampleRate); - void reset(float x0 = 0.f); - void process( - std::array x, - std::array y, - int nSamples); - - void setCutoff(float value); - void setPrewarpAtCutoff(bool value); - void setPrewarpFreq(float value); - void setCoeffX(float value); - void setCoeffLp(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_mm1_coeffs coeffs; - bw_mm1_state states[N_CHANNELS]; - bw_mm1_state *statesP[N_CHANNELS]; -}; - -template -inline MM1::MM1() { - bw_mm1_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void MM1::setSampleRate(float sampleRate) { - bw_mm1_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void MM1::reset(float x0) { - bw_mm1_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_mm1_reset_state(&coeffs, states + i, x0); -} - -template -inline void MM1::process( - std::array x, - std::array y, - int nSamples) { - bw_mm1_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void MM1::setCutoff(float value) { - bw_mm1_set_cutoff(&coeffs, value); -} - -template -inline void MM1::setPrewarpAtCutoff(bool value) { - bw_mm1_set_prewarp_at_cutoff(&coeffs, value); -} - -template -inline void MM1::setPrewarpFreq(float value) { - bw_mm1_set_prewarp_freq(&coeffs, value); -} - -template -inline void MM1::setCoeffX(float value) { - bw_mm1_set_coeff_x(&coeffs, value); -} - -template -inline void MM1::setCoeffLp(float value) { - bw_mm1_set_coeff_lp(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_mm2.h b/include/bwpp_mm2.h deleted file mode 100644 index 762b017..0000000 --- a/include/bwpp_mm2.h +++ /dev/null @@ -1,137 +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_MM2_H -#define BWPP_MM2_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::MM2 - * ```>>> */ -template -class MM2 { -public: - MM2(); - - void setSampleRate(float sampleRate); - void reset(float x0 = 0.f); - void process( - std::array x, - std::array y, - int nSamples); - - void setCutoff(float value); - void setQ(float value); - void setPrewarpAtCutoff(bool value); - void setPrewarpFreq(float value); - void setCoeffX(float value); - void setCoeffLp(float value); - void setCoeffBp(float value); - void setCoeffHp(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_mm2_coeffs coeffs; - bw_mm2_state states[N_CHANNELS]; - bw_mm2_state *statesP[N_CHANNELS]; -}; - -template -inline MM2::MM2() { - bw_mm2_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void MM2::setSampleRate(float sampleRate) { - bw_mm2_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void MM2::reset(float x0) { - bw_mm2_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_mm2_reset_state(&coeffs, states + i, x0); -} - -template -inline void MM2::process( - std::array x, - std::array y, - int nSamples) { - bw_mm2_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void MM2::setCutoff(float value) { - bw_mm2_set_cutoff(&coeffs, value); -} - -template -inline void MM2::setQ(float value) { - bw_mm2_set_Q(&coeffs, value); -} - -template -inline void MM2::setPrewarpAtCutoff(bool value) { - bw_mm2_set_prewarp_at_cutoff(&coeffs, value); -} - -template -inline void MM2::setPrewarpFreq(float value) { - bw_mm2_set_prewarp_freq(&coeffs, value); -} - -template -inline void MM2::setCoeffX(float value) { - bw_mm2_set_coeff_x(&coeffs, value); -} - -template -inline void MM2::setCoeffLp(float value) { - bw_mm2_set_coeff_lp(&coeffs, value); -} - -template -inline void MM2::setCoeffBp(float value) { - bw_mm2_set_coeff_bp(&coeffs, value); -} - -template -inline void MM2::setCoeffHp(float value) { - bw_mm2_set_coeff_hp(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_noise_gate.h b/include/bwpp_noise_gate.h deleted file mode 100644 index 4c6779b..0000000 --- a/include/bwpp_noise_gate.h +++ /dev/null @@ -1,121 +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_NOISE_GATE_H -#define BWPP_NOISE_GATE_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::NoiseGate - * ```>>> */ -template -class NoiseGate { -public: - NoiseGate(); - - 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); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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_noise_gate_coeffs coeffs; - bw_noise_gate_state states[N_CHANNELS]; - bw_noise_gate_state *statesP[N_CHANNELS]; -}; - -template -inline NoiseGate::NoiseGate() { - bw_noise_gate_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void NoiseGate::setSampleRate(float sampleRate) { - bw_noise_gate_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void NoiseGate::reset() { - bw_noise_gate_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_noise_gate_reset_state(&coeffs, states + i); -} - -template -inline void NoiseGate::process( - std::array x, - std::array xSC, - std::array y, - int nSamples) { - bw_noise_gate_process_multi(&coeffs, statesP, x.data(), xSC.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void NoiseGate::setTreshLin(float value) { - bw_noise_gate_set_thresh_lin(&coeffs, value); -} - -template -inline void NoiseGate::setTreshDBFS(float value) { - bw_noise_gate_set_thresh_dBFS(&coeffs, value); -} - -template -inline void NoiseGate::setRatio(float value) { - bw_noise_gate_set_ratio(&coeffs, value); -} - -template -inline void NoiseGate::setAttackTau(float value) { - bw_noise_gate_set_attack_tau(&coeffs, value); -} - -template -inline void NoiseGate::setReleaseTau(float value) { - bw_noise_gate_set_release_tau(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_noise_gen.h b/include/bwpp_noise_gen.h deleted file mode 100644 index 9ff9e62..0000000 --- a/include/bwpp_noise_gen.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_NOISE_GEN_H -#define BWPP_NOISE_GEN_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::NoiseGen - * ```>>> */ -template -class NoiseGen { -public: - NoiseGen(uint64_t *BW_RESTRICT state); - - void setSampleRate(float sampleRate); - void process( - std::array y, - int nSamples); - - void setSampleRateScaling(bool value); - - float getScalingK(); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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_noise_gen_coeffs coeffs; -}; - -template -inline NoiseGen::NoiseGen(uint64_t *BW_RESTRICT state) { - bw_noise_gen_init(&coeffs, state); -} - -template -inline void NoiseGen::setSampleRate(float sampleRate) { - bw_noise_gen_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void NoiseGen::process( - std::array y, - int nSamples) { - bw_noise_gen_process_multi(&coeffs, y.data(), N_CHANNELS, nSamples); -} - -template -inline void NoiseGen::setSampleRateScaling(bool value) { - bw_noise_gen_set_sample_rate_scaling(&coeffs, value); -} - -template -inline float NoiseGen::getScalingK() { - return bw_noise_gen_get_scaling_k(&coeffs); -} - -} - -#endif diff --git a/include/bwpp_notch.h b/include/bwpp_notch.h deleted file mode 100644 index b18f0e4..0000000 --- a/include/bwpp_notch.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_NOTCH_H -#define BWPP_NOTCH_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Notch - * ```>>> */ -template -class Notch { -public: - Notch(); - - void setSampleRate(float sampleRate); - void reset(float x0 = 0.f); - void process( - std::array x, - std::array y, - int nSamples); - - void setCutoff(float value); - void setQ(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_notch_coeffs coeffs; - bw_notch_state states[N_CHANNELS]; - bw_notch_state *statesP[N_CHANNELS]; -}; - -template -inline Notch::Notch() { - bw_notch_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void Notch::setSampleRate(float sampleRate) { - bw_notch_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Notch::reset(float x0) { - bw_notch_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_notch_reset_state(&coeffs, states + i, x0); -} - -template -inline void Notch::process( - std::array x, - std::array y, - int nSamples) { - bw_notch_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Notch::setCutoff(float value) { - bw_notch_set_cutoff(&coeffs, value); -} - -template -inline void Notch::setQ(float value) { - bw_notch_set_Q(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_note_queue.h b/include/bwpp_note_queue.h deleted file mode 100644 index 9a504f1..0000000 --- a/include/bwpp_note_queue.h +++ /dev/null @@ -1,62 +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_NOTE_QUEUE_H -#define BWPP_NOTE_QUEUE_H - -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::NoteQueue - * ```>>> */ -class NoteQueue { -public: - NoteQueue(); - - void clear(); - void add(unsigned char note, bool pressed, float velocity, bool force_went_off); - - bw_note_queue queue; -}; -/*! <<<``` - * }}} */ - -/*** 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. */ - -inline NoteQueue::NoteQueue() { - bw_note_queue_reset(&queue); -} - -inline void NoteQueue::clear() { - bw_note_queue_clear(&queue); -} - -inline void NoteQueue::add(unsigned char note, bool pressed, float velocity, bool force_went_off) { - bw_note_queue_add(&queue, note, pressed, velocity, force_went_off); -} - -} - -#endif