| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: scream-o-matic.ck |
| 3 |
// desc: using multiple LiSas for granular synthesis, to make a |
| 4 |
// continuous scream generator; based on the patch for |
| 5 |
// the augmented FlowBee interface (2014): |
| 6 |
// |
| 7 |
// "Suck-O-Phonic 6000: Augmented Flowbee Musical Interface" |
| 8 |
// https://www.youtube.com/watch?v=g3bkaljCVRs |
| 9 |
// |
| 10 |
// sound files used in this example: |
| 11 |
// https://chuck.stanford.edu/doc/examples/special/scream-o-matic/data/ |
| 12 |
// |
| 13 |
// author: Alex Chechile |
| 14 |
// Spencer Salazar |
| 15 |
// Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 16 |
//--------------------------------------------------------------------- |
| 17 |
// change this for multi-channel screams |
| 18 |
2 => int NUM_CHANNELS; |
| 19 |
// per-channel components |
| 20 |
NRev reverb[NUM_CHANNELS]; |
| 21 |
// DC blockers in case any input files has DC/low-freq bias |
| 22 |
PoleZero dcblocker[NUM_CHANNELS]; |
| 23 |
|
| 24 |
// patch it |
| 25 |
for( int i; i < NUM_CHANNELS; i++ ) |
| 26 |
{ |
| 27 |
dcblocker[i] => reverb[i] => dac.chan(i); |
| 28 |
.99 => dcblocker[i].blockZero; |
| 29 |
.1 => reverb[i].mix; |
| 30 |
} |
| 31 |
|
| 32 |
// max lisa voices |
| 33 |
30 => int LISA_MAX_VOICES; |
| 34 |
// grain duration base |
| 35 |
250::ms => dur GRAIN_DURATION_BASE; |
| 36 |
// grain duration (in multiples of duration base) |
| 37 |
6 => float GRAIN_DURATION_FACTOR; |
| 38 |
// factor relating grain duration to ramp up/down time |
| 39 |
.5 => float GRAIN_RAMP_FACTOR; |
| 40 |
// playback rate |
| 41 |
1 => float GRAIN_PLAY_RATE; |
| 42 |
// grain rate factor (0 means no change) |
| 43 |
.2 => float GRAIN_RATE_FACTOR; |
| 44 |
|
| 45 |
// array of screams |
| 46 |
LiSa @ lisa[0]; |
| 47 |
// load data and append to array |
| 48 |
lisa << load( me.dir() + "data/scream-1.wav" ); |
| 49 |
lisa << load( me.dir() + "data/scream-2.wav" ); |
| 50 |
lisa << load( me.dir() + "data/scream-3.wav" ); |
| 51 |
lisa << load( me.dir() + "data/scream-4.wav" ); |
| 52 |
lisa << load( me.dir() + "data/scream-5.wav" ); |
| 53 |
lisa << load( me.dir() + "data/scream-6-lion.wav" ); |
| 54 |
// how many to use (remove the `-1` to include lion roar) |
| 55 |
lisa.size()-1 => int NUM_LISA; |
| 56 |
|
| 57 |
// connect and pan |
| 58 |
for( int i; i < NUM_LISA; i++ ) |
| 59 |
{ |
| 60 |
// connect lisa to audio output |
| 61 |
lisa[i] => dcblocker[i%NUM_CHANNELS]; |
| 62 |
} |
| 63 |
|
| 64 |
// per-LiSa control shred; the arguments here can be adapted/replaced by |
| 65 |
// other input parameters, e.g., from code/kb/mouse/gametrak |
| 66 |
fun void go( LiSa @ lisa, float avgR, float varR, float avgT, float varT, dur T ) |
| 67 |
{ |
| 68 |
while( true ) |
| 69 |
{ |
| 70 |
// fireGrain( LiSa @ lisa, float pos, float rate, dur T, float gain ) |
| 71 |
fireGrain( lisa, |
| 72 |
Math.random2f(.1,.9), Math.random2f(avgR-varR/2,avgR+varR/2), |
| 73 |
Math.random2f(avgT-varT/2, avgT+varT/2)::ms, 1 ); |
| 74 |
T => now; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// spork per-lisa shre |
| 79 |
for( int i; i < NUM_LISA; i++ ) |
| 80 |
{ |
| 81 |
// randomize each LiSa for now |
| 82 |
// play with these parameters; maybe randomize differently for different effect |
| 83 |
// go( LiSa @ lisa, float avgR, float varR, float avgT, float varT, dur T ) |
| 84 |
spork ~ go( lisa[i], 1, .4, 800, 400, Math.random2f(300,500)::ms ); |
| 85 |
} |
| 86 |
|
| 87 |
// time loop |
| 88 |
while( true ) |
| 89 |
{ |
| 90 |
for( int i; i < NUM_LISA; i++ ) |
| 91 |
{ |
| 92 |
// one of several place to map input (e.g., from kb/mouse/gametrak) |
| 93 |
.5 => lisa[i].gain; |
| 94 |
} |
| 95 |
|
| 96 |
10::ms => now; |
| 97 |
} |
| 98 |
|
| 99 |
// fire a grain |
| 100 |
fun void fireGrain( LiSa @ lisa, float pos, float rate, dur T, float gain ) |
| 101 |
{ |
| 102 |
// get diff time |
| 103 |
// gt.currTime - gt.lastTime => dur diffTime; |
| 104 |
GRAIN_DURATION_BASE => dur diffTime; |
| 105 |
// grain length |
| 106 |
diffTime * GRAIN_DURATION_FACTOR => dur grainLen; |
| 107 |
// ramp time |
| 108 |
grainLen * GRAIN_RAMP_FACTOR => dur rampTime; |
| 109 |
// a grain |
| 110 |
if( lisa != null && pos >= 0 ) |
| 111 |
spork ~ grain( lisa, pos * lisa.duration(), grainLen, T/2, T/2, |
| 112 |
rate * GRAIN_PLAY_RATE, gain ); |
| 113 |
} |
| 114 |
|
| 115 |
// sporkee |
| 116 |
fun void grain( LiSa @ lisa, dur pos, dur grainLen, dur rampUp, dur rampDown, float rate, float gain ) |
| 117 |
{ |
| 118 |
// get a voice to use |
| 119 |
lisa.getVoice() => int voice; |
| 120 |
|
| 121 |
// if available |
| 122 |
if( voice > -1 ) |
| 123 |
{ |
| 124 |
// set rate |
| 125 |
lisa.rate( voice, rate ); |
| 126 |
// set playhead |
| 127 |
lisa.playPos( voice, pos ); |
| 128 |
// voice inga |
| 129 |
lisa.voiceGain( voice, gain ); |
| 130 |
// ramp up |
| 131 |
lisa.rampUp( voice, rampUp ); |
| 132 |
// wait |
| 133 |
(grainLen - rampUp) => now; |
| 134 |
// ramp down |
| 135 |
lisa.rampDown( voice, rampDown ); |
| 136 |
// wait |
| 137 |
rampDown => now; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
// load file into a LiSa |
| 142 |
fun LiSa load( string filename ) |
| 143 |
{ |
| 144 |
// sound buffer |
| 145 |
SndBuf buffy; |
| 146 |
// load it |
| 147 |
filename => buffy.read; |
| 148 |
|
| 149 |
// new LiSa |
| 150 |
LiSa lisa; |
| 151 |
// set duration |
| 152 |
buffy.samples()::samp => lisa.duration; |
| 153 |
|
| 154 |
// transfer values from SndBuf to LiSa |
| 155 |
for( 0 => int i; i < buffy.samples(); i++ ) |
| 156 |
{ |
| 157 |
// args are sample value and sample index |
| 158 |
// (dur must be integral in samples) |
| 159 |
lisa.valueAt( buffy.valueAt(i), i::samp ); |
| 160 |
} |
| 161 |
|
| 162 |
// set LiSa parameters |
| 163 |
lisa.play( false ); |
| 164 |
lisa.loop( false ); |
| 165 |
lisa.maxVoices( LISA_MAX_VOICES ); |
| 166 |
|
| 167 |
return lisa; |
| 168 |
} |