Linux ALSA 配置

OS : opensuse 11.04

查看系统audio设备

查看audio设备摘要信息

$ aplay -l

可能的输出:

**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 9: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

查看audio详细信息

$ aplay -L

可能输出:

 null
    Discard all samples (playback) or generate zero samples (capture)
front:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    Front speakers
surround40:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Intel,DEV=0
    HDA Intel, ALC662 rev1 Digital
    IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 0
    HDMI Audio Output

配置文件

最简单的/etc/asound.conf格式如下(用户配置文件为~/.asoundrc

defaults.ctl.card 0
defaults.pcm.card 0
defaults.timer.card 0

pcm.!default {
        type hw
        card 0
        device 0
}

ctl.!default {
        type hw
        card 0
        device 0
}

其中card和device的确定从aplay -l命令得到。对比aplaya -l的输出,可以看到上面的配置文件使用了Intel的音频设备。

设置默认输出设备

首先根据aplay -l的输出来确定声卡ID和设备ID

把Intel模拟输出作为默认audio输出设备

defaults.ctl.card 0
defaults.pcm.card 0
defaults.timer.card 0

pcm.!default {
	type hw
	card 0
	device 0
}

ctl.!default {
	type hw
	card 0
	device 0
}

另一种简化格式:

defaults.pcm.card 0
defaults.pcm.device 0
defaults.ctl.card 0

把Nvidia HDMI数字输出作为默认audio输出设备

defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1

pcm.!default {
	type hw
	card 1
	device 7
}

ctl.!default {
	type hw
	card 1
	device 7
}

另一种简化格式:

defaults.pcm.card 1
defaults.pcm.device 7
defaults.ctl.card 1

测试audio设备

测试指定audio设备

$ speaker-test -D front:Intel -c2 -r44100 -FS16_LE -twav

或者

speaker-test -c 2 -r 48000 -D hw:1,7

测试默认audio设备

$ speaker-test -c2 -r44100 -FS16_LE -twav

调节audio设备

$ alsamixer -c 0 <---[声卡编号]

配置文件的保存和还原

$ alsactl store -f /var/lib/alsa/asound.state
$ alsactl restore -f /var/lib/alsa/asound.state

一些其它问题

怎样改变声卡的识别顺序

可以编辑/etc/modprobe.d/50-sound.conf文件,比如:

options snd slots=snd-hda-intel,snd-hda-intel
# u1Nb.XgOz+05oSl4:Intel Corporation
alias snd-card-0 snd-hda-intel
# NXNs.vUieta7noB9:nVidia Corporation
alias snd-card-1 snd-hda-intel

options snd-hda-intel index=1,0

这里需要关心的是最后一行的index=1,0 重启机器后使用命令 cat /proc/asound/cards 参看输出:

 0 [NVidia         ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xeb000000 irq 17
 1 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xeb300000 irq 42

参考文档1