Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/vlunt2.ck
Last active December 29, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/7717377 to your computer and use it in GitHub Desktop.
Save zeffii/7717377 to your computer and use it in GitHub Desktop.
//set beat time
.125::second => dur ate;
//set 4 master gains
Gain mgain[3];
mgain[0] => dac;
mgain[1] => dac.left;
mgain[2] => dac.right;
<<<me.dir()>>>;
me.dir() + "/audio/" => string full_path;
//drum beats
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0] @=> float snare_beats[];
[0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0, 0.4, 0.0] @=> float hihat_beats[];
[0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5] @=> float kick_beats[];
["snare_01.wav", "hihat_02.wav", "kick_02.wav"] @=> string sample_paths[];
sample_paths.cap() => int num_samples;
SndBuf sample_buffs[num_samples];
for(0 => int i; i<num_samples; i++){
full_path + sample_paths[i] => sample_buffs[i].read;
sample_buffs[i].samples() => sample_buffs[i].pos;
sample_buffs[i] => mgain[i];
}
//start all three functions
// beat lists buf time gain hurdle #beats high low rate
spork ~ make_rhythm(snare_beats, 0, ate, 0.8, 0.5, 16, 0.1, 0.0, 1);
spork ~ make_rhythm(hihat_beats, 1, ate, 0.8, 0.4, 16, 0.1, 0.0, 1);
spork ~ make_rhythm(kick_beats, 2, ate, 0.8, 0.5, 16, 0.1, 0.0, 1);
//repeat for a minute out of sync around 8 loops?!?!?!
1::minute => now;
//three functions all the same except beat list and wave file
fun void make_rhythm(float beat_list[], int idx,
dur tyme, float dgain, float hurdle, int num_beats,
float high, float low, float rate)
{
// convenience variable, for readability below. is removed when the function ends.
sample_buffs[idx] @=> SndBuf sample;
int count; // initializes to 0 by default, in chuck.
// other programming languages may require explicit initialization to some number
// or strange things happen :)
while(true)
{
<<<count," loop">>>;
for (0=> int i; i < num_beats; i++)
{
if (!(beat_list[i] == 0.0)){
0 => sample.pos;
beat_list[i] + Math.random2f(low, high) => float rnd_gain;
if(rnd_gain >= hurdle) dgain => sample.gain;
else 0.0 => sample.gain;
rate => sample.rate;
}
tyme => now;
count++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment