Bass-Kick-Hi-Hat

This is my first ChucK script so its as basic as they get but its a start.

There are three scripts here: one for a bass drum, one for a snare drum and one for a hi-hat (why do I make the names of my menu items so cryptic?).

Play these all together with ChucK and you should get a complete beat (albeit a small one, only 1 bar long based on 1 second beats in 4/4 at 60 BMP):

Bass Drum:

// Get this file in sync:
// I have used 1 second from now as it is longer than any
// individual note length and is plenty of time for the machine
// to get everythign loaded etc...
1::second => dur durDif;
durDif - (now % durDif) => now;
// Create a sound buffer for the bass drum, connect it to a gain
// unit, and then out to the sound card
SndBuf buffKick => Gain gainKick => dac;
// Read our wav file into the sound buffer
"kick.wav" => buffKick.read;
// Set a gain level, no skill here just trial and error :S
.4 => gainKick.gain;
// Start an infinite loop in which we are setting the sound buffer position
// to the start, allowing time to pass which allows for the buffer to read
// through, and then reset the position of the sound buffer and allow more
// time to pass, playing the sound again, varying the duration of time that
// passed givnig us a sequence as it were
while( true )
{
0 => buffKick.pos;
2::second => now;
0 => buffKick.pos;
.5::second => now;
0 => buffKick.pos;;
1.5::second => now;
}
// Seeing as this is all based around one second time intivals,
// this becomes a 60 BMP track and basic maths allows us to calculate
// location of the off beats for the hi-hat and snares

Snare Drum:

// Get this file in sync:
// I have used 1 second from now as it is longer than any
// individual note length and is plenty of time for the machine
// to get everythign loaded etc...
1::second => dur durDif;
durDif - (now % durDif) => now;
// Create a sound buffer for the snare drum, connect it to a gain
// unit, and then out to the sound card
SndBuf buffSnare => Gain gainSnare => dac;
// Read our wav file into the sound buffer
"snare.wav" => buffSnare.read;
// Set a gain level, no skill here just trial and error :S
.5 => gainSnare.gain;
// Start an infinite loop to play some riddims based on our
// seqeunce outlined below!
while( true )
{
1::second => now;
0 => buffSnare.pos;
2::second => now;
0 => buffSnare.pos;
1::second => now;
}

Hi-Hat:

// Get this file in sync:
// I have used 1 second from now as it is longer than any
// individual note length and is plenty of time for the machine
// to get everythign loaded etc...
1::second => dur durDif;
durDif - (now % durDif) => now;
// Create a sound buffer for the hi-hat, connect it to a gain
// unit, and then out to the sound card
SndBuf buffHat => Gain gainHat => dac;
// Read our wav file into the sound buffer
"hihat.wav" => buffHat.read;
// Set a gain level, no skill here just trial and error :S
.1 => gainHat.gain;
// Start an infinite loop to play some riddims based on our
// seqeunce outlined below!
while( true )
{
.25::second => now;
0 => buffHat.pos;
.25::second => now;
0 => buffHat.pos;
.5::second => now;
}

Need Sounds? In my scripts I reference some WAV files, I haven't included them here but they are included in ChucK when you download it.