xref: /netbsd-src/share/man/man4/speaker.4 (revision 1ca5c1b28139779176bd5c13ad7c5f25c0bcd5f8)
1.\" $NetBSD: speaker.4,v 1.7 2001/09/22 16:21:42 wiz 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 <machine/spkr.h>
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 \fInot\fR monopolize the processor; in fact, the driver
57spends most of its time sleeping while the PC hardware is emitting
58tones. Other processes may emit beeps while the driver is running.
59.Pp
60Applications may call ioctl() on a speaker file descriptor to control the
61speaker driver directly; definitions for the ioctl() interface are in
62<machine/spkr.h>. The tone_t structure used in these calls has two fields,
63specifying a frequency (in hz) and a duration (in 1/100ths of a second).
64A frequency of zero is interpreted as a rest.
65.Pp
66At present there are two such ioctls. SPKRTONE accepts a pointer to a
67single tone structure as third argument and plays it. SPKRTUNE accepts a
68pointer to the first of an array of tone structures and plays them in
69continuous sequence; this array must be terminated by a final member with
70a zero duration.
71.Pp
72The play-string language is modelled on the PLAY statement conventions of
73IBM BASIC 2.0. The MB, MF and X primitives of PLAY are not useful in a UNIX
74environment and are omitted. The `octave-tracking' feature is also 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.Pp
84CDEFGAB -- letters A through G cause the corresponding note to be played in the
85current octave. A note letter may optionally be followed by an \fIaccidental
86sign\fR, one of # + or -; the first two of these cause it to be sharped one
87half-tone, the last causes it to be flatted one half-tone. It may also be
88followed by a time value number and by sustain dots (see below). Time values
89are interpreted as for the L command below;.
90.Pp
91O <n> -- if <n> is numeric, this sets the current octave. <n> may also be one
92of 'L' or 'N' to enable or disable octave-tracking (it is disabled by default).
93When octave-tracking is on, interpretation of a pair of letter notes will
94change octaves if necessary in order to make the smallest possible jump between
95notes. Thus "olbc" will be played as "olb>c", and "olcb" as "olc<b". Octave
96locking is disabled for one letter note following by >, < and O[0123456].
97.Pp
98> -- bump the current octave up one.
99.Pp
100< -- drop the current octave down one.
101.Pp
102N <n> -- play note n, n being 1 to 84 or 0 for a rest of current time value.
103May be followed by sustain dots.
104.Pp
105L <n> -- sets the current time value for notes. The default is L4, quarter
106notes. The lowest possible value is 1; values up to 64 are accepted. L1 sets
107whole notes, L2 sets half notes, L4 sets quarter notes, etc..
108.Pp
109P <n> -- pause (rest), with <n> interpreted as for L. May be followed by
110sustain dots. May also be written '~'.
111.Pp
112T <n> -- Sets the number of quarter notes per minute; default is 120. Musical
113names for common tempi are:
114.Bl -column Description Tempo BPM -offset indent
115.Em 	Tempo		Beats per Minute
116very slow	Larghissimo
117        	Largo	 	40-60
118         	Larghetto	60-66
119        	Grave
120        	Lento
121        	Adagio	 	66-76
122slow    	Adagietto
123        	Andante	 	76-108
124medium   	Andantino
125        	Moderato 	108-120
126fast    	Allegretto
127        	Allegro	 	120-168
128        	Vivace
129        	Veloce
130        	Presto	 	168-208
131very fast	Prestissimo
132.El
133.Pp
134M[LNS] -- set articulation. MN (N for normal) is the default; the last 1/8th of
135the note's value is rest time. You can set ML for legato (no rest space) or
136MS (staccato) 1/4 rest space.
137.Pp
138Notes (that is, CDEFGAB or N command character groups) may be followed by
139sustain dots. Each dot causes the note's value to be lengthened by one-half
140for each one. Thus, a note dotted once is held for 3/2 of its undotted value;
141dotted twice, it is held 9/4, and three times would give 27/8.
142.Pp
143Whitespace in play strings is simply skipped and may be used to separate
144melody sections.
145.Sh FILES
146.Bl -tag -width Pa -compact
147.It Pa /dev/speaker
148.El
149.Sh SEE ALSO
150.Xr pcppi 4
151.Sh AUTHORS
152Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990
153.Sh BUGS
154Due to roundoff in the pitch tables and slop in the tone-generation and timer
155hardware (neither of which was designed for precision), neither pitch accuracy
156nor timings will be mathematically exact.
157.Pp
158There is no volume control.
159.Pp
160In play strings which are very long (longer than your system's physical I/O
161blocks) note suffixes or numbers may occasionally be parsed incorrectly due
162to crossing a block boundary.
163