Debian Codegraph @

examples/special/LiSa-munger1.ck

raw
1 //---------------------------------------------------------------------
2 // name: LiSa-munger1.ck
3 // desc: Live sampling utilities for ChucK
4 // (also see: LiSa-stereo.ck for stereo version of this)
5 //
6 // author: Dan Trueman, 2007
7 //
8 // These three example files demonstrate a couple ways to approach
9 // granular sampling with ChucK and LiSa. All are modeled after the
10 // munger~ from PeRColate. One of the cool things about doing this
11 // in ChucK is that there is a lot more ready flexibility in
12 // designing grain playback patterns; rolling one's own idiosyncratic
13 // munger is a lot easier.
14 //
15 // Example 1 (below) is simple, but will feature some clicking due
16 // to playing back over the record-point discontinuity.
17 //---------------------------------------------------------------------
18 // patch
19 SinOsc s => LiSa lisa => dac;
20 // thru
21 s => dac;
22
23 // LiSa duration (this also allocates internals)
24 lisa.duration( 1::second );
25 // set max voices
26 lisa.maxVoices( 30 );
27 // set ramp duration
28 lisa.recRamp( 20::ms );
29
30 // frequency
31 s.freq( 440 );
32 // gain
33 s.gain( 0.25 );
34
35 // modulator
36 SinOsc freqmod => blackhole;
37 // modulation frequency
38 freqmod.freq( 0.1 );
39
40 // set it recording constantly; loop records by default
41 lisa.record( true );
42 // set gain
43 lisa.gain( 0.1 );
44
45 // compute 1 second from now
46 now + 1000::ms => time later;
47 while( now < later )
48 {
49 // update frequency
50 freqmod.last() * 500. + 200. => s.freq;
51 10::ms => now;
52 }
53
54 // stop recording
55 lisa.record( false );
56 // set gain to 0 for SinOsc
57 s.gain( 0 );
58
59 // this arrangment will create some clicks because of discontinuities
60 // from the loop recording. to fix, need to make a rotating buffer
61 // approach. see the next two example files...
62 while( true )
63 {
64 // random
65 Math.random2f( 1.5, 2.0 ) => float newrate;
66 Math.random2f( 250, 750 )::ms => dur newdur;
67
68 // spork grain
69 spork ~ getgrain( newdur, 20::ms, 20::ms, newrate );
70
71 // advance time
72 10::ms => now;
73 }
74
75 // sporkee: entry point for a grain!
76 fun void getgrain( dur grainlen, dur rampup, dur rampdown, float rate )
77 {
78 // get an available voice
79 lisa.getVoice() => int newvoice;
80
81 // make sure we got a valid voice
82 if( newvoice > -1 )
83 {
84 // set play rate
85 lisa.rate(newvoice, rate);
86 // set play position
87 lisa.playPos(newvoice, 20::ms);
88 // lisa.playpos(newvoice, Math.random2f(0., 1000.)::ms);
89 // set ramp up duration
90 lisa.rampUp( newvoice, rampup );
91 // wait for grain length (minus the ramp-up and -down)
92 (grainlen - (rampup + rampdown)) => now;
93 // set ramp down duration
94 lisa.rampDown( newvoice, rampdown );
95 // for ramp down duration
96 rampdown => now;
97 }
98 }