xref: /freebsd/share/man/man4/spkr.4 (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
1.\"
2.\"	$Id: spkr.4,v 1.9 1997/03/21 20:13:56 mpp Exp $
3.\"
4.Dd November 7, 1993
5.Dt SPKR 4 i386
6.Os FreeBSD
7.Sh NAME
8.Nm speaker ,
9.Nm spkr
10.Nd console speaker device driver
11.Sh SYNOPSIS
12.Cd pseudo-device speaker
13.Fd #include <machine/speaker.h>
14.Sh DESCRIPTION
15The speaker device driver allows applications to control the PC console
16speaker on an
17.Tn IBM-PC Ns --compatible
18machine running
19.Tn FreeBSD .
20.Pp
21Only one process may have this device open at any given time;
22.Xr open 2
23and
24.Xr close 2
25are used to lock and relinquish it. An attempt to open when
26another process has the device locked will return -1 with an
27.Er EBUSY
28error
29indication. Writes to the device are interpreted as `play strings' in a
30simple ASCII melody notation. An
31.Xr ioctl 2
32request
33for tone generation at arbitrary
34frequencies is also supported.
35.Pp
36Sound-generation does not monopolize the processor; in fact, the driver
37spends most of its time sleeping while the PC hardware is emitting
38tones. Other processes may emit beeps while the driver is running.
39.Pp
40Applications may call
41.Xr ioctl 2
42on a speaker file descriptor to control the
43speaker driver directly; definitions for the
44.Xr ioctl 2
45interface are in
46.Pa /usr/include/machine/speaker.h .
47The
48.Li tone_t
49structure used in these calls has two fields,
50specifying a frequency (in Hz) and a duration (in 1/100ths of a second).
51A frequency of zero is interpreted as a rest.
52.Pp
53At present there are two such
54.Xr ioctl 2
55calls.
56.Dv SPKRTONE
57accepts a pointer to a
58single tone structure as third argument and plays it.
59.Dv SPKRTUNE
60accepts a
61pointer to the first of an array of tone structures and plays them in
62continuous sequence; this array must be terminated by a final member with
63a zero duration.
64.Pp
65The play-string language is modelled on the PLAY statement conventions of
66.Tn IBM
67Advanced BASIC 2.0.  The
68.Li MB ,
69.Li MF ,
70and
71.Li X
72primitives of PLAY are not
73useful in a timesharing environment and are omitted. The `octave-tracking'
74feature and the slur mark are new.
75.Pp
76There are 84 accessible notes numbered 1-83 in 7 octaves, each running from
77C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts
78with middle C.  By default, the play function emits half-second notes with the
79last 1/16th second being `rest time'.
80.Pp
81Play strings are interpreted left to right as a series of play command groups;
82letter case is ignored. Play command groups are as follows:
83.Bl -tag -width CDEFGABxx
84.It Li CDEFGAB
85Letters A through G cause the corresponding note to be played in the
86current octave.  A note letter may optionally be followed by an
87.Dq Em "accidental sign" ,
88one of # + or -; the first two of these cause it to be sharped one
89half-tone, the last causes it to be flatted one half-tone.  It may
90also be followed by a time value number and by sustain dots (see
91below).  Time values are interpreted as for the L command below.
92.It Ns Li O Sy n
93If
94.Sy n
95is numeric, this sets the current octave.
96.Sy n
97may also be one of
98.Li L
99or
100.Li N
101to enable or disable octave-tracking (it is disabled by default).
102When octave-tracking is on, interpretation of a pair of letter notes
103will change octaves if necessary in order to make the smallest
104possible jump between notes. Thus ``olbc'' will be played as
105``olb>c'', and ``olcb'' as ``olc<b''.  Octave locking is disabled for
106one letter note following >, < and O[0123456].  (The octave-locking
107feature is not supported in
108.Tn IBM
109BASIC.)
110.It Li >
111Bump the current octave up one.
112.It Li <
113Drop the current octave down one.
114.It Ns Li N Sy n
115Play note
116.Sy n ,
117.Sy n
118being 1 to 84 or 0 for a rest of current time value.
119May be followed by sustain dots.
120.It Ns Li L Sy n
121Sets the current time value for notes.  The default is
122.Li L4 ,
123quarter or crotchet notes. The lowest possible value is 1; values up
124to 64 are accepted.
125.Li L1
126sets whole notes,
127.Li L2
128sets half notes,
129.Li L4
130sets quarter notes, etc.
131.It Ns Li P Sy n
132Pause (rest), with
133.Sy n
134interpreted as for
135.Ns Li L Sy n .
136May be followed by
137sustain dots.  May also be written
138.Li ~ .
139.It Ns Li T Sy n
140Sets the number of quarter notes per minute; default is 120.  Musical
141names for common tempi are:
142
143.Bd -literal -offset indent
144        	Tempo    	Beats Per Minute
145very slow	Larghissimo
146        	Largo    	40-60
147         	Larghetto    	60-66
148        	Grave
149        	Lento
150        	Adagio       	66-76
151slow    	Adagietto
152        	Andante   	76-108
153medium   	Andantino
154        	Moderato	108-120
155fast    	Allegretto
156        	Allegro   	120-168
157        	Vivace
158        	Veloce
159        	Presto    	168-208
160very fast	Prestissimo
161.Ed
162.It Li M[LNS]
163Set articulation.
164.Li MN
165.Ns No ( Li N
166for normal) is the default; the last 1/8th of
167the note's value is rest time. You can set
168.Li ML
169for legato (no rest space) or
170.Li MS
171for staccato (1/4 rest space).
172.El
173.Pp
174Notes (that is,
175.Li CDEFGAB
176or
177.Li N
178command character groups) may be followed by
179sustain dots. Each dot causes the note's value to be lengthened by one-half
180for each one. Thus, a note dotted once is held for 3/2 of its undotted value;
181dotted twice, it is held 9/4, and three times would give 27/8.
182.Pp
183A note and its sustain dots may also be followed by a slur mark (underscore).
184This causes the normal micro-rest after the note to be filled in, slurring it
185to the next one.  (The slur feature is not supported in
186.Tn IBM
187BASIC.)
188.Pp
189Whitespace in play strings is simply skipped and may be used to separate
190melody sections.
191.Sh BUGS
192Due to roundoff in the pitch tables and slop in the tone-generation and timer
193hardware (neither of which was designed for precision), neither pitch accuracy
194nor timings will be mathematically exact. There is no volume control.
195.Pp
196The action of two or more sustain dots does not reflect standard musical
197notation, in which each dot adds half the value of the previous dot
198modifier, not half the value of the note as modified.  Thus, a note dotted
199once is held for 3/2 of its undotted value; dotted twice, it is held 7/4,
200and three times would give 15/8.  The multiply-by-3/2 interpretation,
201however, is specified in the
202.Tn IBM
203BASIC manual and has been retained for
204compatibility.
205.Pp
206In play strings which are very long (longer than your system's physical I/O
207blocks) note suffixes or numbers may occasionally be parsed incorrectly due
208to crossing a block boundary.
209.Sh FILES
210.Bl -tag -width /dev/speakerxx
211.It Pa /dev/speaker
212speaker device file
213.El
214.Sh SEE ALSO
215.Xr spkrtest 8
216.Sh AUTHORS
217.An Eric S. Raymond Aq esr@snark.thyrsus.com
218June 1990
219.Sh "PORTED BY"
220.An Andrew A. Chernov Aq ache@astral.msk.su
221.Sh HISTORY
222The
223.Nm
224device appeared in
225.Fx 1.0 .
226