// patch SndBuf sounds[4]; // read in "special:dope" => sounds[0].read; "special:ahh" => sounds[1].read; "special:eee" => sounds[2].read; "special:ooo" => sounds[3].read; // ... for( int i; i < sounds.size(); i++ ) { // connect sounds[i] => dac; // silence for now 0 => sounds[i].gain; } [ [ .5, 0.1, 0.4, 0.0 ], [ .25, .25, .25, .25 ], [ 0.0, .65, .25, .1 ], [ .1, .2, .7, 0 ] ] @=> float table[][]; // current state 0 => int state; // go while( true ) { // generate Std.rand2f(0,1) => float prob; // sum 0 => float sum; // find transition for( int i; i < table[state].size(); i++ ) { // sum probs we've seen so far table[state][i] +=> sum; // check if( sum > prob ) { // i is the state to transition to i => state; // break out of for break; } } // sound 0 => sounds[state].pos; 1 => sounds[state].gain; // advance 200::ms => now; }