| 1 |
// Listing 2.3 Random music using the Math Library |
| 2 |
|
| 3 |
// Some random square wave music! |
| 4 |
SqrOsc s => dac; // Makes a SinOsc to play your random notes. |
| 5 |
for (0 => int i; i < 16; i++) // (1) for loop plays 16 notes. |
| 6 |
{ |
| 7 |
Math.random2(48,72) => int myNote; // (2) Random integer note number (C3-C5). |
| 8 |
Math.random2f(0.05,0.9) => float myGain; // (3) Random gain from .05 to .9. |
| 9 |
<<< myNote, myGain >>>; // (4) Prints current note and gain. |
| 10 |
Std.mtof(myNote) => s.freq; // (5) Sets oscillator frequency and gain. |
| 11 |
myGain => s.gain; |
| 12 |
0.2 :: second => now; // (6) Lets each note sound for 1/5 second. |
| 13 |
} |
| 14 |
|