1 alsa-utils
alsa-utils是alsa驱动测试的一个命令合集,包含alsactl, aconnect, alsamixer, amidi, amixer, aplay, aplaymidi, arecord, arecordmidi,aseqnet, iecset, speaker-test。常用语的命令有alsamixer,amixer,aplay,arecord。其他的用到再看。
1.1 amixer
amixer -h
查看使用命令
root@linaro-ubuntu-desktop:~# amixer -h
Usage: amixer <options> [command]
Available options:
-h,--help this help
-c,--card N select the card //指定声卡,默认为声卡0
-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
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 //sset sget用于操作
sget sID get contents for one mixer simple control //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 //cset cget用于操作controls
cget cID get control contents for one control
amixer contorls/scontrols
查看当前声卡有哪些control,两个命令显示格式不一样
root@linaro-ubuntu-desktop:~# amixer controls
numid=25,iface=MIXER,name='Headphone Aux Volume'
numid=26,iface=MIXER,name='Headphone Mixer Switch'
numid=24,iface=MIXER,name='Headphone ZC Switch'
numid=23,iface=MIXER,name='Headphone Switch'
numid=22,iface=MIXER,name='Headphone Volume'
numid=20,iface=MIXER,name='ADC High Performance Switch'
numid=14,iface=MIXER,name='Capture HPF Cutoff'
numid=13,iface=MIXER,name='Capture HPF Mode'
numid=12,iface=MIXER,name='Capture HPF Switch'
numid=16,iface=MIXER,name='Capture LHPF Mode'
numid=15,iface=MIXER,name='Capture LHPF Switch'
numid=11,iface=MIXER,name='Capture ZC Switch'
numid=10,iface=MIXER,name='Capture Switch'
numid=9,iface=MIXER,name='Capture Volume'
root@linaro-ubuntu-desktop:~# amixer scontrols
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone Aux',0
Simple mixer control 'Headphone Mixer',0
Simple mixer control 'Headphone ZC',0
Simple mixer control 'Speaker',0
Simple mixer control 'Speaker Boost',0
Simple mixer control 'Speaker Mixer',0
Simple mixer control 'Speaker ZC',0
Simple mixer control 'Sidetone',0
Simple mixer control 'Beep',0
Simple mixer control 'Capture',0
Simple mixer control 'Capture HPF',0
Simple mixer control 'Capture HPF Cutoff',0
amixer contents/scontents
查看当前声卡control的内容及选项,两个命令显示格式不一样
root@linaro-ubuntu-desktop:~# amixer contents
numid=25,iface=MIXER,name='Headphone Aux Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=7,step=0
: values=7,7
| dBscale-min=-7.00dB,step=1.00dB,mute=0
numid=26,iface=MIXER,name='Headphone Mixer Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=24,iface=MIXER,name='Headphone ZC Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=23,iface=MIXER,name='Headphone Switch'
; type=BOOLEAN,access=rw------,values=2
: values=on,on
numid=22,iface=MIXER,name='Headphone Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=127,step=0
: values=121,121
| dBscale-min=-121.00dB,step=1.00dB,mute=1
root@linaro-ubuntu-desktop:~# amixer scontents
Simple mixer control 'Headphone',0
Capabilities: volume pswitch penum
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 127
Front Left: 121 [95%] [0.00dB] Playback [on]
Front Right: 121 [95%] [0.00dB] Playback [on]
Simple mixer control 'Headphone Aux',0
Capabilities: volume penum
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 7
Front Left: 7 [100%] [0.00dB]
Front Right: 7 [100%] [0.00dB]
Simple mixer control 'Headphone Mixer',0
Capabilities: pswitch penum
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [off]
Front Right: Playback [off]
Simple mixer control 'Headphone ZC',0
Capabilities: pswitch penum
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [off]
Front Right: Playback [off]
amixer cset/cget 设置amixer controls中显示的controls中具体的某个controls详细信息,包含最大值,最小值,当前值,可设置的值范围。可以不输入完整control,只要能标识control,如下代码
root@linaro-ubuntu-desktop:~# amixer cget numid=9
numid=9,iface=MIXER,name='Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
: values=63,63
| dBscale-min=-23.25dB,step=0.75dB,mute=0
root@linaro-ubuntu-desktop:~# amixer cget numid=9,iface=MIXER,name='Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
: values=63,63
| dBscale-min=-23.25dB,step=0.75dB,mute=0
amixer cset改变control的值
root@linaro-ubuntu-desktop:~# amixer cset numid=9 31
numid=9,iface=MIXER,name='Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
: values=31,31
| dBscale-min=-23.25dB,step=0.75dB,mute=0
1.2 alsamixer
命令格式: alsamixer [options]
命令选项:
-h, -help 显示帮助信息
-c <card number or idenfication> 指定需要设置的声卡.默认为0
-D <device identification> 选择需要控制的调节器
-g 设置界面颜色
-s 最小化界面窗口
进入alsamixerl图形界面后,可以使用下面命令操作:
左右箭头或n,p 用来选择通道
上下箭头或+,- 同时调整选定通道的左右声道的音量
B,= 设置左右声道音量相同
M静音当前通道
< > 分别对左,右声道静音
空格 选择录音源.在选定的通道上按"空格",可以标记此通道为录音源.此操作仅限输入设备.插入键或";",删除键或"'"分别选定左右通道
L 刷新屏幕.
PageUp 增大5格音量
PageDown 减小5格音量
End 设置音量为0
分别调整左,右或整个通道的音量
Q,W,E 增大 左,右,通道 的音量
Z,X,C 减小 左,右,通道 的音量
alt-q,ESC 退出
1.3 aplay
aplay -h 可以查看相关用法,对于aplay简单使用
查看当前声卡
root@linaro-ubuntu-desktop:# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: wm8962audio [wm8962-audio], device 0: HiFi wm8962-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: imxhdmisoc [imx-hdmi-soc], device 0: IMX HDMI TX mxc-hdmi-soc-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
播放wav格式音频
aplay test.wav
aplay -Dhw:0,0 -r48000 test.wav //指定设备hw:0,0,hw:card,device,表示card0中设备0,采样率48000
1.4 alsactl
alsactl可以用来保存、恢复声卡配置,默认保存到/var/lib/alsa/asound.state文件,可以使用-f来指定配置文件。在linux系统(包括android)中,如果有asound.state配置文件,通常在系统启动时会将此配置恢复到声卡配置中。这种情况有可能导致在驱动层对声卡寄存器修改无效,因为修改被原有保存的配置覆盖了。所以在调试声卡时,需要注意当前系统中的声卡配置文件。
alsactl store # 保存声卡配置到/var/lib/alsa/asound.state
alsactl store -f /var/lib/alsa/asound.state # -f 保存声卡配置到指定/var/lib/alsa/asound.state
alsactl restore -f /var/lib/alsa/asound.state # -f 从指定/var/lib/alsa/asound.state恢复配置
2 alsa配置文件
alsa配置文件主要在/usr/share/alsa目录下, 最重要的是alsa.conf文件。ubuntu下使用dpkg -S alsa.conf,可以看到alsa.conf是libasound2-data包的一个文件。
rpdzkj@ubuntu:~$ dpkg -S alsa.conf
libasound2-data: /usr/share/alsa/alsa.conf.d/README
libasound2-data: /usr/share/alsa/alsa.conf
libasound2-plugins:amd64: /usr/share/alsa/alsa.conf.d/99-pulseaudio-default.conf.example
alsa.conf文件中使用hook读取了/etc/asound.conf和~/.asoundrc两个配置文件,用户相关的个性化配置可写到这两个文件。
rpdzkj@ubuntu:~$ cat /usr/share/alsa/alsa.conf
@hooks [
{
func load
files [
{
@func concat
strings [
{ @func datadir }
"/alsa.conf.d/"
]
}
"/etc/asound.conf"
"~/.asoundrc"
]
errors false
}
]
利用.asoundrc和asound.conf可指定ubuntu下默认声卡,将下面代码添加到其中一个配置文件中
defaults.pcm.card 1 //aplay -l 显示系统中所有声卡,可能需要root权限执行, 1为对应声卡的编号
defaults.ctl.card 1