转自:https://www.cnblogs.com/yikoulinux/p/18102243
基于Linux嵌入式设备常用调试方法很多,本文一口君把调试语音用到的工具和方法给大家做一个简单的介绍。
1. procfs、sysfs
Linux系统上的/proc目录是一种文件系统,即proc文件系统。与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。
基于/proc文件系统如上所述的特殊性,其内的文件也常被称作虚拟文件,并具有一些独特的特点。例如,其中有些文件虽然使用查看命令查看时会返回大量信息,但文件本身的大小却会显示为0字节。此外,这些特殊文件中大多数文件的时间及日期属性通常为当前系统时间和日期,这跟它们随时会被刷新(存储于RAM中)有关。
ALSA有自己的proc tree,在/proc/asound这个目录下可以找到许多关于snd card 的详细信息。
- /proc/asound
rk3568_r:/ # ls /proc/asound -l
total 0
dr-xr-xr-x 5 root root 0 2024-02-19 22:27 card0
dr-xr-xr-x 4 root root 0 2024-02-19 22:27 card1
-r--r--r-- 1 root root 0 2024-02-19 22:27 cards
-r--r--r-- 1 root root 0 2024-02-19 22:27 devices
-r--r--r-- 1 root root 0 2024-02-19 22:27 hwdep
-r--r--r-- 1 root root 0 2024-02-19 22:27 pcm
lrwxrwxrwx 1 root root 5 2024-02-19 22:27 rockchiphdmi -> card1
lrwxrwxrwx 1 root root 5 2024-02-19 22:27 rockchiprk809co -> card0
-r--r--r-- 1 root root 0 2024-02-19 22:27 timers
-r--r--r-- 1 root root 0 2024-02-19 22:27 version
其中主要的节点如下:
- cardx:表示注册的sound card;
- cards:显示当前配置的Alsa Drivers,index,the id string,short and long descriptions;
- version:显示版本字符串;
- devices:列举本机设备映射;
- pcm:列举当前可用的 pcm devides,格式如下:-: : : ;
- /proc/asound/cards
通过 proc fs 确认声卡注册成功
# cat /proc/asound/cards
0 [rockchiprk809co]: rockchip_rk809- - rockchip,rk809-codec
rockchip,rk809-codec
7 [Loopback ]: Loopback - Loopback
Loopback 1
- /proc/asound/devices
查看声卡下的功能设备
rk3568_r:/ # cat /proc/asound/devices
2: [ 0- 0]: digital audio playback
3: [ 0- 0]: digital audio capture
4: [ 0] : control
5: [ 1- 0]: digital audio playback
6: [ 1] : control
33: : timer
对于devices的print格式如下:
- Control设备: “minor: [card_id] : control”;
- PCM设备 : “minor: [card_id- device_id]: digital audio playback/capture”;
- timer设备 : “minor: : timer”;
- /proc/asound/pcm
查看声卡采集、播放PCM信息
rk3568_r:/ # cat /proc/asound/pcm
cat /proc/asound/pcm
00-00: fe410000.i2s-rk817-hifi rk817-hifi-0 : fe410000.i2s-rk817-hifi rk817-hifi-0 : playback 1 : capture 1
01-00: rockchip,hdmi i2s-hifi-0 : rockchip,hdmi i2s-hifi-0 : playback 1
- /proc/asound/version
查看ALSA驱动版本
rk3568_r:/ # cat /proc/asound/version
cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k4.19.232.
- /proc/asound/card0/pcm0p/sub0/status
查看声卡0的信息
rk3568_r:/ # cat /proc/asound/card0/pcm0p/sub0/status
cat /proc/asound/card0/pcm0p/sub0/status
closed
rk3568_r:/sys/devices/platform/rk809-sound # ls
driver driver_override fe410000.i2s-rk817-hifi modalias of_node power sound subsystem uevent
kernel/Documentation/devicetree/bindings/sound/rockchip-i2s.txt rockchip,i2s-tdm.txt
alsa_sound_init函数中会调用snd_info_init函数创建 /proc/asound目录,并将该entry保存在全局变量 snd_proc_root(即作为 sound proc root entry),代码如下
int __init snd_info_init(void)
{
//1、创建 alsa proc root entry;
snd_proc_root = snd_info_create_entry("asound", NULL);
if (!snd_proc_root)
return -ENOMEM;
snd_proc_root->mode = S_IFDIR | 0555;
//2、创建 dir: /proc/asound
snd_proc_root->p = proc_mkdir("asound", NULL);
if (!snd_proc_root->p)
goto error;
#ifdef CONFIG_SND_OSSEMUL
snd_oss_root = create_subdir(THIS_MODULE, "oss");
if (!snd_oss_root)
goto error;
#endif
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
snd_seq_root = create_subdir(THIS_MODULE, "seq");
if (!snd_seq_root)
goto error;
#endif
if (snd_info_version_init() < 0 || //3、创建 file: /proc/asound/version
snd_minor_info_init() < 0 || //4、创建 file: /proc/asound/devices
snd_minor_info_oss_init() < 0 ||
snd_card_info_init() < 0 || //5、创建 file: /proc/asound/cards
snd_info_minor_register() < 0)
goto error;
return 0;
error:
snd_info_free_entry(snd_proc_root);
return -ENOMEM;
}
查看时钟clk summary
查询音频时钟,确认时钟设置正确
示例:查询 i2s0 mclk 频率,以及其所在的 pll,结果:mclk 为 12288000 Hz,pll 源为 cpll
cat /sys/kernel/debug/clk/clk_summary | egrep "i2s0|pll"
pll_cpll 1 1 0 500000000
cpll 5 10 0 500000000
mclk_i2s0_rx_div 0 0 0 500000000
mclk_i2s0_rx_fracdiv 0 0 0 12288000
mclk_i2s0_rx_mux 0 0 0 12288000
mclk_i2s0_rx 0 0 0 12288000
mclk_i2s0_tx_div 1 1 0 500000000
mclk_i2s0_tx_fracdiv 1 1 0 12288000
mclk_i2s0_tx_mux 1 1 0 12288000
mclk_i2s0_tx 1 1 0 12288000
mclk_i2s0_tx_out2io 2 2 0 12288000
2. 寄存器
io命令
通过 io 命令 查看修改寄存器(适合 SOC 寄存器查询),配合芯片手册确认配置以及工作状态。
# cat /proc/iomem | grep i2s
ff800000-ff800fff : i2s@ff800000
# #
io -4 -l 0x40 0xff800000
ff800000: 7200000f 004e000f 10003f3f 00000010
ff800010: 000f0110 01f00000 00000000 00000003
ff800020: 00000000 00000000 00000000 0000001f
ff800030: 00003eff 00003eff 00000303 20150001
regmap
通过 regmap 节点查看寄存器(只读)。
rk3568_r:/ # cat /sys/kernel/debug/regmap/0-0020-rk817-codec/name
cat /sys/kernel/debug/regmap/0-0020-rk817-codec/name
rk808
## rk3568 i2s0控制器寄存器
rk3568_r: # cat /sys/kernel/debug/regmap/fe400000.i2s/registers
cat /sys/kernel/debug/regmap/fe400000.i2s/registers
00: 7200000f
04: 01c8000f
08: 00001f1f
0c: XXXXXXXX
10: 000f0010
14: 01f00000
18: XXXXXXXX
1c: 00000000
20: XXXXXXXX
24: XXXXXXXX
2c: XXXXXXXX
30: 00003eff
34: 00003eff
38: 00000707
## codec es809寄存器
rk3568_r:/ # cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers
cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers
00: 00
01: 00
02: 00
03: 00
04: 00
05: 00
06: 00
07: 00
08: 00
09: 00
0a: 00
0b: 00
0c: 00
0d: 00
0e: 00
0f: 00
10: 00
11: 00
12: 03
13: f4
14: 00
# ls /sys/kernel/debug/regmap/
0-0020-rk817-codec
ff800000.i2s
...
# cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers
12: 03
13: f4
14: 00
15: ff
16: 00
17: 40
18: 48
19: 00
1a: 00
1b: ff
1c: 00
1d: 00
1e: 02
1f: 00
...
注意: regmap 基于 cache 机制,如果通过 io 命令直接修改寄存器后, regmap 节点不会体现更新后的寄存器,除非驱动将寄存器类型设置为 volatile 或者将 regmap cache 关闭。
3. alsa-utils
瑞芯微的android版本的sdk中不支持aplay、arecord、amixer这组命令,下面是以复旦微厂家sdk举例。
官方sdk的buildroot目录下执行make menuconfig:
│ Symbol: BR2_PACKAGE_ALSA_UTILS_APLAY [=y] │
│ Type : boolean │
│ Prompt: aplay/arecord │
│ Location: │
│ -> Target packages │
│ -> Audio and video applications │
│ (1) -> alsa-utils (BR2_PACKAGE_ALSA_UTILS [=y]) │
│ Defined at package/alsa-utils/Config.in:57 │
│ Depends on: BR2_PACKAGE_ALSA_UTILS [=y] │
│ Selects: BR2_PACKAGE_ALSA_LIB_PCM [=y]
aplay
Usage: aplay [OPTION]... [FILE]...
-h, --help help
--version print current version
-l, --list-devices list all soundcards and digital audio devices
-L, --list-pcms list device names
-D, --device=NAME select PCM by name
-q, --quiet quiet mode
-t, --file-type TYPE file type (voc, wav, raw or au)
-c, --channels=# channels
-f, --format=FORMAT sample format (case insensitive)
-r, --rate=# sample rate
-d, --duration=# interrupt after # seconds
-M, --mmap mmap stream
-N, --nonblock nonblocking mode
-F, --period-time=# distance between interrupts is # microseconds
-B, --buffer-time=# buffer duration is # microseconds
--period-size=# distance between interrupts is # frames
--buffer-size=# buffer duration is # frames
-A, --avail-min=# min available space for wakeup is # microseconds
-R, --start-delay=# delay for automatic PCM start is # microseconds
(relative to buffer size if <= 0)
-T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun
-v, --verbose show PCM structure and setup (accumulative)
-V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo)
-I, --separate-channels one file for each channel
-i, --interactive allow interactive operation from stdin
-m, --chmap=ch1,ch2,.. Give the channel map to override or follow
--disable-resample disable automatic rate resample
--disable-channels disable automatic channel conversions
--disable-format disable automatic format conversions
--disable-softvol disable software volume control (softvol)
--test-position test ring buffer position
--test-coef=# test coefficient for ring buffer position (default 8)
expression for validation is: coef * (buffer_size / 2)
--test-nowait do not wait for ring buffer - eats whole CPU
--max-file-time=# start another output file when the old file has recorded
for this many seconds
--process-id-file write the process ID here
--use-strftime apply the strftime facility to the output file name
--dump-hw-params dump hw_params of the device
--fatal-errors treat all errors as fatal
示例:通过声卡0 播放 48k 采样率 2声道 16 位的静音数据
aplay -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f s16_le
/dev/zero
arecord
Usage: arecord [OPTION]... [FILE]...
-h, --help help
--version print current version
-l, --list-devices list all soundcards and digital audio devices
-L, --list-pcms list device names
-D, --device=NAME select PCM by name
-q, --quiet quiet mode
-t, --file-type TYPE file type (voc, wav, raw or au)
-c, --channels=# channels
-f, --format=FORMAT sample format (case insensitive)
-r, --rate=# sample rate
-d, --duration=# interrupt after # seconds
-M, --mmap mmap stream
-N, --nonblock nonblocking mode
-F, --period-time=# distance between interrupts is # microseconds
-B, --buffer-time=# buffer duration is # microseconds
--period-size=# distance between interrupts is # frames
--buffer-size=# buffer duration is # frames
-A, --avail-min=# min available space for wakeup is # microseconds
-R, --start-delay=# delay for automatic PCM start is # microseconds
(relative to buffer size if <= 0)
-T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun
-v, --verbose show PCM structure and setup (accumulative)
-V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo)
-I, --separate-channels one file for each channel
-i, --interactive allow interactive operation from stdin
-m, --chmap=ch1,ch2,.. Give the channel map to override or follow
--disable-resample disable automatic rate resample
--disable-channels disable automatic channel conversions
--disable-format disable automatic format conversions
--disable-softvol disable software volume control (softvol)
--test-position test ring buffer position
--test-coef=# test coefficient for ring buffer position (default 8)
expression for validation is: coef * (buffer_size / 2)
--test-nowait do not wait for ring buffer - eats whole CPU
--max-file-time=# start another output file when the old file has recorded
for this many seconds
--process-id-file write the process ID here
--use-strftime apply the strftime facility to the output file name
--dump-hw-params dump hw_params of the device
--fatal-errors treat all errors as fatal
示例:通过声卡0 录制 16k 采样率 8声道 32 位 的音频数据
arecord -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 16000 -c 8 -f s32_le
r.wav
aplay | arecord
两者通过管道可以方便的实现 loopback 功能,方便驱动调试和指标测试。
示例:声卡0 录制 -> 声卡1 播放
# arecord -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f s16_le
-t raw | aplay -D hw:1,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f
s16_le -t raw
amixer
控制 codec 内部的通路开关,结合 codec 手册的音频拓扑图(比如 图 3-2 RK3308 codec)实现音频流的
路由,音量控制等
Usage: amixer <options> [command]
Available options:
-h,--help this help
-c,--card N select the card
-D,--device N select the device, default 'default'
-d,--debug debug mode
-n,--nocheck do not perform range checking
-v,--version print version of this program
-q,--quiet be quiet
-i,--inactive show also inactive controls
-a,--abstract L select abstraction level (none or basic)
-s,--stdin Read and execute commands from stdin sequentially
-R,--raw-volume Use the raw value (default)
-M,--mapped-volume Use the mapped volume
Available commands:
scontrols show all mixer simple controls
scontents show contents of all mixer simple controls (default command)
sset sID P set contents for one mixer simple control
sget sID get contents for one mixer simple control
controls show all controls for given card
contents show contents of all controls for given card
cset cID P set control contents for one control
cget cID get control contents for one control
示例:查询声卡 controls,将播放通路切换到 SPK
# amixer -c 0 contents
numid=1,iface=MIXER,name='Playback Path'
; type=ENUMERATED,access=rw------,values=1,items=11
; Item #0 'OFF'
; Item #1 'RCV'
; Item #2 'SPK'
; Item #3 'HP'
; Item #4 'HP_NO_MIC'
; Item #5 'BT'
; Item #6 'SPK_HP'
; Item #7 'RING_SPK'
; Item #8 'RING_HP'
; Item #9 'RING_HP_NO_MIC'
; Item #10 'RING_SPK_HP'
: values=0
...
# # amixer -c 0 cset numid=1 2
numid=1,iface=MIXER,name='Playback Path'
; type=ENUMERATED,access=rw------,values=1,items=11
; Item #0 'OFF'
; Item #1 'RCV'
; Item #2 'SPK'
; Item #3 'HP'
; Item #4 'HP_NO_MIC'
; Item #5 'BT'
; Item #6 'SPK_HP'
; Item #7 'RING_SPK'
; Item #8 'RING_HP'
; Item #9 'RING_HP_NO_MIC'
; Item #10 'RING_SPK_HP'
: values=2
alsaloop
支持 任意声卡间的路由
支持 自适应时钟同步
自持 自适应重采样
支持 mixer controls 重定向
Usage: alsaloop [OPTION]...
-h,--help help
-g,--config configuration file (one line = one job specified)
-d,--daemonize daemonize the main process and use syslog for errors
-P,--pdevice playback device
-C,--cdevice capture device
-X,--pctl playback ctl device
-Y,--cctl capture ctl device
-l,--latency requested latency in frames
-t,--tlatency requested latency in usec (1/1000000sec)
-f,--format sample format
-c,--channels channels
-r,--rate rate
-n,--resample resample in alsa-lib
-A,--samplerate use converter (0=sincbest,1=sincmedium,2=sincfastest,
3=zerohold,4=linear)
-B,--buffer buffer size in frames
-E,--period period size in frames
-s,--seconds duration of loop in seconds
-b,--nblock non-block mode (very early process wakeup)
-S,--sync sync mode(0=none,1=simple,2=captshift,3=playshift,4=samplerate,
5=auto)
-a,--slave stream parameters slave mode (0=auto, 1=on, 2=off)
-T,--thread thread number (-1 = create unique)
-m,--mixer redirect mixer, argument is:
SRC_SLAVE_ID(PLAYBACK)[@DST_SLAVE_ID(CAPTURE)]
-O,--ossmixer rescan and redirect oss mixer, argument is:
ALSA_ID@OSS_ID (for example: "Master@VOLUME")
-e,--effect apply an effect (bandpass filter sweep)
-v,--verbose verbose mode (more -v means more verbose)
-w,--workaround use workaround (serialopen)
-U,--xrun xrun profiling
-W,--wake process wake timeout in ms
-z,--syslog use syslog for errors
示例:声卡0录制的音频通过声卡1播放,同步模式采用 策略1(增加或减少采样点)
alsaloop -C hw:0,0 -P hw:1,0 -t 10000 -A 3 -S 1 -b -v
es8388播放和录音举例
/**************************************
* 波形测试, RAW数据
**************************************/
aplay -D hw:0,0 -f S24_LE -r 44100 -c 2 -t raw /bin/busybox & arecord -D hw:0,1 -f S24_LE -r 44100 -c 2 -d 5 record.wav
抓包, 上传record.wav到电脑,可以听见杂波
aplay -D hw:0,0 -f S24_LE -r 44100 -c 2 -t raw test.pcm & arecord -D hw:0,1 -f S24_LE -r 44100 -c 2 -d 5 record.wav
抓包, 上传record.wav到电脑,可以听见疯狂小鸟
aplay -D hw:0,0 -fS24_LE -r 44100 -c 2 -t raw /all_0x00.bin &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav
aplay -D hw:0,0 -fS24_LE -r 44100 -c 2 -t raw /all_0xff.bin &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav
aplay /test.wav &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav
抓包, 上传record.wav, 听见疯狂小鸟
/**************************************
* 设置
**************************************/
# 查看功能
amixer scontrols
# 耳机测试
amixer sset 'Headphone Playback ZC' on # 打开耳机播放 ZC
amixer sset 'Right Output Mixer PCM' on # 打开右声道
amixer sset 'Left Output Mixer PCM' on # 打开左声道
amixer sset Headphone 105,105 # 设置耳机音量
amixer sset Playback 230,230 # 设置播放音量
# 播放
aplay /opt/hardwareTest/wav/test.wav # <---------------------------------------------------
# MIC测试
#设置声卡输入捕获音量大小
amixer sset Capture 56,56
amixer sset 'ADC PCM' 200,200
#音频输入,关闭所有右声道
amixer sset 'Right Input Mixer Boost' off
amixer sset 'Right Boost Mixer RINPUT1' off
amixer sset 'Right Input Boost Mixer RINPUT1' 0
amixer sset 'Right Boost Mixer RINPUT2' off
amixer sset 'Right Input Boost Mixer RINPUT2' 0
amixer sset 'Right Boost Mixer RINPUT3' off
amixer sset 'Right Input Boost Mixer RINPUT3' 0
#音频输入,打开左声道 1 和 2,关闭 3
amixer sset 'Left Input Mixer Boost' on
amixer sset 'Left Boost Mixer LINPUT1' on
amixer sset 'Left Input Boost Mixer LINPUT1' 5
amixer sset 'Left Boost Mixer LINPUT2' on
amixer sset 'Left Input Boost Mixer LINPUT2' 3
amixer sset 'Left Boost Mixer LINPUT3' off
amixer sset 'Left Input Boost Mixer LINPUT3' 0
# 录音
arecord -r 44100 -f S24_LE -c 2 -d 10 -D hw:0,1 record.wav # <---------------------------------------------------
# Line IN 测试
#设置声卡输入捕获音量大小
amixer sset Capture 56,56
amixer sset 'ADC PCM' 200,200
#音频输入,打开左声道 3,,关闭 1 和 2
amixer sset 'Left Input Mixer Boost' on
amixer sset 'Left Boost Mixer LINPUT1' off
amixer sset 'Left Input Boost Mixer LINPUT1' 0
amixer sset 'Left Boost Mixer LINPUT2' off
amixer sset 'Left Input Boost Mixer LINPUT2' 0
amixer sset 'Left Boost Mixer LINPUT3' on
amixer sset 'Left Input Boost Mixer LINPUT3' 5
#音频输入,打开右声道 2,关闭 1 和 3
amixer sset 'Right Input Mixer Boost' on
amixer sset 'Right Boost Mixer RINPUT1' off
amixer sset 'Right Input Boost Mixer RINPUT1' 0
amixer sset 'Right Boost Mixer RINPUT2' on
amixer sset 'Right Input Boost Mixer RINPUT2' 5
amixer sset 'Right Boost Mixer RINPUT3' off
amixer sset 'Right Input Boost Mixer RINPUT3' 0
4. tiny-alsa
RK Android SDK 标配 tiny-alsa 工具。
Linux ALSA 在内核层提供了 alsa-driver
,在应用层提供了 alsa-lib
,应用程序只需要调用 alsa-lib 提供的 API 即可完成对底层硬件的操作。
但由于 ALSA 架构太过于庞大,对于嵌入式设备而言很多功能用不到,且会增加功耗,所以 Android 采用了精简后的 tinyalsa
。
Android 中使用 tinyalsa 控制管理所有模式的音频通路,也可以使用 tinyalsa 提供的工具进行查看、调试。
Tinyalsa 源码位于 android 源码目录下 external/tinyalsa
,可以使用 mmm
命令编译,
mmm external/tinyalsa
编译 tinyalsa 后会生成四个小工具:
- tinymix
- tinyplay
- inycap
- inypcminfo
1) tinypcminfo
tinypcminfo
用于查看 pcm 通道的相关信息,如 PCM 采样率,Channels,采样点数等信息。
Usage: tinypcminfo [-D card] [-d device]
示例:
rk3568_r:/ # tinypcminfo -D 0
Info for card 0, device 0:
PCM out:
Access: 0x000009
Format[0]: 0x000444
Format[1]: 00000000
Format Name: S16_LE, S24_LE, S32_LE
Subformat: 0x000001
Rate: min=8000Hz max=96000Hz
Channels: min=2 max=8
Sample bits: min=16 max=32
Period size: min=8 max=65536
Period count: min=2 max=16384
PCM in:
Access: 0x000009
Format[0]: 0x000444
Format[1]: 00000000
Format Name: S16_LE, S24_LE, S32_LE
Subformat: 0x000001
Rate: min=8000Hz max=96000Hz
Channels: min=2 max=8
Sample bits: min=16 max=32
Period size: min=8 max=65536
Period count: min=2 max=16384
2) tinyplay
tinyplay
是一个简易的音乐播放器,一般用于播放测试。
可以直接进行播放 wav 格式文件,在播放前需要先使用 tinymix 进行相关控件的设置。
Usage: tinyplay file.wav [-D card] [-d device] [-p period_size] [-n n_periods]
示例:播放src_test_xiaoniao.wav、1khz_44100_16bit.wav 音频文件
rk3568_r:/sdcard # tinyplay src_test_xiaoniao.wav
Playing sample: 2 ch, 44100 hz, 16 bit 1764000 bytes
rk3568_r:/sdcard # tinyplay 1khz_44100_16bit.wav
Playing sample: 2 ch, 44100 hz, 16 bit 15876000 bytes
3) tinycap
tinycap
是一个简易的录音软件,一般用于录音测试。
使用之前也需要先设置录音相关的控件,设置好控件后,执行 tinycap xxx.wav 即可将音频录制到 xxx.wav 中。
Usage: tinycap file.wav [-D card] [-d device] [-c channels] [-r rate] [-b bits]
[-p period_size] [-n n_periods]
示例:44.1k 采样率录制音频
# tinycap /sdcard/rec.wav -D 0 -d 0 –c 2 –r 44100 –b 16 –p 1024 –n 3
rk3568_r:/sdcard # tinycap /sdcard/rec.wav -D 0
Capturing sample: 2 ch, 44100 hz, 16 bit
4) tinymix
控制 codec 内部的通路开关, 音量控制等。效果等同于 amixer
1)tinymix
可以查看系统的音频控件,可直接执行 tinymix 进行查看;
2)tinymix 可以手动设置控件的值,控件可通过 tinymix 查看,或者通过 mixer_paths.xml 查看。
usage: tinymix [-D card]
rk3568_r:/sdcard # tinymix --help
tinymix [options] [control name/#] [value to set]
options:
--device|-D <card#> - use the given card # instead of 0.
--all-values|-a - show all possible values/ranges for control.
--tabs-only|-t - separate all output columns/values with tabs.
--value-only|-v - show only the value for the selected control.
示例:
rk3568_r:/sdcard # tinymix
Mixer name: 'rockchip,rk809-codec'
Number of controls: 2
ctl type num name value
0 ENUM 1 Playback Path OFF
1 ENUM 1 Capture MIC Path MIC OFF
rk3568_r:/sdcard # tinymix -a
Mixer name: 'rockchip,rk809-codec'
Number of controls: 2
ctl type num name value
range/values
0 ENUM 1 Playback Path >OFF RCV SPK HP HP_NO_MIC BT SPK_HP RING_SPK RING_HP RING_HP_NO_MIC RING_SPK_HP
1 ENUM 1 Capture MIC Path >MIC OFF Main Mic Hands Free Mic BT Sco Mic
5. i2c工具链
i2c工具主要用于配置codec,本文使用的是es8388,配置该芯片可以通过i2c接口。
通过 i2c tool 查看修改 codec 寄存器(适合 i2c 类型的 codec 设备),配合 codec 手册确认配置以及工作
状态。
rk3568sdk集成i2c工具链,做了精简,与其他版本工具链使用略有差别。
安装命令
apt-get update
apt-get install i2c-tools
linux版本代码下载路径:
https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/
i2cdetect
rk3568_r:/ # i2cdetect --help
usage: i2cdetect [-ary] BUS [FIRST LAST]
usage: i2cdetect -F BUS
usage: i2cdetect -l
Detect i2c devices.
-a All addresses (0x00-0x7f rather than 0x03-0x77)
-F Show functionality
-l List all buses
-r Probe with SMBus Read Byte
-y Answer "yes" to confirmation prompts (for script use)
查询 i2c0 总线上的设备
rk3568_r:/ # i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- --
20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
i2cdump
dump 设备的所有寄存器
rk3568_r:/ # i2cdump --help
usage: i2cdump [-fy] BUS CHIP
Dump i2c registers.
-f Force access to busy devices
-y Answer "yes" to confirmation prompts (for script use)
示例:查询 i2c0 总线下 rk817(设备地址:0x20)的寄存器,其中 0x12 ~ 0x4f 为 codec 寄存器。
rk3568_r:/ # i2cdump -f -y 0 0x20
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 02 00 09 04 08 17 05 00 00 00 01 01 00 01 80 00 ?.?????...??.??.
10: 00 00 03 f4 00 00 00 06 c8 00 00 00 00 00 00 00 ..??...??.......
20: 00 00 00 ff ff 00 00 70 00 66 00 00 00 00 00 0f ...??..p.f.....?
30: 06 03 03 00 a5 02 00 00 01 ff ff 00 00 e0 0f 09 ???.??..???..???
40: 69 7f 0c 58 2d 0c 95 01 00 00 00 0f 20 00 0f 00 i??X-???...? .?.
50: 8c 00 01 00 01 b0 44 10 00 60 00 00 00 00 00 00 ?.?.??D?.`......
60: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 eb 00 ............?.?.
70: 00 00 00 00 ff ff ff ff 00 01 ff ff 00 00 00 00 ....????.???....
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 60 80 e9 7f cb df a6 80 e9 00 00 00 00 00 00 00 `????????.......
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 0f 0f 0f 0f 04 a4 ff ff 00 64 1c 20 64 1a 20 .????????.d? d?
c0: 64 00 00 64 1a 20 6b ff ff ff ff ff 0c 0c 0c 0c d..d? k?????????
d0: 0c 0c 6c 6c 6c 6c 6c 6c 30 30 30 30 30 30 09 31 ??llllll000000?1
e0: 00 00 00 55 a2 c8 c5 40 00 ff 22 03 0a 80 94 0e ...U???@.?"?????
f0: c2 ac a0 40 18 40 00 86 00 fc 00 ff 00 ff 60 00 ???@?@.?.?.?.?`.
i2cget
查询单个寄存器值
Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
b (read byte data, default)
w (read word data)
c (write byte/read byte)
Append p for SMBus PEC
rk3568_r:/ # i2cget --help
usage: i2cget [-fy] BUS CHIP ADDR
Read an i2c register.
-f Force access to busy devices
-y Answer "yes" to confirmation prompts (for script use)
示例:查询 rk817 的 0x12 寄存器
rk3568_r:/ # i2cget -f -y 0 0x20 0x12
0x03
i2cset
修改单个寄存器值
Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE]
... [MODE]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
c (byte, no value)
b (byte data, default)
w (word data)
i (I2C block data)
s (SMBus block data)
Append p for SMBus PEC
rk3568_r:/ # i2cset --help
usage: i2cset [-fy] BUS CHIP ADDR VALUE... MODE
Write an i2c register. MODE is b for byte, w for 16-bit word, i for I2C block.
-f Force access to busy devices
-y Answer "yes" to confirmation prompts (for script use)
示例:修改 rk817(0x20) 的 0x12 寄存器,将值改为0
rk3568_r:/ # i2cset -fy 0 0x20 0x12 0 b
rk3568_r:/ # i2cget -f -y 0 0x20 0x12
0x00
i2ctransfer
i2c-tools-4.0及以后版本添加了i2ctransfer命令。
i2cget和i2cset可以读写的i2c设备的寄存器地址小于0xff,即寄存器是8位地址。
如果i2c设备寄存器是16位地址,可使用i2ctransfer命令,该命令同样可用在寄存器地址是8位的设备。
1、命令
"Usage: i2ctransfer [-f] [-y] [-v] [-V] [-a] I2CBUS DESC [DATA] [DESC [DATA]]...\n"
" I2CBUS is an integer or an I2C bus name\n"
" DESC describes the transfer in the form: {r|w}LENGTH[@address]\n"
" 1) read/write-flag 2) LENGTH (range 0-65535, or '?')\n"
" 3) I2C address (use last one if omitted)\n"
" DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
" = (keep value constant until LENGTH)\n"
" + (increase value by 1 until LENGTH)\n"
" - (decrease value by 1 until LENGTH)\n"
" p (use pseudo random generator until LENGTH with value as seed)\n\n"
"Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):\n"
" # i2ctransfer 0 w1@0x50 0x64 r8\n"
"Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):\n"
" # i2ctransfer 0 w17@0x50 0x42 0xff-\n");
2、用法
## 从i2c 4号总线0x38设备的0x3a01寄存器开始读16个字节的数据,w2:表示寄存器0x3a01的长度为2个字节
i2ctransfer -y -f 4 w2@0x38 0x3a 0x01 r16
## 向i2c 4号总线0x38设备的0x3a01寄存器写0x10,w3:表示寄存器0x3a01和写入值0x10的长度为3字节
i2ctransfer -y -f 4 w3@0x38 0x3a 0x01 0x10
逻辑分析仪
调试过程中,有时候我们需要抓取控制器和codec之间语音信号,并转换成语音数据,
一口君使用的是Kingst的 LA系列逻辑分析仪。
这是一款非常简单容易上手的设备,
即使新手也很容易就能上手,
比示波器好用很多。
后面会单独开一篇讲解该设备如何抓取波形并转换成语音数据。
抓取波形页面