This Github upload shows an example of how to use the I2S module inside the ESP8266 to output sound.
In this case, it is used to output decoded MP3 data (actually, more accurately: MPEG2 layer III data): the code described here basically is a webradio streamer which can connect to an Icecast server, take the MP3 data the server sends out, decode it and output it over the I2S bus to a DAC. The MP3 decoder has been tested for bitrates up to 320KBit/s and sample rates of up to 48KHz.
The biggest part of this code consists of a modified version of libmad, a fixed-point mp3 decoder. The specific version we use here has already been modified by NXP to use less memory (source:www.nxp.com/documents/application_note/AN10583.pdf) and has been massaged by Espressif to store as much constants in flash as possible in order to decrease RAM use even more. The MP3 decoder is fed from a FIFO realized in the external 23LC1024 SPI RAM. This RAM is filled from a network socket in a separate thread.
On the output side, the MP3 samples are fed into the I2S subsystem using DMA. The I2S DMA basically consists of a circular buffer consisting of a number of smaller buffers. As soon as the DMA is done emptying one of the smaller buffers into the I2S subsystem, it will fire an interrupt. This interrupt will put the buffer address in a queue.
When the MP3 decoder has a bunch of samples ready, it will pop a buffer off this queue and put the samples in it until it is full, then take the next buffer etc. The MP3 decoder generally is faster than the I2S output, so at a certain moment there will be no free buffers left. The queue system of FreeRTOS will suspend the mp3 decoding task when that happens, allowing the ESP8266 to attend to other tasks.