speaker - console speaker device driver
spkr0 at pcppi?
The speaker device driver allows applications to control the
speaker on an IBM-PC-compatible machine running UNIX.
Only one process may have this device open at any given
time; open(2) and
close(2) are used to lock and relinquish it. An attempt to
another process has the device locked will return -1 with an
indication. Writes to the device are interpreted as ``play
a simple ASCII melody notation. An ioctl() for tone generation at arbitrary
frequencies is also supported.
Sound-generation does not monopolize the processor; in fact,
spends most of its time sleeping while the PC hardware is
Other processes may emit beeps while the driver is running.
Applications may call ioctl() on a speaker file descriptor
to control the
speaker driver directly; definitions for the ioctl() interface are in
<machine/spkr.h>. The tone_t structure used in these calls
fields, specifying a frequency (in hz) and a duration (in
1/100ths of a
second). A frequency of zero is interpreted as a rest.
At present there are two such ioctls. The SPKRTONE ioctl
pointer to a single tone structure as a third argument and
plays it. The
SPKRTUNE ioctl accepts a pointer to the first of an array of
and plays them in continuous sequence; this array must
by a final member with a zero duration.
The play-string language is modelled on the PLAY statement
IBM BASIC 2.0. The MB, MF and X primitives of PLAY are not
useful in a
UNIX environment and are omitted. The ``octave-tracking''
feature is also
There are 84 accessible notes numbered 1-83 in 7 octaves,
from C to B, numbered 0-6; the scale is equal-tempered A440
and octave 3
starts with middle C. By default, the play function emits
notes with the last 1/16th second being ``rest time''.
Play strings are interpreted left to right as a series of
groups; letter case is ignored. Play command groups are as
Letters A through G cause the corresponding note to be
played in the
current octave. A note letter may optionally be followed by an
``accidental sign'', one of `#', `+', or `-'; the first
two of these
cause it to be sharped one half-tone, the last causes
it to be flatted
one half-tone. It may also be followed by a time
and by sustain dots (see below). Time values are interpreted as for
the L command below;.
If n is numeric, this sets the current octave. n may
also be one of
`L' or `N' to enable or disable octave-tracking (it is
default). When octave-tracking is on, interpretation
of a pair of
letter notes will change octaves if necessary in order
to make the
smallest possible jump between notes. Thus "olbc" will
be played as
"olb>c", and "olcb" as "olc<b". Octave locking is disabled for one
letter note following by `>', `<', and `O'.
> -- bump the current octave up one.
< -- drop the current octave down one.
Play note n, n being 1 to 84 or 0 for a rest of current
May be followed by sustain dots.
Sets the current time value for notes. The default is
notes. The lowest possible value is 1; values up to 64
L1 sets whole notes, L2 sets half notes, L4 sets
Pause (rest), with n interpreted as for L. May be followed by sustain
dots. May also be written `~'.
Sets the number of quarter notes per minute; default is
names for common tempi are:
Tempo Beats per Minute
very slow Larghissimo
very fast Prestissimo
Set articulation. MN (N for normal) is the default;
the last 1/8th
of the note's value is rest time. You can set ML for
rest space) or MS (staccato) 1/4 rest space.
Notes (that is, CDEFGAB or N command character groups) may
be followed by
sustain dots. Each dot causes the note's value to be
lengthened by onehalf
for each one. Thus, a note dotted once is held for 3/2
of its undotted
value; dotted twice, it is held 9/4, and three times
Whitespace in play strings is simply skipped and may be used
Eric S. Raymond <email@example.com>, Feb 1990
Due to roundoff in the pitch tables and slop in the tonegeneration and
timer hardware (neither of which was designed for precision), neither
pitch accuracy nor timings will be mathematically exact.
There is no volume control.
In play strings which are very long (longer than your system's physical
I/O blocks) note suffixes or numbers may occasionally be
due to crossing a block boundary.
OpenBSD 3.6 August 6, 1993
[ Back ]