It is frequently desirable to automate the selection of voices to associate with individual tasks (such as notes to play). For example, a musician playing at a keyboard can't practically choose which voice should go with each note played. To automate voice selection we need a voice allocation algorithm, to be used as shown in Figure 4.9.
Armed with a suitable voice allocation algorithm, the control source need not concern itself with the detail of which voice is taking care of which task; algorithmic note generators and sequencers frequently rely on this. On the other hand, musical writing for ensembles frequently specifies explicitly which instrument plays which note, so that the notes will connect to each other end-to-end in a desirable way.
One simple voice allocation algorithm works as shown in Figure 4.10. Here we suppose that the voice bank has only two voices, and we try to allocate voices for the tasks , , , and . Things go smoothly until task comes along, but then we see no free voices (they are taken up by and ). We could now elect either to drop task , or else to steal the voice of either task or . In practice the best choice is usually to steal one. In this particular example, we chose to steal the voice of the oldest task, .
If we happen to know the length of the tasks and at the outset of task , we may be able to make a better choice of which voice to steal. In this example it might have been better to steal from , so that and would be playing together at the end and not alone. In some situations this information will be available when the choice must be made, and in some (live keyboard input, for example) it will not.