Debian Codegraph @

examples/otf_06.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 // synchronize to period
19 .5::second => dur T;
20 T - (now % T) => now;
21
22 SinOsc s => JCRev r => dac;
23 .05 => s.gain;
24 .25 => r.mix;
25
26 // scale (in semitones)
27 [ 0, 2, 4, 7, 9 ] @=> int scale[];
28
29 // infinite time loop
30 while( true )
31 {
32 // get note class
33 scale[ Math.random2(0,4) ] => float freq;
34 // get the final freq
35 Std.mtof( 69 + (Math.random2(0,3)*12 + freq) ) => s.freq;
36 // reset phase for extra bandwidth
37 0 => s.phase;
38
39 // advance time
40 // note: Math.randomf() returns value between 0 and 1
41 if( Math.randomf() > .25 ) .25::T => now;
42 else .5::T => now;
43 }