xref: /netbsd/share/man/man4/speaker.4 (revision bf9ec67e)
1.\" $NetBSD: speaker.4,v 1.9 2002/02/13 08:17:46 ross Exp $
2.\"
3.\" Copyright (c) 1993 Christopher G. Demetriou
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"          This product includes software developed for the
17.\"          NetBSD Project.  See http://www.netbsd.org/ for
18.\"          information about NetBSD.
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
34.\"
35.Dd August 6, 1993
36.Dt SPEAKER 4
37.Os
38.Sh NAME
39.Nm speaker
40.Nd console speaker audio device driver
41.Sh SYNOPSIS
42.Cd "spkr0	at pcppi?"
43.Fd #include \*[Lt]machine/spkr.h\*[Gt]
44.Pa /dev/speaker
45.Sh DESCRIPTION
46The speaker device driver allows applications to control the console
47speaker on machines with a PC-like 8253 timer implementation.
48.Pp
49Only one process may have this device open at any given time; open() and
50close() are used to lock and relinquish it. An attempt to open() when
51another process has the device locked will return -1 with an EBUSY error
52indication. Writes to the device are interpreted as 'play strings' in a
53simple ASCII melody notation. An ioctl() for tone generation at arbitrary
54frequencies is also supported.
55.Pp
56Sound-generation does
57.Em not
58monopolize the processor; in fact, the driver
59spends most of its time sleeping while the PC hardware is emitting
60tones. Other processes may emit beeps while the driver is running.
61.Pp
62Applications may call ioctl() on a speaker file descriptor to control the
63speaker driver directly; definitions for the ioctl() interface are in
64\*[Lt]machine/spkr.h\*[Gt]. The tone_t structure used in these calls has two fields,
65specifying a frequency (in hz) and a duration (in 1/100ths of a second).
66A frequency of zero is interpreted as a rest.
67.Pp
68At present there are two such ioctls. SPKRTONE accepts a pointer to a
69single tone structure as third argument and plays it. SPKRTUNE accepts a
70pointer to the first of an array of tone structures and plays them in
71continuous sequence; this array must be terminated by a final member with
72a zero duration.
73.Pp
74The play-string language is modelled on the PLAY statement conventions of
75IBM BASIC 2.0. The MB, MF and X primitives of PLAY are not useful in a UNIX
76environment and are omitted. The `octave-tracking' feature is also new.
77.Pp
78There are 84 accessible notes numbered 1-83 in 7 octaves, each running from
79C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts
80with middle C. By default, the play function emits half-second notes with the
81last 1/16th second being `rest time'.
82.Pp
83Play strings are interpreted left to right as a series of play command groups;
84letter case is ignored. Play command groups are as follows:
85.Pp
86CDEFGAB -- letters A through G cause the corresponding note to be played in the
87current octave. A note letter may optionally be followed by an
88.Em accidental sign ,
89one of # + or -; the first two of these cause it to be sharped one
90half-tone, the last causes it to be flatted one half-tone. It may also be
91followed by a time value number and by sustain dots (see below). Time values
92are interpreted as for the L command below;.
93.Pp
94O \*[Lt]n\*[Gt] -- if \*[Lt]n\*[Gt] is numeric, this sets the current octave. \*[Lt]n\*[Gt] may also be one
95of 'L' or 'N' to enable or disable octave-tracking (it is disabled by default).
96When octave-tracking is on, interpretation of a pair of letter notes will
97change octaves if necessary in order to make the smallest possible jump between
98notes. Thus "olbc" will be played as "olb\*[Gt]c", and "olcb" as "olc\*[Lt]b". Octave
99locking is disabled for one letter note following by \*[Gt], \*[Lt] and O[0123456].
100.Pp
101\*[Gt] -- bump the current octave up one.
102.Pp
103\*[Lt] -- drop the current octave down one.
104.Pp
105N \*[Lt]n\*[Gt] -- play note n, n being 1 to 84 or 0 for a rest of current time value.
106May be followed by sustain dots.
107.Pp
108L \*[Lt]n\*[Gt] -- sets the current time value for notes. The default is L4, quarter
109notes. The lowest possible value is 1; values up to 64 are accepted. L1 sets
110whole notes, L2 sets half notes, L4 sets quarter notes, etc..
111.Pp
112P \*[Lt]n\*[Gt] -- pause (rest), with \*[Lt]n\*[Gt] interpreted as for L. May be followed by
113sustain dots. May also be written '~'.
114.Pp
115T \*[Lt]n\*[Gt] -- Sets the number of quarter notes per minute; default is 120. Musical
116names for common tempi are:
117.Bl -column Description Tempo BPM -offset indent
118.Em 	Tempo		Beats per Minute
119very slow	Larghissimo
120        	Largo	 	40-60
121         	Larghetto	60-66
122        	Grave
123        	Lento
124        	Adagio	 	66-76
125slow    	Adagietto
126        	Andante	 	76-108
127medium   	Andantino
128        	Moderato 	108-120
129fast    	Allegretto
130        	Allegro	 	120-168
131        	Vivace
132        	Veloce
133        	Presto	 	168-208
134very fast	Prestissimo
135.El
136.Pp
137M[LNS] -- set articulation. MN (N for normal) is the default; the last 1/8th of
138the note's value is rest time. You can set ML for legato (no rest space) or
139MS (staccato) 1/4 rest space.
140.Pp
141Notes (that is, CDEFGAB or N command character groups) may be followed by
142sustain dots. Each dot causes the note's value to be lengthened by one-half
143for each one. Thus, a note dotted once is held for 3/2 of its undotted value;
144dotted twice, it is held 9/4, and three times would give 27/8.
145.Pp
146Whitespace in play strings is simply skipped and may be used to separate
147melody sections.
148.Sh FILES
149.Bl -tag -width Pa -compact
150.It Pa /dev/speaker
151.El
152.Sh SEE ALSO
153.Xr pcppi 4
154.Sh AUTHORS
155Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990
156.Sh BUGS
157Due to roundoff in the pitch tables and slop in the tone-generation and timer
158hardware (neither of which was designed for precision), neither pitch accuracy
159nor timings will be mathematically exact.
160.Pp
161There is no volume control.
162.Pp
163In play strings which are very long (longer than your system's physical I/O
164blocks) note suffixes or numbers may occasionally be parsed incorrectly due
165to crossing a block boundary.
166