First, a word from our sponsers:

In Memoriam Linuxlots (http://www.linuxlots.com/~dunne), 1999 -- 2011, R.I.P.

You are here: http://dunne.yenn.ulegend.net//lj.pc_speaker.html

Go to: index | blog | contact


The Linux PC Speaker Driver

Introduction

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 your humble PC speaker.  In this article, I will examine one way of doing this.

What PC-Speaker Is

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

Modifying the kernel

The driver comes as a patch file, which must be applied against the Linux source directory (/usr/src/linux).  When make config is run after this, you will be asked whether you want PC Speaker support - say yes! A short "make depend; make clean; make zImage" later, and your new kernel is ready.  The patches to the source include some header files for /usr/include/sys, which are necessary to make the utilities that accompany it.

Devices

The driver supports the following devices :

/dev/pcsp - the raw data device
/dev/pcaudio - the SUN-audio device
/dev/pcmixer - the mixer-device

I have only the /dev/pcsp defined on my machine, like so:
crw—w—w- 1 root root 13, 3 Aug 27 20:25 /dev/pcsp
Having installed the driver, and devices, there is the matter of configuration.  

pcsel

This program Sets options for the PC speaker.  It should be used to configure your /dev/pcsp at system startup or for testing new devices.

You can 'assign' an output-device to /dev/pcsp, using the pcsel program.  The supported output devices are as follows:

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

$ pcsel —help
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 diables 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

supported devices :
  'Sto1' : Stereo-on-One
  'DACm' : Mono DAC
  'DACs' : Stereo DAC
  'PCSP' : PC-Speaker

Without options pcsel reports the actual output-device and its parameters.

$ 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

Use

vplay & vrec

These programs can be used for recording and playing:

CREATIVE LABS VOICE files
MICROSOFT WAVE file
raw audio data.

Both programs accept the same options:

$ vplay —help
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

OK, confession time.  The only real reason I had for adding this driver to my kernel was so that I could have sound effects in Doom! Here is another, trivial, example, of what you can do.  I have a directory of .wav and .au files.  Here is a shell script, called from my .profile, that plays one of these at random each time I login.

#!/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 will be at ftp.informatik.hu-berlin.de, in the directory /pub/os/linux/hu-sound/pcsnd* (where * represents the latest version number).

Conclusion

This is neat bit of software that makes good use of the basic PC speaker.  You will get plenty of interference if your computer is "digitally noisy".  It is unlikely to be made part of the standard kernel; the author, Michael Beck (beck@dgroup.de), says that one of the reasons is that it interferes with the Linux clock. I hadn't noticed this myself, but then my clock is re-synched with my ISPs four times a day.  The distribution comes with a file, that describes how to build your own sound output devices - so that you PC can connect to your amp, for example.  I may try one of these projects in future - watch this space!

Paul Dunne 1997


Viewable with any browser

This page was brought to you by ksh, vi, m4, sed & make, courtesy of openbsd.
Last changed: Tue Nov 8 17:32:18 CET 2016

pay no attention to the 1x1 gif behind the curtain!