Difference between revisions of "Advanced Linux Sound Architecture (简体中文)"

From ArchWiki
Jump to: navigation, search
(安装)
(翻译中)
Line 1: Line 1:
[[Category:Audio/Video (简体中文)]]
+
[[Category:简体中文]]
 
[[Category:Sound (简体中文)]]
 
[[Category:Sound (简体中文)]]
 +
[[Category:Audio/Video (简体中文)]]
 
[[cs:Advanced Linux Sound Architecture]]
 
[[cs:Advanced Linux Sound Architecture]]
 
[[de:Alsa]]
 
[[de:Alsa]]
[[en:Advanced Linux Sound Architecture]]
 
 
[[es:Advanced Linux Sound Architecture]]
 
[[es:Advanced Linux Sound Architecture]]
 
[[fa:ALSA]]
 
[[fa:ALSA]]
Line 9: Line 9:
 
[[he:Advanced Linux Sound Architecture]]
 
[[he:Advanced Linux Sound Architecture]]
 
[[it:Advanced Linux Sound Architecture]]
 
[[it:Advanced Linux Sound Architecture]]
 +
[[ja:Advanced Linux Sound Architecture]]
 
[[nl:Advanced Linux Sound Architecture]]
 
[[nl:Advanced Linux Sound Architecture]]
 
[[pt:Advanced Linux Sound Architecture]]
 
[[pt:Advanced Linux Sound Architecture]]
Line 15: Line 16:
 
[[th:Advanced Linux Sound Architecture]]
 
[[th:Advanced Linux Sound Architecture]]
 
[[tr:Gelişmiş_ses_mimarisi_(ALSA)]]
 
[[tr:Gelişmiş_ses_mimarisi_(ALSA)]]
{{Translateme (简体中文)}}
+
[[en:Advanced Linux Sound Architecture]]
  
高级Linux声音架构(Advanced Linux Sound Architecture,简称'''ALSA''')是一个Linux内核组件,用来代替Open Sound System (OSSv3)为声卡提供设备驱动。 除了声卡设备驱动之外, '''ALSA''' 也包含了一个用户空间库,供应用程序开发者通过高级 API 使用驱动功能,而不是直接与内核驱动交互。
+
{{Article summary start}}
 
+
{{Article summary text|ALSA 的使用、配置及疑难解答。}}
{{注意|如果你要找其它选择请参看[[Open Sound System]]。}}
+
 
+
{{Article summary start|摘要}}
+
{{Article summary text|ALSA 使用、配置及疑难解答。}}
+
 
{{Article summary heading|相关页面}}
 
{{Article summary heading|相关页面}}
{{Article summary wiki|Sound}}
+
{{Article summary wiki|Sound (简体中文)}}
 
{{Article summary wiki|Disable PC Speaker Beep (简体中文)}}
 
{{Article summary wiki|Disable PC Speaker Beep (简体中文)}}
 
{{Article summary end}}
 
{{Article summary end}}
 +
 +
{{TranslationStatus (简体中文)|Systemd|2013-03-14|250172}}
 +
 +
[[Wikipedia:zh:ALSA|高级 Linux 声音体系]](Advanced Linux Sound Architecture,'''ALSA''')是Linux中提供声音设备驱动的内核组件,用来代替原来的开放声音系统(Open Sound System,OSSv3)。除了声音设备驱动,'''ALSA'''还包含一个用户空间的函数库,以方便开发者通过高级API使用驱动功能,而不必直接与内核驱动交互。
 +
 +
{{注意|关于另一种声音体系,请阅读[[Open Sound System (简体中文)|开放声音系统(OSS)]]的页面。}}
 +
 
==安装==
 
==安装==
 +
Arch 默认的内核已经通过一套模块提供了 ALSA,不必特别安装。
  
默认的内核已经包含了 ALSA,所以一般没有必要安装它。
+
[[udev (简体中文)|udev]]会在系统启动时自动检测硬件,并加载相应的声音设备驱动模块。这时,你的声卡已经可以工作了,只是所有声道默认都被设置成静音了。
  
[[udev (简体中文)|udev]]应该在启动时自动检测硬件,加载声卡相关的模块。所以你的声卡应该已经可以使用了,只是默认被静音了。
+
在本地登录(通过虚拟终端或登录管理器)的用户,都有权限播放音频并调整音量。要让远程登录的用户拥有这些权限,必须把用户[[Users and Groups (简体中文)#用户组管理|加入]] {{ic|audio}} 用户组。该组的成员可以直接访问声音设备,会导致某些程序独占音频输出(破坏软件混音),还可能影响用户快速切换和拖机(multiseat)。因此,除非真的有某些[https://wiki.ubuntu.com/Audio/TheAudioGroup 特殊需求],'''不建议'''把用户加入 {{ic|audio}} 用户组。
  
本地登陆(在虚拟终端或显示管理器)的用户被允许播放声音和改变音量。为了使远程登录也能做到这点,这个用户需要 [[Users and Groups (简体中文)#用户组管理|加入]] {{ic|audio}} 组。{{ic|audio}}组的成员也被允许直接访问设备,会导致应用程序获取独占的输出 (破坏软件混音) 和破坏快速用户切换,和 multiseat [http://en.wikipedia.org/wiki/Multiseat_configuration]. 所以, 把用户加入 {{ic|audio}} 组是'''不'''被推荐的,除非你是特别需要[https://wiki.ubuntu.com/Audio/TheAudioGroup]
+
===用户空间工具===
 +
[[Official Repositories (简体中文)|官方仓库]]:
 +
* [[pacman (简体中文)|安装]] {{Pkg|alsa-utils}} 软件包,其中的 {{ic|alsamixer}} 工具允许用户在控制台或终端中配置声音设备。
 +
* 安装 {{Pkg|alsa-oss}} 软件包,如果想让 OSS 应用程序与dmix(软件混音)协同工作。
 +
{{注意|1=从[[udev (简体中文)|udev]]的171版本开始,默认情况下 OSS 仿真模块({{ic|snd_seq_oss}}、{{ic|snd_pcm_oss}}、{{ic|snd_mixer_oss}})不再自动加载。}}
 +
*安装 {{Pkg|alsa-plugins}} 软件包,如果需要 [[#高质量重采样|高质量重采样]]、[[#Upmixing/Downmixing|软件模拟环绕立体声]]和其他高级特性。
  
==用户空间工具==
+
==解除各声道的静音==
来自 [[Official Repositories (简体中文)|官方仓库]]:
+
目前版本的 ALSA 安装后,所有声道'''默认是静音的''',必须手动解除。
* [[pacman (简体中文)|安装]] {{Pkg|alsa-utils}} ,包含 {{ic|alsamixer}} 用户空间工具,能从控制台或终端配置声音设备。
+
* 安装 {{Pkg|alsa-oss}} ,如果你想OSS 应用程序与 dmix (软件混音) 协同工作。
+
{{注意|1=从 [[udev (简体中文)|udev]] >= 171, OSS 仿真模块 ({{ic|snd_seq_oss}}, {{ic|snd_pcm_oss}}, {{ic|snd_mixer_oss}}) 默认不会自动加载。}}
+
* 安装 {{Pkg|alsa-plugins}} ,如果你需要 [[#High quality resampling|高质量采样]], [[#Upmixing/Downmixing|upmixing/downmixing]] 以及其他高级功能。
+
  
==取消通道静音==
+
使用 {{ic|alsamixer}} 的 ncurses 界面,配置十分简单:
  
当前版本的ALSA安装后所有通道'''缺省是静音''',因此即使安装成功并且所有设备都工作正常,你仍然听不到声音。你必须手动开启声音通道。
+
$ alsamixer
  
推荐使用 {{ic|alsamixer}} (ncurses UI) 来完成这个任务:
+
此外,还可以在命令行下使用 {{ic|amixer}}
  
{{bc|$ alsamixer}}
+
$ amixer sset Master unmute
  
底下标有{{ic|MM}}的通道表示该通道是静音的,而{{ic|00}}则表示它是开启的。
+
下方标有 {{ic|MM}} 的声道是静音的,而标有 {{ic|00}} 的通道已经启用。
  
使用左右箭头键在各个通道中切换,按 {{keypress|M}} 键切换{{ic|MM/00}}状态,上下箭头键调整音量。增益值可以在 {{ic|Item:}} 字段看到。过高的增益值会产生失真。
+
使用左右方向键,选中 {{ic|Master}} 和 {{ic|PCM}} 声道。按下 {{keypress|m}} 键解除静音。使用上方向键增加音量,直到增益值为{{ic|0}}。该值显示在左上方 {{ic|Item:}} 字段后。过高的增益值会导致声音失真。
  
想要得到完整的 5.1 或者 7.1 环绕声,你需要取消静音其他的通道,例如 Front, Surround, Center, LFE (subwoofer) 和 Side (这些是使用 Intel HD Audio 的通道名,不同硬件可能不同)。请注意这不会自动 upmix 立体声音源 (如大部分音乐)。想要完成这个功能,参见 [[#Upmixing/Downmixing]].
+
要想得到完整的 5.1 7.1 环绕立体声,还得解除 Front、Surround、Center、LFE (subwoofer) 和 Side 这些声道的静音(上述名称是 Intel HD Audio 声卡使用的声道名,可能因设备不同而有所差异)。注意,仅有这些设置,系统不会自动将立体声源(多数音乐)提升(upmix)成环绕立体声。如果需要这些功能,请阅读[[#Upmixing/Downmixing]]
  
按下 {{Keypress|Esc}} 退出。
+
按下 {{Keypress|Esc}} 键退出 alsamixer。
  
 
{{注意|
 
{{注意|
* 有些声卡需要静音/关闭数字输出通道才能输出模拟声音。对于 Soundblaster Audigy LS 请静音 IEC958 通道。
+
* 有一些声卡,需要关闭数字输出或将其调成静音,才能输出模拟音频信号。对于  Soundblaster Audigy LS 声卡,需要把 IEC958 通道设成静音。
* 一些计算机,(如 Thinkpad T61),有一个 Speaker 通道,也必须被取消静音和进行调整。
+
* 有些机器(如 Thinkpad T61),有一个 Speaker 通道,必须按照上述方法打开调整。
* 一些计算机,(如 Dell E6400) 也许同时需要 {{ic|Front}} 和 {{ic|Headphone}} 通道被取消静音和进行调整。}}
+
* 有些机器(如 Dell E6400),可能还需要把 {{ic|Front}} 和 {{ic|Headphone}} 声道打开调整。}}
  
下一步,测试是否工作:
+
接下来,测试声卡是否工作:
  
{{bc|$ speaker-test -c 2}}
+
$ speaker-test -c 2
  
按照你的扬声器设置改变 -c 参数。对于 7.1 声道,可以使用 -c 8,例如:
+
根据扬声器的实际情况,调整 -c 后的数值。对于 7.1 声道,这个数字是 8:
  
{{bc|$ speaker-test -c 8}}
+
$ speaker-test -c 8
  
如果不工作,查看[[#配置]][[#疑难解答]] 解决问题。
+
如果没有正常工作,请继续阅读 [[#配置]] 以及 [[#疑难解答]] 部分。
  
如果工作,你只需要保存混音器设置。
+
{{pkg|alsa-utils}} 软件包提供了两个配置 alsa 的服务:{{ic|alsa-restore.service}} {{ic|alsa-store.service}}。它们分别在开机和关机时自动运行。
{{bc|# alsactl -f /var/lib/alsa/asound.state store}}
+
这会创建 {{ic|/var/lib/alsa/asound.state}} 文件,保存 alsamixer 设置。
+
  
然后,添加{{ic|alsa}} [[daemon]] 到 {{ic|/etc/rc.conf}} 的 {{ic|DAEMONS}} 部分来自动在启动时还原混音器设置。详细指令参见 [[rc.conf#Daemons]]。
+
==配置==
 +
=== VirtualBox 虚拟机无声音 ===
  
{{注意|alsa daemon 只会读取 {{ic|/var/lib/alsa/asound.state}} 还原混音器级别,这与 Alsa 音频库(以及内核级 API)无关。}}
+
如果使用 VirtualBox 时碰上了麻烦,请尝试以下命令:
  
==配置==
+
{{hc|$ alsactl init|2=<nowiki>
 +
 
 +
Found hardware: "ICH" "SigmaTel STAC9700,83,84" "AC97a:83847600" "0x8086" "0x0000"
 +
Hardware is initialized using a generic method
 +
</nowiki>
 +
}}
 +
 
 +
如果还是不行,请检查所使用的音频软件是否激活了 ALSA 输出。
  
 
===设置默认声卡===
 
===设置默认声卡===
  
====在内核空间====
+
如果发现开机时声卡次序会发生变化,可以在通过 {{ic|/etc/modprobe.d}} 中的 {{ic|.conf}} 文件(比如 {{ic|/etc/modprobe.d/alsa-base.conf}})手动设置次序。
Telephony-capable调制解调器与现代的带有HDMI输出的显卡可能会在默认声音卡插槽的声卡冲突(pcspkr,非ALSA PC扬声器模块的ALSA音效卡,不会发生冲突。) 为了防止出现这种情况, 确保你的声卡的型号在[http://linux.die.net/man/8/lspci lspci(8)]里以及你的ALSA驱动模块在列表里:
+
比如,要让 mia 声卡成为 #0、Intel HDA 声卡成为 #1:
  
{{hc|$ ls -l /sys/module/snd/holders|<nowiki>total 0
+
{{hc|/etc/modprobe.d/alsa-base.conf|2=<nowiki>
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_hda_codec -> ../../snd_hda_codec
+
options snd slots=snd_mia,snd_hda_intel
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_hda_codec_realtek -> ../../snd_hda_codec_realtek
+
options snd_mia index=0
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_hda_intel -> ../../snd_hda_intel
+
options snd_hda_intel index=1
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_hwdep -> ../../snd_hwdep
+
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_pcm -> ../../snd_pcm
+
lrwxrwxrwx 1 root root 0 Apr 25 00:56 snd_timer -> ../../snd_timer
+
 
</nowiki>}}
 
</nowiki>}}
  
Or better (source[http://ubuntuforums.org/showthread.php?t=205449]):
+
snd_mia 和 snd_hda_intel 分别是两个声卡的内核驱动模块。该配置仅适用于同时装有 mia 声卡和使用 snd_hda_intel 驱动的声卡(通常是板载声卡)的情况。
$ cat /proc/asound/modules
+
  
Then add the names of your sound card modules to (source[http://alsa.opensrc.org/MultipleCards#The_newer_.22slots.3D.22_method]):
+
如果使用 -2 的 index 值,ALSA 就不会将对应的设备作为主声卡使用。Linux Mint 和 Ubuntu 等发行版使用了以下配置,避免 USB 声卡和其他“非主流”设备变成 index 为 0 的主声卡:
  
{{hc|/etc/modprobe.d/alsa.conf|2=
+
{{hc|/etc/modprobe.d/alsa-base.conf|2=<nowiki>
options snd slots=snd-intel8x0
+
options bt87x index=-2
}}
+
options cx88_alsa index=-2
 +
options saa7134-alsa index=-2
 +
options snd-atiixp-modem index=-2
 +
options snd-intel8x0m index=-2
 +
options snd-via82xx-modem index=-2
 +
options snd-usb-audio index=-2
 +
options snd-usb-caiaq index=-2
 +
options snd-usb-ua101 index=-2
 +
options snd-usb-us122l index=-2
 +
options snd-usb-usx2y index=-2
 +
# Keep snd-pcsp from being loaded as first soundcard
 +
options snd-pcsp index=-2
 +
# Keep snd-usb-audio from beeing loaded as first soundcard
 +
options snd-usb-audio index=-2
 +
</nowiki>}}
  
These entries ensure that the Intel 82801DB-ICH4 sound card will become card 0 and the PC speaker will become card 1. If there's more cards that have to fall into specific order, their modules can be given to “slots” option as follows:
+
以上配置会在系统重启后生效。
  
{{hc|/etc/modprobe.d/alsa.conf|2=
+
{{Out of date|据英文 Wiki 用户反应,{{ic|/etc/asound.conf}} 这个配置文件默认是不存在的,下列操作可能有误。}}
options snd slots=snd-intel8x0,snd-interwave
+
}}
+
  
This way cards driven by snd-intel8x0 module are enumerated before interwave cards.
+
首先,运行 {{ic|aplay -l}},获取声卡的声卡ID和设备ID:
  
{{Note|
+
{{hc|$ aplay -l|2=<nowiki>
* You will need to unload all your sound modules and reload them for the changes to take effect. It might be easier to reboot. Your choice.
+
**** List of PLAYBACK Hardware Devices ****
* This method will NOT work if the conflicting devices use the same module.  If you would prefer to not configure sound on a per user basis as in the section below, you can directly modify {{ic|/usr/share/alsa/alsa.conf}}.  For example, replace all "card 0" with "card 1" .}}
+
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
 
+
  Subdevices: 1/1
====在用户空间====
+
  Subdevice #0: subdevice #0
This method does not require root permissions, is on a per-user basis, and takes effect as soon as any software has been restarted (like your media player, for example).
+
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
 
+
  Subdevices: 1/1
Located in {{ic|/usr/share/alsa/alsa.conf}} is a list of defaults that alsa uses out of the box.  These can be overridden in a {{ic|~/.asoundrc}} file for each user, or using the same syntax, {{ic|~/etc/asound.conf}} for every user. The following disables dmix, so multiple applications cannot use the same pcm device.
+
  Subdevice #0: subdevice #0
{{hc|~/.asoundrc|2=<nowiki>
+
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
pcm.!default {
+
  Subdevices: 1/1
type hw
+
  Subdevice #0: subdevice #0
card 1
+
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
device 0
+
  Subdevices: 1/1
}
+
  Subdevice #0: subdevice #0
ctl.!default {
+
type hw
+
card 1
+
device 0 #this may cause alsamixer to crash with "cannot open mixer: Invalid argument"
+
}
+
 
</nowiki>}}
 
</nowiki>}}
  
The following leaves dmix intact
+
拿输出中的最后一项来说,这个声卡的声卡ID为2,设备ID为0。若要把这块声卡作为默认声卡,可以把下列配置添加到系统级别的 {{ic|/etc/asound.conf}} 或用户级别的 {{ic|~/.asoundrc}} 文件。如果文件不存在,可以手动创建。其中的各个ID,请根据实际情况调整:
 
+
 
{{hc|~/.asoundrc|2=<nowiki>
 
{{hc|~/.asoundrc|2=<nowiki>
#overrides the defaults set in /usr/share/alsa/alsa.conf
+
defaults.pcm.card 2
defaults.ctl.card 1
+
defaults.pcm.card 1
+
 
defaults.pcm.device 0
 
defaults.pcm.device 0
 +
defaults.ctl.card 2
 
</nowiki>}}
 
</nowiki>}}
 +
“pcm”选项决定用来播放音频的设备,而“ctl”选项决定那个声卡能够由控制工具(如 alsamixer)使用。
  
The 'pcm' options affect which card and device will be used for audio playback.  However it is the 'ctl' option affects which card is used by control utilities like alsamixer, amixer, and the like.
+
上述配置在重启音频程序(如 mplayer)后立即生效。
 
+
To find out which numbers correspond to what audio device, use {{ic|aplay -l}}.
+
$ aplay -l
+
**** List of PLAYBACK Hardware Devices ****
+
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
+
  Subdevices: 1/1
+
  Subdevice #0: subdevice #0
+
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
+
  Subdevices: 1/1
+
  Subdevice #0: subdevice #0
+
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
+
  Subdevices: 1/1
+
  Subdevice #0: subdevice #0
+
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
+
  Subdevices: 1/1
+
  Subdevice #0: subdevice #0
+
  
 
===确认所有声音模块都已经加载===
 
===确认所有声音模块都已经加载===
  
你可以假定udev会正常的自动检测你的声卡,包括OSS兼容模块。你可以通过这个命令进行检查
+
一般 udev 都会自动识别出声卡。使用以下命令确认:
  
{{hc|1=$ lsmod|grep '^snd' | column -t|2=<nowiki>
+
{{hc|<nowiki>$ lsmod | grep '^snd' | column -t</nowiki>|<nowiki>
 
snd_hda_codec_hdmi    22378  4
 
snd_hda_codec_hdmi    22378  4
 
snd_hda_codec_realtek  294191  1
 
snd_hda_codec_realtek  294191  1
Line 178: Line 176:
 
</nowiki>}}
 
</nowiki>}}
  
如果输出和上面类似,你的声音驱动应该已经成功自动检测(请注意在这个案例中,snd_intel8x0和snd_usb_audio是硬件设备的驱动)。
+
如果你的输出和上面类似,那就说明声卡已经被正确识别。
 +
{{注意|1=从[[udev (简体中文)|udev]]的171版本开始,默认情况下 OSS 仿真模块({{ic|snd_seq_oss}}、{{ic|snd_pcm_oss}}、{{ic|snd_mixer_oss}})不再自动加载。如有需要,请[[Kernel_modules_(简体中文)#装入|手动加载]]。}}
  
{{注意|从 {{ic|udev>&#61;171}} 开始,OSS 仿真模块 ({{ic|snd_seq_oss}}, {{ic|snd_pcm_oss}}, {{ic|snd_mixer_oss}}) 默认不会自动加载:如果需要它们,使用 {{ic|modprobe}} 加载它们,并[[Kernel modules#Loading|设置成启动时加载]].}}
+
还可以检查一下 {{ic|/dev/snd/}} 目录,看看是否有这些设备文件:
  
你也可以检查一下目录'''/dev/snd'''有无正确的设备文件:
+
{{hc|$ ls -l /dev/snd|2=<nowiki>
 +
total 0
 +
crw-rw----  1 root audio 116,  0 Apr  8 14:17 controlC0
 +
crw-rw----  1 root audio 116, 32 Apr  8 14:17 controlC1
 +
crw-rw----  1 root audio 116, 24 Apr  8 14:17 pcmC0D0c
 +
crw-rw----  1 root audio 116, 16 Apr  8 14:17 pcmC0D0p
 +
crw-rw----  1 root audio 116, 25 Apr  8 14:17 pcmC0D1c
 +
crw-rw----  1 root audio 116, 56 Apr  8 14:17 pcmC1D0c
 +
crw-rw----  1 root audio 116, 48 Apr  8 14:17 pcmC1D0p
 +
crw-rw----  1 root audio 116,  1 Apr  8 14:17 seq
 +
crw-rw----  1 root audio 116, 33 Apr  8 14:17 timer
 +
</nowiki>}}
  
$ ls -l /dev/snd/
+
{{注意|在 IRC 或论坛寻求这方面帮助时,别忘了贴出上面几个命令的输出。}}
total 0
+
crw-rw----  1 root audio 116,  0 Apr  8 14:17 controlC0
+
crw-rw----  1 root audio 116, 32 Apr  8 14:17 controlC1
+
crw-rw----  1 root audio 116, 24 Apr  8 14:17 pcmC0D0c
+
crw-rw----  1 root audio 116, 16 Apr  8 14:17 pcmC0D0p
+
crw-rw----  1 root audio 116, 25 Apr  8 14:17 pcmC0D1c
+
crw-rw----  1 root audio 116, 56 Apr  8 14:17 pcmC1D0c
+
crw-rw----  1 root audio 116, 48 Apr  8 14:17 pcmC1D0p
+
crw-rw----  1 root audio 116,  1 Apr  8 14:17 seq
+
crw-rw----  1 root audio 116, 33 Apr  8 14:17 timer
+
  
{{Note|If requesting help on IRC or the forums, please post the output of the above commands.}}
+
如果你的输出跟上面类似,或至少有 '''controlC0''' 和 '''pcmC0D0p''',那么声卡就已经正常加载了。
  
如果你至少有'''controlC0'''和'''pcmC0D0p'''或者类似的设备,那么你的声音模块已经被正确检测并加载了。
+
如果出现问题,声卡模块没有正确加载,那么请尝试手动加载模块:
  
如果不是这个结果,表示你的声音模块尚未被正确检测。'''如果你想在IRC或者论坛上寻求帮助,请将上述命令的输出结果粘贴出来。'''要解决这个问题,你得尝试手动加载模块:
+
* 确定声卡对应的驱动模块:[http://www.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard Matrix]。这些模块都会有一个”snd-“前缀(例如:{{ic|snd-via82xx}})。
 +
* [[Kernel_modules_(简体中文)#装入|加载模块]]。
 +
* 检查 {{ic|/dev/snd}} 目录中的设备文件(参见上文);或者,检查 {{ic|alsamixer}} 或 {{ic|amixer}} 的输出是否正确。
 +
* 修改配置,使 {{ic|snd-<模块名>}} 和 {{ic|snd-pcm-oss}} 模块[[Kernel_modules_(简体中文)#装入|开机自动加载]]。
  
* 在[http://www.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard Matrix]里查找你的声卡模块。模块都是以'snd-'作为前缀的(例如:‘snd-via82xx’)。
+
===启用 SPDIF 输出===
* [[Kernel modules#Loading|装载模块]].
+
* 检查'''/dev/snd'''里的设备文件(上面已经叙述),并且/或者尝试'''alsamixer'''或'''amixer'''有没有合理的输出。
+
* [[Kernel modules#Loading|启动时加载]]{{ic|snd-NAME-OF-MODULE}}和{{ic|snd-pcm-oss}}.
+
  
===获得SPDIF输出===
+
(由 Gentoo 论坛的 gralves 提供)
 +
* 在 GNOME 音量控制的选项(Options)标签中,把 IEC958 改成 PCM。该选项可以在首选项中启用。
 +
* 不使用 GNOME 音量控制工具的话:
 +
** 编辑 {{ic|/var/lib/alsa/asound.state}}。该文件是 alsasound 保存混音器设置的地方。
 +
** 找到这一行:“IEC958 Playback Switch”。该行上下应该有一行内容为 {{ic|value:false}},将其改为 {{ic|value:true}}。
 +
** 再找到这一行:”IEC958 Playback AC97-SPSA“。把对应的值改为 0。
 +
** 重启 ALSA。
  
* (来源于gentoo论坛的gralves)
+
{{Out of date|rc.local 在 systemd 中已经弃用,以下方法可能不再适用。}}
* 在Gnome音量控制的选项(Options)标签页下,将IEC958改为PCM。这个选项可以在设置里被启用。
+
* 如果你没有安装Gnome音量控制
+
** 编辑/etc/asound.state。这个文件是alsasound用来保存你的混音器设置的。
+
** 找到有'IEC958 Playback Switch'内容的那行。在它附近你会发现有一行写着value:false,将它改为value:true
+
** 现在找到这行:'IEC958 Playback AC97-SPSA',将值改为0。
+
** 重启alsa。
+
  
另一种登录时自动启用SPDIF输出的方法是(在SoundBlaster Audigy上测试通过):
+
还有另外一个开机自动启用 SPDIF 输出的方法(在 SoundBlaster Audigy 声卡上测试过):
* 加入下面几行到/etc/rc.local:
+
  
 +
* 在 {{ic|/etc/rc.local}} 中添加如下内容:
 
   # Use COAX-digital output
 
   # Use COAX-digital output
 
   amixer set 'IEC958 Optical' 100 unmute
 
   amixer set 'IEC958 Optical' 100 unmute
 
   amixer set 'Audigy Analog/Digital Output Jack' on
 
   amixer set 'Audigy Analog/Digital Output Jack' on
  
你可以用这个命令查看声卡的数字输出名称:
+
使用以下命令,获取你的声卡的数字输出的名称:
 
+
  $ amixer scontrols
$ amixer scontrols
+
  
 
===系统级均衡器===
 
===系统级均衡器===
====使用 AlsaEqual (提供 UI)====
+
====使用 AlsaEqual(包含界面)====
 +
从 [[AUR(简体中文)|AUR]] 安装 {{AUR|alsaequal}}。
  
安装 {{aur|alsaequal}} from the [[AUR]].
+
{{注意|如果使用的是64位系统,而又安装了32位的 Flash 插件,这里的设置会导致 Flash 无声。如果发生了这种情况,请禁用 alsaequal 或编译32位版本的 alsaequal。}}
  
{{注意|如果你使用 x86_64 系统,而且正在使用32位 flash 插件,flash 中的声音不会工作。你或者禁用 alsaequal 或者为32位编译alsaequal。}}
+
安装后,把下列内容添加到 ALSA 配置文件({{ic|~/.asoundrc}} {{ic|/etc/asound.conf}}):
 
+
After installing the package, insert the following into your ALSA configuration file ({{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}):
+
  
 
  ctl.equal {
 
  ctl.equal {
Line 244: Line 242:
 
   type equal;
 
   type equal;
 
   # Modify the line below if you do not
 
   # Modify the line below if you do not
  # want to use sound card 0.
 
 
   #slave.pcm "plughw:0,0";
 
   #slave.pcm "plughw:0,0";
 
   #by default we want to play from more sources at time:
 
   #by default we want to play from more sources at time:
Line 250: Line 247:
 
  }
 
  }
 
  #pcm.equal {
 
  #pcm.equal {
   # Or if you want the equalizer to be your
+
   # If you do not want the equalizer to be your
 
   # default soundcard comment the following
 
   # default soundcard comment the following
   # line and uncomment the above line.
+
   # line and uncomment the above line. (You can
 +
  # choose it as the output device by addressing
 +
  # it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
 
  pcm.!default {
 
  pcm.!default {
 
   type plug;
 
   type plug;
Line 258: Line 257:
 
  }
 
  }
 
   
 
   
Then Reload your alsa settings (as root).
+
设置好后,切换均衡器:
# systemctl restart alsa
+
not sure if this is really needed - more important is to shut down all applications using ALSA...
+
 
+
And you are ready to change your equalizer using command
+
 
  $ alsamixer -D equal
 
  $ alsamixer -D equal
  
Note that configuration file is different for each user (until not specified else) it is saved in '''$HOME/.alsaequal.bin'''.
+
需要注意,每个用户的 alsaequal 配置文件都是独立的,位于 {{ic|~/.alsaequal.bin}}。因此,如果想在 [[mpd]] 之类的以独立用户身份运行的程序中使用 AlsaEqual,就得像下面这样:
so if you want to use AlsaEqual with [[mpd]] or another software running under different user, you can configure it using
+
 
  # su mpd -c 'alsamixer -D equal'
 
  # su mpd -c 'alsamixer -D equal'
or eg. you can make symlink to your '''.alsaequal.bin''' in his home...
+
或者,在其他用户的主目录下创建符号链接,指向你的 {{ic|.alsaequal.bin}}……
 +
 
 +
=====管理 AlsaEqual 配置=====
 +
从 [http://xyne.archlinux.ca/repos/ Xyne 的软件仓库] 或 [https://aur.archlinux.org/packages.php?ID=62420 AUR] 安装 [http://xyne.archlinux.ca/projects/alsaequal-mgr/ alsaequal-mgr]。
 +
 
 +
同上,配置均衡器:
 +
$alsamixer -D equal
 +
 
 +
如果对效果感到满意,将其命名(如“foo”)并保存该配置:
 +
$alsaequal-mgr save foo
 +
 
 +
重新加载“foo”中的配置:
 +
$alsaequal-mgr load foo
 +
 
 +
这样,就可以为游戏、电影、不同音乐流派、网络电话等等创建不同的均衡器配置,以便随时切换。
 +
 
 +
参见[http://xyne.archlinux.ca/projects/alsaequal-mgr/ 项目主页]和程序的帮助信息,了解更多设置。
  
 
====使用 mbeq====
 
====使用 mbeq====
{{Note | This method requires the use of a ladspa plugin which might use quite a bit of CPU when sound plays. In addition, this was made with stereophonic sound (e.g. headphones) in mind.}}
+
{{注意|该软件用到了一个 ladspa 插件,可能导致播放音频时 CPU 占用率偏高。In addition, this was made with stereophonic sound (e.g. headphones) in mind.}}
 +
 
 +
安装 {{Pkg|alsa-plugins}}、{{Pkg|ladspa}} 和 {{Pkg|swh-plugins}} 软件包。
  
* You will need, in addition to the aforementioned userspace utilities, alsa-plugins.
+
* {{ic|~/.asoundrc}} {{ic|/etc/asound.conf}} 中添加如下内容:
# pacman -S alsa-plugins
+
* Get the ladspa and swh-plugins packages too if you do not already have them.
+
# pacman -S ladspa swh-plugins
+
* If you have not already created either an {{ic|~/.asoundrc}} or a {{ic|/etc/asound.conf}} file, then create either one
+
$ vim ~/.asoundrc
+
* Insert the following into your ALSA configuration file ({{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}):
+
  
 
{{hc|/etc/asound.conf|2=<nowiki>pcm.eq {
 
{{hc|/etc/asound.conf|2=<nowiki>pcm.eq {
Line 311: Line 317:
  
 
  # Redirect the default device to go via the EQ - you may want to do
 
  # Redirect the default device to go via the EQ - you may want to do
  # this last, once you're sure everything is working.  Otherwise all
+
  # this last, once you are sure everything is working.  Otherwise all
 
  # your audio programs will break/crash if something has gone wrong.
 
  # your audio programs will break/crash if something has gone wrong.
  
Line 327: Line 333:
 
</nowiki>}}
 
</nowiki>}}
  
*Reload your alsa settings (as root).
+
* 完成。若有问题,欢迎前往论坛咨询。
# systemctl restart alsa
+
 
+
*You should be good to go (if not, ask in the forum).
+
  
 
==高质量重采样==
 
==高质量重采样==
 +
启用软件混音时,ALSA 会强制把所有音频重采样到相同的频率(如果系统支持,默认是 48000)。dmix 的重采样算法很糟糕,会导致显著的质量损失。
  
When software mixing is enabled, ALSA is forced to resample everything to the same frequency (48000 by default when supported). dmix uses a poor resampling algorithm which produces noticeable sound quality loss.
+
安装 {{pkg|alsa-plugins}} 和 {{pkg|libsamplerate}}。
  
Install alsa-plugins and libsamplerate:
+
将默认的采样率转换器更改为 libsamplerate:
{{bc|# pacman -S alsa-plugins libsamplerate}}
+
 
+
Change the default rate converter to libsamplerate:
+
  
 
{{hc|/etc/asound.conf|defaults.pcm.rate_converter "samplerate_best"}}
 
{{hc|/etc/asound.conf|defaults.pcm.rate_converter "samplerate_best"}}
  
or
+
或:
  
 
{{hc|~/.asoundrc|defaults.pcm.rate_converter "samplerate_best"}}
 
{{hc|~/.asoundrc|defaults.pcm.rate_converter "samplerate_best"}}
  
'''samplerate_best''' offers the best sound quality, but you need a decent CPU to be able to use it as it requires a lot of CPU cycles for real-time resampling. There are other algorithms available ('''samplerate''', etc.) but they may not provide much of an improvement over the default resampler.
+
'''samplerate_best''' 输出的声音质量最佳,但需要耗费大量CPU资源进行实时重采样。还有其他的算法可供选择(如 '''samplerate''' 等),但比起默认的算法,这些算法的改进并不明显。
  
{{Warning|On some systems, enabling samplerate_best may cause an issue where you get no sound from flashplayer.}}
+
{{警告|某些系统中,启用 samplerate_best 可能导致 Flash 播放器无声音。}}
  
 
==Upmixing/Downmixing==
 
==Upmixing/Downmixing==
 
===Upmixing===
 
===Upmixing===
In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. Thus, install alsa-plugins:
+
In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. Thus, install {{Pkg|alsa-plugins}}.
{{bc|# pacman -S alsa-plugins}}
+
  
Then add the following to your alsa configuration file of choice (either /etc/asound.conf or ~/.asoundrc):
+
Then add the following to your ALSA configuration file of choice (either {{ic|/etc/asound.conf}} or {{ic|~/.asoundrc}}):
 
  pcm.upmix71 {
 
  pcm.upmix71 {
 
     type upmix
 
     type upmix
Line 370: Line 370:
 
  pcm.!default "plug:upmix71"
 
  pcm.!default "plug:upmix71"
  
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.
+
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.  
 +
If this is not working, you have to setup your own dmixer for the upmixing PCM like this:
 +
pcm.dmix6 {
 +
    type asym
 +
    playback.pcm {
 +
        type dmix
 +
        ipc_key 567829
 +
        slave {
 +
            pcm "hw:0,0"
 +
            channels 6
 +
        }
 +
    }
 +
}
  
If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a [[#High quality resampling|high quality resampler]].
+
and use "dmix6" instead of "surround71".
 +
If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a [[#高质量重采样|high quality resampler]].
  
 
===Downmixing===
 
===Downmixing===
Line 387: Line 400:
 
     slave.pcm "default"
 
     slave.pcm "default"
 
  }
 
  }
 
 
  
 
==混音==
 
==混音==
===Software mixing (dmix)===
+
===软件混音(dmix)===
  
{{注意|对于 ALSA 1.0.9rc2 和更高版本,你不需要设置 dmix。Dmix 对于不支持硬件混音的声卡会自动启用。}}
+
{{注意|ALSA 1.0.9rc2 及以上版本中,如果声卡不支持硬件混音,模拟输出将默认使用 dmix 混音,无需额外设置。}}
  
If that does not work however it is a matter of simply creating a .asoundrc file in your home folder with the following contents.
+
如果软件混音未正常启用,那么可以手动创建 {{ic|~/.asoundrc}},加入以下内容:
  
 
  pcm.dsp {
 
  pcm.dsp {
Line 402: Line 413:
 
  }
 
  }
  
This should enable software mixing and allows more than one application to make use of the soundcard.
+
这样就启用了软件混音,多个程序能够同时使用声卡。
  
See [[#Troubleshooting]] for common problems and solutions.
+
至于 S/PDIF 之类的数字音频输出,目前的 ALSA 还不会默认启用 dmix。因此,必须像上面这样手动启用。
  
===Hardware mixing===
+
常见问题的解答,参见[[#疑难解答]]部分。
{{poor writing}}
+
Use soundcard that supports hardware mixing: old SoundBlaster Live! series (emu10k1 chip) and new Audigy series (emu10k2 chip) cards are known to work.
+
  
The SoundBlaster Live! 5.1 is fairly easy to find and is cheap to buy.
+
===硬件混音===
 +
====支持====
 +
如果声卡支持,一般无需任何配置即可启用硬件混音。绝大多数板载声卡都不支持硬件混音,必须得使用软件混音(见上文)。很多独立声卡都支持硬件混音,Linux 下支持较好的有:
  
'''Note:''' new cheap Audigy SE, Audigy 2 NX, SoundBlaster Live! 24bit and SoundBlaster Live! 7.1 '''do not''' support hardware mixing (they use other chips).
+
* Creative SoundBlaster Live! (5.1 型号)
 +
* Creative SoundBlaster Audigy (部分型号)
 +
* Creative SoundBlaster Audidy 2 (ZS 系列型号)
 +
* Creative SoundBlaster Audigy 4 (Pro 系列型号)
  
99% of motherboards with integrated sound '''do not''' support hardware mixing.
+
{{注意|上述声卡的低端版本(Audigy SE、Audigy 2 NX、SoundBlaster Live! 24bit 以及 SoundBlaster Live! 7.1)使用了不同的芯片,'''不支持'''硬件混音。}}
  
An exception is the onboard VIA8237 chip which supports 4-stream hardware mixing. However it does only 3 for some motherboards (the 4th makes no sound), or is just broken. Even if it works, the quality is not good compared to other solutions.
+
{{注意|板载 VIA8237 芯片支持4路硬件混音,但在某些主板上只能使用3路(第4路无声),甚至根本无法使用。即使能正常工作,质量也比不上其他混音方法。}}
  
For Arch64 and the 00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 02), and to get sound from Enemy Territory, it works this by setting these:
+
====问题修复====
 +
如果你的声卡是 Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 02),且使用了64位系统,需要执行以下命令才能在 Enemy Territory 中听到声音:
 
  echo "et.x86 0 0 direct" > /proc/asound/card0/pcm0p/oss
 
  echo "et.x86 0 0 direct" > /proc/asound/card0/pcm0p/oss
 
  echo "et.x86 0 0 disable" > /proc/asound/card0/pcm0c/oss
 
  echo "et.x86 0 0 disable" > /proc/asound/card0/pcm0c/oss
  
 
==疑难解答==
 
==疑难解答==
===仍然没有声音?===
+
===使用CPU频率动态调整时,音频发生跳跃===
 +
使用 {{ic|ondemand}} 或 {{ic|conservative}} 频率策略、启用CPU频率动态调整时,某些声卡和某些 ALSA 驱动会出现声音跳跃的情况。目前,唯一的解决方案是使用固定的频率,如 {{ic|performance}} 性能策略。
  
记住,ALSA安装后所有通道'''缺省是静音'''(看前面的章节)。不过,如果你确定没有静音,驱动安装正确,音量没问题,但还是听不到声音,试一下把下面内容加入到<code>/etc/modprobe.d/modprobe.conf</code>,应该可以解决问题(至少<code>via82xx</code>驱动是)。
+
详情参见 [[CPU Frequency Scaling (简体中文)]]。
 +
 
 +
===Problems with Availability to Only One User at a Time===
 +
You might find that only one user can use the dmixer at a time.  This is probably ok for most, but for those who run [[mpd]] as a separate user this poses a problem.  When mpd is playing a normal user cannot play sounds though the dmixer.  While it's quite possible to just run mpd under a user's login account, another solution has been found.  Adding the line {{ic|ipc_key_add_uid 0}} to the {{ic|pcm.dmixer}} block disables this locking.  The following is a snippet of the {{ic|asound.conf}}, the rest is the same as above.
 +
...
 +
pcm.dmixer {
 +
  type dmix
 +
  ipc_key 1024
 +
  ipc_key_add_uid 0
 +
  ipc_perm 0660
 +
slave {
 +
...
 +
 
 +
===Simultaneous Playback Issues===
 +
 
 +
If you are having simultaneous playback issues, and if [[PulseAudio]] is installed (i.e. by [[GNOME]]), its default configuration is set to "hijack" the soundcard. Some users of ALSA may not want to use [[PulseAudio]] and are quite content with their current ALSA settings. One fix is to edit {{ic|/etc/asound.conf}} and comment out the following lines:
 +
# Use PulseAudio by default
 +
#pcm.!default {
 +
#  type pulse
 +
#  fallback "sysdefault"
 +
#  hint {
 +
#    show on
 +
#    description "Default ALSA Output (currently PulseAudio Sound Server)"
 +
#  }
 +
#}
 +
 
 +
Commenting the following out also may help:
 +
#ctl.!default {
 +
#  type pulse
 +
#  fallback "sysdefault"
 +
#}
 +
 
 +
This may be a much simpler solution than completely uninstalling [[PulseAudio]].
 +
 
 +
Effectively, here is an example of a working {{ic|/etc/asound.conf}}:
 +
{{bc|<nowiki>pcm.dmixer {
 +
        type dmix
 +
        ipc_key 1024
 +
        ipc_key_add_uid 0
 +
        ipc_perm 0660
 +
}
 +
pcm.dsp {
 +
        type plug
 +
        slave.pcm "dmix"
 +
}</nowiki>
 +
}}
 +
 
 +
{{note|This {{ic|/etc/asound.conf}} file was intended for and used successfully with a global [[MPD]] configuration. See [[Alsa#Problems_with_Availability_to_Only_One_User_at_a_Time|this section]] on multiple users}}
 +
 
 +
===Random Lack of Sound on Startup===
 +
If you randomly have no sound on startup, it may be because your system has multiple sound cards, and their order may sometimes change on startup.  If this is the case, try [[#Set the default sound card|setting the default sound card]].
 +
 
 +
If you use mpd and the configuration tips above do not work for you, try [http://mpd.wikia.com/wiki/Configuration#ALSA_MPD_software_volume_control reading this] instead.
 +
 
 +
===Specific Program Problems===
 +
For other programs who insist on their own audio setup, eg, XMMS or Mplayer, you would need to set their specific options.
 +
 
 +
For mplayer, open up {{ic|~/.mplayer/config}} (or {{ic|/etc/mplayer/mplayer.conf}} for global setting) and add the following line:
 +
ao=alsa
 +
 
 +
For XMMS/Beep Media Player, go into their options and make sure the sound driver is set to Alsa, not oss.
 +
 
 +
To do this in XMMS:
 +
* Open XMMS
 +
** Options -> preferences.
 +
** Choose the Alsa output plugin.
 +
 
 +
For applications which do not provide a ALSA output, you can use aoss from the alsa-oss package. To use aoss, when you run the program, prefix it with {{ic|aoss}}, eg:
 +
aoss realplay
 +
 
 +
pcm.!default{ ... }  doesnt work for me anymore. but this does:
 +
  pcm.default pcm.dmixer
 +
 
 +
===Model Settings===
 +
Although Alsa detects your soundcard through the BIOS at times Alsa may not be able to recognize your [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt model type].  The soundcard chip can be found in {{ic|alsamixer}} (e.g. ALC662) and the model can be set in {{ic|/etc/modprobe.d/modprobe.conf}} or {{ic|/etc/modprobe.d/sound.conf}}.  For example:
 +
 
 +
options snd-hda-intel model=MODEL
 +
 
 +
There are other model settings too.  For most cases Alsa defaults will do.  If you want to look at more specific settings for your soundcard take a look at the [http://bugtrack.alsa-project.org/main/index.php/Matrix:Main Alsa Soundcard List] find your model, then Details, then look at the "Setting up modprobe..." section.  Enter these values in {{ic|/etc/modprobe.d/modprobe.conf}}.  For example, for an Intel AC97 audio:
 +
 
 +
{{bc|# ALSA portion
 +
alias char-major-116 snd
 +
alias snd-card-0 snd-intel8x0
 +
# module options should go here
 +
 
 +
# OSS/Free portion
 +
alias char-major-14 soundcore
 +
alias sound-slot-0 snd-card-0
 +
 
 +
# card #1
 +
alias sound-service-0-0 snd-mixer-oss
 +
alias sound-service-0-1 snd-seq-oss
 +
alias sound-service-0-3 snd-pcm-oss
 +
alias sound-service-0-8 snd-seq-oss
 +
alias sound-service-0-12 snd-pcm-oss}}
 +
 
 +
===Conflicting PC Speaker===
 +
If you are sure nothing is muted, that your drivers are installed correctly, and that your volume is right, but you still do not hear anything, then try adding the following line to {{ic|/etc/modprobe.d/modprobe.conf}}:
  
 
  options snd-NAME-OF-MODULE ac97_quirk=0
 
  options snd-NAME-OF-MODULE ac97_quirk=0
  
也有可能是Udev在检测时,将主板喇叭配置成了主声音设备.这时可以试着删掉/etc/rc.conf中MODULES行中的snd-pcsp 。
+
The above fix has been observed to work with {{ic|via82xx}}
 +
options snd-NAME-OF-MODULE ac97_quirk=1
 +
The above fix has been reported to work with {{ic|snd_intel8x0}}
  
===板载Intel声卡无声===
+
===No Microphone Input===
 +
In alsamixer, make sure that all the volume levels are up under recording, and that CAPTURE is toggled active on the microphone (e.g. Mic, Internal Mic) and/or on Capture (in alsamixer, select these items and press space). Try making positive Mic Boost and raising Capture and Digital levels higher; this make make static or distortion, but then you can adjust them back down once you are hearing ''something'' when you record
  
这也许是因为同时加载两个冲突的模块<code>snd_intel8x0</code>和<code>snd_intel8x0m</code>导致。这种情况的话,编辑<code>rc.conf</code>,在MODULES数组黑名单里加入后者<code>!snd_intel8x0m</code>。
+
As the pulseaudio wrapper is shown as "default" in alsamixer, you may have to press F6 to select your actual soundcard first. You may also need to enable and increase the volume of Line-in in the Playback section.
  
===糟糕的音质?===
+
To test the microphone, run these commands (see arecord's man page for further information):
 +
  arecord -d 5 test-mic.wav
 +
  aplay test-mic.wav
  
如果你觉得音质很差,请尝试设置PCM的音量(通过alsamixer)使得增益(gain)为0。
+
If all fails, you may want to eliminate hardware failure by testing the microphone with a different device.
  
===启动和停止回放时有暴音===
+
For at least some computers, muting a microphone (MM) simply means its input does not go immediately to the speakers. It still receives input.
  
某些模块会在你的声卡不使用的时候将它断电。断电过程会使你的声卡发出些噪音。如果你对此感到厌烦可以试一下"modinfo snd-MY-MODULE",然后找这个模块的有关选项调整或者关闭这个特性。
+
Many Dell laptops need "-dmic" to be appended to the model name in {{ic|/etc/modprobe.d/modprobe.conf}}:
 +
  options snd-hda-intel model=dell-m6-dmic
  
例如:要禁止snd-hda-intel的能源保护模式,将 "options snd-hda-intel power_save=0"加入到/etc/modprobe.d/modprobe.conf,或者试试"modprobe snd-hda-intel power_save=0"。
+
Some programs use try to use OSS as the main input software. Add the following lines to {{ic|/etc/modprobe.d/modprobe.conf}} to prevent OSS modules from being loaded:
  
===Alsamixer无法运行===
+
{{Note|The OSS modules are no longer autoloaded anyway.}}
如果运行alsamixer出错并且获得这样的错误信息
+
alsamixer: function snd_ctl_open failed for default: No such device
+
  
请确保你是audio组的用户,如果没有请加入 audio 组并重新登录。你可能需要重新安装你的内核。执行{{ic|pacman -S linux}} 或者添加其它需要的 patchset。
+
blacklist snd_pcm_oss
 +
blacklist snd_mixer_oss
 +
blacklist snd_seq_oss
  
===SigmaTel STAC9205的耳机无声===
+
See also:
使用内置的扬声器能够播放声音,可是插入耳机后,耳机内却没有任何声音。这个问题出现在DELL的部分机型和Gateway的T系列的机型上。
+
* http://www.alsa-project.org/main/index.php/SoundcardTesting
 +
* http://alsa.opensrc.org/Record_from_mic
 +
 
 +
===Setting the default Microphone/Capture Device===
 +
Some applications (Pidgin, Adobe Flash) do not provide an option to change the capture device. It becomes an issue if your microphone is on a separate device (e.g. USB webcam or microphone) than your internal sound card. To change only the default capture device, leaving the default playback device as is, you can modify your {{ic|~/.asoundrc}} file to include the following:
 +
 
 +
pcm.usb
 +
{
 +
    type hw
 +
    card U0x46d0x81d
 +
}
 +
 +
pcm.!default
 +
{
 +
    type asym
 +
    playback.pcm
 +
    {
 +
        type plug
 +
        slave.pcm "dmix"
 +
    }
 +
    capture.pcm
 +
    {
 +
        type plug
 +
        slave.pcm "usb"
 +
    }
 +
}
 +
 
 +
Replace "U0x46d0x81d" with your capture device's card name in ALSA. You can use {{ic|arecord -L}} to list all the capture devices detected by ALSA.
 +
 
 +
===Internal Microphone not working===
 +
First make sure all the volume levels are up under recording in alsamixer. In my case adding the following option to /etc/sound.conf and reloading the snd-* module produced a new volume setting called Capture which was capturing for the internal mic. For eg, for snd-hda-intel add
 +
 
 +
  options snd-hda-intel enable_msi=1
 +
 
 +
Then reload the module (as below), up the recording volume of Capture and then test.
 +
 
 +
{{bc|# rmmod snd-hda-intel && modprobe snd-hda-intel}}
 +
 
 +
===No Sound with Onboard Intel Sound Card===
 +
There may be an issue with two conflicting modules loaded, namely {{ic|snd_intel8x0}} and {{ic|snd_intel8x0m}}. In this case, blacklist snd_intel8x0m:
 +
 
 +
{{hc|/etc/modprobe.d/modprobe.conf|blacklist snd_intel8x0m}}
 +
 
 +
''Muting'' the "External Amplifier" in {{ic|alsamixer}} or {{ic|amixer}} may also help. See [http://alsa.opensrc.org/Intel8x0#Dell_Inspiron_8600_.28and_probably_others.29 the ALSA wiki].
 +
 
 +
Unmuting the "Mix" setting in the mixer might help, also.
 +
 
 +
===No Headphone Sound with Onboard Intel Sound Card===
 +
With '''Intel Corporation 82801 I (ICH9 Family) HD Audio Controller''' on laptop, you may need to add this line to modprobe or sound.conf:
 +
 
 +
options snd-hda-intel model=$model
 +
 
 +
Where $model is any one of the following (in order of possibility to work, but not merit):
 +
 
 +
* dell-vostro
 +
* olpc-xo-1_5
 +
* laptop
 +
* dell-m6
 +
* laptop-hpsense
 +
 
 +
Note: It may be necessary to put this "options" line below (after) any "alias" lines about your card.
 +
 
 +
You can see all the available models in the kernel documentation. For example [http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.35.y.git;a=blob;f=Documentation/sound/alsa/HD-Audio-Models.txt;h=dc25bb84b83b49665a7ed850e7bf5423d50cd3ba;hb=HEAD here], but check that it is the correct version of that document for your kernel version.
 +
 
 +
A list of available models is also available [http://www.mjmwired.net/kernel/Documentation/sound/alsa/HD-Audio-Models.txt here]. To know your chip name type the following command (with * being corrected to match your files). Note that some chips could have been renamed and do not directly match the available ones in the file.
 +
 
 +
cat /proc/asound/card*/codec* | grep Codec
 +
 
 +
Note that there is a high chance none of the input devices (all internal and external mics) will work if you choose to do this, so it is either your headphones or your mic. Please report to ALSA if you are affected by this bug.
 +
 
 +
And also, if you have problems getting beeps to work (pcspkr):
 +
 
 +
options snd-hda-intel model=$model enable=1 index=0
 +
 
 +
===No sound when S/PDIF video card is installed===
 +
Discover available modules and their order:
 +
$ cat /proc/asound/modules
 +
0 snd_hda_intel
 +
1 snd_ca0106
 +
 
 +
Disable the undesired video card audio codec in {{ic|/etc/modprobe.d/modprobe.conf}}:
 +
# /etc/modprobe.d/modprobe.conf
 +
#
 +
install snd_hda_intel /bin/false
 +
 
 +
If both devices use the same module, it might be possible to disable one of them in the BIOS.
 +
 
 +
===Poor sound quality or clipping===
 +
If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.
 +
 
 +
If snd-usb-audio driver has been loaded, you could try to enable {{ic|softvol}} in '''/etc/asound.conf''' file. Example configuration for the first audio device:
 +
  pcm.!default {
 +
    type plug
 +
    slave.pcm "softvol"
 +
  }
 +
  pcm.dmixer {
 +
      type dmix
 +
      ipc_key 1024
 +
      slave {
 +
          pcm "hw:0"
 +
          period_time 0
 +
          period_size 4096
 +
          buffer_size 131072
 +
          rate 50000
 +
      }
 +
      bindings {
 +
          0 0
 +
          1 1
 +
      }
 +
  }
 +
  pcm.dsnooper {
 +
      type dsnoop
 +
      ipc_key 1024
 +
      slave {
 +
          pcm "hw:0"
 +
          channels 2
 +
          period_time 0
 +
          period_size 4096
 +
          buffer_size 131072
 +
          rate 50000
 +
      }
 +
      bindings {
 +
          0 0
 +
          1 1
 +
      }
 +
  }
 +
  pcm.softvol {
 +
      type softvol
 +
      slave { pcm "dmixer" }
 +
      control {
 +
          name "Master"
 +
          card 0
 +
      }
 +
  }
 +
  ctl.!default {
 +
    type hw
 +
    card 0
 +
  }
 +
  ctl.softvol {
 +
    type hw
 +
    card 0
 +
  }
 +
  ctl.dmixer {
 +
    type hw
 +
    card 0
 +
  }
 +
 
 +
===Pops When Starting and Stopping Playback===
 +
Some modules (e.g. snd_ac97_codec and snd_hda_intel) can power off your sound card when not in use. This can make an audible noise (like a crack/pop/scratch) when turning on/off your sound card. Sometimes even when move the slider volume, or open and close windows (KDE4). If you find this annoying try {{ic|modinfo snd_MY_MODULE}}, and look for a module option that adjusts or disables this feature.
 +
 
 +
Example: to disable the power saving mode and solve cracking sound trough speakers issue, using snd_hda_intel add in {{ic|/etc/modprobe.d/modprobe.conf}}
 +
options snd_hda_intel power_save=0
 +
or
 +
options snd_hda_intel power_save=0 power_save_controller=N
 +
 
 +
You can also try it with {{ic|1=modprobe snd_hda_intel power_save=0}} before.
 +
 
 +
You may also have to unmute the 'Line' ALSA channel for this to work. Any value will do (other than '0' or something too high).
 +
 
 +
''Example:'' on an onboard VIA VT1708S (using the snd_hda_intel module) these cracks occured even though 'power_save' was set to 0. Unmuting the 'Line' channel and setting a value of '1' solved the issue.
 +
 
 +
Source: https://www.kernel.org/doc/Documentation/sound/alsa/powersave.txt
 +
 
 +
If you use a laptop, pm-utils will change {{ic|power_save}} back to 1 when you go onto battery power even if you disable power saving in {{ic|/etc/modprobe.d}}. Disable this for pm-utils by disabling the script that makes the change (see [https://wiki.archlinux.org/index.php/Pm-utils#Disabling_a_hook Disabling a hook] for more information):
 +
# touch /etc/pm/power.d/intel-audio-powersave
 +
 
 +
===S/PDIF Output Does Not Work===
 +
 
 +
If the optical/coaxial digital output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try running
 +
# iecset audio on
 +
 
 +
as root.
 +
 
 +
You can also put this command in {{Ic|rc.local}} as it sometimes it may stop working after a reboot.
 +
 
 +
===HDMI Output Does Not Work===
 +
If the HDMI output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try the following.
 +
 
 +
Query for Playback Devices:
 +
 
 +
  $ aplay -l
 +
  **** List of PLAYBACK Hardware Devices ****
 +
  card 0: NVidia [HDA NVidia], device 0: ALC1200 Analog [ALC1200 Analog]
 +
    Subdevices: 1/1
 +
    Subdevice #0: subdevice #0
 +
  card 0: NVidia [HDA NVidia], device 1: ALC1200 Digital [ALC1200 Digital]
 +
    Subdevices: 1/1
 +
    Subdevice #0: subdevice #0
 +
  card 0: NVidia [HDA NVidia], device 3: NVIDIA HDMI [NVIDIA HDMI]
 +
    Subdevices: 0/1
 +
    Subdevice #0: subdevice #0
 +
 
 +
Now that we have the info for the HDMI device, try a test,  In the example below, 0 is the card number and 3 is the device number.
 +
 
 +
  $ aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav
 +
 
 +
If aplay does not output any errors, but still no sound is heared, "reboot" the receiver, monitor or tv set. Since the HDMI interface executes a handshake on connection, it might have noticed before that there was no audio stream embedded, and disabled audio decoding. In particular, if you are using a standalone window manager (don’t know about Gnome or KDE), you may need to have some sound playing ''while'' plugging in the HDMI cable.
 +
 
 +
{{Note|If you are using an ATI card and linux 3.0, check your kernel/grub settings, you most likely need to use the ''''radeon.audio'''<nowiki>=</nowiki>'''1'''' boot parameter, or alternatively set up the option in your modprobe configuration files.}}
 +
 
 +
If the test is successful, create or edit your ~/.asoundrc file to set HDMI as the default audio device.
 +
 
 +
{{hc|~/.asoundrc|
 +
pcm.!default {
 +
  type hw
 +
  card 0
 +
  device 3
 +
}
 +
}}
 +
 
 +
Or you above config does not work try:
 +
{{hc|~/.asoundrc|
 +
defaults.pcm.card 0
 +
defaults.pcm.device 3
 +
defaults.ctl.card 0
 +
}}
 +
 
 +
===HDMI Multi-channel PCM output does not work (Intel) ===
 +
As of Linux 3.1 multi-channel PCM output through HDMI with a Intel card (Intel Eaglelake, IbexPeak/Ironlake,SandyBridge/CougarPoint and IvyBridge/PantherPoint) is not yet supported. Support for it has been recently added and expected to be available in Linux 3.2. To make it work in Linux 3.1 you need to apply the following patches:
 +
 
 +
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=76adaa34db407f174dd06370cb60f6029c33b465 drm: support routines for HDMI/DP ELD]
 +
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=e0dac65ed45e72fe34cc7ccc76de0ba220bd38bb drm/i915: pass ELD to HDMI/DP audio driver]
 +
 
 +
===HP TX2500===
 +
Add these 2 lines into {{ic|/etc/modprobe.d/modprobe.conf}}:
 +
options snd-cmipci mpu_port=0x330 fm_port=0x388
 +
options snd-hda-intel index=0 model=toshiba position_fix=1
 +
 
 +
options snd-hda-intel model=hp (works for tx2000cto)
 +
 
 +
===Skipping Sound When Playing MP3===
 +
If you have sound skipping when playing MP3 files and you have more then 2 speakers attached to your computer (i.e. > 2 speaker system), run alsamixer and disable the channels for the speakers that you '''DO NOT''' have (i.e. do not enable the sound for the center speaker if you do not have a center speaker.
 +
 
 +
===Using a USB Headset and External USB Sound Cards===
 +
If you are using a USB headset with ALSA you can try using {{AUR|asoundconf}} (currently only available from the [[AUR]]) to set the headset as the primary sound output. Before running make sure you have usb audio module enabled ({{ic|modprobe snd-usb-audio}}).
 +
 
 +
# asoundconf is-active
 +
# asoundconf list
 +
# asoundconf set-default-card <chosen soundcard>
 +
 
 +
==== Crackling sound with USB devices ====
 +
If you experience crackling sound on USB devices, you can try tuning the snd-usb-audio for minimal latency.
 +
 
 +
Add this to your {{ic|/etc/modprobe.d/modprobe.conf}}:
 +
 
 +
options snd-usb-audio nrpacks=1
 +
 
 +
source: http://alsa.opensrc.org/Usb-audio#Tuning_USB_devices_for_minimal_latencies
 +
 
 +
==== Hot-plugging a USB Sound Card ====
 +
In order to automatically make a USB Sound Card the primary output device, when the card is plugged in, you can use the following udev rules (e.g. add the following two lines to {{ic|/etc/udev/rules.d/00-local.rules}} and reboot).
 +
 
 +
{{bc|1=KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
 +
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"}}
 +
 
 +
===Error 'Unknown hardware' Appears After a Kernel Update===
 +
The following messages may be displayed during the start-up ALSA after the kernel update:
 +
Unknown hardware "foo" "bar" ...
 +
Hardware is initialized using a guess method
 +
/usr/sbin/alsactl: set_control:nnnn:failed to obtain info for control #mm (No such file or directory)
 +
 
 +
or
 +
Found hardware: "HDA-Intel" "VIA VT1705" "HDA:11064397,18490397,00100000" "0x1849" "0x0397"
 +
Hardware is initialized using a generic method
 +
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #1 (No such file or directory)
 +
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #2 (No such file or directory)
 +
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #25 (No such file or directory)
 +
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #26 (No such file or directory)
 +
 
 +
Simply store ALSA mixer settings again (as root):
 +
# alsactl -f /var/lib/alsa/asound.state store
 +
 
 +
It may be necessary configure ALSA again with alsamixer
 +
 
 +
===HDA Analyzer===
 +
If the mappings to your audio pins(plugs) do not correspond but ALSA works fine, you could try HDA Analyzer -- a pyGTK2 GUI for HD-audio control can be found [http://www.alsa-project.org/main/index.php/HDA_Analyzer at the ALSA wiki].
 +
Try tweaking the Widget Control section of the PIN nodes, to make microphones IN and headphone jacks OUT. Referring to the Config Defaults heading is a good idea.
 +
 
 +
NOTE: the script is done by such way that it is incompatible with python3 (which is now shipped with ArchLinux) but tries to use it.
 +
The workaround is: open "run.py", find all occurences of "python" (2 occurences - one on the first line, and the second on the last line) and replace them all by "python2".
 +
 
 +
NOTE2: the script requires root acces, but running it via su/sudo is bogus. Run it via {{ic|kdesu}} or {{ic|gksu}}.
 +
 
 +
===ALSA with SDL===
 +
If you get no sound via SDL and ALSA cannot be chosen from the application. Try setting the environmental variable SDL_AUDIODRIVER to alsa.
 +
# export SDL_AUDIODRIVER=alsa
 +
 
 +
===Low Sound Workaround===
 +
 
 +
If you are facing low sound even after maxing out your speakers/headphones, you can give the softvol plugin a try. Add the following to {{ic|/etc/asound.conf}}.
 +
{{bc|<nowiki>
 +
pcm.!default {
 +
      type plug
 +
      slave.pcm "softvol"
 +
  }
 +
 
 +
pcm.softvol {
 +
    type softvol
 +
    slave {
 +
        pcm "dmix"
 +
    }
 +
    control {
 +
        name "Pre-Amp"
 +
        card 0
 +
    }
 +
    min_dB -5.0
 +
    max_dB 20.0
 +
    resolution 6
 +
}
 +
</nowiki>}}
 +
{{note| You will probably have to restart the computer, as restarting the alsa daemon did not load the new configuration for me. Also, if the configuration does not work even after restarting, try changing {{ic|plug}} with {{ic|hw}} in the above configuration.}}
  
目前,alsa-lib = 1.0.20已经部分解决了这个问题。请确保你已经升级到了最新版本。
+
After the changes are loaded successfully, you will see a {{ic|Pre-Amp}} section in alsamixer. You can adjust the levels there.
pacman -S alsa-lib alsa-utils
+
{{note|Setting a high value for {{ic|Pre-Amp}} can cause sound distortion, so adjust it according to the level that suits you.}}
  
假如依然不能解决,请在 <code>/etc/modprobe.d/modprobe.conf</code> 中添加snd-hda-intel模块参数:
+
===Popping sound after resuming from suspension===
options snd-hda-intel enable_msi=0 model=eapd
+
You might hear a popping sound after resuming the computer from suspension. This can be fixed by editing {{ic|/etc/pm/sleep.d/90alsa}} and removing the line that says {{ic|aplay -d 1 /dev/zero}}
  
这个参数目前在我的 Gateway T-6834c + kernel 2.6.30 + x86_64上成功解决耳机无声问题。
+
==设置文件范例==
 +
参见:[[Advanced Linux Sound Architecture/Example Configurations]]。
  
= 其它资源 =
+
==相关阅读==
你可以在这里找到更多的信息
+
* [http://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt ALSA 模块高级配置]
* [http://alsa.opensrc.org/index.php/Main_Page Unofficial ALSA Wiki]
+
* [http://alsa.opensrc.org/Main_Page 非官方的 ALSA Wiki]
* [http://alsa.opensrc.org/index.php/Aadebug A simple shell script to aid ALSA audio debugging]
+
* [https://bbs.archlinux.org/viewtopic.php?id=36815 如何从 svn 获取驱动代码并编译]
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: Compile driver from svn]
+
* [http://gentoo-wiki.com/HOWTO_Set_up_a_system-wide_equaliser_with_ALSA_and_LADSPA HOWTO Set up a system-wide equaliser with ALSA and LADSPA]
+
* [https://bugs.launchpad.net/alsa-driver/+bug/306755]
+

Revision as of 07:45, 14 March 2013


Summary help replacing me
ALSA 的使用、配置及疑难解答。
相关页面
Sound (简体中文)
Disable PC Speaker Beep (简体中文)
翻译状态: 本文是英文页面 Systemd翻译,最后翻译时间:2013-03-14,点击这里可以查看翻译后英文页面的改动。

高级 Linux 声音体系(Advanced Linux Sound Architecture,ALSA)是Linux中提供声音设备驱动的内核组件,用来代替原来的开放声音系统(Open Sound System,OSSv3)。除了声音设备驱动,ALSA还包含一个用户空间的函数库,以方便开发者通过高级API使用驱动功能,而不必直接与内核驱动交互。

注意: 关于另一种声音体系,请阅读开放声音系统(OSS)的页面。

Contents

安装

Arch 默认的内核已经通过一套模块提供了 ALSA,不必特别安装。

udev会在系统启动时自动检测硬件,并加载相应的声音设备驱动模块。这时,你的声卡已经可以工作了,只是所有声道默认都被设置成静音了。

在本地登录(通过虚拟终端或登录管理器)的用户,都有权限播放音频并调整音量。要让远程登录的用户拥有这些权限,必须把用户加入 audio 用户组。该组的成员可以直接访问声音设备,会导致某些程序独占音频输出(破坏软件混音),还可能影响用户快速切换和拖机(multiseat)。因此,除非真的有某些特殊需求不建议把用户加入 audio 用户组。

用户空间工具

官方仓库

  • 安装 alsa-utils 软件包,其中的 alsamixer 工具允许用户在控制台或终端中配置声音设备。
  • 安装 alsa-oss 软件包,如果想让 OSS 应用程序与dmix(软件混音)协同工作。
注意: udev的171版本开始,默认情况下 OSS 仿真模块(snd_seq_osssnd_pcm_osssnd_mixer_oss)不再自动加载。

解除各声道的静音

目前版本的 ALSA 安装后,所有声道默认是静音的,必须手动解除。

使用 alsamixer 的 ncurses 界面,配置十分简单:

$ alsamixer

此外,还可以在命令行下使用 amixer

$ amixer sset Master unmute

下方标有 MM 的声道是静音的,而标有 00 的通道已经启用。

使用左右方向键,选中 MasterPCM 声道。按下 Template:Keypress 键解除静音。使用上方向键增加音量,直到增益值为0。该值显示在左上方 Item: 字段后。过高的增益值会导致声音失真。

要想得到完整的 5.1 或 7.1 环绕立体声,还得解除 Front、Surround、Center、LFE (subwoofer) 和 Side 这些声道的静音(上述名称是 Intel HD Audio 声卡使用的声道名,可能因设备不同而有所差异)。注意,仅有这些设置,系统不会自动将立体声源(多数音乐)提升(upmix)成环绕立体声。如果需要这些功能,请阅读#Upmixing/Downmixing

按下 Template:Keypress 键退出 alsamixer。

注意:
  • 有一些声卡,需要关闭数字输出或将其调成静音,才能输出模拟音频信号。对于 Soundblaster Audigy LS 声卡,需要把 IEC958 通道设成静音。
  • 有些机器(如 Thinkpad T61),有一个 Speaker 通道,必须按照上述方法打开调整。
  • 有些机器(如 Dell E6400),可能还需要把 FrontHeadphone 声道打开调整。

接下来,测试声卡是否工作:

$ speaker-test -c 2

根据扬声器的实际情况,调整 -c 后的数值。对于 7.1 声道,这个数字是 8:

$ speaker-test -c 8

如果没有正常工作,请继续阅读 #配置 以及 #疑难解答 部分。

alsa-utils 软件包提供了两个配置 alsa 的服务:alsa-restore.servicealsa-store.service。它们分别在开机和关机时自动运行。

配置

VirtualBox 虚拟机无声音

如果使用 VirtualBox 时碰上了麻烦,请尝试以下命令:

$ alsactl init

Found hardware: "ICH" "SigmaTel STAC9700,83,84" "AC97a:83847600" "0x8086" "0x0000"
Hardware is initialized using a generic method

如果还是不行,请检查所使用的音频软件是否激活了 ALSA 输出。

设置默认声卡

如果发现开机时声卡次序会发生变化,可以在通过 /etc/modprobe.d 中的 .conf 文件(比如 /etc/modprobe.d/alsa-base.conf)手动设置次序。 比如,要让 mia 声卡成为 #0、Intel HDA 声卡成为 #1:

/etc/modprobe.d/alsa-base.conf
options snd slots=snd_mia,snd_hda_intel
options snd_mia index=0
options snd_hda_intel index=1

snd_mia 和 snd_hda_intel 分别是两个声卡的内核驱动模块。该配置仅适用于同时装有 mia 声卡和使用 snd_hda_intel 驱动的声卡(通常是板载声卡)的情况。

如果使用 -2 的 index 值,ALSA 就不会将对应的设备作为主声卡使用。Linux Mint 和 Ubuntu 等发行版使用了以下配置,避免 USB 声卡和其他“非主流”设备变成 index 为 0 的主声卡:

/etc/modprobe.d/alsa-base.conf
options bt87x index=-2
options cx88_alsa index=-2
options saa7134-alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2
options snd-usb-audio index=-2
options snd-usb-caiaq index=-2
options snd-usb-ua101 index=-2
options snd-usb-us122l index=-2
options snd-usb-usx2y index=-2
# Keep snd-pcsp from being loaded as first soundcard
options snd-pcsp index=-2
# Keep snd-usb-audio from beeing loaded as first soundcard
options snd-usb-audio index=-2

以上配置会在系统重启后生效。

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: 据英文 Wiki 用户反应,/etc/asound.conf 这个配置文件默认是不存在的,下列操作可能有误。 (Discuss in Talk:Advanced Linux Sound Architecture (简体中文)#)

首先,运行 aplay -l,获取声卡的声卡ID和设备ID:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

拿输出中的最后一项来说,这个声卡的声卡ID为2,设备ID为0。若要把这块声卡作为默认声卡,可以把下列配置添加到系统级别的 /etc/asound.conf 或用户级别的 ~/.asoundrc 文件。如果文件不存在,可以手动创建。其中的各个ID,请根据实际情况调整:

~/.asoundrc
defaults.pcm.card 2
defaults.pcm.device 0
defaults.ctl.card 2

“pcm”选项决定用来播放音频的设备,而“ctl”选项决定那个声卡能够由控制工具(如 alsamixer)使用。

上述配置在重启音频程序(如 mplayer)后立即生效。

确认所有声音模块都已经加载

一般 udev 都会自动识别出声卡。使用以下命令确认:

$ lsmod | grep '^snd' | column -t
snd_hda_codec_hdmi     22378   4
snd_hda_codec_realtek  294191  1
snd_hda_intel          21738   1
snd_hda_codec          73739   3  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
snd_hwdep              6134    1  snd_hda_codec
snd_pcm                71032   3  snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
snd_timer              18992   1  snd_pcm
snd                    55132   9  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
snd_page_alloc         7017    2  snd_hda_intel,snd_pcm

如果你的输出和上面类似,那就说明声卡已经被正确识别。

注意: udev的171版本开始,默认情况下 OSS 仿真模块(snd_seq_osssnd_pcm_osssnd_mixer_oss)不再自动加载。如有需要,请手动加载

还可以检查一下 /dev/snd/ 目录,看看是否有这些设备文件:

$ ls -l /dev/snd
total 0
crw-rw----  1 root audio 116,  0 Apr  8 14:17 controlC0
crw-rw----  1 root audio 116, 32 Apr  8 14:17 controlC1
crw-rw----  1 root audio 116, 24 Apr  8 14:17 pcmC0D0c
crw-rw----  1 root audio 116, 16 Apr  8 14:17 pcmC0D0p
crw-rw----  1 root audio 116, 25 Apr  8 14:17 pcmC0D1c
crw-rw----  1 root audio 116, 56 Apr  8 14:17 pcmC1D0c
crw-rw----  1 root audio 116, 48 Apr  8 14:17 pcmC1D0p
crw-rw----  1 root audio 116,  1 Apr  8 14:17 seq
crw-rw----  1 root audio 116, 33 Apr  8 14:17 timer
注意: 在 IRC 或论坛寻求这方面帮助时,别忘了贴出上面几个命令的输出。

如果你的输出跟上面类似,或至少有 controlC0pcmC0D0p,那么声卡就已经正常加载了。

如果出现问题,声卡模块没有正确加载,那么请尝试手动加载模块:

  • 确定声卡对应的驱动模块:ALSA Soundcard Matrix。这些模块都会有一个”snd-“前缀(例如:snd-via82xx)。
  • 加载模块
  • 检查 /dev/snd 目录中的设备文件(参见上文);或者,检查 alsamixeramixer 的输出是否正确。
  • 修改配置,使 snd-<模块名>snd-pcm-oss 模块开机自动加载

启用 SPDIF 输出

(由 Gentoo 论坛的 gralves 提供)

  • 在 GNOME 音量控制的选项(Options)标签中,把 IEC958 改成 PCM。该选项可以在首选项中启用。
  • 不使用 GNOME 音量控制工具的话:
    • 编辑 /var/lib/alsa/asound.state。该文件是 alsasound 保存混音器设置的地方。
    • 找到这一行:“IEC958 Playback Switch”。该行上下应该有一行内容为 value:false,将其改为 value:true
    • 再找到这一行:”IEC958 Playback AC97-SPSA“。把对应的值改为 0。
    • 重启 ALSA。

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: rc.local 在 systemd 中已经弃用,以下方法可能不再适用。 (Discuss in Talk:Advanced Linux Sound Architecture (简体中文)#)

还有另外一个开机自动启用 SPDIF 输出的方法(在 SoundBlaster Audigy 声卡上测试过):

  • /etc/rc.local 中添加如下内容:
 # Use COAX-digital output
 amixer set 'IEC958 Optical' 100 unmute
 amixer set 'Audigy Analog/Digital Output Jack' on

使用以下命令,获取你的声卡的数字输出的名称:

 $ amixer scontrols

系统级均衡器

使用 AlsaEqual(包含界面)

AUR 安装 alsaequalAUR

注意: 如果使用的是64位系统,而又安装了32位的 Flash 插件,这里的设置会导致 Flash 无声。如果发生了这种情况,请禁用 alsaequal 或编译32位版本的 alsaequal。

安装后,把下列内容添加到 ALSA 配置文件(~/.asoundrc/etc/asound.conf):

ctl.equal {
 type equal;
}

pcm.plugequal {
  type equal;
  # Modify the line below if you do not
  #slave.pcm "plughw:0,0";
  #by default we want to play from more sources at time:
  slave.pcm "plug:dmix";
}
#pcm.equal {
  # If you do not want the equalizer to be your
  # default soundcard comment the following
  # line and uncomment the above line. (You can
  # choose it as the output device by addressing
  # it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
pcm.!default {
  type plug;
  slave.pcm plugequal;
}

设置好后,切换均衡器:

$ alsamixer -D equal

需要注意,每个用户的 alsaequal 配置文件都是独立的,位于 ~/.alsaequal.bin。因此,如果想在 mpd 之类的以独立用户身份运行的程序中使用 AlsaEqual,就得像下面这样:

# su mpd -c 'alsamixer -D equal'

或者,在其他用户的主目录下创建符号链接,指向你的 .alsaequal.bin……

管理 AlsaEqual 配置

Xyne 的软件仓库AUR 安装 alsaequal-mgr

同上,配置均衡器:

$alsamixer -D equal

如果对效果感到满意,将其命名(如“foo”)并保存该配置:

$alsaequal-mgr save foo

重新加载“foo”中的配置:

$alsaequal-mgr load foo

这样,就可以为游戏、电影、不同音乐流派、网络电话等等创建不同的均衡器配置,以便随时切换。

参见项目主页和程序的帮助信息,了解更多设置。

使用 mbeq

注意: 该软件用到了一个 ladspa 插件,可能导致播放音频时 CPU 占用率偏高。In addition, this was made with stereophonic sound (e.g. headphones) in mind.

安装 alsa-pluginsladspaswh-plugins 软件包。

  • ~/.asoundrc/etc/asound.conf 中添加如下内容:
/etc/asound.conf
pcm.eq {
  type ladspa

  # The output from the EQ can either go direct to a hardware device
  # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
  # to the software mixer shown here.
  #slave.pcm "plughw:0,0"
  slave.pcm "plug:dmix"

  # Sometimes you may need to specify the path to the plugins,
  # especially if you have just installed them.  Once you have logged
  # out/restarted this should not be necessary, but if you get errors
  # about being unable to find plugins, try uncommenting this.
  #path "/usr/lib/ladspa"

  plugins [
    {
      label mbeq
      id 1197
      input {
        #this setting is here by example, edit to your own taste
        #bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz, 1250hz, 1750hz, 25000hz,
        #50000hz, 10000hz, 20000hz
        controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
      }
    }
  ]
 }

 # Redirect the default device to go via the EQ - you may want to do
 # this last, once you are sure everything is working.  Otherwise all
 # your audio programs will break/crash if something has gone wrong.

 pcm.!default {
  type plug
  slave.pcm "eq"
 }

 # Redirect the OSS emulation through the EQ too (when programs are running through "aoss")

 pcm.dsp0 {
  type plug
  slave.pcm "eq"
 }
  • 完成。若有问题,欢迎前往论坛咨询。

高质量重采样

启用软件混音时,ALSA 会强制把所有音频重采样到相同的频率(如果系统支持,默认是 48000)。dmix 的重采样算法很糟糕,会导致显著的质量损失。

安装 alsa-pluginslibsamplerate

将默认的采样率转换器更改为 libsamplerate:

/etc/asound.conf
defaults.pcm.rate_converter "samplerate_best"

或:

~/.asoundrc
defaults.pcm.rate_converter "samplerate_best"

samplerate_best 输出的声音质量最佳,但需要耗费大量CPU资源进行实时重采样。还有其他的算法可供选择(如 samplerate 等),但比起默认的算法,这些算法的改进并不明显。

警告: 某些系统中,启用 samplerate_best 可能导致 Flash 播放器无声音。

Upmixing/Downmixing

Upmixing

In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. Thus, install alsa-plugins.

Then add the following to your ALSA configuration file of choice (either /etc/asound.conf or ~/.asoundrc):

pcm.upmix71 {
    type upmix
    slave.pcm "surround71"
    delay 15
    channels 8
}

You can easily change this example for 7.1 upmixing to 5.1 or 4.0.

This adds a new pcm that you can use for upmixing. If you want all sound sources to go through this pcm, add it as a default below the previous definition like so:

pcm.!default "plug:upmix71"

The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice. If this is not working, you have to setup your own dmixer for the upmixing PCM like this:

pcm.dmix6 {
    type asym
    playback.pcm {
        type dmix
        ipc_key 567829
        slave {
            pcm "hw:0,0"
            channels 6
        }
    }
}

and use "dmix6" instead of "surround71". If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a high quality resampler.

Downmixing

If you want to downmix sources to stereo because you, for instance, want to watch a movie with 5.1 sound on a stereo system, you need to use the vdownmix plugin that alsa provides in the same package.

Again, in your configuration file, add this:

pcm.!surround51 {
    type vdownmix
    slave.pcm "default"
}
pcm.!surround40 {
    type vdownmix
    slave.pcm "default"
}

混音

软件混音(dmix)

注意: 在 ALSA 1.0.9rc2 及以上版本中,如果声卡不支持硬件混音,模拟输出将默认使用 dmix 混音,无需额外设置。

如果软件混音未正常启用,那么可以手动创建 ~/.asoundrc,加入以下内容:

pcm.dsp {
    type plug
    slave.pcm "dmix"
}

这样就启用了软件混音,多个程序能够同时使用声卡。

至于 S/PDIF 之类的数字音频输出,目前的 ALSA 还不会默认启用 dmix。因此,必须像上面这样手动启用。

常见问题的解答,参见#疑难解答部分。

硬件混音

支持

如果声卡支持,一般无需任何配置即可启用硬件混音。绝大多数板载声卡都不支持硬件混音,必须得使用软件混音(见上文)。很多独立声卡都支持硬件混音,Linux 下支持较好的有:

  • Creative SoundBlaster Live! (5.1 型号)
  • Creative SoundBlaster Audigy (部分型号)
  • Creative SoundBlaster Audidy 2 (ZS 系列型号)
  • Creative SoundBlaster Audigy 4 (Pro 系列型号)
注意: 上述声卡的低端版本(Audigy SE、Audigy 2 NX、SoundBlaster Live! 24bit 以及 SoundBlaster Live! 7.1)使用了不同的芯片,不支持硬件混音。
注意: 板载 VIA8237 芯片支持4路硬件混音,但在某些主板上只能使用3路(第4路无声),甚至根本无法使用。即使能正常工作,质量也比不上其他混音方法。

问题修复

如果你的声卡是 Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 02),且使用了64位系统,需要执行以下命令才能在 Enemy Territory 中听到声音:

echo "et.x86 0 0 direct" > /proc/asound/card0/pcm0p/oss
echo "et.x86 0 0 disable" > /proc/asound/card0/pcm0c/oss

疑难解答

使用CPU频率动态调整时,音频发生跳跃

使用 ondemandconservative 频率策略、启用CPU频率动态调整时,某些声卡和某些 ALSA 驱动会出现声音跳跃的情况。目前,唯一的解决方案是使用固定的频率,如 performance 性能策略。

详情参见 CPU Frequency Scaling (简体中文)

Problems with Availability to Only One User at a Time

You might find that only one user can use the dmixer at a time. This is probably ok for most, but for those who run mpd as a separate user this poses a problem. When mpd is playing a normal user cannot play sounds though the dmixer. While it's quite possible to just run mpd under a user's login account, another solution has been found. Adding the line ipc_key_add_uid 0 to the pcm.dmixer block disables this locking. The following is a snippet of the asound.conf, the rest is the same as above.

...
pcm.dmixer {
 type dmix
 ipc_key 1024
 ipc_key_add_uid 0
 ipc_perm 0660
slave {
...

Simultaneous Playback Issues

If you are having simultaneous playback issues, and if PulseAudio is installed (i.e. by GNOME), its default configuration is set to "hijack" the soundcard. Some users of ALSA may not want to use PulseAudio and are quite content with their current ALSA settings. One fix is to edit /etc/asound.conf and comment out the following lines:

# Use PulseAudio by default
#pcm.!default {
#  type pulse
#  fallback "sysdefault"
#  hint {
#    show on
#    description "Default ALSA Output (currently PulseAudio Sound Server)"
#  }
#}

Commenting the following out also may help:

#ctl.!default {
#  type pulse
#  fallback "sysdefault"
#}

This may be a much simpler solution than completely uninstalling PulseAudio.

Effectively, here is an example of a working /etc/asound.conf:

pcm.dmixer {
        type dmix
        ipc_key 1024
        ipc_key_add_uid 0
        ipc_perm 0660
}
pcm.dsp {
        type plug
        slave.pcm "dmix"
}
Note: This /etc/asound.conf file was intended for and used successfully with a global MPD configuration. See this section on multiple users

Random Lack of Sound on Startup

If you randomly have no sound on startup, it may be because your system has multiple sound cards, and their order may sometimes change on startup. If this is the case, try setting the default sound card.

If you use mpd and the configuration tips above do not work for you, try reading this instead.

Specific Program Problems

For other programs who insist on their own audio setup, eg, XMMS or Mplayer, you would need to set their specific options.

For mplayer, open up ~/.mplayer/config (or /etc/mplayer/mplayer.conf for global setting) and add the following line:

ao=alsa

For XMMS/Beep Media Player, go into their options and make sure the sound driver is set to Alsa, not oss.

To do this in XMMS:

  • Open XMMS
    • Options -> preferences.
    • Choose the Alsa output plugin.

For applications which do not provide a ALSA output, you can use aoss from the alsa-oss package. To use aoss, when you run the program, prefix it with aoss, eg:

aoss realplay

pcm.!default{ ... } doesnt work for me anymore. but this does:

 pcm.default pcm.dmixer

Model Settings

Although Alsa detects your soundcard through the BIOS at times Alsa may not be able to recognize your model type. The soundcard chip can be found in alsamixer (e.g. ALC662) and the model can be set in /etc/modprobe.d/modprobe.conf or /etc/modprobe.d/sound.conf. For example:

options snd-hda-intel model=MODEL

There are other model settings too. For most cases Alsa defaults will do. If you want to look at more specific settings for your soundcard take a look at the Alsa Soundcard List find your model, then Details, then look at the "Setting up modprobe..." section. Enter these values in /etc/modprobe.d/modprobe.conf. For example, for an Intel AC97 audio:

# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-intel8x0
# module options should go here

# OSS/Free portion
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0

# card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

Conflicting PC Speaker

If you are sure nothing is muted, that your drivers are installed correctly, and that your volume is right, but you still do not hear anything, then try adding the following line to /etc/modprobe.d/modprobe.conf:

options snd-NAME-OF-MODULE ac97_quirk=0

The above fix has been observed to work with via82xx

options snd-NAME-OF-MODULE ac97_quirk=1

The above fix has been reported to work with snd_intel8x0

No Microphone Input

In alsamixer, make sure that all the volume levels are up under recording, and that CAPTURE is toggled active on the microphone (e.g. Mic, Internal Mic) and/or on Capture (in alsamixer, select these items and press space). Try making positive Mic Boost and raising Capture and Digital levels higher; this make make static or distortion, but then you can adjust them back down once you are hearing something when you record

As the pulseaudio wrapper is shown as "default" in alsamixer, you may have to press F6 to select your actual soundcard first. You may also need to enable and increase the volume of Line-in in the Playback section.

To test the microphone, run these commands (see arecord's man page for further information):

 arecord -d 5 test-mic.wav
 aplay test-mic.wav

If all fails, you may want to eliminate hardware failure by testing the microphone with a different device.

For at least some computers, muting a microphone (MM) simply means its input does not go immediately to the speakers. It still receives input.

Many Dell laptops need "-dmic" to be appended to the model name in /etc/modprobe.d/modprobe.conf:

 options snd-hda-intel model=dell-m6-dmic

Some programs use try to use OSS as the main input software. Add the following lines to /etc/modprobe.d/modprobe.conf to prevent OSS modules from being loaded:

Note: The OSS modules are no longer autoloaded anyway.
blacklist snd_pcm_oss
blacklist snd_mixer_oss
blacklist snd_seq_oss

See also:

Setting the default Microphone/Capture Device

Some applications (Pidgin, Adobe Flash) do not provide an option to change the capture device. It becomes an issue if your microphone is on a separate device (e.g. USB webcam or microphone) than your internal sound card. To change only the default capture device, leaving the default playback device as is, you can modify your ~/.asoundrc file to include the following:

pcm.usb
{
    type hw
    card U0x46d0x81d
}

pcm.!default
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "dmix"
    }
    capture.pcm
    {
        type plug
        slave.pcm "usb"
    }
}

Replace "U0x46d0x81d" with your capture device's card name in ALSA. You can use arecord -L to list all the capture devices detected by ALSA.

Internal Microphone not working

First make sure all the volume levels are up under recording in alsamixer. In my case adding the following option to /etc/sound.conf and reloading the snd-* module produced a new volume setting called Capture which was capturing for the internal mic. For eg, for snd-hda-intel add

 options snd-hda-intel enable_msi=1

Then reload the module (as below), up the recording volume of Capture and then test.

# rmmod snd-hda-intel && modprobe snd-hda-intel

No Sound with Onboard Intel Sound Card

There may be an issue with two conflicting modules loaded, namely snd_intel8x0 and snd_intel8x0m. In this case, blacklist snd_intel8x0m:

/etc/modprobe.d/modprobe.conf
blacklist snd_intel8x0m

Muting the "External Amplifier" in alsamixer or amixer may also help. See the ALSA wiki.

Unmuting the "Mix" setting in the mixer might help, also.

No Headphone Sound with Onboard Intel Sound Card

With Intel Corporation 82801 I (ICH9 Family) HD Audio Controller on laptop, you may need to add this line to modprobe or sound.conf:

options snd-hda-intel model=$model

Where $model is any one of the following (in order of possibility to work, but not merit):

  • dell-vostro
  • olpc-xo-1_5
  • laptop
  • dell-m6
  • laptop-hpsense

Note: It may be necessary to put this "options" line below (after) any "alias" lines about your card.

You can see all the available models in the kernel documentation. For example here, but check that it is the correct version of that document for your kernel version.

A list of available models is also available here. To know your chip name type the following command (with * being corrected to match your files). Note that some chips could have been renamed and do not directly match the available ones in the file.

cat /proc/asound/card*/codec* | grep Codec

Note that there is a high chance none of the input devices (all internal and external mics) will work if you choose to do this, so it is either your headphones or your mic. Please report to ALSA if you are affected by this bug.

And also, if you have problems getting beeps to work (pcspkr):

options snd-hda-intel model=$model enable=1 index=0

No sound when S/PDIF video card is installed

Discover available modules and their order:

$ cat /proc/asound/modules
0 snd_hda_intel
1 snd_ca0106

Disable the undesired video card audio codec in /etc/modprobe.d/modprobe.conf:

# /etc/modprobe.d/modprobe.conf
#
install snd_hda_intel /bin/false

If both devices use the same module, it might be possible to disable one of them in the BIOS.

Poor sound quality or clipping

If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.

If snd-usb-audio driver has been loaded, you could try to enable softvol in /etc/asound.conf file. Example configuration for the first audio device:

 pcm.!default {
   type plug
   slave.pcm "softvol"
 }
 pcm.dmixer {
      type dmix
      ipc_key 1024
      slave {
          pcm "hw:0"
          period_time 0
          period_size 4096
          buffer_size 131072
          rate 50000
      }
      bindings {
          0 0
          1 1
      }
 }
 pcm.dsnooper {
      type dsnoop
      ipc_key 1024
      slave {
          pcm "hw:0"
          channels 2
          period_time 0
          period_size 4096
          buffer_size 131072
          rate 50000
      }
      bindings {
          0 0
          1 1
      }
 }
 pcm.softvol {
      type softvol
      slave { pcm "dmixer" }
      control {
          name "Master"
          card 0
      }
 }
 ctl.!default {
   type hw
   card 0
 }
 ctl.softvol {
   type hw
   card 0
 }
 ctl.dmixer {
   type hw
   card 0
 }

Pops When Starting and Stopping Playback

Some modules (e.g. snd_ac97_codec and snd_hda_intel) can power off your sound card when not in use. This can make an audible noise (like a crack/pop/scratch) when turning on/off your sound card. Sometimes even when move the slider volume, or open and close windows (KDE4). If you find this annoying try modinfo snd_MY_MODULE, and look for a module option that adjusts or disables this feature.

Example: to disable the power saving mode and solve cracking sound trough speakers issue, using snd_hda_intel add in /etc/modprobe.d/modprobe.conf

options snd_hda_intel power_save=0

or

options snd_hda_intel power_save=0 power_save_controller=N

You can also try it with modprobe snd_hda_intel power_save=0 before.

You may also have to unmute the 'Line' ALSA channel for this to work. Any value will do (other than '0' or something too high).

Example: on an onboard VIA VT1708S (using the snd_hda_intel module) these cracks occured even though 'power_save' was set to 0. Unmuting the 'Line' channel and setting a value of '1' solved the issue.

Source: https://www.kernel.org/doc/Documentation/sound/alsa/powersave.txt

If you use a laptop, pm-utils will change power_save back to 1 when you go onto battery power even if you disable power saving in /etc/modprobe.d. Disable this for pm-utils by disabling the script that makes the change (see Disabling a hook for more information):

# touch /etc/pm/power.d/intel-audio-powersave

S/PDIF Output Does Not Work

If the optical/coaxial digital output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try running

# iecset audio on

as root.

You can also put this command in rc.local as it sometimes it may stop working after a reboot.

HDMI Output Does Not Work

If the HDMI output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try the following.

Query for Playback Devices:

 $ aplay -l
 **** List of PLAYBACK Hardware Devices ****
 card 0: NVidia [HDA NVidia], device 0: ALC1200 Analog [ALC1200 Analog]
   Subdevices: 1/1
   Subdevice #0: subdevice #0
 card 0: NVidia [HDA NVidia], device 1: ALC1200 Digital [ALC1200 Digital]
   Subdevices: 1/1
   Subdevice #0: subdevice #0
 card 0: NVidia [HDA NVidia], device 3: NVIDIA HDMI [NVIDIA HDMI]
   Subdevices: 0/1
   Subdevice #0: subdevice #0

Now that we have the info for the HDMI device, try a test, In the example below, 0 is the card number and 3 is the device number.

 $ aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav

If aplay does not output any errors, but still no sound is heared, "reboot" the receiver, monitor or tv set. Since the HDMI interface executes a handshake on connection, it might have noticed before that there was no audio stream embedded, and disabled audio decoding. In particular, if you are using a standalone window manager (don’t know about Gnome or KDE), you may need to have some sound playing while plugging in the HDMI cable.

Note: If you are using an ATI card and linux 3.0, check your kernel/grub settings, you most likely need to use the 'radeon.audio=1' boot parameter, or alternatively set up the option in your modprobe configuration files.

If the test is successful, create or edit your ~/.asoundrc file to set HDMI as the default audio device.

~/.asoundrc
pcm.!default {
  type hw
  card 0
  device 3
}

Or you above config does not work try:

~/.asoundrc
defaults.pcm.card 0
defaults.pcm.device 3
defaults.ctl.card 0

HDMI Multi-channel PCM output does not work (Intel)

As of Linux 3.1 multi-channel PCM output through HDMI with a Intel card (Intel Eaglelake, IbexPeak/Ironlake,SandyBridge/CougarPoint and IvyBridge/PantherPoint) is not yet supported. Support for it has been recently added and expected to be available in Linux 3.2. To make it work in Linux 3.1 you need to apply the following patches:

HP TX2500

Add these 2 lines into /etc/modprobe.d/modprobe.conf:

options snd-cmipci mpu_port=0x330 fm_port=0x388
options snd-hda-intel index=0 model=toshiba position_fix=1
options snd-hda-intel model=hp (works for tx2000cto)

Skipping Sound When Playing MP3

If you have sound skipping when playing MP3 files and you have more then 2 speakers attached to your computer (i.e. > 2 speaker system), run alsamixer and disable the channels for the speakers that you DO NOT have (i.e. do not enable the sound for the center speaker if you do not have a center speaker.

Using a USB Headset and External USB Sound Cards

If you are using a USB headset with ALSA you can try using asoundconfAUR (currently only available from the AUR) to set the headset as the primary sound output. Before running make sure you have usb audio module enabled (modprobe snd-usb-audio).

# asoundconf is-active
# asoundconf list
# asoundconf set-default-card <chosen soundcard>

Crackling sound with USB devices

If you experience crackling sound on USB devices, you can try tuning the snd-usb-audio for minimal latency.

Add this to your /etc/modprobe.d/modprobe.conf:

options snd-usb-audio nrpacks=1

source: http://alsa.opensrc.org/Usb-audio#Tuning_USB_devices_for_minimal_latencies

Hot-plugging a USB Sound Card

In order to automatically make a USB Sound Card the primary output device, when the card is plugged in, you can use the following udev rules (e.g. add the following two lines to /etc/udev/rules.d/00-local.rules and reboot).

KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

Error 'Unknown hardware' Appears After a Kernel Update

The following messages may be displayed during the start-up ALSA after the kernel update:

Unknown hardware "foo" "bar" ...
Hardware is initialized using a guess method
/usr/sbin/alsactl: set_control:nnnn:failed to obtain info for control #mm (No such file or directory)

or

Found hardware: "HDA-Intel" "VIA VT1705" "HDA:11064397,18490397,00100000" "0x1849" "0x0397"
Hardware is initialized using a generic method
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #1 (No such file or directory)
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #2 (No such file or directory)
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #25 (No such file or directory)
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #26 (No such file or directory)

Simply store ALSA mixer settings again (as root):

# alsactl -f /var/lib/alsa/asound.state store

It may be necessary configure ALSA again with alsamixer

HDA Analyzer

If the mappings to your audio pins(plugs) do not correspond but ALSA works fine, you could try HDA Analyzer -- a pyGTK2 GUI for HD-audio control can be found at the ALSA wiki. Try tweaking the Widget Control section of the PIN nodes, to make microphones IN and headphone jacks OUT. Referring to the Config Defaults heading is a good idea.

NOTE: the script is done by such way that it is incompatible with python3 (which is now shipped with ArchLinux) but tries to use it. The workaround is: open "run.py", find all occurences of "python" (2 occurences - one on the first line, and the second on the last line) and replace them all by "python2".

NOTE2: the script requires root acces, but running it via su/sudo is bogus. Run it via kdesu or gksu.

ALSA with SDL

If you get no sound via SDL and ALSA cannot be chosen from the application. Try setting the environmental variable SDL_AUDIODRIVER to alsa.

# export SDL_AUDIODRIVER=alsa

Low Sound Workaround

If you are facing low sound even after maxing out your speakers/headphones, you can give the softvol plugin a try. Add the following to /etc/asound.conf.

pcm.!default {
      type plug
      slave.pcm "softvol"
  }

pcm.softvol {
    type softvol
    slave {
        pcm "dmix"
    }
    control {
        name "Pre-Amp"
        card 0
    }
    min_dB -5.0
    max_dB 20.0
    resolution 6
}
Note: You will probably have to restart the computer, as restarting the alsa daemon did not load the new configuration for me. Also, if the configuration does not work even after restarting, try changing plug with hw in the above configuration.

After the changes are loaded successfully, you will see a Pre-Amp section in alsamixer. You can adjust the levels there.

Note: Setting a high value for Pre-Amp can cause sound distortion, so adjust it according to the level that suits you.

Popping sound after resuming from suspension

You might hear a popping sound after resuming the computer from suspension. This can be fixed by editing /etc/pm/sleep.d/90alsa and removing the line that says aplay -d 1 /dev/zero

设置文件范例

参见:Advanced Linux Sound Architecture/Example Configurations

相关阅读