bwp_trig_v2

Periodic trigger.

Examples

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

Contact us

API

Module type: Utility

bwp_trig

typedef struct bwp_trig_v2 bwp_trig_v2;

Trigger object.

bwp_trig_v2_init()

static inline void bwp_trig_v2_init(
	bwp_trig_v2 * BW_RESTRICT trig);

Initializes option values in trig.

Call this on trig before other functions in this API.

bwp_trig_v2_set_sample_rate()

static inline void bwp_trig_v2_set_sample_rate(
	bwp_trig_v2 * BW_RESTRICT trig,
	float                     sample_rate);

Sets the sample_rate (Hz) value in trig.

This function must be called at least once before calling bwp_trig_v2_reset().

bwp_trig_v2_reset()

static inline void bwp_trig_v2_reset(
	bwp_trig_v2 * BW_RESTRICT trig);

Resets trig to its initial state.

This function must be called at least once after each call to bwp_trig_v2_set_sample_rate() and at least once before the first call bwp_trig_v2_process() after a call to bwp_trig_v2_set_sample_rate().

bwp_trig_v2_process()

static inline void bwp_trig_v2_process(
	bwp_trig_v2 * BW_RESTRICT trig,
	size_t                    n_samples);

Lets trig advance by n_samples samples.

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_sync()

static inline void bwp_trig_v2_sync(
	bwp_trig_v2 * BW_RESTRICT trig,
	uint64_t                  phase);

Syncs trig with an external trig phase of range [0, UINT64_MAX], covering two periods of trig's own phase (this in order to take swing into account).

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_set_frequency()

static inline void bwp_trig_v2_set_frequency(
	bwp_trig_v2 * BW_RESTRICT trig,
	float                     value);

Sets the triggering frequency value (Hz) in trig.

Valid range: [0.f, half the sample_rate that is/will be passed to bwp_trig_v2_set_sample_rate()].

Default value: 0.f.

bwp_trig_v2_set_swing()

static inline void bwp_trig_v2_set_swing(
	bwp_trig_v2 * BW_RESTRICT trig,
	float                     value);

Sets the swing value (%) in trig.

This setting controls the duration of two successive periods, so that the duration of the first is value % the duration of the both together, which stays constant.

The actual value used internally is however limited so that the instantaneous frequency does not exceed half the sample_rate that is/will be passed to bwp_trig_v2_set_sample_rate().

Valid range: [0.f, 100.f].

Default value: 50.f.

bwp_trig_v2_get_samples_to_next()

static inline size_t bwp_trig_v2_get_samples_to_next(
	bwp_trig_v2 * BW_RESTRICT trig);

Returns the number of samples before the next trigger event from trig, given its current settings. If the current triggering frequency in very small, it returns SIZE_MAX.

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_get_samples_to_next_div()

static inline size_t bwp_trig_v2_get_samples_to_next_div(
	bwp_trig_v2 * BW_RESTRICT trig,
	uint64_t                  factor);

Returns the number of samples before the next trigger event from trig, given its current settings but excluding swing, and with frequency multiplied by factor. If such triggering frequency in very small, it returns SIZE_MAX.

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_set_phase()

static inline void bwp_trig_v2_set_phase(
	bwp_trig_v2 * BW_RESTRICT trig,
	uint64_t                  value);

Sets the current phase to value (range [0, UINT64_MAX]) in trig.

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_get_phase()

static inline uint64_t bwp_trig_v2_get_phase(
	bwp_trig_v2 * BW_RESTRICT trig);

Gets trig's current phase (range [0, UINT64_MAX]).

This function must not be called before calling bwp_trig_v2_reset().

bwp_trig_v2_is_valid()

static inline char bwp_trig_v2_is_valid(
	bwp_trig_v2 * BW_RESTRICT trig);

Tries to determine whether trig 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.

trig must at least point to a readable memory block of size greater than or equal to that of bwp_trig.

C++ wrapper

BrickworksPro::TrigV2
class TrigV2 {
public:
	TrigV2();

	void setSampleRate(
		float sampleRate);

	void reset();

	void process(
		size_t nSamples);

	void sync(
		uint64_t phase);

	void setFrequency(
		float value);

	void setSwing(
		float value);

	size_t getSamplesToNext();

	size_t getSamplesToNextDiv(
		uint64_t factor);

	void setPhase(
		uint64_t value);

	uint64_t getPhase();
...
}

Changelog

  • Version 2.0.0:
    • Added bwp_trig_v2_set_swing(), bwp_trig_v2_get_samples_to_next_div(), bwp_trig_v2_set_phase(), and bwp_trig_v2_get_phase().
    • Fixed typo in the documentation of bwp_trig_is_valid().
    • Clarified documentation overall.
  • Version 1.0.0:
    • First release.