Audio System

OpenAL-based 3D positional audio with automatic WAV loading, spatial attenuation, and Doppler effect. Attach an AudioListenerComponent to the camera and AudioSourceComponent to sound-emitting entities.

# AudioListenerComponent

Represents the audio listener in the scene. Only one listener should be active at a time. The listener's position and orientation are synced from its entity's TransformComponent each frame by the audio system.

audio_listener.jl

# AudioSourceComponent

A mutable component that emits sound from an entity's position. Supports looping, pitch shifting, and configurable spatial attenuation. Set spatial=false for non-positional audio like background music or UI sounds.

audio_source.jl

# 3D Positional Audio

Spatial sources use inverse distance clamped attenuation. Volume decreases as the listener moves away from the source, controlled by three parameters: reference_distance, max_distance, and rolloff_factor. Doppler effect is computed automatically by OpenAL from relative velocities.

spatial_audio.jl

# WAV Loading

Audio files are loaded lazily on first use. The backend maintains a buffer cache so each WAV file is only read from disk once, regardless of how many sources reference it. Supports PCM 8-bit and 16-bit, mono and stereo.

wav_loading.jl

# Example: Scene with Audio

A complete scene with a camera listener, a spatial campfire sound source, and non-spatial background music.

audio_example.jl