polished bw_{hp1,hs1,hs2,lp1,ls2,ls2} + removed corresponding bwpp_ +

fixed examples + fixed doc in bw_clip
This commit is contained in:
Stefano D'Angelo 2023-08-13 04:18:10 +02:00
parent 7e32e18d66
commit 22030272d9
18 changed files with 772 additions and 796 deletions

View File

@ -23,8 +23,8 @@
#include "platform.h" #include "platform.h"
#include <bwpp_ls2.h> #include <bw_ls2.h>
#include <bwpp_hs2.h> #include <bw_hs2.h>
#include <bwpp_peak.h> #include <bwpp_peak.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -23,7 +23,7 @@
#include "platform.h" #include "platform.h"
#include <bwpp_hp1.h> #include <bw_hp1.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -23,7 +23,7 @@
#include "platform.h" #include "platform.h"
#include <bwpp_hs1.h> #include <bw_hs1.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -23,7 +23,7 @@
#include "platform.h" #include "platform.h"
#include <bwpp_lp1.h> #include <bw_lp1.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -23,7 +23,7 @@
#include "platform.h" #include "platform.h"
#include <bwpp_ls1.h> #include <bw_ls1.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -40,9 +40,9 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li><code>bw_chorus_process()</code> and * <li><code>bw_clip_process()</code> and
* <code>bw_chorus_process_multi()</code> now use * <code>bw_clip_process_multi()</code> now use <code>size_t</code>
* <code>size_t</code> to count samples and channels.</li> * to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input * <li>Added more <code>const</code> specifiers to input
* arguments.</li> * arguments.</li>
* <li>Moved C++ code to C header.</li> * <li>Moved C++ code to C header.</li>

View File

@ -30,8 +30,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_hp1_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_hp1_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -60,8 +67,8 @@
* }}} * }}}
*/ */
#ifndef _BW_HP1_H #ifndef BW_HP1_H
#define _BW_HP1_H #define BW_HP1_H
#include <bw_common.h> #include <bw_common.h>
@ -72,13 +79,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_hp1_coeffs * #### bw_hp1_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_hp1_coeffs bw_hp1_coeffs; typedef struct bw_hp1_coeffs bw_hp1_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_hp1_state * #### bw_hp1_state
* ```>>> */ * ```>>> */
typedef struct _bw_hp1_state bw_hp1_state; typedef struct bw_hp1_state bw_hp1_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -102,10 +109,10 @@ static inline void bw_hp1_reset_coeffs(bw_hp1_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_hp1_reset_state() * #### bw_hp1_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x0); static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_hp1_update_coeffs_ctrl() * #### bw_hp1_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -128,7 +135,7 @@ static inline float bw_hp1_process1(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_hp1_process() * #### bw_hp1_process()
* ```>>> */ * ```>>> */
static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -136,7 +143,7 @@ static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_stat
* *
* #### bw_hp1_process_multi() * #### bw_hp1_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -167,12 +174,12 @@ static inline void bw_hp1_set_cutoff(bw_hp1_coeffs *BW_RESTRICT coeffs, float va
extern "C" { extern "C" {
#endif #endif
struct _bw_hp1_coeffs { struct bw_hp1_coeffs {
// Sub-components // Sub-components
bw_lp1_coeffs lp1_coeffs; bw_lp1_coeffs lp1_coeffs;
}; };
struct _bw_hp1_state { struct bw_hp1_state {
bw_lp1_state lp1_state; bw_lp1_state lp1_state;
}; };
@ -188,8 +195,8 @@ static inline void bw_hp1_reset_coeffs(bw_hp1_coeffs *BW_RESTRICT coeffs) {
bw_lp1_reset_coeffs(&coeffs->lp1_coeffs); bw_lp1_reset_coeffs(&coeffs->lp1_coeffs);
} }
static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x0) { static inline void bw_hp1_reset_state(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, float x_0) {
bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x0); bw_lp1_reset_state(&coeffs->lp1_coeffs, &state->lp1_state, x_0);
} }
static inline void bw_hp1_update_coeffs_ctrl(bw_hp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hp1_update_coeffs_ctrl(bw_hp1_coeffs *BW_RESTRICT coeffs) {
@ -205,19 +212,19 @@ static inline float bw_hp1_process1(const bw_hp1_coeffs *BW_RESTRICT coeffs, bw_
return x - lp; return x - lp;
} }
static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_hp1_process(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_hp1_update_coeffs_ctrl(coeffs); bw_hp1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hp1_update_coeffs_audio(coeffs); bw_hp1_update_coeffs_audio(coeffs);
y[i] = bw_hp1_process1(coeffs, state, x[i]); y[i] = bw_hp1_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_hp1_process_multi(bw_hp1_coeffs *BW_RESTRICT coeffs, bw_hp1_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_hp1_update_coeffs_ctrl(coeffs); bw_hp1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hp1_update_coeffs_audio(coeffs); bw_hp1_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_hp1_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_hp1_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -227,6 +234,90 @@ static inline void bw_hp1_set_cutoff(bw_hp1_coeffs *BW_RESTRICT coeffs, float va
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::HP1
* ```>>> */
template<size_t N_CHANNELS>
class HP1 {
public:
HP1();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(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_hp1_coeffs coeffs;
bw_hp1_state states[N_CHANNELS];
bw_hp1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HP1<N_CHANNELS>::HP1() {
bw_hp1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hp1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::reset(float x_0) {
bw_hp1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hp1_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_hp1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HP1<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 HP1<N_CHANNELS>::setCutoff(float value) {
bw_hp1_set_cutoff(&coeffs, value);
}
} }
#endif #endif

View File

@ -29,8 +29,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_hs1_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_hs1_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -59,8 +66,8 @@
* }}} * }}}
*/ */
#ifndef _BW_HS1_H #ifndef BW_HS1_H
#define _BW_HS1_H #define BW_HS1_H
#include <bw_common.h> #include <bw_common.h>
@ -71,13 +78,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_hs1_coeffs * #### bw_hs1_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_hs1_coeffs bw_hs1_coeffs; typedef struct bw_hs1_coeffs bw_hs1_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_hs1_state * #### bw_hs1_state
* ```>>> */ * ```>>> */
typedef struct _bw_hs1_state bw_hs1_state; typedef struct bw_hs1_state bw_hs1_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -101,10 +108,10 @@ static inline void bw_hs1_reset_coeffs(bw_hs1_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_hs1_reset_state() * #### bw_hs1_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_hs1_reset_state(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, float x0); static inline void bw_hs1_reset_state(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_hs1_update_coeffs_ctrl() * #### bw_hs1_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -127,7 +134,7 @@ static inline float bw_hs1_process1(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_hs1_process() * #### bw_hs1_process()
* ```>>> */ * ```>>> */
static inline void bw_hs1_process(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_hs1_process(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -135,7 +142,7 @@ static inline void bw_hs1_process(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_stat
* *
* #### bw_hs1_process_multi() * #### bw_hs1_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_hs1_process_multi(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_hs1_process_multi(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -186,7 +193,7 @@ static inline void bw_hs1_set_high_gain_dB(bw_hs1_coeffs *BW_RESTRICT coeffs, fl
extern "C" { extern "C" {
#endif #endif
struct _bw_hs1_coeffs { struct bw_hs1_coeffs {
// Sub-components // Sub-components
bw_mm1_coeffs mm1_coeffs; bw_mm1_coeffs mm1_coeffs;
@ -196,7 +203,7 @@ struct _bw_hs1_coeffs {
char update; char update;
}; };
struct _bw_hs1_state { struct bw_hs1_state {
bw_mm1_state mm1_state; bw_mm1_state mm1_state;
}; };
@ -213,7 +220,7 @@ static inline void bw_hs1_set_sample_rate(bw_hs1_coeffs *BW_RESTRICT coeffs, flo
bw_mm1_set_sample_rate(&coeffs->mm1_coeffs, sample_rate); bw_mm1_set_sample_rate(&coeffs->mm1_coeffs, sample_rate);
} }
static inline void _bw_hs1_update_mm1_params(bw_hs1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs1_update_mm1_params(bw_hs1_coeffs *BW_RESTRICT coeffs) {
if (coeffs->update) { if (coeffs->update) {
bw_mm1_set_cutoff(&coeffs->mm1_coeffs, coeffs->cutoff * bw_sqrtf(coeffs->high_gain)); bw_mm1_set_cutoff(&coeffs->mm1_coeffs, coeffs->cutoff * bw_sqrtf(coeffs->high_gain));
bw_mm1_set_coeff_x(&coeffs->mm1_coeffs, coeffs->high_gain); bw_mm1_set_coeff_x(&coeffs->mm1_coeffs, coeffs->high_gain);
@ -225,16 +232,16 @@ static inline void _bw_hs1_update_mm1_params(bw_hs1_coeffs *BW_RESTRICT coeffs)
static inline void bw_hs1_reset_coeffs(bw_hs1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs1_reset_coeffs(bw_hs1_coeffs *BW_RESTRICT coeffs) {
coeffs->update = 1; coeffs->update = 1;
_bw_hs1_update_mm1_params(coeffs); bw_hs1_update_mm1_params(coeffs);
bw_mm1_reset_coeffs(&coeffs->mm1_coeffs); bw_mm1_reset_coeffs(&coeffs->mm1_coeffs);
} }
static inline void bw_hs1_reset_state(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, float x0) { static inline void bw_hs1_reset_state(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, float x_0) {
bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x0); bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
} }
static inline void bw_hs1_update_coeffs_ctrl(bw_hs1_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs1_update_coeffs_ctrl(bw_hs1_coeffs *BW_RESTRICT coeffs) {
_bw_hs1_update_mm1_params(coeffs); bw_hs1_update_mm1_params(coeffs);
bw_mm1_update_coeffs_ctrl(&coeffs->mm1_coeffs); bw_mm1_update_coeffs_ctrl(&coeffs->mm1_coeffs);
} }
@ -246,19 +253,19 @@ static inline float bw_hs1_process1(const bw_hs1_coeffs *BW_RESTRICT coeffs, bw_
return bw_mm1_process1(&coeffs->mm1_coeffs, &state->mm1_state, x); return bw_mm1_process1(&coeffs->mm1_coeffs, &state->mm1_state, x);
} }
static inline void bw_hs1_process(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_hs1_process(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_hs1_update_coeffs_ctrl(coeffs); bw_hs1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hs1_update_coeffs_audio(coeffs); bw_hs1_update_coeffs_audio(coeffs);
y[i] = bw_hs1_process1(coeffs, state, x[i]); y[i] = bw_hs1_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_hs1_process_multi(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_hs1_process_multi(bw_hs1_coeffs *BW_RESTRICT coeffs, bw_hs1_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_hs1_update_coeffs_ctrl(coeffs); bw_hs1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hs1_update_coeffs_audio(coeffs); bw_hs1_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_hs1_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_hs1_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -282,6 +289,102 @@ static inline void bw_hs1_set_high_gain_dB(bw_hs1_coeffs *BW_RESTRICT coeffs, fl
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::HS1
* ```>>> */
template<size_t N_CHANNELS>
class HS1 {
public:
HS1();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setHighGainLin(float value);
void setHighGainDB(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_hs1_coeffs coeffs;
bw_hs1_state states[N_CHANNELS];
bw_hs1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HS1<N_CHANNELS>::HS1() {
bw_hs1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hs1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::reset(float x_0) {
bw_hs1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hs1_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_hs1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HS1<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 HS1<N_CHANNELS>::setCutoff(float value) {
bw_hs1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setHighGainLin(float value) {
bw_hs1_set_high_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setHighGainDB(float value) {
bw_hs1_set_high_gain_dB(&coeffs, value);
}
} }
#endif #endif

View File

@ -29,8 +29,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_hs2_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_hs2_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -59,8 +66,8 @@
* }}} * }}}
*/ */
#ifndef _BW_HS2_H #ifndef BW_HS2_H
#define _BW_HS2_H #define BW_HS2_H
#include <bw_common.h> #include <bw_common.h>
@ -71,13 +78,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_hs2_coeffs * #### bw_hs2_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_hs2_coeffs bw_hs2_coeffs; typedef struct bw_hs2_coeffs bw_hs2_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_hs2_state * #### bw_hs2_state
* ```>>> */ * ```>>> */
typedef struct _bw_hs2_state bw_hs2_state; typedef struct bw_hs2_state bw_hs2_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -101,10 +108,10 @@ static inline void bw_hs2_reset_coeffs(bw_hs2_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_hs2_reset_state() * #### bw_hs2_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x0); static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_hs2_update_coeffs_ctrl() * #### bw_hs2_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -127,7 +134,7 @@ static inline float bw_hs2_process1(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_hs2_process() * #### bw_hs2_process()
* ```>>> */ * ```>>> */
static inline void bw_hs2_process(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_hs2_process(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -135,7 +142,7 @@ static inline void bw_hs2_process(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_stat
* *
* #### bw_hs2_process_multi() * #### bw_hs2_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_hs2_process_multi(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_hs2_process_multi(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -195,7 +202,7 @@ static inline void bw_hs2_set_high_gain_dB(bw_hs2_coeffs *BW_RESTRICT coeffs, fl
extern "C" { extern "C" {
#endif #endif
struct _bw_hs2_coeffs { struct bw_hs2_coeffs {
// Sub-components // Sub-components
bw_mm2_coeffs mm2_coeffs; bw_mm2_coeffs mm2_coeffs;
@ -209,12 +216,12 @@ struct _bw_hs2_coeffs {
int param_changed; int param_changed;
}; };
struct _bw_hs2_state { struct bw_hs2_state {
bw_mm2_state mm2_state; bw_mm2_state mm2_state;
}; };
#define _BW_HS2_PARAM_HIGH_GAIN 1 #define BW_HS2_PARAM_HIGH_GAIN 1
#define _BW_HS2_PARAM_CUTOFF (1<<1) #define BW_HS2_PARAM_CUTOFF (1<<1)
static inline void bw_hs2_init(bw_hs2_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs2_init(bw_hs2_coeffs *BW_RESTRICT coeffs) {
bw_mm2_init(&coeffs->mm2_coeffs); bw_mm2_init(&coeffs->mm2_coeffs);
@ -227,16 +234,16 @@ static inline void bw_hs2_set_sample_rate(bw_hs2_coeffs *BW_RESTRICT coeffs, flo
bw_mm2_set_sample_rate(&coeffs->mm2_coeffs, sample_rate); bw_mm2_set_sample_rate(&coeffs->mm2_coeffs, sample_rate);
} }
static inline void _bw_hs2_update_mm2_params(bw_hs2_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs2_update_mm2_params(bw_hs2_coeffs *BW_RESTRICT coeffs) {
if (coeffs->param_changed) { if (coeffs->param_changed) {
if (coeffs->param_changed & _BW_HS2_PARAM_HIGH_GAIN) { if (coeffs->param_changed & BW_HS2_PARAM_HIGH_GAIN) {
coeffs->sg = bw_sqrtf(coeffs->high_gain); coeffs->sg = bw_sqrtf(coeffs->high_gain);
coeffs->ssg = bw_sqrtf(coeffs->sg); coeffs->ssg = bw_sqrtf(coeffs->sg);
bw_mm2_set_coeff_x(&coeffs->mm2_coeffs, coeffs->sg); bw_mm2_set_coeff_x(&coeffs->mm2_coeffs, coeffs->sg);
bw_mm2_set_coeff_lp(&coeffs->mm2_coeffs, 1.f - coeffs->sg); bw_mm2_set_coeff_lp(&coeffs->mm2_coeffs, 1.f - coeffs->sg);
bw_mm2_set_coeff_hp(&coeffs->mm2_coeffs, coeffs->high_gain - coeffs->sg); bw_mm2_set_coeff_hp(&coeffs->mm2_coeffs, coeffs->high_gain - coeffs->sg);
} }
if (coeffs->param_changed & _BW_HS2_PARAM_CUTOFF) if (coeffs->param_changed & BW_HS2_PARAM_CUTOFF)
bw_mm2_set_prewarp_freq(&coeffs->mm2_coeffs, coeffs->cutoff); bw_mm2_set_prewarp_freq(&coeffs->mm2_coeffs, coeffs->cutoff);
bw_mm2_set_cutoff(&coeffs->mm2_coeffs, coeffs->cutoff * coeffs->ssg); bw_mm2_set_cutoff(&coeffs->mm2_coeffs, coeffs->cutoff * coeffs->ssg);
coeffs->param_changed = 0; coeffs->param_changed = 0;
@ -245,16 +252,16 @@ static inline void _bw_hs2_update_mm2_params(bw_hs2_coeffs *BW_RESTRICT coeffs)
static inline void bw_hs2_reset_coeffs(bw_hs2_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs2_reset_coeffs(bw_hs2_coeffs *BW_RESTRICT coeffs) {
coeffs->param_changed = ~0; coeffs->param_changed = ~0;
_bw_hs2_update_mm2_params(coeffs); bw_hs2_update_mm2_params(coeffs);
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs); bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
} }
static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x0) { static inline void bw_hs2_reset_state(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, float x_0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0); bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x_0);
} }
static inline void bw_hs2_update_coeffs_ctrl(bw_hs2_coeffs *BW_RESTRICT coeffs) { static inline void bw_hs2_update_coeffs_ctrl(bw_hs2_coeffs *BW_RESTRICT coeffs) {
_bw_hs2_update_mm2_params(coeffs); bw_hs2_update_mm2_params(coeffs);
bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs); bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs);
} }
@ -266,19 +273,19 @@ static inline float bw_hs2_process1(const bw_hs2_coeffs *BW_RESTRICT coeffs, bw_
return bw_mm2_process1(&coeffs->mm2_coeffs, &state->mm2_state, x); return bw_mm2_process1(&coeffs->mm2_coeffs, &state->mm2_state, x);
} }
static inline void bw_hs2_process(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_hs2_process(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_hs2_update_coeffs_ctrl(coeffs); bw_hs2_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hs2_update_coeffs_audio(coeffs); bw_hs2_update_coeffs_audio(coeffs);
y[i] = bw_hs2_process1(coeffs, state, x[i]); y[i] = bw_hs2_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_hs2_process_multi(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_hs2_process_multi(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs2_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_hs2_update_coeffs_ctrl(coeffs); bw_hs2_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_hs2_update_coeffs_audio(coeffs); bw_hs2_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_hs2_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_hs2_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -286,7 +293,7 @@ static inline void bw_hs2_process_multi(bw_hs2_coeffs *BW_RESTRICT coeffs, bw_hs
static inline void bw_hs2_set_cutoff(bw_hs2_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_hs2_set_cutoff(bw_hs2_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->cutoff) { if (coeffs->cutoff) {
coeffs->cutoff = value; coeffs->cutoff = value;
coeffs->param_changed |= _BW_HS2_PARAM_CUTOFF; coeffs->param_changed |= BW_HS2_PARAM_CUTOFF;
} }
} }
@ -297,7 +304,7 @@ static inline void bw_hs2_set_Q(bw_hs2_coeffs *BW_RESTRICT coeffs, float value)
static inline void bw_hs2_set_high_gain_lin(bw_hs2_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_hs2_set_high_gain_lin(bw_hs2_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->high_gain != value) { if (coeffs->high_gain != value) {
coeffs->high_gain = value; coeffs->high_gain = value;
coeffs->param_changed |= _BW_HS2_PARAM_HIGH_GAIN; coeffs->param_changed |= BW_HS2_PARAM_HIGH_GAIN;
} }
} }
@ -305,10 +312,112 @@ static inline void bw_hs2_set_high_gain_dB(bw_hs2_coeffs *BW_RESTRICT coeffs, fl
bw_hs2_set_high_gain_lin(coeffs, bw_dB2linf(value)); bw_hs2_set_high_gain_lin(coeffs, bw_dB2linf(value));
} }
#undef _BW_HS2_PARAM_HIGH_GAIN #undef BW_HS2_PARAM_HIGH_GAIN
#undef _BW_HS2_PARAM_CUTOFF #undef BW_HS2_PARAM_CUTOFF
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::HS2
* ```>>> */
template<size_t N_CHANNELS>
class HS2 {
public:
HS2();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setQ(float value);
void setHighGainLin(float value);
void setHighGainDB(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_hs2_coeffs coeffs;
bw_hs2_state states[N_CHANNELS];
bw_hs2_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HS2<N_CHANNELS>::HS2() {
bw_hs2_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hs2_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::reset(float x_0) {
bw_hs2_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hs2_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_hs2_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HS2<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 HS2<N_CHANNELS>::setCutoff(float value) {
bw_hs2_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setQ(float value) {
bw_hs2_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setHighGainLin(float value) {
bw_hs2_set_high_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setHighGainDB(float value) {
bw_hs2_set_high_gain_dB(&coeffs, value);
}
} }
#endif #endif

View File

@ -32,8 +32,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_lp1_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_lp1_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -63,8 +70,8 @@
* }}} * }}}
*/ */
#ifndef _BW_LP1_H #ifndef BW_LP1_H
#define _BW_LP1_H #define BW_LP1_H
#include <bw_common.h> #include <bw_common.h>
@ -75,13 +82,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_lp1_coeffs * #### bw_lp1_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_lp1_coeffs bw_lp1_coeffs; typedef struct bw_lp1_coeffs bw_lp1_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_lp1_state * #### bw_lp1_state
* ```>>> */ * ```>>> */
typedef struct _bw_lp1_state bw_lp1_state; typedef struct bw_lp1_state bw_lp1_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -105,10 +112,10 @@ static inline void bw_lp1_reset_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_lp1_reset_state() * #### bw_lp1_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_lp1_reset_state(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x0); static inline void bw_lp1_reset_state(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_lp1_update_coeffs_ctrl() * #### bw_lp1_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -131,7 +138,7 @@ static inline float bw_lp1_process1(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_lp1_process() * #### bw_lp1_process()
* ```>>> */ * ```>>> */
static inline void bw_lp1_process(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_lp1_process(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -139,7 +146,7 @@ static inline void bw_lp1_process(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_stat
* *
* #### bw_lp1_process_multi() * #### bw_lp1_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_lp1_process_multi(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_lp1_process_multi(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -190,7 +197,7 @@ static inline void bw_lp1_set_prewarp_freq(bw_lp1_coeffs *BW_RESTRICT coeffs, fl
extern "C" { extern "C" {
#endif #endif
struct _bw_lp1_coeffs { struct bw_lp1_coeffs {
// Sub-components // Sub-components
bw_one_pole_coeffs smooth_coeffs; bw_one_pole_coeffs smooth_coeffs;
bw_one_pole_state smooth_cutoff_state; bw_one_pole_state smooth_cutoff_state;
@ -210,7 +217,7 @@ struct _bw_lp1_coeffs {
float prewarp_freq; float prewarp_freq;
}; };
struct _bw_lp1_state { struct bw_lp1_state {
float y_z1; float y_z1;
float X_z1; float X_z1;
}; };
@ -230,7 +237,7 @@ static inline void bw_lp1_set_sample_rate(bw_lp1_coeffs *BW_RESTRICT coeffs, flo
coeffs->t_k = 3.141592653589793f / sample_rate; coeffs->t_k = 3.141592653589793f / sample_rate;
} }
static inline void _bw_lp1_do_update_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs, char force) { static inline void bw_lp1_do_update_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs, char force) {
const float prewarp_freq = coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq); const float prewarp_freq = coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq);
float prewarp_freq_cur = bw_one_pole_get_y_z1(&coeffs->smooth_prewarp_freq_state); float prewarp_freq_cur = bw_one_pole_get_y_z1(&coeffs->smooth_prewarp_freq_state);
float cutoff_cur = bw_one_pole_get_y_z1(&coeffs->smooth_cutoff_state); float cutoff_cur = bw_one_pole_get_y_z1(&coeffs->smooth_cutoff_state);
@ -254,12 +261,12 @@ static inline void _bw_lp1_do_update_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs, c
static inline void bw_lp1_reset_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_lp1_reset_coeffs(bw_lp1_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_cutoff_state, coeffs->cutoff); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_cutoff_state, coeffs->cutoff);
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_prewarp_freq_state, coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq)); bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_prewarp_freq_state, coeffs->prewarp_freq + coeffs->prewarp_k * (coeffs->cutoff - coeffs->prewarp_freq));
_bw_lp1_do_update_coeffs(coeffs, 1); bw_lp1_do_update_coeffs(coeffs, 1);
} }
static inline void bw_lp1_reset_state(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x0) { static inline void bw_lp1_reset_state(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x_0) {
(void)coeffs; (void)coeffs;
state->y_z1 = x0; state->y_z1 = x_0;
state->X_z1 = 0.f; state->X_z1 = 0.f;
} }
@ -268,7 +275,7 @@ static inline void bw_lp1_update_coeffs_ctrl(bw_lp1_coeffs *BW_RESTRICT coeffs)
} }
static inline void bw_lp1_update_coeffs_audio(bw_lp1_coeffs *BW_RESTRICT coeffs) { static inline void bw_lp1_update_coeffs_audio(bw_lp1_coeffs *BW_RESTRICT coeffs) {
_bw_lp1_do_update_coeffs(coeffs, 0); bw_lp1_do_update_coeffs(coeffs, 0);
} }
static inline float bw_lp1_process1(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x) { static inline float bw_lp1_process1(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, float x) {
@ -279,17 +286,17 @@ static inline float bw_lp1_process1(const bw_lp1_coeffs *BW_RESTRICT coeffs, bw_
return y; return y;
} }
static inline void bw_lp1_process(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_lp1_process(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_lp1_update_coeffs_audio(coeffs); bw_lp1_update_coeffs_audio(coeffs);
y[i] = bw_lp1_process1(coeffs, state, x[i]); y[i] = bw_lp1_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_lp1_process_multi(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_lp1_process_multi(bw_lp1_coeffs *BW_RESTRICT coeffs, bw_lp1_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_lp1_update_coeffs_audio(coeffs); bw_lp1_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_lp1_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_lp1_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -307,6 +314,102 @@ static inline void bw_lp1_set_prewarp_freq(bw_lp1_coeffs *BW_RESTRICT coeffs, fl
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::LP1
* ```>>> */
template<size_t N_CHANNELS>
class LP1 {
public:
LP1();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setPrewarpAtCutoff(bool value);
void setPrewarpFreq(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_lp1_coeffs coeffs;
bw_lp1_state states[N_CHANNELS];
bw_lp1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LP1<N_CHANNELS>::LP1() {
bw_lp1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_lp1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::reset(float x_0) {
bw_lp1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_lp1_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_lp1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LP1<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 LP1<N_CHANNELS>::setCutoff(float value) {
bw_lp1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setPrewarpAtCutoff(bool value) {
bw_lp1_set_prewarp_at_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setPrewarpFreq(float value) {
bw_lp1_set_prewarp_freq(&coeffs, value);
}
} }
#endif #endif

View File

@ -30,8 +30,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_ls1_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_ls1_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -60,8 +67,8 @@
* }}} * }}}
*/ */
#ifndef _BW_LS1_H #ifndef BW_LS1_H
#define _BW_LS1_H #define BW_LS1_H
#include <bw_common.h> #include <bw_common.h>
@ -72,13 +79,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_ls1_coeffs * #### bw_ls1_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_ls1_coeffs bw_ls1_coeffs; typedef struct bw_ls1_coeffs bw_ls1_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_ls1_state * #### bw_ls1_state
* ```>>> */ * ```>>> */
typedef struct _bw_ls1_state bw_ls1_state; typedef struct bw_ls1_state bw_ls1_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -102,10 +109,10 @@ static inline void bw_ls1_reset_coeffs(bw_ls1_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_ls1_reset_state() * #### bw_ls1_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_ls1_reset_state(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, float x0); static inline void bw_ls1_reset_state(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_ls1_update_coeffs_ctrl() * #### bw_ls1_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -128,7 +135,7 @@ static inline float bw_ls1_process1(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_ls1_process() * #### bw_ls1_process()
* ```>>> */ * ```>>> */
static inline void bw_ls1_process(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_ls1_process(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -136,7 +143,7 @@ static inline void bw_ls1_process(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_stat
* *
* #### bw_ls1_process_multi() * #### bw_ls1_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_ls1_process_multi(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_ls1_process_multi(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -184,7 +191,7 @@ static inline void bw_ls1_set_dc_gain_dB(bw_ls1_coeffs *BW_RESTRICT coeffs, floa
extern "C" { extern "C" {
#endif #endif
struct _bw_ls1_coeffs { struct bw_ls1_coeffs {
// Sub-components // Sub-components
bw_mm1_coeffs mm1_coeffs; bw_mm1_coeffs mm1_coeffs;
@ -194,7 +201,7 @@ struct _bw_ls1_coeffs {
char update; char update;
}; };
struct _bw_ls1_state { struct bw_ls1_state {
bw_mm1_state mm1_state; bw_mm1_state mm1_state;
}; };
@ -211,7 +218,7 @@ static inline void bw_ls1_set_sample_rate(bw_ls1_coeffs *BW_RESTRICT coeffs, flo
bw_mm1_set_sample_rate(&coeffs->mm1_coeffs, sample_rate); bw_mm1_set_sample_rate(&coeffs->mm1_coeffs, sample_rate);
} }
static inline void _bw_ls1_update_mm1_params(bw_ls1_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls1_update_mm1_params(bw_ls1_coeffs *BW_RESTRICT coeffs) {
if (coeffs->update) { if (coeffs->update) {
bw_mm1_set_cutoff(&coeffs->mm1_coeffs, coeffs->cutoff * bw_rcpf(bw_sqrtf(coeffs->dc_gain))); bw_mm1_set_cutoff(&coeffs->mm1_coeffs, coeffs->cutoff * bw_rcpf(bw_sqrtf(coeffs->dc_gain)));
bw_mm1_set_coeff_lp(&coeffs->mm1_coeffs, coeffs->dc_gain - 1.f); bw_mm1_set_coeff_lp(&coeffs->mm1_coeffs, coeffs->dc_gain - 1.f);
@ -222,16 +229,16 @@ static inline void _bw_ls1_update_mm1_params(bw_ls1_coeffs *BW_RESTRICT coeffs)
static inline void bw_ls1_reset_coeffs(bw_ls1_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls1_reset_coeffs(bw_ls1_coeffs *BW_RESTRICT coeffs) {
coeffs->update = 1; coeffs->update = 1;
_bw_ls1_update_mm1_params(coeffs); bw_ls1_update_mm1_params(coeffs);
bw_mm1_reset_coeffs(&coeffs->mm1_coeffs); bw_mm1_reset_coeffs(&coeffs->mm1_coeffs);
} }
static inline void bw_ls1_reset_state(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, float x0) { static inline void bw_ls1_reset_state(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, float x_0) {
bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x0); bw_mm1_reset_state(&coeffs->mm1_coeffs, &state->mm1_state, x_0);
} }
static inline void bw_ls1_update_coeffs_ctrl(bw_ls1_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls1_update_coeffs_ctrl(bw_ls1_coeffs *BW_RESTRICT coeffs) {
_bw_ls1_update_mm1_params(coeffs); bw_ls1_update_mm1_params(coeffs);
bw_mm1_update_coeffs_ctrl(&coeffs->mm1_coeffs); bw_mm1_update_coeffs_ctrl(&coeffs->mm1_coeffs);
} }
@ -243,19 +250,19 @@ static inline float bw_ls1_process1(const bw_ls1_coeffs *BW_RESTRICT coeffs, bw_
return bw_mm1_process1(&coeffs->mm1_coeffs, &state->mm1_state, x); return bw_mm1_process1(&coeffs->mm1_coeffs, &state->mm1_state, x);
} }
static inline void bw_ls1_process(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_ls1_process(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_ls1_update_coeffs_ctrl(coeffs); bw_ls1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ls1_update_coeffs_audio(coeffs); bw_ls1_update_coeffs_audio(coeffs);
y[i] = bw_ls1_process1(coeffs, state, x[i]); y[i] = bw_ls1_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_ls1_process_multi(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_ls1_process_multi(bw_ls1_coeffs *BW_RESTRICT coeffs, bw_ls1_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_ls1_update_coeffs_ctrl(coeffs); bw_ls1_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ls1_update_coeffs_audio(coeffs); bw_ls1_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_ls1_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_ls1_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -279,6 +286,102 @@ static inline void bw_ls1_set_dc_gain_dB(bw_ls1_coeffs *BW_RESTRICT coeffs, floa
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::LS1
* ```>>> */
template<size_t N_CHANNELS>
class LS1 {
public:
LS1();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setDcGainLin(float value);
void setDcGainDB(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_ls1_coeffs coeffs;
bw_ls1_state states[N_CHANNELS];
bw_ls1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LS1<N_CHANNELS>::LS1() {
bw_ls1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ls1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::reset(float x_0) {
bw_ls1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ls1_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_ls1_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LS1<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 LS1<N_CHANNELS>::setCutoff(float value) {
bw_ls1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setDcGainLin(float value) {
bw_ls1_set_dc_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setDcGainDB(float value) {
bw_ls1_set_dc_gain_dB(&coeffs, value);
}
} }
#endif #endif

View File

@ -30,8 +30,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_ls2_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_ls2_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> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -60,8 +67,8 @@
* }}} * }}}
*/ */
#ifndef _BW_LS2_H #ifndef BW_LS2_H
#define _BW_LS2_H #define BW_LS2_H
#include <bw_common.h> #include <bw_common.h>
@ -72,13 +79,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_ls2_coeffs * #### bw_ls2_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_ls2_coeffs bw_ls2_coeffs; typedef struct bw_ls2_coeffs bw_ls2_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_ls2_state * #### bw_ls2_state
* ```>>> */ * ```>>> */
typedef struct _bw_ls2_state bw_ls2_state; typedef struct bw_ls2_state bw_ls2_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -102,10 +109,10 @@ static inline void bw_ls2_reset_coeffs(bw_ls2_coeffs *BW_RESTRICT coeffs);
* *
* #### bw_ls2_reset_state() * #### bw_ls2_reset_state()
* ```>>> */ * ```>>> */
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x0); static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x_0);
/*! <<<``` /*! <<<```
* Resets the given `state` to its initial values using the given `coeffs` * 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_ls2_update_coeffs_ctrl() * #### bw_ls2_update_coeffs_ctrl()
* ```>>> */ * ```>>> */
@ -128,7 +135,7 @@ static inline float bw_ls2_process1(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_ls2_process() * #### bw_ls2_process()
* ```>>> */ * ```>>> */
static inline void bw_ls2_process(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_ls2_process(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_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 * 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 * first `n_samples` of the output buffer `y`, while using and updating both
@ -136,7 +143,7 @@ static inline void bw_ls2_process(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_stat
* *
* #### bw_ls2_process_multi() * #### bw_ls2_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_ls2_process_multi(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_ls2_process_multi(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_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 * 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 * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -194,7 +201,7 @@ static inline void bw_ls2_set_dc_gain_dB(bw_ls2_coeffs *BW_RESTRICT coeffs, floa
extern "C" { extern "C" {
#endif #endif
struct _bw_ls2_coeffs { struct bw_ls2_coeffs {
// Sub-components // Sub-components
bw_mm2_coeffs mm2_coeffs; bw_mm2_coeffs mm2_coeffs;
@ -208,12 +215,12 @@ struct _bw_ls2_coeffs {
int param_changed; int param_changed;
}; };
struct _bw_ls2_state { struct bw_ls2_state {
bw_mm2_state mm2_state; bw_mm2_state mm2_state;
}; };
#define _BW_LS2_PARAM_DC_GAIN 1 #define BW_LS2_PARAM_DC_GAIN 1
#define _BW_LS2_PARAM_CUTOFF (1<<1) #define BW_LS2_PARAM_CUTOFF (1<<1)
static inline void bw_ls2_init(bw_ls2_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls2_init(bw_ls2_coeffs *BW_RESTRICT coeffs) {
bw_mm2_init(&coeffs->mm2_coeffs); bw_mm2_init(&coeffs->mm2_coeffs);
@ -226,16 +233,16 @@ static inline void bw_ls2_set_sample_rate(bw_ls2_coeffs *BW_RESTRICT coeffs, flo
bw_mm2_set_sample_rate(&coeffs->mm2_coeffs, sample_rate); bw_mm2_set_sample_rate(&coeffs->mm2_coeffs, sample_rate);
} }
static inline void _bw_ls2_update_mm2_params(bw_ls2_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls2_update_mm2_params(bw_ls2_coeffs *BW_RESTRICT coeffs) {
if (coeffs->param_changed) { if (coeffs->param_changed) {
if (coeffs->param_changed & _BW_LS2_PARAM_DC_GAIN) { if (coeffs->param_changed & BW_LS2_PARAM_DC_GAIN) {
coeffs->sg = bw_sqrtf(coeffs->dc_gain); coeffs->sg = bw_sqrtf(coeffs->dc_gain);
coeffs->issg = bw_sqrtf(bw_rcpf(coeffs->sg)); coeffs->issg = bw_sqrtf(bw_rcpf(coeffs->sg));
bw_mm2_set_coeff_x(&coeffs->mm2_coeffs, coeffs->sg); bw_mm2_set_coeff_x(&coeffs->mm2_coeffs, coeffs->sg);
bw_mm2_set_coeff_lp(&coeffs->mm2_coeffs, coeffs->dc_gain - coeffs->sg); bw_mm2_set_coeff_lp(&coeffs->mm2_coeffs, coeffs->dc_gain - coeffs->sg);
bw_mm2_set_coeff_hp(&coeffs->mm2_coeffs, 1.f - coeffs->sg); bw_mm2_set_coeff_hp(&coeffs->mm2_coeffs, 1.f - coeffs->sg);
} }
if (coeffs->param_changed & _BW_LS2_PARAM_CUTOFF) if (coeffs->param_changed & BW_LS2_PARAM_CUTOFF)
bw_mm2_set_prewarp_freq(&coeffs->mm2_coeffs, coeffs->cutoff); bw_mm2_set_prewarp_freq(&coeffs->mm2_coeffs, coeffs->cutoff);
bw_mm2_set_cutoff(&coeffs->mm2_coeffs, coeffs->cutoff * coeffs->issg); bw_mm2_set_cutoff(&coeffs->mm2_coeffs, coeffs->cutoff * coeffs->issg);
coeffs->param_changed = 0; coeffs->param_changed = 0;
@ -244,16 +251,16 @@ static inline void _bw_ls2_update_mm2_params(bw_ls2_coeffs *BW_RESTRICT coeffs)
static inline void bw_ls2_reset_coeffs(bw_ls2_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls2_reset_coeffs(bw_ls2_coeffs *BW_RESTRICT coeffs) {
coeffs->param_changed = ~0; coeffs->param_changed = ~0;
_bw_ls2_update_mm2_params(coeffs); bw_ls2_update_mm2_params(coeffs);
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs); bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
} }
static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x0) { static inline void bw_ls2_reset_state(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, float x_0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0); bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x_0);
} }
static inline void bw_ls2_update_coeffs_ctrl(bw_ls2_coeffs *BW_RESTRICT coeffs) { static inline void bw_ls2_update_coeffs_ctrl(bw_ls2_coeffs *BW_RESTRICT coeffs) {
_bw_ls2_update_mm2_params(coeffs); bw_ls2_update_mm2_params(coeffs);
bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs); bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs);
} }
@ -265,19 +272,19 @@ static inline float bw_ls2_process1(const bw_ls2_coeffs *BW_RESTRICT coeffs, bw_
return bw_mm2_process1(&coeffs->mm2_coeffs, &state->mm2_state, x); return bw_mm2_process1(&coeffs->mm2_coeffs, &state->mm2_state, x);
} }
static inline void bw_ls2_process(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_ls2_process(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_ls2_update_coeffs_ctrl(coeffs); bw_ls2_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ls2_update_coeffs_audio(coeffs); bw_ls2_update_coeffs_audio(coeffs);
y[i] = bw_ls2_process1(coeffs, state, x[i]); y[i] = bw_ls2_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_ls2_process_multi(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_ls2_process_multi(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls2_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_ls2_update_coeffs_ctrl(coeffs); bw_ls2_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ls2_update_coeffs_audio(coeffs); bw_ls2_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_ls2_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_ls2_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -285,7 +292,7 @@ static inline void bw_ls2_process_multi(bw_ls2_coeffs *BW_RESTRICT coeffs, bw_ls
static inline void bw_ls2_set_cutoff(bw_ls2_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_ls2_set_cutoff(bw_ls2_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->cutoff != value) { if (coeffs->cutoff != value) {
coeffs->cutoff = value; coeffs->cutoff = value;
coeffs->param_changed |= _BW_LS2_PARAM_CUTOFF; coeffs->param_changed |= BW_LS2_PARAM_CUTOFF;
} }
} }
@ -296,7 +303,7 @@ static inline void bw_ls2_set_Q(bw_ls2_coeffs *BW_RESTRICT coeffs, float value)
static inline void bw_ls2_set_dc_gain_lin(bw_ls2_coeffs *BW_RESTRICT coeffs, float value) { static inline void bw_ls2_set_dc_gain_lin(bw_ls2_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->dc_gain != value) { if (coeffs->dc_gain != value) {
coeffs->dc_gain = value; coeffs->dc_gain = value;
coeffs->param_changed |= _BW_LS2_PARAM_DC_GAIN; coeffs->param_changed |= BW_LS2_PARAM_DC_GAIN;
} }
} }
@ -304,10 +311,112 @@ static inline void bw_ls2_set_dc_gain_dB(bw_ls2_coeffs *BW_RESTRICT coeffs, floa
bw_ls2_set_dc_gain_lin(coeffs, bw_dB2linf(value)); bw_ls2_set_dc_gain_lin(coeffs, bw_dB2linf(value));
} }
#undef _BW_LS2_PARAM_DC_GAIN #undef BW_LS2_PARAM_DC_GAIN
#undef _BW_LS2_PARAM_CUTOFF #undef BW_LS2_PARAM_CUTOFF
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::LS2
* ```>>> */
template<size_t N_CHANNELS>
class LS2 {
public:
LS2();
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<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setQ(float value);
void setDcGainLin(float value);
void setDcGainDB(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_ls2_coeffs coeffs;
bw_ls2_state states[N_CHANNELS];
bw_ls2_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LS2<N_CHANNELS>::LS2() {
bw_ls2_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ls2_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::reset(float x_0) {
bw_ls2_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ls2_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_ls2_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LS2<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 LS2<N_CHANNELS>::setCutoff(float value) {
bw_ls2_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setQ(float value) {
bw_ls2_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setDcGainLin(float value) {
bw_ls2_set_dc_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setDcGainDB(float value) {
bw_ls2_set_dc_gain_dB(&coeffs, value);
}
} }
#endif #endif

View File

@ -1,95 +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_HP1_H
#define BWPP_HP1_H
#include <bw_hp1.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::HP1
* ```>>> */
template<size_t N_CHANNELS>
class HP1 {
public:
HP1();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(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_hp1_coeffs coeffs;
bw_hp1_state states[N_CHANNELS];
bw_hp1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HP1<N_CHANNELS>::HP1() {
bw_hp1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hp1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::reset(float x0) {
bw_hp1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hp1_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_hp1_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HP1<N_CHANNELS>::setCutoff(float value) {
bw_hp1_set_cutoff(&coeffs, value);
}
}
#endif

View File

@ -1,107 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_HS1_H
#define BWPP_HS1_H
#include <bw_hs1.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::HS1
* ```>>> */
template<size_t N_CHANNELS>
class HS1 {
public:
HS1();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setHighGainLin(float value);
void setHighGainDB(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_hs1_coeffs coeffs;
bw_hs1_state states[N_CHANNELS];
bw_hs1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HS1<N_CHANNELS>::HS1() {
bw_hs1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hs1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::reset(float x0) {
bw_hs1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hs1_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_hs1_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setCutoff(float value) {
bw_hs1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setHighGainLin(float value) {
bw_hs1_set_high_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS1<N_CHANNELS>::setHighGainDB(float value) {
bw_hs1_set_high_gain_dB(&coeffs, value);
}
}
#endif

View File

@ -1,113 +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_HS2_H
#define BWPP_HS2_H
#include <bw_hs2.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::HS2
* ```>>> */
template<size_t N_CHANNELS>
class HS2 {
public:
HS2();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setQ(float value);
void setHighGainLin(float value);
void setHighGainDB(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_hs2_coeffs coeffs;
bw_hs2_state states[N_CHANNELS];
bw_hs2_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline HS2<N_CHANNELS>::HS2() {
bw_hs2_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_hs2_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::reset(float x0) {
bw_hs2_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_hs2_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_hs2_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setCutoff(float value) {
bw_hs2_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setQ(float value) {
bw_hs2_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setHighGainLin(float value) {
bw_hs2_set_high_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void HS2<N_CHANNELS>::setHighGainDB(float value) {
bw_hs2_set_high_gain_dB(&coeffs, value);
}
}
#endif

View File

@ -1,107 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_LP1_H
#define BWPP_LP1_H
#include <bw_lp1.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::LP1
* ```>>> */
template<size_t N_CHANNELS>
class LP1 {
public:
LP1();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setPrewarpAtCutoff(bool value);
void setPrewarpFreq(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_lp1_coeffs coeffs;
bw_lp1_state states[N_CHANNELS];
bw_lp1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LP1<N_CHANNELS>::LP1() {
bw_lp1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_lp1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::reset(float x0) {
bw_lp1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_lp1_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_lp1_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setCutoff(float value) {
bw_lp1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setPrewarpAtCutoff(bool value) {
bw_lp1_set_prewarp_at_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LP1<N_CHANNELS>::setPrewarpFreq(float value) {
bw_lp1_set_prewarp_freq(&coeffs, value);
}
}
#endif

View File

@ -1,107 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_LS1_H
#define BWPP_LS1_H
#include <bw_ls1.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::LS1
* ```>>> */
template<size_t N_CHANNELS>
class LS1 {
public:
LS1();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setDcGainLin(float value);
void setDcGainDB(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_ls1_coeffs coeffs;
bw_ls1_state states[N_CHANNELS];
bw_ls1_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LS1<N_CHANNELS>::LS1() {
bw_ls1_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ls1_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::reset(float x0) {
bw_ls1_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ls1_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_ls1_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setCutoff(float value) {
bw_ls1_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setDcGainLin(float value) {
bw_ls1_set_dc_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS1<N_CHANNELS>::setDcGainDB(float value) {
bw_ls1_set_dc_gain_dB(&coeffs, value);
}
}
#endif

View File

@ -1,113 +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_LS2_H
#define BWPP_LS2_H
#include <bw_ls2.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::LS2
* ```>>> */
template<size_t N_CHANNELS>
class LS2 {
public:
LS2();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setQ(float value);
void setDcGainLin(float value);
void setDcGainDB(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_ls2_coeffs coeffs;
bw_ls2_state states[N_CHANNELS];
bw_ls2_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline LS2<N_CHANNELS>::LS2() {
bw_ls2_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ls2_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::reset(float x0) {
bw_ls2_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ls2_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_ls2_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setCutoff(float value) {
bw_ls2_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setQ(float value) {
bw_ls2_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setDcGainLin(float value) {
bw_ls2_set_dc_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void LS2<N_CHANNELS>::setDcGainDB(float value) {
bw_ls2_set_dc_gain_dB(&coeffs, value);
}
}
#endif