16.2 Setting Up The Sound Card Contributed by Moses Moore, edited by Orion Hodson, . 16.2.1 Audio driver overview FreeBSD supports a variety of PCI, ISA, and USB audio devices for pcm audio playback and recording. Audio device drivers are responsible for communicating with the audio hardware works with the kernel pcm code to provide a largely OSS compatible interface. In order to use audio hardware an audio device driver needs to be loaded or compiled into the kernel and the appropriate device entries made. This section of the handbook describes the supported hardware and the operations required to make it work under FreeBSD. It also provides useful tips, answers to common problems, and contact information for when problems arise. 16.2.2 Supported Devices 16.2.2.1 Supported PCI devices Device name Supported in kernel Loadable module Acer Labs M5451 yes snd_t4dwave.ko Avance Logic ALS4000 yes snd_als4000.ko C-Media cmi8338/cmi8738 yes snd_cmi.ko Crystal CS4281 yes snd_cs4281.ko Crystal CS461x/CS2480 yes (Note 1) snd_csa.ko Creative SBLive! yes snd_emu10k1.ko Creative SB PCI (CT5880) yes snd_es137x.ko Ensoniq AudioPCI ES137x yes snd_es137x.ko ESS Maestro 1/2/2E yes snd_maestro.ko ESS Maestro 3 no snd_maestro3.ko ESS Solo 1/1E yes snd_solo.ko Fortemedia FM801 yes snd_fm801.ko Intel ICH/ICH2/ICH2 yes snd_ich.ko (Note 2) Intel ICH4 yes (Note 3) snd_ich.ko (Note 2) Neomagic 256AV/256XZ yes snd_neomagic.ko S3 Sonicvibes yes snd_vibes.ko Sis 7018 yes snd_t4dwave.ko Trident 4DWave DX/NX yes snd_t4dwave.ko VIA VT8233 yes snd_vt8233.ko (Note 2, 3) VIA VT82c686 yes snd_vt8233.ko (Note 2) Yamaha DS-1 yes snd_ds1.ko Note 1: In kernel configuration requires 'device csa' in addition to 'device pcm'. Note 2: Integrated audio controllers, like the Intel ICH audio controllers and VIA VT82c686, may not be loadable as kernel modules from the command line. They are loadable at boot time. Note 3: Available from 4.7R onwards. 16.2.2.2 Loading PCI audio drivers There are three ways to load PCI audio drivers: 1. Create a kernel config file containing: device pcm and compile and install the corresponding kernel. Then reboot. 2. Load the kernel module from the command line. kldload where is the appropriate module name from the table above. 3. Edit /boot/loader.conf to enable automatic loading of the driver at boot time. The file /boot/defaults/loader.conf contains the appropriate variable that needs setting. The variable name is derived from the kernel module name, ie for the ICH audio driver the module is snd_ich.ko and the /boot/loader.conf to be set is: snd_ich_load="YES" After loading the audio driver, the appropriate device nodes needs to be created. See section below. 16.2.2.3 Supported ISA devices Device type Supported in kernel Analog Devices AD1816 yes ESS ES18xx yes Gravis Ultrasound PnP yes Microsoft MSS cards yes Analog Devices AD1848 Aztech AZT2320 C-Media CMI8330 Crystal CS423x Ensoniq Soundscape VIVO Neomagic 256AV OPTi924/925/931 Yamaha OPL3-SA2/OPL3-SA3/OPL3-SAx Soundblaster SB16/32/AWE64/ViBRA16 yes Avance Asound 100, 110, 120 yes ESS ES1868/ES1869/ES1879/ES1888 yes 16.2.2.4 Loading ISA audio drivers The easiest way to load ISA driver is to compile a kernel with the appropriate device settings. 16.2.2.4.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. 16.2.2.4.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.2.4.3 Crystal Sound Cards For Crystal cards, you will need to add: device pcm device csa to your kernel configuration file. 16.2.2.4.4 Generic Support For PnP ISA, 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.2.5 USB audio devices USB audio devices are a new feature as of FreeBSD 4.7R. To enable a USB audio device load the snd_uaudio.ko kernel module using kldload: % kldload snd_uaudio.ko then plug the USB audio device into a USB port. The first time the device is attached the audio device nodes need to be made. Warning: At the time of writing (FreeBSD 4.7R), unplugging a USB audio device may cause the machine to panic. 16.2.2.6 Creating and Testing the Device Nodes After rebooting or loading the appropriate kernel module, you need to check the driver has been able to attach and then build the appropriate device entries. To see if the driver managed to attach type: # dmesg | grep pcm pcm0: 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. 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 8-bit mu-law pcm audio device /dev/dsp 8-bit linear pcm audio device /dev/dspW 16-bit linear pcm audio device /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 soundcard, you can put a CD in the drive and play it with cdcontrol(1). % cdcontrol -f /dev/acd0c play 1 A very simple test of pcm audio is: % dd if=/dev/urandom of=/dev/audio count=10 which should produce a short blast of noise. If you do not hear anything try adjusting the volume settings with the mixer program. 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.7 Common Problems If a resource problem is reported when the driver attaches, check whether the bios on the offending machine an option "PnP OS", if so set it to "no". If this option does not exist, try compiling a kernel with the following option: options PCI_ENABLE_IO_MODES For some audio controllers integrated on the motherboard the following kernel option is required. options PNPBIOS 16.2.X Understanding particular error messages 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. 16.2.X Reporting Problems Configuration problems should be reported on using gnats and addressed to "sound". The freebsd-multimedia@freebsd.org is a mailing list for people interested in multimedia and people on that list may have an idea of whether hardware works and/or issues with a particular piece of hardare. When reporting a problem please include: a description of the system and the problem. the output of 'dmesg', preferably following a verbose boot. the output of 'pciconf -l' if the card is pci based. the output of 'cat /dev/sndstat' any diagnostic messages that have appeared on the console. 16.2.X Contributing There are many soundcards and often several variants of each soundcard. Supporting these is difficult at the best of times. The sound developers welcome patches, particularly if you fix a problem, such as an unsupported card or card revision. If you need development help regarding sound and you've already read the developers handbook section on sound, then contact the sound developers at sound@freebsd.org.