Advanced Linux Sound Architecture (简体中文)
Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end
高级 Linux 声音体系(Advanced Linux Sound Architecture,ALSA)是Linux中提供声音设备驱动的内核组件,用来代替原来的开放声音系统(Open Sound System,OSSv3)。除了声音设备驱动,ALSA还包含一个用户空间的函数库,以方便开发者通过高级API使用驱动功能,而不必直接与内核驱动交互。
Contents
- 1 安装
- 2 解除各声道的静音
- 3 配置
- 4 高质量重采样
- 5 上混和下混
- 6 混音
- 7 疑难解答
- 7.1 使用CPU频率动态调整时,音频发生跳跃
- 7.2 同时只能有一个用户播放音频
- 7.3 无法同时播放多个音频
- 7.4 有时候开机无声
- 7.5 特定程序的问题
- 7.6 特定型号的配置
- 7.7 与蜂鸣器冲突
- 7.8 麦克风输入无声音
- 7.9 设置默认的麦克风/录音设备
- 7.10 内置麦克风无效
- 7.11 Intel 板载声卡无声
- 7.12 Intel 板载声卡耳机无声
- 7.13 安装支持 S/PDIF 输出的显卡后无声
- 7.14 音效差或卡顿
- 7.15 开始或停止音频播放时出现噪音
- 7.16 S/PDIF 输出无效
- 7.17 HDMI 输出无效
- 7.18 HDMI Multi-channel PCM output does not work (Intel)
- 7.19 HP TX2500
- 7.20 Skipping Sound When Playing MP3
- 7.21 Using a USB Headset and External USB Sound Cards
- 7.22 Error 'Unknown hardware' Appears After a Kernel Update
- 7.23 HDA Analyzer
- 7.24 ALSA with SDL
- 7.25 Low Sound Workaround
- 7.26 Popping sound after resuming from suspension
- 8 配置文件范例
- 9 相关阅读
安装
Arch 默认的内核已经通过一套模块提供了 ALSA,不必特别安装。
udev会在系统启动时自动检测硬件,并加载相应的声音设备驱动模块。这时,你的声卡已经可以工作了,只是所有声道默认都被设置成静音了。
在本地登录(通过虚拟终端或登录管理器)的用户,都有权限播放音频并调整音量。要让远程登录的用户拥有这些权限,必须把用户加入 audio
用户组。该组的成员可以直接访问声音设备,会导致某些程序独占音频输出(破坏软件混音),还可能影响用户快速切换和拖机(multiseat)。因此,除非真的有某些特殊需求,不建议把用户加入 audio
用户组。
用户空间工具
从 官方仓库:
- 安装 alsa-utils 软件包,其中的
alsamixer
工具允许用户在控制台或终端中配置声音设备。 - 安装 alsa-oss 软件包,如果想让 OSS 应用程序与dmix(软件混音)协同工作。
- 安装 alsa-plugins 软件包,如果需要 高质量重采样、软件模拟环绕立体声和其他高级特性。
解除各声道的静音
目前版本的 ALSA 安装后,所有声道默认是静音的,必须手动解除。
使用 alsamixer
的 ncurses 界面,配置十分简单:
$ alsamixer
此外,还可以在命令行下使用 amixer
:
$ amixer sset Master unmute
在 alsamixer
中,下方标有 MM
的声道是静音的,而标有 00
的通道已经启用。
使用左右方向键,选中 Master
和 PCM
声道。按下 Template:Keypress 键解除静音。使用上方向键增加音量,直到增益值为0
。该值显示在左上方 Item:
字段后。过高的增益值会导致声音失真。
要想得到完整的 5.1 或 7.1 环绕立体声,还得解除 Front、Surround、Center、LFE (subwoofer) 和 Side 这些声道的静音(上述名称是 Intel HD Audio 声卡使用的声道名,可能因设备不同而有所差异)。注意,仅有这些设置,系统不会自动将立体声源(多数音乐)提升(upmix)成环绕立体声。如果需要这些功能,请阅读#Upmixing/Downmixing。
要启用麦克风,切换至 Capture 选项卡,按下 Template:Keypress,按下 Template:Keypress 启用其中一个声道即可。
按下 Template:Keypress 键退出 alsamixer。
接下来,测试声卡是否工作:
$ speaker-test -c 2
根据扬声器的实际情况,调整 -c 后的数值。对于 7.1 声道,这个数字是 8:
$ speaker-test -c 8
如果没有正常工作,请继续阅读 #配置 以及 #疑难解答 部分。
alsa-utils 软件包提供了两个配置 alsa 的服务:alsa-restore.service
和 alsa-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
使用 lsmod | grep snd
获取设备列表。
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
以上配置会在系统重启后生效。
首先,运行 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,请根据实际情况调整:
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
如果你的输出和上面类似,那就说明声卡已经被正确识别。
还可以检查一下 /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
如果你的输出跟上面类似,或至少有 controlC0 和 pcmC0D0p,那么声卡就已经正常加载了。
如果出现问题,声卡模块没有正确加载,那么请尝试手动加载模块:
- 确定声卡对应的驱动模块:ALSA Soundcard Matrix。这些模块都会有一个”snd-“前缀(例如:
snd-via82xx
)。 - 加载模块。
- 检查
/dev/snd
目录中的设备文件(参见上文);或者,检查alsamixer
或amixer
的输出是否正确。 - 修改配置,使
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。
- 编辑
还有另外一个开机自动启用 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(包含界面)
安装后,把下列内容添加到 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
安装 alsa-plugins、ladspa 和 swh-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-plugins 和 libsamplerate。
将默认的采样率转换器更改为 libsamplerate:
/etc/asound.conf
defaults.pcm.rate_converter "samplerate_best"
或:
~/.asoundrc
defaults.pcm.rate_converter "samplerate_best"
samplerate_best 输出的声音质量最佳,但需要耗费大量CPU资源进行实时重采样。还有其他的算法可供选择(如 samplerate 等),但比起默认的算法,这些算法的改进并不明显。
上混和下混
上混(upmixing)
播放双声道立体声音源(如音乐)时,利用上混,即可充分利用 5.1 或 7.1 环绕立体声的所有声道。以前,上混很麻烦,还经常出错。但如今就方便多了,只需要安装一些插件即可。这些插件由 alsa-plugins 软件包提供。
安装后,在配置文件(/etc/asound.conf
或 ~/.asoundrc
)中添加如下内容:
pcm.upmix71 { type upmix slave.pcm "surround71" delay 15 channels 8 }
该范例适用于7.1声道上混。类比该范例,同样能设置5.1或4.0声道上混。
该设置添加了一个新的用于上混的 pcm。如果希望所有音频源都通过该 pcm 输出,在上述设置后添加如下配置即可:
pcm.!default "plug:upmix71"
插件默认配置就允许多个音频源同时通过它输出,一般无需额外配置。如果不行,就得向下面这样为上混配置 dmixer:
pcm.dmix6 { type asym playback.pcm { type dmix ipc_key 567829 slave { pcm "hw:0,0" channels 6 } } }
注意要用 dmix6 而非 surround71。
如果遇到声音卡顿或混乱,可能需要增加 buffer_size(比如增加到 32768),或使用高质量重采样。
下混(downmixing)
有时也会用到下混,比如在只支持双声道立体声的电脑上观看5.1声道的电影时。这一功能由 ALSA 插件 vdownmix 实现(同样在 alsa-plugins 软件包里)。
在配置文件中添加如下内容:
pcm.!surround51 { type vdownmix slave.pcm "default" } pcm.!surround40 { type vdownmix slave.pcm "default" }
混音
软件混音(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 系列型号)
问题修复
如果你的声卡是 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频率动态调整时,音频发生跳跃
使用 ondemand
或 conservative
频率策略、启用CPU频率动态调整时,某些声卡和某些 ALSA 驱动会出现声音跳跃的情况。目前,唯一的解决方案是使用固定的频率,如 performance
性能策略。
详情参见 CPU Frequency Scaling (简体中文)。
同时只能有一个用户播放音频
有时会出现一个用户独占软件混音器的情况。多数情况下这没什么影响,但在使用 mpd 这样以独立用户身份运行的程序时,就会出现问题。当 mpd 运行时,用户自己就无法播放其他音频了。一种解决方法是,以正在使用的用户身份运行 mpd。另一种方法是,在 ALSA 配置文件的 pcm.dmixer
部分添加 ipc_key_add_uid 0
禁止独占。以下是 asound.conf
示例的片段,省略的部分无需修改:
... pcm.dmixer { type dmix ipc_key 1024 ipc_key_add_uid 0 ipc_perm 0660 slave { ...
无法同时播放多个音频
如果安装了 PulseAudio(可能作为 GNOME 的依赖被安装),可能出现无法同步播放的问题,因为 PulseAudio 的默认配置是“独占”声卡。ALSA 的用户可能对自己的配置已经很满意、不希望使用 PulseAudio。解决方案是编辑 /etc/asound.conf
并注释掉以下内容:
# Use PulseAudio by default #pcm.!default { # type pulse # fallback "sysdefault" # hint { # show on # description "Default ALSA Output (currently PulseAudio Sound Server)" # } #}
可能还需要注释掉下面的内容:
#ctl.!default { # type pulse # fallback "sysdefault" #}
比起完全卸载 PulseAudio,这大概是个更简单的方法。
以下是 /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" }
有时候开机无声
如果会随机地出现开机无声的问题,原因可能是多声卡的顺序发生了变化。如果是这种情况,请参照#设置默认声卡进行设置。
对于 mpd 用户,上述配置无效,请参考该文设置。
特定程序的问题
对于不使用系统声音配置的程序,如 XMMS 和 Mplayer,必须特别设置以应用 ALSA 配置。
对于 mplayer,将以下内容添加到 ~/.mplayer/config
(或系统全局配置文件 /etc/mplayer/mplayer.conf
):
ao=alsa
对于 XMMS 和 Beep Media Player,打开选项窗口,要把声音驱动设置为 ALSA 而不是 OSS。
XMMS 的设置方法:
- 启动 XMMS
- 选项 -> 首选项
- 选择 Alsa 输出插件
对于未提供 ALSA 输出的程序,可以使用 alsa-oss 软件包中的 aoss 工具启动。使用方法是:在要运行的程序的命令行前加上 aoss
。例如:
aoss realplay
pcm.!default{ ... } 貌似已经不管用了。但下面的设置有效:
pcm.default pcm.dmixer
特定型号的配置
ALSA 会通过 BIOS 检测声卡型号,少数情况下也可能无法正确识别。声卡芯片类型可以在 alsamixer
界面上找到(如 ALC662),而型号则要设置在 /etc/modprobe.d/modprobe.conf
或 /etc/modprobe.d/sound.conf
文件中:
options snd-hda-intel model=<型号>
具体设置因声卡型号而异。多数情况下不需要特地这样做。如果想知道具体声卡型号的设置,请查阅 Alsa Soundcard List,找到你的声卡型号,点击“Details”,然后查看“Setting up modprobe...”小节,将其中的内容插入 /etc/modprobe.d/modprobe.conf
文件即可。例如,Intel AC97 的配置如下:
# 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
与蜂鸣器冲突
如果你确认所有声道都已解除静音,声卡驱动配置正确,且音量大小也合适,但还是听不到声音,那么请试试将下面的内容添加到 /etc/modprobe.d/modprobe.conf
:
(如果是 via82xx
驱动)
options snd-<模块名请自行补充> ac97_quirk=0
(如果是 snd_intel8x0
驱动)
options snd-NAME-OF-MODULE ac97_quirk=1
麦克风输入无声音
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:
blacklist snd_pcm_oss blacklist snd_mixer_oss blacklist snd_seq_oss
See also:
设置默认的麦克风/录音设备
某些程序(Pidgin、Adobe Flash)提供了设置录音设备的选项。如果录音设备不是内置的声卡,而是外接的(如USB摄像头、麦克风),就会有些问题。如果只想更改默认的录音设备、不更改回放设备,需要像下面这样设置 ~/.asoundrc
:
pcm.usb { type hw card U0x46d0x81d } pcm.!default { type asym playback.pcm { type plug slave.pcm "dmix" } capture.pcm { type plug slave.pcm "usb" } }
把“U0x46d0x81d”替换为你的录音设备的名称。可以通过 arecord -L
查看所有 ALSA 识别到的录音设备。
内置麦克风无效
首先,请检查 alsamixer,确保所有的录音声道的音量都达到可以录制的程度。如果还是不行,试试修改 /etc/sound.conf 并重载 snd-* 模块。这样就会多出来一个名叫 Capture 的音频控制,可以用它调节内置麦克风的音量。例如,对于 snd-hda-intel 模块,配置如下:
options snd-hda-intel enable_msi=1
然后,输入下面的命令重载模块,调整音量并测试。
# rmmod snd-hda-intel && modprobe snd-hda-intel
Intel 板载声卡无声
可能由两个相互冲突的驱动模块引起,分别是 snd_intel8x0
和 snd_intel8x0m
。如果是的话,屏蔽 snd_intel8x0m 即可:
/etc/modprobe.d/modprobe.conf
blacklist snd_intel8x0m
以下方法可能也有效:在 alsamixer
或 amixer
把 “External Amplifier” 设置为静音。参见:ALSA wiki 相关条目。
也可以试试解除“Mix”的静音。
Intel 板载声卡耳机无声
对于笔记本电脑上的 Intel Corporation 82801 I (ICH9 Family) HD Audio Controller 声卡,可能需要添加如下内容到 modprobe 配置文件或 sound.conf,以解决耳机无声的问题:
options snd-hda-intel model=$model
$model 在下列型号中选择:
- dell-vostro
- olpc-xo-1_5
- laptop
- dell-m6
- laptop-hpsense
可以在内核文档中找到所有支持的型号,如该文。这是 2.6.35 版本内核的文档,你需要自己查找适用于自己内核版本的文档。
也可以从这里获取型号列表。要查看你的声卡芯片名称,输入下列命令(其中的“*”请根据实际情况替换)。注意,有些芯片名称被更改过,因此实际名称与文件中的可能不匹配。
cat /proc/asound/card*/codec* | grep Codec
注意,这么做很可能导致所有输入设备(内置和外置麦克风)无法工作,即要么让麦克风正常、要么让耳机正常。如果遇到这一问题,请向 ALSA 开发者报告。
另外,如果蜂鸣器(pcspkr)出现问题,可以试试使用以下配置修复:
options snd-hda-intel model=$model enable=1 index=0
安装支持 S/PDIF 输出的显卡后无声
检测已加载的相关模块,并记录顺序:
$ cat /proc/asound/modules 0 snd_hda_intel 1 snd_ca0106
在 /etc/modprobe.d/modprobe.conf
中禁用不希望使用的显卡的音频解码模块:
# /etc/modprobe.d/modprobe.conf # install snd_hda_intel /bin/false
如果不同设备使用同一模块,那么只能在 BIOS 中禁用其中之一。
音效差或卡顿
如果发现音效特别差,试试在 alsamixer 中调节一下 PCM 音量,到增益(gain)为0的水平。
若使用 snd-usb-audio 驱动,可以试试在 /etc/asound.conf
中启用 softvol
。下面是针对第一个声音设备的配置范例:
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 }
开始或停止音频播放时出现噪音
某些驱动模块(如 snd_ac97_codec 和 snd_hda_intel)会在声卡闲置时关闭它以节约用电。声卡启动或关闭时,就会发出刺耳的噪音。在调节音量或开关窗口(KDE4)时也可能发生这种情况。要消除这一问题,需要添加特定模块参数(通过 modinfo snd_MY_MODULE
查询)关闭该功能。
例如:对于 snd_hda_intel 模块,要禁用自动节电并解决噪音问题,需在 /etc/modprobe.d/modprobe.conf
中添加如下内容:
options snd_hda_intel power_save=0
或:
options snd_hda_intel power_save=0 power_save_controller=N
可以先使用 modprobe snd_hda_intel power_save=0
测试一下效果。
对于 VIA VT1708S 板载声卡(使用 snd_hda_intel 模块)等一些声卡,即使把 power_save 参数设置为0可能仍会有噪音。还得在 alsamixer 中把“Line”声道激活才能生效,只要激活并调到一个非0的音量即可(1即可,不要太高)。
内核模块文档:[1]
对于笔记本,即使在 /etc/modprobe.d
设置了 power_save
参数,当切换电池时 pm-utils 仍会将该值重置为1。需要禁用相关的脚步才行(详情参见:Pm-utils#Disabling_a_hook):
# touch /etc/pm/power.d/intel-audio-powersave
S/PDIF 输出无效
如果你已经在 alsamixer 中启用相关声道,但声卡的光学/同轴数字输出还是无效,试试以 root 身份运行:
# iecset audio on
每次开机都需要重新设置。如果嫌麻烦,可以自己写一个 systemd 服务。
HDMI 输出无效
若遇到声卡或主板的HDMI输出无法工作的问题,请首先确认 alsamixer 中的相关声道已经解除静音。如果还是不行,请进行下列操作:
查询回放设备:
$ 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
我们需要的是 HDMI 设备的信息,下面来做一个测试(在该例中,0是声卡编号,3是设备编号):
$ aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav
如果 aplay 没有给出错误信息,但还是听不到声音,请尝试重启通过HDMI链接的播放设备(显示器或电视)。HDMI接口会在链接时执行一次握手,有可能因为当时没有检测到音频流而禁用了音频解码。特别是,如果使用了独立的窗口管理器(不太清楚 Gnome 和 KDE 的情况),可能就必须一边播放音乐、一边链接HDMI线。
若测试成功,接下来编辑或创建 ~/.asoundrc
,把 HDMI 设置为默认音频设备。
~/.asoundrc
pcm.!default { type hw card 0 device 3 }
如果上述配置无效,试试下面这个:
~/.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 }
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.
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。