Project: Drum Machine

March 16, 2020

I can’t remember why I decided to build a drum machine in Csound. After spending a few weeks on the James Tenney instrument, which generates notes in a very randomized way, I must have been interested in generating notes within a metrical framework. In other words, I wanted to learn how to use the metro opcode.

But first, why would you build a drum machine when there are dozens of free, full-featured drum machines available online? Two reasons:

  1. You’ll learn a lot about Csound by building one yourself.
  2. You can custom code the drum machine to do anything you’d like.

Sampling Drum Sounds

The first step was deciding how to generate the drum sounds. Rather than synthesize the sounds from scratch I decided to play pre-recorded drum samples with the loscil opcode. I found a huge collection of free drum machine samples on Reverb.com and a more extensive collection of free TR-808 samples from Michael Fischer. I chose several of my favorite samples and loaded them into function tables with GEN routine 01. The loscil opcode would then play the different drum parts depending on which function table it was told to read from.

Controlling Rhythmic Patterns

The most challenging part of designing a drum machine is deciding how the user will interact with the machine to create rhythmic patterns. The trick is striking the right balance between controlability and simplicity. You want to provide enough ways for the user to control the drum machine and do exactly what they want to do musically, but you also want the drum machine to be simple enough for the user to use it without overwhelming the user with all the options.

Drum machine
Screenshot of the drum machine interface built in Cabbage.

I was most interested in how the user will control the rhythmic pattern of each drum part. I decided not to have the user click a box for every 1/16th note of every drum part because there would be a total of 192 boxes on the screen! I was afraid that would be overwhelming to the user and difficult to control in real time. Instead, I decided to have the user control the rhythmic patterns by entering and modifying strings of characters. My thinking was that the 24 string fields are visually simpler than 192 buttons, and it’s faster for the user to type characters than to move and click the mouse dozens of times.

Here's a quick overview of what the characters in the strings mean.

Under the hood, this drum machine reads the various widget values into arrays, cycles through the active rows (i.e. drum parts) and columns (i.e. rhythmic sequences), parses and interprets the strings, and triggers the drum samples.

Controlling Widgets in Cabbage

I began coding the drum machine in CsoundQt, but managing the widgets (i.e. buttons, knobs, and sliders) became cumbersome as the drum machine became more complex. I needed a more efficient way to work with lots of widgets in an instrument. On the Csound listserv [edit: the listserv has mostly moved over to the Csound forum] I saw someone recommend another Csound development environment called Cabbage, so I decided to give it a shot. There was a learning curve going from CsoundQt to Cabbage, but I could see the benefits.

Drum machine in Cabbage
Screenshot of Cabbage, code, and drum machine.

Special Features

"hallen_drum_machine_2019_9_6.mp3" -- A live performance of the drum machine.

Here's a recording of a live performance I did with this drum machine. It's pretty simple, but it's made from scratch! That's as far as I got on the drum machine because another project grabbed my attention at the time. I'm sure I'll return to this though. When I do, I'd like to expand the number of characters the user can use to control the rhythmic patterns. I'd also like to spend more time "tuning the randomness" in the drum machine because truly random rhythmic patterns are often not satisfying musically. That's for another day.

Leave a Comment

Your email address will not be published. Required fields are marked *