File: chirp.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (47 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// po-tweet!

// patch
SinOsc s => dac;
// gain
.4 => s.gain;

// call chirp
chirp( 127, 20, 1::second );

// call chirp (with tinc)
chirp( 20, 120, 1.5::second, 100::ms );

// chirp function
fun void chirp( float src, float target, dur duration )
{
    chirp( src, target, duration, 1::ms );
}

// chirp function (with tinc)
fun void chirp( float src, float target, dur duration, dur tinc )
{
    // initialize freq
    src => float freq;
    // find the number of steps
    duration / tinc => float steps;
    // find the inc
    ( target - src ) / steps => float inc;
    // counter
    float count;

    // do the actual work over time
    while( count < steps )
    {
        // increment the freq
        freq + inc => freq;
        // count
        1 +=> count;

        // set the freq
        Std.mtof( freq ) => s.freq;

        // advance time
        tinc => now;
    }
}