Brickworks > API documentation > bw_osc_tri

bw_osc_tri

Description

Triangle oscillator waveshaper with variable slope (increasing time over period) and PolyBLEP antialiasing.

It turns a normalized phase signal, such as that geneated by bw_phase_gen, into a triangle 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_tri_coeffs

typedef struct bw_osc_tri_coeffs bw_osc_tri_coeffs;

Coefficients and related.

bw_osc_tri_init()

static inline void bw_osc_tri_init(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs);

Initializes input parameter values in coeffs.

bw_osc_tri_set_sample_rate()

static inline void bw_osc_tri_set_sample_rate(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs,
	float                           sample_rate);

Sets the sample_rate (Hz) value in coeffs.

bw_osc_tri_reset_coeffs()

static inline void bw_osc_tri_reset_coeffs(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs);

Resets coefficients in coeffs to assume their target values.

bw_osc_tri_update_coeffs_ctrl()

static inline void bw_osc_tri_update_coeffs_ctrl(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.

bw_osc_tri_update_coeffs_audio()

static inline void bw_osc_tri_update_coeffs_audio(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.

bw_osc_tri_process1*()

static inline float bw_osc_tri_process1(
	const bw_osc_tri_coeffs * BW_RESTRICT coeffs,
	float                                 x);

static inline float bw_osc_tri_process1_antialias(
	const bw_osc_tri_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_tri_process()

static inline void bw_osc_tri_process(
	bw_osc_tri_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.

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_tri_process_multi()

static inline void bw_osc_tri_process_multi(
	bw_osc_tri_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, x_inc must contain n_channels buffers of 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_tri_set_antialiasing()

static inline void bw_osc_tri_set_antialiasing(
	bw_osc_tri_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_tri_set_slope()

static inline void bw_osc_tri_set_slope(
	bw_osc_tri_coeffs * BW_RESTRICT coeffs,
	float                           value);

Sets the slope (increasing time over period) to value in coeffs.

Valid range: [0.001f, 0.999f].

Default value: 0.5f.

bw_osc_tri_coeffs_is_valid()

static inline char bw_osc_tri_coeffs_is_valid(
	const bw_osc_tri_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_tri_coeffs.

C++ wrapper

Brickworks::OscTri
template<size_t N_CHANNELS>
class OscTri {
public:
	OscTri();
	
	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 setSlope(
		float value);
...
}

ChangeLog