Debian Codegraph @

examples/book/digital-artists/chapter5/Listing5.6.ck

raw
1 // Listing 5.6 Using functions to set oscillator frequencies
2
3 // three oscillators in stereo
4 SqrOsc s => dac.left; // (1) Three square waves, panned left,
5 SqrOsc t => dac; // center,
6 SqrOsc u => dac.right; // and right
7
8 // set gains so we don't overload the dac
9 0.4 => s.gain => t.gain => u.gain; // (2) Sets gains of all three
10
11 // functions for octave and fifth
12 fun float octave( float originalFreq )
13 {
14 return 2.0*originalFreq;
15 }
16
17 fun float fifth( float originalFreq )
18 {
19 return 1.5*originalFreq;
20 }
21
22 // Main program
23 for (100 => float freq; freq < 500; 0.5 +=> freq ) // (3) Sweeps frequency
24 { // from 100 to 500 by 1/2 Hz each step
25 freq => s.freq; // (4) Sets left square wave to freq
26 octave(freq) => t.freq; // (5) Sets center square wave to octave above
27 fifth(freq) => u.freq; // (6) Sets right square wave to fifth above
28 <<< s.freq(), t.freq(), u.freq() >>>;
29 10::ms => now;
30 }