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