Digital Audio For Microcontrollers Doesn’t Come Much Simpler Than A WART

Adding an audio channel to your microcontroller project can mean a pile of extra components and a ton of processing power, as a compressed stream must be retrieved and sent to a dedicated DAC. Or if you are [rdpoor], it can mean hooking up a low-pass filter to the UART that’s present on even the simplest of devices, and constructing a serial data stream that mimics PWM audio.

Sound on your microcontroller, it’s this simple!

WART is a Python script that converts a WAV file into a C formatted byte array that can be baked into your microcontroller code, and for which playback is as simple as streaming it to the UART. The example uses a Teensy and a transistor to drive a small speaker, we’re guessing that better quality might come with using a dedicated low-pass filter rather than relying on the speaker itself, but at least audio doesn’t come any simpler.

The code can be found in a GitHub repository and there’s a few recordings of the output in the files section page, one is embedded below. It’s better than we might have expected given that the quality won’t be the best at the PWM data rate of even the fastest UART. But even if you won’t be incorporating it into your music system any time soon we can see it being a useful addition for such things as small warning sounds. Meanwhile if persuading serially driven speakers to talk is of interest, there’s always the venerable PC speaker.

11 thoughts on “Digital Audio For Microcontrollers Doesn’t Come Much Simpler Than A WART

  1. Nice project.
    However, implementation could be improved in few ways :
    – Instead of using simple oversampling (x10, from the python script), use sigma delta to increase ENOB (and theb play 16bit wav file, as below 10 bits, audio is rather mediocre)
    – The sigma delta could be computed on the script processing wav and generate large binary but is less demanding on the target CPU, or the other way around.
    – add a large (10uF) capacitor in serie with the voice coil and stop heating the room

    1. @Tweepy: Absolutely! I intentionally created the project to (a) be as absolutely as simple as possible [six lines of Arduino code, two external components], and (b) leave lots of room for other people to invent improvements!

  2. This is new to me and I think it is awesome! sure, it is not a solution to music playback but for microcontroller appropriate sounds and voice messages this is awesome.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.