Play real music with an ATmega328

Maker creates a slick six-voice AVR wavetable synth song machine.

What originally began as an 8-bit guitar simulator has evolved into a sophisticated six-voice music player running capable of running on an ATmega328 MCU. Maker Enrico Colombini wanted to see how far he could get with only a few resistors and capacitors, and so, selected an Arduino Uno to do the trick.


The project, which is dubbed play-v6is an open-source synthensizer that can be programmed in plain C in Atmel Studio 6 and the Arduino IDE. Using only a tight 512-cycle CPU loop, the device is capable of producing six independent 8-bit voices with individual note volume and a play-time voice mixer, a 31.25 kHz sampling frequency oversampled at 62.5 kHz for better quality and filtering, as well as emitting both built-in music from Flash and uploaded tunes from RAM memory.

play-v6 can function as both a standalone device and via USB-Serial remote control. Beyond that, it is equipped with an adjustable tempo and up to 16 selectable instruments — each with its own waveform and ADSR envelope.


“It’s pretty sweet to get six channels of 31.25 kHz sampled 8-bit audio running on a 16MHz chip. The code underlying it works through some tricky optimization in the sample update routine (UpdateVoiceSample() in play.c if you’re reading along) and by carefully prioritizing the time critical elements,” Hackaday’s Elliot Williams writes.

Aside from simply playing embedded music, the package also includes several system-independent tools. With these, Colombini’s project can act as a compiler that converts sheet music into a compact block of binary data, an instrument generator that creates new or modifies existing sounds to emulate everything from a guitar to an accordion, and an auxiliary tool that to prompts firmware tables. The Maker notes that a music packer is required to store music into the Flash memory of the Arduino, so that it could be played without a USB-computer connection.


Additionally, a table generator is responsible for producing a note table that play-v6 employs to generate the correct pitch (frequency) for a given note. What’s more, it creates the tempo table that controls each musical setting and for how long an 1/64 interval will last. Doing the slow math as infrequently as possible lets Colombini make his timing. For instance, the pitch is updated once every two PWM samples, I/O and other auxiliary player tasks every eights samples, and the sound’s dynamic volume envelope is only recalculated every 48 samples.

“The table generator adds comments in player\tables.c indicating the pitch error for each note, assuming an accurate microcontroller clock. Unfortunately the Arduino Uno uses a cheap and imprecise ceramic resonator instead of the usual crystal. This could add a pitch error up to about 20 cents, but it does not affect the relative pitch between different notes, so unless you are a trained musician with an ‘absolute ear’ you will probably be unable to tell the difference,” the Maker concludes.

Interested? Head over to the project’s official page to learn more, or watch it in action below. (Nice find, Hackaday!)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s