spkr.4 revision 739
1.Dd November 7, 1993
2.TH SPKR 4
3.Os FreeBSD
4.SH NAME
5.Nm spkr
6.Nd console speaker device driver
7.SH DESCRIPTION
8The speaker device driver allows applications to control the PC console
9speaker on an IBM-PC-compatible machine running UNIX.
10.PP
11Only one process may have this device open at any given time; open() and
12close() are used to lock and relinquish it. An attempt to open() when
13another process has the device locked will return -1 with an EBUSY error
14indication. Writes to the device are interpreted as 'play strings' in a
15simple ASCII melody notation. An ioctl() for tone generation at arbitrary
16frequencies is also supported.
17.PP
18Sound-generation does \fInot\fR monopolize the processor; in fact, the driver
19spends most of its time sleeping while the PC hardware is emitting
20tones. Other processes may emit beeps while the driver is running.
21.PP
22Applications may call ioctl() on a speaker file descriptor to control the
23speaker driver directly; definitions for the ioctl() interface are in
24machine/speaker.h. The tone_t structure used in these calls has two fields,
25specifying a frequency (in hz) and a duration (in 1/100ths of a second).
26A frequency of zero is interpreted as a rest.
27.PP
28At present there are two such ioctls. SPKRTONE accepts a pointer to a
29single tone structure as third argument and plays it. SPKRTUNE accepts a
30pointer to the first of an array of tone structures and plays them in
31continuous sequence; this array must be terminated by a final member with
32a zero duration.
33.PP
34The play-string language is modelled on the PLAY statement conventions of
35IBM BASIC 2.0. The MB, MF and X primitives of PLAY are not useful in a UNIX 
36environment and are omitted. The `octave-tracking' feature and the slur
37mark are new.
38.PP
39There are 84 accessible notes numbered 1-83 in 7 octaves, each running from
40C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts
41with middle C. By default, the play function emits half-second notes with the
42last 1/16th second being `rest time'.
43.PP
44Play strings are interpreted left to right as a series of play command groups;
45letter case is ignored. Play command groups are as follows:
46.PP
47CDEFGAB -- letters A through G cause the corresponding note to be played in the
48current octave. A note letter may optionally be followed by an \fIaccidental
49sign\fR, one of # + or -; the first two of these cause it to be sharped one
50half-tone, the last causes it to be flatted one half-tone. It may also be
51followed by a time value number and by sustain dots (see below). Time values
52are interpreted as for the L command below.
53.PP
54O <n> -- if <n> is numeric, this sets the current octave. <n> may also be one
55of 'L' or 'N' to enable or disable octave-tracking (it is disabled by default).
56When octave-tracking is on, interpretation of a pair of letter notes will
57change octaves if necessary in order to make the smallest possible jump between
58notes. Thus "olbc" will be played as "olb>c", and "olcb" as "olc<b". Octave
59locking is disabled for one letter note following >, < and O[0123456].
60(The octave-locking feature is not supported in Microsoft Basic.)
61.PP
62> -- bump the current octave up one.
63.PP
64< -- drop the current octave down one.
65.PP
66N <n> -- play note n, n being 1 to 84 or 0 for a rest of current time value.
67May be followed by sustain dots.
68.PP
69L <n> -- sets the current time value for notes. The default is L4, quarter or
70crotchet notes. The lowest possible value is 1; values up to 64 are accepted.
71L1 sets whole notes, L2 sets half notes, L4 sets quarter notes, etc..
72.PP
73P <n> -- pause (rest), with <n> interpreted as for L. May be followed by
74sustain dots. May also be written '~'.
75.PP
76T <n> -- Sets the number of quarter notes per minute; default is 120. Musical
77names for common tempi are:
78
79.TS
80a a a.
81        	Tempo    	Beats Per Minute
82very slow	Larghissimo	
83        	Largo    	40-60
84         	Larghetto    	60-66
85        	Grave       	
86        	Lento       	
87        	Adagio       	66-76
88slow    	Adagietto    	
89        	Andante   	76-108
90medium   	Andantino	
91        	Moderato	108-120
92fast    	Allegretto	
93        	Allegro   	120-168
94        	Vivace    	
95        	Veloce    	
96        	Presto    	168-208
97very fast	Prestissimo	
98.TE
99.PP
100M[LNS] -- set articulation. MN (N for normal) is the default; the last 1/8th of
101the note's value is rest time. You can set ML for legato (no rest space) or
102MS (staccato) 1/4 rest space.
103.PP
104Notes (that is, CDEFGAB or N command character groups) may be followed by
105sustain dots. Each dot causes the note's value to be lengthened by one-half
106for each one. Thus, a note dotted once is held for 3/2 of its undotted value;
107dotted twice, it is held 9/4, and three times would give 27/8. 
108.PP
109A note and its sustain dots may also be followed by a slur mark (underscore).
110This causes the normal micro-rest after the note to be filled in, slurring it
111to the next one.  (The slur feature is not supported in Microsoft Basic.)
112.PP
113Whitespace in play strings is simply skipped and may be used to separate
114melody sections.
115.SH BUGS
116Due to roundoff in the pitch tables and slop in the tone-generation and timer
117hardware (neither of which was designed for precision), neither pitch accuracy
118nor timings will be mathematically exact. There is no volume control.
119.PP
120The action of two or more sustain dots does not reflect standard musical
121notation, in which each dot adds half the value of the previous dot
122modifier, not half the value of the note as modified.  Thus, a note dotted
123once is held for 3/2 of its undotted value; dotted twice, it is held 7/4,
124and three times would give 15/8.  The multiply-by-3/2 interpretation,
125however, is specified in the IBM BASIC manual and has been retained for
126compatibility.
127.PP
128In play strings which are very long (longer than your system's physical I/O
129blocks) note suffixes or numbers may occasionally be parsed incorrectly due
130to crossing a block boundary.
131.SH FILES
132/dev/speaker -- speaker device file
133.SH AUTHOR
134Eric S. Raymond <esr@snark.thyrsus.com) June 1990
135FreeBSD port -- Andrew A. Chernov <ache@astral.msk.su>
136