| 1 |
// Listing 8.7 Jazz band: |
| 2 |
// save as "drums.ck" |
| 3 |
|
| 4 |
// sound chain |
| 5 |
SndBuf hihat => dac; // (1) Hi-hat sound for percussion. |
| 6 |
|
| 7 |
// me.dir, one level up to find the /audio directory |
| 8 |
me.dir(-1) + "/audio/hihat_01.wav" => hihat.read; // (2) Reads the wave file. |
| 9 |
|
| 10 |
// parameter setup |
| 11 |
.5 => hihat.gain; |
| 12 |
|
| 13 |
// loop |
| 14 |
while( true ) // (3) Infinite loop. |
| 15 |
{ |
| 16 |
Math.random2f(0.1,.3) => hihat.gain; // (4) Random volume... |
| 17 |
Math.random2f(.9,1.2) => hihat.rate; // (5) ...and pitch (rate). |
| 18 |
// (6) Waits either .2 or .4 seconds |
| 19 |
(Math.random2(1,2) * 0.2) :: second => now; |
| 20 |
0 => hihat.pos; // (7) ...then plays and loops. |
| 21 |
} |