I2S MP3 webradio streaming example//I2S MP3 webradio流例子

This is 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.

这是一个使用ESP8266的I2S模组输出声音的例子。在这个案子中,他解码MP3数据输出
数据(其实,更准确是:MPEG2 layer III 数据)。这里的代码为一个基本的webradio
连接到一个Icecast服务器,下载MP3数据,解码并且通过I2S总线输出到DAC。MP3解码器
用320KBit/s的波特和48KHz的采样率数据进行测试。

## Configuration options, building//配置控制,编译

All high-level options can be configured in mp3/user/playerconfig.h. Edit
that file to set up your access point and a webradio stream or other source of
MP3 data served over HTTP.

所有高级的控制可以通过配置mp3/user/playerconfig.h来实现。编译文件设置你的
访问点和webradio流或者其它的机遇HTTP的MP3数据服务。

To build the code, try running make.sh in the mp3/ directory. Alternatively,
the way to use ‘make’ to build this code is:
make COMPILE=gcc BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE=1024

编译代码,通过运行mp3/make.sh文件来实现。或者通过运行‘make’来实现:
make COMPILE=gcc BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE=1024

The resulting binaries will be in the bin/ folder. Please disregard the message
that pops up at the end of the make process: the addresses it mentions are
wrong. The correct addresses to load the resulting files are:

编译的结果将出现在 bin 文件夹下。请忽略弹出的消息,将make运行完成:它提到的
地址是错误的。正确的装载文件地址在如下面显示的:

bin/eagle.flash.bin     - 0x00000
bin/eagle.irom0text.bin - 0xA0000

Needed hardware //需要的硬件

If you want to have nice, high-quality buffered audio output, you will need to
connect two ICs to your ESP: a 128KByte SPI RAM and an I2S codec. Both ICs are
optional, but you will get stuttering and low-quality sound if you leave them
off.

如果你需要一个好的,高质量的音频输出,你将需要连接2个ICs到你的ESP:一个128KByte
的SPI RAM和一个I2S codec。如果你需要一个断断续续的和低质量的声音的话,你可以
不需要这两个芯片。

The SPI RAM is a Microchip 23LC1024 part and is used to buffer the incoming
MP3 data. This guards against latency isuues that are present in all but the
most quiet networks and closest connections. It is connected to the same
bus as the SPI flash:

SPI RAM采用Microchip的23LC1024芯片,用来缓存接收MP3数据。
This guards against latency isuues that are present in all but the most quiet networks and closest connections.它连接到SPI Flash相同的总线。

ESP pin   - 23LC1024 pin
------------------------
GPIO0     - /CS (1)
SD_D0     - SO/SI1 (2)
SD_D3     - SIO2 (3) *
gnd       - gnd (4)
SD_D1     - SI/SIO0 (5)
SD_CLK    - SCK (6)
SD_D2     - /HOLD/SIO3 (7) *
3.3V      - VCC (8)*=optional, may also be connected to Vcc on 23LC1024 side.//也许可以将这些引脚连接到Vcc在23LC1024侧。

One way to make these connections is to take the SSOIC version of the 23LC1024,
bend up pin 1 (/CS) and piggyback it on the SPI flash chip that already is on the
ESP module. Solder all the pins to the same pins on the SPI flash chip except
for the bent /CS pin; use a wire to connect that to GPIO0.

As Github user milkpirate correctly remarked, GPIO0 is also used to enter
programming mode on the ESP8266 and will interfere with correct flashing if kept
low. The correct way of flashing the module is to make GPIO0 low, reset the
ESP8266 to enter programming mode, then make GPIO0 high again. Tools like
esptool.py generally follow this method to automatically enter programming
mode; if you manually enter programming mode you may have to adjust your
methodology.

For the I2S codec, pick whatever chip or board works for you; this code was
written using a ES9023 chip, but other I2S boards and chips will probably
work as well. The connections to make here are:

对于I2S codec, 不论你选择芯片或板子;这个代码使用的是ES9023芯片进行编写,但是其它I2S板子和芯片应该也可以工作的很好。引脚连接参照下面的方法:

ESP pin   - I2S signal
----------------------
GPIO2/TX1   - LRCK
GPIO3/RX0   - DATA
GPIO15      - BCLK

Also, don’t forget to hook up any supply voltages and grounds needed.

当然,不要忘记连接所有需要的电源和地。

Running without the SPI RAM part // 没有SPI RAM元件运行

To not use the SPI RAM chip, please edit mp3/user/playerconfig.h and
define FAKE_SPI_BUFF. This will use a much smaller buffer in the main
memory of the ESP8266. Because the buffer is much smaller, the code
will be very sensitive to network latency; also, clock synchronization
with live streaming stations will not work. Expect the sound to cut
out a fair amount of times unless you have a quiet network and connect
to a server very close to you.

不使用SIP RAM芯片,请编辑 mp3/user/playerconfig.h,定义FAKE_SPI_BUF。这将在ESP8266的主内内存中使用非常小的缓冲器。因为缓冲器非常小,代码对网络延迟将非常敏感。同样,直播站的时钟同步将不工作。期望声音挖出大量的时间,除非你有一个清静的网络,并且连接的服务器距离你非常近。

Running without the I2S DAC // 没有I2S DAC 运行

To not use an I2S DAC chip, please edit mp3/user/playerconfig.h and
define PWM_HACK. This uses some code to abuse the I2S module as a
5-bit PWM generator. You can now connect an amplifier to the I2S
data pin (GPIO3/RX0) of the ESP module. Connecting a speaker
directly may also work but is not advised: the GPIOs of the ESP
are not meant to drive inductive loads directly.

不使用一个I2S DAC芯片,请编辑 mp3/user/palyerconfig.h,定义PWM_HACK。这是用一些代码滥用I2S模组作为一个5-bit PWM产生器。有可以连接一个放大器到ESP模块的I2S数据输入引脚(GPIO3/RX0)。直接连接一个喇叭也是可以工作了。但是,这是不被推荐的:ESP的GPIO的意思不是说可以直接驱动感性负载。

Sound quality // 声音质量

In the default configuration, this code will output 16-bit mono audio.
Stereo audio is possible but hasn’t been implemented yet: a stereo
synth is available but has not been modified for ESP8266 use yet. In
PWM mode, the output is a dithered 5-bit PWM output. Furthermore, the
ESP can decode a pretty wide range of bitrates: 96KBit to 320KBit
MP3s have been tested and seem to work fine. Sound quality in general
is not bad, but the scaling and clock adaption algorithms can use
some improvement if the decoder needs to output real high-quality
sound: Patches are welcome.

在默认的配置里,这个代码输出16-bit的单声道声音。立体声是可能的,但是还没有实现:立体声合成是有效的,但是还没有修改给ESP8266是用。在PWM模式下,输出是一个紧张的5-bit PWM输出。此外,ESP能够解码一个非常宽范围的波特率:96KBit - 320KBit的MP3测试,看其来工作很好。产生的声音质量也不坏,但是缩放和时钟自适应算法可以使用一些改进,如果解码器需要输出真实高质量的声音:欢迎创建分支。

About the FreeRTOS SDK used // 关于使用的 FreeRTOS SDK

The MP3 example is a very memory-sensitive piece of code: the MP3 decoder
uses almost all the RAM and the needed buffers for input and output
buffering take up the rest: when using no external SPI RAM, only a few
bytes of memory are left. The SDK libs that come with this example are
libraries that have been optimized for memory usage and are known to work.

MP3代码是一个内存非常敏感的一块代码:MP3解码器使用几乎所有的RAM,输入和输出需要的缓冲器使用了剩余:当不使用外部SPI RAM,仅剩余几个字节的内存。伴随这个例子的SDK库是一个已经优化了内存使用的库,这是众所周知的工作。

Technical details on this implementation // 这个实现的技术详情

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.

在输出侧,MP3 采样数据使用DMA传送给了I2S子系统。I2S DMA基于大量的小缓冲区组成的环形缓冲区。DMA尽快排空到I2S子系统的缓冲区,它将产生一个中断。这个中断将放置buffer地址到一个序列。

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.

当MP3解码器有一个采样串准备好,它将pop

While the ESP8266 is able to run at 160MHz, we’re leaving it at its
default speed of 80MHz here: it seems that at that speed the ESP8266
is perfectly capable of decoding even 320KBit MP3 data.

事实上ESP8266能够运行在160MHz,在这里我们保持它在默认80MHz速度:看起来ESP8266的速度甚至有能力解码320KBit的MP3数据。

https://github.com/espressif/esp8266_mp3_decoder相关推荐

  1. 一步一步指引你在Windows7上配置编译使用Caffe(https://github.com/fengbingchun/Caffe_Test)

    之前写过几篇关于Caffe源码在Windows764位上配置编译及使用过程,只是没有把整个工程放到网上,最近把整个工程整理清理了下,把它放到了GitHub上.下面对这个工程的使用作几点说明: 1.   ...

  2. 1 sec on Large Judge (java): https://github.com/l...

    1 sec on Large Judge (java): https://github.com/leoyonn/leetcode/blob/master/src/q029_substring_of_a ...

  3. https://github.com/fendouai/Awesome-Chatbot

    https://github.com/fendouai/Awesome-Chatbot

  4. github push报 Unable to access ‘https://github.com/xxxx/xxxx.git/‘: OpenSSL SSL_read: Connection was

    idea操作git时 报 Unable to access 'https://github.com/xxxx/xxxx.git/': OpenSSL SSL_read: Connection was ...

  5. ESP32彩屏应用开源了https://github.com/wireless-tag-cn/lv_port_esp32

    号外.号外-- 久久等候的ESP32彩屏终于开源了 https://github.com/wireless-tag-cn/lv_port_esp32 启明云端是国内乐鑫最高级别的核心合作伙伴,年初推出 ...

  6. git remote add Mycat https://github.com/MyCATApache/Mycat-Server.git

    git remote add Mycat https://github.com/MyCATApache/Mycat-Server.git 这个命令总是忘记

  7. unable to access ‘https://github.com/***.git‘: OpenSSL SSL_read: Connection was reset, errno 10054

    Git提交项目报错: unable to access 'https://github.com/***.git': OpenSSL SSL_read: Connection was reset, er ...

  8. fatal: unable to access ‘https://github.com/***.git/‘: OpenSSL SSL_read: Connection was reset, errno

    写了点code,想交到GitHub,结果报了个错. fatal: unable to access 'https://github.com/koking0/Algorithm.git/': OpenS ...

  9. fatal: unable to access ‘https://github.com/PanJiaChen/vue-element-admin.git/‘: OpenSSL SSL_read: Co

    将git clone https://github.com/PanJiaChen/vue-element-admin.git 中的https改为git即可. 例:git clone git://git ...

最新文章

  1. 太嚣张了!会Python的人!
  2. android谷歌补丁日期,在谷歌日历Android中添加开始日期和结束日期之间所有日期的事件...
  3. Visual C# 3.0 新特性概览
  4. linux的centos版本修改时间重启后无效的问题
  5. 信息系统项目管理师-项目采购管理核心知识点思维脑图
  6. php5.6 交叉编译,Cross-compile - 龙芯开源社区
  7. 前端学习(3059):vue+element今日头条管理-优化文章状态
  8. CVPR2021论文整理
  9. atitit.提升开发效率---MDA 软件开发方式的革命(4)----编辑表单建模
  10. python 声音模仿_浅谈盘点5种基于Python生成的个性化语音方法
  11. 解构给默认值_使用 JavaScript 解构让代码更优雅
  12. 《数据挖掘概念与技术》第三版 范明 孟小峰译 课后习题答案(一)
  13. IP地址规划之子网划分
  14. 专访王豫翔:编程道路上的“三少三多”
  15. Microarchitecture: HyperThreading(超线程)
  16. 做戴威式的管理者,还是雷军式的管理者?
  17. Excel2016通过宏生成拼音码
  18. android微信下拉出现小程序,仿新版微信的小程序下拉栏
  19. 最小化一维曼哈顿距离的简单证明
  20. sourceTree使用教程

热门文章

  1. Flex AS3数据类型转换成Fluorine数据类型
  2. Matlab/Simulink中查表函数的应用
  3. chrome91.0.4472.77(正式版本)(64位) windows和mac跨域解决
  4. 【MOT】多目标追踪学习笔记之MOTR
  5. 快速排序法(随缘学习)
  6. 计算机经典图书介绍 [转]
  7. 在linux系统中使用USB存储器
  8. WPF进阶之接口(4):ICommand实现详解
  9. 瞎写 - 如何“免费”在codeforge下载代码
  10. 【观察】vivo上线政企开放平台,解读背后的三重新价值