examples/book/digital-artists/chapter2/Listing2.1.ck
raw| 1 | // Listing 2.1 Playing a chromatic scale using Std.mtof() |
| 2 | |
| 3 | // sound chain |
| 4 | TriOsc t => dac; |
| 5 | 0.4 => t.gain; |
| 6 | |
| 7 | // loop |
| 8 | for (0 => int i; i < 127; i++) |
| 9 | { |
| 10 | // (1) Use Std.mtof to convert note number to frequency |
| 11 | Std.mtof(i) => float Hz; // MIDI to Hertz frequency |
| 12 | <<< i, Hz >>>; // print out result |
| 13 | Hz => t.freq; // update frequency // (2) Set oscillator frequency to Hz |
| 14 | 200::ms => now; // advance time |
| 15 | } |