polished bw_{pan,peak,phase_gen} + removed corresponding bwpp + fixed

examples
This commit is contained in:
Stefano D'Angelo 2023-08-13 06:36:35 +02:00
parent 40503b7cb1
commit f55a9a146b
12 changed files with 413 additions and 420 deletions

View File

@ -25,7 +25,7 @@
#include <bw_ls2.h>
#include <bw_hs2.h>
#include <bwpp_peak.h>
#include <bw_peak.h>
using namespace Brickworks;

View File

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

View File

@ -23,7 +23,7 @@
#include "platform.h"
#include <bwpp_phase_gen.h>
#include <bw_phase_gen.h>
#include <bw_osc_saw.h>
#include <bw_osc_pulse.h>
#include <bw_osc_tri.h>

View File

@ -24,7 +24,7 @@
#include "platform.h"
#include <bw_note_queue.h>
#include <bwpp_phase_gen.h>
#include <bw_phase_gen.h>
#include <bw_osc_saw.h>
#include <bw_osc_pulse.h>
#include <bw_osc_tri.h>

View File

@ -23,7 +23,7 @@
#include "platform.h"
#include <bwpp_phase_gen.h>
#include <bw_phase_gen.h>
#include <bw_osc_pulse.h>
#include <bw_osc_filt.h>
#include <bwpp_svf.h>

View File

@ -307,10 +307,10 @@ inline void Notch<N_CHANNELS>::setSampleRate(float sampleRate) {
}
template<size_t N_CHANNELS>
inline void Notch<N_CHANNELS>::reset(float x0) {
inline void Notch<N_CHANNELS>::reset(float x_0) {
bw_notch_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_notch_reset_state(&coeffs, states + i, x0);
bw_notch_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>

View File

@ -29,8 +29,16 @@
* <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>Now using parabolic curves instead of trigonometric ones.</li>
* <li><code>bw_pan_process()</code> and
* <code>bw_pan_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 +63,8 @@
* }}}
*/
#ifndef _BW_PAN_H
#define _BW_PAN_H
#ifndef BW_PAN_H
#define BW_PAN_H
#include <bw_common.h>
@ -67,7 +75,7 @@ extern "C" {
/*! api {{{
* #### bw_pan_coeffs
* ```>>> */
typedef struct _bw_pan_coeffs bw_pan_coeffs;
typedef struct bw_pan_coeffs bw_pan_coeffs;
/*! <<<```
* Coefficients and related.
*
@ -111,7 +119,7 @@ static inline void bw_pan_process1(const bw_pan_coeffs *BW_RESTRICT coeffs, floa
*
* #### bw_pan_process()
* ```>>> */
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, int n_samples);
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, size_t n_samples);
/*! <<<```
* Processes the first `n_samples` of the input buffer `x` and fills the
* first `n_samples` of the output buffers `y_l` (left) and `y_r` (right),
@ -119,7 +127,7 @@ static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float
*
* #### bw_pan_process_multi()
* ```>>> */
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float **x, float **y_l, float **y_r, int n_channels, int n_samples);
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float * const *x, float **y_l, float **y_r, 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_l`
@ -152,7 +160,7 @@ static inline void bw_pan_set_pan(bw_pan_coeffs *BW_RESTRICT coeffs, float value
extern "C" {
#endif
struct _bw_pan_coeffs {
struct bw_pan_coeffs {
// Sub-components
bw_gain_coeffs l_coeffs;
bw_gain_coeffs r_coeffs;
@ -173,23 +181,23 @@ static inline void bw_pan_set_sample_rate(bw_pan_coeffs *BW_RESTRICT coeffs, flo
bw_gain_set_sample_rate(&coeffs->r_coeffs, sample_rate);
}
static inline void _bw_pan_do_update_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs, char force) {
static inline void bw_pan_do_update_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs, char force) {
if (force || coeffs->pan != coeffs->pan_prev) {
const float k = 0.125f * coeffs->pan + 0.125f;
bw_gain_set_gain_lin(&coeffs->l_coeffs, bw_cos2pif(k));
bw_gain_set_gain_lin(&coeffs->r_coeffs, bw_sin2pif(k));
const float l = 0.7071067811865477f + coeffs->pan * (-0.5f + coeffs->pan * -0.20710678118654768f);
bw_gain_set_gain_lin(&coeffs->l_coeffs, l);
bw_gain_set_gain_lin(&coeffs->r_coeffs, l + coeffs->pan);
coeffs->pan_prev = coeffs->pan;
}
}
static inline void bw_pan_reset_coeffs(bw_pan_coeffs *BW_RESTRICT coeffs) {
_bw_pan_do_update_coeffs(coeffs, 1);
bw_pan_do_update_coeffs(coeffs, 1);
bw_gain_reset_coeffs(&coeffs->l_coeffs);
bw_gain_reset_coeffs(&coeffs->r_coeffs);
}
static inline void bw_pan_update_coeffs_ctrl(bw_pan_coeffs *BW_RESTRICT coeffs) {
_bw_pan_do_update_coeffs(coeffs, 0);
bw_pan_do_update_coeffs(coeffs, 0);
bw_gain_update_coeffs_ctrl(&coeffs->l_coeffs);
bw_gain_update_coeffs_ctrl(&coeffs->r_coeffs);
}
@ -204,19 +212,19 @@ static inline void bw_pan_process1(const bw_pan_coeffs *BW_RESTRICT coeffs, floa
*y_r = bw_gain_process1(&coeffs->r_coeffs, x);
}
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, int n_samples) {
static inline void bw_pan_process(bw_pan_coeffs *BW_RESTRICT coeffs, const float *x, float *y_l, float *y_r, size_t n_samples) {
bw_pan_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_pan_update_coeffs_audio(coeffs);
bw_pan_process1(coeffs, x[i], y_l + i, y_r + i);
}
}
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float **x, float **y_l, float **y_r, int n_channels, int n_samples) {
static inline void bw_pan_process_multi(bw_pan_coeffs *BW_RESTRICT coeffs, const float * const *x, float **y_l, float **y_r, size_t n_channels, size_t n_samples) {
bw_pan_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_pan_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++)
for (size_t j = 0; j < n_channels; j++)
bw_pan_process1(coeffs, x[j][i], y_l[j] + i, y_r[j] + i);
}
}
@ -226,6 +234,88 @@ static inline void bw_pan_set_pan(bw_pan_coeffs *BW_RESTRICT coeffs, float value
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Pan
* ```>>> */
template<size_t N_CHANNELS>
class Pan {
public:
Pan();
void setSampleRate(float sampleRate);
void reset();
void process(
const float * const *x,
float **y_l,
float **y_r,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
size_t nSamples);
void setPan(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_pan_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline Pan<N_CHANNELS>::Pan() {
bw_pan_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_pan_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::reset() {
bw_pan_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::process(
const float * const *x,
float **y_l,
float **y_r,
size_t nSamples) {
bw_pan_process_multi(&coeffs, x, y_l, y_r, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
size_t nSamples) {
process(x.data(), y_l.data(), y_r.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::setPan(float value) {
bw_pan_set_pan(&coeffs, value);
}
}
#endif

View File

@ -37,8 +37,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_peak_process()</code> and
* <code>bw_peak_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>:
@ -69,8 +76,8 @@
* }}}
*/
#ifndef _BW_PEAK_H
#define _BW_PEAK_H
#ifndef BW_PEAK_H
#define BW_PEAK_H
#include <bw_common.h>
@ -81,13 +88,13 @@ extern "C" {
/*! api {{{
* #### bw_peak_coeffs
* ```>>> */
typedef struct _bw_peak_coeffs bw_peak_coeffs;
typedef struct bw_peak_coeffs bw_peak_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_peak_state
* ```>>> */
typedef struct _bw_peak_state bw_peak_state;
typedef struct bw_peak_state bw_peak_state;
/*! <<<```
* Internal state and related.
*
@ -111,10 +118,10 @@ static inline void bw_peak_reset_coeffs(bw_peak_coeffs *BW_RESTRICT coeffs);
*
* #### bw_peak_reset_state()
* ```>>> */
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x0);
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x_0);
/*! <<<```
* Resets the given `state` to its initial values using the given `coeffs`
* and the quiescent/initial input value `x0`.
* and the quiescent/initial input value `x_0`.
*
* #### bw_peak_update_coeffs_ctrl()
* ```>>> */
@ -137,7 +144,7 @@ static inline float bw_peak_process1(const bw_peak_coeffs *BW_RESTRICT coeffs, b
*
* #### bw_peak_process()
* ```>>> */
static inline void bw_peak_process(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
static inline void bw_peak_process(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_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
@ -145,7 +152,7 @@ static inline void bw_peak_process(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_s
*
* #### bw_peak_process_multi()
* ```>>> */
static inline void bw_peak_process_multi(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
static inline void bw_peak_process_multi(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_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
@ -221,7 +228,7 @@ static inline void bw_peak_set_use_bandwidth(bw_peak_coeffs *BW_RESTRICT coeffs,
extern "C" {
#endif
struct _bw_peak_coeffs {
struct bw_peak_coeffs {
// Sub-components
bw_mm2_coeffs mm2_coeffs;
@ -236,13 +243,13 @@ struct _bw_peak_coeffs {
int param_changed;
};
struct _bw_peak_state {
struct bw_peak_state {
bw_mm2_state mm2_state;
};
#define _BW_PEAK_PARAM_PEAK_GAIN 1
#define _BW_PEAK_PARAM_Q (1<<1)
#define _BW_PEAK_PARAM_BANDWIDTH (1<<2)
#define BW_PEAK_PARAM_PEAK_GAIN 1
#define BW_PEAK_PARAM_Q (1<<1)
#define BW_PEAK_PARAM_BANDWIDTH (1<<2)
static inline void bw_peak_init(bw_peak_coeffs *BW_RESTRICT coeffs) {
bw_mm2_init(&coeffs->mm2_coeffs);
@ -256,19 +263,19 @@ static inline void bw_peak_set_sample_rate(bw_peak_coeffs *BW_RESTRICT coeffs, f
bw_mm2_set_sample_rate(&coeffs->mm2_coeffs, sample_rate);
}
static inline void _bw_peak_update_mm2_params(bw_peak_coeffs *BW_RESTRICT coeffs) {
static inline void bw_peak_update_mm2_params(bw_peak_coeffs *BW_RESTRICT coeffs) {
if (coeffs->param_changed) {
if (coeffs->use_bandwidth) {
if (coeffs->param_changed & (_BW_PEAK_PARAM_PEAK_GAIN | _BW_PEAK_PARAM_BANDWIDTH)) {
if (coeffs->param_changed & _BW_PEAK_PARAM_BANDWIDTH)
if (coeffs->param_changed & (BW_PEAK_PARAM_PEAK_GAIN | BW_PEAK_PARAM_BANDWIDTH)) {
if (coeffs->param_changed & BW_PEAK_PARAM_BANDWIDTH)
coeffs->bw_k = bw_pow2f(coeffs->bandwidth);
const float Q = bw_sqrtf(coeffs->bw_k * coeffs->peak_gain) * bw_rcpf(coeffs->bw_k - 1.f);
bw_mm2_set_Q(&coeffs->mm2_coeffs, Q);
bw_mm2_set_coeff_bp(&coeffs->mm2_coeffs, (coeffs->peak_gain - 1.f) * bw_rcpf(Q));
}
} else {
if (coeffs->param_changed & (_BW_PEAK_PARAM_PEAK_GAIN | _BW_PEAK_PARAM_Q)) {
if (coeffs->param_changed & _BW_PEAK_PARAM_Q)
if (coeffs->param_changed & (BW_PEAK_PARAM_PEAK_GAIN | BW_PEAK_PARAM_Q)) {
if (coeffs->param_changed & BW_PEAK_PARAM_Q)
bw_mm2_set_Q(&coeffs->mm2_coeffs, coeffs->Q);
bw_mm2_set_coeff_bp(&coeffs->mm2_coeffs, (coeffs->peak_gain - 1.f) * bw_rcpf(coeffs->Q));
}
@ -279,16 +286,16 @@ static inline void _bw_peak_update_mm2_params(bw_peak_coeffs *BW_RESTRICT coeffs
static inline void bw_peak_reset_coeffs(bw_peak_coeffs *BW_RESTRICT coeffs) {
coeffs->param_changed = ~0;
_bw_peak_update_mm2_params(coeffs);
bw_peak_update_mm2_params(coeffs);
bw_mm2_reset_coeffs(&coeffs->mm2_coeffs);
}
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x0);
static inline void bw_peak_reset_state(const bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, float x_0) {
bw_mm2_reset_state(&coeffs->mm2_coeffs, &state->mm2_state, x_0);
}
static inline void bw_peak_update_coeffs_ctrl(bw_peak_coeffs *BW_RESTRICT coeffs) {
_bw_peak_update_mm2_params(coeffs);
bw_peak_update_mm2_params(coeffs);
bw_mm2_update_coeffs_ctrl(&coeffs->mm2_coeffs);
}
@ -300,19 +307,19 @@ static inline float bw_peak_process1(const bw_peak_coeffs *BW_RESTRICT coeffs, b
return bw_mm2_process1(&coeffs->mm2_coeffs, &state->mm2_state, x);
}
static inline void bw_peak_process(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
static inline void bw_peak_process(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
bw_peak_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_peak_update_coeffs_audio(coeffs);
y[i] = bw_peak_process1(coeffs, state, x[i]);
}
}
static inline void bw_peak_process_multi(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
static inline void bw_peak_process_multi(bw_peak_coeffs *BW_RESTRICT coeffs, bw_peak_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
bw_peak_update_coeffs_ctrl(coeffs);
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_peak_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_peak_process1(coeffs, state[j], x[j][i]);
}
}
@ -324,14 +331,14 @@ static inline void bw_peak_set_cutoff(bw_peak_coeffs *BW_RESTRICT coeffs, float
static inline void bw_peak_set_Q(bw_peak_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->Q != value) {
coeffs->Q = value;
coeffs->param_changed |= _BW_PEAK_PARAM_Q;
coeffs->param_changed |= BW_PEAK_PARAM_Q;
}
}
static inline void bw_peak_set_peak_gain_lin(bw_peak_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->peak_gain != value) {
coeffs->peak_gain = value;
coeffs->param_changed |= _BW_PEAK_PARAM_PEAK_GAIN;
coeffs->param_changed |= BW_PEAK_PARAM_PEAK_GAIN;
}
}
@ -342,22 +349,136 @@ static inline void bw_peak_set_peak_gain_dB(bw_peak_coeffs *BW_RESTRICT coeffs,
static inline void bw_peak_set_bandwidth(bw_peak_coeffs *BW_RESTRICT coeffs, float value) {
if (coeffs->bandwidth != value) {
coeffs->bandwidth = value;
coeffs->param_changed |= _BW_PEAK_PARAM_BANDWIDTH;
coeffs->param_changed |= BW_PEAK_PARAM_BANDWIDTH;
}
}
static inline void bw_peak_set_use_bandwidth(bw_peak_coeffs *BW_RESTRICT coeffs, char value) {
if ((coeffs->use_bandwidth && !value) || (!coeffs->use_bandwidth && value)) {
coeffs->use_bandwidth = value;
coeffs->param_changed |= _BW_PEAK_PARAM_Q | _BW_PEAK_PARAM_BANDWIDTH;
coeffs->param_changed |= BW_PEAK_PARAM_Q | BW_PEAK_PARAM_BANDWIDTH;
}
}
#undef _BW_PEAK_PARAM_PEAK_GAIN
#undef _BW_PEAK_PARAM_Q
#undef _BW_PEAK_PARAM_BANDWIDTH
#undef BW_PEAK_PARAM_PEAK_GAIN
#undef BW_PEAK_PARAM_Q
#undef BW_PEAK_PARAM_BANDWIDTH
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::Peak
* ```>>> */
template<size_t N_CHANNELS>
class Peak {
public:
Peak();
void setSampleRate(float sampleRate);
void reset(float x_0 = 0.f);
void process(
const float * const *x,
float **y,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
void setCutoff(float value);
void setQ(float value);
void setPeakGainLin(float value);
void setPeakGainDB(float value);
void setBandwidth(float value);
void setUseBandwidth(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_peak_coeffs coeffs;
bw_peak_state states[N_CHANNELS];
bw_peak_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Peak<N_CHANNELS>::Peak() {
bw_peak_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_peak_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::reset(float x_0) {
bw_peak_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_peak_reset_state(&coeffs, states + i, x_0);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::process(
const float * const *x,
float **y,
size_t nSamples) {
bw_peak_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Peak<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 Peak<N_CHANNELS>::setCutoff(float value) {
bw_peak_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setQ(float value) {
bw_peak_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setPeakGainLin(float value) {
bw_peak_set_peak_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setPeakGainDB(float value) {
bw_peak_set_peak_gain_dB(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setBandwidth(float value) {
bw_peak_set_bandwidth(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setUseBandwidth(bool value) {
bw_peak_set_use_bandwidth(&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_phase_gen_process()</code> and
* <code>bw_phase_gen_process_multi()</code> now use
* <code>size_t</code> to count samples and channels.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li>
* <li>Added overladed C++ <code>process()</code> function taking
* C-style arrays as arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -71,8 +78,8 @@
* }}}
*/
#ifndef _BW_PHASE_GEN_H
#define _BW_PHASE_GEN_H
#ifndef BW_PHASE_GEN_H
#define BW_PHASE_GEN_H
#include <bw_common.h>
@ -83,13 +90,13 @@ extern "C" {
/*! api {{{
* #### bw_phase_gen_coeffs
* ```>>> */
typedef struct _bw_phase_gen_coeffs bw_phase_gen_coeffs;
typedef struct bw_phase_gen_coeffs bw_phase_gen_coeffs;
/*! <<<```
* Coefficients and related.
*
* #### bw_phase_gen_state
* ```>>> */
typedef struct _bw_phase_gen_state bw_phase_gen_state;
typedef struct bw_phase_gen_state bw_phase_gen_state;
/*! <<<```
* Internal state and related.
*
@ -146,7 +153,7 @@ static inline void bw_phase_gen_process1_mod(const bw_phase_gen_coeffs *BW_RESTR
*
* #### bw_phase_gen_process()
* ```>>> */
static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state *BW_RESTRICT state, const float *x_mod, float *y, float *y_phase_inc, int n_samples);
static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state *BW_RESTRICT state, const float *x_mod, float *y, float *y_phase_inc, size_t n_samples);
/*! <<<```
* Generates and fills the first `n_samples` of the output buffer `y`, while
* using and updating both `coeffs` and `state` (control and audio rate).
@ -158,7 +165,7 @@ static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs,
*
* #### bw_phase_gen_process_multi()
* ```>>> */
static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state **BW_RESTRICT state, const float **x_mod, float **y, float **y_phase_inc, int n_channels, int n_samples);
static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state * const *BW_RESTRICT state, const float * const *x_mod, float **y, float **y_phase_inc, size_t n_channels, size_t n_samples);
/*! <<<```
* Generates and fills the first `n_samples` of the `n_channels` output
* buffers `y`, while using and updating both the common `coeffs` and each of
@ -204,7 +211,7 @@ static inline void bw_phase_gen_set_portamento_tau(bw_phase_gen_coeffs *BW_RESTR
extern "C" {
#endif
struct _bw_phase_gen_coeffs {
struct bw_phase_gen_coeffs {
// Sub-components
bw_one_pole_coeffs portamento_coeffs;
bw_one_pole_state portamento_state;
@ -219,7 +226,7 @@ struct _bw_phase_gen_coeffs {
float frequency_prev;
};
struct _bw_phase_gen_state {
struct bw_phase_gen_state {
float phase;
};
@ -233,7 +240,7 @@ static inline void bw_phase_gen_set_sample_rate(bw_phase_gen_coeffs *BW_RESTRICT
coeffs->T = 1.f / sample_rate;
}
static inline void _bw_phase_gen_do_update_coeffs_ctrl(bw_phase_gen_coeffs *BW_RESTRICT coeffs, char force) {
static inline void bw_phase_gen_do_update_coeffs_ctrl(bw_phase_gen_coeffs *BW_RESTRICT coeffs, char force) {
bw_one_pole_update_coeffs_ctrl(&coeffs->portamento_coeffs);
if (force || coeffs->frequency != coeffs->frequency_prev) {
coeffs->portamento_target = coeffs->T * coeffs->frequency;
@ -242,7 +249,7 @@ static inline void _bw_phase_gen_do_update_coeffs_ctrl(bw_phase_gen_coeffs *BW_R
}
static inline void bw_phase_gen_reset_coeffs(bw_phase_gen_coeffs *BW_RESTRICT coeffs) {
_bw_phase_gen_do_update_coeffs_ctrl(coeffs, 1);
bw_phase_gen_do_update_coeffs_ctrl(coeffs, 1);
bw_one_pole_reset_coeffs(&coeffs->portamento_coeffs);
bw_one_pole_reset_state(&coeffs->portamento_coeffs, &coeffs->portamento_state, coeffs->portamento_target);
}
@ -253,7 +260,7 @@ static inline void bw_phase_gen_reset_state(const bw_phase_gen_coeffs *BW_RESTRI
}
static inline void bw_phase_gen_update_coeffs_ctrl(bw_phase_gen_coeffs *BW_RESTRICT coeffs) {
_bw_phase_gen_do_update_coeffs_ctrl(coeffs, 0);
bw_phase_gen_do_update_coeffs_ctrl(coeffs, 0);
}
static inline void bw_phase_gen_update_coeffs_audio(bw_phase_gen_coeffs *BW_RESTRICT coeffs) {
@ -276,29 +283,29 @@ static inline void bw_phase_gen_process1_mod(const bw_phase_gen_coeffs *BW_RESTR
*y = _bw_phase_gen_update_phase(state, *y_phase_inc);
}
static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state *BW_RESTRICT state, const float *x_mod, float* y, float *y_phase_inc, int n_samples) {
static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state *BW_RESTRICT state, const float *x_mod, float* y, float *y_phase_inc, size_t n_samples) {
bw_phase_gen_update_coeffs_ctrl(coeffs);
if (y != NULL) {
if (x_mod != NULL) {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
bw_phase_gen_process1_mod(coeffs, state, x_mod[i], y + i, y_phase_inc + i);
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v_phase_inc;
bw_phase_gen_process1_mod(coeffs, state, x_mod[i], y + i, &v_phase_inc);
}
} else {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
bw_phase_gen_process1(coeffs, state, y + i, y_phase_inc + i);
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v_phase_inc;
bw_phase_gen_process1(coeffs, state, y + i, &v_phase_inc);
@ -307,26 +314,26 @@ static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs,
} else {
if (x_mod != NULL) {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v;
bw_phase_gen_process1_mod(coeffs, state, x_mod[i], &v, y_phase_inc + i);
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v, v_phase_inc;
bw_phase_gen_process1_mod(coeffs, state, x_mod[i], &v, &v_phase_inc);
}
} else {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v;
bw_phase_gen_process1(coeffs, state, &v, y_phase_inc + i);
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
float v, v_phase_inc;
bw_phase_gen_process1(coeffs, state, &v, &v_phase_inc);
@ -335,14 +342,14 @@ static inline void bw_phase_gen_process(bw_phase_gen_coeffs *BW_RESTRICT coeffs,
}
}
static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state **BW_RESTRICT state, const float **x_mod, float **y, float **y_phase_inc, int n_channels, int n_samples) {
static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT coeffs, bw_phase_gen_state * const *BW_RESTRICT state, const float * const *x_mod, float **y, float **y_phase_inc, size_t n_channels, size_t n_samples) {
bw_phase_gen_update_coeffs_ctrl(coeffs);
if (y != NULL) {
if (x_mod != NULL) {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
if (x_mod[j])
bw_phase_gen_process1_mod(coeffs, state[j], x_mod[j][i], &v, &v_phase_inc);
@ -355,9 +362,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
if (x_mod[j])
bw_phase_gen_process1_mod(coeffs, state[j], x_mod[j][i], &v, &v_phase_inc);
@ -369,9 +376,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
} else {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
bw_phase_gen_process1(coeffs, state[j], &v, &v_phase_inc);
if (y[j])
@ -381,9 +388,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
bw_phase_gen_process1(coeffs, state[j], &v, &v_phase_inc);
if (y[j])
@ -394,9 +401,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
} else {
if (x_mod != NULL) {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
if (x_mod[j])
bw_phase_gen_process1_mod(coeffs, state[j], x_mod[j][i], &v, &v_phase_inc);
@ -407,9 +414,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
if (x_mod[j])
bw_phase_gen_process1_mod(coeffs, state[j], x_mod[j][i], &v, &v_phase_inc);
@ -419,9 +426,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
} else {
if (y_phase_inc != NULL)
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
bw_phase_gen_process1(coeffs, state[j], &v, &v_phase_inc);
if (y_phase_inc[j])
@ -429,9 +436,9 @@ static inline void bw_phase_gen_process_multi(bw_phase_gen_coeffs *BW_RESTRICT c
}
}
else
for (int i = 0; i < n_samples; i++) {
for (size_t i = 0; i < n_samples; i++) {
bw_phase_gen_update_coeffs_audio(coeffs);
for (int j = 0; j < n_channels; j++) {
for (size_t j = 0; j < n_channels; j++) {
float v, v_phase_inc;
bw_phase_gen_process1(coeffs, state[j], &v, &v_phase_inc);
}
@ -449,6 +456,100 @@ static inline void bw_phase_gen_set_portamento_tau(bw_phase_gen_coeffs *BW_RESTR
}
#ifdef __cplusplus
}
#include <array>
namespace Brickworks {
/*** Public C++ API ***/
/*! api_cpp {{{
* ##### Brickworks::PhaseGen
* ```>>> */
template<size_t N_CHANNELS>
class PhaseGen {
public:
PhaseGen();
void setSampleRate(float sampleRate);
void reset(float phase_0 = 0.f);
void process(
const float * const *x_mod,
float **y,
float **y_phase_inc,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
size_t nSamples);
void setFrequency(float value);
void setPortamentoTau(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_phase_gen_coeffs coeffs;
bw_phase_gen_state states[N_CHANNELS];
bw_phase_gen_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PhaseGen<N_CHANNELS>::PhaseGen() {
bw_phase_gen_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_phase_gen_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::reset(float phase_0) {
bw_phase_gen_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phase_gen_reset_state(&coeffs, states + i, phase_0);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::process(
const float * const *x_mod,
float **y,
float **y_phase_inc,
size_t nSamples) {
bw_phase_gen_process_multi(&coeffs, statesP, x_mod, y, y_phase_inc, N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
size_t nSamples) {
process(x_mod.data(), y.data(), y_phase_inc.data(), nSamples);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setFrequency(float value) {
bw_phase_gen_set_frequency(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setPortamentoTau(float value) {
bw_phase_gen_set_portamento_tau(&coeffs, value);
}
}
#endif

View File

@ -1,91 +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_PAN_H
#define BWPP_PAN_H
#include <bw_pan.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Pan
* ```>>> */
template<size_t N_CHANNELS>
class Pan {
public:
Pan();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
int nSamples);
void setPan(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_pan_coeffs coeffs;
};
template<size_t N_CHANNELS>
inline Pan<N_CHANNELS>::Pan() {
bw_pan_init(&coeffs);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_pan_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::reset() {
bw_pan_reset_coeffs(&coeffs);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y_l,
std::array<float *, N_CHANNELS> y_r,
int nSamples) {
bw_pan_process_multi(&coeffs, x.data(), y_l.data(), y_r.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Pan<N_CHANNELS>::setPan(float value) {
bw_pan_set_pan(&coeffs, value);
}
}
#endif

View File

@ -1,125 +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_PEAK_H
#define BWPP_PEAK_H
#include <bw_peak.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::Peak
* ```>>> */
template<size_t N_CHANNELS>
class Peak {
public:
Peak();
void setSampleRate(float sampleRate);
void reset(float x0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setCutoff(float value);
void setQ(float value);
void setPeakGainLin(float value);
void setPeakGainDB(float value);
void setBandwidth(float value);
void setUseBandwidth(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_peak_coeffs coeffs;
bw_peak_state states[N_CHANNELS];
bw_peak_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline Peak<N_CHANNELS>::Peak() {
bw_peak_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_peak_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::reset(float x0) {
bw_peak_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_peak_reset_state(&coeffs, states + i, x0);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_peak_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setCutoff(float value) {
bw_peak_set_cutoff(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setQ(float value) {
bw_peak_set_Q(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setPeakGainLin(float value) {
bw_peak_set_peak_gain_lin(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setPeakGainDB(float value) {
bw_peak_set_peak_gain_dB(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setBandwidth(float value) {
bw_peak_set_bandwidth(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void Peak<N_CHANNELS>::setUseBandwidth(bool value) {
bw_peak_set_use_bandwidth(&coeffs, value);
}
}
#endif

View File

@ -1,103 +0,0 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can rephase_genribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is phase_genributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_PHASE_GEN_H
#define BWPP_PHASE_GEN_H
#include <bw_phase_gen.h>
#include <array>
namespace Brickworks {
/*! api {{{
* ##### Brickworks::PhaseGen
* ```>>> */
template<size_t N_CHANNELS>
class PhaseGen {
public:
PhaseGen();
void setSampleRate(float sampleRate);
void reset(float phase_0 = 0.f);
void process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
int nSamples);
void setFrequency(float value);
void setPortamentoTau(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_phase_gen_coeffs coeffs;
bw_phase_gen_state states[N_CHANNELS];
bw_phase_gen_state *statesP[N_CHANNELS];
};
template<size_t N_CHANNELS>
inline PhaseGen<N_CHANNELS>::PhaseGen() {
bw_phase_gen_init(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_phase_gen_set_sample_rate(&coeffs, sampleRate);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::reset(float phase_0) {
bw_phase_gen_reset_coeffs(&coeffs);
for (size_t i = 0; i < N_CHANNELS; i++)
bw_phase_gen_reset_state(&coeffs, states + i, phase_0);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
int nSamples) {
bw_phase_gen_process_multi(&coeffs, statesP, x_mod.data(), y.data(), y_phase_inc.data(), N_CHANNELS, nSamples);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setFrequency(float value) {
bw_phase_gen_set_frequency(&coeffs, value);
}
template<size_t N_CHANNELS>
inline void PhaseGen<N_CHANNELS>::setPortamentoTau(float value) {
bw_phase_gen_set_portamento_tau(&coeffs, value);
}
}
#endif