1.\" $OpenBSD: speaker.4,v 1.9 2015/11/21 08:04:20 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: November 21 2015 $ 33.Dt SPKR 4 34.Os 35.Sh NAME 36.Nm speaker , 37.Nm spkr 38.Nd console speaker device driver 39.Sh SYNOPSIS 40.Cd "spkr0 at pcppi?" 41.Sh DESCRIPTION 42The 43.Nm 44device driver allows applications to control the built-in speaker on 45machines providing a PCPPI speaker interface. 46.Pp 47Only one process may have this device open at any given time; 48.Xr open 2 49and 50.Xr close 2 51are used to lock and relinquish it. 52An attempt to 53.Fn open 54when another process has the device locked will return \-1 with an 55.Er EBUSY 56error indication. 57Writes to the device are interpreted as 58.Dq play strings 59in a simple ASCII melody notation. 60An 61.Fn ioctl 62for tone generation at arbitrary frequencies is also supported. 63.Pp 64Sound-generation does 65.Em not 66monopolize the processor; in fact, the driver 67spends most of its time sleeping while the PC hardware is emitting tones. 68Other processes may emit beeps while the driver is running. 69.Pp 70Applications may call 71.Fn ioctl 72on a speaker file descriptor to control the speaker driver directly; 73definitions for the 74.Fn ioctl 75interface are in 76.In dev/isa/spkrio.h . 77The 78.Li tone_t 79structure used in these calls has two fields, 80specifying a frequency (in Hz) and a duration (in 1/100ths of a second). 81A frequency of zero is interpreted as a rest. 82.Pp 83At present there are two such ioctls. 84The 85.Dv SPKRTONE 86ioctl accepts a pointer to a single tone structure as a third argument and 87plays it. 88The 89.Dv SPKRTUNE 90ioctl accepts a pointer to the first of an array of tone structures and plays 91them in continuous sequence; this array must be terminated by a final member 92with a zero duration. 93.Pp 94The play-string language is modelled on the PLAY statement conventions of 95IBM BASIC 2.0. 96The MB, MF and X primitives of PLAY are not useful in a UNIX environment and 97are omitted. 98The 99.Dq octave-tracking 100feature is also new. 101.Pp 102There are 84 accessible notes numbered 1-83 in 7 octaves, each running from 103C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts 104with middle C. 105By default, the play function emits half-second notes with the last 1/16th 106second being 107.Dq rest time . 108.Pp 109Play strings are interpreted left to right as a series of play command groups; 110letter case is ignored. 111Play command groups are as follows: 112.Bl -tag -width xxx 113.It CDEFGAB 114Letters A through G cause the corresponding note to be played in the current 115octave. 116A note letter may optionally be followed by an 117.Dq accidental sign , 118one of 119.Ql # , 120.Ql + , 121or 122.Ql - ; 123the first two of these cause it to be sharped one half-tone, the last causes 124it to be flatted one half-tone. 125It may also be followed by a time value number and by sustain dots (see below). 126Time values are interpreted as for the L command below;. 127.It O Aq Ar n 128If 129.Ar n 130is numeric, this sets the current octave. 131.Ar n 132may also be one of 133.Sq L 134or 135.Sq N 136to enable or disable octave-tracking (it is disabled by default). 137When octave-tracking is on, interpretation of a pair of letter notes will 138change octaves if necessary in order to make the smallest possible jump between 139notes. 140Thus 141.Qq olbc 142will be played as 143.Qq olb>c , 144and 145.Qq olcb 146as 147.Qq olc<b . 148Octave locking is disabled for one letter note following by 149.Ql > , 150.Ql < , 151and 152.Ql O[0123456] . 153.Bd -literal -offset indent 154> -- bump the current octave up one. 155< -- drop the current octave down one. 156.Ed 157.It N Aq Ar n 158Play note 159.Ar n , 160.Ar n 161being 1 to 84 or 0 for a rest of current time value. 162May be followed by sustain dots. 163.It L Aq Ar n 164Sets the current time value for notes. 165The default is L4, quarter notes. 166The lowest possible value is 1; values up to 64 are accepted. 167L1 sets whole notes, L2 sets half notes, L4 sets quarter notes, etc. 168.It P Aq Ar n 169Pause (rest), with 170.Ar n 171interpreted as for L. 172May be followed by sustain dots. 173May also be written 174.Ql ~ . 175.It T Aq Ar n 176Sets the number of quarter notes per minute; default is 120. 177Musical names for common tempi are: 178.Bl -column "Description" "Larghissimo" "Beats per minute" -offset indent 179.It Em "Description" Ta Em "Tempo" Ta Em "Beats per Minute" 180.It "very slow" Ta Larghissimo Ta 40\(en60 181.It "very slow" Ta Largo Ta 40\(en60 182.It "very slow" Ta Larghetto Ta 60\(en66 183.It "very slow" Ta Grave Ta 60\(en66 184.It "very slow" Ta Lento Ta 60\(en66 185.It "slow" Ta Adagio Ta 66\(en76 186.It "slow" Ta Adagietto Ta 66\(en76 187.It "medium" Ta Andante Ta 76\(en108 188.It "medium" Ta Andantino Ta 76\(en108 189.It "fast" Ta Moderato Ta 108\(en120 190.It "fast" Ta Allegretto Ta 108\(en120 191.It "fast" Ta Allegro Ta 120\(en168 192.It "fast" Ta Vivace Ta 120\(en168 193.It "fast" Ta Veloce Ta 120\(en168 194.It "very fast" Ta Presto Ta 168\(en208 195.It "very fast" Ta Prestissimo Ta 168\(en208 196.El 197.It M[LNS] 198Set articulation. 199MN (N for normal) is the default; the last 1/8th of the note's value is rest 200time. 201You can set ML for legato (no rest space) or MS (staccato) 1/4 rest space. 202.El 203.Pp 204Notes (that is, CDEFGAB or N command character groups) may be followed by 205sustain dots. 206Each dot causes the note's value to be lengthened by one-half for each one. 207Thus, a note dotted once is held for 3/2 of its undotted value; 208dotted twice, it is held 9/4, and three times would give 27/8. 209.Pp 210Whitespace in play strings is simply skipped and may be used to separate 211melody sections. 212.Sh FILES 213.Bl -tag -width Pa -compact 214.It Pa /dev/speaker 215.El 216.Sh SEE ALSO 217.Xr intro 4 , 218.Xr pcppi 4 219.Sh AUTHORS 220.An Eric S. Raymond Aq Mt esr@snark.thyrsus.com , 221Feb 1990 222.Sh BUGS 223Due to roundoff in the pitch tables and slop in the tone-generation and timer 224hardware (neither of which was designed for precision), neither pitch accuracy 225nor timings will be mathematically exact. 226.Pp 227There is no volume control. 228.Pp 229In play strings which are very long (longer than your system's physical I/O 230blocks) note suffixes or numbers may occasionally be parsed incorrectly due 231to crossing a block boundary. 232