Debian Codegraph @

examples/book/digital-artists/chapter5/Listing5.9.ck

raw
1 // Listing 5.9 Creating and using a cool granularize() function to chop up a sound file
2
3 SndBuf2 click => dac; // (1) Makes and connects a stereo SndBuf2
4
5 // read soundfile, (2) Loads stereo SndBuf2 with a stereo sound file
6 me.dir() + "/audio/stereo_fx_01.wav" => click.read;
7
8 // function to hack up any sound file
9 fun void granularize(SndBuf myWav, int steps ) // (3) Defines granularize function
10 {
11 myWav.samples()/steps => int grain; // (4) Calculates grain size
12 // (5) Sets play pointer to random grain location in buffer
13 Math.random2(0,myWav.samples() - grain) + grain => myWav.pos;
14 grain :: samp => now;
15 }
16
17 // Main Program
18 while (true)
19 {
20 // call function, time passes there
21 granularize(click, 70);
22 }