-->
Page 1 of 6

MP3, FLAC, MOD, & WAV with SW or HW DAC in Arduino IDE

PostPosted: Sat Aug 12, 2017 12:25 pm
by earlephilhower
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

Re: MP3, MOD, and WAV with software-DAC playback in Arduino

PostPosted: Mon Aug 14, 2017 12:06 pm
by reaper7
very nice!
what about SD card support?
there's no file seek(pos, dir) only seek(pos) :roll:

Re: MP3, MOD, and WAV with software-DAC playback in Arduino

PostPosted: Mon Aug 14, 2017 2:20 pm
by rudy
Wow that looks fantastic. You are really good. :ugeek:

I bet you could even put a radio selection option on this and stream internet radio with this. :o

;)

Re: MP3, MOD, and WAV with software-DAC playback in Arduino

PostPosted: Mon Aug 14, 2017 3:54 pm
by earlephilhower
reaper7 wrote:very nice!
what about SD card support?
there's no file seek(pos, dir) only seek(pos) :roll:


To run off of SD cards you'd need to write a wrapper subclass, similar to the AudioFileSourceSPIFFS class. All this class does is unify the different "filesystem" classes into one simple interface the consumers can use. I think a SPIFFS File != a SD File, for example, so instead of writing two players just wrap the appropriate calls with a simple base class. None of the players need any seek other than absolute, so no seek(pos,dir), just seek(pos). In fact, I think the only seek required is with the MOD player to pull different samples and events into RAM, the MP3 and WAV just read sequentially.

If you look at the SPIFFS one, it just has a local SPIFFS File class variable and runs 1-line wrappers for each of its methods. The SD one would be the same idea, but I don't have a SD card reader hooked to any of my ESP8266 to test. The examples would still work fine, you'd just need to change the class in setup() from AudioFileSourceSPIFFS to AudioFileSourceSDCard and recompile. the .ino.