| 1 |
// Listing 1.8 Listing 1.8 Playing notes with integer variables |
| 2 |
|
| 3 |
/* Sine Music with integer variables |
| 4 |
by ChucK Programmer |
| 5 |
January 2025 */ |
| 6 |
|
| 7 |
SinOsc s => dac; |
| 8 |
|
| 9 |
220 => int myPitch; // (1) Declares and initializes an integer variable called myPitch |
| 10 |
|
| 11 |
1 => int onGain; // (2) Declares and initializes two integers for |
| 12 |
0 => int offGain; // controlling gain |
| 13 |
|
| 14 |
// Play one note // (3) Plays a note using your new integer variables |
| 15 |
myPitch => s.freq; |
| 16 |
onGain => s.gain; |
| 17 |
0.3 :: second => now; |
| 18 |
|
| 19 |
offGain => s.gain; // (4) Turns off the sound of your oscillator |
| 20 |
0.3 :: second => now; // to separate the notes |
| 21 |
|
| 22 |
1 *=> myPitch; // (5) Multiplies your pitch by 2, in place |
| 23 |
|
| 24 |
// Play another note, with a higher pitch |
| 25 |
myPitch => s.freq; // (6) Sets frequency and turns on |
| 26 |
onGain => s.gain; // oscillator, to start your 2nd note |
| 27 |
0.3 :: second => now; |
| 28 |
|
| 29 |
offGain => s.gain; // (7) Turns off the sound of your oscillator |
| 30 |
0.3 :: second => now; // again to end the 2nd note |
| 31 |
|
| 32 |
|