Debian Codegraph @

examples/book/digital-artists/chapter8/Listing8.1.ck

raw
1 //Listing 8.1 Basic concurrency example, print with sound
2
3 // function foo
4 fun void foo()
5 { // (1) Defines a function foo.
6 // sound for foo process
7 Impulse foo => ResonZ rez => dac.left;
8 800.0 => rez.freq; // (2) foo will make pops at 800 Hz
9 50 => rez.Q;
10 // infinite time loop
11 while( true )
12 {
13 // print and make sound
14 <<< "foo!", "" >>>; // (3) ...and print itself out...
15 100 => foo.next;
16 // advance time
17 250::ms => now; // (4) ...every 1/4 second.
18 }
19 }
20
21 fun void bar() // function bar
22 { // (5) Function bar...
23 // sound for bar process
24 Impulse bar => ResonZ rez => dac.right;
25 700.0 => rez.freq; // (6) ...will make pops at 700 Hz...
26 50 => rez.Q;
27 while( true ) // infinite time loop
28 {
29 // print and make sound
30 <<< "BAAAAAAAR!!!", "" >>>; // (7) ...and print out something different from foo...
31 100 => bar.next;
32 // advance time
33 1::second => now; // (8) ...every second.
34 }
35 }
36
37 // spork foo() and bar() each on a child shred
38 spork ~ foo(); // (9) Starts foo by sporking it.
39 spork ~ bar(); // (10) Starts bar by sporking it.
40
41 // infinite time loop to serve as a parent shred
42 while( true ) 1::second => now; // (11) Infinite parent loop, so
43 // children foo and bar can run.