Debian Codegraph @

examples/book/digital-artists/chapter4/Listing4.1.ck

raw
1 // Listing 4.1 Loading and playing sound files with SndBuf
2
3 // Using SndBuf to play a sound file
4 // by ChucK Programmer, December 2050
5 SndBuf mySound => dac;
6
7 // get file path
8 me.dir() => string path; // (1) Gets current working directory.
9
10 // sound file we want to play
11 "/audio/snare_01.wav" => string filename;
12
13 // + sign connects strings together!
14 path+filename => filename; // (2) builds a full path/name to a sound file.
15
16 // tell SndBuf to read this file
17 filename => mySound.read; // (3) ChucKing a string to the .read member of
18 // SndBuf causes it to load that file
19
20 // set gain
21 0.5 => mySound.gain;
22
23 // play sound from the beginning
24 0 => mySound.pos; // ChucKing a number to the .pos (for
25 // position) member of SndBuf causes it to
26 // start playing from that position in the
27 // array (in this case, from the beginning).
28
29 // advance time so we can hear it
30 second => now;