開始設定之前,必須先知道你的音效卡型號、晶片為何。 FreeBSD 支援許多種音效卡,請檢查支援的音效硬體表 Hardware Notes,以確認你的音效卡是否支援以及如何在 FreeBSD 上驅動。
要使用音效裝置,必須要載入正確的驅動程式才行。最簡單方式就是以 kldload(8) 來載入核心模組。以下範例示範載入 Intel 規格內建的音效晶片驅動程式:
#
kldload snd_hda
要開機時自動載入驅動程式,需將驅動程式加到 /boot/loader.conf
檔,以此驅動程式為例:
snd_hda_load="YES"
其他可用的音效卡模組清單列於 /boot/defaults/loader.conf
。當不確認要使用何種驅動程式時,可載入 snd_driver
模組:
#
kldload snd_driver
它是 metadriver 會載入所有最通用的音效驅動程式並且用來加速尋找正確的驅動程式。也可以把 metadriver 加入 /boot/loader.conf
檔來載入所有音效驅動程式。
要知道載入 snd_driver
metadriver 後使用了那個音效卡驅動程式,請輸入 cat /dev/sndstat
。
This section is for users who prefer to statically compile in support for the sound card in a custom kernel. For more information about recompiling a kernel, refer to 章 8, 設定 FreeBSD 核心.
When using a custom kernel to provide sound support, make sure that the audio framework driver exists in the custom kernel configuration file:
device sound
Next, add support for the sound card. To continue the example of the built-in audio chipset based on the Intel specification from the previous section, use the following line in the custom kernel configuration file:
device snd_hda
Be sure to read the manual page of the driver for the device name to use for the driver.
Non-PnP ISA sound cards may require the IRQ and I/O port
settings of the card to be added to
/boot/device.hints
. During the boot
process, loader(8) reads this file and passes the
settings to the kernel. For example, an old Creative
SoundBlaster® 16 ISA non-PnP card will use the
snd_sbc(4) driver in conjunction with
snd_sb16
. For this card, the following
lines must be added to the kernel configuration file:
device snd_sbc
device snd_sb16
If the card uses the 0x220
I/O port and
IRQ 5
, these lines must also be added to
/boot/device.hints
:
hint.sbc.0.at="isa"
hint.sbc.0.port="0x220"
hint.sbc.0.irq="5"
hint.sbc.0.drq="1"
hint.sbc.0.flags="0x15"
The syntax used in /boot/device.hints
is described in sound(4) and the manual page for the
driver of the sound card.
The settings shown above are the defaults. In some cases, the IRQ or other settings may need to be changed to match the card. Refer to snd_sbc(4) for more information about this card.
After loading the required module or rebooting into the
custom kernel, the sound card should be detected. To confirm,
run dmesg | grep pcm
. This example is
from a system with a built-in Conexant CX20590 chipset:
pcm0: <NVIDIA (0x001c) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm1: <NVIDIA (0x001c) (HDMI/DP 8ch)> at nid 6 on hdaa0
pcm2: <Conexant CX20590 (Analog 2.0+HP/2.0)> at nid 31,25 and 35,27 on hdaa1
The status of the sound card may also be checked using this command:
#
cat /dev/sndstat
FreeBSD Audio Driver (newpcm: 64bit 2009061500/amd64)
Installed devices:
pcm0: <NVIDIA (0x001c) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x001c) (HDMI/DP 8ch)> (play)
pcm2: <Conexant CX20590 (Analog 2.0+HP/2.0)> (play/rec) default
The output will vary depending upon the sound card. If no
pcm
devices are listed, double-check
that the correct device driver was loaded or compiled into the
kernel. The next section lists some common problems and their
solutions.
If all goes well, the sound card should now work in FreeBSD. If the CD or DVD drive is properly connected to the sound card, one can insert an audio CD in the drive and play it with cdcontrol(1):
%
cdcontrol -f /dev/acd0 play 1
Audio CDs have specialized encodings which means that they should not be mounted using mount(8).
Various applications, such as audio/workman, provide a friendlier interface. The audio/mpg123 port can be installed to listen to MP3 audio files.
Another quick way to test the card is to send data to
/dev/dsp
:
%
cat filename
> /dev/dsp
where
can
be any type of file. This command should produce some noise,
confirming that the sound card is working.filename
The /dev/dsp*
device nodes will
be created automatically as needed. When not in use, they
do not exist and will not appear in the output of
ls(1).
Connecting to a Bluetooth device is out of scope for this chapter. Refer to 節 31.5, “藍牙” for more information.
To get Bluetooth sound sink working with FreeBSD's sound system, users have to install audio/virtual_oss first:
#
pkg install virtual_oss
audio/virtual_oss requires
cuse
to be loaded into the kernel:
#
kldload cuse
To load cuse
during system startup, run
this command:
#
sysrc -f /boot/loader.conf cuse_load=yes
To use headphones as a sound sink with audio/virtual_oss, users need to create a virtual device after connecting to a Bluetooth audio device:
#
virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/
headphones
-d dsp
headphones
in this example is
a hostname from /etc/bluetooth/hosts
.
BT_ADDR
could be used instead.
請參考 virtual_oss(8) 取得更多資訊。
表格 7.1, “常見錯誤訊息” lists some common error messages and their solutions:
錯誤 | 解決方式 |
---|---|
sb_dspwr(XX) timed out | The I/O port is not set correctly. |
bad irq XX | The IRQ is set incorrectly. Make sure that the set IRQ and the sound IRQ are the same. |
xxx: gus pcm not attached, out of memory | There is not enough available memory to use the device. |
xxx: can't open /dev/dsp! | Type |
Modern graphics cards often come with their own sound
driver for use with HDMI. This sound
device is sometimes enumerated before the sound card meaning
that the sound card will not be used as the default playback
device. To check if this is the case, run
dmesg and look for
pcm
. The output looks something like
this:
...
hdac0: HDA Driver Revision: 20100226_0142
hdac1: HDA Driver Revision: 20100226_0142
hdac0: HDA Codec #0: NVidia (Unknown)
hdac0: HDA Codec #1: NVidia (Unknown)
hdac0: HDA Codec #2: NVidia (Unknown)
hdac0: HDA Codec #3: NVidia (Unknown)
pcm0: <HDA NVidia (Unknown) PCM #0 DisplayPort> at cad 0 nid 1 on hdac0
pcm1: <HDA NVidia (Unknown) PCM #0 DisplayPort> at cad 1 nid 1 on hdac0
pcm2: <HDA NVidia (Unknown) PCM #0 DisplayPort> at cad 2 nid 1 on hdac0
pcm3: <HDA NVidia (Unknown) PCM #0 DisplayPort> at cad 3 nid 1 on hdac0
hdac1: HDA Codec #2: Realtek ALC889
pcm4: <HDA Realtek ALC889 PCM #0 Analog> at cad 2 nid 1 on hdac1
pcm5: <HDA Realtek ALC889 PCM #1 Analog> at cad 2 nid 1 on hdac1
pcm6: <HDA Realtek ALC889 PCM #2 Digital> at cad 2 nid 1 on hdac1
pcm7: <HDA Realtek ALC889 PCM #3 Digital> at cad 2 nid 1 on hdac1
...
In this example, the graphics card
(NVidia
) has been enumerated before the
sound card (Realtek ALC889
). To use the
sound card as the default playback device, change
hw.snd.default_unit
to the unit that should
be used for playback:
#
sysctl hw.snd.default_unit=n
where n
is the number of the sound
device to use. In this example, it should be
4
. Make this change permanent by adding
the following line to
/etc/sysctl.conf
:
hw.snd.default_unit=4
It is often desirable to have multiple sources of sound that are able to play simultaneously. FreeBSD uses “Virtual Sound Channels” to multiplex the sound card's playback by mixing sound in the kernel.
Three sysctl(8) knobs are available for configuring virtual channels:
#
sysctl dev.pcm.0.play.vchans=4
#
sysctl dev.pcm.0.rec.vchans=4
#
sysctl hw.snd.maxautovchans=4
This example allocates four virtual channels, which is a
practical number for everyday use. Both
dev.pcm.0.play.vchans=4
and
dev.pcm.0.rec.vchans=4
are configurable
after a device has been attached and represent the number of
virtual channels pcm0
has for playback
and recording. Since the pcm
module can
be loaded independently of the hardware drivers,
hw.snd.maxautovchans
indicates how many
virtual channels will be given to an audio device when it is
attached. Refer to pcm(4) for more information.
The number of virtual channels for a device cannot be changed while it is in use. First, close any programs using the device, such as music players or sound daemons.
The correct pcm
device will
automatically be allocated transparently to a program that
requests /dev/dsp0
.
The default values for the different mixer channels are
hardcoded in the source code of the pcm(4) driver. While
sound card mixer levels can be changed using mixer(8) or
third-party applications and daemons, this is not a permanent
solution. To instead set default mixer values at the driver
level, define the appropriate values in
/boot/device.hints
, as seen in this
example:
hint.pcm.0.vol="50"
This will set the volume channel to a default value of
50
when the pcm(4) module is
loaded.
本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。
若有 FreeBSD 方面疑問,請先閱讀
FreeBSD 相關文件,如不能解決的話,再洽詢
<questions@FreeBSD.org>。
關於本文件的問題,請洽詢
<doc@FreeBSD.org>。