7.2 設定音效卡

Contributed by Moses Moore. 加強 FreeBSD 5.X 的內容:Marc Fonvieille.

7.2.1 設定系統

開始設定之前,必須先知道你的音效卡型號、晶片為何,以及是 PCI 或 ISA 規格。 FreeBSD 有支援許多種的 PCI、ISA 音效卡,請檢查支援的音效硬體表 Hardware Notes, 以確認你的音效卡是否支援。 本文也會提到相對應該卡的驅動程式。

要使用音效卡,必須要載入正確的驅動程式才行。 有兩種方式都可以完成這動作,最簡單方式就是以 kldload(8) 來輕鬆載入 kernel 動態模組(module),像是下列指令:

# kldload snd_emu10k1

或者把相關驅動程式加到 /boot/loader.conf 檔,像是:

snd_emu10k1_load="YES"

上面例子是給 Creative SoundBlaster® Live! 音效卡使用的。 其他可用的音效卡驅動程式模組,可參考 /boot/defaults/loader.conf 範例。 若不確定到底該用哪一種驅動程式,那麼可以試試載入 snd_driver 模組看看:

# kldload snd_driver

這個組合程式會載入常用的許多音效卡驅動程式。 這將可以縮短找尋正確驅動程式的時間。當然,也可以直接透過 /boot/loader.conf 載入所有的音效卡驅動程式。

如果您想在載入 snd_driver 後找出 屬於您音效卡的驅動程式,您可以查看利用 cat /dev/sndstat 來 查看 /dev/sndstat 內容。

第二種方式是編譯核心,將對音效卡的支援編入核心。 在下面的章節中將會介紹如何操作。關於重新編譯核心, 請參考 Chapter 8

7.2.1.1 設定支援音效卡的核心

首先,將通用音效卡驅動程式 sound(4) 增加到核心,您 需要在核心設定檔中增加下面這一行:

device sound

接著,我們需要讓核心支援我們的音效卡。 因此,我們需要知道哪一個驅動程式支援我們的音效卡。 查看音效卡支援清單 Hardware Notes, 找出正確的驅動程式。例如,Creative SoundBlaster Live! 這張音效卡 的驅動程式為 snd_emu10k1(4)。要新增此張卡的支援,需要在 核心設定檔中加入這一行:

device snd_emu10k1

Be sure to read the manual page of the driver for the syntax to use. Information regarding the syntax of sound drivers in the kernel configuration can also be found in the /usr/src/sys/conf/NOTES file.

Non-PnP ISA cards may require you to provide the kernel with information on the sound card settings (IRQ, I/O port, etc). This is done via the /boot/device.hints file. At system boot, the loader(8) will read this file and pass 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(4). For this card the following lines have to be added to the kernel configuration file:

device snd_sbc
device snd_sb16

as well as the following in /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"

In this case, the card uses the 0x220 I/O port and the IRQ 5.

The syntax used in the /boot/device.hints file is covered in the sound driver manual page. On FreeBSD 4.X, these settings are directly written in the kernel configuration file. In the case of our ISA card.

The settings shown above are the defaults. In some cases, you may need to change the IRQ or the other settings to match your card. See the snd_sbc(4) manual page for more information.

7.2.2 Testing the Sound Card

After rebooting with the modified kernel, or after loading the required module, the sound card should appear in your system message buffer (dmesg(8)) as something like:

pcm0: <Intel ICH3 (82801CA)> port 0xdc80-0xdcbf,0xd800-0xd8ff irq 5 at device 31.5 on pci0
pcm0: [GIANT-LOCKED]
pcm0: <Cirrus Logic CS4205 AC97 Codec>

The status of the sound card may be checked via the /dev/sndstat file:

# cat /dev/sndstat
FreeBSD Audio Driver (newpcm)
Installed devices:
pcm0: <Intel ICH3 (82801CA)> at io 0xd800, 0xdc80 irq 5 bufsz 16384
kld snd_ich (1p/2r/0v channels duplex default)

The output from your system may vary. If no pcm devices show up, go back and review what was done earlier. Go through your kernel configuration file again and make sure the correct device is chosen. Common problems are listed in Section 7.2.2.1.

If all goes well, you should now have a functioning sound card. If your CD-ROM or DVD-ROM drive is properly coupled to your sound card, you can put a CD in the drive and play it with cdcontrol(1):

% cdcontrol -f /dev/acd0 play 1

Various applications, such as audio/workman can provide a friendlier interface. You may want to install an application such as audio/mpg123 to listen to MP3 audio files. A quick way to test the card is sending data to the /dev/dsp, like this:

% cat filename > /dev/dsp

where filename can be any file. This command line should produce some noise, confirming the sound card is actually working.

Sound card mixer levels can be changed via the mixer(8) command. More details can be found in the mixer(8) manual page.

7.2.2.1 Common Problems

Error Solution
unsupported subdevice XX

One or more of the device nodes was not created correctly. Repeat the steps above.

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!

Check with fstat | grep dsp if another application is holding the device open. Noteworthy troublemakers are esound and KDE's sound support.

7.2.3 Utilizing Multiple Sound Sources

Contributed by Munish Chopra.

It is often desirable to have multiple sources of sound that are able to play simultaneously, such as when esound or artsd do not support sharing of the sound device with a certain application.

FreeBSD lets you do this through Virtual Sound Channels, which can be set with the sysctl(8) facility. Virtual channels allow you to multiplex your sound card's playback channels by mixing sound in the kernel.

To set the number of virtual channels, there are two sysctl knobs which, if you are the root user, can be set like this:

# sysctl hw.snd.pcm0.vchans=4
# sysctl hw.snd.maxautovchans=4

The above example allocates four virtual channels, which is a practical number for everyday use. hw.snd.pcm0.vchans is the number of virtual channels pcm0 has, and is configurable once a device has been attached. hw.snd.maxautovchans is the number of virtual channels a new audio device is given when it is attached using kldload(8). Since the pcm module can be loaded independently of the hardware drivers, hw.snd.maxautovchans can store how many virtual channels any devices which are attached later will be given.

Note: You cannot change the number of virtual channels for a device while it is in use. First close any programs using the device, such as music players or sound daemons.

If you are not using devfs(5), you will have to point your applications at /dev/dsp0.x, where x is 0 to 3 if hw.snd.pcm.0.vchans is set to 4 as in the above example. On a system using devfs(5), the above will automatically be allocated transparently to the user.

7.2.4 設定預設(Mixer Channel)的音量大小

Contributed by Josef El-Rayes.

The default values for the different mixer channels are hardcoded in the sourcecode of the pcm(4) driver. There are a lot of different applications and daemons that allow you to set values for the mixer they remember and set each time they are started, but this is not a clean solution, we want to have default values at the driver level. This is accomplished by defining the appropriate values in /boot/device.hints. E.g.:

hint.pcm.0.vol="100"

This will set the volume channel to a default value of 100, when the pcm(4) module is loaded.

本文及其他文件,可由此下載:ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/

若有 FreeBSD 方面疑問,請先閱讀 FreeBSD 相關文件,如不能解決的話,再洽詢 <questions@FreeBSD.org>。
關於本文件的問題,請洽詢 <doc@FreeBSD.org>。