diff --git a/examples/fxpp_fuzz/src/bw_example_fxpp_fuzz.h b/examples/fxpp_fuzz/src/bw_example_fxpp_fuzz.h index d0975f2..8991355 100644 --- a/examples/fxpp_fuzz/src/bw_example_fxpp_fuzz.h +++ b/examples/fxpp_fuzz/src/bw_example_fxpp_fuzz.h @@ -23,7 +23,7 @@ #include "platform.h" -#include +#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 caf7d2a..10c0ee9 100644 --- a/examples/synthpp_mono/src/bw_example_synthpp_mono.h +++ b/examples/synthpp_mono/src/bw_example_synthpp_mono.h @@ -32,8 +32,8 @@ #include #include #include -#include -#include +#include +#include #include using namespace Brickworks; diff --git a/examples/synthpp_poly/src/bw_example_synthpp_poly.h b/examples/synthpp_poly/src/bw_example_synthpp_poly.h index 3723cab..5e85506 100644 --- a/examples/synthpp_poly/src/bw_example_synthpp_poly.h +++ b/examples/synthpp_poly/src/bw_example_synthpp_poly.h @@ -33,8 +33,8 @@ #include #include #include -#include -#include +#include +#include #include using namespace Brickworks; diff --git a/examples/synthpp_simple/src/bw_example_synthpp_simple.h b/examples/synthpp_simple/src/bw_example_synthpp_simple.h index b3953f4..79ae2dc 100644 --- a/examples/synthpp_simple/src/bw_example_synthpp_simple.h +++ b/examples/synthpp_simple/src/bw_example_synthpp_simple.h @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include using namespace Brickworks; diff --git a/include/bw_env_follow.h b/include/bw_env_follow.h index 7bea373..87468dd 100644 --- a/include/bw_env_follow.h +++ b/include/bw_env_follow.h @@ -30,8 +30,15 @@ *
    *
  • Version 1.0.0: *
      - *
    • Now using size_t instead of - * BW_SIZE_T.
    • + *
    • bw_env_follow_process() and + * bw_env_follow_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: @@ -64,8 +71,8 @@ * }}} */ -#ifndef _BW_ENV_FOLLOW_H -#define _BW_ENV_FOLLOW_H +#ifndef BW_ENV_FOLLOW_H +#define BW_ENV_FOLLOW_H #include @@ -76,13 +83,13 @@ extern "C" { /*! api {{{ * #### bw_env_follow_coeffs * ```>>> */ -typedef struct _bw_env_follow_coeffs bw_env_follow_coeffs; +typedef struct bw_env_follow_coeffs bw_env_follow_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_env_follow_state * ```>>> */ -typedef struct _bw_env_follow_state bw_env_follow_state; +typedef struct bw_env_follow_state bw_env_follow_state; /*! <<<``` * Internal state and related. * @@ -131,7 +138,7 @@ static inline float bw_env_follow_process1(const bw_env_follow_coeffs *BW_RESTRI * * #### bw_env_follow_process() * ```>>> */ -static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_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 @@ -141,7 +148,7 @@ static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeff * * #### bw_env_follow_process_multi() * ```>>> */ -static inline void bw_env_follow_process_multi(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_env_follow_process_multi(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_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 @@ -191,12 +198,12 @@ static inline float bw_env_follow_get_y_z1(const bw_env_follow_state *BW_RESTRIC extern "C" { #endif -struct _bw_env_follow_coeffs { +struct bw_env_follow_coeffs { // Sub-components bw_one_pole_coeffs one_pole_coeffs; }; -struct _bw_env_follow_state { +struct bw_env_follow_state { bw_one_pole_state one_pole_state; }; @@ -229,35 +236,35 @@ static inline float bw_env_follow_process1(const bw_env_follow_coeffs *BW_RESTRI return bw_one_pole_process1_asym(&coeffs->one_pole_coeffs, &state->one_pole_state, x); } -static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_env_follow_process(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_env_follow_update_coeffs_ctrl(coeffs); if (y != NULL) - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_env_follow_update_coeffs_audio(coeffs); y[i] = bw_env_follow_process1(coeffs, state, x[i]); } else - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_env_follow_update_coeffs_audio(coeffs); bw_env_follow_process1(coeffs, state, x[i]); } } -static inline void bw_env_follow_process_multi(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_env_follow_process_multi(bw_env_follow_coeffs *BW_RESTRICT coeffs, bw_env_follow_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_env_follow_update_coeffs_ctrl(coeffs); if (y != NULL) - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_env_follow_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) { + for (size_t j = 0; j < n_channels; j++) { const float v = bw_env_follow_process1(coeffs, state[j], x[j][i]); if (y[j] != NULL) y[j][i] = v; } } else - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_env_follow_update_coeffs_audio(coeffs); - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) bw_env_follow_process1(coeffs, state[j], x[j][i]); } } @@ -275,6 +282,103 @@ static inline float bw_env_follow_get_y_z1(const bw_env_follow_state *BW_RESTRIC } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::EnvFollow + * ```>>> */ +template +class EnvFollow { +public: + EnvFollow(); + + 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 setAttackTau(float value); + void setReleaseTau(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_env_follow_coeffs coeffs; + bw_env_follow_state states[N_CHANNELS]; + bw_env_follow_state *statesP[N_CHANNELS]; +}; + +template +inline EnvFollow::EnvFollow() { + bw_env_follow_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void EnvFollow::setSampleRate(float sampleRate) { + bw_env_follow_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void EnvFollow::reset() { + bw_env_follow_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_env_follow_reset_state(&coeffs, states + i); +} + +template +inline void EnvFollow::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_env_follow_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void EnvFollow::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void EnvFollow::setAttackTau(float value) { + bw_env_follow_set_attack_tau(&coeffs, value); +} + +template +inline void EnvFollow::setReleaseTau(float value) { + bw_env_follow_set_release_tau(&coeffs, value); +} + +template +inline float EnvFollow::getYZ1(size_t channel) { + return bw_env_follow_get_y_z1(states + channel); +} + } #endif diff --git a/include/bw_env_gen.h b/include/bw_env_gen.h index b649c75..df68e27 100644 --- a/include/bw_env_gen.h +++ b/include/bw_env_gen.h @@ -42,8 +42,15 @@ *
      *
    • Version 1.0.0: *
        - *
      • Now using size_t instead of - * BW_SIZE_T.
      • + *
      • bw_env_gen_process() and + * bw_env_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: @@ -86,8 +93,8 @@ * }}} */ -#ifndef _BW_ENV_GEN_H -#define _BW_ENV_GEN_H +#ifndef BW_ENV_GEN_H +#define BW_ENV_GEN_H #include @@ -98,13 +105,13 @@ extern "C" { /*! api {{{ * #### bw_env_gen_coeffs * ```>>> */ -typedef struct _bw_env_gen_coeffs bw_env_gen_coeffs; +typedef struct bw_env_gen_coeffs bw_env_gen_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_env_gen_state * ```>>> */ -typedef struct _bw_env_gen_state bw_env_gen_state; +typedef struct bw_env_gen_state bw_env_gen_state; /*! <<<``` * Internal state and related. * @@ -177,7 +184,7 @@ static inline float bw_env_gen_process1(const bw_env_gen_coeffs *BW_RESTRICT coe * * #### bw_env_gen_process() * ```>>> */ -static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float *y, int n_samples); +static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float *y, size_t n_samples); /*! <<<``` * Generates and fills the first `n_samples` of the output buffer `y` using * the given `gate` value (`0` for off, non-`0` for on), while using and @@ -187,7 +194,7 @@ static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_ * * #### bw_env_gen_process_multi() * ```>>> */ -static inline void bw_env_gen_process_multi(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state **BW_RESTRICT state, char *gate, float **y, int n_channels, int n_samples); +static inline void bw_env_gen_process_multi(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state * const *BW_RESTRICT state, const char *gate, 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 the given `n_channels` `gate` values (`0` for off, @@ -263,7 +270,7 @@ static inline float bw_env_gen_get_y_z1(const bw_env_gen_state *state); extern "C" { #endif -struct _bw_env_gen_coeffs { +struct bw_env_gen_coeffs { // Sub-components bw_one_pole_coeffs smooth_coeffs; @@ -282,16 +289,16 @@ struct _bw_env_gen_coeffs { int param_changed; }; -struct _bw_env_gen_state { +struct bw_env_gen_state { bw_env_gen_phase phase; float y_z1; bw_one_pole_state smooth_state; }; -#define _BW_ENV_GEN_PARAM_ATTACK 1 -#define _BW_ENV_GEN_PARAM_DECAY (1<<1) -#define _BW_ENV_GEN_PARAM_SUSTAIN (1<<2) -#define _BW_ENV_GEN_PARAM_RELEASE (1<<3) +#define BW_ENV_GEN_PARAM_ATTACK 1 +#define BW_ENV_GEN_PARAM_DECAY (1<<1) +#define BW_ENV_GEN_PARAM_SUSTAIN (1<<2) +#define BW_ENV_GEN_PARAM_RELEASE (1<<3) static inline void bw_env_gen_init(bw_env_gen_coeffs *BW_RESTRICT coeffs) { bw_one_pole_init(&coeffs->smooth_coeffs); @@ -322,11 +329,11 @@ static inline void bw_env_gen_reset_state(const bw_env_gen_coeffs *BW_RESTRICT c static inline void bw_env_gen_update_coeffs_ctrl(bw_env_gen_coeffs *BW_RESTRICT coeffs) { if (coeffs->param_changed) { // 1 ns considered instantaneous - if (coeffs->param_changed & _BW_ENV_GEN_PARAM_ATTACK) + if (coeffs->param_changed & BW_ENV_GEN_PARAM_ATTACK) coeffs->attack_inc = coeffs->attack > 1e-9f ? coeffs->T * bw_rcpf(coeffs->attack) : INFINITY; - if (coeffs->param_changed & (_BW_ENV_GEN_PARAM_DECAY | _BW_ENV_GEN_PARAM_SUSTAIN)) + if (coeffs->param_changed & (BW_ENV_GEN_PARAM_DECAY | BW_ENV_GEN_PARAM_SUSTAIN)) coeffs->decay_inc = coeffs->decay > 1e-9f ? (coeffs->sustain - 1.f) * coeffs->T * bw_rcpf(coeffs->decay) : -INFINITY; - if (coeffs->param_changed & (_BW_ENV_GEN_PARAM_SUSTAIN | _BW_ENV_GEN_PARAM_RELEASE)) + if (coeffs->param_changed & (BW_ENV_GEN_PARAM_SUSTAIN | BW_ENV_GEN_PARAM_RELEASE)) coeffs->release_inc = coeffs->release > 1e-9f ? -coeffs->sustain * coeffs->T * bw_rcpf(coeffs->release) : -INFINITY; } } @@ -382,59 +389,59 @@ static inline float bw_env_gen_process1(const bw_env_gen_coeffs *BW_RESTRICT coe return v; } -static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float *y, int n_samples) { +static inline void bw_env_gen_process(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state, char gate, float *y, size_t n_samples) { bw_env_gen_update_coeffs_ctrl(coeffs); bw_env_gen_update_state_ctrl(coeffs, state, gate); if (y != NULL) - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) y[i] = bw_env_gen_process1(coeffs, state); else - for (int i = 0; i < n_samples; i++) + for (size_t i = 0; i < n_samples; i++) bw_env_gen_process1(coeffs, state); } -static inline void bw_env_gen_process_multi(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state **BW_RESTRICT state, char *gate, float **y, int n_channels, int n_samples) { +static inline void bw_env_gen_process_multi(bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state * const *BW_RESTRICT state, const char *gate, float **y, size_t n_channels, size_t n_samples) { bw_env_gen_update_coeffs_ctrl(coeffs); - for (int j = 0; j < n_channels; j++) + for (size_t j = 0; j < n_channels; j++) bw_env_gen_update_state_ctrl(coeffs, state[j], gate[j]); if (y != NULL) - for (int i = 0; i < n_samples; i++) - for (int j = 0; j < n_channels; j++) { + for (size_t i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) { const float v = bw_env_gen_process1(coeffs, state[j]); if (y[j] != NULL) y[j][i] = v; } else - for (int i = 0; i < n_samples; i++) - for (int j = 0; j < n_channels; j++) + for (size_t i = 0; i < n_samples; i++) + for (size_t j = 0; j < n_channels; j++) bw_env_gen_process1(coeffs, state[j]); } static inline void bw_env_gen_set_attack(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value) { if (coeffs->attack != value) { coeffs->attack = value; - coeffs->param_changed |= _BW_ENV_GEN_PARAM_ATTACK; + coeffs->param_changed |= BW_ENV_GEN_PARAM_ATTACK; } } static inline void bw_env_gen_set_decay(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value) { if (coeffs->decay != value) { coeffs->decay = value; - coeffs->param_changed |= _BW_ENV_GEN_PARAM_DECAY; + coeffs->param_changed |= BW_ENV_GEN_PARAM_DECAY; } } static inline void bw_env_gen_set_sustain(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value) { if (coeffs->sustain != value) { coeffs->sustain = value; - coeffs->param_changed |= _BW_ENV_GEN_PARAM_SUSTAIN; + coeffs->param_changed |= BW_ENV_GEN_PARAM_SUSTAIN; } } static inline void bw_env_gen_set_release(bw_env_gen_coeffs *BW_RESTRICT coeffs, float value) { if (coeffs->release != value) { coeffs->release = value; - coeffs->param_changed |= _BW_ENV_GEN_PARAM_RELEASE; + coeffs->param_changed |= BW_ENV_GEN_PARAM_RELEASE; } } @@ -446,12 +453,127 @@ static inline float bw_env_gen_get_y_z1(const bw_env_gen_state *state) { return state->y_z1; } -#undef _BW_ENV_GEN_PARAM_ATTACK -#undef _BW_ENV_GEN_PARAM_DECAY -#undef _BW_ENV_GEN_PARAM_SUSTAIN -#undef _BW_ENV_GEN_PARAM_RELEASE +#undef BW_ENV_GEN_PARAM_ATTACK +#undef BW_ENV_GEN_PARAM_DECAY +#undef BW_ENV_GEN_PARAM_SUSTAIN +#undef BW_ENV_GEN_PARAM_RELEASE #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::EnvGen + * ```>>> */ +template +class EnvGen { +public: + EnvGen(); + + void setSampleRate(float sampleRate); + void reset(); + void process( + const char *gate, + float **y, + size_t nSamples); + void process( + std::array gate, + std::array y, + size_t nSamples); + + void setAttack(float value); + void setDecay(float value); + void setSustain(float value); + void setRelease(float value); + + bw_env_gen_phase getPhase(size_t channel); + 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_env_gen_coeffs coeffs; + bw_env_gen_state states[N_CHANNELS]; + bw_env_gen_state *statesP[N_CHANNELS]; +}; + +template +inline EnvGen::EnvGen() { + bw_env_gen_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void EnvGen::setSampleRate(float sampleRate) { + bw_env_gen_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void EnvGen::reset() { + bw_env_gen_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_env_gen_reset_state(&coeffs, states + i); +} + +template +inline void EnvGen::process( + const char *gate, + float **y, + size_t nSamples) { + bw_env_gen_process_multi(&coeffs, statesP, gate, y, N_CHANNELS, nSamples); +} + +template +inline void EnvGen::process( + std::array gate, + std::array y, + size_t nSamples) { + process(gate.data(), y.data(), nSamples); +} + +template +inline void EnvGen::setAttack(float value) { + bw_env_gen_set_attack(&coeffs, value); +} + +template +inline void EnvGen::setDecay(float value) { + bw_env_gen_set_decay(&coeffs, value); +} + +template +inline void EnvGen::setSustain(float value) { + bw_env_gen_set_sustain(&coeffs, value); +} + +template +inline void EnvGen::setRelease(float value) { + bw_env_gen_set_release(&coeffs, value); +} + +template +inline bw_env_gen_phase EnvGen::getPhase(size_t channel) { + return bw_env_gen_get_phase(states + channel); +} + +template +inline float EnvGen::getYZ1(size_t channel) { + return bw_env_gen_get_y_z1(states + channel); +} + } #endif diff --git a/include/bw_fuzz.h b/include/bw_fuzz.h index 19d152e..8a0fab6 100644 --- a/include/bw_fuzz.h +++ b/include/bw_fuzz.h @@ -34,8 +34,15 @@ *
        *
      • Version 1.0.0: *
          - *
        • Now using size_t instead of - * BW_SIZE_T.
        • + *
        • bw_fuzz_process() and + * bw_fuzz_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: @@ -52,8 +59,8 @@ * }}} */ -#ifndef _BW_FUZZ_H -#define _BW_FUZZ_H +#ifndef BW_FUZZ_H +#define BW_FUZZ_H #include @@ -64,13 +71,13 @@ extern "C" { /*! api {{{ * #### bw_fuzz_coeffs * ```>>> */ -typedef struct _bw_fuzz_coeffs bw_fuzz_coeffs; +typedef struct bw_fuzz_coeffs bw_fuzz_coeffs; /*! <<<``` * Coefficients and related. * * #### bw_fuzz_state * ```>>> */ -typedef struct _bw_fuzz_state bw_fuzz_state; +typedef struct bw_fuzz_state bw_fuzz_state; /*! <<<``` * Internal state and related. * @@ -119,7 +126,7 @@ static inline float bw_fuzz_process1(const bw_fuzz_coeffs *BW_RESTRICT coeffs, b * * #### bw_fuzz_process() * ```>>> */ -static inline void bw_fuzz_process(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state *BW_RESTRICT state, const float *x, float *y, int n_samples); +static inline void bw_fuzz_process(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_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 @@ -127,7 +134,7 @@ static inline void bw_fuzz_process(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_s * * #### bw_fuzz_process_multi() * ```>>> */ -static inline void bw_fuzz_process_multi(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_fuzz_process_multi(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_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,7 +179,7 @@ static inline void bw_fuzz_set_volume(bw_fuzz_coeffs *BW_RESTRICT coeffs, float extern "C" { #endif -struct _bw_fuzz_coeffs { +struct bw_fuzz_coeffs { // Sub-components bw_svf_coeffs svf_coeffs; bw_hs1_coeffs hs1_coeffs; @@ -181,7 +188,7 @@ struct _bw_fuzz_coeffs { bw_gain_coeffs gain_coeffs; }; -struct _bw_fuzz_state { +struct bw_fuzz_state { // Sub-components bw_svf_state svf_state; bw_hs1_state hs1_state; @@ -245,19 +252,19 @@ static inline float bw_fuzz_process1(const bw_fuzz_coeffs *BW_RESTRICT coeffs, b return bw_gain_process1(&coeffs->gain_coeffs, y); } -static inline void bw_fuzz_process(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { +static inline void bw_fuzz_process(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) { bw_fuzz_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_fuzz_update_coeffs_audio(coeffs); y[i] = bw_fuzz_process1(coeffs, state, x[i]); } } -static inline void bw_fuzz_process_multi(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_fuzz_process_multi(bw_fuzz_coeffs *BW_RESTRICT coeffs, bw_fuzz_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_fuzz_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_fuzz_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_fuzz_process1(coeffs, state[j], x[j][i]); } } @@ -271,6 +278,96 @@ static inline void bw_fuzz_set_volume(bw_fuzz_coeffs *BW_RESTRICT coeffs, float } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Fuzz + * ```>>> */ +template +class Fuzz { +public: + Fuzz(); + + 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 setFuzz(float value); + void setVolume(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_fuzz_coeffs coeffs; + bw_fuzz_state states[N_CHANNELS]; + bw_fuzz_state *statesP[N_CHANNELS]; +}; + +template +inline Fuzz::Fuzz() { + bw_fuzz_init(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + statesP[i] = states + i; +} + +template +inline void Fuzz::setSampleRate(float sampleRate) { + bw_fuzz_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Fuzz::reset() { + bw_fuzz_reset_coeffs(&coeffs); + for (size_t i = 0; i < N_CHANNELS; i++) + bw_fuzz_reset_state(&coeffs, states + i); +} + +template +inline void Fuzz::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_fuzz_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples); +} + +template +inline void Fuzz::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Fuzz::setFuzz(float value) { + bw_fuzz_set_fuzz(&coeffs, value); +} + +template +inline void Fuzz::setVolume(float value) { + bw_fuzz_set_volume(&coeffs, value); +} + } #endif diff --git a/include/bw_gain.h b/include/bw_gain.h index aba0764..01aefa0 100644 --- a/include/bw_gain.h +++ b/include/bw_gain.h @@ -29,8 +29,15 @@ *
          *
        • Version 1.0.0: *
            - *
          • Now using size_t instead of - * BW_SIZE_T.
          • + *
          • bw_gain_process() and + * bw_gain_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: @@ -67,8 +74,8 @@ * }}} */ -#ifndef _BW_GAIN_H -#define _BW_GAIN_H +#ifndef BW_GAIN_H +#define BW_GAIN_H #include @@ -79,7 +86,7 @@ extern "C" { /*! api {{{ * #### bw_gain_coeffs * ```>>> */ -typedef struct _bw_gain_coeffs bw_gain_coeffs; +typedef struct bw_gain_coeffs bw_gain_coeffs; /*! <<<``` * Coefficients and related. * @@ -122,7 +129,7 @@ static inline float bw_gain_process1(const bw_gain_coeffs *BW_RESTRICT coeffs, f * * #### bw_gain_process() * ```>>> */ -static inline void bw_gain_process(bw_gain_coeffs *BW_RESTRICT coeffs, const float *x, float *y, int n_samples); +static inline void bw_gain_process(bw_gain_coeffs *BW_RESTRICT coeffs, 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 @@ -130,7 +137,7 @@ static inline void bw_gain_process(bw_gain_coeffs *BW_RESTRICT coeffs, const flo * * #### bw_gain_process_multi() * ```>>> */ -static inline void bw_gain_process_multi(bw_gain_coeffs *BW_RESTRICT coeffs, const float **x, float **y, int n_channels, int n_samples); +static inline void bw_gain_process_multi(bw_gain_coeffs *BW_RESTRICT coeffs, 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 @@ -183,7 +190,7 @@ static inline float bw_gain_get_gain(const bw_gain_coeffs *BW_RESTRICT coeffs); extern "C" { #endif -struct _bw_gain_coeffs { +struct bw_gain_coeffs { // Sub-components bw_one_pole_coeffs smooth_coeffs; bw_one_pole_state smooth_state; @@ -206,7 +213,7 @@ static inline void bw_gain_set_sample_rate(bw_gain_coeffs *BW_RESTRICT coeffs, f bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs); } -static inline void _bw_gain_do_update_coeffs(bw_gain_coeffs *BW_RESTRICT coeffs, char force) { +static inline void bw_gain_do_update_coeffs(bw_gain_coeffs *BW_RESTRICT coeffs, char force) { if (force || coeffs->smooth_tau != coeffs->smooth_tau_prev) { bw_one_pole_set_tau(&coeffs->smooth_coeffs, coeffs->smooth_tau); bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs); @@ -215,12 +222,12 @@ static inline void _bw_gain_do_update_coeffs(bw_gain_coeffs *BW_RESTRICT coeffs, } static inline void bw_gain_reset_coeffs(bw_gain_coeffs *BW_RESTRICT coeffs) { - _bw_gain_do_update_coeffs(coeffs, 1); + bw_gain_do_update_coeffs(coeffs, 1); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_state, coeffs->gain); } static inline void bw_gain_update_coeffs_ctrl(bw_gain_coeffs *BW_RESTRICT coeffs) { - _bw_gain_do_update_coeffs(coeffs, 0); + bw_gain_do_update_coeffs(coeffs, 0); } static inline void bw_gain_update_coeffs_audio(bw_gain_coeffs *BW_RESTRICT coeffs) { @@ -231,19 +238,19 @@ static inline float bw_gain_process1(const bw_gain_coeffs *BW_RESTRICT coeffs, f return bw_one_pole_get_y_z1(&coeffs->smooth_state) * x; } -static inline void bw_gain_process(bw_gain_coeffs *BW_RESTRICT coeffs, const float *x, float *y, int n_samples) { +static inline void bw_gain_process(bw_gain_coeffs *BW_RESTRICT coeffs, const float *x, float *y, size_t n_samples) { bw_gain_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_gain_update_coeffs_audio(coeffs); y[i] = bw_gain_process1(coeffs, x[i]); } } -static inline void bw_gain_process_multi(bw_gain_coeffs *BW_RESTRICT coeffs, const float **x, float **y, int n_channels, int n_samples) { +static inline void bw_gain_process_multi(bw_gain_coeffs *BW_RESTRICT coeffs, const float * const *x, float **y, size_t n_channels, size_t n_samples) { bw_gain_update_coeffs_ctrl(coeffs); - for (int i = 0; i < n_samples; i++) { + for (size_t i = 0; i < n_samples; i++) { bw_gain_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_gain_process1(coeffs, x[j][i]); } } @@ -265,6 +272,103 @@ static inline float bw_gain_get_gain(const bw_gain_coeffs *BW_RESTRICT coeffs) { } #ifdef __cplusplus +} + +#include + +namespace Brickworks { + +/*** Public C++ API ***/ + +/*! api_cpp {{{ + * ##### Brickworks::Gain + * ```>>> */ +template +class Gain { +public: + Gain(); + + 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 setGainLin(float value); + void setGainDB(float value); + void setSmoothTau(float value); + + float getGain(); +/*! <<<... + * } + * ``` + * }}} */ + +/*** 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_gain_coeffs coeffs; +}; + +template +inline Gain::Gain() { + bw_gain_init(&coeffs); +} + +template +inline void Gain::setSampleRate(float sampleRate) { + bw_gain_set_sample_rate(&coeffs, sampleRate); +} + +template +inline void Gain::reset() { + bw_gain_reset_coeffs(&coeffs); +} + +template +inline void Gain::process( + const float * const *x, + float **y, + size_t nSamples) { + bw_gain_process_multi(&coeffs, x, y, N_CHANNELS, nSamples); +} + +template +inline void Gain::process( + std::array x, + std::array y, + size_t nSamples) { + process(x.data(), y.data(), nSamples); +} + +template +inline void Gain::setGainLin(float value) { + bw_gain_set_gain_lin(&coeffs, value); +} + +template +inline void Gain::setGainDB(float value) { + bw_gain_set_gain_dB(&coeffs, value); +} + +template +inline void Gain::setSmoothTau(float value) { + bw_gain_set_smooth_tau(&coeffs, value); +} + +template +inline float Gain::getGain() { + return bw_gain_get_gain(&coeffs); +} + } #endif diff --git a/include/bwpp_env_follow.h b/include/bwpp_env_follow.h deleted file mode 100644 index c96341e..0000000 --- a/include/bwpp_env_follow.h +++ /dev/null @@ -1,108 +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_ENV_FOLLOW_H -#define BWPP_ENV_FOLLOW_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::EnvFollow - * ```>>> */ -template -class EnvFollow { -public: - EnvFollow(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setAttackTau(float value); - void setReleaseTau(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_env_follow_coeffs coeffs; - bw_env_follow_state states[N_CHANNELS]; - bw_env_follow_state *statesP[N_CHANNELS]; -}; - -template -inline EnvFollow::EnvFollow() { - bw_env_follow_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void EnvFollow::setSampleRate(float sampleRate) { - bw_env_follow_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void EnvFollow::reset() { - bw_env_follow_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_env_follow_reset_state(&coeffs, states + i); -} - -template -inline void EnvFollow::process( - std::array x, - std::array y, - int nSamples) { - bw_env_follow_process_multi(&coeffs, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void EnvFollow::setAttackTau(float value) { - bw_env_follow_set_attack_tau(&coeffs, value); -} - -template -inline void EnvFollow::setReleaseTau(float value) { - bw_env_follow_set_release_tau(&coeffs, value); -} - -template -inline float EnvFollow::getYZ1(size_t channel) { - return bw_env_follow_get_y_z1(states + channel); -} - -} - -#endif diff --git a/include/bwpp_env_gen.h b/include/bwpp_env_gen.h deleted file mode 100644 index 6bcfdc3..0000000 --- a/include/bwpp_env_gen.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Brickworks - * - * Copyright (C) 2023 Orastron Srl unipersonale - * - * Brickworks is free software: you can reenv_genribute 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 env_genributed 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_ENV_GEN_H -#define BWPP_ENV_GEN_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::EnvGen - * ```>>> */ -template -class EnvGen { -public: - EnvGen(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array gate, - std::array y, - int nSamples); - - void setAttack(float value); - void setDecay(float value); - void setSustain(float value); - void setRelease(float value); - - bw_env_gen_phase getPhase(size_t channel); - 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_env_gen_coeffs coeffs; - bw_env_gen_state states[N_CHANNELS]; - bw_env_gen_state *statesP[N_CHANNELS]; -}; - -template -inline EnvGen::EnvGen() { - bw_env_gen_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void EnvGen::setSampleRate(float sampleRate) { - bw_env_gen_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void EnvGen::reset() { - bw_env_gen_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_env_gen_reset_state(&coeffs, states + i); -} - -template -inline void EnvGen::process( - std::array gate, - std::array y, - int nSamples) { - bw_env_gen_process_multi(&coeffs, statesP, gate.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void EnvGen::setAttack(float value) { - bw_env_gen_set_attack(&coeffs, value); -} - -template -inline void EnvGen::setDecay(float value) { - bw_env_gen_set_decay(&coeffs, value); -} - -template -inline void EnvGen::setSustain(float value) { - bw_env_gen_set_sustain(&coeffs, value); -} - -template -inline void EnvGen::setRelease(float value) { - bw_env_gen_set_release(&coeffs, value); -} - -template -inline bw_env_gen_phase EnvGen::getPhase(size_t channel) { - return bw_env_gen_get_phase(states + channel); -} - -template -inline float EnvGen::getYZ1(size_t channel) { - return bw_env_gen_get_y_z1(states + channel); -} - -} - -#endif diff --git a/include/bwpp_fuzz.h b/include/bwpp_fuzz.h deleted file mode 100644 index 0210ec0..0000000 --- a/include/bwpp_fuzz.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Brickworks - * - * Copyright (C) 2023 Orastron Srl unipersonale - * - * Brickworks is free software: you can refuzzribute 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 fuzzributed 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_FUZZ_H -#define BWPP_FUZZ_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Fuzz - * ```>>> */ -template -class Fuzz { -public: - Fuzz(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setFuzz(float value); - void setVolume(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_fuzz_coeffs coeffs; - bw_fuzz_state states[N_CHANNELS]; - bw_fuzz_state *statesP[N_CHANNELS]; -}; - -template -inline Fuzz::Fuzz() { - bw_fuzz_init(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - statesP[i] = states + i; -} - -template -inline void Fuzz::setSampleRate(float sampleRate) { - bw_fuzz_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Fuzz::reset() { - bw_fuzz_reset_coeffs(&coeffs); - for (size_t i = 0; i < N_CHANNELS; i++) - bw_fuzz_reset_state(&coeffs, states + i); -} - -template -inline void Fuzz::process( - std::array x, - std::array y, - int nSamples) { - bw_fuzz_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Fuzz::setFuzz(float value) { - bw_fuzz_set_fuzz(&coeffs, value); -} - -template -inline void Fuzz::setVolume(float value) { - bw_fuzz_set_volume(&coeffs, value); -} - -} - -#endif diff --git a/include/bwpp_gain.h b/include/bwpp_gain.h deleted file mode 100644 index 7fff496..0000000 --- a/include/bwpp_gain.h +++ /dev/null @@ -1,108 +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_GAIN_H -#define BWPP_GAIN_H - -#include -#include - -namespace Brickworks { - -/*! api {{{ - * ##### Brickworks::Gain - * ```>>> */ -template -class Gain { -public: - Gain(); - - void setSampleRate(float sampleRate); - void reset(); - void process( - std::array x, - std::array y, - int nSamples); - - void setGainLin(float value); - void setGainDB(float value); - void setSmoothTau(float value); - - float getGain(); -/*! <<<... - * } - * ``` - * }}} */ - -/*** 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_gain_coeffs coeffs; -}; - -template -inline Gain::Gain() { - bw_gain_init(&coeffs); -} - -template -inline void Gain::setSampleRate(float sampleRate) { - bw_gain_set_sample_rate(&coeffs, sampleRate); -} - -template -inline void Gain::reset() { - bw_gain_reset_coeffs(&coeffs); -} - -template -inline void Gain::process( - std::array x, - std::array y, - int nSamples) { - bw_gain_process_multi(&coeffs, x.data(), y.data(), N_CHANNELS, nSamples); -} - -template -inline void Gain::setGainLin(float value) { - bw_gain_set_gain_lin(&coeffs, value); -} - -template -inline void Gain::setGainDB(float value) { - bw_gain_set_gain_dB(&coeffs, value); -} - -template -inline void Gain::setSmoothTau(float value) { - bw_gain_set_smooth_tau(&coeffs, value); -} - -template -inline float Gain::getGain() { - return bw_gain_get_gain(&coeffs); -} - -} - -#endif