bwp_osc_saw

Advanced version of bw_osc_saw with hard-sync antialiasing.

Hard sync signals are those introduced in bwp_phase_gen.

Examples

We can privately hand you one or more example plugins if you are interested.

Contact us

API

Module type: DSP

bwp_osc_saw_coeffs

typedef struct bwp_osc_saw_coeffs bwp_osc_saw_coeffs;

Coefficients and related.

bwp_osc_saw_state

typedef struct bwp_osc_saw_state bwp_osc_saw_state;

Internal state and related.

bwp_osc_saw_init()

static inline void bwp_osc_saw_init(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs);

Initializes input parameter values in coeffs.

bwp_osc_saw_set_sample_rate()

static inline void bwp_osc_saw_set_sample_rate(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	float                            sample_rate);

Sets the sample_rate (Hz) value in coeffs.

bwp_osc_saw_reset_coeffs()

static inline void bwp_osc_saw_reset_coeffs(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs);

Resets coefficients in coeffs to assume their target values.

bwp_osc_saw_reset_state()

static inline float bwp_osc_saw_reset_state(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_state * BW_RESTRICT        state,
	float                                  x_0,
	float                                  x_inc_0,
	char                                   is_slave,
	float                                  x_sync_low_0,
	float                                  x_sync_high_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, and x_sync_low_0 and x_sync_high_0 input hard sync signal initial values.

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.

bwp_osc_saw_reset_state_multi()

static inline void bwp_osc_saw_reset_state_multi(
	const bwp_osc_saw_coeffs * BW_RESTRICT              coeffs,
	bwp_osc_saw_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,
	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, and input hard sync signal initial values in the x_sync_low_0 and x_sync_high_0 arrays.

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

bwp_osc_saw_update_coeffs_ctrl()

static inline void bwp_osc_saw_update_coeffs_ctrl(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.

bwp_osc_saw_update_coeffs_audio()

static inline void bwp_osc_saw_update_coeffs_audio(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.

bwp_osc_saw_shape1()

static inline float bwp_osc_saw_shape1(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	float                                  x);

Returns the aliased output that would correspond to the given input sample x and coefficients coeffs, discarding smoothing (i.e., using target coefficient values).

coeffs MUST be at least in the "reset" state.

bwp_osc_saw_shape1_multi()

static inline void bwp_osc_saw_shape1_multi(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	const float *                          x,
	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 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.

bwp_osc_saw_process1*()

static inline float bwp_osc_saw_process1(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_state * BW_RESTRICT        state,
	float                                  x);

static inline float bwp_osc_saw_process1_antialias(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_state * BW_RESTRICT        state,
	float                                  x,
	float                                  x_inc);

static inline float bwp_osc_saw_process1_slave(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_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_saw_process1_antialias_slave(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_state * BW_RESTRICT        state,
	float                                  x,
	float                                  x_inc,
	char                                   x_sync_do,
	float                                  x_sync_low,
	float                                  x_sync_high);

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

In particular:

  • bwp_osc_saw_process1() assumes that antialiasing is disabled and the corresponding phase generator is not a hard sync slave;
  • bwp_osc_saw_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_saw_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_saw_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.

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

bwp_osc_saw_process()

static inline void bwp_osc_saw_process(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	bwp_osc_saw_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,
	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.

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

bwp_osc_saw_process_multi()

static inline void bwp_osc_saw_process_multi(
	bwp_osc_saw_coeffs * BW_RESTRICT                    coeffs,
	bwp_osc_saw_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,
	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.

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

bwp_osc_saw_set_antialiasing()

static inline void bwp_osc_saw_set_antialiasing(
	bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	char                             value);

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

Default value: 0 (off).

bwp_osc_saw_set_sync_phase()

static inline void bwp_osc_saw_set_sync_phase(
	bwp_osc_saw_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.

bwp_osc_saw_coeffs_is_valid()

static inline char bwp_osc_saw_coeffs_is_valid(
	const bwp_osc_saw_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_saw_coeffs.

bwp_osc_saw_state_is_valid()

static inline char bwp_osc_saw_state_is_valid(
	const bwp_osc_saw_coeffs * BW_RESTRICT coeffs,
	const bwp_osc_saw_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_saw_state.

C++ wrapper

BrickworksPro::OscSaw
template<size_t N_CHANNELS>
class OscSaw {
public:
	OscSaw();

	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 * BW_RESTRICT y0 = nullptr);

# ifndef BW_CXX_NO_ARRAY
	void reset(
		float                                       x0,
		float                                       xInc0,
		char                                        isSlave,
		float                                       xSyncLow0,
		float                                       xSyncHigh0,
		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,
		float *                  y0 = nullptr);

# 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> * BW_RESTRICT y0 = nullptr);
# endif

	void shape1(
		const float * x,
		float *       y);

# ifndef BW_CXX_NO_ARRAY
	void shape1(
		std::array<float, N_CHANNELS>               x,
		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,
		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<float *, N_CHANNELS>                  y,
		size_t                                           nSamples);
# endif

	void setAntialiasing(
		bool value);

	void setSyncPhase(
		float value);
...
}

Changelog

  • Version 1.0.0:
    • First release.