| 1 |
// Listing 5.7 Using a swell function to ramp oscillator volume up and down |
| 2 |
|
| 3 |
// swell function, operates on any type of UGen |
| 4 |
fun void swell(UGen osc, float begin, float end, float step) |
| 5 |
{ // (1) swell function definition |
| 6 |
float val; |
| 7 |
|
| 8 |
// swell up volume |
| 9 |
for (begin => val; val < end; step +=> val) // (2) for loop to ramp up volume |
| 10 |
{ |
| 11 |
val => osc.gain; |
| 12 |
0.01 :: second => now; |
| 13 |
} |
| 14 |
|
| 15 |
// swell down volume |
| 16 |
while (val > begin) // (3) while loop to ramp it back down |
| 17 |
{ |
| 18 |
val => osc.gain; |
| 19 |
step -=> val; |
| 20 |
0.01:: second => now; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
<<< "This code does nothing by itself.", "Run Listing5.8.ck" >>>; |
| 25 |
|