SPKR(4)
β¨ SPKR(4) β speaker, spkr β¨
okay bestie, gather round π this is the manual page for the console speaker device driver β you know, that little beeper inside your IBM-PC-compatible machine? she's tiny, she's iconic, and she's about to make sounds you did not know a computer could make. section 4 energy, Kernel Interfaces Manual, let's GO π
πΈ SYNOPSIS πΈ
device speaker
#include <dev/speaker/speaker.h>
π DESCRIPTION π
So. The speaker device driver lets applications control the PC console speaker on an IBM-PCβcompatible machine running FreeBSD. That's the whole gig. She beeps. On purpose. With style. π₯
Only one process may have this device open at any given time β open(2) and close(2) are how you lock it and how you give it back. If you try to open it while somebody else has it locked, you get -1 with an EBUSY error indication. so rude of them, but fair tbh. π
Writes to the device are interpreted as play strings in a simple ASCII melody notation. There's also an ioctl(2) request for tone generation at arbitrary frequencies, if you're feeling β¨fancyβ¨.
good news: sound-generation does not monopolize the processor. fr fr. The driver spends most of its time sleeping while the PC hardware is out there emitting tones, which means other processes can still emit beeps while the driver is running. multitasking queen π
Applications may call ioctl(2) on a speaker file descriptor to control the speaker driver directly; the definitions for the ioctl(2) interface live in <dev/speaker/speaker.h>. The tone_t structure used in these calls has two fields, specifying a frequency (in Hz) and a duration (in 1/100ths of a second). A frequency of zero is interpreted as a rest. silence, but make it intentional π«Ά
At present there are two such ioctl(2) calls:
SPKRTONEβ accepts a pointer to a single tone structure as third argument and plays it. one note. one moment. slay.SPKRTUNEβ accepts a pointer to the first of an array of tone structures and plays them in continuous sequence; this array must be terminated by a final member with a zero duration. do not forget the zero-duration terminator bestie, she will simply keep reading π
The play-string language is modeled on the PLAY statement conventions of IBM Advanced BASIC 2.0. The MB, MF, and X primitives of PLAY are not useful in a timesharing environment and are omitted. The octave-tracking feature and the slur mark are new. β¨ upgrade era β¨
There are 84 accessible notes numbered 1-84 in 7 octaves, each running from C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3 starts with middle C. By default, the play function emits half-second notes with the last 1/16th second being rest time. lil breather. self care. πΈ
Play strings are interpreted left to right as a series of play command groups; letter case is ignored. The play command groups are as follows:
CDEFGABβ Letters A through G cause the corresponding note to be played in the current octave. A note letter may optionally be followed by an "accidental sign", one of#+or-; the first two of these cause it to be sharped one half-tone, the last causes it to be flatted one half-tone. It may also be followed by a time value number and by sustain dots (see below). Time values are interpreted as for theLcommand below.O nβ If n is numeric, this sets the current octave. n may also be one ofLorNto enable or disable octave-tracking (it is disabled by default). When octave-tracking is on, interpretation of a pair of letter notes will change octaves if necessary in order to make the smallest possible jump between notes. Thusolbc'' will be played asolb>c'', andolcb'' asolc<b''. Octave locking is disabled for one letter note following>,<andO[0123456]. (The octave-locking feature is not supported in IBM BASIC.)>β Bump the current octave up one. β¬οΈ<β Drop the current octave down one. β¬οΈN nβ Play note n, n being1to84or0for a rest of current time value. May be followed by sustain dots.L nβ Sets the current time value for notes. The default isL4, quarter or crotchet notes. The lowest possible value is1; values up to64are accepted.L1sets whole notes,L2sets half notes,L4sets quarter notes, etc.P nβ Pause (rest), with n interpreted as forL n. May be followed by sustain dots. May also be written~.T nβ Sets the number of quarter notes per minute; default is120. Musical names for common tempi are:- very slow β
Larghissimo - very slow β
Largo,40-60 - very slow β
Larghetto,60-66 - very slow β
Grave - very slow β
Lento - very slow β
Adagio,66-76 - slow β
Adagietto - slow β
Andante,76-108 - medium β
Andantino - medium β
Moderato,108-120 - fast β
Allegretto - fast β
Allegro,120-168 - fast β
Vivace - fast β
Veloce - fast β
Presto,168-208 - very fast β
Prestissimo
- very slow β
M[LNS]β Set articulation.MN(N for normal) is the default; the last1/8thof the note's value is rest time. You can setMLfor legato (no rest space) orMSfor staccato (1/4rest space).
Notes (that is, CDEFGAB or N command character groups) may be followed by sustain dots. Each dot causes the note's value to be lengthened by one-half for each one. Thus, a note dotted once is held for 3/2 of its undotted value; dotted twice, it is held 9/4, and three times would give 27/8. math girlie π
A note and its sustain dots may also be followed by a slur mark (_, underscore). This causes the normal micro-rest after the note to be filled in, slurring it to the next one. (The slur feature is not supported in IBM BASIC.)
Whitespace in play strings is simply skipped and may be used to separate melody sections. whitespace as aesthetic. we love to see it π¦
π FILES π
/dev/speakerβ speaker device file
π SEE ALSO π
π HISTORY π
The speaker device appeared in FreeBSD 1.0. ancient. legendary. she's been beeping since the beginning π
π AUTHORS π
Eric S. Raymond <esr@snark.thyrsus.com>, June 1990
π«Ά PORTED BY π«Ά
Andrew A. Chernov <ache@astral.msk.su>
π BUGS π
okay so listen. Due to roundoff in the pitch tables and slop in the tone-generation and timer hardware (neither of which was designed for precision), neither pitch accuracy nor timings will be mathematically exact. There is no volume control. so she's vibes-based, not science-based π
The action of two or more sustain dots does not reflect standard musical notation, in which each dot adds half the value of the previous dot modifier, not half the value of the note as modified. Thus, a note dotted once is held for 3/2 of its undotted value; dotted twice, it is held 7/4, and three times would give 15/8. The multiply-by-3/2 interpretation, however, is specified in the IBM BASIC manual and has been retained for compatibility. yes it's weird. no we're not changing it. periodt. π
In play strings which are very long (longer than your system's physical I/O blocks) note suffixes or numbers may occasionally be parsed incorrectly due to crossing a block boundary.
so keep your play strings reasonable, bestie. long ones can trip over a block boundary and misparse a note suffix or a number, and that's just how it is. π«
k that's the whole page!! this one came from the Debian crew and it's dated November 10, 2005, and yes, SPKR(4) really is the girlies' beep bible. go make some noise, you've earned it πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms