Debian Codegraph @

examples/otf_07.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 => JCRev r => dac;
24 me.dir() + "data/snare.wav" => buf.read;
25 .5 => g.gain;
26 .05 => r.mix;
27
28 // where we actually want to start (in # of sample frames)
29 25 => int where;
30
31 // time loop
32 while( true )
33 {
34 // randomize the gain a bit
35 Math.random2f(.8,.9) => buf.gain;
36
37 // note: Math.randomf() returns value between 0 and 1
38 if( Math.randomf() > .75 )
39 {
40 0 => int i;
41 while( i < 8 )
42 {
43 // gradually increase gain
44 i / 8.0 => buf.gain;
45 // set play position
46 where => buf.pos;
47
48 // advance time
49 (1.0/8.0)::T => now;
50 // increment loop counter
51 i++;
52 }
53
54 while( i > 0 )
55 {
56 i / 8.0 => buf.gain;
57 where => buf.pos;
58 (1.0/8.0)::T => now;
59 i--;
60 }
61 }
62 else
63 {
64 .9 => buf.gain;
65 where => buf.pos;
66 .25::T => now;
67 .3 => buf.gain;
68 where => buf.pos;
69 .25::T => now;
70 .3 => buf.gain;
71 where => buf.pos;
72 .25::T => now;
73
74 .9 => buf.gain;
75 where => buf.pos;
76 .25::T => now;
77 .3 => buf.gain;
78 where => buf.pos;
79 .25::T => now;
80 .3 => buf.gain;
81 where => buf.pos;
82 .25::T => now;
83
84 .9 => buf.gain;
85 where => buf.pos;
86 .25::T => now;
87 .3 => buf.gain;
88 where => buf.pos;
89 .25::T => now;
90 }
91 }