Brickworks > API documentation > bw_osc_pulse

bw_osc_pulse

Description

Pulse oscillator waveshaper with variable pulse width (actually, duty cycle) and PolyBLEP antialiasing.

It turns a normalized phase signal, such as that geneated by bw_phase_gen, into a pulse wave.

The antialiasing algorithm is based on

V. Valimaki and A. Huovilainen, "Antialiasing Oscillators in Subtractive Synthesis", IEEE Signal Processing Magazine, vol. 24, no. 2, pp. 116-125, March 2007.

Info

Module type: dsp

Version: 1.1.0

Requires:

API

bw_osc_pulse_coeffs

typedef struct bw_osc_pulse_coeffs bw_osc_pulse_coeffs;

Coefficients and related.

bw_osc_pulse_init()

static inline void bw_osc_pulse_init(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs);

Initializes input parameter values in coeffs.

bw_osc_pulse_set_sample_rate()

static inline void bw_osc_pulse_set_sample_rate(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	float                             sample_rate);

Sets the sample_rate (Hz) value in coeffs.

bw_osc_pulse_reset_coeffs()

static inline void bw_osc_pulse_reset_coeffs(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs);

Resets coefficients in coeffs to assume their target values.

bw_osc_pulse_update_coeffs_ctrl()

static inline void bw_osc_pulse_update_coeffs_ctrl(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.

bw_osc_pulse_update_coeffs_audio()

static inline void bw_osc_pulse_update_coeffs_audio(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.

bw_osc_pulse_process1*()

static inline float bw_osc_pulse_process1(
	const bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	float                                   x);

static inline float bw_osc_pulse_process1_antialias(
	const bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	float                                   x,
	float                                   x_inc);

These function process one input sample x, representing the normalized phase, using coeffs. They return the corresponding output sample.

In particular:

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].

bw_osc_pulse_process()

static inline void bw_osc_pulse_process(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	const float *                     x,
	const float *                     x_inc,
	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 coeffs (control and audio rate).

If antialiasing is enabled, x_inc must contain phase increment values, otherwise it is ignored and can be BW_NULL.

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].

bw_osc_pulse_process_multi()

static inline void bw_osc_pulse_process_multi(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	const float * const *             x,
	const float * const *             x_inc,
	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_channels output buffers y, while using and updating the common coeffs (control and audio rate).

If antialiasing is enabled, 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.

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].

bw_osc_pulse_set_antialiasing()

static inline void bw_osc_pulse_set_antialiasing(
	bw_osc_pulse_coeffs * BW_RESTRICT coeffs,
	char                              value);

Sets whether the antialiasing is on (value non-0) or off (0) in coeffs.

Default value: 0 (off).

bw_osc_pulse_set_pulse_width()

static inline void bw_osc_pulse_set_pulse_width(
	bw_osc_pulse_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.

bw_osc_pulse_coeffs_is_valid()

static inline char bw_osc_pulse_coeffs_is_valid(
	const bw_osc_pulse_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_osc_pulse_coeffs.

C++ wrapper

Brickworks::OscPulse
template<size_t N_CHANNELS>
class OscPulse {
public:
	OscPulse();
	
	void setSampleRate(
		float sampleRate);

	void reset();

	void process(
		const float * const * x,
		const float * const * x_inc,
		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> x_inc,
		std::array<float *, N_CHANNELS>       y,
		size_t                                nSamples);
#endif
	
	void setAntialiasing(
		bool value);

	void setPulseWidth(
		float value);
...
}

ChangeLog