Debian Codegraph @

examples/basic/sndbuf.ck

raw
1 // sound file to load; me.dir() returns location of this file
2 me.dir() + "../data/snare.wav" => string filename;
3 // if there is argument, use it as the filename
4 if( me.args() ) me.arg(0) => filename;
5
6 // the patch
7 SndBuf buf(filename) => dac;
8 // can also load the file this way
9 // filename => buf.read;
10
11 // check if file successfully loaded
12 if( !buf.ready() ) me.exit();
13
14 // time loop
15 while( true )
16 {
17 // set playback position to beginning
18 0 => buf.pos;
19 // randomize gain
20 Math.random2f(.25,.5) => buf.gain;
21 // randomize rate
22 Math.random2f(.5,1.5) => buf.rate;
23 // advance time
24 100::ms => now;
25 }