Generated Sound Commands
 
Commands for generated sound, PLAY strings, and sfxlib mix settings.

Syntax

Beep [ duration, pitch ]
Sound frequency, duration
Sound channel, frequency, duration, volume
Tone channel, frequency, duration
Noise channel, duration, volume
Noise channel, frequency, duration, volume
Note name, octave, duration
Note channel, name, octave, duration
Rest duration
Rest channel, duration
Play music
Play channel, music
Play music1, music2
Play music1, music2, music3
Tempo bpm
bpm = Tempo()
Channel channel
channel = Channel()
Octave octave
octave = Octave()
Voice instrument
instrument = Voice()
Vol level
Volume level
level = Volume()
Volume channel, level
level = Volume( channel )
Balance position
position = Balance()
Pan channel, position
position = Pan( channel )
Wave id, waveform
Envelope id, attack, decay, sustain, release
Instrument id, wave_id, envelope_id
Instrument channel, instrument_id

Description

These commands synthesize sound directly through sfxlib. Sound, Tone, Noise, Note, and Play create voices. Tempo, Channel, Octave, and Voice set defaults used by PLAY-string and generated-sound commands. Volume, Vol, Balance, and Pan control mix levels and stereo placement.

Sound also accepts several legacy BASIC-compatible integer forms used by older dialects. Those forms are provided so historical listings can compile with minimal changes; new code should prefer the frequency/duration or channel/frequency/duration/volume forms shown above.

Wave defines a waveform id. The currently supported waveform values are:
    • 0 sine
    • 1 square
    • 2 triangle
    • 3 saw
    • 4 noise

Envelope defines an ADSR envelope using seconds for attack, decay, and release, and a 0.0 to 1.0 sustain level. Instrument can define an instrument from a waveform and envelope, or assign an instrument to a channel.

The channel-oriented commands use sfxlib's channel table. Channels are zero-based.

Example

See examples/sfxlib/basics-01-generated-sound.bas, examples/sfxlib/basics-02-play-strings.bas, examples/sfxlib/basics-03-channels-mix.bas, examples/sfxlib/basics-04-instruments.bas, and examples/sfxlib/showcase.bas.

Platform Differences

  • On headless or diagnostic runs, SFXLIB_DRIVER=null can be set before program startup to use the null output driver.

Differences from QB

  • New to FreeBASIC.

See also