Hacker News Loves Student's Euclidean Drum Machine

Marc Wilhite has long been interested in electronic music, so it didn’t take long for him to use his JavaScript abilities learned at Hack Reactor on a musical side project. In his spare time, Wilhite built the Euclidean Drum Machine, which allows people to quickly create beats based on an algorithm originally conceived by Euclid, the Ancient Greek mathematician. The project’s fun interface, mathematical intrigue and musical applications led to some quick popularity: last week, Wilhite posted the project on Hacker News, where it reached the front page and stayed there for about ten hours.

electronic music, hacker news, hack reactor, beat generator

Marc Wilhite's Drum Machine is based on a Euclidean algorithm, and has a corresponding visualizer, so that users can see their beats in action.

“I was studying for a Master’s degree in music tech at NYU, and I discovered papers about the algorithm,” Wilhite describes. “I thought it would be great to build an app from the ground up.”

The app uses a modified version of an algorithm created by Euclid for finding the greatest common divisor between two numbers. The Euclidean Drum Machine uses this basic principle to evenly slot beats within a cycle of a set length. Wilhite explains the specifics in a blog post:

“Essentially it generates a binary sequence where a number of pulses (beats) is evenly spaced within a certain number of steps. The steps without a pulse are silent. For example if one were to place 4 pulses into 7 steps the result would be the sequence 1-0-1-0-1-0-1 and from there the sequence repeats.”

The user simply chooses the length of the cycle and the number of beats within that cycle for each available sound (or the user can choose to not use that sound), and the application does the rest. This simple process allows anyone to quickly create a fun beat, with a practically endless array of possibilities. The Drum Machine resets every 32 beats (the user can change this number) so that the sounds continue to line up as the user intended them to.

The app was built primarily with the Web Audio API, a JavaScript API which has a number of features to modify and deploy sounds.

“Web Audio API has its own clock that’s separate from the browser clock,” Wilhite explains. “The audio clocks are microseconds accurate. You can use them to schedule events [such as beats] on that clocking system. That’s how you get the audio to sound really really tight.”

Time precision is crucial for an app like this, because a delay of half a second would radically alter the sound.

Wilhite built the user interface for his app using Jquery, and a beat visualizer in d3.

Whether or not it factors into his career as a Software Engineer going forward, Wilhite will continue to use his programming skills to bolster his hobby in electronic music and music tech.

Want to learn to convert your interests into applications? Apply to Hack Reactor, onsite or online today!

Read more:

Student Team Builds 3D-Printed Drone with Tessel Chip

Online Students Create Web RTC Library for Video Conferencing App

Student App Recommends Beers Based on User Ratings