Automatic Drum Set

Jonathan Potter

Final Project, Music 220A


For my final project, I wrote a program simulating an automatic drum set. The set incorporates nine different pre-recorded drum sounds into three different beats: a swing beat, a Latin beat, and a rock beat.

Using the Automatic Drum Set

1) Download the drum sound files.

2) Add the shred “Auto Set.ck” in miniAudicle. Make sure you change the file names of the drum sounds and the keyboard numbers as appropriate (see code comments).

3) Indicate the desired beat type by pressing a letter (“r” for rock, “l” for Latin, and “s” for swing).

4) Indicate the desired tempo by pressing any key four times – analogous to a count-off.

5) Once the beat has started playing, cue one-measure fills by pressing any key.

The Implementation (see below for code)

To build the automatic drum set, I started by loading each drum set sound (downloaded from the Free Sound Project -- www.freesound.org) into an array of sound buffers. I then wrote a simple four-line function for each sound that played the sound file from the appropriate element in the array. These functions were sporked throughout the program so that multiple drum sounds could play at once. I had to add a couple wrinkles for the closedHighHat and closeHighHat functions (which played a hit on a closed high hat and a high hat closing, respectively) so that the buffer that played the open high hat sound stopped playing. This step was to make the program more realistic, since a high hat cannot be closed and open at the same time.

The next two pieces of code in the program are relatively simple bits of S.M.E.L.T. (source for basic starter code: www.smelt.cs.princeton.edu). The first prompts the user for the desired type of beat and loops until the user enters either “s” for swing, “l” for Latin, or “r” for rock. The second prompts the user to press a key four times to determine the tempo. The code calculates the tempo by storing the three time intervals between the four key strikes and then taking the average.

Before the beat starts, a function called startFill is sporked to run simultaneously while the set is playing. This function listens for a key strike from the user to indicate that there should be a fill in the next measure. When the user strikes a key, the function takes the current measure number (stored as a variable), and stores the next measure number as a variable called “fill.” The main loop (to be discussed shortly) can then access this variable and determine whether it should be playing a fill or the regular beat.

After startFill is called, the program then calls the function corresponding to the style of beat the user chose. This function serves as the main loop for the program and is essentially the same for the rock, Latin, and swing beats. It has access to two variables which serve as the backbone for the loop: a measure variable and a beat variable. At the beginning of each cycle, the beat variable is incremented. If it is equal to a certain value (16 for rock and Latin and 12 for swing), it loops back to zero and the measure variable is incremented. The program then checks to see if the measure variable is equal to “fill” (which is continuously updated by startFill). If so, it calls the fill beat function. Otherwise, it calls the regular beat function. In both cases, it passes the beat number to the function it calls so that the called function can play the appropriate drum sounds depending on where in the measure the set is.

These two subsidiary functions, the regular beat function and the fill beat function, are very similar between the three beat styles. The regular beat function operates deterministically, taking the beat number and sporking the appropriate drum sound functions. For example, if the beat is the down beat of 2 or 4, the regular swing beat function sporks the close high hat function. The fill beat function, on the other hand, works through a simple probabilistic model (though it might look rather messy in code) such that the set can play a relatively realistic fill. In these probabilistic models, certain drum sounds are given more weight on certain beats than on others. The snare sound, for instance, is given significantly more weight towards the end of a rock fill beat, which means that more of the hits towards the end of a rock fill will be snare hits.

In the rock and Latin beats, I added a condition in the main loop to test if the beat was the first beat after a fill. If so, the main loop plays a crash cymbal.

The Manual Drum Set (code also below)

In addition to the automatic drum set, I also constructed a simple manual drum set which I mostly used to test the drum sounds. This program consists solely of a sound buffer containing all the drum sound files and an infinite loop listening for key strikes. To each drum sound I assigned a key such that the user can effectively play the automatic drum set manually with his/her keyboard. The code for the manual drum set is also included below.

Ideas for expansion

The following is a brainstorm of ideas for how the functionality and general coolness of the automatic drum set could be improved.

1) More drum set sounds could be added (more toms, timbales, cowbell, etc.).

2) Sounds of different volumes could be added to simulate dynamics and accents.

3) More beats could be implemented (different styles, time signatures, etc.).

4) Currently fills can only take up one measure, since the user cannot indicate another fill measure if a fill is already occurring. One idea I thought of but did not get a chance to implement was to make it so that a fill started and stopped when the user indicated. This would be challenging because the program currently evaluates whether a fill should be played every beat (rather than every measure). Thus it would be difficult to implement this idea while simultaneously making sure the fills extend to the end of a measure.

5) Another thought I had was to implement a way for the user to change what beat the set plays in real time, rather than just choosing a beat at the beginning and going with it.

6) The automatic drum set could be made much more user-friendly. A graphical interface could be implemented (via MAUI) to let the user start and stop different beats, indicate tempo, and indicate fills all with buttons.

7) The manual drum set could be incorporated into the automatic drum set such that the user could either start and stop automatic beats or play their own beats, all in the same application.

8) Both the manual and automatic drum sets could be hooked up to some sort of graphical display of a drum set, which would then respond to different drum sounds being played by having the drum heads vibrate or light up.

Code

Automatic Drum Set

Manual Drum Set

Drum Sounds

bass

snare

rim shot

low tom

open high hat

closed high hat

close high hat

ride

crash