2023-06-01 10:20:37 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* module_type {{{ dsp }}}
|
2023-08-08 08:46:05 +00:00
|
|
|
* version {{{ 1.0.0 }}}
|
2023-07-21 06:56:27 +00:00
|
|
|
* requires {{{ bw_common bw_gain bw_math bw_one_pole }}}
|
2023-06-01 10:20:37 +00:00
|
|
|
* description {{{
|
|
|
|
* Dry/wet mixer.
|
|
|
|
* }}}
|
|
|
|
* changelog {{{
|
|
|
|
* <ul>
|
2023-08-08 08:46:05 +00:00
|
|
|
* <li>Version <strong>1.0.0</strong>:
|
|
|
|
* <ul>
|
2023-08-14 04:05:21 +00:00
|
|
|
* <li>Module renamed as bw_dry_wet.</li>
|
|
|
|
* <li><code>bw_dry_wet_process()</code> and
|
|
|
|
* <code>bw_dry_wet_process_multi()</code> now use
|
2023-08-12 16:45:19 +00:00
|
|
|
* <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>
|
2023-09-05 09:35:30 +00:00
|
|
|
* <li>Added overloaded C++ <code>process()</code> function taking
|
2023-08-12 16:45:19 +00:00
|
|
|
* C-style arrays as arguments.</li>
|
|
|
|
* <li>Removed usage of reserved identifiers.</li>
|
2023-08-08 08:46:05 +00:00
|
|
|
* </ul>
|
|
|
|
* </li>
|
2023-07-21 06:56:27 +00:00
|
|
|
* <li>Version <strong>0.6.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>Removed dependency on bw_config.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
2023-06-01 10:20:37 +00:00
|
|
|
* <li>Version <strong>0.5.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>First release.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* }}}
|
|
|
|
*/
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
#ifndef BW_DRY_WET_H
|
|
|
|
#define BW_DRY_WET_H
|
2023-06-01 10:20:37 +00:00
|
|
|
|
2023-08-12 08:15:04 +00:00
|
|
|
#include <bw_common.h>
|
|
|
|
|
2023-06-01 10:20:37 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*! api {{{
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_coeffs
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
typedef struct bw_dry_wet_coeffs bw_dry_wet_coeffs;
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Coefficients and related.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_init()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_init(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Initializes input parameter values in `coeffs`.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_set_sample_rate()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_sample_rate(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float sample_rate);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets the `sample_rate` (Hz) value in `coeffs`.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_reset_coeffs()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_reset_coeffs(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Resets coefficients in `coeffs` to assume their target values.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_update_coeffs_ctrl()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_update_coeffs_ctrl(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Triggers control-rate update of coefficients in `coeffs`.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_update_coeffs_audio()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_update_coeffs_audio(bw_dry_wet_coeffs *BW_RESTRICT coeffs);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Triggers audio-rate update of coefficients in `coeffs`.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_process1()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline float bw_dry_wet_process1(const bw_dry_wet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Processes one dry input sample `x_dry` and one wet input sample `x_wet`
|
|
|
|
* using `coeffs` and returns the corresponding output sample.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_process()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_process(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Processes the first `n_samples` of the dry input buffer `x_dry` and of the
|
|
|
|
* wet input buffer `x_wet` and fills the first `n_samples` of the output
|
|
|
|
* buffer `y`, while using and updating `coeffs` (control and audio rate).
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_process_multi()
|
2023-06-07 13:41:20 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_process_multi(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples);
|
2023-06-07 13:41:20 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Processes the first `n_samples` of the `n_channels` dry input buffers
|
|
|
|
* `x_dry` and of the `n_channels` wet input buffers `x_wet`, and fills the
|
|
|
|
* first `n_samples` of the `n_channels` output buffers `y`, while using and
|
|
|
|
* updating the common `coeffs` (control and audio rate).
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_set_wet()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_wet(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets the wet gain parameter to the given `value` (linear gain) in `coeffs`.
|
|
|
|
*
|
|
|
|
* Default value: `1.f`.
|
|
|
|
*
|
2023-08-14 04:05:21 +00:00
|
|
|
* #### bw_dry_wet_set_smooth_tau()
|
2023-06-01 10:20:37 +00:00
|
|
|
* ```>>> */
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_smooth_tau(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value);
|
2023-06-01 10:20:37 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets the smoothing time constant `value` (s) in `coeffs`.
|
|
|
|
*
|
|
|
|
* Default value: `0.05f`.
|
|
|
|
* }}} */
|
|
|
|
|
2023-08-12 08:15:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-06-01 10:20:37 +00:00
|
|
|
/*** 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. */
|
|
|
|
|
|
|
|
#include <bw_gain.h>
|
|
|
|
|
2023-08-12 08:15:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
struct bw_dry_wet_coeffs {
|
2023-06-01 10:20:37 +00:00
|
|
|
// Sub-components
|
2023-06-01 11:39:47 +00:00
|
|
|
bw_gain_coeffs gain_coeffs;
|
2023-06-01 10:20:37 +00:00
|
|
|
};
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_init(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_init(&coeffs->gain_coeffs);
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_sample_rate(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float sample_rate) {
|
2023-06-01 11:39:47 +00:00
|
|
|
bw_gain_set_sample_rate(&coeffs->gain_coeffs, sample_rate);
|
2023-06-01 10:20:37 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_reset_coeffs(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_reset_coeffs(&coeffs->gain_coeffs);
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_update_coeffs_ctrl(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_update_coeffs_ctrl(&coeffs->gain_coeffs);
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_update_coeffs_audio(bw_dry_wet_coeffs *BW_RESTRICT coeffs) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_update_coeffs_audio(&coeffs->gain_coeffs);
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline float bw_dry_wet_process1(const bw_dry_wet_coeffs *BW_RESTRICT coeffs, float x_dry, float x_wet) {
|
2023-09-01 17:43:50 +00:00
|
|
|
return bw_gain_process1(&coeffs->gain_coeffs, x_wet - x_dry) + x_dry;
|
2023-06-01 10:20:37 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_process(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float *x_dry, const float *x_wet, float *y, size_t n_samples) {
|
|
|
|
bw_dry_wet_update_coeffs_ctrl(coeffs);
|
2023-08-12 16:45:19 +00:00
|
|
|
for (size_t i = 0; i < n_samples; i++) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_update_coeffs_audio(coeffs);
|
|
|
|
y[i] = bw_dry_wet_process1(coeffs, x_dry[i], x_wet[i]);
|
2023-06-01 10:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_process_multi(bw_dry_wet_coeffs *BW_RESTRICT coeffs, const float * const *x_dry, const float * const *x_wet, float * const *y, size_t n_channels, size_t n_samples) {
|
|
|
|
bw_dry_wet_update_coeffs_ctrl(coeffs);
|
2023-08-12 16:45:19 +00:00
|
|
|
for (size_t i = 0; i < n_samples; i++) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_update_coeffs_audio(coeffs);
|
2023-08-12 16:45:19 +00:00
|
|
|
for (size_t j = 0; j < n_channels; j++)
|
2023-08-14 04:05:21 +00:00
|
|
|
y[j][i] = bw_dry_wet_process1(coeffs, x_dry[j][i], x_wet[j][i]);
|
2023-06-07 13:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_wet(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_set_gain_lin(&coeffs->gain_coeffs, value);
|
|
|
|
}
|
|
|
|
|
2023-08-14 04:05:21 +00:00
|
|
|
static inline void bw_dry_wet_set_smooth_tau(bw_dry_wet_coeffs *BW_RESTRICT coeffs, float value) {
|
2023-06-01 10:20:37 +00:00
|
|
|
bw_gain_set_smooth_tau(&coeffs->gain_coeffs, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace Brickworks {
|
|
|
|
|
|
|
|
/*** Public C++ API ***/
|
|
|
|
|
|
|
|
/*! api_cpp {{{
|
|
|
|
* ##### Brickworks::DryWet
|
|
|
|
* ```>>> */
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
class DryWet {
|
|
|
|
public:
|
|
|
|
DryWet();
|
|
|
|
|
|
|
|
void setSampleRate(float sampleRate);
|
|
|
|
void reset();
|
|
|
|
void process(
|
|
|
|
const float * const *x_dry,
|
|
|
|
const float * const *x_wet,
|
2023-08-13 13:37:15 +00:00
|
|
|
float * const *y,
|
2023-08-12 16:45:19 +00:00
|
|
|
size_t nSamples);
|
|
|
|
void process(
|
|
|
|
std::array<const float *, N_CHANNELS> x_dry,
|
|
|
|
std::array<const float *, N_CHANNELS> x_wet,
|
|
|
|
std::array<float *, N_CHANNELS> y,
|
|
|
|
size_t nSamples);
|
|
|
|
|
|
|
|
void setWet(float value);
|
|
|
|
void setSmoothTau(float value);
|
|
|
|
/*! <<<...
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
* }}} */
|
|
|
|
|
|
|
|
/*** Implementation ***/
|
|
|
|
|
|
|
|
/* WARNING: This part of the file is not part of the public API. Its content may
|
|
|
|
* change at any time in future versions. Please, do not use it directly. */
|
|
|
|
|
|
|
|
private:
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_coeffs coeffs;
|
2023-08-12 16:45:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline DryWet<N_CHANNELS>::DryWet() {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_init(&coeffs);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::setSampleRate(float sampleRate) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_set_sample_rate(&coeffs, sampleRate);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::reset() {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_reset_coeffs(&coeffs);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::process(
|
|
|
|
const float * const *x_dry,
|
|
|
|
const float * const *x_wet,
|
2023-08-13 13:37:15 +00:00
|
|
|
float * const *y,
|
2023-08-12 16:45:19 +00:00
|
|
|
size_t nSamples) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_process_multi(&coeffs, x_dry, x_wet, y, N_CHANNELS, nSamples);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::process(
|
|
|
|
std::array<const float *, N_CHANNELS> x_dry,
|
|
|
|
std::array<const float *, N_CHANNELS> x_wet,
|
|
|
|
std::array<float *, N_CHANNELS> y,
|
|
|
|
size_t nSamples) {
|
|
|
|
process(x_dry.data(), x_wet.data(), y.data(), nSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::setWet(float value) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_set_wet(&coeffs, value);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N_CHANNELS>
|
|
|
|
inline void DryWet<N_CHANNELS>::setSmoothTau(float value) {
|
2023-08-14 04:05:21 +00:00
|
|
|
bw_dry_wet_set_smooth_tau(&coeffs, value);
|
2023-08-12 16:45:19 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 10:20:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|