Project 2 Experiment 7 – Polyrhythm in ChucK

While preparing audio clips of water dripping in a random way in Ableton Live to use on the second project, I had the idea of trying to create a program that would handle polyrhythm in ChucK. From the start, it was an experiment not supposed to be used on the presentation version of the project because I was happy with the random sounding clips made in Ableton.
The easy to program concurrency capability of ChucK sounded like a relatively easy way to create polyrhythm. My idea was to have a function that each time it was called, the function would run in parallel with the other calls of itself and each call would handle different note timings. For the different timings, tuplets were stored in arrays that would be passed to the function. Another array stored the gain for each note in order to have control over wich beat should be stressed and also to have more control over the feel of the note sequence.
The function ended up looking like this:

fun void sequencer ( int beatArray[], float gainArray[],
float duration, SndBuf sampleName )
{ while ( true) {
for( 0 => int i; i < beatArray.cap(); i++ )
if( beatArray[i] == 1 )
gainArray[i] => sampleName.gain;
0 => sampleName.pos;
duration::second => now;
} } }

Very simple, but it worked as intended. The samples I used to test the program were recorded from a metal bucket with water. Had them in my computer for some time, but hadn’t use them untill writing this chuck code. For the example video, all instances of the function start at the same time and further rhythmic complexity can be added by making the them not share a starting point so they meet each other every certain number of measures.