Advanced version of bw_osc_pulse with hard-sync antialiasing and advanced pulse width modulation.
Hard sync signals are those introduced in bwp_phase_gen.
Pulse width parameter modulation is implemented as detailed in bwp_mod_func. It is however internally limited to the valid range.
Requires:
We can privately hand you one or more example plugins if you are interested.
Module type: DSP
typedef struct bwp_osc_pulse_v2_coeffs bwp_osc_pulse_v2_coeffs;
Coefficients and related.
typedef struct bwp_osc_pulse_v2_state bwp_osc_pulse_v2_state;
Internal state and related.
static inline void bwp_osc_pulse_v2_init(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs);
Initializes input parameter values in coeffs.
static inline void bwp_osc_pulse_v2_set_sample_rate(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
float sample_rate);
Sets the sample_rate (Hz) value in coeffs.
static inline void bwp_osc_pulse_v2_reset_coeffs(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs);
Resets coefficients in coeffs to assume their target values.
static inline float bwp_osc_pulse_v2_reset_state(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x_0,
float x_inc_0,
char is_slave,
float x_sync_low_0,
float x_sync_high_0,
float x_pw_0);
Resets the given state to its initial values using the given coeffs and the initial input value x_0, the corresponding phase increment value x_inc_0, an is_slave flag indicating whether the corresponding phase generator is a hard sync slave, x_sync_low_0 and x_sync_high_0 input hard sync signal initial values, and the initial pulse width value x_pw_0.
Returns the corresponding initial output value.
x_0 must be in [0.f, 1.f).
If antialiasing is not enabled or is_slave is 0 then x_inc_0 is ignored. Otherwise, x_inc must be in [-0.5f, 0.5f].
If is_slave is 0 then x_sync_low_0 and x_sync_high_0 are ignored.
x_pw_0 must be in [0.f, 1.f].
static inline void bwp_osc_pulse_v2_reset_state_multi(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT const * BW_RESTRICT state,
const float * x_0,
const float * x_inc_0,
const char * BW_RESTRICT is_slave,
const float * x_sync_low_0,
const float * x_sync_high_0,
const float * x_pw_0,
float * y_0,
size_t n_channels);
Resets each of the n_channels states to its initial values using the given coeffs and the corresponding initial input value in the x_0 array, phase increment value in the x_inc_0 array, flag indicating whether the corresponding phase generator is a hard sync slave in the is_slave array, input hard sync signal initial values in the x_sync_low_0 and x_sync_high_0 arrays, and initial pulse width value in the x_pw_0 array.
The corresponding initial output values are written into the y_0 array, if not BW_NULL.
Values in x_0 must be in [0.f, 1.f).
is_slave may be BW_NULL, in which case x_sync_low_0 and x_sync_high_0 are ignored. Otherwise, if any element in is_slave is non-0, then both x_sync_low_0 and x_sync_high_0 are required to be not BW_NULL. Furthermore, if is_slave[i] is 0 then x_sync_low_0[i] and x_sync_high_0[i] are ignored.
If antialiasing is enabled or both is_slave is not BW_NULL and is_slave[i] is non-0, then x_inc_0 must not be BW_NULL and x_inc_0[i] must be in [-0.5f, 0.5f].
Values in x_pw_0 must be in [0.f, 1.f].
static inline void bwp_osc_pulse_v2_update_coeffs_ctrl(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs);
Triggers control-rate update of coefficients in coeffs.
static inline void bwp_osc_pulse_v2_update_coeffs_audio(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs);
Triggers audio-rate update of coefficients in coeffs.
static inline float bwp_osc_pulse_v2_shape1(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
float x,
float x_pwm);
Returns the aliased output that would correspond to the given input sample x, audio-rate pulse width modulation input sample x_pwm, and coefficients coeffs, discarding smoothing (i.e., using target coefficient values).
coeffs MUST be at least in the "reset" state.
static inline void bwp_osc_pulse_v2_shape1_multi(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
const float * x,
const float * x_pwm,
float * y,
size_t n_channels);
Computes the n_channels aliased output samples that would correspond to the given n_channels input samples in x and audio-rate pulse width modulation samples in x_pwm, using coefficients in coeffs, discarding smoothing (i.e., using target coefficient values), and stores them in y.
coeffs MUST be at least in the "reset" state.
static inline float bwp_osc_pulse_v2_process1(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x);
static inline float bwp_osc_pulse_v2_process1_antialias(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc);
static inline float bwp_osc_pulse_v2_process1_slave(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc,
char x_sync_do,
float x_sync_low,
float x_sync_high);
static inline float bwp_osc_pulse_v2_process1_antialias_slave(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc,
char x_sync_do,
float x_sync_low,
float x_sync_high);
static inline float bwp_osc_pulse_v2_process1_pwm(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_pwm);
static inline float bwp_osc_pulse_v2_process1_antialias_pwm(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc,
float x_pwm);
static inline float bwp_osc_pulse_v2_process1_slave_pwm(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc,
char x_sync_do,
float x_sync_low,
float x_sync_high,
float x_pwm);
static inline float bwp_osc_pulse_v2_process1_antialias_slave_pwm(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
float x,
float x_inc,
char x_sync_do,
float x_sync_low,
float x_sync_high,
float x_pwm);
These function process one input sample x, representing the normalized phase, using coeffs. They return the corresponding output sample.
In particular:
bwp_osc_pulse_v2_process1() assumes that antialiasing is disabled and the corresponding phase generator is not a hard sync slave;bwp_osc_pulse_v2_process1_antialias() assumes that antialiasing is enabled and the corresponding phase generator is not a hard sync slave -- the corresponding phase increment value to be passed via x_inc;bwp_osc_pulse_v2_process1_slave() assumes that antialiasing is disabled and the corresponding phase generator is a hard sync slave -- the corresponding phase increment value to be passed via x_inc and the input hard sync signal values are x_sync_do, x_sync_low, and x_sync_high;bwp_osc_pulse_v2_process1_antialias_slave() assumes that antialiasing is enabled and the corresponding phase generator is a hard sync slave -- the corresponding phase increment value to be passed via x_inc and the input hard sync signal values are x_sync_do, x_sync_low, and x_sync_high;bwp_osc_pulse_v2_process1_\*_pwm() correspond to the above but also take the audio-rate pulse width modulation sample x_pwm.Whether antialiasing is enabled or not is unchecked even for debugging purposes.
x must be in [0.f, 1.f).
x_inc must be in [-0.5f, 0.5f].
static inline void bwp_osc_pulse_v2_process(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT state,
const float * x,
const float * x_inc,
const char * BW_RESTRICT x_sync_do,
const float * x_sync_low,
const float * x_sync_high,
const float * x_pwm,
float * y,
size_t n_samples);
Processes the first n_samples of the input buffer x, containing the normalized phase signal, and fills the first n_samples of the output buffer y, while using and updating both coeffs and state (control and audio rate).
If antialiasing is enabled or x_sync_do is not BW_NULL, x_inc must contain phase increment values, otherwise it is ignored and can be BW_NULL.
If x_sync_do is not BW_NULL, x_sync_low and x_sync_high must point to different buffers. These buffers represent input hard sync signals.
If x_pwm is not BW_NULL, it is used as a source of pulse width modulation.
All samples in x must be in [0.f, 1.f).
All samples is x_inc, if not ignored, must be in [-0.5f, 0.5f].
static inline void bwp_osc_pulse_v2_process_multi(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_osc_pulse_v2_state * BW_RESTRICT const * BW_RESTRICT state,
const float * const * x,
const float * const * x_inc,
const char * BW_RESTRICT const * BW_RESTRICT x_sync_do,
const float * const * x_sync_low,
const float * const * x_sync_high,
const float * const * x_pwm,
float * const * y,
size_t n_channels,
size_t n_samples);
Processes the first n_samples of the n_channels input buffers x, containing the normalized phase signals, and fills the first n_samples of the n_samples output buffers y, while using coeffs and updating both the common coeffs and each of the n_channels states (control and audio rate).
If antialiasing is enabled or both x_sync_do and x_sync_do[i] are not BW_NULL then x_inc must not be BW_NULL and each of the n_channels buffers pointed by x_inc must contain phase increment values, otherwise x_inc is ignored and can be BW_NULL.
If x_sync_do is not BW_NULL, x_sync_low and x_sync_high must point to different arrays. Then, if x_sync_do[i] is not BW_NULL, x_sync_low[i] and x_sync_high[i] must point to different buffers. These buffers represent input hard sync signals.
If x_pwm and the cannel-specific element are not BW_NULL, this is used as a source of pulse width modulation for that channel.
All samples in x must be in [0.f, 1.f).
All samples is x_inc, if not ignored, must be in [-0.5f, 0.5f].
static inline void bwp_osc_pulse_v2_set_antialiasing(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
char value);
Sets whether the antialiasing is on (value non-0) or off (0) in coeffs.
Default value: 0 (off).
static inline void bwp_osc_pulse_v2_set_sync_phase(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
float value);
Sets which value the phase assumes immediately after a hard sync event. This should match the same parameter value in the phase generator.
Valid range: [0.f, 1.f).
Default value: 0.f.
static inline void bwp_osc_pulse_v2_set_pulse_width(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
float value);
Sets the pulse width (actually, the duty cycle) to value in coeffs.
Valid range: [0.f (0% duty cycle), 1.f (100% duty cycle)].
Default value: 0.5f.
static inline void bwp_osc_pulse_v2_set_pulse_width_mod(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
float value);
Sets the non-smoothed pulse width (actually, duty cycle) component to value in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_osc_pulse_v2_set_mod_func_pulse_width(
bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
bwp_mod_func value);
Sets the pulse width modulation function.
Default value: [bwp_mod_func_sum](bwp_mod_func#bwp_mod_func_sum).
static inline char bwp_osc_pulse_v2_coeffs_is_valid(
const bwp_osc_pulse_v2_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 bwp_osc_pulse_v2_coeffs.
static inline char bwp_osc_pulse_v2_state_is_valid(
const bwp_osc_pulse_v2_coeffs * BW_RESTRICT coeffs,
const bwp_osc_pulse_v2_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 BW_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 bwp_osc_pulse_v2_state.
template<size_t N_CHANNELS = 1>
class OscPulseV2 {
public:
OscPulseV2();
void setSampleRate(
float sampleRate);
void reset(
float x0 = 0.f,
float xInc0 = 0.f,
char isSlave = 0,
float xSyncLow0 = 0.f,
float xSyncHigh0 = 0.f,
float xPw0 = 0.f,
float * BW_RESTRICT y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
float x0,
float xInc0,
char isSlave,
float xSyncLow0,
float xSyncHigh0,
float xPw0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0);
# endif
void reset(
const float * x0,
const float * xInc0,
const char * BW_RESTRICT isSlave,
const float * xSyncLow0,
const float * xSyncHigh0,
const float * xPw0,
float * y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> xInc0,
std::array<char, N_CHANNELS> isSlave,
std::array<float, N_CHANNELS> xSyncLow0,
std::array<float, N_CHANNELS> xSyncHigh0,
std::array<float, N_CHANNELS> xPw0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = BW_NULL);
# endif
void shape1(
const float * x,
const float * xPwm,
float * y);
# ifndef BW_CXX_NO_ARRAY
void shape1(
std::array<float, N_CHANNELS> x,
std::array<float, N_CHANNELS> xPwm,
std::array<float, N_CHANNELS> * BW_RESTRICT y);
# endif
void process(
const float * const * x,
const float * const * xInc,
const char * BW_RESTRICT const * BW_RESTRICT xSyncDo,
const float * const * xSyncLow,
const float * const * xSyncHigh,
const float * const * xPwm,
float * const * y,
size_t nSamples);
# ifndef BW_CXX_NO_ARRAY
void process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> xInc,
std::array<const char * BW_RESTRICT, N_CHANNELS> xSyncDo,
std::array<const float *, N_CHANNELS> xSyncLow,
std::array<const float *, N_CHANNELS> xSyncHigh,
std::array<const float *, N_CHANNELS> xPwm,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
# endif
void setAntialiasing(
bool value);
void setSyncPhase(
float value);
void setPulseWidth(
float value);
void setPulseWidthMod(
float value);
void setModFuncPulseWidth(
bwp_mod_func value);
...
}
N_CHANNELS in C++ API.bwp_osc_pulse_shape1().BW_NULL in the C++ API and implementation.