polished bw_{env_follow,env_gen,fuzz,gain} + removed

bwpp_{env_follow,env_gen,fuzz,gain} + fix examples
This commit is contained in:
Stefano D'Angelo 2023-08-12 19:46:14 +02:00
parent f89188f790
commit 7e32e18d66
12 changed files with 517 additions and 533 deletions

View File

@ -23,7 +23,7 @@
#include "platform.h"
#include <bwpp_fuzz.h>
#include <bw_fuzz.h>
#include <bwpp_src_int.h>
using namespace Brickworks;

View File

@ -32,8 +32,8 @@
#include <bwpp_noise_gen.h>
#include <bwpp_pink_filt.h>
#include <bwpp_svf.h>
#include <bwpp_env_gen.h>
#include <bwpp_gain.h>
#include <bw_env_gen.h>
#include <bw_gain.h>
#include <bwpp_ppm.h>
using namespace Brickworks;

View File

@ -33,8 +33,8 @@
#include <bwpp_noise_gen.h>
#include <bwpp_pink_filt.h>
#include <bwpp_svf.h>
#include <bwpp_env_gen.h>
#include <bwpp_gain.h>
#include <bw_env_gen.h>
#include <bw_gain.h>
#include <bwpp_ppm.h>
using namespace Brickworks;

View File

@ -27,8 +27,8 @@
#include <bwpp_osc_pulse.h>
#include <bwpp_osc_filt.h>
#include <bwpp_svf.h>
#include <bwpp_env_gen.h>
#include <bwpp_gain.h>
#include <bw_env_gen.h>
#include <bw_gain.h>
#include <bwpp_ppm.h>
using namespace Brickworks;

View File

@ -30,8 +30,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_env_follow_process()</code> and
* <code>bw_env_follow_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -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 <bw_common.h>
@ -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 <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::EnvFollow
* ```>>> */
template<size_t N_CHANNELS>
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline EnvFollow<N_CHANNELS>::EnvFollow() {
bw_env_follow_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_env_follow_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::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<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_env_follow_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(x.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setAttackTau(float value) {
bw_env_follow_set_attack_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setReleaseTau(float value) {
bw_env_follow_set_release_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float EnvFollow<N_CHANNELS>::getYZ1(size_t channel) {
return bw_env_follow_get_y_z1(states + channel);
}
}
#endif

View File

@ -42,8 +42,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_env_gen_process()</code> and
* <code>bw_env_gen_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -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 <bw_common.h>
@ -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 <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::EnvGen
* ```>>> */
template<size_t N_CHANNELS>
class EnvGen {
public:
EnvGen();
void setSampleRate(float sampleRate);
void reset();
void process(
const char *gate,
float **y,
size_t nSamples);
void process(
std::array<char, N_CHANNELS> gate,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline EnvGen<N_CHANNELS>::EnvGen() {
bw_env_gen_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_env_gen_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::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<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::process(
const char *gate,
float **y,
size_t nSamples) {
bw_env_gen_process_multi(&coeffs, statesP, gate, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::process(
std::array<char, N_CHANNELS> gate,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(gate.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setAttack(float value) {
bw_env_gen_set_attack(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setDecay(float value) {
bw_env_gen_set_decay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setSustain(float value) {
bw_env_gen_set_sustain(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setRelease(float value) {
bw_env_gen_set_release(&coeffs, value);
}
template<size_t N_CHANNELS>
inline bw_env_gen_phase EnvGen<N_CHANNELS>::getPhase(size_t channel) {
return bw_env_gen_get_phase(states + channel);
}
template<size_t N_CHANNELS>
inline float EnvGen<N_CHANNELS>::getYZ1(size_t channel) {
return bw_env_gen_get_y_z1(states + channel);
}
}
#endif

View File

@ -34,8 +34,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_fuzz_process()</code> and
* <code>bw_fuzz_process_multi()</code> now use <code>size_t</code>
* to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -52,8 +59,8 @@
* }}}
*/
#ifndef _BW_FUZZ_H
#define _BW_FUZZ_H
#ifndef BW_FUZZ_H
#define BW_FUZZ_H
#include <bw_common.h>
@ -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 <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Fuzz
* ```>>> */
template<size_t N_CHANNELS>
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline Fuzz<N_CHANNELS>::Fuzz() {
bw_fuzz_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_fuzz_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::reset() {
bw_fuzz_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_fuzz_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_fuzz_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(x.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setFuzz(float value) {
bw_fuzz_set_fuzz(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setVolume(float value) {
bw_fuzz_set_volume(&coeffs, value);
}
}
#endif

View File

@ -29,8 +29,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_gain_process()</code> and
* <code>bw_gain_process_multi()</code> now use <code>size_t</code>
* to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -67,8 +74,8 @@
* }}}
*/
#ifndef _BW_GAIN_H
#define _BW_GAIN_H
#ifndef BW_GAIN_H
#define BW_GAIN_H
#include <bw_common.h>
@ -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 <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Gain
* ```>>> */
template<size_t N_CHANNELS>
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline Gain<N_CHANNELS>::Gain() {
bw_gain_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_gain_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::reset() {
bw_gain_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_gain_process_multi(&coeffs, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(x.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setGainLin(float value) {
bw_gain_set_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setGainDB(float value) {
bw_gain_set_gain_dB(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setSmoothTau(float value) {
bw_gain_set_smooth_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float Gain<N_CHANNELS>::getGain() {
return bw_gain_get_gain(&coeffs);
}
}
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_ENV_FOLLOW_H
#define BWPP_ENV_FOLLOW_H
#include <bw_env_follow.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::EnvFollow
* ```>>> */
template<size_t N_CHANNELS>
class EnvFollow {
public:
EnvFollow();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline EnvFollow<N_CHANNELS>::EnvFollow() {
bw_env_follow_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_env_follow_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::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<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_env_follow_process_multi(&coeffs, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setAttackTau(float value) {
bw_env_follow_set_attack_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvFollow<N_CHANNELS>::setReleaseTau(float value) {
bw_env_follow_set_release_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float EnvFollow<N_CHANNELS>::getYZ1(size_t channel) {
return bw_env_follow_get_y_z1(states + channel);
}
}
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_ENV_GEN_H
#define BWPP_ENV_GEN_H
#include <bw_env_gen.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::EnvGen
* ```>>> */
template<size_t N_CHANNELS>
class EnvGen {
public:
EnvGen();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<char, N_CHANNELS> gate,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline EnvGen<N_CHANNELS>::EnvGen() {
bw_env_gen_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_env_gen_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::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<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::process(
std::array<char, N_CHANNELS> gate,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_env_gen_process_multi(&coeffs, statesP, gate.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setAttack(float value) {
bw_env_gen_set_attack(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setDecay(float value) {
bw_env_gen_set_decay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setSustain(float value) {
bw_env_gen_set_sustain(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void EnvGen<N_CHANNELS>::setRelease(float value) {
bw_env_gen_set_release(&coeffs, value);
}
template<size_t N_CHANNELS>
inline bw_env_gen_phase EnvGen<N_CHANNELS>::getPhase(size_t channel) {
return bw_env_gen_get_phase(states + channel);
}
template<size_t N_CHANNELS>
inline float EnvGen<N_CHANNELS>::getYZ1(size_t channel) {
return bw_env_gen_get_y_z1(states + channel);
}
}
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_FUZZ_H
#define BWPP_FUZZ_H
#include <bw_fuzz.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Fuzz
* ```>>> */
template<size_t N_CHANNELS>
class Fuzz {
public:
Fuzz();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline Fuzz<N_CHANNELS>::Fuzz() {
bw_fuzz_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_fuzz_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::reset() {
bw_fuzz_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_fuzz_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_fuzz_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setFuzz(float value) {
bw_fuzz_set_fuzz(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Fuzz<N_CHANNELS>::setVolume(float value) {
bw_fuzz_set_volume(&coeffs, value);
}
}
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_GAIN_H
#define BWPP_GAIN_H
#include <bw_gain.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Gain
* ```>>> */
template<size_t N_CHANNELS>
class Gain {
public:
Gain();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> 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<size_t N_CHANNELS>
inline Gain<N_CHANNELS>::Gain() {
bw_gain_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_gain_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::reset() {
bw_gain_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_gain_process_multi(&coeffs, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setGainLin(float value) {
bw_gain_set_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setGainDB(float value) {
bw_gain_set_gain_dB(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Gain<N_CHANNELS>::setSmoothTau(float value) {
bw_gain_set_smooth_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float Gain<N_CHANNELS>::getGain() {
return bw_gain_get_gain(&coeffs);
}
}
#endif