Debian Codegraph @

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

raw
1 // Listing 5.2 Testing the addOctave function with sound
2
3 // Define addOctave
4 fun int addOctave( int note )
5 {
6 int result;
7 note + 12 => result;
8 return result;
9 }
10
11 // Let's use addOctave for music
12 SinOsc s => dac; // (1) Oscillator so you can hear addOctave function
13 60 => int myNote; // (2) Initial note
14
15 Std.mtof(myNote) => s.freq; // (3) Plays initial note
16 second => now;
17
18 myNote => addOctave => Std.mtof => s.freq; // (4) Plays one octave up
19 second => now;