polished + bw_{phaser,pink_filt,ppm} + removed bwpps + fixed examples

This commit is contained in:
Stefano D'Angelo 2023-08-13 06:57:50 +02:00
parent f55a9a146b
commit ccc94c1b0f
12 changed files with 355 additions and 367 deletions

View File

@ -23,8 +23,8 @@
#include "platform.h" #include "platform.h"
#include <bwpp_balance.h> #include <bw_balance.h>
#include <bwpp_ppm.h> #include <bw_ppm.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -24,7 +24,7 @@
#include "platform.h" #include "platform.h"
#include <bw_pan.h> #include <bw_pan.h>
#include <bwpp_ppm.h> #include <bw_ppm.h>
using namespace Brickworks; using namespace Brickworks;

View File

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

View File

@ -30,11 +30,11 @@
#include <bw_osc_sin.h> #include <bw_osc_sin.h>
#include <bw_osc_filt.h> #include <bw_osc_filt.h>
#include <bw_noise_gen.h> #include <bw_noise_gen.h>
#include <bwpp_pink_filt.h> #include <bw_pink_filt.h>
#include <bwpp_svf.h> #include <bwpp_svf.h>
#include <bw_env_gen.h> #include <bw_env_gen.h>
#include <bw_gain.h> #include <bw_gain.h>
#include <bwpp_ppm.h> #include <bw_ppm.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -31,11 +31,11 @@
#include <bw_osc_sin.h> #include <bw_osc_sin.h>
#include <bw_osc_filt.h> #include <bw_osc_filt.h>
#include <bw_noise_gen.h> #include <bw_noise_gen.h>
#include <bwpp_pink_filt.h> #include <bw_pink_filt.h>
#include <bwpp_svf.h> #include <bwpp_svf.h>
#include <bw_env_gen.h> #include <bw_env_gen.h>
#include <bw_gain.h> #include <bw_gain.h>
#include <bwpp_ppm.h> #include <bw_ppm.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -29,7 +29,7 @@
#include <bwpp_svf.h> #include <bwpp_svf.h>
#include <bw_env_gen.h> #include <bw_env_gen.h>
#include <bw_gain.h> #include <bw_gain.h>
#include <bwpp_ppm.h> #include <bw_ppm.h>
using namespace Brickworks; using namespace Brickworks;

View File

@ -32,8 +32,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_phaser_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_phaser_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -57,8 +64,8 @@
* }}} * }}}
*/ */
#ifndef _BW_PHASER_H #ifndef BW_PHASER_H
#define _BW_PHASER_H #define BW_PHASER_H
#include <bw_common.h> #include <bw_common.h>
@ -69,13 +76,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_phaser_coeffs * #### bw_phaser_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_phaser_coeffs bw_phaser_coeffs; typedef struct bw_phaser_coeffs bw_phaser_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_phaser_state * #### bw_phaser_state
* ```>>> */ * ```>>> */
typedef struct _bw_phaser_state bw_phaser_state; typedef struct bw_phaser_state bw_phaser_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -124,7 +131,7 @@ static inline float bw_phaser_process1(const bw_phaser_coeffs *BW_RESTRICT coeff
* *
* #### bw_phaser_process() * #### bw_phaser_process()
* ```>>> */ * ```>>> */
static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the * Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffer `y`, while using and updating both * first `n_samples` of the output buffer `y`, while using and updating both
@ -132,7 +139,7 @@ static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_ph
* *
* #### bw_phaser_process_multi() * #### bw_phaser_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and * Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -182,7 +189,7 @@ static inline void bw_phaser_set_amount(bw_phaser_coeffs *BW_RESTRICT coeffs, fl
extern "C" { extern "C" {
#endif #endif
struct _bw_phaser_coeffs { struct bw_phaser_coeffs {
// Sub-components // Sub-components
bw_phase_gen_coeffs phase_gen_coeffs; bw_phase_gen_coeffs phase_gen_coeffs;
bw_phase_gen_state phase_gen_state; bw_phase_gen_state phase_gen_state;
@ -196,7 +203,7 @@ struct _bw_phaser_coeffs {
float amount; float amount;
}; };
struct _bw_phaser_state { struct bw_phaser_state {
bw_ap1_state ap1_state[4]; bw_ap1_state ap1_state[4];
}; };
@ -248,19 +255,19 @@ static inline float bw_phaser_process1(const bw_phaser_coeffs *BW_RESTRICT coeff
return x + bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[3], y); return x + bw_ap1_process1(&coeffs->ap1_coeffs, &state->ap1_state[3], y);
} }
static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_phaser_process(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_phaser_update_coeffs_ctrl(coeffs); bw_phaser_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_phaser_update_coeffs_audio(coeffs); bw_phaser_update_coeffs_audio(coeffs);
y[i] = bw_phaser_process1(coeffs, state, x[i]); y[i] = bw_phaser_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_phaser_process_multi(bw_phaser_coeffs *BW_RESTRICT coeffs, bw_phaser_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_phaser_update_coeffs_ctrl(coeffs); bw_phaser_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_phaser_update_coeffs_audio(coeffs); bw_phaser_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_phaser_process1(coeffs, state[j], x[j][i]); y[j][i] = bw_phaser_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -278,6 +285,102 @@ static inline void bw_phaser_set_amount(bw_phaser_coeffs *BW_RESTRICT coeffs, fl
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Phaser
* ```>>> */
template<size_t N_CHANNELS>
class Phaser {
public:
Phaser();
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 setCenter(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_phaser_coeffs coeffs;
bw_phaser_state states[N_CHANNELS];
bw_phaser_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Phaser<N_CHANNELS>::Phaser() {
bw_phaser_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_phaser_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset() {
bw_phaser_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phaser_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_phaser_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Phaser<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 Phaser<N_CHANNELS>::setRate(float value) {
bw_phaser_set_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setCenter(float value) {
bw_phaser_set_center(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setAmount(float value) {
bw_phaser_set_amount(&coeffs, value);
}
} }
#endif #endif

View File

@ -36,8 +36,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_pink_filt_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_pink_filt_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -78,8 +85,8 @@
* }}} * }}}
*/ */
#ifndef _BW_PINK_FILT_H #ifndef BW_PINK_FILT_H
#define _BW_PINK_FILT_H #define BW_PINK_FILT_H
#include <bw_common.h> #include <bw_common.h>
@ -90,13 +97,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_pink_filt_coeffs * #### bw_pink_filt_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_pink_filt_coeffs bw_pink_filt_coeffs; typedef struct bw_pink_filt_coeffs bw_pink_filt_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_pink_filt_state * #### bw_pink_filt_state
* ```>>> */ * ```>>> */
typedef struct _bw_pink_filt_state bw_pink_filt_state; typedef struct bw_pink_filt_state bw_pink_filt_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -133,7 +140,7 @@ static inline float bw_pink_filt_process1_scaling(const bw_pink_filt_coeffs *BW_
* *
* #### bw_pink_filt_process() * #### bw_pink_filt_process()
* ```>>> */ * ```>>> */
static inline void bw_pink_filt_process(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_pink_filt_process(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the * Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffer `y`, while using `coeffs` and * first `n_samples` of the output buffer `y`, while using `coeffs` and
@ -141,7 +148,7 @@ static inline void bw_pink_filt_process(bw_pink_filt_coeffs *BW_RESTRICT coeffs,
* *
* #### bw_pink_filt_process_multi() * #### bw_pink_filt_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_pink_filt_process_multi(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_pink_filt_process_multi(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and * Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -183,7 +190,7 @@ static inline float bw_pink_filt_get_scaling_k(const bw_pink_filt_coeffs *BW_RES
extern "C" { extern "C" {
#endif #endif
struct _bw_pink_filt_coeffs { struct bw_pink_filt_coeffs {
// Coefficients // Coefficients
float scaling_k; float scaling_k;
@ -191,7 +198,7 @@ struct _bw_pink_filt_coeffs {
float sample_rate_scaling; float sample_rate_scaling;
}; };
struct _bw_pink_filt_state { struct bw_pink_filt_state {
float s1_z1; float s1_z1;
float s2_z1; float s2_z1;
float s3_z1; float s3_z1;
@ -232,17 +239,17 @@ static inline float bw_pink_filt_process1_scaling(const bw_pink_filt_coeffs *BW_
return coeffs->scaling_k * bw_pink_filt_process1(coeffs, state, x); return coeffs->scaling_k * bw_pink_filt_process1(coeffs, state, x);
} }
static inline void bw_pink_filt_process(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state *BW_RESTRICT state, const float *x, float* y, int n_samples) { static inline void bw_pink_filt_process(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state *BW_RESTRICT state, const float *x, float* y, size_t n_samples) {
if (coeffs->sample_rate_scaling) if (coeffs->sample_rate_scaling)
for (int i = 0; i < n_samples; i++) for (size_t i = 0; i < n_samples; i++)
y[i] = bw_pink_filt_process1_scaling(coeffs, state, x[i]); y[i] = bw_pink_filt_process1_scaling(coeffs, state, x[i]);
else else
for (int i = 0; i < n_samples; i++) for (size_t i = 0; i < n_samples; i++)
y[i] = bw_pink_filt_process1(coeffs, state, x[i]); y[i] = bw_pink_filt_process1(coeffs, state, x[i]);
} }
static inline void bw_pink_filt_process_multi(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_pink_filt_process_multi(bw_pink_filt_coeffs *BW_RESTRICT coeffs, bw_pink_filt_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
for (int i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_pink_filt_process(coeffs, state[i], x[i], y[i], n_samples); bw_pink_filt_process(coeffs, state[i], x[i], y[i], n_samples);
} }
@ -255,6 +262,96 @@ static inline float bw_pink_filt_get_scaling_k(const bw_pink_filt_coeffs *BW_RES
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::PinkFilt
* ```>>> */
template<size_t N_CHANNELS>
class PinkFilt {
public:
PinkFilt();
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 setSampleRateScaling(bool value);
float getScalingK();
/*! <<<...
* }
* ```
* }}} */
/*** 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_pink_filt_coeffs coeffs;
bw_pink_filt_state states[N_CHANNELS];
bw_pink_filt_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PinkFilt<N_CHANNELS>::PinkFilt() {
bw_pink_filt_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_pink_filt_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::reset() {
for (size_t i = 0; i < N_CHANNELS; i++)
bw_pink_filt_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_pink_filt_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PinkFilt<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 PinkFilt<N_CHANNELS>::setSampleRateScaling(bool value) {
bw_pink_filt_set_sample_rate_scaling(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float PinkFilt<N_CHANNELS>::getScalingK() {
return bw_pink_filt_get_scaling_k(&coeffs);
}
} }
#endif #endif

View File

@ -32,8 +32,15 @@
* <ul> * <ul>
* <li>Version <strong>1.0.0</strong>: * <li>Version <strong>1.0.0</strong>:
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li><code>bw_ppm_process()</code> and
* <code>BW_SIZE_T</code>.</li> * <code>bw_ppm_process_multi()</code> now use <code>size_t</code>
* to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul> * </ul>
* </li> * </li>
* <li>Version <strong>0.6.0</strong>: * <li>Version <strong>0.6.0</strong>:
@ -58,8 +65,8 @@
* }}} * }}}
*/ */
#ifndef _BW_PPM_H #ifndef BW_PPM_H
#define _BW_PPM_H #define BW_PPM_H
#include <bw_common.h> #include <bw_common.h>
@ -70,13 +77,13 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_ppm_coeffs * #### bw_ppm_coeffs
* ```>>> */ * ```>>> */
typedef struct _bw_ppm_coeffs bw_ppm_coeffs; typedef struct bw_ppm_coeffs bw_ppm_coeffs;
/*! <<<``` /*! <<<```
* Coefficients and related. * Coefficients and related.
* *
* #### bw_ppm_state * #### bw_ppm_state
* ```>>> */ * ```>>> */
typedef struct _bw_ppm_state bw_ppm_state; typedef struct bw_ppm_state bw_ppm_state;
/*! <<<``` /*! <<<```
* Internal state and related. * Internal state and related.
* *
@ -125,7 +132,7 @@ static inline float bw_ppm_process1(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_
* *
* #### bw_ppm_process() * #### bw_ppm_process()
* ```>>> */ * ```>>> */
static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, int n_samples); static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the * Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffer `y`, while using and updating both * first `n_samples` of the output buffer `y`, while using and updating both
@ -137,7 +144,7 @@ static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_stat
* *
* #### bw_ppm_process_multi() * #### bw_ppm_process_multi()
* ```>>> */ * ```>>> */
static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples); static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples);
/*! <<<``` /*! <<<```
* Processes the first `n_samples` of the `n_channels` input buffers `x` and * Processes the first `n_samples` of the `n_channels` input buffers `x` and
* fills the first `n_samples` of the `n_channels` output buffers `y`, while * fills the first `n_samples` of the `n_channels` output buffers `y`, while
@ -178,12 +185,12 @@ static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state);
extern "C" { extern "C" {
#endif #endif
struct _bw_ppm_coeffs { struct bw_ppm_coeffs {
// Sub-components // Sub-components
bw_env_follow_coeffs env_follow_coeffs; bw_env_follow_coeffs env_follow_coeffs;
}; };
struct _bw_ppm_state { struct bw_ppm_state {
bw_env_follow_state env_follow_state; bw_env_follow_state env_follow_state;
float y_z1; float y_z1;
}; };
@ -221,35 +228,35 @@ static inline float bw_ppm_process1(const bw_ppm_coeffs *BW_RESTRICT coeffs, bw_
return y; return y;
} }
static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, int n_samples) { static inline void bw_ppm_process(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_ppm_update_coeffs_ctrl(coeffs); bw_ppm_update_coeffs_ctrl(coeffs);
if (y != NULL) if (y != NULL)
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ppm_update_coeffs_audio(coeffs); bw_ppm_update_coeffs_audio(coeffs);
y[i] = bw_ppm_process1(coeffs, state, x[i]); y[i] = bw_ppm_process1(coeffs, state, x[i]);
} }
else else
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ppm_update_coeffs_audio(coeffs); bw_ppm_update_coeffs_audio(coeffs);
bw_ppm_process1(coeffs, state, x[i]); bw_ppm_process1(coeffs, state, x[i]);
} }
} }
static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) { static inline void bw_ppm_process_multi(bw_ppm_coeffs *BW_RESTRICT coeffs, bw_ppm_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_ppm_update_coeffs_ctrl(coeffs); bw_ppm_update_coeffs_ctrl(coeffs);
if (y != NULL) if (y != NULL)
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ppm_update_coeffs_audio(coeffs); bw_ppm_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) { for (size_t j = 0; j < n_channels; j++) {
const float v = bw_ppm_process1(coeffs, state[j], x[j][i]); const float v = bw_ppm_process1(coeffs, state[j], x[j][i]);
if (y[j] != NULL) if (y[j] != NULL)
y[j][i] = v; y[j][i] = v;
} }
} }
else else
for (int i = 0; i < n_samples; i++) { for (size_t i = 0; i < n_samples; i++) {
bw_ppm_update_coeffs_audio(coeffs); bw_ppm_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) for (size_t j = 0; j < n_channels; j++)
bw_ppm_process1(coeffs, state[j], x[j][i]); bw_ppm_process1(coeffs, state[j], x[j][i]);
} }
} }
@ -263,6 +270,97 @@ static inline float bw_ppm_get_y_z1(const bw_ppm_state *BW_RESTRICT state) {
} }
#ifdef __cplusplus #ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::PPM
* ```>>> */
template<size_t N_CHANNELS>
class PPM {
public:
PPM();
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 setIntegrationTau(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_ppm_coeffs coeffs;
bw_ppm_state states[N_CHANNELS];
bw_ppm_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PPM<N_CHANNELS>::PPM() {
bw_ppm_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ppm_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::reset() {
bw_ppm_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ppm_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_ppm_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PPM<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 PPM<N_CHANNELS>::setIntegrationTau(float value) {
bw_ppm_set_integration_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float PPM<N_CHANNELS>::getYZ1(size_t channel) {
return bw_ppm_get_y_z1(states + channel);
}
} }
#endif #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_PHASER_H
#define BWPP_PHASER_H
#include <bw_phaser.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Phaser
* ```>>> */
template<size_t N_CHANNELS>
class Phaser {
public:
Phaser();
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 setCenter(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_phaser_coeffs coeffs;
bw_phaser_state states[N_CHANNELS];
bw_phaser_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Phaser<N_CHANNELS>::Phaser() {
bw_phaser_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_phaser_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::reset() {
bw_phaser_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phaser_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_phaser_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setRate(float value) {
bw_phaser_set_rate(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setCenter(float value) {
bw_phaser_set_center(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Phaser<N_CHANNELS>::setAmount(float value) {
bw_phaser_set_amount(&coeffs, value);
}
}
#endif

View File

@ -1,101 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can repink_filtribute 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 pink_filtributed 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_PINK_FILT_H
#define BWPP_PINK_FILT_H
#include <bw_pink_filt.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::PinkFilt
* ```>>> */
template<size_t N_CHANNELS>
class PinkFilt {
public:
PinkFilt();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setSampleRateScaling(bool value);
float getScalingK();
/*! <<<...
* }
* ```
* }}} */
/*** 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_pink_filt_coeffs coeffs;
bw_pink_filt_state states[N_CHANNELS];
bw_pink_filt_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PinkFilt<N_CHANNELS>::PinkFilt() {
bw_pink_filt_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_pink_filt_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::reset() {
for (size_t i = 0; i < N_CHANNELS; i++)
bw_pink_filt_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_pink_filt_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PinkFilt<N_CHANNELS>::setSampleRateScaling(bool value) {
bw_pink_filt_set_sample_rate_scaling(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float PinkFilt<N_CHANNELS>::getScalingK() {
return bw_pink_filt_get_scaling_k(&coeffs);
}
}
#endif

View File

@ -1,102 +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_PPM_H
#define BWPP_PPM_H
#include <bw_ppm.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::PPM
* ```>>> */
template<size_t N_CHANNELS>
class PPM {
public:
PPM();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setIntegrationTau(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_ppm_coeffs coeffs;
bw_ppm_state states[N_CHANNELS];
bw_ppm_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PPM<N_CHANNELS>::PPM() {
bw_ppm_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_ppm_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::reset() {
bw_ppm_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_ppm_reset_state(&coeffs, states + i);
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_ppm_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PPM<N_CHANNELS>::setIntegrationTau(float value) {
bw_ppm_set_integration_tau(&coeffs, value);
}
template<size_t N_CHANNELS>
inline float PPM<N_CHANNELS>::getYZ1(size_t channel) {
return bw_ppm_get_y_z1(states + channel);
}
}
#endif