Debian Codegraph @

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

raw
1 // Listing 6.4 Simple clarinet synthesis with Envelope applied to SqrOsc
2
3 // Simple Clarinet Synthesis
4
5 // Envelope applied to SqrOsc
6 SqrOsc clar => Envelope env => dac; // (1) Square wave mimics Clarinet waveform.
7
8 // initial note frequency (musical A)
9 55.0 => clar.freq; // (2) Sets initial pitch.
10
11 // play up the overtone series
12 while (clar.freq() < 441.0) // (3) Loops over three octaves of pitches.
13 {
14 // trigger envelope
15 1 => env.keyOn; // (4) Envelope.keyOn starts note.
16
17 // hang out a bit
18 0.2 :: second => now;
19
20 // tell envelope to ramp down
21 1 => env.keyOff; // (5) Envelope.keyOff ends note.
22
23 // hang out some more
24 0.2 :: second => now;
25
26 // next note up the overtone series
27 clar.freq() + 55.0 => clar.freq; // (6) Increases pitch, climbing up harmonic series.
28 }