polished bw_{delay,dist,drive,drywet} + removed

bwpp_{delay,dist,drive,drywet} + fixed doc in bw_{clip,comb,comp} + fixed examples
This commit is contained in:
Stefano D'Angelo 2023-08-12 18:45:19 +02:00
parent 425aa020e1
commit f89188f790
16 changed files with 507 additions and 510 deletions

9
TODO
View File

@ -1,6 +1,11 @@
1.0.0
-----
in progress:
* merge c++ code into c headers
* revise typedef style (see https://stackoverflow.com/questions/54752861/using-an-anonymous-struct-vs-a-named-struct-with-typedef)
* var names xy -> x_y
* don't use reserved identifiers (https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=107685)
code:
* debugging
* check all examples again
@ -27,13 +32,9 @@ code:
* bw_fuzz gain compensation?
* make gain of distortions homogeneous?
* max_delay -> set sample rate? see reverb
* revise typedef style (see https://stackoverflow.com/questions/54752861/using-an-anonymous-struct-vs-a-named-struct-with-typedef)
* var names xy -> x_y
* don't use reserved identifiers (https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=107685)
* update state ctrl -> process ctrl?
* mem req -> return value of set sample rate?
* peak gain + Q ???
* merge c++ code into c headers
* sr_reduce reset_coeffs? update_coeffs? process_multi?
* drywet -> dry_wet, ringmod -> ring_mod, etc?
* allow nullptr in C++ wrappers where process_multi arg can be NULL

View File

@ -21,6 +21,8 @@
#ifndef _BW_EXAMPLE_FX_REVERB_H
#define _BW_EXAMPLE_FX_REVERB_H
#include "platform.h"
#include <bw_reverb.h>
#ifdef __cplusplus

View File

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

View File

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

View File

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

View File

@ -327,7 +327,9 @@ static inline void bw_clip_set_gain_compensation(bw_clip_coeffs *BW_RESTRICT coe
namespace Brickworks {
/*! api {{{
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Clip
* ```>>> */
template<size_t N_CHANNELS>

View File

@ -397,7 +397,9 @@ static inline void bw_comb_set_coeff_fb(bw_comb_coeffs *BW_RESTRICT coeffs, floa
namespace Brickworks {
/*! api {{{
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Comb
* ```>>> */
template<size_t N_CHANNELS>

View File

@ -31,8 +31,8 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li><code>bw_comb_process()</code> and
* <code>bw_comb_process_multi()</code> now use <code>size_t</code>
* <li><code>bw_comp_process()</code> and
* <code>bw_comp_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>
@ -346,7 +346,9 @@ static inline void bw_comp_set_gain_dB(bw_comp_coeffs *BW_RESTRICT coeffs, float
namespace Brickworks {
/*! api {{{
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Comp
* ```>>> */
template<size_t N_CHANNELS>

View File

@ -35,6 +35,15 @@
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_delay_process()</code> and
* <code>bw_delay_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>:
@ -58,8 +67,8 @@
* }}}
*/
#ifndef _BW_DELAY_H
#define _BW_DELAY_H
#ifndef BW_DELAY_H
#define BW_DELAY_H
#include <bw_common.h>
@ -70,13 +79,13 @@ extern "C" {
/*! api {{{
* #### bw_delay_coeffs
* ```>>> */
typedef struct _bw_delay_coeffs bw_delay_coeffs;
typedef struct bw_delay_coeffs bw_delay_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_delay_state
* ```>>> */
typedef struct _bw_delay_state bw_delay_state;
typedef struct bw_delay_state bw_delay_state;
/*! <<<```
* Internal state and related.
*
@ -156,7 +165,7 @@ static inline float bw_delay_process1(const bw_delay_coeffs *BW_RESTRICT coeffs,
*
* #### bw_delay_process()
* ```>>> */
static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_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
@ -164,7 +173,7 @@ static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_dela
*
* #### bw_delay_process_multi()
* ```>>> */
static inline void bw_delay_process_multi(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_delay_process_multi(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_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 +211,7 @@ static inline size_t bw_delay_get_length(const bw_delay_coeffs *BW_RESTRICT coef
extern "C" {
#endif
struct _bw_delay_coeffs {
struct bw_delay_coeffs {
// Coefficients
float fs;
size_t len;
@ -216,7 +225,7 @@ struct _bw_delay_coeffs {
char delay_changed;
};
struct _bw_delay_state {
struct bw_delay_state {
float *buf;
size_t idx;
};
@ -280,16 +289,16 @@ static inline float bw_delay_process1(const bw_delay_coeffs *BW_RESTRICT coeffs,
return bw_delay_read(coeffs, state, coeffs->di, coeffs->df);
}
static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_delay_process(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_delay_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++)
for (size_t i = 0; i < n_samples; i++)
y[i] = bw_delay_process1(coeffs, state, x[i]);
}
static inline void bw_delay_process_multi(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_delay_process_multi(bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_delay_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++)
for (int j = 0; j < n_channels; j++)
for (size_t i = 0; i < n_samples; i++)
for (size_t j = 0; j < n_channels; j++)
y[j][i] = bw_delay_process1(coeffs, state[j], x[j][i]);
}
@ -305,6 +314,126 @@ static inline size_t bw_delay_get_length(const bw_delay_coeffs *BW_RESTRICT coef
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Delay
* ```>>> */
template<size_t N_CHANNELS>
class Delay {
public:
Delay(float maxDelay = 1.f);
~Delay();
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);
float read(size_t channel, size_t di, float df);
void write(size_t channel, float x);
void setDelay(float value);
size_t getLength();
/*! <<<...
* }
* ```
* }}} */
/*** 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_delay_coeffs coeffs;
bw_delay_state states[N_CHANNELS];
bw_delay_state *statesP[N_CHANNELS];
void *mem;
};
template<size_t N_CHANNELS>
inline Delay<N_CHANNELS>::Delay(float maxDelay) {
bw_delay_init(&coeffs, maxDelay);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
mem = nullptr;
}
template<size_t N_CHANNELS>
inline Delay<N_CHANNELS>::~Delay() {
if (mem != nullptr)
operator delete(mem);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_delay_set_sample_rate(&coeffs, sampleRate);
size_t req = bw_delay_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_delay_mem_set(&coeffs, states + i, m);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::reset() {
bw_delay_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_delay_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_delay_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Delay<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 float Delay<N_CHANNELS>::read(size_t channel, size_t di, float df) {
return bw_delay_read(&coeffs, states + channel, di, df);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::write(size_t channel, float x) {
bw_delay_write(&coeffs, states + channel, x);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::setDelay(float value) {
bw_delay_set_delay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline size_t Delay<N_CHANNELS>::getLength() {
return bw_delay_get_length(&coeffs);
}
}
#endif

View File

@ -34,8 +34,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_dist_process()</code> and
* <code>bw_dist_process_multi()</code> now use <code>size_t</code>
* to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -52,8 +59,8 @@
* }}}
*/
#ifndef _BW_DIST_H
#define _BW_DIST_H
#ifndef BW_DIST_H
#define BW_DIST_H
#include <bw_common.h>
@ -64,13 +71,13 @@ extern "C" {
/*! api {{{
* #### bw_dist_coeffs
* ```>>> */
typedef struct _bw_dist_coeffs bw_dist_coeffs;
typedef struct bw_dist_coeffs bw_dist_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_dist_state
* ```>>> */
typedef struct _bw_dist_state bw_dist_state;
typedef struct bw_dist_state bw_dist_state;
/*! <<<```
* Internal state and related.
*
@ -119,7 +126,7 @@ static inline float bw_dist_process1(const bw_dist_coeffs *BW_RESTRICT coeffs, b
*
* #### bw_dist_process()
* ```>>> */
static inline void bw_dist_process(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_dist_process(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffer `y`, while using and updating both
@ -127,7 +134,7 @@ static inline void bw_dist_process(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_s
*
* #### bw_dist_process_multi()
* ```>>> */
static inline void bw_dist_process_multi(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_dist_process_multi(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_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
@ -181,7 +188,7 @@ static inline void bw_dist_set_volume(bw_dist_coeffs *BW_RESTRICT coeffs, float
extern "C" {
#endif
struct _bw_dist_coeffs {
struct bw_dist_coeffs {
// Sub-components
bw_hp1_coeffs hp1_coeffs;
bw_peak_coeffs peak_coeffs;
@ -191,7 +198,7 @@ struct _bw_dist_coeffs {
bw_gain_coeffs gain_coeffs;
};
struct _bw_dist_state {
struct bw_dist_state {
// Sub-components
bw_hp1_state hp1_state;
bw_peak_state peak_state;
@ -263,19 +270,19 @@ static inline float bw_dist_process1(const bw_dist_coeffs *BW_RESTRICT coeffs, b
return bw_gain_process1(&coeffs->gain_coeffs, y);
}
static inline void bw_dist_process(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_dist_process(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_dist_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_dist_update_coeffs_audio(coeffs);
y[i] = bw_dist_process1(coeffs, state, x[i]);
}
}
static inline void bw_dist_process_multi(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_dist_process_multi(bw_dist_coeffs *BW_RESTRICT coeffs, bw_dist_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_dist_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_dist_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_dist_process1(coeffs, state[j], x[j][i]);
}
}
@ -293,6 +300,102 @@ static inline void bw_dist_set_volume(bw_dist_coeffs *BW_RESTRICT coeffs, float
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Dist
* ```>>> */
template<size_t N_CHANNELS>
class Dist {
public:
Dist();
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 setDistortion(float value);
void setTone(float value);
void setVolume(float value);
/*! <<<...
* }
* ```
* }}} */
/*** Implementation ***/
/* WARNING: This part of the file is not part of the public API. Its content may
* change at any time in future versions. Please, do not use it directly. */
private:
bw_dist_coeffs coeffs;
bw_dist_state states[N_CHANNELS];
bw_dist_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Dist<N_CHANNELS>::Dist() {
bw_dist_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_dist_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::reset() {
bw_dist_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_dist_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_dist_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Dist<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 Dist<N_CHANNELS>::setDistortion(float value) {
bw_dist_set_distortion(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setTone(float value) {
bw_dist_set_tone(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setVolume(float value) {
bw_dist_set_volume(&coeffs, value);
}
}
#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_drive_process()</code> and
* <code>bw_drive_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>:
@ -51,8 +58,8 @@
* }}}
*/
#ifndef _BW_DRIVE_H
#define _BW_DRIVE_H
#ifndef BW_DRIVE_H
#define BW_DRIVE_H
#include <bw_common.h>
@ -63,13 +70,13 @@ extern "C" {
/*! api {{{
* #### bw_drive_coeffs
* ```>>> */
typedef struct _bw_drive_coeffs bw_drive_coeffs;
typedef struct bw_drive_coeffs bw_drive_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_drive_state
* ```>>> */
typedef struct _bw_drive_state bw_drive_state;
typedef struct bw_drive_state bw_drive_state;
/*! <<<```
* Internal state and related.
*
@ -118,7 +125,7 @@ static inline float bw_drive_process1(const bw_drive_coeffs *BW_RESTRICT coeffs,
*
* #### bw_drive_process()
* ```>>> */
static inline void bw_drive_process(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_drive_process(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_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
@ -126,7 +133,7 @@ static inline void bw_drive_process(bw_drive_coeffs *BW_RESTRICT coeffs, bw_driv
*
* #### bw_drive_process_multi()
* ```>>> */
static inline void bw_drive_process_multi(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_drive_process_multi(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_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
@ -178,7 +185,7 @@ static inline void bw_drive_set_volume(bw_drive_coeffs *BW_RESTRICT coeffs, floa
extern "C" {
#endif
struct _bw_drive_coeffs {
struct bw_drive_coeffs {
// Sub-components
bw_svf_coeffs hp2_coeffs;
bw_peak_coeffs peak_coeffs;
@ -187,7 +194,7 @@ struct _bw_drive_coeffs {
bw_gain_coeffs gain_coeffs;
};
struct _bw_drive_state {
struct bw_drive_state {
// Sub-components
bw_svf_state hp2_state;
bw_peak_state peak_state;
@ -252,19 +259,19 @@ static inline float bw_drive_process1(const bw_drive_coeffs *BW_RESTRICT coeffs,
return bw_gain_process1(&coeffs->gain_coeffs, v_lp);
}
static inline void bw_drive_process(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_drive_process(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_drive_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_drive_update_coeffs_audio(coeffs);
y[i] = bw_drive_process1(coeffs, state, x[i]);
}
}
static inline void bw_drive_process_multi(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_drive_process_multi(bw_drive_coeffs *BW_RESTRICT coeffs, bw_drive_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_drive_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_drive_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_drive_process1(coeffs, state[j], x[j][i]);
}
}
@ -282,6 +289,102 @@ static inline void bw_drive_set_volume(bw_drive_coeffs *BW_RESTRICT coeffs, floa
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Drive
* ```>>> */
template<size_t N_CHANNELS>
class Drive {
public:
Drive();
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 setDrive(float value);
void setTone(float value);
void setVolume(float value);
/*! <<<...
* }
* ```
* }}} */
/*** Implementation ***/
/* WARNING: This part of the file is not part of the public API. Its content may
* change at any time in future versions. Please, do not use it directly. */
private:
bw_drive_coeffs coeffs;
bw_drive_state states[N_CHANNELS];
bw_drive_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Drive<N_CHANNELS>::Drive() {
bw_drive_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_drive_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::reset() {
bw_drive_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_drive_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_drive_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Drive<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 Drive<N_CHANNELS>::setDrive(float value) {
bw_drive_set_drive(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setTone(float value) {
bw_drive_set_tone(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setVolume(float value) {
bw_drive_set_volume(&coeffs, value);
}
}
#endif

View File

@ -29,8 +29,15 @@
* <ul>
* <li>Version <strong>1.0.0</strong>:
* <ul>
* <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li>
* <li><code>bw_drywet_process()</code> and
* <code>bw_drywet_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>:
@ -47,8 +54,8 @@
* }}}
*/
#ifndef _BW_DRYWET_H
#define _BW_DRYWET_H
#ifndef BW_DRYWET_H
#define BW_DRYWET_H
#include <bw_common.h>
@ -59,7 +66,7 @@ extern "C" {
/*! api {{{
* #### bw_drywet_coeffs
* ```>>> */
typedef struct _bw_drywet_coeffs bw_drywet_coeffs;
typedef struct bw_drywet_coeffs bw_drywet_coeffs;
/*! <<<```
* Coefficients and related.
*
@ -102,7 +109,7 @@ static inline float bw_drywet_process1(const bw_drywet_coeffs *BW_RESTRICT coeff
*
* #### bw_drywet_process()
* ```>>> */
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, int n_samples);
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the dry input buffer `x_dry` and of the
* wet input buffer `x_wet` and fills the first `n_samples` of the output
@ -110,7 +117,7 @@ static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const
*
* #### bw_drywet_process_multi()
* ```>>> */
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float **x_dry, const float **x_wet, float **y, int n_channels, int n_samples);
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float **y, size_t n_channels, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the `n_channels` dry input buffers
* `x_dry` and of the `n_channels` wet input buffers `x_wet`, and fills the
@ -149,7 +156,7 @@ static inline void bw_drywet_set_smooth_tau(bw_drywet_coeffs *BW_RESTRICT coeffs
extern "C" {
#endif
struct _bw_drywet_coeffs {
struct bw_drywet_coeffs {
// Sub-components
bw_gain_coeffs gain_coeffs;
};
@ -178,19 +185,19 @@ static inline float bw_drywet_process1(const bw_drywet_coeffs *BW_RESTRICT coeff
return bw_gain_get_gain(&coeffs->gain_coeffs) * (x_wet - x_dry) + x_dry;
}
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, int n_samples) {
static inline void bw_drywet_process(bw_drywet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples) {
bw_drywet_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_drywet_update_coeffs_audio(coeffs);
y[i] = bw_drywet_process1(coeffs, x_dry[i], x_wet[i]);
}
}
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float **x_dry, const float **x_wet, float **y, int n_channels, int n_samples) {
static inline void bw_drywet_process_multi(bw_drywet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float **y, size_t n_channels, size_t n_samples) {
bw_drywet_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_drywet_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_drywet_process1(coeffs, x_dry[j][i], x_wet[j][i]);
}
}
@ -204,6 +211,94 @@ static inline void bw_drywet_set_smooth_tau(bw_drywet_coeffs *BW_RESTRICT coeffs
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::DryWet
* ```>>> */
template<size_t N_CHANNELS>
class DryWet {
public:
DryWet();
void setSampleRate(float sampleRate);
void reset();
void process(
const float * const *x_dry,
const float * const *x_wet,
float **y,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x_dry,
std::array<const float *, N_CHANNELS> x_wet,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setWet(float value);
void setSmoothTau(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_drywet_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline DryWet<N_CHANNELS>::DryWet() {
bw_drywet_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_drywet_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::reset() {
bw_drywet_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::process(
const float * const *x_dry,
const float * const *x_wet,
float **y,
size_t nSamples) {
bw_drywet_process_multi(&coeffs, x_dry, x_wet, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_dry,
std::array<const float *, N_CHANNELS> x_wet,
std::array<float *, N_CHANNELS> y,
size_t nSamples) {
process(x_dry.data(), x_wet.data(), y.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setWet(float value) {
bw_drywet_set_wet(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSmoothTau(float value) {
bw_drywet_set_smooth_tau(&coeffs, value);
}
}
#endif

View File

@ -1,131 +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_DELAY_H
#define BWPP_DELAY_H
#include <bw_delay.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Delay
* ```>>> */
template<size_t N_CHANNELS>
class Delay {
public:
Delay(float maxDelay = 1.f);
~Delay();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
float read(size_t channel, size_t di, float df);
void write(size_t channel, float x);
void setDelay(float value);
size_t getLength();
/*! <<<...
* }
* ```
* }}} */
/*** 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_delay_coeffs coeffs;
bw_delay_state states[N_CHANNELS];
bw_delay_state *statesP[N_CHANNELS];
void *mem;
};
template<size_t N_CHANNELS>
inline Delay<N_CHANNELS>::Delay(float maxDelay) {
bw_delay_init(&coeffs, maxDelay);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
mem = nullptr;
}
template<size_t N_CHANNELS>
inline Delay<N_CHANNELS>::~Delay() {
if (mem != nullptr)
operator delete(mem);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_delay_set_sample_rate(&coeffs, sampleRate);
size_t req = bw_delay_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_delay_mem_set(&coeffs, states + i, m);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::reset() {
bw_delay_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_delay_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_delay_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline float Delay<N_CHANNELS>::read(size_t channel, size_t di, float df) {
return bw_delay_read(&coeffs, states + channel, di, df);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::write(size_t channel, float x) {
bw_delay_write(&coeffs, states + channel, x);
}
template<size_t N_CHANNELS>
inline void Delay<N_CHANNELS>::setDelay(float value) {
bw_delay_set_delay(&coeffs, value);
}
template<size_t N_CHANNELS>
inline size_t Delay<N_CHANNELS>::getLength() {
return bw_delay_get_length(&coeffs);
}
}
#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_DIST_H
#define BWPP_DIST_H
#include <bw_dist.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Dist
* ```>>> */
template<size_t N_CHANNELS>
class Dist {
public:
Dist();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setDistortion(float value);
void setTone(float value);
void setVolume(float value);
/*! <<<...
* }
* ```
* }}} */
/*** Implementation ***/
/* WARNING: This part of the file is not part of the public API. Its content may
* change at any time in future versions. Please, do not use it directly. */
private:
bw_dist_coeffs coeffs;
bw_dist_state states[N_CHANNELS];
bw_dist_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Dist<N_CHANNELS>::Dist() {
bw_dist_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_dist_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::reset() {
bw_dist_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_dist_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_dist_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setDistortion(float value) {
bw_dist_set_distortion(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setTone(float value) {
bw_dist_set_tone(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Dist<N_CHANNELS>::setVolume(float value) {
bw_dist_set_volume(&coeffs, value);
}
}
#endif

View File

@ -1,107 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can redriveribute 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 driveributed 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_DRIVE_H
#define BWPP_DRIVE_H
#include <bw_drive.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Drive
* ```>>> */
template<size_t N_CHANNELS>
class Drive {
public:
Drive();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setDrive(float value);
void setTone(float value);
void setVolume(float value);
/*! <<<...
* }
* ```
* }}} */
/*** Implementation ***/
/* WARNING: This part of the file is not part of the public API. Its content may
* change at any time in future versions. Please, do not use it directly. */
private:
bw_drive_coeffs coeffs;
bw_drive_state states[N_CHANNELS];
bw_drive_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Drive<N_CHANNELS>::Drive() {
bw_drive_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_drive_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::reset() {
bw_drive_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_drive_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_drive_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setDrive(float value) {
bw_drive_set_drive(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setTone(float value) {
bw_drive_set_tone(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Drive<N_CHANNELS>::setVolume(float value) {
bw_drive_set_volume(&coeffs, value);
}
}
#endif

View File

@ -1,97 +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_DRYWET_H
#define BWPP_DRYWET_H
#include <bw_drywet.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::DryWet
* ```>>> */
template<size_t N_CHANNELS>
class DryWet {
public:
DryWet();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x_dry,
std::array<const float *, N_CHANNELS> x_wet,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setWet(float value);
void setSmoothTau(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_drywet_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline DryWet<N_CHANNELS>::DryWet() {
bw_drywet_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_drywet_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::reset() {
bw_drywet_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_dry,
std::array<const float *, N_CHANNELS> x_wet,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_drywet_process_multi(&coeffs, x_dry.data(), x_wet.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setWet(float value) {
bw_drywet_set_wet(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void DryWet<N_CHANNELS>::setSmoothTau(float value) {
bw_drywet_set_smooth_tau(&coeffs, value);
}
}
#endif