SPKR(4) BSD Programmer's Manual SPKR(4)
NAME
speaker, spkr - console speaker device driver
SYNOPSIS
spkr0 at pcppi?
DESCRIPTION
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, within timer and device boundaries, is also supported.
Sound generation does not monopolise 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 struc-
tures and plays them in continuous sequence; this array must be terminat-
ed by a final member (sentinel) with a zero duration.
Music Macro Language
There are 84 accessible notes numbered 1-83 in 7 octaves (numbered 0 to
6), running from C to B each. Octave 2 is identical with the fourth oc-
tave in scientific pitch notation and the one-line octave in Helmholtz
pitch notation, i.e. it starts with O2c ("middle C"), which is C4 in SPN
or c' following Helmholtz, and contains the "pitch standard" at 440 Hz on
O2a (A4, a', MIDI note #69). 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:
CDEFGAB[sign][len]
Letters A through G cause the corresponding note (letter B plays the
German note H) 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 (combination B- plays
the German note B). It may also be followed by a time value number
(see the L command below) and by sustain dots (see below).
Ll Sets the current time value for notes. The default is L4, quarter
notes. The lowest possible value is 1; values up to 64 are accepted.
L1 sets whole notes, L2 sets half notes, L4 sets quarter notes, etc.
M[LNS]
MN sets normal articulation; the last 1/8th of the note's value is
rest time. MS is staccato, the last 1/4th is rest time. ML means
both legato or slur (Bindebogen) and tie (Haltebogen) with no rest.
Nn Play note n, n being 1 to 84 or 0 for a rest of current time value.
May be followed by sustain dots. n defaults to 0 if omitted. Note
n=34 is O2a, i.e. 15 below claviature, 35 below MIDI note numbers.
Ox If x is numeric, this sets the current octave. x may also be one of
'L' or 'N' to enable or disable octave-tracking (it is disabled by
default); when enabled, interpretation of a pair of letter notes
will change octaves if necessary in order to make the smallest pos-
sible jump between notes. Thus "olbc" will be played as "olb>c", and
"olcb" as "olc<b". Octave tracking is disabled for one letter note
following by '>', '<', and 'O[0123456]'. x defaults to 4 if omitted.
Pl Pause (rest) for the duration l, interpreted as for L; if omitted,
the current time value is used. May be followed by sustain dots.
Tt Sets the number of quarter notes per minute; values from 32 to 255
are accepted; default is 120. Musical names for common tempi are:
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 (including pauses, that is, CDEFGAB, P, or N command character
groups) may be followed (after all other arguments) by sustain dots.
Each dot causes the note's time value to be lengthened by one-half.
Thus, a note dotted once is held for 3/2 of its undotted value; dot-
ted twice, it is held 9/4, and three times would give 27/8, etc.
> Bump the current octave up one.
< Drop the current octave down one.
Whitespace in play strings is simply skipped and may be used to separate
melody sections.
The default initialisation string is: MF MN ON O4 L4 T120
FILES
/dev/speaker
SEE ALSO
intro(4), pcppi(4)
https://edugit.org/nik/mmllib
STANDARDS
The play-string language is modelled on the PLAY statement conventions of
IBM BASIC 2.0. It is also known as "modern MML" (music macro language).
The MB, MF, and X directives, as well as variable references, are tied to
the BASIC realisation and not useful in a UNIX environment; this imple-
mentation skips the byte after an M, as well as from an X up to a semi-
colon (';'). Passing a command argument as "=varname;" or its VARPTR$()
form is not even parsed correctly, for obvious reasons.
As extensions, if the arguments to L, N, O, P, and T are omitted, their
default values are used; BASIC requires the arguments. The "accidental
sign" can be applied abnormally (e.g. E# = F) and is ignored for O0C- and
O6B#; too large values for immediate note lengths and the value for P use
the current time value; for the values for L, O, and T, their respective
default values are used; an N command with too large n is just ignored.
As a local extension, a tilde ('~') can be used as an alias for P. Some
implementations of modern MML use R (rest) instead of P for a pause; this
is not supported, either in BASIC or by this implementation.
The "octave-tracking" feature is also a local extension.
Some implementations of parallel MML use the bar character ('|'), analog
to bar lines, for synchronisation, as an extension. This implementation
ignores these characters, allowing an individual stave from such MML file
to be played without further modification (beyond extraction).
AUTHORS
Eric S. Raymond <esr@snark.thyrsus.com>, Feb 1990
The driver and this manual page have been updated for MML description and
implementation correctness and completeness by mirabilos <m@mirbsd.org>.
CAVEATS
Often-used file extensions for files containing play strings are .PLY
(BASIC play) and .MML (often with extensions). Parallel MML files usually
contain a per-file global header and multiple staff lines in an ordered
fashion, akin to a container format for multiple MML tracks.
ML articulation does not prohibit rearticulation, although it is expected
that if a note played with ML articulation is followed immediately by
another sound with the same frequency, their play times are merged. This
implementation does not support merging; this is a known shortcoming.
BUGS
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, only close.
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 in-
correctly due to crossing a block boundary. This also applies to multi-
character commands such as M or X.
The original Microsoft(R) GW-BASIC(R) documentation, as well as the IBM
Personal Computer Hardware Reference Library BASIC manual, Second Edition
(May 1982), Version 1.10, wrongly stated that octave 3 begins at the mid-
dle C. Middle C (C4, c'), situated between bass and treble clef, centre
of historic C clefs, starts MML octave 2 even in GW-BASIC(R) and BASICA.
MirBSD #10-current September 4, 2020 2