This is a follow-up to my old post about advanced audio effects on a diorama, where I described the capabilities of the ESP8266Audio library and how it can be used to create realistic sound effects.

I decided to have my own try on welding effect on a model train layout with sounds, and here I present my findings on the topic of audio libraries for audio playback.

I’ve found some more Arduino libraries that allow such tasks. Compared to ESP8266Audio, some of these solutions target AVR MCUs, so will work on a classic Arduino UNO or NANO.

Mozzi

The library is aimed at music synthesis, so polyphony comes as a default, as are some effects like frequency changes. Has built-in support for looping samples, with customizable loop points, which is a nice feature for engine sounds or similar long-lasting looping sounds.

Does not support WAV files, you’ll need to encode your samples as a Mozzi-specific C array. It’s designed to play small samples that are stored in MCU flash, so completely lacks features for streaming data from SD card, Internet or anything similar.

Targets AVR-based Arduinos, so can work with minimal amount of resources. Also supports a wide range or targets like STM32, RP2xxx, ESP32, ESP8266, Teensy and others.

The API allows to start/stop individual samples at any time, so it’s easy to play multiple samples at the same time and synchronize sounds with other events, like lighting effects. All in all, I quite liked the API and structure of the library.

TMRpcm

Plays WAV files from SD card (attached to Arduino via SPI bus). It’s written to play one file at a time, but can be used to play 2 files simultaneously by sending them to different PWM channels and mixing them in hardware (see MultiTrack examples). Works with AVR-based Arduinos, so needs minimal amount of resources.

I briefly looked at the internals of the library and it's horrible didn’t like the design decisions, for example those that restrict playing multiple files into a single output.

ESP32Synth

As the name suggests, works only with ESP32-based MCUs (and relies on its FreeRTOS for background processing). Has massive polyphony, can play samples from SPI SD card. Can output to I2S DACs, built-in DACs, PWM/PDM pins, Bluetooth sinks. I haven’t used it, as for this usecase it doesn’t add much compared to the ESP8266Audio library.

BackgroundAudio

Successor to the ESP8266Audio library, with limited feature set but better performance. Only supports ESP32 and RP2xxx MCUs, not AVR-based Arduinos. I haven’t used it, but may try in future.