MP3, FLAC, MOD, & WAV with SW or HW DAC in Arduino IDE
Posted: Sat Aug 12, 2017 12:25 pm
I've created a library for the ESP8266 Arduino IDE which can play stereo MP3s, WAVs, and MODs over an I2S DAC or using the I2S as a 32x oversampling delta-sigma DAC for a 1-transistor speaker output.
The MP3 playback is a clean room port of the libmad sources. I looked at the NONOS-SDK version, but frankly comments like "I breaked things..." for GIT commits made me stop right there. This new port runs under the Arduino IDE and supports stereo output at 44.1khz. Stack usage is about 1K, and HEAP maximum is ~34K, but when not actually in the decoder about 10KB add'l are freed.
The I2SNoDAC class implements a delta-sigma ADC with 32x to 128x oversampling (but at 44.1khz only 32x is supported because of I2S interface max clock limitations). At 32x oversampling and 44.1khz it sounds very good even without a low-pass filter. Unlike the NONOS-SDK this is not a hardcoded lookup table, but dynamically interpolates every bit and should give an effective 8-12 bit dynamic range.
The library includes samples and the readme shows the schematic for the 1-transistor speaker driver, and can read from SPIFFS or PROGMEM.
There are also Microsoft WAV playback objects and Amiga ModTracker (chiptunes!) objects.
It's available at GitHub: https://github.com/earlephilhower/ESP8266Audio
[edit 8/17] FLAC support was just added via libFLAC 1.3.2
The MP3 playback is a clean room port of the libmad sources. I looked at the NONOS-SDK version, but frankly comments like "I breaked things..." for GIT commits made me stop right there. This new port runs under the Arduino IDE and supports stereo output at 44.1khz. Stack usage is about 1K, and HEAP maximum is ~34K, but when not actually in the decoder about 10KB add'l are freed.
The I2SNoDAC class implements a delta-sigma ADC with 32x to 128x oversampling (but at 44.1khz only 32x is supported because of I2S interface max clock limitations). At 32x oversampling and 44.1khz it sounds very good even without a low-pass filter. Unlike the NONOS-SDK this is not a hardcoded lookup table, but dynamically interpolates every bit and should give an effective 8-12 bit dynamic range.
The library includes samples and the readme shows the schematic for the 1-transistor speaker driver, and can read from SPIFFS or PROGMEM.
There are also Microsoft WAV playback objects and Amiga ModTracker (chiptunes!) objects.
It's available at GitHub: https://github.com/earlephilhower/ESP8266Audio
[edit 8/17] FLAC support was just added via libFLAC 1.3.2