File: sndbuf.ck

package info (click to toggle)
chuck 1.5.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 40,904 kB
  • sloc: cpp: 120,943; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 456; python: 174; perl: 86
file content (25 lines) | stat: -rw-r--r-- 625 bytes parent folder | download | duplicates (3)
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
// sound file to load; me.dir() returns location of this file
me.dir() + "../data/snare.wav" => string filename;
// if there is argument, use it as the filename
if( me.args() ) me.arg(0) => filename;

// the patch
SndBuf buf(filename) => dac;
// can also load the file this way
// filename => buf.read;

// check if file successfully loaded
if( !buf.ready() ) me.exit();

// time loop
while( true )
{
    // set playback position to beginning
    0 => buf.pos;
    // randomize gain
    Math.random2f(.25,.5) => buf.gain;
    // randomize rate
    Math.random2f(.5,1.5) => buf.rate;
    // advance time
    100::ms => now;
}