Debian Codegraph @

examples/extend/chugraph.ck

raw
1 // name: chugraph.ck
2 // desc: pronounced "chu-graph" -- rhymes with "chew-graph"
3 // create new UGens by compositing existing UGens!
4 // note: (chuck-1.4.1.0 and up) "Chubgraph" deprecated; use "Chugraph"
5 // BTW deprecated Chubgraph rhymes with "subgraph"
6
7 // make a plucked string
8 class PluckedString extends Chugraph // Chubgraph
9 {
10 // karplus + strong plucked string filter
11 // Ge Wang ([email protected])
12
13 Noise imp => OneZero lowpass => outlet;
14 lowpass => DelayA delay => lowpass;
15
16 .99999 => float R;
17 1/220 => float L;
18 -1 => lowpass.zero;
19 220 => freq;
20 0 => imp.gain;
21
22 fun float freq( float f )
23 {
24 // delay length
25 1/f => L;
26 // set delay length
27 L::second => delay.delay;
28 // set gain
29 Math.pow( R, L ) => delay.gain;
30 // return frequency through
31 return f;
32 }
33
34 fun void pluck( dur ringDur )
35 {
36 // turn on the noise...
37 1 => imp.gain;
38 // for one delay length
39 L::second => now;
40 // turn off the noise
41 0 => imp.gain;
42 // let it ring
43 ringDur => now;
44 }
45 }
46
47 // instantiate three chugraphs
48 PluckedString ps[3];
49 // connect as any other UGen
50 for( int i; i < ps.size(); i++ ) ps[i] => dac;
51 // ring duration
52 2::second => dur ringDur;
53
54 // infinite time loop
55 while( true )
56 {
57 // iterate over plucked strings
58 for( int i; i < ps.size(); i++ )
59 {
60 // randomize pitch
61 Math.random2( 36, 72 ) => Std.mtof => ps[i].freq;
62 // spork the pluck
63 spork ~ ps[i].pluck( 2*ringDur );
64 // wait a bit
65 0.25::second => now;
66 }
67
68 // let ring...
69 ringDur => now;
70 }