I2S播放
1 原理介绍
x1600和x1660系列因为cpu内部没有封装codec功能, 所以录音和播放实现方式与 x2000系列不同. 本开发板硬件设计上I2S和以太网MAC是复用的主控,做功能切换的是两个切换芯片U13和U17. 当 U13、U17 的 2 脚 (IN) 为低电平 0 时, 此时为 MAC 功能. 当 U13、U17 的 2 脚 (IN) 为高电平1 时, 此时为I2S功能.
由下图切换电路的设计可见, 跳冒CON6插上就是I2S导通, 跳冒CON6拔出就是MAC导通.
播放采用I2S 输出数字信号给DAC模块, 经过DAC转成模拟信号后给到功放SPK
2 软件配置
以x1600e_halley6_nand_factory_defconfig为例. 打开IConfigTool工具,选择配置文件
不要配置mac会和I2S冲突
配置i2s
保存iconfig配置
buildroot配置
bhu@bhu-PC:~/work/build$ cd ../buildroot/buildroot
bhu@bhu-PC:~/work/buildroot/buildroot$ make menuconfig
保存并生效配置
bhu@bhu-PC:~/work/buildroot/buildroot$ grep -nr "buildroot" ../../build/configs/x1600e_halley6_nand_factory_defconfig
8:APP_br_dir=../buildroot/buildroot
9:APP_br_config_file=configs/buildroot/buildroot_wifi_common_defconfig //buildroot配置
369:# APP_br_root_login_keep_buildroot is not set
bhu@bhu-PC:~/work/buildroot/buildroot$ cp .config ../../build/configs/buildroot/buildroot_wifi_common_defconfig //修改配置覆盖默认
3 编译烧录
bhu@bhu-PC:~/work/build$ make x1600e_halley6_nand_factory_defconfig
bhu@bhu-PC:~/work/build$ make
烧录固件, 没烧录过见 烧录方法
4 播放测试
4.1 列出设备
# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: dummysoundcard [dummy-sound-card], device 0: x1600 i2s pcm snd-soc-dummy-dai-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
可知, 当前card0为所配置的虚拟声卡设备节点名,device0可作为录音和播放设备. line-in输入音频模拟信号就可以实现录音了
4.2 播放操作
aplay播放
aplay -Dplughw:0,0 -f S16_LE -r 44100 /tmp/test.wav
cmd_alsa 播放
cmd_alsa play device=plughw:0,0 rate=44100 channels=2 file=/tmp/test.wav
详细参数见
# cmd_alsa
cmd_alsa usage
-h/--help : show help info
record : record pcm from device
play : write pcm to device
rate=value : pcm sample rate, default 48000
channels=value : pcm channles, default 2
format=value : pcm format, "s16_le, s24_le, s32_le", default s16_le
buffer_time=value : pcm buffer time, in msecs, defualt get from device
period_time=value : pcm period time, in msecs, defualt 50
time=value : record/paly time, in secs, defualt no limit
device=value : pcm device name, "plughw:0,0 plughw:1,0 hw:0,0 ..." default is defualt
file=value : in/out file path, default is stdin or stdout
list_ctls : list the controls
set_ctl : set the ctl value
get_ctl : get the ctl value
card=value : card name, "hw:0 hw:1 ..." default is default
ctl=value : ctl name, see result of list_ctls, muset be set for get_ctl, set_ctl
value=value : ctl value, see result of list_ctls, muset be set for set_ctl
example:
cmd_alsa record device=hw:1,0 rate=48000 channels=1 time=10 > /tmp/xxx
cmd_alsa play device=plughw:1,0 rate=48000 channels=1 file=/tmp/xxx
cmd_alsa list_ctls card=hw:0
cmd_alsa list_ctls card=hw:1
cmd_alsa set_ctl card=hw:1 ctl="Master Playback Volume" value=18
cmd_alsa get_ctl card=hw:1 ctl="Master Playback Volume"
cmd_alsa get_ctl card=hw:1 ctl="Playback Mute"
源文件见libhardware2/src/cmds/alsa_main.c