Snare.ck

From CSWiki
Jump to: navigation, search
// snare.ck
// constructing a percussion set
// Rasmus Kaj program implemented by Gary Williams

60::second / 125.0 => dur t4;
t4 / 2.0 => dur t8;
t4 / 4.0 => dur t16;
t4 / 8.0 => dur t32;
t4 * 2.0 => dur t2;
t4 * 4.0 => dur t1;

fun void taktpos(dur module, dur offset) {
    module - ((now - offset) % module) => now;
}

// snare drum
sndbuf snare => dac;
"data/snare.wav" => snare.read;
// silence it for now
0 => snare.gain;

while(true)
{
    taktpos(t1, t1 - t8);
    0 => snare.pos;
    std.rand2f( .5, .8 ) => snare.gain;
    t16 => now;
    0 => snare.pos;

    t16 + t4 => now;
    0 => snare.pos;
    t2 => now;
    0 => snare.pos;
}