Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Audio Builtins

Audio builtins are available on native targets. On WASM they are no-ops.

Every builtin below is callable in all five languages — the aliases are accepted by the interpreter and produced by lingfu normalize.

Multilingual names

EN🇨🇳 ZH🇯🇵 JA🇰🇷 KO🇹🇭 TH
audio_tone音调音調음조เสียงโทน
audio_volume音量音量음량ระดับเสียง
audio_listener音频监听音声リスナー오디오리스너ผู้ฟัง
audio_bgm背景乐BGM배경음악เพลงพื้นหลัง
audio_bgm_volume背景乐音量BGM音量배경음악음량ระดับเสียงพื้นหลัง
fft_push频谱输入FFT入力FFT입력วิเคราะห์เสียง
fft_bands频段周波数帯주파수대แถบความถี่
fft_beat节拍检测ビート検出비트จังหวะเสียง
fft_rms均方根二乗平均RMS레벨ระดับRMS
fft_dominant_freq主频主要周波数주파수ความถี่หลัก

Tone synthesis

# audio_tone(slot, x, y, z, w,  freq_hz, amplitude, lfo_rate, lfo_depth)
audio_tone(0,  0.0, 0.0, 8.0,  1.5,   261.63, 0.08, 0.10, 0.008)
ParamDescription
slotTone slot index (0–15)
x, y, z3D world position of the sound source
wSpatial spread / falloff width
freq_hzOscillator frequency in Hz
amplitudeBase amplitude (0..1)
lfo_rateLFO modulation rate in Hz
lfo_depthLFO depth (0..1)

Volume

audio_volume(0.5)         # master volume
audio_bgm_volume(0.4)     # background music volume

Background music

audio_bgm("path/to/file.wav", 0.5)   # load and play WAV BGM

Listener position

# Must be called each frame to update 3D audio perspective
audio_listener(cos(ry), sin(ry), cos(rx), sin(rx))

Pentatonic reference

Common frequencies for East Asian pentatonic scales:

Note宫 (Gōng)商 (Shāng)角 (Jué)徵 (Zhǐ)羽 (Yǔ)
Octave 3C3 130.81D3 146.83E3 164.81G3 196.00A3 220.00
Octave 4C4 261.63D4 293.66E4 329.63G4 392.00A4 440.00
Octave 5C5 523.25D5 587.33E5 659.25G5 783.99A5 880.00

FFT analysis

# Push mono samples to the rolling FFT window
令 smp = list_new()
令 k = 0
循 k < 64 {
    令 smp = list_push(smp, sin(k * 0.1))
    令 k = k + 1
}
fft_push(smp)

# Get 32 log-spaced frequency bands (values 0..1)
令 bands = fft_bands(32)

# Beat detection
若 fft_beat() {
    印("beat!")
}
令 ratio = fft_beat_ratio()   # 1.0 = at threshold
令 rms   = fft_rms()
令 freq  = fft_dominant_freq()