The speaker device driver allows applications to control the PC console speaker on an IBM-PC --compatible machine running
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(2) request 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(2) on a speaker file descriptor to control the speaker driver directly; definitions for the ioctl(2) interface are in
.In machine/speaker.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 ioctl(2) calls. SPKRTONE accepts a pointer to a single tone structure as third argument and plays it. SPKRTUNE 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 modeled on the PLAY statement conventions of IBM Advanced BASIC 2.0. The MB, MF, and X primitives of PLAY are not useful in a timesharing environment and are omitted. The octave-tracking feature and the slur mark are 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: