| 1 |
// more chirping... |
| 2 |
|
| 3 |
// patch with envelope and pan |
| 4 |
SinOsc s => Envelope e => Pan2 p => dac; |
| 5 |
// gain |
| 6 |
.5 => s.gain; |
| 7 |
|
| 8 |
// pan hard left |
| 9 |
-1 => p.pan; |
| 10 |
// call chirp |
| 11 |
chirp( 127, 20, 1::second ); |
| 12 |
|
| 13 |
// wait for envelope to go down |
| 14 |
10::ms => now; |
| 15 |
// pan hard right |
| 16 |
1 => p.pan; |
| 17 |
// call chirp |
| 18 |
chirp( 20, 120, 1::second, 100::ms ); |
| 19 |
|
| 20 |
// wait a second |
| 21 |
1::second => now; |
| 22 |
|
| 23 |
// randomize pan |
| 24 |
Math.random2f( -1, 1 ) => p.pan; |
| 25 |
// call chirp |
| 26 |
chirp( 30, 110, .5::second ); |
| 27 |
|
| 28 |
// wait for envelope to go down |
| 29 |
10::ms => now; |
| 30 |
// pan |
| 31 |
Math.random2f( -1, 1 ) => p.pan; |
| 32 |
// call chirp |
| 33 |
chirp( 110, 30, 1::second, 100::ms ); |
| 34 |
|
| 35 |
// wait a second |
| 36 |
1::second => now; |
| 37 |
|
| 38 |
|
| 39 |
// chirp function |
| 40 |
fun void chirp( float src, float target, dur duration ) |
| 41 |
{ |
| 42 |
// just call the other one with default tinc |
| 43 |
chirp( src, target, duration, 1::ms ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
// chirp function (with tinc) |
| 48 |
fun void chirp( float src, float target, dur duration, dur tinc ) |
| 49 |
{ |
| 50 |
// initialize freq |
| 51 |
src => float freq; |
| 52 |
// find the number of steps |
| 53 |
duration / tinc => float steps; |
| 54 |
// find the inc |
| 55 |
( target - src ) / steps => float inc; |
| 56 |
// counter |
| 57 |
float count; |
| 58 |
// set env |
| 59 |
.01 * duration / second => e.time; |
| 60 |
// open env |
| 61 |
1 => e.keyOn; |
| 62 |
|
| 63 |
// do the actual work over time |
| 64 |
while( count < steps ) |
| 65 |
{ |
| 66 |
// increment the freq |
| 67 |
freq + inc => freq; |
| 68 |
// count |
| 69 |
1 +=> count; |
| 70 |
|
| 71 |
// set the freq |
| 72 |
Std.mtof( freq ) => s.freq; |
| 73 |
|
| 74 |
// advance time |
| 75 |
tinc => now; |
| 76 |
} |
| 77 |
|
| 78 |
// close env |
| 79 |
1 => e.keyOff; |
| 80 |
} |
| 81 |
|