Support libraries, good application notes, and worked examples from a manufacturer can really help speed us on our way in making cool stuff with new parts. Espressif Systems has been doing a good job with their ESP8266 product (of course, it doesn’t hurt that the thing makes a sub-$5 IOT device a reality). Only recently, though, have they started publishing completed, complex application examples. This demo, a networked MP3 webradio player, just popped up in Github, written by the man better known to us as Sprite_tm. We can’t wait to see more.
The MP3 decoder itself is a port of the MAD MP3 library, adapted for smaller amounts of SRAM and ported to the ESP8266. With a couple external parts, you can make an internet-connected device that you can point to any Icecast MP3 stream, for instance, and it’ll decode and play the resulting audio.
What external parts, you ask? First is something to do the digital-to-analog conversion. The application, as written, is build for an ES9023 DAC, but basically anything that speaks I2S should be workable with only a little bit of datasheet-poking and head-scratching. Of course, you could get rid of the nice-sounding DAC chip and output 5-bit PWM directly from the ESP8266, but aside from being a nice quick demo, it’s going to sound like crap.
The other suggested external IC is an SPI RAM chip to allow for buffering of the incoming MP3 file. WiFi — and TCP networks in general — being what they are, you’re going to want to buffer the MP3 files to prevent glitching. As with the dedicated DAC, you could get away without it (and there are defines in the “playerconfig.h” file to do so) but you’ll probably regret it.
In sum, an ESP8266 chip, a cheap I2S DAC, and some external RAM and you’ve got a webradio player. OK, maybe we’d also add an amplifier chip, power supply, and a speaker. Hmmm…. and a display? Or leave it all configurable over WiFi? Point is, it’s a great worked code example, and a neat DIY device to show your friends.
The downsides? So far, only the mono version of the libMAD decoder / synth has been ported over to ESP8266. The github link is begging for a pull request, the unported code is just sitting there, and we think that someone should take up the task.
Other Resources
In our search for other code examples for the ESP8266, we stumbled on three repositories that appear to be official Espressif repositories on Github: espressif, EspressifSystems, and EspressifApp (for mobile apps that connect to the ESP8266). The official “Low Power Voltage Measurement” example looks like a great place to start, and it uses the current version of the SDK and toolchain.
There’s also an active forum, with their own community Github repository, with a few “Hello World” examples and a nice walkthrough of the toolchain.
And of course, we’ve reported on a few in the past. This application keeps track of battery levels, for instance. If you’ve got the time, have a look at all the posts tagged ESP8266 here on Hackaday.
You couldn’t possibly want more resources for getting started with your ESP8266 project. Oh wait, you want Arduino IDE support?
Thanks [Sprite_tm] for the tip.
You could generate the audio with PWM.
Use two PWM pins for stereo.
“Of course, you could get rid of the nice-sounding DAC chip and output 5-bit PWM directly from the ESP8266”
I think they have covered that already.
Aye. Unfortunately, only mono audio can be made that way: you really need buffered output, and in this case I abuse the hardware I2S and DMA to do that, but that gives only a single output. To have two outputs, you’d have to do everything in software and I don’t know if that’d leave enough room to actually decode the MP3.
As per the post about the teensy; SPDIF possible ?
Why is it only 5 bits?
Because instead of sending 32-bits PCM data to the I2S DAC, I send 32-bits worth of PWM data. Because in that case every bit has the same weight, I can only send 2^5 values with unique rations between 1s and 0s. Theoretically I could do more, but I don’t really have the memory to buffer that in this application.
Ah, I get it. It repurposes the I2S module as a PWM module, but only achieves 5-bit resolution.
Why not use the built-in PWM module?
I need some buffer to multitask between decoding MP3 data, reading MP3 from the network and various network stack things. Theoretically, it would be possible to modify the PWM code to use a buffer like that, but the PWM mode basically was a quick hack to allow people to test this without waiting for the I2S chip to come in, so I didn’t want to spend too much time on it.
ESP does have hardware SPI, so maybe DSD (https://en.wikipedia.org/wiki/Direct_Stream_Digital) would be possible? Though doing the conversion on-the-fly may be too slow.
The ESP actually has I2S, which in this case is basically SPI with a DMA engine to feed it. The DSD thing you mention seems to need an 1-bit output at 2.8MHz, plus some logic to calculate the output. Processor time I have in the ESP: the MP3 decoder actually uses the CPU at 80MHz while it can run at 160MHz. I fear that the bottleneck is going to be the output buffers: I only have enough to do 1.4MHz 1-bit output… otherwise, it may be worth looking at.
A second-order sigma-delta 1-bit DAC at 1.4MHz should produce reasonable audio quality… and just uses integer addition and subtraction.
Most commercial SD DACs are 5th order, but that wants a multiplier as well as figuring out the correct coefficients for the lowpass filter (while a 2nd order SDDAC is just a double integrator)
I’ve implemented a 2nd-order delta-sigma DAC, and indeed, to my untrained ear at least it seems that the noise is more concentrated in the high frequency bands and should be easier to filter out using a lowpass filter. Check the github repo for the code if you want it. I’m sure a 5th order DAC is doable as well, but I don’t know if the analog qualities of the ESPs output pin warrant implementing that.
Has anyone tried Tremor (fixed point Vorbis codec) with these chips?
There are hardware mp3 decoder chips out there that have a DAC and all inside. why not just one of those and make is stereo with zero need for a decoding library.
https://www.sparkfun.com/products/8125?gclid=CjwKEAjwtMqrBRDwtoehx72vm34SJACl_Un1R0wxL6KfMDieBItdWKCHNcFcWAvS3KBkdJuZ_8aLXRoCxaTw_wcB
Because then it wouldn’t be a sub-$5 device anymore?
I think the cheap Chinese ones probably come in at less than the cost of a standalone DAC and SPI RAM chip, we just don’t really have any way to buy or develop for them unfortunately.
airplay on an esp8266 would be great…
Some 74’595s and a bunch of resistors and you have a cheap I2S DAC. Well, ok, not as cheap as the integrated stuff in high quantities, but at least very easy to source.
74HC595 is $0.45 US QTY1 and that’s a 8-bit mono assuming you actually get 8-bit linearity out of a R2R. The cheapest DAC at Digikey is AK4430ET $1.05 US @ qty 1 with “24-bit” stereo.
Here were I live 74HC595 is 0.19€ + 5.60€ shipping in one shop and 0.20€ + 3.85€ shipping in another shop while Digikey wants to have 18€ shipping unless you order parts for >= 65€. I can’t find any other shop selling the AK4430.
From Farnell Element 14,
UDA1334BT/N2 £1.08
PCM1781DBQ £1.3687
WM8711CBLGEFL/V £1.64
Surely you preferred mail order place would carry some of those?
Am I the only one who would like to see a low bandwidth two way VOIP implementation on these modules?
No
Can’t see a big problem – if the MP3 stack works, a slim SIP stack next and you’re virtually there.
I’m sure a bodged SIP implementation for fun is enough, or trimmed PJSIP for those that want to use any PBX.
And you will be sued for infringing software patents.
Most of the MP3 patents have actually expired now because it’s so old. The standard itself dates back to 1993, and there have been software MP3 decoders that run on an ordinary PC in real time since 1995. (In a sane world, all of them should have expired at this point because it’s been 20 years, but the patent system is a little broken.)
Good to know this. Any way we don’t have software patents in Brazil so it wouldn’t be a problem here : )
Congratulations on your new job at Espressif!
http://www.reddit.com/r/esp8266/comments/38o5uk/software_mp3_decoder_with_i2s_interface_in_an/crx7gxl
Thanks!
Are you based out of Shanghai, or does EspressIf support working remotely?
The .a lib files in github all seem to be empty. Are these files not used or are they binary blobs that EspressIf provides for the tcp/ip stack, freertos, etc.?
What are you working on now, either for the esp8266 web radio, or project-wise?
I’ve used the Espressif job as an excuse to move to Shanghai. No idea on working remotely, I know they don’t mind it for small amounts of time but I’m unsure how good an idea it would be to never come in to the company ever.
The .a files all have data in them (not in text format, so Github doesn’t show it in the preview). They indeed contain the SDK libraries.
How do you like ShangHai so far?
I missed ShangHai. (I used to live in ShangHai between 1992-1997, University then first job.)
Could this be an easy and cheap start for DIY-WLAN-speakers – UPNP-connected and synchronized (Squeeze-Server?)?
I made my own boombox which currently only has Bluetooth input; but I’d rather set the ESP8266 as something that can advertise itself as an audio sink in the wifi network, much like some current TVs will do. And then receive an audio stream from Spotify, Google Play Music, maybe even YouTube.
Is this even feasible? Anyone can point me into the right direction as to which protocol/service should the ESP8266 use to announce itself in the network?
did you find playing spotify to eso8266 based ‘wifi speakers’ was possible?
Does the ESP8266 also output the clock signal for the I2S DAC? I think the ES9023 was mentioned in the README which requires a clock signal of N times the sampling frequency on its MCLK pin.
Ah, now there’s a subtlety. As far as I can tell it doesn’t, but the ES9023 is unusual in that MCLK doesn’t have to be derived from the same clock as BCLK – it supports a special asynchronous mode where MCLK is supplied by a different clock source, and I think you can get modules with an ES9023 and an onboard clock. This is not true of DAC chips in general. Most expect MCLK and BCLK to come from the same clock source and MCLK to be an exact multiple of the sample rate.
Indeed, you can attach an external oscillator to this DAC but it is hard to find a common frequency for 44.1 and 48 khnz for example. I remember that a pic32 (mx220fb32 and other MCUs with a I2S interface are able to do this) was able to output the clock signal (N*fs where N=128,256,…). It would be really useful to have a clock output directly from the ESP8266. Maybe one of the PWM outputs can be used…
I have some questions :
1. Does anyone else thought about sending a PCM/DSD (1-bit sigma-delta modulated data) via wifi and use the ESP8266 as a gate driver for a H-Bridge of a class D amplifier. (PCM to PWM or DSD low pass filter PWM)
Why whould or wouldn’t this work ?
2. Is MP3 necessary because the ESP8266’s data rate is too slow ? I bet that 99% of the users would not hear the difference between a 1-bit delta modulated 48 kHz stream and a 16-bit PCM DAC.
In most cases I don’t care about a full player inside ESP8266, but rather a device to stream audio to and play it over wifi on a decent class D amplifier.
I have some questions :
1. Does anyone else thought about sending a PCM/DSD (1-bit sigma-delta modulated data) via wifi and use the ESP8266 as a gate driver for a H-Bridge of a class D amplifier. (PCM to PWM or DSD low pass filter PWM) Why whould or wouldn’t this work ?
2. Is MP3 necessary because the ESP8266’s data rate is too slow ? I bet that 99% of the users would not hear the difference between a 1-bit delta modulated 48 kHz stream and a 16-bit PCM DAC. In most cases I don’t care about a full player inside ESP8266, but rather a device to stream audio to and play it over wifi on a decent class D amplifier.
What about playing FLAC files instead of MP3? An output directly to coax/spdif should be nice as it would allow to use an external (high quality) DAC.
Hi all ,
I am working on esp8266,my idea is send audio files to MCU, here my MCU is TM4C123 through ESP8266.
Can any one help me how to do this ? Please
Thanks in advance
Rohit
Hey, is there any way to compile the code with arduino? Im glad that i can manage arduion on my Windows, but im not understanding anything about the makefile etc.. I already got my ESP8266 ESP-01 with the aditional SPI RAM installes also all the wiring is done, now im only lacking the Software. I want to use the pwm chanel as the sound output.