spkr.4 revision 1099
150477Speter.Dd November 7, 1993 249611Swpaul.Dt SPKR 4 3181741Simp.Os FreeBSD 449611Swpaul.Sh NAME 570711Sobrien.Nm spkr 6150636Smlaier.Nd console speaker device driver 770711Sobrien.Sh SYNOPSIS 870711Sobrien.Cd pseudo-device speaker 960966Speter.Fd #include <machine/speaker.h> 10.Sh DESCRIPTION 11The speaker device driver allows applications to control the PC console 12speaker on an 13.Tn IBM-PC Ns --compatible 14machine running FreeBSD. 15.Pp 16Only one process may have this device open at any given time; 17.Xr open 2 18and 19.Xr close 2 20are used to lock and relinquish it. An attempt to open when 21another process has the device locked will return -1 with an 22.Er EBUSY 23error 24indication. Writes to the device are interpreted as `play strings' in a 25simple ASCII melody notation. An 26.Xr ioctl 2 27request 28for tone generation at arbitrary 29frequencies is also supported. 30.Pp 31Sound-generation does not monopolize the processor; in fact, the driver 32spends most of its time sleeping while the PC hardware is emitting 33tones. Other processes may emit beeps while the driver is running. 34.Pp 35Applications may call 36.Xr ioctl 2 37on a speaker file descriptor to control the 38speaker driver directly; definitions for the 39.Xr ioctl 2 40interface are in 41.Pa /usr/include/machine/speaker.h . 42The 43.Li tone_t 44structure used in these calls has two fields, 45specifying a frequency (in Hz) and a duration (in 1/100ths of a second). 46A frequency of zero is interpreted as a rest. 47.Pp 48At present there are two such 49.Xr ioctl 2 50calls. 51.Dv SPKRTONE 52accepts a pointer to a 53single tone structure as third argument and plays it. 54.Dv SPKRTUNE 55accepts a 56pointer to the first of an array of tone structures and plays them in 57continuous sequence; this array must be terminated by a final member with 58a zero duration. 59.Pp 60The play-string language is modelled on the PLAY statement conventions of 61.Tn IBM 62Advanced BASIC 2.0. The 63.Li MB , 64.Li MF , 65and 66.Li X 67primitives of PLAY are not 68useful in a timesharing environment and are omitted. The `octave-tracking' 69feature and the slur mark are new. 70.Pp 71There are 84 accessible notes numbered 1-83 in 7 octaves, each running from 72C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts 73with middle C. By default, the play function emits half-second notes with the 74last 1/16th second being `rest time'. 75.Pp 76Play strings are interpreted left to right as a series of play command groups; 77letter case is ignored. Play command groups are as follows: 78.Bl -tag -width CDEFGABxx 79.It Li CDEFGAB 80Letters A through G cause the corresponding note to be played in the 81current octave. A note letter may optionally be followed by an 82.Dq Em "accidental sign" , 83one of # + or -; the first two of these cause it to be sharped one 84half-tone, the last causes it to be flatted one half-tone. It may 85also be followed by a time value number and by sustain dots (see 86below). Time values are interpreted as for the L command below. 87.It Ns Li O Sy n 88If 89.Sy n 90is numeric, this sets the current octave. 91.Sy n 92may also be one of 93.Li L 94or 95.Li N 96to enable or disable octave-tracking (it is disabled by default). 97When octave-tracking is on, interpretation of a pair of letter notes 98will change octaves if necessary in order to make the smallest 99possible jump between notes. Thus ``olbc'' will be played as 100``olb>c'', and ``olcb'' as ``olc<b''. Octave locking is disabled for 101one letter note following >, < and O[0123456]. (The octave-locking 102feature is not supported in 103.Tn IBM 104BASIC.) 105.It Li > 106Bump the current octave up one. 107.It Li < 108Drop the current octave down one. 109.It Ns Li N Sy n 110Play note 111.Sy n , 112.Sy n 113being 1 to 84 or 0 for a rest of current time value. 114May be followed by sustain dots. 115.It Ns Li L Sy n 116Sets the current time value for notes. The default is 117.Li L4 , 118quarter or crotchet notes. The lowest possible value is 1; values up 119to 64 are accepted. 120.Li L1 121sets whole notes, 122.Li L2 123sets half notes, 124.Li L4 125sets quarter notes, etc. 126.It Ns Li P Sy n 127Pause (rest), with 128.Sy n 129interpreted as for 130.Ns Li L Sy n . 131May be followed by 132sustain dots. May also be written 133.Li ~ . 134.It Ns Li T Sy n 135Sets the number of quarter notes per minute; default is 120. Musical 136names for common tempi are: 137 138.Bd -literal -offset indent 139 Tempo Beats Per Minute 140very slow Larghissimo 141 Largo 40-60 142 Larghetto 60-66 143 Grave 144 Lento 145 Adagio 66-76 146slow Adagietto 147 Andante 76-108 148medium Andantino 149 Moderato 108-120 150fast Allegretto 151 Allegro 120-168 152 Vivace 153 Veloce 154 Presto 168-208 155very fast Prestissimo 156.Ed 157.It Li M[LNS] 158Set articulation. 159.Li MN 160.Ns No ( Li N 161for normal) is the default; the last 1/8th of 162the note's value is rest time. You can set 163.Li ML 164for legato (no rest space) or 165.Li MS 166for staccato (1/4 rest space). 167.El 168.Pp 169Notes (that is, 170.Li CDEFGAB 171or 172.Li N 173command character groups) may be followed by 174sustain dots. Each dot causes the note's value to be lengthened by one-half 175for each one. Thus, a note dotted once is held for 3/2 of its undotted value; 176dotted twice, it is held 9/4, and three times would give 27/8. 177.Pp 178A note and its sustain dots may also be followed by a slur mark (underscore). 179This causes the normal micro-rest after the note to be filled in, slurring it 180to the next one. (The slur feature is not supported in 181.Tn IBM 182BASIC.) 183.Pp 184Whitespace in play strings is simply skipped and may be used to separate 185melody sections. 186.Sh BUGS 187Due to roundoff in the pitch tables and slop in the tone-generation and timer 188hardware (neither of which was designed for precision), neither pitch accuracy 189nor timings will be mathematically exact. There is no volume control. 190.Pp 191The action of two or more sustain dots does not reflect standard musical 192notation, in which each dot adds half the value of the previous dot 193modifier, not half the value of the note as modified. Thus, a note dotted 194once is held for 3/2 of its undotted value; dotted twice, it is held 7/4, 195and three times would give 15/8. The multiply-by-3/2 interpretation, 196however, is specified in the 197.Tn IBM 198BASIC manual and has been retained for 199compatibility. 200.Pp 201In play strings which are very long (longer than your system's physical I/O 202blocks) note suffixes or numbers may occasionally be parsed incorrectly due 203to crossing a block boundary. 204.Sh FILES 205.Bl -tag -width /dev/speakerxx 206.It Pa /dev/speaker 207speaker device file 208.El 209.Sh AUTHOR 210Eric S. Raymond <esr@snark.thyrsus.com) June 1990 211.Sh "PORTED BY" 212Andrew A. Chernov <ache@astral.msk.su> 213.Sh HISTORY 214The 215.Nm 216device appeared in 217.Fx 1.0 . 218