16.2 Setting Up the Sound Card

Contributed by Moses Moore.

16.2.1 Locating the Correct Device

Before you begin, you should know the model of the card you have, the chip it uses, and whether it is a PCI or ISA card. FreeBSD supports a wide variety of both PCI and ISA cards. If you do not see your card in the following list, check the pcm(4) manual page. This is not a complete list; however, it does list some of the most common cards.

To use your sound device, you will need to load the proper device driver. This may be accomplished in one of two ways. The easiest way is to simply load a kernel module for your sound card with kldload(8). Alternatively, you may statically compile in support for your sound card in your kernel. The sections below provide the information you need to add support for your hardware in this manner. For more information about recompiling your kernel, please see Chapter 9.

16.2.1.1 Creative, Advance, and ESS Sound Cards

If you have one of the above cards, you will need to add:

device pcm

to your kernel configuration file. If you have a PnP ISA card, you will also need to add:

device sbc

For a non-PnP ISA card, add:

device pcm
device sbc0 at isa? port 0x220 irq 5 drq 1 flags 0x15

to your kernel configuration file. The settings shown above are the defaults. You may need to change the IRQ or the other settings to match your card. See the sbc(4) manual page for more information.

Note: The Sound Blaster Live is not supported under FreeBSD 4.0 without a patch, which this section will not cover. It is recommended that you update to the latest -STABLE before trying to use this card.

16.2.1.2 Gravis UltraSound Cards

For a PnP ISA card, you will need to add:

device pcm
device gusc

to your kernel configuration file. If you have a non-PnP ISA card, you will need to add:

device pcm
device gus0 at isa? port 0x220 irq 5 drq 1 flags 0x13

to your kernel configuration file. You may need to change the IRQ or the other settings to match your card. See the gusc(4) manual page for more information.

16.2.1.3 Crystal Sound Cards

For Crystal cards, you will need to add:

device pcm
device csa

to your kernel configuration file.

16.2.1.4 Generic Support

For PnP ISA or PCI cards, you will need to add:

device pcm

to your kernel configuration file. If you have a non-PnP ISA sound card that does not have a bridge driver, you will need to add:

device pcm0 at isa? irq 10 drq 1 flags 0x0

to your kernel configuration file. You may need to change the IRQ or the other settings to match your card.

16.2.1.5 Onboard Sound

Some systems with built-in motherboard sound devices may require the following option in your kernel configuration:

options PNPBIOS

16.2.2 Creating and Testing the Device Nodes

After you reboot, log in and check for the device in the /var/run/dmesg.boot file, as shown below:

# grep pcm /var/run/dmesg.boot
pcm0: <SB16 DSP 4.11> on sbc0

The output from your system may look different. If no pcm devices show up, something went wrong earlier. If that happens, go through your kernel configuration file again and make sure you chose the correct device. Common problems are listed in Section 16.2.2.1.

Note: If you are running FreeBSD 5.0 or later, you can safely skip the rest of this section. These versions use devfs(5) to automatically create devices nodes.

If the previous command returned pcm0, you will have to run the following as root:

# cd /dev
# sh MAKEDEV snd0

If the command returned pcm1, follow the same steps as shown above, replacing snd0 with snd1.

Note: The above commands will not create a /dev/snd device!

MAKEDEV will create a group of device nodes, including:

Device Description
/dev/audio Sparc® compatible audio device
/dev/dsp Digitized voice device
/dev/dspW Like /dev/dsp, but 16 bits per sample
/dev/midi Raw midi access device
/dev/mixer Control port mixer device
/dev/music Level 2 sequencer interface
/dev/sequencer Sequencer device
/dev/pss Programmable device interface

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/acd0c play 1

Various applications, such as audio/workman offer a better interface. You may want to install an application such as audio/mpg123 to listen to MP3 audio files.

16.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.

16.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.

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.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <[email protected]>.
For questions about this documentation, e-mail <[email protected]>.