return to first page linux journal archive
keywordscontents

Sound Through the PC-Speaker

Here's how to get sound to your speakers using a driver instead of a sound card.

by Paul Dunne

Linux supports most of the popular sound cards. If you don't have a sound card, you can still get a degree of sound support from the humble speaker that came with your PC. In this article, I will discuss one way of obtaining sound output without a sound card.

What PC-Speaker Is

PC-Speaker is a driver for the modest sound output device that comes standard with most (perhaps all?) IBM PC clones. It is installed as part of the kernel or as a loadable module; either way, the kernel needs to be changed. PC-Speaker comes with a small set of programs to use with it--I have compiled these programs on my system without trouble.

Modifying the Kernel

The driver comes as a patch file, which must be applied to the Linux source directory (/usr/src/linux). When make<\!s>config is run after applying the patch, it will ask whether you want PC-Speaker support--answer ``yes''. Give the commands:

make depend; make clean; make zImage
and your new kernel will be ready. The patches to the source include some header files for /usr/include/sys, which are necessary to make the utilities that accompany the driver.

Devices

The driver supports the following devices :

  1. /dev/pcsp: The raw data device
  2. /dev/pcaudio: The SUN-audio device
  3. /dev/pcmixer: The mixer-device

I have /dev/pcsp only defined on my machine:

crw--w--w-	1 root	root	13,	3 Aug 27 20:25	/dev/pcsp

pcsel

The program pcsel sets options for PC-Speaker and is used to configure the /dev/pcsp device at system startup and to test new devices. You can also assign an output device to /dev/pcsp using the pcsel program. The supported output devices are:

Listing 1. Help Output from pcsel

Specifying the help option on the pcsel command line:

$ pcsel -help
gives you a listing of all the pcsel options and what they mean. With no options specified, pcsel reports the actual output-device and its parameters in this way:

$ pcsel
PCSP driver version 1.0
Actual PCSP output device: PC-Speaker
Volume : 100 %, real samplerate : 18356 Hz
Maximum Samplerate is 51877 Hz
16bit Stereo Emulation enabled

vplay and vrec

These two programs, vplay and vrec, can be used for recording and playing the following types of files:

  1. Creative Labs voice files
  2. Microsoft wave files
  3. raw audio data files

Both programs accept the same options, which can be listed by specifying the help option:

vplay --help
The output of this command is shown in Listing 2.

Applications

Okay, confession time--the main reason I had for adding this driver to my kernel was to have sound effects in Doom. Here is another trivial example of what you can do with PC-Speaker. I have a directory of .wav and .au files. This shell script, called from my .profile file, plays one of these audio files at random each time I log in.

#!/bin/sh
# random-sound.sh: play a random file from the 
# sounds directory
export count="`ls sounds/*|wc -l|sed s/ //`"
export count=`expr $count + 0'
(1>/dev/null 2>&1 vplay `echo sounds/*| \
awk BEGIN{srand()}{x=1+int(rand()*number)
print $x} number=$count') &

Where to Get It

The latest version of PC-Speaker can be found at ftp://ftp.informatik.hu-berlin.de/, in the directory /pub/os/linux/hu-sound/pcsnd* (where * represents the latest version number).

Conclusion

PC-Speaker is a neat bit of software that makes good use of the basic speaker. Be warned--you will get plenty of interference if your computer is digitally noisy. It is unlikely to become part of the standard kernel; the author, Michael Beck (beck@dgroup.de), tells me that one of the reasons is that the driver interferes with the Linux clock. I haven't noticed this myself, but my clock is re-synched with my ISP's clock four times a day. The distribution comes with a file that describes how to build your own sound output devices. For example, using these instructions you can connect your PC to your amplifier.

Paul Dunne is a free-lance writer and consultant who specializes in Linux. His first book, Linux for Webmasters, is due to be published by Digital Press later this year.

  Previous    Next