Brickworks > API documentation > bw_phase_gen
Phase generator with portamento and exponential frequency modulation.
It outputs a normalized phase signal (range [0.f
, 1.f
]).
Module type: dsp
Version: 1.0.0
Requires:
typedef struct bw_phase_gen_coeffs bw_phase_gen_coeffs;
Coefficients and related.
typedef struct bw_phase_gen_state bw_phase_gen_state;
Internal state and related.
static inline void bw_phase_gen_init(
bw_phase_gen_coeffs * BW_RESTRICT coeffs);
Initializes input parameter values in coeffs
.
static inline void bw_phase_gen_set_sample_rate(
bw_phase_gen_coeffs * BW_RESTRICT coeffs,
float sample_rate);
Sets the sample_rate
(Hz) value in coeffs
.
static inline void bw_phase_gen_reset_coeffs(
bw_phase_gen_coeffs * BW_RESTRICT coeffs);
Resets coefficients in coeffs
to assume their target values.
static inline void bw_phase_gen_reset_state(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs,
bw_phase_gen_state * BW_RESTRICT state,
float phase_0,
float * BW_RESTRICT y_0,
float * BW_RESTRICT y_inc_0);
Resets the given state
to its initial values using the given coeffs
and the initial phase value phase_0
.
The corresponding initial output and phase increment values are put into y_0
and y_inc_0
respectively.
static inline void bw_phase_gen_reset_state_multi(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs,
bw_phase_gen_state * BW_RESTRICT const * BW_RESTRICT state,
const float * phase_0,
float * y_0,
float * y_inc_0,
size_t n_channels);
Resets each of the n_channels
state
s to its initial values using the given coeffs
and the corresponding initial phase value in the phase_0
array.
The corresponding initial output and phase increment values are put into the y_0
and y_inc_0
arrays, respectively, if they are not NULL
.
static inline void bw_phase_gen_update_coeffs_ctrl(
bw_phase_gen_coeffs * BW_RESTRICT coeffs);
Triggers control-rate update of coefficients in coeffs
.
static inline void bw_phase_gen_update_coeffs_audio(
bw_phase_gen_coeffs * BW_RESTRICT coeffs);
Triggers audio-rate update of coefficients in coeffs
.
static inline void bw_phase_gen_process1(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs,
bw_phase_gen_state * BW_RESTRICT state,
float * BW_RESTRICT y,
float * BW_RESTRICT y_inc);
static inline void bw_phase_gen_process1_mod(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs,
bw_phase_gen_state * BW_RESTRICT state,
float x_mod,
float * BW_RESTRICT y,
float * BW_RESTRICT y_inc);
These functions generate one output sample using coeffs
, while using and updating state
, putting its value in y
and the corresponding phase increment value in y_inc
.
In particular:
bw_phase_gen_process1()
does not apply frequency modulation;bw_phase_gen_process1_mod()
applies exponential frequency modulation using x_mod
as modulation input (scale 1.f
/octave).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_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).
If x_mod
is not NULL
, it is used as a source of exponential frequency modulation (scale 1.f
/octave).
If y_inc
is not NULL
, it is filled with phase increment values.
static inline void bw_phase_gen_process_multi(
bw_phase_gen_coeffs * BW_RESTRICT coeffs,
bw_phase_gen_state * BW_RESTRICT const * BW_RESTRICT state,
const float * const * x_mod,
float * const * y,
float * const * y_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 the n_channels
state
s (control and audio rate).
If x_mod
and the channel-specific element are not NULL
, this is used as a source of exponential frequency modulation (scale 1.f
/octave) for that channel.
If y_inc
and the channel-specific element are not NULL
, this is filled with phase increment values for that channel.
static inline void bw_phase_gen_set_frequency(
bw_phase_gen_coeffs * BW_RESTRICT coeffs,
float value);
Sets the base frequency to value
(Hz) in coeffs
.
value
must be finite.
Default value: 1.f
.
static inline void bw_phase_gen_set_portamento_tau(
bw_phase_gen_coeffs * BW_RESTRICT coeffs,
float value);
Sets the portamento time constant value
(s) in coeffs
.
value
must be non-negative.
Default value: 0.f
.
static inline char bw_phase_gen_coeffs_is_valid(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs);
Tries to determine whether coeffs
is valid and returns non-0
if it seems to be the case and 0
if it is certainly not. False positives are possible, false negatives are not.
coeffs
must at least point to a readable memory block of size greater than or equal to that of bw_phase_gen_coeffs
.
static inline char bw_phase_gen_state_is_valid(
const bw_phase_gen_coeffs * BW_RESTRICT coeffs,
const bw_phase_gen_state * BW_RESTRICT state);
Tries to determine whether state
is valid and returns non-0
if it seems to be the case and 0
if it is certainly not. False positives are possible, false negatives are not.
If coeffs
is not NULL
extra cross-checks might be performed (state
is supposed to be associated to coeffs
).
state
must at least point to a readable memory block of size greater than or equal to that of bw_phase_gen_state
.
template<size_t N_CHANNELS>
class PhaseGen {
public:
PhaseGen();
void setSampleRate(
float sampleRate);
void reset(
float phase0 = 0.f,
float * BW_RESTRICT y0 = nullptr,
float * BW_RESTRICT yInc0 = nullptr);
void reset(
float phase0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0,
std::array<float, N_CHANNELS> * BW_RESTRICT yInc0);
void reset(
const float * phase0,
float * y0 = nullptr,
float * yInc0 = nullptr);
void reset(
std::array<float, N_CHANNELS> phase0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = nullptr,
std::array<float, N_CHANNELS> * BW_RESTRICT yInc0 = nullptr);
void process(
const float * const * xMod,
float * const * y,
float * const * yInc,
size_t nSamples);
void process(
std::array<const float *, N_CHANNELS> xMod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> yInc,
size_t nSamples);
void setFrequency(
float value);
void setPortamentoTau(
float value);
...
}
bw_phase_gen_reset_state()
.bw_phase_gen_reset_state_multi()
and updated C++ API in this regard.bw_phase_gen_reset_state()
returns the initial output values.reset()
functions taking arrays as arguments.bw_phase_gen_process()
and bw_phase_gen_process_multi()
now use size_t
to count samples and channels.const
and BW_RESTRICT
specifiers to input arguments and implementation.process()
function taking C-style arrays as arguments.bw_phase_gen_reset_coeffs()
.bw_phase_gen_process_multi()
.BW_RESTRICT
to bw_phase_gen_process1*()
.