Procedures, command families, examples, and backend notes for FreeBASIC's built-in sound library.
The sound library, or
sfxlib, is the built-in audio layer used by FreeBASIC's new 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.
How sfxlib is arranged
Generated sound commands create tones, notes, PLAY strings, waveforms, envelopes, and instruments. The MUSIC family controls one current music stream. The SFX family loads and plays short reusable samples. MIDI sends MIDI commands where a backend supports MIDI. DEVICE selects the output backend, and CAPTURE records input where capture support exists.
For headless tests and package smoke tests, set SFXLIB_DRIVER=null before the program starts to use the null output driver.
Quick example
' generated tone
sound 440, 0.25
' PLAY-string phrase
play "t140 o4 cdefgab"
' short reusable sample
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.
Advanced sfxlib headers
Documents raw PCM output, underrun and sample-rate queries, final-output WAV recording, and whole-mix echo.