polished bw_{chorus,clip} + removed bwpp_{chorus,clip} + fixed doc typos
in bw_{balance,bd_reduce} + fixed examples
This commit is contained in:
parent
7a2630951f
commit
ac7d49028b
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#include <bwpp_chorus.h>
|
#include <bw_chorus.h>
|
||||||
|
|
||||||
using namespace Brickworks;
|
using namespace Brickworks;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#include <bwpp_clip.h>
|
#include <bw_clip.h>
|
||||||
#include <bwpp_src_int.h>
|
#include <bwpp_src_int.h>
|
||||||
|
|
||||||
using namespace Brickworks;
|
using namespace Brickworks;
|
||||||
|
@ -242,7 +242,7 @@ namespace Brickworks {
|
|||||||
|
|
||||||
/*** Public C++ API ***/
|
/*** Public C++ API ***/
|
||||||
|
|
||||||
/*! api {{{
|
/*! api_cpp {{{
|
||||||
* ##### Brickworks::Balance
|
* ##### Brickworks::Balance
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
|
@ -219,7 +219,7 @@ namespace Brickworks {
|
|||||||
|
|
||||||
/*** Public C++ API ***/
|
/*** Public C++ API ***/
|
||||||
|
|
||||||
/*! api {{{
|
/*! api_cpp {{{
|
||||||
* ##### Brickworks::BDReduce
|
* ##### Brickworks::BDReduce
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
template<size_t N_CHANNELS>
|
template<size_t N_CHANNELS>
|
||||||
|
@ -40,6 +40,15 @@
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>Now using <code>size_t</code> instead of
|
* <li>Now using <code>size_t</code> instead of
|
||||||
* <code>BW_SIZE_T</code>.</li>
|
* <code>BW_SIZE_T</code>.</li>
|
||||||
|
* <li><code>bw_chorus_process()</code> and
|
||||||
|
* <code>bw_chorus_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>:
|
||||||
@ -64,8 +73,8 @@
|
|||||||
* }}}
|
* }}}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BW_CHORUS_H
|
#ifndef BW_CHORUS_H
|
||||||
#define _BW_CHORUS_H
|
#define BW_CHORUS_H
|
||||||
|
|
||||||
#include <bw_common.h>
|
#include <bw_common.h>
|
||||||
|
|
||||||
@ -76,13 +85,13 @@ extern "C" {
|
|||||||
/*! api {{{
|
/*! api {{{
|
||||||
* #### bw_chorus_coeffs
|
* #### bw_chorus_coeffs
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
typedef struct _bw_chorus_coeffs bw_chorus_coeffs;
|
typedef struct bw_chorus_coeffs bw_chorus_coeffs;
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Coefficients and related.
|
* Coefficients and related.
|
||||||
*
|
*
|
||||||
* #### bw_chorus_state
|
* #### bw_chorus_state
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
typedef struct _bw_chorus_state bw_chorus_state;
|
typedef struct bw_chorus_state bw_chorus_state;
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Internal state and related.
|
* Internal state and related.
|
||||||
*
|
*
|
||||||
@ -145,7 +154,7 @@ static inline float bw_chorus_process1(const bw_chorus_coeffs *BW_RESTRICT coeff
|
|||||||
*
|
*
|
||||||
* #### bw_chorus_process()
|
* #### bw_chorus_process()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_chorus_process(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
|
static inline void bw_chorus_process(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_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
|
||||||
@ -153,7 +162,7 @@ static inline void bw_chorus_process(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_ch
|
|||||||
*
|
*
|
||||||
* #### bw_chorus_process_multi()
|
* #### bw_chorus_process_multi()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_chorus_process_multi(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
|
static inline void bw_chorus_process_multi(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_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
|
||||||
@ -226,7 +235,7 @@ static inline void bw_chorus_set_coeff_fb(bw_chorus_coeffs *BW_RESTRICT coeffs,
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _bw_chorus_coeffs {
|
struct bw_chorus_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;
|
||||||
@ -237,7 +246,7 @@ struct _bw_chorus_coeffs {
|
|||||||
float amount;
|
float amount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _bw_chorus_state {
|
struct bw_chorus_state {
|
||||||
// Sub-components
|
// Sub-components
|
||||||
bw_comb_state comb_state;
|
bw_comb_state comb_state;
|
||||||
};
|
};
|
||||||
@ -293,19 +302,19 @@ static inline float bw_chorus_process1(const bw_chorus_coeffs *BW_RESTRICT coeff
|
|||||||
return bw_comb_process1(&coeffs->comb_coeffs, &state->comb_state, x);
|
return bw_comb_process1(&coeffs->comb_coeffs, &state->comb_state, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_chorus_process(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
|
static inline void bw_chorus_process(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
|
||||||
bw_chorus_update_coeffs_ctrl(coeffs);
|
bw_chorus_update_coeffs_ctrl(coeffs);
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_chorus_update_coeffs_audio(coeffs);
|
bw_chorus_update_coeffs_audio(coeffs);
|
||||||
y[i] = bw_chorus_process1(coeffs, state, x[i]);
|
y[i] = bw_chorus_process1(coeffs, state, x[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_chorus_process_multi(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
|
static inline void bw_chorus_process_multi(bw_chorus_coeffs *BW_RESTRICT coeffs, bw_chorus_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
|
||||||
bw_chorus_update_coeffs_ctrl(coeffs);
|
bw_chorus_update_coeffs_ctrl(coeffs);
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_chorus_update_coeffs_audio(coeffs);
|
bw_chorus_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_chorus_process1(coeffs, state[j], x[j][i]);
|
y[j][i] = bw_chorus_process1(coeffs, state[j], x[j][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,6 +345,136 @@ static inline void bw_chorus_set_coeff_fb(bw_chorus_coeffs *BW_RESTRICT coeffs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
namespace Brickworks {
|
||||||
|
|
||||||
|
/*** Public C++ API ***/
|
||||||
|
|
||||||
|
/*! api_cpp {{{
|
||||||
|
* ##### Brickworks::Chorus
|
||||||
|
* ```>>> */
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
class Chorus {
|
||||||
|
public:
|
||||||
|
Chorus(float maxDelay = 0.01f);
|
||||||
|
~Chorus();
|
||||||
|
|
||||||
|
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 setDelay(float value);
|
||||||
|
void setAmount(float value);
|
||||||
|
void setCoeffX(float value);
|
||||||
|
void setCoeffMod(float value);
|
||||||
|
void setCoeffFB(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_chorus_coeffs coeffs;
|
||||||
|
bw_chorus_state states[N_CHANNELS];
|
||||||
|
bw_chorus_state *statesP[N_CHANNELS];
|
||||||
|
void *mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline Chorus<N_CHANNELS>::Chorus(float maxDelay) {
|
||||||
|
bw_chorus_init(&coeffs, maxDelay);
|
||||||
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
statesP[i] = states + i;
|
||||||
|
mem = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline Chorus<N_CHANNELS>::~Chorus() {
|
||||||
|
if (mem != nullptr)
|
||||||
|
operator delete(mem);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setSampleRate(float sampleRate) {
|
||||||
|
bw_chorus_set_sample_rate(&coeffs, sampleRate);
|
||||||
|
size_t req = bw_chorus_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_chorus_mem_set(&coeffs, states + i, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::reset() {
|
||||||
|
bw_chorus_reset_coeffs(&coeffs);
|
||||||
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
bw_chorus_reset_state(&coeffs, states + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::process(
|
||||||
|
const float * const *x,
|
||||||
|
float **y,
|
||||||
|
size_t nSamples) {
|
||||||
|
bw_chorus_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<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 Chorus<N_CHANNELS>::setRate(float value) {
|
||||||
|
bw_chorus_set_rate(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setDelay(float value) {
|
||||||
|
bw_chorus_set_delay(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setAmount(float value) {
|
||||||
|
bw_chorus_set_amount(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setCoeffX(float value) {
|
||||||
|
bw_chorus_set_coeff_x(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setCoeffMod(float value) {
|
||||||
|
bw_chorus_set_coeff_mod(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Chorus<N_CHANNELS>::setCoeffFB(float value) {
|
||||||
|
bw_chorus_set_coeff_fb(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -40,8 +40,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_chorus_process()</code> and
|
||||||
* <code>BW_SIZE_T</code>.</li>
|
* <code>bw_chorus_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_CLIP_H
|
#ifndef BW_CLIP_H
|
||||||
#define _BW_CLIP_H
|
#define BW_CLIP_H
|
||||||
|
|
||||||
#include <bw_common.h>
|
#include <bw_common.h>
|
||||||
|
|
||||||
@ -70,13 +77,13 @@ extern "C" {
|
|||||||
/*! api {{{
|
/*! api {{{
|
||||||
* #### bw_clip_coeffs
|
* #### bw_clip_coeffs
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
typedef struct _bw_clip_coeffs bw_clip_coeffs;
|
typedef struct bw_clip_coeffs bw_clip_coeffs;
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Coefficients and related.
|
* Coefficients and related.
|
||||||
*
|
*
|
||||||
* #### bw_clip_state
|
* #### bw_clip_state
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
typedef struct _bw_clip_state bw_clip_state;
|
typedef struct bw_clip_state bw_clip_state;
|
||||||
/*! <<<```
|
/*! <<<```
|
||||||
* Internal state and related.
|
* Internal state and related.
|
||||||
*
|
*
|
||||||
@ -130,7 +137,7 @@ static inline float bw_clip_process1_comp(const bw_clip_coeffs *BW_RESTRICT coef
|
|||||||
*
|
*
|
||||||
* #### bw_clip_process()
|
* #### bw_clip_process()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_clip_process(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state, const float *x, float *y, int n_samples);
|
static inline void bw_clip_process(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_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
|
||||||
@ -138,7 +145,7 @@ static inline void bw_clip_process(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_s
|
|||||||
*
|
*
|
||||||
* #### bw_clip_process_multi()
|
* #### bw_clip_process_multi()
|
||||||
* ```>>> */
|
* ```>>> */
|
||||||
static inline void bw_clip_process_multi(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples);
|
static inline void bw_clip_process_multi(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_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
|
||||||
@ -189,7 +196,7 @@ static inline void bw_clip_set_gain_compensation(bw_clip_coeffs *BW_RESTRICT coe
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _bw_clip_coeffs {
|
struct bw_clip_coeffs {
|
||||||
// Sub-components
|
// Sub-components
|
||||||
bw_one_pole_coeffs smooth_coeffs;
|
bw_one_pole_coeffs smooth_coeffs;
|
||||||
bw_one_pole_state smooth_bias_state;
|
bw_one_pole_state smooth_bias_state;
|
||||||
@ -205,7 +212,7 @@ struct _bw_clip_coeffs {
|
|||||||
char gain_compensation;
|
char gain_compensation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _bw_clip_state {
|
struct bw_clip_state {
|
||||||
float x_z1;
|
float x_z1;
|
||||||
float F_z1;
|
float F_z1;
|
||||||
};
|
};
|
||||||
@ -224,7 +231,7 @@ static inline void bw_clip_set_sample_rate(bw_clip_coeffs *BW_RESTRICT coeffs, f
|
|||||||
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
|
bw_one_pole_reset_coeffs(&coeffs->smooth_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void _bw_clip_do_update_coeffs(bw_clip_coeffs *BW_RESTRICT coeffs, char force) {
|
static inline void bw_clip_do_update_coeffs(bw_clip_coeffs *BW_RESTRICT coeffs, char force) {
|
||||||
float bias_cur = bw_one_pole_get_y_z1(&coeffs->smooth_bias_state);
|
float bias_cur = bw_one_pole_get_y_z1(&coeffs->smooth_bias_state);
|
||||||
if (force || coeffs->bias != bias_cur) {
|
if (force || coeffs->bias != bias_cur) {
|
||||||
bias_cur = bw_one_pole_process1_sticky_abs(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
|
bias_cur = bw_one_pole_process1_sticky_abs(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
|
||||||
@ -240,7 +247,7 @@ static inline void _bw_clip_do_update_coeffs(bw_clip_coeffs *BW_RESTRICT coeffs,
|
|||||||
static inline void bw_clip_reset_coeffs(bw_clip_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_clip_reset_coeffs(bw_clip_coeffs *BW_RESTRICT coeffs) {
|
||||||
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
|
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_bias_state, coeffs->bias);
|
||||||
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_gain_state, coeffs->gain);
|
bw_one_pole_reset_state(&coeffs->smooth_coeffs, &coeffs->smooth_gain_state, coeffs->gain);
|
||||||
_bw_clip_do_update_coeffs(coeffs, 1);
|
bw_clip_do_update_coeffs(coeffs, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_clip_reset_state(const bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state) {
|
static inline void bw_clip_reset_state(const bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state) {
|
||||||
@ -254,7 +261,7 @@ static inline void bw_clip_update_coeffs_ctrl(bw_clip_coeffs *BW_RESTRICT coeffs
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_clip_update_coeffs_audio(bw_clip_coeffs *BW_RESTRICT coeffs) {
|
static inline void bw_clip_update_coeffs_audio(bw_clip_coeffs *BW_RESTRICT coeffs) {
|
||||||
_bw_clip_do_update_coeffs(coeffs, 0);
|
bw_clip_do_update_coeffs(coeffs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float bw_clip_process1(const bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state, float x) {
|
static inline float bw_clip_process1(const bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state, float x) {
|
||||||
@ -273,30 +280,30 @@ static inline float bw_clip_process1_comp(const bw_clip_coeffs *BW_RESTRICT coef
|
|||||||
return coeffs->inv_gain * y;
|
return coeffs->inv_gain * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_clip_process(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state, const float *x, float *y, int n_samples) {
|
static inline void bw_clip_process(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state *BW_RESTRICT state, const float *x, float *y, size_t n_samples) {
|
||||||
if (coeffs->gain_compensation)
|
if (coeffs->gain_compensation)
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_clip_update_coeffs_audio(coeffs);
|
bw_clip_update_coeffs_audio(coeffs);
|
||||||
y[i] = bw_clip_process1_comp(coeffs, state, x[i]);
|
y[i] = bw_clip_process1_comp(coeffs, state, x[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_clip_update_coeffs_audio(coeffs);
|
bw_clip_update_coeffs_audio(coeffs);
|
||||||
y[i] = bw_clip_process1(coeffs, state, x[i]);
|
y[i] = bw_clip_process1(coeffs, state, x[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bw_clip_process_multi(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state **BW_RESTRICT state, const float **x, float **y, int n_channels, int n_samples) {
|
static inline void bw_clip_process_multi(bw_clip_coeffs *BW_RESTRICT coeffs, bw_clip_state * const *BW_RESTRICT state, const float * const *x, float **y, size_t n_channels, size_t n_samples) {
|
||||||
if (coeffs->gain_compensation)
|
if (coeffs->gain_compensation)
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_clip_update_coeffs_audio(coeffs);
|
bw_clip_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_clip_process1_comp(coeffs, state[j], x[j][i]);
|
y[j][i] = bw_clip_process1_comp(coeffs, state[j], x[j][i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (size_t i = 0; i < n_samples; i++) {
|
||||||
bw_clip_update_coeffs_audio(coeffs);
|
bw_clip_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_clip_process1(coeffs, state[j], x[j][i]);
|
y[j][i] = bw_clip_process1(coeffs, state[j], x[j][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,6 +321,100 @@ static inline void bw_clip_set_gain_compensation(bw_clip_coeffs *BW_RESTRICT coe
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
namespace Brickworks {
|
||||||
|
|
||||||
|
/*! api {{{
|
||||||
|
* ##### Brickworks::Clip
|
||||||
|
* ```>>> */
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
class Clip {
|
||||||
|
public:
|
||||||
|
Clip();
|
||||||
|
|
||||||
|
void setSampleRate(float sampleRate);
|
||||||
|
void reset();
|
||||||
|
void process(
|
||||||
|
const float * const *x,
|
||||||
|
float **y,
|
||||||
|
size_t nSamples);
|
||||||
|
void process(
|
||||||
|
std::array<const float *, N_CHANNELS> x,
|
||||||
|
std::array<float *, N_CHANNELS> y,
|
||||||
|
size_t nSamples);
|
||||||
|
|
||||||
|
void setBias(float value);
|
||||||
|
void setGain(float value);
|
||||||
|
void setGainCompensation(bool value);
|
||||||
|
/*! <<<...
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
* }}} */
|
||||||
|
|
||||||
|
/*** Implementation ***/
|
||||||
|
|
||||||
|
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||||
|
* change at any time in future versions. Please, do not use it directly. */
|
||||||
|
|
||||||
|
private:
|
||||||
|
bw_clip_coeffs coeffs;
|
||||||
|
bw_clip_state states[N_CHANNELS];
|
||||||
|
bw_clip_state *statesP[N_CHANNELS];
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline Clip<N_CHANNELS>::Clip() {
|
||||||
|
bw_clip_init(&coeffs);
|
||||||
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
statesP[i] = states + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<N_CHANNELS>::setSampleRate(float sampleRate) {
|
||||||
|
bw_clip_set_sample_rate(&coeffs, sampleRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<N_CHANNELS>::reset() {
|
||||||
|
bw_clip_reset_coeffs(&coeffs);
|
||||||
|
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||||
|
bw_clip_reset_state(&coeffs, states + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<N_CHANNELS>::process(
|
||||||
|
const float * const *x,
|
||||||
|
float **y,
|
||||||
|
size_t nSamples) {
|
||||||
|
bw_clip_process_multi(&coeffs, statesP, x, y, N_CHANNELS, nSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<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 Clip<N_CHANNELS>::setBias(float value) {
|
||||||
|
bw_clip_set_bias(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<N_CHANNELS>::setGain(float value) {
|
||||||
|
bw_clip_set_gain(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t N_CHANNELS>
|
||||||
|
inline void Clip<N_CHANNELS>::setGainCompensation(bool value) {
|
||||||
|
bw_clip_set_gain_compensation(&coeffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,141 +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_CHORUS_H
|
|
||||||
#define BWPP_CHORUS_H
|
|
||||||
|
|
||||||
#include <bw_chorus.h>
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace Brickworks {
|
|
||||||
|
|
||||||
/*! api {{{
|
|
||||||
* ##### Brickworks::Chorus
|
|
||||||
* ```>>> */
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
class Chorus {
|
|
||||||
public:
|
|
||||||
Chorus(float maxDelay = 0.01f);
|
|
||||||
~Chorus();
|
|
||||||
|
|
||||||
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 setDelay(float value);
|
|
||||||
void setAmount(float value);
|
|
||||||
void setCoeffX(float value);
|
|
||||||
void setCoeffMod(float value);
|
|
||||||
void setCoeffFB(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_chorus_coeffs coeffs;
|
|
||||||
bw_chorus_state states[N_CHANNELS];
|
|
||||||
bw_chorus_state *statesP[N_CHANNELS];
|
|
||||||
void *mem;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline Chorus<N_CHANNELS>::Chorus(float maxDelay) {
|
|
||||||
bw_chorus_init(&coeffs, maxDelay);
|
|
||||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
|
||||||
statesP[i] = states + i;
|
|
||||||
mem = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline Chorus<N_CHANNELS>::~Chorus() {
|
|
||||||
if (mem != nullptr)
|
|
||||||
operator delete(mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setSampleRate(float sampleRate) {
|
|
||||||
bw_chorus_set_sample_rate(&coeffs, sampleRate);
|
|
||||||
size_t req = bw_chorus_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_chorus_mem_set(&coeffs, states + i, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::reset() {
|
|
||||||
bw_chorus_reset_coeffs(&coeffs);
|
|
||||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
|
||||||
bw_chorus_reset_state(&coeffs, states + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::process(
|
|
||||||
std::array<const float *, N_CHANNELS> x,
|
|
||||||
std::array<float *, N_CHANNELS> y,
|
|
||||||
int nSamples) {
|
|
||||||
bw_chorus_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setRate(float value) {
|
|
||||||
bw_chorus_set_rate(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setDelay(float value) {
|
|
||||||
bw_chorus_set_delay(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setAmount(float value) {
|
|
||||||
bw_chorus_set_amount(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setCoeffX(float value) {
|
|
||||||
bw_chorus_set_coeff_x(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setCoeffMod(float value) {
|
|
||||||
bw_chorus_set_coeff_mod(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Chorus<N_CHANNELS>::setCoeffFB(float value) {
|
|
||||||
bw_chorus_set_coeff_fb(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -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_CLIP_H
|
|
||||||
#define BWPP_CLIP_H
|
|
||||||
|
|
||||||
#include <bw_clip.h>
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace Brickworks {
|
|
||||||
|
|
||||||
/*! api {{{
|
|
||||||
* ##### Brickworks::Clip
|
|
||||||
* ```>>> */
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
class Clip {
|
|
||||||
public:
|
|
||||||
Clip();
|
|
||||||
|
|
||||||
void setSampleRate(float sampleRate);
|
|
||||||
void reset();
|
|
||||||
void process(
|
|
||||||
std::array<const float *, N_CHANNELS> x,
|
|
||||||
std::array<float *, N_CHANNELS> y,
|
|
||||||
int nSamples);
|
|
||||||
|
|
||||||
void setBias(float value);
|
|
||||||
void setGain(float value);
|
|
||||||
void setGainCompensation(bool value);
|
|
||||||
/*! <<<...
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
* }}} */
|
|
||||||
|
|
||||||
/*** Implementation ***/
|
|
||||||
|
|
||||||
/* WARNING: This part of the file is not part of the public API. Its content may
|
|
||||||
* change at any time in future versions. Please, do not use it directly. */
|
|
||||||
|
|
||||||
private:
|
|
||||||
bw_clip_coeffs coeffs;
|
|
||||||
bw_clip_state states[N_CHANNELS];
|
|
||||||
bw_clip_state *statesP[N_CHANNELS];
|
|
||||||
};
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline Clip<N_CHANNELS>::Clip() {
|
|
||||||
bw_clip_init(&coeffs);
|
|
||||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
|
||||||
statesP[i] = states + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::setSampleRate(float sampleRate) {
|
|
||||||
bw_clip_set_sample_rate(&coeffs, sampleRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::reset() {
|
|
||||||
bw_clip_reset_coeffs(&coeffs);
|
|
||||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
|
||||||
bw_clip_reset_state(&coeffs, states + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::process(
|
|
||||||
std::array<const float *, N_CHANNELS> x,
|
|
||||||
std::array<float *, N_CHANNELS> y,
|
|
||||||
int nSamples) {
|
|
||||||
bw_clip_process_multi(&coeffs, statesP, x.data(), y.data(), N_CHANNELS, nSamples);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::setBias(float value) {
|
|
||||||
bw_clip_set_bias(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::setGain(float value) {
|
|
||||||
bw_clip_set_gain(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N_CHANNELS>
|
|
||||||
inline void Clip<N_CHANNELS>::setGainCompensation(bool value) {
|
|
||||||
bw_clip_set_gain_compensation(&coeffs, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user