Home » Linux Magazine » Sound Through the PC-Speaker

Sound Through the PC-Speaker

Paul Dunne

Issue #43, November 1997

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

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:

  • Stereo-on-One (designed by Mark J. Cox), which is auto-detected during kernel startup and selected by default.
  • PC-Speaker, which is selected if Stereo-on-One was not found.
  • Mono DAC, which is for one lp-port.
  • Stereo DAC, which is for two lp-ports.

Listing 1. Help Output from pcsel

Listing 1.

pcsel 0.9c (12 Oct 95)
Usage: pcsel [OPTIONS]

-V --version   output version information and exit
-d --device=DEVICE   set the output-device
-p --port=PORT the lp port to use (0-2) for
      single DAC
-r --right-port=PORT the lp port for the right
      DAC
-l --left-port=PORT  the lp port for the left
      DAC
-b --realspeed=SPEED set the real sampling
      rate for PC-Speaker
-e --emulation=on|off   enables or disables the
      16bit stereo emulation
-s --speed=SPEED  set the sampling rate
-M --mono   set mono
-S --stereo set stereo if possible
-v --volume=VOLUME   set the volume for
      PC-Speaker
-h --help   display this help and exit


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.

Listing 2.

vplay 1.2 (12 Oct 95)
Usage: vplay [OPTIONS] [file ...]

-V --version   output version information and exit
-S --stereo stereo output (default is mono)
-s --speed=SPEED  sets the samplerate (default
      is 8000 Hz)
-t --timelimit=SEC   sets the recording time
      in seconds
-b --samplesize=BITS sets the sample size
      (default is 8 bit)
-o --device=DEVICE   changes the audio device
      (default is /dev/dsp)
-v --voc record a CREATIVE LABS VOICE file
      (default)
-w --wave   record a MICROSOFT WAVE file
-r --raw record raw data without header
-q --quiet  quiet mode
-d --verbose   show verbose informations
-h --help   display this help and exit

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.

x

Check Also

A Tale of DXPC: Differential X Protocol Compression

Justin Gaither Issue #53, September 1998 When you have a slow modem and want faster ...