From CSWiki
Jump to: navigation, search
// name: LiSa
// desc: Live sampling utilities for ChucK
// author: Dan Trueman, 2007
// to run (in command line chuck):
//     %> chuck


LiSa allows for multiple voice playback from a live-sampled buffer. Useful
for granular sampling (a la [munger~] from PeRColate) and looping (a la LoopLoop,
Jamman, Echoplex, etc....). The methods are overloaded, taking a "voice" number
as a first arg. if no voice number is specified, LiSa assumes 0=>voice.

Below is a simple example to show how to crossfade two voices. See also the 
LiSa_munger directory for other approaches.

Below the example find a (lengthy) command summary.



//signal chain; record a sine wave, play it back
SinOsc s => Envelope e => LiSa loopme => dac;
s => dac;
440. => s.freq;
0.2 => s.gain;

//alloc memory
6::second => loopme.duration;

//play s for a bit
500::ms => now;

//sweep the freq for fun
Envelope pitchmod => blackhole;

//confirm that the length of the buffer is what you expect
<<<"buffer duration = ", loopme.duration() / 44100.>>>;

//set times for recording fade in/out and sample loop length
100::ms => dur recfadetime;
1000::ms => dur mylooplen;

//start recording input; record 1 seconds worth
e.keyOn(); //can also do without the Envelope and use loopme.recramp(dur) to set a recording ramp

now + (mylooplen - recfadetime) => time later;
while(now < later) {
	pitchmod.value() => s.freq;
	10::ms => now;

recfadetime => now;

//disconnect input and hangout a bit
s =< dac;
1000::ms => now;

//now, manipulate the sample
//	get a voicenumber; note that this voice won't actually be reserved until you play it
loopme.getVoice() => int voice1;

//we'll play voice 1 forward, and then crossfade it with voice 2 backwards, 1);
(mylooplen - recfadetime) => now;

//just as voice 1 is going to fade, bring in voice 2
loopme.getVoice() => int voice2;
loopme.rate(voice2, -1.);
loopme.playPos(voice2, mylooplen); 
loopme.voiceGain(voice2, 0.2);, 1);

//wait until voice 1 had finished fading, then turn off
recfadetime => now;, 0);

//wait for voice 2 to finish
1000::ms => now;