Debian Codegraph @

examples/book/digital-artists/chapter6/Listing6.15.ck

raw
1 // Listing 6.15 Musical fun with a resonant filter and three delay lines
2
3 // Fun with UGens! By UG dude, Oct 14, 2020
4 // Impulse-excited resonant filter drives
5 // three delay lines, fed back to themselves
6 Impulse imp => ResonZ rez => Gain input => dac;
7 // (1) Direct path of resonant filtered impulse.
8
9 100 => rez.Q;
10 100 => rez.gain;
11 1.0 => input.gain;
12
13 // We can make arrays of UGens, too
14 Delay del[3]; // (2) Array of three delay lines.
15
16 // Let's have some stereo (3) Left, right, center delay outputs.
17 input => del[0] => dac.left;
18 input => del[1] => dac;
19 input => del[2] => dac.right;
20
21 // (4) Set up all the delay lines
22 for (0 => int i; i < 3; i++) {
23 del[i] => del[i];
24 0.6 => del[i].gain;
25 // (5) Each delay time is different but related.
26 (0.8 + i*0.3) :: second => del[i].max => del[i].delay;
27 }
28
29 // Define note array for our song
30 // (6) Array of notes that you'll draw from.
31 [60, 64, 65, 67, 70, 72] @=> int notes[];
32 notes.cap() - 1 => int numNotes;
33
34 // Let the fun begin! (and continue forever)
35 while (1) {
36 // (7) Play a random note (resonant filter frequency).
37 Std.mtof(notes[Math.random2(0,numNotes)]) => rez.freq;
38 1.0 => imp.next; // (8) Fires impulse (output 1 on next sample).
39 0.4 :: second => now;
40 }