Next Previous Contents

8. Playing audio files on UNIX.

The commands needed to play an audio file depend on the file format and the available hardware and software. Most systems can only directly play sound in their native format; use a conversion program to play other formats.

In general, UNIX systems that support audio will have a deviece that you can send RAW audio data to and it will be played. For those systems it is possible to use SOX to convert any sound file into the default format that the system excepts and send that data to the device.

For example:

sox soundfile.wav -t raw -r 8012 -u -b -c 1 | cat > /dev/audio

Later versions of SOX will now how to open several UNIX audio devices and play any audio format at the highest possible sound quality.

8.1 Sun Sparcstation running SunOS 4.x.

Raw u-law files can be played using "cat file >/dev/audio".

A whole package for dealing with ".au" files is provided by Sun on an experimental basis, in /usr/demo/SOUND. You may have to compile the programs first. (If you can't find this directory, either you are not running SunOS 4.1 yet, or your system administrator hasn't installed it -- go ask him for it, not me!) The program "play" in this directory recognizes all files in Sun/NeXT format. A strange thing Sun did is that most older Sparc hardware only play audio files using u-law encoding at 8 k -- newer hardware plays can play linear PCM data up to 44k but can't play u-law files.

If you can't find "play", you can also cat a ".au" file to /dev/audio, if it uses u-law; the header will sound like a short burst of noise but the rest of the data will sound OK (really, the only difference in this case between raw u-law and ".au" files is the header; the u-law data is exactly the same).

OpenWindows 3.0 has a full-fledged audio tool (called "audiotool"). You can drop audio file icons into it, edit them, etc.

Finally, current versions of SoX include the ability to convert and play sounds directly to the Sun /dev/audio device. It should include a script called "play" to do this.

8.2 Solaris.

Apparently, under older versions of Solaris, writing to /dev/audio from the shell is a bad idea, because the device driver will flush its queue as soon as the file is closed. Use "audioplay" instead or a newer version of Solaris. The supported formats and sampling rates are the same as above for SunOS.

Since Solaris uses the same hardware as SunOS, most all that applies to SunOS applies to Solaris as well. For example, Solaris also includes an AudioTool program. Also, as with SunOS you can use the Sox package to play files to /dev/audio.

8.3 NeXT

On NeXT machines, the standard "sndplay" program can play all NeXT format files (this include Sun ".au" files). It supports at least u-law at 8 k and 16 bits samples at 22 or 44.1 k. It attempts on-the-fly conversions for other formats.

Sound files are also played if you double-click on them in the file browser.

8.4 SGI Indigo, Indigo2, Indy and Personal IRIS.

On SGI Indigo, Indigo2, Indy and the 4D/30 and /35 Personal IRIS workstations, "WorkSpace" plays audio files in .aiff, .aifc, .au, and .wav formats if you double click them and the sampling rate is one of 8000, 11025, 16000, 22050, 32000, 44100, or 48000. On the Personal IRIS, you need to have the audio board installed (check the output from hinv) and you must run IRIX 3.3.2 or 4.0 or higher. These files can also be played with "soundfiler" and "sfplay". ".aiff" and ".aifc" files at the above sampling rates can also be played with playaifc. (All in /usr/sbin)

There is no simple /dev/audio interface on these SGI machines. (There was one on 4D/25 machines, reading and writing signed linear 8-bit samples at rates of 8, 16 and 32 k.)

A program "playulaw" was posted as part of the "radio 2.0" release. It plays raw u-law files on the Indigo, Indigo2, Indy or Personal IRIS audio hardware.

8.5 Linux

Linux has an entire document devoted to playing sound files that give much more detail than this document can provide. It can be obtained from Sunsite's Linux HOWTO directory.

The quickest way to play all sound files under Linux is to install Sox as it includes support for playing directly to Linux's /dev/dsp device.

8.6 Others.

Most other UNIX boxes don't have audio hardware and thus can't play audio data. This is actually rapidly changing and most new hardware that hits the market has some form of audio support. Unfortunately there is no single portable interface for audio that comes near the acceptance and functionality (let alone code size :-) of X11 for graphics. There are at least two network-transparent packages, both in some way based on the X11 architecture, that attempt to fill the gap:

DEC CRL's AudioFile supports Digital RISC systems running Ultrix, Digital Alpha AXP systems running OSF/1, Sun Sparcs, and SGI AL-capable systems (e.g., Indigo, Indy). The source kit is located at ftp site in /pub/DEC/AF.

NCD's NetAudio supports NCD's MCX line of X terminals as well as Sparcs running either SunOS 4.1.3 or Solaris 2.2, using the /dev/audio interface (they claim it should be easy to port). The source it located at in contrib/netaudio. It is also ported to SGI (tested on IRIX 5.x), and there are unconfirmed rumors that it is being ported to SCI and Linux.

Next Previous Contents