Debian Codegraph @

examples/special/readme-LiSa2.ck

raw
1 //--------------------------------------------------------------------
2 // name: readme-LiSa2.ck
3 // desc: Live Sampling (LiSa) utilities for ChucK
4 //
5 // author: Dan Trueman
6 // date: 2007
7 //
8 // to run (in command line chuck):
9 // %> chuck readme-LiSa2.ck
10 //
11 // to run (in miniAudicle):
12 // (just run it!)
13 //--------------------------------------------------------------------
14 // LiSa allows for multiple voice playback from a live-sampled buffer.
15 // Useful for granular sampling (a la [munger~] from PeRColate) and
16 // looping (a la LoopLoop, Jamman, Echoplex, etc....). The methods
17 // are overloaded, taking a "voice" number as a first arg. if no
18 // voice number is specified, LiSa assumes 0 => voice.
19 //
20 // Below is a simple example to show how to crossfade two voices.
21 // See also the LiSa_munger examples for other approaches.
22 //
23 // Below the example find a (lengthy) command summary.
24 //--------------------------------------------------------------------
25
26 // signal chain; record a sine wave, play it back
27 SinOsc s => Envelope e => LiSa10 loopme => dac;
28 // direct
29 s => e => dac;
30 // set frequency
31 440. => s.freq;
32 // set gain
33 0.25 => s.gain;
34
35 // print channel info
36 <<< "LiSa channels:", loopme.channels() >>>;
37
38 // allocate memory in LiSa
39 6::second => loopme.duration;
40
41 // play s for a bit
42 500::ms => now;
43
44 // sweep the freq for fun
45 Envelope pitchmod => blackhole;
46 pitchmod.duration( 2000::ms );
47 pitchmod.value( s.freq() );
48 pitchmod.target( 880.0 );
49
50 // confirm that the length of the buffer is what you expect
51 <<< "buffer duration = ", loopme.duration() / second >>>;
52
53 // set times for recording fade in/out and sample loop length
54 100::ms => dur recfadetime;
55 1000::ms => dur mylooplen;
56 // set envelope duration
57 e.duration( recfadetime );
58
59 // print
60 <<< "start recording input into LiSa...", "" >>>;
61 // start recording input; record 1 seconds worth
62 loopme.record(1);
63 // open envelope (can also do without the Envelope and use
64 // loopme.recramp(dur) to set a recording ramp)
65 e.keyOn();
66
67 // calcuate later
68 now + (mylooplen - recfadetime) => time later;
69 // go until now is later (or later)
70 while(now < later)
71 {
72 // set frequency
73 pitchmod.value() => s.freq;
74 // advance time
75 10::ms => now;
76 }
77 // close envelope
78 e.keyOff();
79 // let fade time pass
80 recfadetime => now;
81 // print
82 <<< "stop recording input into LiSa...", "" >>>;
83 // stop recording input
84 loopme.record(0);
85
86 // disconnect direct input...
87 s =< dac;
88 // print
89 <<< "disconnect sine and hanging out...", "" >>>;
90 // and hang out for a bit
91 1000::ms => now;
92
93 // now, manipulate the sample
94 // get a voicenumber; note that this voice won't actually be
95 // reserved until you play it
96 loopme.getVoice() => int voice1;
97
98 // we'll play voice 1 forward; then crossfade with voice 2 backwards
99 // set gain
100 loopme.voiceGain( voice1, .5 );
101 // set pan (hard left channel)
102 loopme.pan( voice1, 0 );
103 // play voice 1
104 loopme.play( voice1, 1 );
105 // print
106 <<< "playing LiSa voice 1 ( id:", voice1, ")" >>>;
107 // let time pass
108 (mylooplen - recfadetime) => now;
109
110 // just as voice 1 is going to fade, bring in voice 2
111 loopme.getVoice() => int voice2;
112 // set play rate to go backwards
113 loopme.rate( voice2, -1.0 );
114 // set play head at the end
115 loopme.playPos( voice2, mylooplen );
116 // set gain
117 loopme.voiceGain( voice2, 0.5 );
118 // set pan (hard right channel)
119 loopme.pan( voice2, 1 );
120 // play
121 loopme.play( voice2, 1 );
122 // print
123 <<< "playing LiSa voice 2 ( id:", voice2, ")" >>>;
124
125 // wait until voice 1 had finished fading...
126 recfadetime => now;
127 // turn off voice 1
128 loopme.play( voice1, 0 );
129 // print
130 <<< "stopping LiSa voice 1...", "" >>>;
131
132 // wait for voice 2 to finish
133 1000::ms => now;
134
135 // print
136 <<< "program ending...", "" >>>;
137
138 //--------------------------------------------------------------------
139 // LiSa Command Summary:
140 //
141 // mylisa.duration(dur); required -- sets max length of buffer
142 // mylisa.duration(); returns max length of buffer
143 // mylisa.record(1/0); turn on/off recording into buffer
144 // mylisa.getVoice() => voice (int); returns first free voice number
145 // mylisa.maxVoices(int); sets maximum # of allowable voices
146 // mylisa.play(voice, 1/0); turn on/off play for particular voice
147 // mylisa.rampUp(voice, dur); turn on play for voice with ramp
148 // mylisa.rampDown(voice, dur); ramp down voice and then turn off play
149 // mylisa.rate(voice, float); sets play rate for "voice"
150 // mylisa.playPos(voice, dur); sets playback position for "voice" within buffer
151 // mylisa.playPos(voice); returns playback position for "voice"
152 // mylisa.recordPos(dur); sets record position
153 // mylisa.recordPos(); gets record position
154 // mylisa.recRamp(dur); sets ramping for the edges of the record buffer
155 // mylisa.loopStart(dur, voice); sets loopstart point for "voice"
156 // mylisa.loopStart(voice); get loopstart
157 // mylisa.loopEnd(voice, dur); sets loopend point for "voice"
158 // mylisa.loopEnd(voice); gets loopend
159 // mylisa.loop(voice, 1/0); turn on/off looping for "voice"
160 // mylisa.loop(voice); get looping state
161 // mylisa.bi(voice, 1/0); turn on/off bidirectional looping for "voice"
162 // mylisa.bi(voice); get bi state
163 // mylisa.voiceGain(voice, float); sets gain "voice"
164 // mylisa.voiceGain(voice); gets gain for "voice"
165 // mylisa.loopEndRec(dur); set looping end point for recording
166 // mylisa.loopEndRec(); get ...
167 // mylisa.feedback(float); set feedback amount [0,1] for recording
168 // mylisa.feedback(); get...
169 // mylisa.clear(); clear recording buffer
170 // mylisa.pan(); returns pan value of voice 0
171 // mylisa.pan(float where); pans voice 0 where can be [0., 7.], to place voice across LiSa's 8 outputs
172 // mylisa.pan(int voice); returns pan value of voice
173 // mylisa.pan(int voice, float where); pans specified voice where can be [0., 7.], to place voice across LiSa's 8 outputs
174 //
175 // Note that that LiSa defaults to mono;
176 // As of chuck 1.4.1.0 multi-channel LiSas can be instantiated
177 // using the following UGens:
178 // LiSa2 (stereo)
179 // LiSa4 (quad),
180 // LiSa6 (6-channel, laptop orchestra edition)
181 // LiSa8 (8-channel),
182 // LiSa10 (10-channel, for compatibility)
183 // LiSa16 (16-channel)
184 // The outputs of these LiSas can be sent to a multichannel dac, or
185 // simply to other ugens, if it is desirable to process the channels
186 // in different ways. These multiple channels are available
187 // regardless of whether the dac is running > 2 chans. LiSaX's
188 // multi-channel output can be manually connected through .chan(n).
189 //
190 // All of these commands should work without the "voice" arg;
191 // 0 => voice will be assumed see online documentation for most
192 // up-do-date listing...
193 //--------------------------------------------------------------------