| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: LiSa-stereo.ck |
| 3 |
// desc: Live sampling utilities for ChucK (stereo edition) |
| 4 |
// |
| 5 |
// this can readily adapted to more channels, using one of the |
| 6 |
// following: |
| 7 |
// ---- |
| 8 |
// LiSa2 (stereo) |
| 9 |
// LiSa4 (quad), |
| 10 |
// LiSa6 (6-channel, laptop orchestra edition) |
| 11 |
// LiSa8 (8-channel), |
| 12 |
// LiSa10 (10-channel, for compatibility) |
| 13 |
// LiSa16 (16-channel) |
| 14 |
// ---- |
| 15 |
// The outputs of these LiSas can be sent to a multichannel dac, or |
| 16 |
// simply to other ugens, if it is desirable to process the channels |
| 17 |
// in different ways. These multiple channels are available |
| 18 |
// regardless of whether the dac is running > 2 chans. LiSaX's |
| 19 |
// multi-channel output can be manually connected through .chan(n). |
| 20 |
// |
| 21 |
// author: Dan Trueman, 2007 (LiSa-munger1.ck) |
| 22 |
// Ge Wang 2023 (LiSa-stereo.ck, based on the above) |
| 23 |
//--------------------------------------------------------------------- |
| 24 |
// patch |
| 25 |
SinOsc s => LiSa2 lisa => dac; |
| 26 |
// thru |
| 27 |
s => dac; |
| 28 |
|
| 29 |
// LiSa duration (this also allocates internals) |
| 30 |
lisa.duration( 1::second ); |
| 31 |
// set max voices |
| 32 |
lisa.maxVoices( 30 ); |
| 33 |
// set voice pan |
| 34 |
for( int v; v < lisa.maxVoices(); v++ ) |
| 35 |
{ |
| 36 |
// can pan across all available channels |
| 37 |
// note LiSa.pan( voice, [0...channels-1] ) |
| 38 |
lisa.pan( v, Math.random2f( 0, lisa.channels()-1 ) ); |
| 39 |
} |
| 40 |
// set ramp |
| 41 |
lisa.recRamp( 20::ms ); |
| 42 |
|
| 43 |
// frequency |
| 44 |
s.freq( 440 ); |
| 45 |
// gain |
| 46 |
s.gain( 0.25 ); |
| 47 |
|
| 48 |
// modulator |
| 49 |
SinOsc freqmod => blackhole; |
| 50 |
// modulation frequency |
| 51 |
freqmod.freq( 0.1 ); |
| 52 |
|
| 53 |
// start recording; will loop-record by default |
| 54 |
lisa.record( true ); |
| 55 |
// set gain |
| 56 |
lisa.gain( 0.1 ); |
| 57 |
|
| 58 |
// compute 1 second from now |
| 59 |
now + 1000::ms => time later; |
| 60 |
while( now < later ) |
| 61 |
{ |
| 62 |
// update frequency |
| 63 |
freqmod.last() * 500. + 200. => s.freq; |
| 64 |
10::ms => now; |
| 65 |
} |
| 66 |
|
| 67 |
// stop recording |
| 68 |
lisa.record( false ); |
| 69 |
// set gain to 0 for SinOsc |
| 70 |
s.gain( 0 ); |
| 71 |
|
| 72 |
// this arrangment will create some clicks because of discontinuities |
| 73 |
// from the loop recording. to fix, need to make a rotating buffer |
| 74 |
// approach. see the next two example files... |
| 75 |
while( true ) |
| 76 |
{ |
| 77 |
// random |
| 78 |
Math.random2f( 1.5, 2.0 ) => float newrate; |
| 79 |
Math.random2f( 250, 750 )::ms => dur newdur; |
| 80 |
|
| 81 |
// spork grain |
| 82 |
spork ~ getgrain( newdur, 20::ms, 20::ms, newrate ); |
| 83 |
|
| 84 |
// advance time |
| 85 |
10::ms => now; |
| 86 |
} |
| 87 |
|
| 88 |
// sporkee: entry point for a grain! |
| 89 |
fun void getgrain( dur grainlen, dur rampup, dur rampdown, float rate ) |
| 90 |
{ |
| 91 |
// get an available voice |
| 92 |
lisa.getVoice() => int newvoice; |
| 93 |
|
| 94 |
// make sure we got a valid voice |
| 95 |
if( newvoice > -1 ) |
| 96 |
{ |
| 97 |
// set play rate |
| 98 |
lisa.rate(newvoice, rate); |
| 99 |
// set play position |
| 100 |
lisa.playPos(newvoice, 20::ms); |
| 101 |
// lisa.playpos(newvoice, Math.random2f(0., 1000.)::ms); |
| 102 |
// set ramp up duration |
| 103 |
lisa.rampUp( newvoice, rampup ); |
| 104 |
// wait for grain length (minus the ramp-up and -down) |
| 105 |
(grainlen - (rampup + rampdown)) => now; |
| 106 |
// set ramp down duration |
| 107 |
lisa.rampDown( newvoice, rampdown ); |
| 108 |
// for ramp down duration |
| 109 |
rampdown => now; |
| 110 |
} |
| 111 |
} |