Debian Codegraph @

examples/otf_02.ck

raw
1 //----------------------------|
2 // on-the-fly synchronization
3 // adapted from Perry's ChucK Drummin' + Ge's sine poops
4 //
5 // authors: Perry Cook ([email protected])
6 // Ge Wang ([email protected])
7 // --------------------|
8 // add one by one into VM (in pretty much any order):
9 //
10 // terminal-1%> chuck --loop
11 // ---
12 // terminal-2%> chuck + otf_01.ck
13 // (anytime later)
14 // terminal-2%> chuck + otf_02.ck
15 // (etc...)
16 //--------------------------------------|
17
18 // this synchronizes to period
19 .5::second => dur T;
20 T - (now % T) => now;
21
22 // construct the patch
23 SndBuf buf => Gain g => dac;
24 // read in the file
25 me.dir() + "data/hihat.wav" => buf.read;
26 // set the gain
27 .25 => g.gain;
28
29 // time loop
30 while( true )
31 {
32 // randomize the gain a bit
33 Math.random2f(.4,.9) => buf.gain;
34
35 // note: Math.randomf() returns value between 0 and 1
36 if( Math.randomf() > 0.875 )
37 {
38 // set play position to beginning
39 0 => buf.pos;
40 // advance time
41 .5::T => now;
42 }
43 else
44 {
45 0 => buf.pos;
46 .25::T => now;
47 0 => buf.pos;
48 .25::T => now;
49 }
50 }