| 1 |
//-------------------------------------------------------------------- |
| 2 |
// name: LiSa-trigger.ck |
| 3 |
// desc: Live sampling utilities for ChucK |
| 4 |
// |
| 5 |
// author: Dan Trueman, 2007 |
| 6 |
// |
| 7 |
// based on the S.M.E.L.T. (http://smelt.cs.princeton.edu/) envelope |
| 8 |
// follower trigger program will trigger start and stop to one-shot |
| 9 |
// LiSa buffers. a sort of triggered delay line, so the delays follow |
| 10 |
// the player rather than being static. Success depends on tuning the |
| 11 |
// envelope follower closely to the input gains on however you are |
| 12 |
// getting audio into ChucK. Mileage will vary.... |
| 13 |
//-------------------------------------------------------------------- |
| 14 |
|
| 15 |
// patch |
| 16 |
adc => Gain g => OnePole p => blackhole; |
| 17 |
// square the input, by chucking adc to g a second time |
| 18 |
adc => g; |
| 19 |
// set g to multiply its inputs |
| 20 |
3 => g.op; |
| 21 |
|
| 22 |
// set pole position, influences how closely the envelope follows the input |
| 23 |
// : pole = 0 -> output == input; |
| 24 |
// : as pole position approaches 1, follower will respond more slowly to input |
| 25 |
0.995 => p.pole; |
| 26 |
// thresholds |
| 27 |
.0001 => float threshold; |
| 28 |
.00005 => float releaseThresh; |
| 29 |
|
| 30 |
// duration between successive polling |
| 31 |
10::ms => dur pollDur; |
| 32 |
|
| 33 |
// LiSa stuff |
| 34 |
adc => LiSa lisa => dac; |
| 35 |
lisa.duration(25::second); |
| 36 |
lisa.recRamp(20::ms); |
| 37 |
|
| 38 |
// start recording input |
| 39 |
lisa.record(1); |
| 40 |
// voice variable |
| 41 |
-1 => int voice; |
| 42 |
// rate |
| 43 |
float rate; |
| 44 |
|
| 45 |
// read command line args; set rate |
| 46 |
// be nice to have pitch follower determine this, or some kind of table.... |
| 47 |
Std.atof(me.arg(0)) => rate; |
| 48 |
if( rate == 0 ) 1. => rate; |
| 49 |
<<< "setting rate to: ", rate >>>; |
| 50 |
|
| 51 |
// events |
| 52 |
Event attacks[10]; |
| 53 |
dur newstarttime, newlen; |
| 54 |
time starttime_real; |
| 55 |
|
| 56 |
// infinite time loop |
| 57 |
while( true ) |
| 58 |
{ |
| 59 |
// detect onset |
| 60 |
if( p.last() > threshold ) |
| 61 |
{ |
| 62 |
// do something |
| 63 |
<<< "attack!; starting voice", voice >>>; |
| 64 |
// play last sample |
| 65 |
if( voice > -1 ) attacks[voice].signal(); |
| 66 |
lisa.recPos() => newstarttime; |
| 67 |
now => starttime_real; |
| 68 |
|
| 69 |
// wait for release |
| 70 |
while( p.last() > releaseThresh ) { pollDur => now; } |
| 71 |
<<< "release..." >>>; |
| 72 |
|
| 73 |
// spork off new sample |
| 74 |
now - starttime_real => newlen; |
| 75 |
lisa.getVoice() => voice; |
| 76 |
if( voice > -1 ) spork ~ playlast( attacks[voice], newstarttime, newlen, rate, voice ); |
| 77 |
} |
| 78 |
|
| 79 |
// determines poll rate |
| 80 |
pollDur => now; |
| 81 |
} |
| 82 |
|
| 83 |
// sporkee |
| 84 |
fun void playlast( Event on, dur starttime, dur len, float newrate, int myvoice ) |
| 85 |
{ |
| 86 |
if( newrate == 0. ) 1. => newrate; |
| 87 |
<<< "sporking shred with rate: ", newrate >>>; |
| 88 |
if( rate > 0. ) lisa.playPos( myvoice, starttime ); |
| 89 |
else lisa.playPos( myvoice, lisa.recPos() - 1::ms ); |
| 90 |
|
| 91 |
// wait |
| 92 |
on => now; |
| 93 |
|
| 94 |
lisa.rate( myvoice, newrate ); |
| 95 |
lisa.rampUp( myvoice, 20::ms ); |
| 96 |
|
| 97 |
Math.fabs( newrate ) => float absrate; |
| 98 |
len / absrate => now; |
| 99 |
lisa.rampDown( myvoice, ( 250 / absrate )::ms ); |
| 100 |
( 250 / absrate )::ms => now; |
| 101 |
|
| 102 |
// bye bye shred.... |
| 103 |
} |