polished bw_{reverb,ringmod,satur,slew_lim,sr_reduce,trem} + removed

bwpps + fixed examples
This commit is contained in:
Stefano D'Angelo 2023-08-13 11:18:45 +02:00
parent ccc94c1b0f
commit a5e4fa0c76
18 changed files with 757 additions and 772 deletions

1
TODO
View File

@ -46,6 +46,7 @@ code:
* modulation vs process (multi) no update (post 1.0.0)???
* check assumptions w.r.t. usage of math functions
* extern "C" in a macro to be individually applied (easier #include)
* x_0 vs y_z1 (eg svf vs one_pole/slew_lim)
build system:
* single header generation (vs modules in bwp... to think about)

View File

@ -23,7 +23,7 @@
#include "platform.h"
#include <bwpp_sr_reduce.h>
#include <bw_sr_reduce.h>
#include <bw_bd_reduce.h>
using namespace Brickworks;

View File

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

View File

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

View File

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

View File

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

View File

@ -39,6 +39,15 @@
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_reverb_process()</code> and
* <code>bw_reverb_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>:
@ -55,8 +64,8 @@
* }}}
*/
#ifndef _BW_REVERB_H
#define _BW_REVERB_H
#ifndef BW_REVERB_H
#define BW_REVERB_H
#include <bw_common.h>
@ -67,13 +76,13 @@ extern "C" {
/*! api {{{
* #### bw_reverb_coeffs
* ```>>> */
typedef struct _bw_reverb_coeffs bw_reverb_coeffs;
typedef struct bw_reverb_coeffs bw_reverb_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_reverb_state
* ```>>> */
typedef struct _bw_reverb_state bw_reverb_state;
typedef struct bw_reverb_state bw_reverb_state;
/*! <<<```
* Internal state and related.
*
@ -128,15 +137,15 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c
*
* #### bw_reverb_process1()
* ```>>> */
static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float xl, float xr, float *yl, float *yr);
static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float x_l, float x_r, float *y_l, float *y_r);
/*! <<<```
* Processes one set of input samples `xl` (left) and `xr` (right) using
* Processes one set of input samples `x_l` (left) and `x_r` (right) using
* `coeffs`, while using and updating `state`. The left and right output
* samples are put into `yl` (left) and `yr` (right) respectively.
* samples are put into `y_l` (left) and `y_r` (right) respectively.
*
* #### bw_reverb_process()
* ```>>> */
static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *xl, const float *xr, float *yl, float *yr, int n_samples);
static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *x_l, const float *x_r, float *y_l, float *y_r, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the input buffers `xl` (left) and `xr`
* (right) and fills the first `n_samples` of the output buffers `yl` (left)
@ -145,11 +154,11 @@ static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_re
*
* #### bw_reverb_process_multi()
* ```>>> */
static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state **BW_RESTRICT state, const float **xl, const float **xr, float **yl, float **yr, int n_channels, int n_samples);
static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state * const *BW_RESTRICT state, const float * const *x_l, const float * const *x_r, float **yl, float **yr, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `xl`
* (left) and `xr` (right) and fills the first `n_samples` of the
* `n_channels` output buffers `yl` (left) and `yr` (right), while using and
* Processes the first `n_samples` of the `n_channels` input buffers `x_l`
* (left) and `x_r` (right) and fills the first `n_samples` of the
* `n_channels` output buffers `y_l` (left) and `y_r` (right), while using and
* updating both the common `coeffs` and each of the `n_channels` `state`s
* (control and audio rate).
*
@ -220,7 +229,7 @@ static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float
extern "C" {
#endif
struct _bw_reverb_coeffs {
struct bw_reverb_coeffs {
// Sub-components
bw_delay_coeffs predelay_coeffs;
bw_lp1_coeffs bandwidth_coeffs;
@ -279,7 +288,7 @@ struct _bw_reverb_coeffs {
float predelay;
};
struct _bw_reverb_state {
struct bw_reverb_state {
bw_delay_state predelay_state;
bw_lp1_state bandwidth_state;
bw_delay_state delay_id1_state;
@ -491,8 +500,8 @@ static inline void bw_reverb_update_coeffs_audio(bw_reverb_coeffs *BW_RESTRICT c
bw_drywet_update_coeffs_audio(&coeffs->drywet_coeffs);
}
static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float xl, float xr, float *yl, float *yr) {
const float i = 0.5f * (xl + xr);
static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, float x_l, float x_r, float *y_l, float *y_r) {
const float i = 0.5f * (x_l + x_r);
const float pd = bw_delay_process1(&coeffs->predelay_coeffs, &state->predelay_state, i);
const float bw = bw_lp1_process1(&coeffs->bandwidth_coeffs, &state->bandwidth_state, pd);
@ -552,7 +561,7 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs
bw_delay_write(&coeffs->delay_d2_coeffs, &state->delay_d2_state, dd2);
bw_delay_write(&coeffs->delay_d4_coeffs, &state->delay_d4_state, dd4);
*yl = 0.6f * (
*y_l = 0.6f * (
bw_delay_read(&coeffs->delay_d3_coeffs, &state->delay_d3_state, coeffs->dl1, 0.f)
+ bw_delay_read(&coeffs->delay_d3_coeffs, &state->delay_d3_state, coeffs->dl2, 0.f)
- bw_delay_read(&coeffs->delay_dd4_coeffs, &state->delay_dd4_state, coeffs->dl3, 0.f)
@ -561,7 +570,7 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs
- bw_delay_read(&coeffs->delay_dd2_coeffs, &state->delay_dd2_state, coeffs->dl6, 0.f)
- bw_delay_read(&coeffs->delay_d2_coeffs, &state->delay_d2_state, coeffs->dl7, 0.f)
);
*yr = 0.6f * (
*y_r = 0.6f * (
bw_delay_read(&coeffs->delay_d1_coeffs, &state->delay_d1_state, coeffs->dr1, 0.f)
+ bw_delay_read(&coeffs->delay_d1_coeffs, &state->delay_d1_state, coeffs->dr2, 0.f)
- bw_delay_read(&coeffs->delay_dd2_coeffs, &state->delay_dd2_state, coeffs->dr3, 0.f)
@ -570,24 +579,24 @@ static inline void bw_reverb_process1(const bw_reverb_coeffs *BW_RESTRICT coeffs
- bw_delay_read(&coeffs->delay_dd4_coeffs, &state->delay_dd4_state, coeffs->dr6, 0.f)
- bw_delay_read(&coeffs->delay_d4_coeffs, &state->delay_d4_state, coeffs->dr7, 0.f)
);
*yl = bw_drywet_process1(&coeffs->drywet_coeffs, xl, *yl);
*yr = bw_drywet_process1(&coeffs->drywet_coeffs, xr, *yr);
*y_l = bw_drywet_process1(&coeffs->drywet_coeffs, x_l, *y_l);
*y_r = bw_drywet_process1(&coeffs->drywet_coeffs, x_r, *y_r);
}
static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *xl, const float *xr, float *yl, float *yr, int n_samples) {
static inline void bw_reverb_process(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state *BW_RESTRICT state, const float *x_l, const float *x_r, float *y_l, float *y_r, size_t n_samples) {
bw_reverb_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_reverb_update_coeffs_audio(coeffs);
bw_reverb_process1(coeffs, state, xl[i], xr[i], yl + i, yr + i);
bw_reverb_process1(coeffs, state, x_l[i], x_r[i], y_l + i, y_r + i);
}
}
static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state **BW_RESTRICT state, const float **xl, const float **xr, float **yl, float **yr, int n_channels, int n_samples) {
static inline void bw_reverb_process_multi(bw_reverb_coeffs *BW_RESTRICT coeffs, bw_reverb_state * const *BW_RESTRICT state, const float * const *x_l, const float * const *x_r, float **y_l, float **y_r, size_t n_channels, size_t n_samples) {
bw_reverb_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_reverb_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++)
bw_reverb_process1(coeffs, state[j], xl[j][i], xr[j][i], yl[j] + i, yr[j] + i);
for (size_t j = 0; j < n_channels; j++)
bw_reverb_process1(coeffs, state[j], x_l[j][i], x_r[j][i], y_l[j] + i, y_r[j] + i);
}
}
@ -612,6 +621,138 @@ static inline void bw_reverb_set_wet(bw_reverb_coeffs *BW_RESTRICT coeffs, float
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Reverb
* ```>>> */
template<size_t N_CHANNELS>
class Reverb {
public:
Reverb();
~Reverb();
void setSampleRate(float sampleRate);
void reset();
void process(
const float * const *x_l,
const float * const *x_r,
float **y_l,
float **y_r,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x_l,
std::array<const float *, N_CHANNELS> x_r,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
size_t nSamples);
void setPredelay(float value);
void setBandwidth(float value);
void setDamping(float value);
void setDecay(float value);
void setWet(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_reverb_coeffs coeffs;
bw_reverb_state states[N_CHANNELS];
bw_reverb_state *statesP[N_CHANNELS];
void *mem;
};
template<size_t N_CHANNELS>
inline Reverb<N_CHANNELS>::Reverb() {
bw_reverb_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
mem = nullptr;
}
template<size_t N_CHANNELS>
inline Reverb<N_CHANNELS>::~Reverb() {
if (mem != nullptr)
operator delete(mem);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_reverb_set_sample_rate(&coeffs, sampleRate);
size_t req = bw_reverb_mem_req(&coeffs);
if (mem != nullptr)
operator delete(mem);
mem = operator new(req * N_CHANNELS);
void *m = mem;
for (size_t i = 0; i < N_CHANNELS; i++, m = static_cast<char *>(m) + req)
bw_reverb_mem_set(&coeffs, states + i, m);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::reset() {
bw_reverb_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_reverb_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::process(
const float * const *x_l,
const float * const *x_r,
float **y_l,
float **y_r,
size_t nSamples) {
bw_reverb_process_multi(&coeffs, statesP, x_l, x_r, y_l, y_r, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_l,
std::array<const float *, N_CHANNELS> x_r,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
size_t nSamples) {
process(x_l.data(), x_r.data(), y_l.data(), y_r.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setPredelay(float value) {
bw_reverb_set_predelay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setBandwidth(float value) {
bw_reverb_set_bandwidth(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setDamping(float value) {
bw_reverb_set_damping(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setDecay(float value) {
bw_reverb_set_decay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setWet(float value) {
bw_reverb_set_wet(&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_ringmod_process()</code> and
* <code>bw_ringmod_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>:
@ -55,8 +62,8 @@
* }}}
*/
#ifndef _BW_RINGMOD_H
#define _BW_RINGMOD_H
#ifndef BW_RINGMOD_H
#define BW_RINGMOD_H
#include <bw_common.h>
@ -67,7 +74,7 @@ extern "C" {
/*! api {{{
* #### bw_ringmod_coeffs
* ```>>> */
typedef struct _bw_ringmod_coeffs bw_ringmod_coeffs;
typedef struct bw_ringmod_coeffs bw_ringmod_coeffs;
/*! <<<```
* Coefficients and related.
*
@ -110,7 +117,7 @@ static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coe
*
* #### bw_ringmod_process()
* ```>>> */
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, int n_samples);
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the modulation input buffer `x_mod` and
* of the carrier input buffer `x_car` and fills the first `n_samples` of the
@ -119,7 +126,7 @@ static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, con
*
* #### bw_ringmod_process_multi()
* ```>>> */
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float **x_mod, const float **x_car, float **y, int n_channels, int n_samples);
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float **y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` modulation input
* buffers `x_mod` and of the `n_channels` carrier input buffers `x_car`, and
@ -153,7 +160,7 @@ static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs,
extern "C" {
#endif
struct _bw_ringmod_coeffs {
struct bw_ringmod_coeffs {
// Sub-components
bw_one_pole_coeffs smooth_coeffs;
bw_one_pole_state smooth_state;
@ -190,17 +197,17 @@ static inline float bw_ringmod_process1(const bw_ringmod_coeffs *BW_RESTRICT coe
return k * x_car * x_mod + bw_absf(1.f - k) * x_mod;
}
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, int n_samples) {
for (int i = 0; i < n_samples; i++) {
static inline void bw_ringmod_process(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float *x_mod, const float *x_car, float *y, size_t n_samples) {
for (size_t i = 0; i < n_samples; i++) {
bw_ringmod_update_coeffs_audio(coeffs);
y[i] = bw_ringmod_process1(coeffs, x_mod[i], x_car[i]);
}
}
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float **x_mod, const float **x_car, float **y, int n_channels, int n_samples) {
for (int i = 0; i < n_samples; i++) {
static inline void bw_ringmod_process_multi(bw_ringmod_coeffs *BW_RESTRICT coeffs, const float * const *x_mod, const float * const *x_car, float **y, size_t n_channels, size_t n_samples) {
for (size_t i = 0; i < n_samples; i++) {
bw_ringmod_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_ringmod_process1(coeffs, x_mod[j][i], x_car[j][i]);
}
}
@ -210,6 +217,88 @@ static inline void bw_ringmod_set_amount(bw_ringmod_coeffs *BW_RESTRICT coeffs,
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::RingMod
* ```>>> */
template<size_t N_CHANNELS>
class RingMod {
public:
RingMod();
void setSampleRate(float sampleRate);
void reset();
void process(
const float * const *x_mod,
const float * const *x_car,
float **y,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<const float *, N_CHANNELS> x_car,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setAmount(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_ringmod_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline RingMod<N_CHANNELS>::RingMod() {
bw_ringmod_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ringmod_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::reset() {
bw_ringmod_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::process(
const float * const *x_mod,
const float * const *x_car,
float **y,
size_t nSamples) {
bw_ringmod_process_multi(&coeffs, x_mod, x_car, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<const float *, N_CHANNELS> x_car,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(x_mod.data(), x_car.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setAmount(float value) {
bw_ringmod_set_amount(&coeffs, value);
}
}
#endif

View File

@ -40,8 +40,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_satur_process()</code> and
* <code>bw_satur_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>:
@ -71,8 +78,8 @@
* }}}
*/
#ifndef _BW_SATUR_H
#define _BW_SATUR_H
#ifndef BW_SATUR_H
#define BW_SATUR_H
#include <bw_common.h>
@ -83,13 +90,13 @@ extern "C" {
/*! api {{{
* #### bw_satur_coeffs
* ```>>> */
typedef struct _bw_satur_coeffs bw_satur_coeffs;
typedef struct bw_satur_coeffs bw_satur_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_satur_state
* ```>>> */
typedef struct _bw_satur_state bw_satur_state;
typedef struct bw_satur_state bw_satur_state;
/*! <<<```
* Internal state and related.
*
@ -143,7 +150,7 @@ static inline float bw_satur_process1_comp(const bw_satur_coeffs *BW_RESTRICT co
*
* #### bw_satur_process()
* ```>>> */
static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_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
@ -151,7 +158,7 @@ static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satu
*
* #### bw_satur_process_multi()
* ```>>> */
static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -202,7 +209,7 @@ static inline void bw_satur_set_gain_compensation(bw_satur_coeffs *BW_RESTRICT c
extern "C" {
#endif
struct _bw_satur_coeffs {
struct bw_satur_coeffs {
// Sub-components
bw_one_pole_coeffs smooth_coeffs;
bw_one_pole_state smooth_bias_state;
@ -218,12 +225,12 @@ struct _bw_satur_coeffs {
char gain_compensation;
};
struct _bw_satur_state {
struct bw_satur_state {
float x_z1;
float F_z1;
};
static inline float _bw_satur_tanhf(float x) {
static inline float bw_satur_tanhf(float x) {
const float xm = bw_clipf(x, -2.115287308554551f, 2.115287308554551f);
const float axm = bw_absf(xm);
return xm * axm * (0.01218073260037716f * axm - 0.2750231331124371f) + xm;
@ -243,11 +250,11 @@ static inline void bw_satur_set_sample_rate(bw_satur_coeffs *BW_RESTRICT coeffs,
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
}
static inline void _bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs, char force) {
static inline void bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs, char force) {
float bias_cur = bw_one_pole_get_y_z1(&coeffs->smooth_bias_state);
if (force || coeffs->bias != bias_cur) {
bias_cur = bw_one_pole_process1_sticky_abs(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
coeffs->bias_dc = _bw_satur_tanhf(bias_cur);
coeffs->bias_dc = bw_satur_tanhf(bias_cur);
}
float gain_cur = bw_one_pole_get_y_z1(&coeffs->smooth_gain_state);
if (force || coeffs->gain != gain_cur) {
@ -259,7 +266,7 @@ static inline void _bw_satur_do_update_coeffs(bw_satur_coeffs *BW_RESTRICT coeff
static inline void bw_satur_reset_coeffs(bw_satur_coeffs *BW_RESTRICT coeffs) {
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_gain_state, coeffs->gain);
_bw_satur_do_update_coeffs(coeffs, 1);
bw_satur_do_update_coeffs(coeffs, 1);
}
static inline void bw_satur_reset_state(const bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state) {
@ -273,7 +280,7 @@ static inline void bw_satur_update_coeffs_ctrl(bw_satur_coeffs *BW_RESTRICT coef
}
static inline void bw_satur_update_coeffs_audio(bw_satur_coeffs *BW_RESTRICT coeffs) {
_bw_satur_do_update_coeffs(coeffs, 0);
bw_satur_do_update_coeffs(coeffs, 0);
}
static inline float bw_satur_process1(const bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, float x) {
@ -281,7 +288,7 @@ static inline float bw_satur_process1(const bw_satur_coeffs *BW_RESTRICT coeffs,
const float ax = bw_absf(x);
const float F = ax >= 2.115287308554551f ? ax - 0.6847736211329452f : ax * ax * ((0.00304518315009429f * ax - 0.09167437770414569f) * ax + 0.5f);
const float d = x - state->x_z1;
const float y = d * d < 1e-6f ? _bw_satur_tanhf(0.5f * (x + state->x_z1)) : (F - state->F_z1) * bw_rcpf(d);
const float y = d * d < 1e-6f ? bw_satur_tanhf(0.5f * (x + state->x_z1)) : (F - state->F_z1) * bw_rcpf(d);
state->x_z1 = x;
state->F_z1 = F;
return y - coeffs->bias_dc;
@ -292,24 +299,24 @@ static inline float bw_satur_process1_comp(const bw_satur_coeffs *BW_RESTRICT co
return coeffs->inv_gain * y;
}
static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_satur_process(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
if (coeffs->gain_compensation)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_satur_update_coeffs_audio(coeffs);
y[i] = bw_satur_process1_comp(coeffs, state, x[i]);
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_satur_update_coeffs_audio(coeffs);
y[i] = bw_satur_process1(coeffs, state, x[i]);
}
}
static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_satur_process_multi(bw_satur_coeffs *BW_RESTRICT coeffs, bw_satur_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_satur_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_satur_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_satur_process1(coeffs, state[j], x[j][i]);
}
}
@ -327,6 +334,102 @@ static inline void bw_satur_set_gain_compensation(bw_satur_coeffs *BW_RESTRICT c
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Satur
* ```>>> */
template<size_t N_CHANNELS>
class Satur {
public:
Satur();
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 setBias(float value);
void setGain(float value);
void setGainCompensation(bool 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_satur_coeffs coeffs;
bw_satur_state states[N_CHANNELS];
bw_satur_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Satur<N_CHANNELS>::Satur() {
bw_satur_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_satur_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::reset() {
bw_satur_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_satur_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_satur_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Satur<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 Satur<N_CHANNELS>::setBias(float value) {
bw_satur_set_bias(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setGain(float value) {
bw_satur_set_gain(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setGainCompensation(bool value) {
bw_satur_set_gain_compensation(&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_slew_lim_process()</code> and
* <code>bw_slew_lim_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>:
@ -60,8 +67,8 @@
* }}}
*/
#ifndef _BW_SLEW_LIM_H
#define _BW_SLEW_LIM_H
#ifndef BW_SLEW_LIM_H
#define BW_SLEW_LIM_H
#include <bw_common.h>
@ -72,13 +79,13 @@ extern "C" {
/*! api {{{
* #### bw_slew_lim_coeffs
* ```>>> */
typedef struct _bw_slew_lim_coeffs bw_slew_lim_coeffs;
typedef struct bw_slew_lim_coeffs bw_slew_lim_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_slew_lim_state
* ```>>> */
typedef struct _bw_slew_lim_state bw_slew_lim_state;
typedef struct bw_slew_lim_state bw_slew_lim_state;
/*! <<<```
* Internal state and related.
*
@ -140,7 +147,7 @@ static inline float bw_slew_lim_process1_down(const bw_slew_lim_coeffs *BW_RESTR
*
* #### bw_slew_lim_process()
* ```>>> */
static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_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
@ -150,7 +157,7 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b
*
* #### bw_slew_lim_process_multi()
* ```>>> */
static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -220,7 +227,7 @@ static inline float bw_slew_lim_get_y_z1(const bw_slew_lim_state *BW_RESTRICT st
extern "C" {
#endif
struct _bw_slew_lim_coeffs {
struct bw_slew_lim_coeffs {
// Coefficients
float T;
@ -232,7 +239,7 @@ struct _bw_slew_lim_coeffs {
float max_rate_down;
};
struct _bw_slew_lim_state {
struct bw_slew_lim_state {
float y_z1;
};
@ -282,22 +289,22 @@ static inline float bw_slew_lim_process1_down(const bw_slew_lim_coeffs *BW_RESTR
return y;
}
static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_slew_lim_update_coeffs_ctrl(coeffs);
if (y != NULL) {
if (coeffs->max_rate_up != INFINITY) {
if (coeffs->max_rate_down != INFINITY)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[i] = bw_slew_lim_process1(coeffs, state, x[i]);
else
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[i] = bw_slew_lim_process1_up(coeffs, state, x[i]);
} else {
if (coeffs->max_rate_down != INFINITY)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[i] = bw_slew_lim_process1_down(coeffs, state, x[i]);
else {
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[i] = x[i];
state->y_z1 = x[n_samples - 1];
}
@ -305,14 +312,14 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b
} else {
if (coeffs->max_rate_up != INFINITY) {
if (coeffs->max_rate_down != INFINITY)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1(coeffs, state, x[i]);
else
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1_up(coeffs, state, x[i]);
} else {
if (coeffs->max_rate_down != INFINITY)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1_down(coeffs, state, x[i]);
else
state->y_z1 = x[n_samples - 1];
@ -320,38 +327,38 @@ static inline void bw_slew_lim_process(bw_slew_lim_coeffs *BW_RESTRICT coeffs, b
}
}
static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coeffs, bw_slew_lim_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_slew_lim_update_coeffs_ctrl(coeffs);
if (y != NULL) {
if (coeffs->max_rate_up != INFINITY) {
if (coeffs->max_rate_down != INFINITY)
for (int j = 0; j < n_channels; j++)
for (size_t j = 0; j < n_channels; j++)
if (y[j] != NULL)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[j][i] = bw_slew_lim_process1(coeffs, state[j], x[j][i]);
else
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1(coeffs, state[j], x[j][i]);
else
for (int j = 0; j < n_channels; j++)
for (int i = 0; i < n_samples; i++)
for (size_t j = 0; j < n_channels; j++)
for (size_t i = 0; i < n_samples; i++)
if (y[j] != NULL)
y[j][i] = bw_slew_lim_process1_up(coeffs, state[j], x[j][i]);
else
bw_slew_lim_process1_up(coeffs, state[j], x[j][i]);
} else {
if (coeffs->max_rate_down != INFINITY)
for (int j = 0; j < n_channels; j++)
for (size_t j = 0; j < n_channels; j++)
if (y[j] != NULL)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[j][i] = bw_slew_lim_process1_down(coeffs, state[j], x[j][i]);
else
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1_down(coeffs, state[j], x[j][i]);
else
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
if (y[j] != NULL)
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[j][i] = x[j][i];
state[j]->y_z1 = x[j][n_samples - 1];
}
@ -359,20 +366,20 @@ static inline void bw_slew_lim_process_multi(bw_slew_lim_coeffs *BW_RESTRICT coe
} else {
if (coeffs->max_rate_up != INFINITY) {
if (coeffs->max_rate_down != INFINITY)
for (int j = 0; j < n_channels; j++)
for (int i = 0; i < n_samples; i++)
for (size_t j = 0; j < n_channels; j++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1(coeffs, state[j], x[j][i]);
else
for (int j = 0; j < n_channels; j++)
for (int i = 0; i < n_samples; i++)
for (size_t j = 0; j < n_channels; j++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1_up(coeffs, state[j], x[j][i]);
} else {
if (coeffs->max_rate_down != INFINITY)
for (int j = 0; j < n_channels; j++)
for (int i = 0; i < n_samples; i++)
for (size_t j = 0; j < n_channels; j++)
for (size_t i = 0; i < n_samples; i++)
bw_slew_lim_process1_down(coeffs, state[j], x[j][i]);
else
for (int j = 0; j < n_channels; j++)
for (size_t j = 0; j < n_channels; j++)
state[j]->y_z1 = x[j][n_samples - 1];
}
}
@ -396,6 +403,109 @@ static inline float bw_slew_lim_get_y_z1(const bw_slew_lim_state *BW_RESTRICT st
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::SlewLim
* ```>>> */
template<size_t N_CHANNELS>
class SlewLim {
public:
SlewLim();
void setSampleRate(float sampleRate);
void reset(float y_z1 = 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 setMaxRate(float value);
void setMaxRateUp(float value);
void setMaxRateDown(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_slew_lim_coeffs coeffs;
bw_slew_lim_state states[N_CHANNELS];
bw_slew_lim_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline SlewLim<N_CHANNELS>::SlewLim() {
bw_slew_lim_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_slew_lim_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::reset(float y_z1) {
bw_slew_lim_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_slew_lim_reset_state(&coeffs, states + i, y_z1);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_slew_lim_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void SlewLim<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 SlewLim<N_CHANNELS>::setMaxRate(float value) {
bw_slew_lim_set_max_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setMaxRateUp(float value) {
bw_slew_lim_set_max_rate_up(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setMaxRateDown(float value) {
bw_slew_lim_set_max_rate_down(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float SlewLim<N_CHANNELS>::getYZ1(size_t channel) {
return bw_slew_lim_get_y_z1(states + channel);
}
}
#endif

View File

@ -33,8 +33,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_sr_reduce_lim_process()</code> and
* <code>bw_sr_reduce_lim_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>:
@ -62,8 +69,8 @@
* }}}
*/
#ifndef _BW_SR_REDUCE_H
#define _BW_SR_REDUCE_H
#ifndef BW_SR_REDUCE_H
#define BW_SR_REDUCE_H
#include <bw_common.h>
@ -74,13 +81,13 @@ extern "C" {
/*! api {{{
* #### bw_sr_reduce_coeffs
* ```>>> */
typedef struct _bw_sr_reduce_coeffs bw_sr_reduce_coeffs;
typedef struct bw_sr_reduce_coeffs bw_sr_reduce_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_sr_reduce_state
* ```>>> */
typedef struct _bw_sr_reduce_state bw_sr_reduce_state;
typedef struct bw_sr_reduce_state bw_sr_reduce_state;
/*! <<<```
* Internal state and related.
*
@ -105,7 +112,7 @@ static inline float bw_sr_reduce_process1(const bw_sr_reduce_coeffs *BW_RESTRICT
*
* #### bw_sr_reduce_process()
* ```>>> */
static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_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 `coeffs` and
@ -113,7 +120,7 @@ static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs,
*
* #### bw_sr_reduce_process_multi()
* ```>>> */
static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_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
@ -146,12 +153,12 @@ static inline void bw_sr_reduce_set_ratio(bw_sr_reduce_coeffs *BW_RESTRICT coeff
extern "C" {
#endif
struct _bw_sr_reduce_coeffs {
struct bw_sr_reduce_coeffs {
// Parameters
float ratio;
};
struct _bw_sr_reduce_state {
struct bw_sr_reduce_state {
float phase;
float y_z1;
};
@ -174,13 +181,13 @@ static inline float bw_sr_reduce_process1(const bw_sr_reduce_coeffs *BW_RESTRICT
return state->y_z1;
}
static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
for (int i = 0; i < n_samples; i++)
static inline void bw_sr_reduce_process(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
for (size_t i = 0; i < n_samples; i++)
y[i] = bw_sr_reduce_process1(coeffs, state, x[i]);
}
static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
for (int i = 0; i < n_channels; i++)
static inline void bw_sr_reduce_process_multi(bw_sr_reduce_coeffs *BW_RESTRICT coeffs, bw_sr_reduce_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
for (size_t i = 0; i < n_channels; i++)
bw_sr_reduce_process(coeffs, state[i], x[i], y[i], n_samples);
}
@ -189,6 +196,83 @@ static inline void bw_sr_reduce_set_ratio(bw_sr_reduce_coeffs *BW_RESTRICT coeff
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::SRReduce
* ```>>> */
template<size_t N_CHANNELS>
class SRReduce {
public:
SRReduce();
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 setRatio(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_sr_reduce_coeffs coeffs;
bw_sr_reduce_state states[N_CHANNELS];
bw_sr_reduce_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline SRReduce<N_CHANNELS>::SRReduce() {
bw_sr_reduce_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void SRReduce<N_CHANNELS>::reset() {
for (size_t i = 0; i < N_CHANNELS; i++)
bw_sr_reduce_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void SRReduce<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_sr_reduce_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void SRReduce<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 SRReduce<N_CHANNELS>::setRatio(float value) {
bw_sr_reduce_set_ratio(&coeffs, value);
}
}
#endif

View File

@ -31,8 +31,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_trem_process()</code> and
* <code>bw_trem_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>:
@ -55,8 +62,8 @@
* }}}
*/
#ifndef _BW_TREM_H
#define _BW_TREM_H
#ifndef BW_TREM_H
#define BW_TREM_H
#include <bw_common.h>
@ -67,13 +74,13 @@ extern "C" {
/*! api {{{
* #### bw_trem_coeffs
* ```>>> */
typedef struct _bw_trem_coeffs bw_trem_coeffs;
typedef struct bw_trem_coeffs bw_trem_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_trem_state
* ```>>> */
typedef struct _bw_trem_state bw_trem_state;
typedef struct bw_trem_state bw_trem_state;
/*! <<<```
* Internal state and related.
*
@ -122,7 +129,7 @@ static inline float bw_trem_process1(const bw_trem_coeffs *BW_RESTRICT coeffs, b
*
* #### bw_trem_process()
* ```>>> */
static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_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
@ -130,7 +137,7 @@ static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_s
*
* #### bw_trem_process_multi()
* ```>>> */
static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_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,13 +179,13 @@ static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float
extern "C" {
#endif
struct _bw_trem_coeffs {
struct bw_trem_coeffs {
// Sub-components
bw_phase_gen_coeffs phase_gen_coeffs;
bw_ringmod_coeffs ringmod_coeffs;
};
struct _bw_trem_state {
struct bw_trem_state {
bw_phase_gen_state phase_gen_state;
};
@ -218,19 +225,19 @@ static inline float bw_trem_process1(const bw_trem_coeffs *BW_RESTRICT coeffs, b
return bw_ringmod_process1(&coeffs->ringmod_coeffs, x, 1.f + c);
}
static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_trem_process(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_trem_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_trem_update_coeffs_audio(coeffs);
y[i] = bw_trem_process1(coeffs, state, x[i]);
}
}
static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_trem_process_multi(bw_trem_coeffs *BW_RESTRICT coeffs, bw_trem_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_trem_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_trem_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_trem_process1(coeffs, state[j], x[j][i]);
}
}
@ -244,6 +251,96 @@ static inline void bw_trem_set_amount(bw_trem_coeffs *BW_RESTRICT coeffs, float
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Trem
* ```>>> */
template<size_t N_CHANNELS>
class Trem {
public:
Trem();
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 setRate(float value);
void setAmount(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_trem_coeffs coeffs;
bw_trem_state states[N_CHANNELS];
bw_trem_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Trem<N_CHANNELS>::Trem() {
bw_trem_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Trem<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_trem_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Trem<N_CHANNELS>::reset() {
bw_trem_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_trem_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Trem<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_trem_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Trem<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 Trem<N_CHANNELS>::setRate(float value) {
bw_trem_set_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Trem<N_CHANNELS>::setAmount(float value) {
bw_trem_set_amount(&coeffs, value);
}
}
#endif

View File

@ -1,139 +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_REVERB_H
#define BWPP_REVERB_H
#include <bw_reverb.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Reverb
* ```>>> */
template<size_t N_CHANNELS>
class Reverb {
public:
Reverb();
~Reverb();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> xl,
std::array<const float *, N_CHANNELS> xr,
std::array<float *, N_CHANNELS> yl,
std::array<float *, N_CHANNELS> yr,
int nSamples);
void setPredelay(float value);
void setBandwidth(float value);
void setDamping(float value);
void setDecay(float value);
void setWet(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_reverb_coeffs coeffs;
bw_reverb_state states[N_CHANNELS];
bw_reverb_state *statesP[N_CHANNELS];
void *mem;
};
template<size_t N_CHANNELS>
inline Reverb<N_CHANNELS>::Reverb() {
bw_reverb_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
mem = nullptr;
}
template<size_t N_CHANNELS>
inline Reverb<N_CHANNELS>::~Reverb() {
if (mem != nullptr)
operator delete(mem);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_reverb_set_sample_rate(&coeffs, sampleRate);
size_t req = bw_reverb_mem_req(&coeffs);
if (mem != nullptr)
operator delete(mem);
mem = operator new(req * N_CHANNELS);
void *m = mem;
for (size_t i = 0; i < N_CHANNELS; i++, m = static_cast<char *>(m) + req)
bw_reverb_mem_set(&coeffs, states + i, m);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::reset() {
bw_reverb_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_reverb_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> xl,
std::array<const float *, N_CHANNELS> xr,
std::array<float *, N_CHANNELS> yl,
std::array<float *, N_CHANNELS> yr,
int nSamples) {
bw_reverb_process_multi(&coeffs, statesP, xl.data(), xr.data(), yl.data(), yr.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setPredelay(float value) {
bw_reverb_set_predelay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setBandwidth(float value) {
bw_reverb_set_bandwidth(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setDamping(float value) {
bw_reverb_set_damping(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setDecay(float value) {
bw_reverb_set_decay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Reverb<N_CHANNELS>::setWet(float value) {
bw_reverb_set_wet(&coeffs, value);
}
}
#endif

View File

@ -1,91 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can reringmodribute 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 ringmodributed 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_RINGMOD_H
#define BWPP_RINGMOD_H
#include <bw_ringmod.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::RingMod
* ```>>> */
template<size_t N_CHANNELS>
class RingMod {
public:
RingMod();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<const float *, N_CHANNELS> x_car,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setAmount(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_ringmod_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline RingMod<N_CHANNELS>::RingMod() {
bw_ringmod_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ringmod_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::reset() {
bw_ringmod_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<const float *, N_CHANNELS> x_car,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_ringmod_process_multi(&coeffs, statesP, x_mod.data(), x_car.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void RingMod<N_CHANNELS>::setAmount(float value) {
bw_ringmod_set_amount(&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_SATUR_H
#define BWPP_SATUR_H
#include <bw_satur.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Satur
* ```>>> */
template<size_t N_CHANNELS>
class Satur {
public:
Satur();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setBias(float value);
void setGain(float value);
void setGainCompensation(bool 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_satur_coeffs coeffs;
bw_satur_state states[N_CHANNELS];
bw_satur_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Satur<N_CHANNELS>::Satur() {
bw_satur_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_satur_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::reset() {
bw_satur_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_satur_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_satur_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setBias(float value) {
bw_satur_set_bias(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setGain(float value) {
bw_satur_set_gain(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Satur<N_CHANNELS>::setGainCompensation(bool value) {
bw_satur_set_gain_compensation(&coeffs, value);
}
}
#endif

View File

@ -1,114 +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_SLEW_LIM_H
#define BWPP_SLEW_LIM_H
#include <bw_slew_lim.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::SlewLim
* ```>>> */
template<size_t N_CHANNELS>
class SlewLim {
public:
SlewLim();
void setSampleRate(float sampleRate);
void reset(float y_z1 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setMaxRate(float value);
void setMaxRateUp(float value);
void setMaxRateDown(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_slew_lim_coeffs coeffs;
bw_slew_lim_state states[N_CHANNELS];
bw_slew_lim_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline SlewLim<N_CHANNELS>::SlewLim() {
bw_slew_lim_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_slew_lim_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::reset(float y_z1) {
bw_slew_lim_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_slew_lim_reset_state(&coeffs, states + i, y_z1);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_slew_lim_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setMaxRate(float value) {
bw_slew_lim_set_max_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setMaxRateUp(float value) {
bw_slew_lim_set_max_rate_up(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void SlewLim<N_CHANNELS>::setMaxRateDown(float value) {
bw_slew_lim_set_max_rate_down(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float SlewLim<N_CHANNELS>::getYZ1(size_t channel) {
return bw_slew_lim_get_y_z1(states + channel);
}
}
#endif

View File

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

View File

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