Archive for October 2011
polyphony II
whew! well, this is embarassing.
i haven’t been afforded much in the way of an environment conducive to concentration lately, having had a relatively hectic and physically demanding week. my polyphony code sat there day after day with me being unable or unwilling to address it.
i’ve finally hammered the thing out (i think) and it is really quite simple. only the most elementary sorting is required once one has a scheme to address it.
my scheme has some necessities others may not have – it’s a module for synthedit to be used for various applications. it needed to have two operational modes: a conventional “synth” polyphony mode, and a “physical” polyphony mode, where the same voice is used for recurring pitches (in synth polyphony, the same note/pitch can be present on all voices, eg. retriggering a tom with a long release.. you wouldn’t want this behaviour for eg. a piano..)
the other suggestion is to use an array for recording which voice was most recently released. if you retrigger one key polyphonically, you want it to “round robin” the voices so that the release is as long as possible. my application, being a component for a modular environment, is limited by only operating on gate on/off events.. it doesn’t receive information on the release stage.
so my ‘voice age’ algorithm works like this: ‘age’ is incremented so that the highest coefficient indicates the newest voice – when a noteoff occurs, the highest age value is discerned, this value is incremented by one and applied to the voice being released. because the variable is only used for sorting when a noteon event occurs, it is at this time that i sort the lowest age value and subtract it from all the ages to keep things from overflowing.
i had tried two kookier schemes precedent to this involving the position of each voice in the held notes stack. the final solution is a lot neater and the only one that satisfied my desire for orderliness as well as functionality. it is quite dizzying to consider how convoluted the solution was before determining this method! 🙂
polyphony algorithm
i’m posting this because i found very little reference on the logistics of writing a polyphony system (there’s one thread on kvr that’s worth reading). i thought i’d mention something about it.
writing a sorting algorithm can be aggravating. it’s such an elementary programming skill that one feels as if one should have it mastered even without any experience. of course, you can write programs for years without needing to use one, then when you do, you’re unfamiliar with the terminology. it can be challenging if you aren’t afforded peacable concentration and are pressured to produce.
my polyphony hint: don’t start writing code to handle noteon and noteoff. for conventional keyboard performance, the first thing to implement is a dynamic array of the currently held notes. activating and deactivating voices will reference this list (eg. to recall held notes at key release), so start with that (i’m still not sure what the correct term for this kind of data structure is.. stack, zipper, dynamic array..)
a bit obvious really 🙂