| 1 |
//----------------------------| |
| 2 |
// on-the-fly synchronization |
| 3 |
// adapted from Perry's ChucK Drummin' + Ge's sine poops |
| 4 |
// |
| 5 |
// authors: Perry Cook ([email protected]) |
| 6 |
// Ge Wang ([email protected]) |
| 7 |
// --------------------| |
| 8 |
// add one by one into VM (in pretty much any order): |
| 9 |
// |
| 10 |
// terminal-1%> chuck --loop |
| 11 |
// --- |
| 12 |
// terminal-2%> chuck + otf_01.ck |
| 13 |
// (anytime later) |
| 14 |
// terminal-2%> chuck + otf_02.ck |
| 15 |
// (etc...) |
| 16 |
//--------------------------------------| |
| 17 |
|
| 18 |
// this synchronizes to period |
| 19 |
.5::second => dur T; |
| 20 |
T - (now % T) => now; |
| 21 |
|
| 22 |
// one period offset |
| 23 |
T => now; |
| 24 |
|
| 25 |
// construct the patch |
| 26 |
SndBuf buf => Gain g => dac; |
| 27 |
// read in from file |
| 28 |
me.dir() + "data/snare-hop.wav" => buf.read; |
| 29 |
// set the gain |
| 30 |
.6 => g.gain; |
| 31 |
|
| 32 |
// where we actually want to start (in # of sample frames) |
| 33 |
100 => int where; |
| 34 |
|
| 35 |
// time loop |
| 36 |
while( true ) |
| 37 |
{ |
| 38 |
// randomize the gain a bit |
| 39 |
Math.random2f(.8,.9) => buf.gain; |
| 40 |
|
| 41 |
// note: Math.randomf() returns value between 0 and 1 |
| 42 |
if( Math.randomf() > .25 ) |
| 43 |
{ |
| 44 |
// set play position to 'where' |
| 45 |
where => buf.pos; |
| 46 |
// advance time |
| 47 |
2::T => now; |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
where => buf.pos; |
| 52 |
.75::T => now; |
| 53 |
|
| 54 |
.8 => buf.gain; |
| 55 |
where => buf.pos; |
| 56 |
1.25::T => now; |
| 57 |
} |
| 58 |
} |