bw_voice_alloc

Basic voice allocator with low/high note priority.

Examples

Here you can download one or more example VST3 plugins for Windows, macOS and Linux. Source code of the audio engine(s) is included in the archive(s).

DescriptionLink
Polyphonic subtractive synth Download
VST® is a trademark of Steinberg Media Technologies GmbH, registered in Europe and other countries.

API

Module type: Utility

bw_voice_alloc_priority

typedef enum {
	bw_voice_alloc_priority_low,
	bw_voice_alloc_priority_high
} bw_voice_alloc_priority;

Note priority:

  • bw_voice_alloc_priority_low: low note priority;
  • bw_voice_alloc_priority_high: high note priority.

bw_voice_alloc_opts

typedef struct {
	bw_voice_alloc_priority priority;

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

	void (*note_off)(
		void * BW_RESTRICT voice,
		float              velocity);

	unsigned char (*get_note)(
		const void * BW_RESTRICT voice);

	char (*is_free)(
		const void * BW_RESTRICT voice);
} bw_voice_alloc_opts;

Voice allocation options:

  • priority: note priority;
  • note_on: note on callback, 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;
  • note_off: note off callback, 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;
  • get_note: callback that returns the note number associated to the given voice;
  • is_free: callback that returns whether the given voice is free (non-0) or not (0);

bw_voice_alloc()

static inline void bw_voice_alloc(
	const bw_voice_alloc_opts * BW_RESTRICT opts,
	bw_note_queue * BW_RESTRICT             queue,
	void * BW_RESTRICT const * BW_RESTRICT  voices,
	size_t                                  n_voices);

It performs voice allocation according to opts and using the events in queue.

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

Changelog

  • Version 1.1.0:
    • Added static inline to bw_voice_alloc().
    • Added support for BW_INCLUDE_WITH_QUOTES and BW_CXX_NO_EXTERN_C.
  • Version 1.0.1:
    • Now using BW_NULL.
  • Version 1.0.0:
    • Specified that velocity can be negative in bw_voice_alloc_opts.
    • Now using size_t instead of BW_SIZE_T.
    • Added const and BW_RESTRICT where needed to callback types in bw_voice_alloc_opts and to bw_voice_alloc().
    • Removed usage of reserved identifiers.
  • Version 0.6.0:
    • Now using BW_SIZE_T to count voices in bw_voice_alloc().
    • Added debugging code.
    • Removed dependency on bw_config.
  • Version 0.5.0:
    • First release.