SPKR(4) | Device Drivers Manual | SPKR(4) |
speaker
, spkr
— console speaker device driver
spkr0 at pcppi?
The speaker
device driver allows
applications to control the built-in speaker on machines providing a PCPPI
speaker interface.
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
open
() when
another process has the device locked will return -1 with an
EBUSY
error indication. Writes to the device are
interpreted as “play strings” in 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, the driver spends most of its time sleeping while the PC hardware is emitting tones. 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
<dev/isa/spkrio.h>
. The
tone_t
structure used in these calls has two 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 accepts a 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 tone structures and plays them in continuous sequence; this array
must be terminated by a final member with a zero duration.
The play-string language is modelled on the PLAY statement conventions of 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 new.
There are 84 accessible notes numbered 1-84 in 7 octaves, each running 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 half-second notes with the last 1/16th second being “rest time”.
Play strings are interpreted left to right as a series of play command groups; letter case is ignored. Play command groups are as follows:
#
’,
‘+
’, 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 value number and by sustain
dots (see below). Time values are interpreted as for the L command
below;.>
’,
‘<
’, and
‘O[0123456]
’.
> -- bump the current octave up one. < -- drop the current octave down one.
~
’.Description | Tempo | Beats per Minute |
very slow | Larghissimo | 40–60 |
very slow | Largo | 40–60 |
very slow | Larghetto | 60–66 |
very slow | Grave | 60–66 |
very slow | Lento | 60–66 |
slow | Adagio | 66–76 |
slow | Adagietto | 66–76 |
medium | Andante | 76–108 |
medium | Andantino | 76–108 |
fast | Moderato | 108–120 |
fast | Allegretto | 108–120 |
fast | Allegro | 120–168 |
fast | Vivace | 120–168 |
fast | Veloce | 120–168 |
very fast | Presto | 168–208 |
very fast | Prestissimo | 168–208 |
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 one-half 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 would give 27/8.
Whitespace in play strings is simply skipped and may be used to separate melody sections.
Eric S. Raymond <esr@snark.thyrsus.com>, Feb 1990
Due to roundoff in the pitch tables and slop in the tone-generation 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 parsed incorrectly due to crossing a block boundary.
July 5, 2020 | OpenBSD-current |