Brickworks > API documentation > bw_phase_gen

bw_phase_gen

Description

Phase generator with portamento and exponential frequency modulation.

It outputs a normalized phase signal (range [0.f, 1.f]).

Info

Module type: dsp

Version: 1.1.0

Requires:

API

bw_phase_gen_coeffs

typedef struct bw_phase_gen_coeffs bw_phase_gen_coeffs;

Coefficients and related.

bw_phase_gen_state

typedef struct bw_phase_gen_state bw_phase_gen_state;

Internal state and related.

bw_phase_gen_init()

static inline void bw_phase_gen_init(
	bw_phase_gen_coeffs * BW_RESTRICT coeffs);

Initializes input parameter values in coeffs.

bw_phase_gen_set_sample_rate()

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.

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

bw_phase_gen_reset_state()

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.

bw_phase_gen_reset_state_multi()

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 states 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 BW_NULL.

bw_phase_gen_update_coeffs_ctrl()

static inline void bw_phase_gen_update_coeffs_ctrl(
	bw_phase_gen_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.

bw_phase_gen_update_coeffs_audio()

static inline void bw_phase_gen_update_coeffs_audio(
	bw_phase_gen_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.

bw_phase_gen_process1*()

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

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 BW_NULL, it is used as a source of exponential frequency modulation (scale 1.f/octave).

If y_inc is not BW_NULL, it is filled with phase increment values.

bw_phase_gen_process_multi()

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 states (control and audio rate).

If x_mod and the channel-specific element are not BW_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 BW_NULL, this is filled with phase increment values for that channel.

bw_phase_gen_set_frequency()

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.

bw_phase_gen_set_portamento_tau()

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.

bw_phase_gen_coeffs_is_valid()

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.

bw_phase_gen_state_is_valid()

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

C++ wrapper

Brickworks::PhaseGen
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);

#ifndef BW_CXX_NO_ARRAY
	void reset(
		float                                       phase0,
		std::array<float, N_CHANNELS> * BW_RESTRICT y0,
		std::array<float, N_CHANNELS> * BW_RESTRICT yInc0);
#endif

	void reset(
		const float * phase0,
		float *       y0 = nullptr,
		float *       yInc0 = nullptr);

#ifndef BW_CXX_NO_ARRAY
	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);
#endif

	void process(
		const float * const * xMod,
		float * const *       y,
		float * const *       yInc,
		size_t                nSamples);

#ifndef BW_CXX_NO_ARRAY
	void process(
		std::array<const float *, N_CHANNELS> xMod,
		std::array<float *, N_CHANNELS>       y,
		std::array<float *, N_CHANNELS>       yInc,
		size_t                                nSamples);
#endif

	void setFrequency(
		float value);

	void setPortamentoTau(
		float value);
...
}

ChangeLog