Chapter 17. Audio

Table of Contents
17.1. Basic hardware elements
17.2. BIOS settings
17.3. Configuring the audio device
17.4. Configuring the kernel audio devices
17.5. Advanced commands

Contributed by Manolo De Santis

This chapter is a short introduction to the usage of audio devices on NetBSD (who wants a dumb computer, anyway?)

17.1. Basic hardware elements

In order to make audio work on your system you must know what audio card is installed. Sadly it often not enough to know the brand and model of the card, because many cards use chipsets manufactured from third parties. Therefore knowing the chipset installed on the audio card can sometimes be useful. The NetBSD kernel can recognize many chipsets and a quick look at dmesg is enough most of the times.

Therefore, write the following command:

# dmesg | more    

and look for the audio card and chipset. If you're lucky you don't need to do anything because NetBSD automatically detects and configures many audio cards.

Sometimes audio doesn't work because the card is not supported or because you need to do some work in order for the card to be detected by NetBSD. Many audio cards are nowadays very cheap, and it is worth considering buying a different card, but before doing this you can try some simple steps to make the card work with NetBSD.

17.2. BIOS settings

This section is useful only to the owners of i386 PCs; on other architectures (eg. Amiga) there are no such features. The most important thing to determine in order to use the audio card with NetBSD is the type of bus supported by the card.

The most common interfaces are ISA and PCI.

ISA cards are usually more tricky to configure mostly because of the interaction with the BIOS of the computer.

On the newer machines (those produced after 1997) there is a BIOS option which causes many headaches for the configuration of ISA audio cards (but not only audio cards): this option is usually named "PNP OS Installed" and is commonly found in the "PNP/PCI Configuration" (the names can be different in your BIOS.) As a general rule it is usually better to disable (i.e. set it to "NO") this option for NetBSD.

Note: on many systems everything works fine even if this option is enabled. This is highly system dependent.

17.3. Configuring the audio device

During the installation of NetBSD the devices are created in the dev directory. We are primarily interested in:

/dev/audio
/dev/sound
/dev/mixer
    

If they are not present they can be created like this:

# cd /dev
# ./MAKEDEV all
    

This command creates all the devices, including the audio devices.

The audio card is now probably ready to be used without further work.

You can make a quick test and send an audio file to the device (audio files usually have the .au extension), but if you don't have an audio file you can just send a text or binary file (of course you won't hear anything useful...). Use /dev/audio or /dev/sound:

# cat filename > /dev/audio    

or

# cat filename > /dev/sound    

If you hear something it means that the card is supported by NetBSD and was recognized and configured by the kernel at boot, otherwise you must configure the kernel settings for the audio device installed on the system (assuming the card/chipset is supported.)

17.4. Configuring the kernel audio devices

NetBSD supports a wide range of audio cards and the GENERIC kernel already enables and configures most of them.

Many PCs don't have a sound card but an integrated audio chipset; this means that the chipset is installed on the motherboard. These are not enabled in the GENERIC kernel and you'll have to compile a custom kernel in order to use them. Look for the following (or similar) lines in the GENERIC file:

# Plug-and-Play BIOS and attached devices
 
#pnpbios*       at mainbus?
  
# mainboard audio chips 
#ess*           at pnpbios? index ?     # ESS AudioDrive
#sb*            at pnpbios? index ?     # NeoMagic 256AV in sb mode
#wss*           at pnpbios? index ?     # NeoMagic 256AV in wss mode
#ym*            at pnpbios? index ?     # OPL3-SA3    

Uncomment the "pnpbios" line and the line which describes the device on you motherboard.

Note: when you create a custom kernel it is better to work on a copy of the GENERIC file, as described in Chapter 7.

Sometimes it is necessary to setup manually the IRQ and DMA for the device.

If you still have problems you can try enabling all the devices, because some audio cards can be made to work only by emulating another card.

Many chipset make use of the SoundBlaster and OPL compatibility, but a great number of them work with the WSS emulation.

OPL is a MIDI synthetizer produced by Yamaha; there are many OPL variants (eg. OPL2, OPL3SA, OPL3SA2, etc.). Many audio cards rely on this component or on a compatible one. For example, the chips produced by Crystal (and amongst them the very common CS423x) all have this chipset, and that's why they work with NetBSD.

WSS is not a microchip; it is the acronym of Windows Sound System. Wss is the name of the NetBSD kernel driver which supports the audio system of Microsoft Windows. Many audio cards work with Windows because they adhere to this standard (WSS) and the same holds for NetBSD.

Of the many audio cards that I tested with NetBSD, a good number works only if opl* and wss* are enabled in the kernel.

You should have no problem to get the Creative SoundBlaster cards to work with NetBSD: almost all of them are supported, including the Sound Blaster Live 1024!

When everything works you can disable in the kernel configuration file the devices that you don't need.

17.5. Advanced commands

NetBSD comes with a number of commands that deal with audio devices. They are:

17.5.1. audioctl

Audioctl made its appearance in NetBSD 1.3 and is used to manually set some variables regarding audio I/O, like the frequencies for playing and recording. The available parameters can be displayed with the following command:

# audioctl -a | more      

For example, to listen to CD quality music you can use the following command.

# audioctl -w play=44100,2,16,slinear_le      

This command sets the frequence to 44100Hz, 2 audio channels, 16 bit, slinear_le encoding.

You can see the supported encodings with:

# audioctl encodings      

This command displays the list of all the encodings supported by the audio card on your system.

17.5.2. mixerctl

This command is used to configure the audio mixing and has an interface similar to that of audioctl.

17.5.3. audioplay

With this command you can play audio files. For more sophisticated needs you might want to install one of the many programs available in the package system which let you play audio files in different formats (eg. MP3, etc.)

17.5.4. audiorecord

Not unsurprisingly this command is used to record audio files.