Subject: dev/audiobell.c proposal
To: None <>
From: Ben Harris <>
List: tech-kern
Date: 01/10/2004 23:29:02
Some systems (all acorn32 and acorn26 systems, for a start) don't have a
dedicated console bell, and have to use general-purpose audio hardware for
this purpose.  Until recently, this was handled on acorn32 by having the
bell function forcibly take over the audio hardware, but the code was
ugly, and didn't survive my rewrite of the vidcaudio driver.

It seems to me that it would be cleaner for the bell code to interact with
the existing MI audio system, and Richard Earnshaw included some code to
do this in his independent rewrite of vidcaudi, but it seems to me that
this should be MI code, and hence I'd like to put it in
sys/dev/audiobell.c.  Before I do that, I'd like to know what other people

Here's the important part of the code (I'll spare you the sample

audiobell(void *arg, u_int pitch, u_int period, u_int volume, int poll)
	struct device *audio = arg;
	struct uio auio;
	struct iovec aiov;

	/* The audio system isn't built for polling. */
	if (poll) return;

	/* If not configured, we can't beep. */
	if (audioopen(AUDIO_DEVICE | audio->dv_unit, FWRITE, 0, NULL) != 0)

	aiov.iov_base = (caddr_t)bell_waveform;
	aiov.iov_len = sizeof(bell_waveform);
	auio.uio_iov = & aiov;
	auio.uio_iovcnt = 1;
	auio.uio_resid = sizeof(bell_waveform);
	auio.uio_rw = UIO_WRITE;
	auio.uio_segflg = UIO_SYSSPACE;
	auio.uio_procp = (struct proc *)0;

	audiowrite(AUDIO_DEVICE, &auio, 0);

	audioclose(AUDIO_DEVICE, FWRITE, 0, (struct proc *)0);

Since audio(9) doesn't export any interfaces for playing sounds within the
kernel, audiobell() just uses the standard user interface.  This makes the
code very simple, but means that it doesn't make a noise if the audio
device is already open, since it can only be opened once.

My intention is that it should be up to MD code to arrange for audiobell()
to be called at the right time, and the proposed signature is compatible
with pckbd_hookup_bell().  There'd probably be an "audiobell" attribute to
trigger the inclusion of the code.

Any comments?  Obviously, the precise noise generator is easy to change,
so it's the interfaces I'd like feedback on.  I'll commit this next
weekend unless I change my mind.

Ben Harris                                                   <>
Portmaster, NetBSD/acorn26           <URL:>