Alsa是Advanced Linux Sound Architecture的缩写,即高级Linux声音架构,在Linux操作系统上提供了对音频和MIDI的支持。Alsa提供的调试命令有基于文本下的图形界面的alsamixer和文本模式的 amixer,amixer也可以称作命令行模式。
Ubuntu Debian 等常见 Linux 终端文件系统音频开发过程,没有显示器但又需要查看音频设备信息,amixer 则是不错的选择。接下来以 rk3568 芯片的 rk809(rk817) codec 为例,讲解如何获取声卡参数设定和如何设定声卡参数。
a) 设定 “Playback Path” 为 “SPK_HP”
$ amixer -c 0 sset "Playback Path" "SPK_HP"
Simple mixer control 'Playback Path',0
Capabilities: enum
Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT' 'SPK_HP' 'RING_SPK' 'RING_HP' 'RING_HP_NO_MIC' 'RING_SPK_HP'
Item0: 'SPK_HP'
b) 获取 “Playback Path” 的参数值
$ amixer -c 0 sget "Playback Path"
Simple mixer control 'Playback Path',0
Capabilities: enum
Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT' 'SPK_HP' 'RING_SPK' 'RING_HP' 'RING_HP_NO_MIC' 'RING_SPK_HP'
Item0: 'SPK_HP'
a) 如何快速查看声卡的信息,命令如下
$ amixer -c 0 contents
numid=2,iface=MIXER,name='Capture MIC Path'
; type=ENUMERATED,access=rw------,values=1,items=4
; Item #0 'MIC OFF'
; Item #1 'Main Mic'
; Item #2 'Hands Free Mic'
; Item #3 'BT Sco Mic'
: values=1
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=6
b)不仅可查看声卡内容,还可查卡控制信息
$ amixer -c 0 controls
numid=2,iface=MIXER,name='Capture MIC Path'
numid=1,iface=MIXER,name='Playback Path'
a) 设定指定声卡可控属性信息
$ amixer -c 0 cget numid=1,iface=MIXER,name='Playback Path'
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=6
b) 获取指定声卡可控属性信息
$ amixer -c 0 cset numid=1,iface=MIXER,name='Playback Path' 4
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=4
$ amixer
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 65536
Front Left: Capture 65536 [100%] [on]
Front Right: Capture 65536 [100%] [on]
a) 设置静音、解决静音
# 播放音频静音
amixer --set 'Master' mute
# 录音静音
amixer --set 'Capture' mute
# 解除播放静音
amixer --set 'Master' unmute
# 接触录音静音
amixer --set 'Capture' unmute
b) 设定音量
amixer sset 'Master',0 100%,80% unmute
# -c 选择声卡, 不设置则为默认
# 'Master',0:Simple mixer control 'Master',0
# 100%,80% : 左声道、右声道音量
amixer - command-line mixer for ALSA soundcard driver.
$ amixer --help
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
Tips
a) 声卡数量信息可根据系统信息查看
cat /proc/asound/cards
0 [rockchiprk809co]: rockchip_rk809- - rockchip,rk809-codec
rockchip,rk809-codec
b) -c 参数声卡名或数字编号, 也就是‘0’ 或者’rockchiprk809co’
c) sset/sget 的参数对应 "contents“的内容,cset/cget的参数对应 controls的属性