[sdiy] Polyphonic voice allocation algorithm

Olivier Gillet ol.gillet at gmail.com
Tue Jun 24 00:16:19 CEST 2014

Hi Richie,

The code used in all my projects (Shruthi in polychaining mode,
Ambika, MIDIpal "dispatcher" app, Yarns...) is a variant of this:

It supports two modes: cyclic and voice-stealing (aka "piano mode"
because hitting the same note twice will cause it to be allocated to
the same voicecard). Let N be the number of voices.

The cyclic mode is trivial - every time a note on arrives, a counter
is incremented modulo N. The note is played on voice N.

The voice-stealing mode works as follow:

First, there are two data structures:
* A "status" array of size N that stores, for each voicecard, what is
the currently played note and if this note is currently held or
released (gate = on or gate = off). In my implementation, this fits in
8-bit (MSB is gate status, 7 lower bits are MIDI note number).
* A "history" array of size N that stores the order in which the
voicecards have received note on or note off messages. First element =
most recently played or released note.

The procedure for a note on is:

- Check in the status array if there is already a voice playing this
note. If so, retrigger this voice.
- Otherwise, check in the status array if there are voices with gate =
off. If so use the history array to find the least recently released
among them, and allocate to this voice.
- Otherwise (all voices have gate = on), use the history array to find
the least recently triggered voice, and allocated the note to it.

After that, update the status array, and move the selected voice to
the head of the history array.

The procedure for a note off is:

- Search in the status array for the voice to which this note has been
allocated. That's the information we need!
- Clear the gate bit in the status array.
- Move the freshly released voice to the head of the history array.

Everything is O(n).

The "status" array can also be used to lookup to which voicecard we
should route polyphonic aftertouch messages.

This basic data structure can be used for fancy things such as 2x
unison (configure it with N/2, play each note on voice k and voice
k+N/2), polyphony doubling through MIDI chaining (configure it with
2N, if a note gets allocated to voice k < N, play it internally,
otherwise forward it to the MIDI out).

You can see the core note dispatching logic of my polysynth here:


On Mon, Jun 23, 2014 at 11:32 PM, Terry Shultz <thx1138 at earthlink.net> wrote:
> Hi Folks,
> The Microprocessor based Polyphonic keyboard was patented by E-Mu Systems in
> 1976 by Dave Rossum.
> E-Mu licensed this to Oberheim Elec., Sequential Circuits, Shultz Sound
> Desigm. and perhaps a few others I can't remember now.
> They successfully defended this patent against Allen Organs and so forth.
> The Pratt-Read keyboard that E-Mu specified was used by many others,
> Oberheim, Sequential Circuits, PPG, and so forth.
> It was originally implemented on an 8080 processor, but migrated to a Z-80
> at Patent filing time I believe.
> This patent I believe has run out but it should be located in a google
> search.
> Hopefully this helps you as I need to look at my source code to give you an
> exact answer on exact algorithm function.
> It has been many years since I looked at this software.
> best regards,
> Terry Shultz
> On 6/23/2014 1:57 PM, rburnett at richieburnett.co.uk wrote:
>> Hi guys and girls,
>> Does anyone have a link or document that gives a good explanation for a
>> basic polyphonic voice allocation algorithm.  I'm not after anything fancy,
>> just the sort of process that goes on inside a basic mono-timbral polysynth
>> like Roland's Juno series.
>> I know some basic terminology like "voice stealing" and "round robin
>> fashion" but I'm trying to avoid sitting down and going through the thought
>> process of coming up with my own voice allocation algorithm from scratch!
>> Life is too short to spend time re-inventing the wheel when this algorithm
>> has been used for decades and must surely be documented somewhere?
>> I know synths like the Juno 106 had two different poly voice allocation
>> modes on offer.  One of them assigns repetitive same notes to new voices in
>> round-robin fashion so that their release phases can overlap, and the other
>> mode plays the repeating same notes by just retriggering the same module.
>> What I'm really looking for is something like a flowchart, or text
>> description of how the voice allocation decisions are performed.
>> I appreciate that things can get complicated when notes can arrive from
>> local keyboard vs over MIDI, and things like Sustain messages, and
>> multi-timbral setups are considered.  However, I'd like to keep it simple at
>> the moment so that I can just play about with some synthesis options.
>> Thanks in advance for any help,
>> -Richie,
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at dropmix.xs4all.nl
>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy

More information about the Synth-diy mailing list