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