Three things a game could not say, each of which had been worked around. Audio.play_at(id, gain:, pitch:, pan:) fires a one-shot with its own gain, pitch and stereo position. Audio.volume and Audio.pitch are global - they are the options screen - so a game placing a sound in the world was fighting them, and distance attenuation was simply not expressible. The backend already took volume and rate per call; this adds setPan: alongside them and stops routing through the master state. ludic.render3d gains outline_model(model, mat, width, r, g, b): a rim around something that is not an Actor. The outline pass walked the actor list and stopped, so instanced scatter - a forest - could not be highlighted at all. It is a queue flushed by the same pass, which is what gets the depth test right when the caller does not control pass order. And terrain_coast(cx, cz, margin, fall), the other way to make an island: the sea around the survey's own edge rather than cut out of the middle of it. terrain_island measures a radius from a centre, which drowns two thirds of a real survey to make an island of the rest; this measures inward from the boundary, so everything the data covers stays land and the coast is where the data runs out. Both modes gained a strand - the last few metres of height either side of the water line compressed, which stretches a cliff plunge out into beach and shallows. 132 regression tests and the self-host fixpoints pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
39 lines
2.3 KiB
Text
39 lines
2.3 KiB
Text
# audio.ludic — the Audio.* standard library (#22). Sound effects and music over
|
|
# the platform audio backend (AVAudioPlayer on macOS). A sound is loaded once
|
|
# into a handle; sfx fire one-shot, music loops on a single channel; master
|
|
# volume and pitch apply across everything, and Audio.play_at fires one shot with
|
|
# its own gain, pitch and stereo position without touching them.
|
|
#
|
|
# Playback is out-of-band — the audio device is real-time, not part of the
|
|
# deterministic simulation — but every trigger is an ordinary frame-driven call,
|
|
# so a recorded run replays the same sounds at the same frames. Headless (no
|
|
# window) every call is a safe no-op: load returns 0 and is_playing returns
|
|
# false, so the same code runs under the test harness. A full headless run:
|
|
# bin/ludic examples/library/audio.ludic -> 0 0 0 0 1
|
|
program AudioDemo {
|
|
function bi(b: bool) -> int { if b { return 1 }; return 0 }
|
|
|
|
entry {
|
|
let sfx = Audio.load("assets/sfx/blip.wav") # 0 headless (no audio device)
|
|
let mus = Audio.load("assets/music/theme.ogg") # 0 headless
|
|
print(sfx) # 0
|
|
print(mus) # 0
|
|
|
|
Audio.volume(0.8) # master volume, 0.0..1.0
|
|
Audio.pitch(1.25) # playback rate / pitch
|
|
Audio.play(sfx) # one-shot sound effect
|
|
# the per-voice version: a sound placed in the world rather than the master settings.
|
|
# This is what distance attenuation is made of - work out how far away and which side
|
|
# it is, and say so. gain rides on top of the master volume, so the options screen wins.
|
|
Audio.play_at(id: sfx, gain: 0.35, pitch: 0.9, pan: -0.6)
|
|
Audio.play_at(sfx, 0.35, 0.9, -0.6) # or positionally, which a tight loop prefers
|
|
Audio.play_music(mus) # looping background music
|
|
print(bi(Audio.is_playing(sfx))) # 0 headless
|
|
|
|
Audio.stop(sfx) # stop one sound
|
|
Audio.stop_music() # stop the music channel
|
|
Audio.stop_all() # stop everything
|
|
print(bi(Audio.is_playing(mus))) # 0
|
|
print(1) # 1 — every call returned cleanly
|
|
}
|
|
}
|