Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2013 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/7717375 to your computer and use it in GitHub Desktop.
Save anonymous/7717375 to your computer and use it in GitHub Desktop.
test
//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 channel
spork ~ make_rhythm(snare_beats, sample_buffs[0], ate, 0.8, 0.5, 16, 0.1, 0.0, 1, 0);
spork ~ make_rhythm(hihat_beats, sample_buffs[1], ate, 0.8, 0.4, 16, 0.1, 0.0, 1, 1);
spork ~ make_rhythm(kick_beats, sample_buffs[2], ate, 0.8, 0.5, 16, 0.1, 0.0, 1, 2);
//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[], SndBuf sample,
dur tyme, float dgain, float hurdle, int num_beats,
float high, float low, float rate, int mg)
{
// clarity variable, temporary and is destroyed at the end of the loop.
1 => int count;
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 + 1 => count;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment