bwp_voice_alloc

Advanced version of bw_voice_alloc with more and different priority modes, unison, and more.

Examples

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

Contact us

API

Module type: Utility

bwp_voice_alloc_priority

typedef enum {
	bwp_voice_alloc_priority_none,
	bwp_voice_alloc_priority_low,
	bwp_voice_alloc_priority_high,
	bwp_voice_alloc_priority_old,
	bwp_voice_alloc_priority_new
} bwp_voice_alloc_priority;

Note priority:

  • bwp_voice_alloc_priority_none: no priority, do nothing;
  • bwp_voice_alloc_priority_low: low note priority;
  • bwp_voice_alloc_priority_high: high note priority;
  • bwp_voice_alloc_priority_old: old note priority;
  • bwp_voice_alloc_priority_new: new note priority.

bwp_voice_alloc_unison_mode

typedef enum {
	bwp_voice_alloc_unison_mode_off,
	bwp_voice_alloc_unison_mode_fill
} bwp_voice_alloc_unison_mode;

Unison mode:

  • bwp_voice_alloc_unison_mode_off: unison off;
  • bwp_voice_alloc_unison_mode_fill: fill maximum number of voices.

bwp_voice_alloc_order

typedef enum {
	bwp_voice_alloc_order_first_to_last,
	bwp_voice_alloc_order_round_robin
} bwp_voice_alloc_order;

Allocation order:

  • bwp_voice_alloc_order_first_to_last: first to last voice;
  • bwp_voice_alloc_order_round_robin: round robin.

bwp_voice_alloc

typedef struct bwp_voice_alloc bwp_voice_alloc;

Voice allocator.

bwp_voice_alloc_init()

static inline void bwp_voice_alloc_init(
	bwp_voice_alloc * BW_RESTRICT alloc);

Initializes option values in alloc.

Call this on alloc before other functions in this API.

bwp_voice_alloc_reset()

static inline void bwp_voice_alloc_reset(
	bwp_voice_alloc * BW_RESTRICT alloc);

Resets alloc to its initial state.

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

bwp_voice_alloc_process()

static inline void bwp_voice_alloc_process(
	bwp_voice_alloc * BW_RESTRICT                    alloc,
	const bw_note_queue * BW_RESTRICT                queue,
	void * BW_RESTRICT const * BW_RESTRICT           voices,
	size_t                                           n_voices);

Lets alloc perform voice allocation using the events in queue.

voices is the array of opaque voice pointers and n_voices indicates the number of elements in voices.

n_voices must be greater than or equal to the current poliphony setting. Only voices with index 0 to polyphony setting minus 1 will be considered for allocation.

bwp_voice_alloc_set_priority_busy()

static inline void bwp_voice_alloc_set_priority_busy(
	bwp_voice_alloc * BW_RESTRICT alloc,
	bwp_voice_alloc_priority      value);

Sets note priority when stealing from busy voices to value in alloc.

Default value: bwp_voice_alloc_priority_none.

bwp_voice_alloc_set_priority_releasing()

static inline void bwp_voice_alloc_set_priority_releasing(
	bwp_voice_alloc * BW_RESTRICT alloc,
	bwp_voice_alloc_priority      value);

Sets note priority when stealing from releasing voices to value in alloc.

Default value: bwp_voice_alloc_priority_none.

bwp_voice_alloc_set_priority_reassign()

static inline void bwp_voice_alloc_set_priority_reassign(
	bwp_voice_alloc * BW_RESTRICT alloc,
	bwp_voice_alloc_priority      value);

Sets note priority when reassigning pressed but not currently playing notes (typically after a note off event) to value in alloc.

Default value: bwp_voice_alloc_priority_none.

bwp_voice_alloc_set_unison_mode()

static inline void bwp_voice_alloc_set_unison_mode(
	bwp_voice_alloc * BW_RESTRICT alloc,
	bwp_voice_alloc_unison_mode   value);

Sets the unison mode to value in alloc.

Default value: bwp_voice_alloc_unison_mode_off.

bwp_voice_alloc_set_polyphony()

static inline void bwp_voice_alloc_set_polyphony(
	bwp_voice_alloc * BW_RESTRICT alloc,
	size_t                        value);

Sets the current poliphony to value in alloc.

value must be strictly positive.

Default value: 1.

bwp_voice_alloc_set_prefer_already_playing()

static inline void bwp_voice_alloc_set_prefer_already_playing(
	bwp_voice_alloc * BW_RESTRICT alloc,
	char                          value);

Sets whether alloc should prefer reusing voices already playing the same note over allocating free voices or stealing other voices (value non-0) or not (0).

Default value: non-0 (prefer reusing voices already playing the note).

bwp_voice_alloc_set_prefer_steal_releasing()

static inline void bwp_voice_alloc_set_prefer_steal_releasing(
	bwp_voice_alloc * BW_RESTRICT alloc,
	char                          value);

Sets whether alloc should prefer stealing releasing voices over allocating free voices (value non-0) or not (0).

Default value: 0 (prefer allocating free voices).

bwp_voice_alloc_set_order()

static inline void bwp_voice_alloc_set_order(
	bwp_voice_alloc * BW_RESTRICT alloc,
	bwp_voice_alloc_order         value);

Sets the allocation order value in alloc.

Default value: bwp_voice_alloc_order_first_to_last.

bwp_voice_alloc_set_note_on_cb()

static inline void bwp_voice_alloc_set_note_on_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	void (*value)(
		void * BW_RESTRICT voice,
		unsigned char      note,
		float              velocity));

Sets the note on callback to value in alloc, where voice is an opaque pointer to the chosen voice, note is the note number, and velocity is the note velocity in [0.f, 1.f] or otherwise negative to indicate unknown / not available.

This must be set to an actual callback before calling bwp_voice_alloc_process().

bwp_voice_alloc_set_note_off_cb()

static inline void bwp_voice_alloc_set_note_off_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	void (*value)(
		void * BW_RESTRICT voice,
		float              velocity));

Sets the note on callback to value in alloc, where voice is an opaque pointer to the chosen voice and velocity is the note velocity in [0.f, 1.f] or otherwise negative to indicate unknown / not available.

This must be set to an actual callback before calling bwp_voice_alloc_process().

bwp_voice_alloc_set_get_note_cb()

static inline void bwp_voice_alloc_set_get_note_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	unsigned char (*value)(
		const void * BW_RESTRICT voice));

Sets the get note callback to value in alloc, which returns the note number associated to the given voice.

This must be set to an actual callback before calling bwp_voice_alloc_process().

bwp_voice_alloc_set_get_gate_cb()

static inline void bwp_voice_alloc_set_get_gate_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	char (*value)(
		const void * BW_RESTRICT voice));

Sets the get gate callback to value in alloc, which returns whether voice's gate is on (non-0) or not (0).

This must be set to an actual callback before calling bwp_voice_alloc_process().

bwp_voice_alloc_set_is_free_cb()

static inline void bwp_voice_alloc_set_is_free_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	char (*value)(
		const void * BW_RESTRICT voice));

Sets the is free callback to value in alloc, which returns whether the given voice is free (non-0) or not (0).

This must be set to an actual callback before calling bwp_voice_alloc_process().

bwp_voice_alloc_set_subpriority_busy_cb()

static inline void bwp_voice_alloc_set_subpriority_busy_cb(
	bwp_voice_alloc * BW_RESTRICT alloc,
	char (*value)(
		const void * BW_RESTRICT voice));

Sets the subpriority busy callback to value in alloc, which returns a value specifying the voice's busy subpriority. Busy voices with higher busy subpriorities are stolen before other busy voices with lower subpriorities, no matter the chosen busy note priority, as long as it is not bwp_voice_alloc_priority_none.

This callback is optional and can be set to BW_NULL.

bwp_voice_alloc_is_valid()

static inline char bwp_voice_alloc_is_valid(
	const bwp_voice_alloc * BW_RESTRICT alloc);

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

C++ wrapper

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

	void reset();

	void process(
		const bw_note_queue * BW_RESTRICT      queue,
		void * BW_RESTRICT const * BW_RESTRICT voices,
		size_t                                 n_voices);

	void setPriorityBusy(
		bwp_voice_alloc_priority value);

	void setPriorityReleasing(
		bwp_voice_alloc_priority value);

	void setPriorityReassign(
		bwp_voice_alloc_priority value);

	void setUnisonMode(
		bwp_voice_alloc_unison_mode value);

	void setPolyphony(
		size_t value);

	void setPreferAlreadyPlaying(
		char value);

	void setPreferStealReleasing(
		char value);

	void setOrder(
		bwp_voice_alloc_order value);

	void setNoteOnCb(
		void (*value)(
			void * BW_RESTRICT voice,
			unsigned char      note,
			float              velocity));

	void setNoteOffCb(
		void (*value)(
			void * BW_RESTRICT voice,
			float              velocity));

	void setGetNoteCb(
		unsigned char (*value)(
			const void * BW_RESTRICT voice));

	void setGetGateCb(
		char (*value)(
			const void * BW_RESTRICT voice));

	void setIsFreeCb(
		char (*value)(
			const void * BW_RESTRICT voice));

	void setSubpriorityBusyCb(
		char (*value)(
			const void * BW_RESTRICT voice));
...
}

Changelog

  • Version 1.0.0:
    • First release.