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