Sound Through the PC-Speaker

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

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).

______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState