troydenton.ca

Yep, I'm on the internet

Drum Machine pt1

Feb 5, 2025

Update (Feb 10 2025) - Part 2 is now up

I've been working on a foot-actuated drum machine. It's a work in progress. This drum machine will eventually let me play samples and punch in patterns with foot switches, which is useful when you are also playing a guitar. The closest product I've found to this idea is the "Beat Buddy" pedal, but it costs a lot and isn't close enough to what I want. I'll just invent stuff instead.

Hardware

Good-feeling foot switches are what will make or break this project. That, and all of the other things that break my projects. This project has one more degree of freedom when it comes to breaking.

Eventually, I will design my own footswitches. I want them very big and kickable. This is still a prototype, though, so I'm using good-enough foot switches at the moment. These are just whatever the local hardware store had. I convinced FreeCAD that they exist by clicking a lot of things and pushing a lot of buttons:

Anyway, I didn't have any project boxes around so I designed + printed one. Normally these switches would be panel-mounted, i.e. the face of enclosure bears the force of foot stomps. That's probably asking too much of PLA. On this design, the switches slide into a channel which supports them from them bottom. I'm hoping that most of the actuation force is bore by the (thick-layered) bottom of the enclosure. It hasn't busted yet, so I'm happy enough with it. One less degree of breaking to worry about.

While I was designing the enclosure, I had the foresight to put a wide wiring channel accessible from the back. It's very useful. It also cuts down on print time.

Computer brain

Like many computer nerds in their 30's, I have about 87 raspberry pi's in a box somewhere, so I just used one of those. Few things are as satisfying as finally using a part you've been keeping around for 5+ years.

Initially I didn't want to run real-time audio software on a task-switching OS, but I also didn't have any smaller micros with enough sample memory. I briefly entertained the idea of using a bare-metal OS on the rpi, but I'm not unemployed enough for the time commitment. Until such a time, with much buffer and sample period tweaking, the sound trigger latency feels like its sub-40ms. That's good enough for now.

Software

Originally I wrote an ALSA-based audio engine - triggering samples worked fine, but it's metronome bpm was very inconsistent. I think my program wasn't "real-time" enough, bordering on imaginary-time. Imaginary-time is really bad for things like metronomes, so I threw it out and used RTAudio instead. RTAudio is working very well.

I was hoping for a way to do interrupt-based GPIO stuff. Maybe it can be done, but I couldn't find it in 45 seconds of googling so I gave up forever. Polling every couple milliseconds is working for now. RTAudio does the audio data shuffling in a separate thread, so my main thread can spend all of it's time polling and debouncing switches. Speaking of debouncing switches, these switches needed like 30+ milliseconds of debouncing and a minimum "actuated" registering window; when you release the switch, it will briefly bounce from 'open' back to 'closed'. I think that's the first time I've seen it happen. What a crazy world we live in. Nothing else about the world is crazy right now, except for the minutiae of these cheap switches.

So far, it can trigger samples with the footswitches during live playback, play a metronome click, and change the click tempo via "tap" entry on one of the buttons. The samples can be re-triggered and overlap each other. This represents most of the 'hard part', I hope.

What's next