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