Debian Codegraph @

examples/basic/chirp.ck

raw
1 // po-tweet!
2
3 // patch
4 SinOsc s => dac;
5 // gain
6 .4 => s.gain;
7
8 // call chirp
9 chirp( 127, 20, 1::second );
10
11 // call chirp (with tinc)
12 chirp( 20, 120, 1.5::second, 100::ms );
13
14 // chirp function
15 fun void chirp( float src, float target, dur duration )
16 {
17 chirp( src, target, duration, 1::ms );
18 }
19
20 // chirp function (with tinc)
21 fun void chirp( float src, float target, dur duration, dur tinc )
22 {
23 // initialize freq
24 src => float freq;
25 // find the number of steps
26 duration / tinc => float steps;
27 // find the inc
28 ( target - src ) / steps => float inc;
29 // counter
30 float count;
31
32 // do the actual work over time
33 while( count < steps )
34 {
35 // increment the freq
36 freq + inc => freq;
37 // count
38 1 +=> count;
39
40 // set the freq
41 Std.mtof( freq ) => s.freq;
42
43 // advance time
44 tinc => now;
45 }
46 }
47