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. Check the supported audio devices list of the Hardware Notes to see if your card is supported. The Hardware Notes will also mention which driver supports your card.
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) which can either be done from the command line:
# kldload snd_emu10k1or by adding the appropriate line to the file
/boot/loader.conf like this:
These examples are for a Creative SoundBlaster® Live! sound
card. Other available loadable sound modules are listed in
/boot/defaults/loader.conf.
If you are not sure which driver to use, you may try to load
the snd_driver module:
# kldload snd_driverThis is a metadriver loading the most common device drivers
at once. This speeds up the search for the correct driver. It
is also possible to load all sound drivers via the
/boot/loader.conf facility.
If you wish to find out the driver selected for your
soundcard after loading the snd_driver
metadriver, you may check the /dev/sndstat
file with the cat /dev/sndstat
command.
A second method is to statically compile in support for your sound card in your kernel. The section below provides the information you need to add support for your hardware in this manner. For more information about recompiling your kernel, please see Chapter 9, Configuring the FreeBSD Kernel.
The first thing to do is add the audio framework driver sound(4) to the kernel; for that you will need to add the following line to the kernel configuration file:
Next, you have to add the support for your sound card. Therefore, you need to know which driver supports the card. Check the supported audio devices list of the Hardware Notes, to determine the correct driver for your sound card. For example, a Creative SoundBlaster® Live! sound card is supported by the snd_emu10k1(4) driver. To add the support for this card, use the following:
Be sure to read the manual page of the driver for the
syntax to use. The explicit syntax for the kernel
configuration of every supported sound driver can also be
found in the /usr/src/sys/conf/NOTES
file.
Non-PnP ISA sound cards may require you to provide the
kernel with information on the card settings (IRQ, I/O port,
etc), as is true of all non-PnP ISA cards. This is done via
the /boot/device.hints file. During the
boot process, 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. For this card the following
lines must be added to the kernel configuration file:
and these to
/boot/device.hints:
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(4) driver manual page and the manual page
for the driver in question.
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 about this 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:
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 are listed, go back and
review what was done earlier. Go through your kernel
configuration file again and make sure the correct
device driver was chosen. Common problems are listed in Section 8.2.2.1, “Common Problems”.
If all goes well, you should now have a functioning sound card. If your CD-ROM or DVD-ROM drive's audio-out pins are properly connected to your sound card, you can put a CD in the drive and play it with cdcontrol(1):
% cdcontrol -f /dev/acd0 play 1Various 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.
Another quick way to test the card is sending data
to /dev/dsp, like this:
% cat filename > /dev/dspwhere
can
be any file. This command line should produce some noise,
confirming the sound card is actually working.filename
The device nodes /dev/dsp* will be
created automatically when needed. If they are not used, they
do not exist and will not appear in the output of
ls(1).
Sound card mixer levels can be changed via the mixer(8) command. More details can be found in the mixer(8) manual page.
| Error | Solution |
|---|---|
| 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 |
Another issue is that modern graphics cards often come
with their own sound driver, for use with
HDMI and similar. This sound device will
sometimes be enumerated before the actual soundcard and the
soundcard will subsequently 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:
Here the graphics card (NVidia) has
been enumerated before the sound card (Realtek
ALC889). To use the sound card as default playback
device, change hw.snd.default_unit to the
unit that should be used for playback, enter the
following:
# sysctl hw.snd.default_unit=nHere, n is the number of the sound
device to use, in this example 4. You can
make this change permanent by adding the following line to
/etc/sysctl.conf:
4It 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 enabled with the sysctl(8) facility. Virtual channels allow you to multiplex your sound card's playback by mixing sound in the kernel.
To set the number of virtual channels, there are three
sysctl knobs which, if you are the root
user, can be set like this:
# sysctl dev.pcm.0.play.vchans=4
# sysctl dev.pcm.0.rec.vchans=4
# sysctl hw.snd.maxautovchans=4The above 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 the number of
virtual channels pcm0 has for playback
and recording, and are 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. Refer to pcm(4) manual page
for more information.
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.
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 sourcecode of the pcm(4) driver. There
are many different applications and daemons that allow
you to set values for the mixer that are remembered between
invocations, but this is not a clean solution. It is possible
to set default mixer values at the driver level — this
is accomplished by defining the appropriate values in
/boot/device.hints, e.g.:
This will set the volume channel to a default value of 50 when the pcm(4) module is loaded.
This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/
For questions about FreeBSD, read the
documentation before
contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.