Linux India
Home » Linux Magazine » Linux Sound Support

Linux Sound Support

Jeff Tranter

Issue #4, August 1994

Multimedia has received a lot of attention in the computer industry recently. Unix systems traditionally have not provided much support for multimedia in general, and sound in particular, except for some expensive professional systems. Workstation vendors are now scrambling to introduce multimedia-ready systems.

With the availability of Linux and low-cost sound hardware for Intel-based PCs, a sound-capable Unix system is within the reach of most computer hobbyists.

Possibly because sound support was lacking in Unix systems, many new users are confused by the technical jargon specific to sound and electronic music, and the many sound cards available. This article will to explain what can be done with sound under Linux, unravel some of the technical terms, and point the reader to sources of more information.

What can a Sound Card do?

The typical sound card hardware provides the capability for one or more of the following functions:

  • playing and recording digitized sound samples
  • playing music from an audio Compact Disc in a CD-ROM drive
  • generating sounds using an internal FM synthesizer
  • controlling external MIDI (Musical Instrument Digital Interface) devices
  • miscellaneous functions, such as providing a joystick interface, SCSI disk interface, volume and tone controls, and facilities for mixing of inputs

Different Types of Sound Cards

For digitized sounds, there are two basic parameters that determine the sound quality: sampling rate and sample size.

The sampling rate is the speed at which the analog waveform is converted to digital “samples”. This is expressed in samples per second, or more often (and less accurately), Hertz. The sample size indicates the number of data bits which are stored for each sample; the more bits, the more accurately the sample represents the original waveform. Sounds can also be recorded with one channel (mono) or two channels (stereo). Various coding schemes are used to represent the sample as a numerical value.

As an example, a low-cost sound card can produce single channel, 8-bit samples at 8000 samples per second. This provides sound quality comparable to the telephone network. A 16-bit sound card producing stereo sound at 44100 samples/second is equivalent to Compact Disc audio quality (ignoring issues such as noise and distortion).

Some sound cards also provide hardware for producing sounds using FM synthesis. This technique is based on modifying sine waves. The advantage of this scheme is that the hardware is reasonably simple and not much computing power is required. The disadvantage is that it is difficult to determine the parameters needed to produce specific sounds (e.g., a piano).

Sound cards also typically provide other miscellaneous features, including joystick ports, CD-ROM interface, SCSI interface, MIDI port, facilities for sound input and output, and volume and tone controls.

Supported Sound Cards

The Linux kernel currently supports the following sound cards:

  • Roland MPU-401 MIDI interface
  • AdLib
  • SoundBlaster and compatibles (including ThunderBoard and Ati Stereo F/X)
  • SoundBlaster Pro
  • SoundBlaster 16
  • ProAudioSpectrum 16
  • Gravis UltraSound

The Linux kernel also supports the SCSI port provided on some sound cards (e.g., ProAudioSpectrum 16) and the CD-ROM interface provided on the Soundblaster Pro and SoundBlaster 16.

For those who do not (yet) have sound hardware, there are a couple of other options. With a little hardware, a sound interface can be built using the parallel printer port. For a zero-cost solution, there is even a sound driver for the internal speaker of your PC. The driver is compatible with the sound card driver, but the quality may leave something to be desired.

Configuring Linux for Sound

Setting up Linux to support a sound card involves the following steps:

  1. installing the sound card
  2. configuring and building the kernel with the sound drivers
  3. creating the sound device files
  4. testing the installation

The first requirement, if you have not already done so, is to install the sound card. Follow the instructions provided by the manufacturer. Be sure to note down the jumper settings for IRQ, DMA channel, and so on; if you are unsure, use the factory defaults. Try to avoid conflicts with other devices (e.g., Ethernet cards) if possible. You will also need speakers, and a microphone if you want to do any recording. A math co-processor is also useful for some sound applications (e.g., changing file formats, adding effects or speech synthesis), but not necessary.

The next step is to configure the Linux kernel. If you are using a recent version (0.99 patch level 14 or later), the sound drivers are included with the kernel release. Follow your usual procedure for building the kernel. When you configure the kernel, enable the sound driver, and answer the questions about sound card settings when prompted by the configure program.

Once the kernel is configured, you need to create the sound device files. The easiest way to do this is to cut the short shell script from the end of the file /usr/src/linux/drivers/sound/Readme.linux, and run it as root. These are the files that will be created:

  • /dev/audio- Sun workstation compatible audio device (read/write)
  • /dev/dsp- digital sampling device (read/write)
  • /dev/mixer- sound mixer
  • /dev/sequencer- MIDI, FM, and GUS synthesizer access
  • /dev/midi- MIDI device (not yet implemented in current sound driver)
  • /dev/sndstat- displays sound driver status when read
  • /dev/audio1- for second sound card
  • /dev/dsp1- for second sound card

If you are using the PC speaker sound driver, then it will use the following devices:

  • /dev/pcaudio- equivalent to /dev/audio
  • /dev/pcsp- equivalent to /dev/dsp
  • /dev/pcmixer- equivalent to /dev/mixer

Now that the kernel is configured and the device files created, you can verify the sound hardware and software. Follow your usual procedure for installing and rebooting the new kernel. (Keep the old kernel around in case of problems, of course.) Verify that sound card is recognized during kernel initialization. You should see a message such as the following on powerup:

snd2 <SoundBlaster Pro 3.2> at 0x220 irq 5 drq 1
snd1 <Yamaha OPL-3 FM> at 0x388 irq 0 drq 0

This should match your sound card type and jumper settings. The driver may also display some error messages and warnings during boot up. Watch for these when booting the first time after configuring the sound driver.

If no sound card is detected when booting, there are a couple of possible reasons. The configuration of the driver could be incorrect and the driver was not able to detect your card in the given I/O address. Another common error is not having the sound driver in the kernel, because you booted with an old kernel instead of the one that was just compiled.

Reading the sound driver status device file provides additional information on whether the sound card driver initialized properly. Sample output should look something like this:

% cat /dev/sndstat
Sound Driver:2.4 (Sun Feb 13 14:49:20 EST 1994 root@fizzbin.mitel.com)
Config options: 1aa2
HW config:
Type 2: SoundBlaster at 0x220 irq 5 drq 1
Type 1: AdLib at 0x388 irq 0 drq 0
PCM devices:
0: SoundBlaster Pro 3.2
Synth devices:
0: Yamaha OPL-3
Midi devices:
0: SoundBlaster
Mixer(s) installed

If the cat command displays “No such device”, then the sound driver is not active in the kernel. If the printout contains no devices (PCM, Synth or Midi), then your sound card was not detected. Verify that you entered the correct information when configuring the sound driver.

Now you should be ready to play a sample sound file, and send it to the sound device as a basic check of sound output, for example,

% cat endoftheworld >/dev/dsp
% cat crash.au >/dev/audio

Some sample sound files can be obtained from the file snd-data-0.1.tar.Z, available on many Linux archive sites.

If you have sound input capability, you can do a quick test of this using commands such as the following:

# record 4 seconds of audio from microphone
% dd bs=8k count=4 </dev/audio >sample.au
# play back sound
% cat sample.au >/dev/audio

If these tests pass, you can be reasonably confident that the sound hardware and software are working. If you experience problems, consult one of the references listed at the end of this article.

More on Music

When it comes to playing music, there are several methods that can be used.

First, don’t plan on digitizing a 60 minute music CD as a sound file and storing it on your hard disk. Some simple calculations show the size of the data involved:

     60 minutes
  x 60 secs/minute
  x 44100 samples/second
  x 2 channels
  x 2 bytes/sample
  = more than 635 million bytes!

Small sound samples at low sampling rates are reasonable though:

    10 seconds
  x 8000 samples/second
  x 1 channel
  x 1 byte/sample
  = 80 thousand bytes

A more compact method of storing music is MOD files. These originated with the Amiga computer, but MOD file editors and players are now available on other systems as well, including Linux. MOD files essentially store a bank of short samples (instruments), and sequencing information (musical notes). These files are of the order of 30K to 300K bytes in size and can represent several minutes of music (i.e. a complete song).

MIDI stands for Musical Instrument Digital Interface, and as the name suggests, is a standard hardware and software protocol for allowing electronic musical instruments to communicate. MIDI files describe songs in terms of keypress events, and can be played using either an internal FM synthesizer on the sound card, or external MIDI devices.

Another, less common, file format is Adagio files. Adagio is a music description language developed at Carnegie Mellon University. Programs to play Adagio files, and convert between Adagio and MIDI files are available.

Games

We can’t forget another important application for sound—games! Several graphical games supporting sound run under Linux, including Bdash and Xboing.

Sound Tools and Utilities

To make use of the sound support in the Linux kernel, applications are needed. Several of the important ones are Sox (a utility for converting sound files from one format to another and adding effects), and tracker (a MOD file player). Some graphical programs that run under X are available as well, including xmix (a sound mixer), xplay (a sound player/recorder), and xmp (a MIDI file player).

There are many others, including some interesting applications such as speech synthesis.

The Future

Now it’s time for me to get up on my soapbox. Sound support in Linux is quite new, and application support is not as complete as for some other operating systems. I envision seeing a complete set of sound tools, that would provide a consistent, graphical user interface for all of the common sound functions. This would help bring Linux to the forefront of multimedia operating systems. Some of the tools that need to be developed are:

  • sound player/recorder tool
  • file conversion utility
  • audio mixer
  • MOD file player
  • MOD file editor
  • MIDI file player and sequencer
  • FM synthesizer patch editor
  • text to speech synthesizer (how about support for a /dev/speak device?)
  • an X window manager supporting sound

Many of these already exist in various forms, and just need more development to be more reliable and consistent. Any volunteers?

An interesting side note is that the author of the Linux sound drivers, Hannu Savolainen, is porting them to other Intel operating systems as well. The package has been dubbed VoxWare, and should make it easier to write sound applications that are portable across several operating systems.

Sources of more information

The Linux Sound-HOWTO document provides more information on the topics discussed in this article and provides other references. Look for it on your local Linux archive site.

If you have access to the Internet, the following FAQs (Frequently Asked Question documents) are regularly posted to the usenet newsgroup news.announce as well as being archived at the site rtfm.mit.edu in the directory /pub/usenet/news.answers:

PCsoundcards/generic-faq (Generic PC Soundcard FAQ)

PCsoundcards/soundcard-faq (comp.sys.ibm.pc.soundcard FAQ)

PCsoundcards/gravis-ultrasound/faq (Gravis Ultrasound FAQ)

audio-fmts/part1,part2 (Audio file format descriptions)

These FAQs also list several product specific mailing lists and archive sites. The following Usenet news groups discuss sound and/or music related issues:

alt.binaries.sounds.misc (Digitized sounds and software)

alt.binaries.sounds.d (Discussion and follow-up group)

alt.binaries.multimedia (Multimedia sounds and software)

alt.sb.programmer (SoundBlaster programming topics)

comp.multimedia (Multimedia topics)

comp.music (Computer music theory and research)

If you have Internet mail access, then you can subscribe to the SOUND channel of the Linux Activists mailing list. To find out how to join the mailing list, send mail to linux-activists-request@joker.cs.hut.fi.

The Readme files included with the kernel sound driver source code contain useful information about the sound card drivers. These can typically be found in the directory /usr/src/linux/drivers/sound.

The Linux Software Map (LSM) is an invaluable reference for locating Linux software. Searching the LSM for keywords such as “sound” is a good way to identify applications related to sound hardware. The LSM can be found on various anonymous FTP sites, including sunsite.unc.edu in the file /pub/Linux/docs/LSM.gz.

Note that at the time this article was written, the sound driver was at version 2.4, and was included as part of the Linux kernel version 0.99 patch level 15 (and is probably ancient history by the time you read this).

Jeff Tranter (Jeff_Tranter@mitel.com) is a software designer for a high-tech telecommunications company in Kanata, Canada. He is the author of the Linux Sound HOWTO.