Debian Codegraph @

examples/special/LiSa-load-classic.ck

raw
1 //-----------------------------------------------------------------------------
2 // name: LiSa-load-classic.ck
3 // desc: deprecated: see LiSa-load.ck for much easier loading of
4 // audio file into LiSa (requires 1.5.5.6)
5 // this example is kept for historic purposes as well as for
6 // pre-1.5.5.6 chuck systems
7 //
8 // author: Dan Trueman, original example (2007): was LiSa-SndBuf.ck
9 // Ge Wang, modified example (2021): rolled function, added twilight
10 // sound (see twilight-granular-kb-interp.ck for more info)
11 // and bi-directional loop
12 //-----------------------------------------------------------------------------
13 // this example shows how to open a soundfile and use it in LiSa. someday LiSa
14 // may be able to open soundfiles directly, but don't hold your breath.
15 //
16 // note that unlike SndBuf, LiSa wants a dur (not an int) to specify the index
17 // of the sample location
18 //-----------------------------------------------------------------------------
19
20 // one-stop function for creating a LiSa, loaded with the specified audio file
21 load( me.dir() + "twilight/twilight-granular.aiff" ) @=> LiSa @ lisa;
22 // connect
23 lisa => dac;
24
25 // party on...
26 2 => lisa.rate; // rate!
27 1 => lisa.loop; // loop it!
28 1 => lisa.bi; // bi-directional loop!
29 1 => lisa.play; // play!
30
31 // commence party
32 while( true ) 1::second => now;
33
34 // create a new LiSa pre-loaded with the specified file
35 fun LiSa load( string filename )
36 {
37 // sound buffer
38 SndBuf buffy;
39 // load it
40 filename => buffy.read;
41
42 // instantiate new LiSa (will be returned)
43 LiSa lisa;
44 // set duration
45 buffy.samples()::samp => lisa.duration;
46
47 // transfer values from SndBuf to LiSa
48 for( 0 => int i; i < buffy.samples(); i++ )
49 {
50 // args are sample value and sample index
51 // (dur must be integral in samples)
52 lisa.valueAt( buffy.valueAt(i), i::samp );
53 }
54
55 // set default LiSa parameters; actual usage parameters intended
56 // to be set to taste by the user after this function returns
57 lisa.play( false );
58 lisa.loop( false );
59
60 return lisa;
61 }