Debian Codegraph @

examples/book/digital-artists/chapter1/Listing1.2.ck

raw
1 // Listing 1.2 Sine wave music
2
3 /* Sine Music // (1) comment block; ChucK ignores this.
4 by ChucK Programmer
5 January 2025 */
6 SinOsc s => dac;
7
8 // Play one note // (2) Connects sine oscillator to dac
9 220 => s.freq; // (3) Sets the gain to 1.0 and frequency to 220 Hz.
10 1.0 => s.gain;
11 0.3 :: second => now; // Let this run for 0.3 second by ChucKing it to
12 // now (advance time).
13
14 0.0 => s.gain; // (4) Makes your sine oscillator silent
15 // for 0.3 seconds to separate it
16 0.3 :: second => now; // from the next note.
17
18 // Play another note, same pitch
19 1.0 => s.gain; // (5) Repeats the process of
20 0.3 :: second => now; // blocks B and D.
21 0.0 => s.gain;
22 0.3 :: second => now;
23
24 // Play two more notes, higher, less loud
25 330 => s.freq; // (6) Repeats the same two-note
26 0.3 => s.gain; // pattern of blocks B, D, and E
27 0.3 :: second => now; // but with a different frequency
28 // (pitch) and gain (loudness).
29 0.0 => s.gain;
30 0.3 :: second => now;
31
32 0.3 => s.gain;
33 0.3 :: second => now;
34
35 0.0 => s.gain;
36 0.3 :: second => now;