Sound Library Reference
Procedures, command families, examples, and backend notes for FreeBASIC's built-in sound library.
Description
The sound library, or `sfxlib`, is the built-in audio layer used by FreeBASIC's sound commands. It covers generated tones, PLAY-string music, short sound effects, music file playback, MIDI commands, output device selection, and audio capture where the target backend supports it.
Programs that use these commands automatically request the sfxlib runtime. If a program does not use the sound command surface and needs words such as `Music`, `Sfx`, or `Device` as normal identifiers, define `FB_NO_SFXLIB` before those names are parsed.
For headless tests and package smoke tests, set `SFXLIB_DRIVER=null` before the program starts to use the null output driver.
Quick example
`
sound 440, 0.25
play "t140 o4 cdefgab"
sfx load 1, "click.wav"
sfx play 1
sleep 1000, 1
`
Generated Sound

BEEP: produces a beep or short pitched note. SOUND: plays a generated tone. TONE: plays a generated tone on a selected channel. NOISE: plays generated noise. NOTE: plays a named musical note. PLAY: plays BASIC PLAY strings. TEMPO: sets or returns PLAY-string tempo. CHANNEL: sets or returns the default generated-sound channel. | OCTAVE: sets or returns the default note octave. VOICE: sets or returns the default instrument. VOL: sets master volume. VOLUME: sets or returns master or channel volume. BALANCE: sets or returns master stereo balance. PAN: sets or returns channel stereo pan. WAVE: defines a generated waveform. ENVELOPE: defines an ADSR envelope. INSTRUMENT: defines or assigns an instrument.

Digital Audio and MIDI

- MUSIC: loads, plays, loops, pauses, resumes, stops, and queries the current music stream.
- SFX: loads and controls short sound effects by id or channel.
- MIDI: opens MIDI output, plays MIDI files, and sends MIDI messages where supported.

Devices, Backends, and Capture

- DEVICE: lists, selects, and queries sfxlib output devices.
- sfxlib backends: summarizes the output backends used on supported targets.
- CAPTURE: starts, pauses, resumes, stops, reads, and saves audio capture where available.