Overview
Spatial audio (3D audio) makes sounds appear to come from specific positions in your 3D scene. Atlas Engine’s Finewave system provides automatic spatialization with distance attenuation, panning, and Doppler effects.How Spatial Audio Works
Spatial audio in Finewave:- Listener Position: Automatically synced with the active camera
- Source Position: Set via the audio source or attached object
- Attenuation: Volume decreases with distance
- Panning: Sound moves between left/right channels based on position
- Doppler Effect: Pitch shifts based on relative velocity
Enabling Spatialization
Using AudioPlayer Component
The AudioPlayer component makes spatial audio simple:test/main.cpp shows the key line: player->useSpatialization(). Once enabled, the AudioPlayer automatically:
- Updates the source position every frame based on the object’s position
- Syncs the listener position with the camera
- Updates listener orientation and velocity
Using AudioSource Directly
Disabling Spatialization
For global sounds like UI or background music:Automatic Listener Updates
The AudioPlayer component’supdate() method (from include/atlas/audio.h) automatically handles listener positioning:
Manual Listener Control
For custom camera setups, you can control the listener directly:Position-Based Audio Example
Ambient Environment Sounds
Moving Audio Source
Distance Attenuation
Finewave automatically attenuates audio based on distance from the listener. The further away a source is, the quieter it becomes.Doppler Effect
The Doppler effect changes pitch based on relative velocity between source and listener:Query Position Information
You can query spatial audio positions at runtime:Complete Scene Example
Best Practices
Use Spatialization for Diegetic Sounds
Use Spatialization for Diegetic Sounds
Enable spatialization for sounds that exist within the game world (footsteps, object interactions, environment sounds). Disable it for UI sounds and background music.
AudioPlayer Handles Updates Automatically
AudioPlayer Handles Updates Automatically
When using AudioPlayer component, you don’t need to manually update source or listener positions. The component handles this in its update() method.
Mono Audio for Spatialization
Mono Audio for Spatialization
Spatial audio works best with mono audio files. Stereo files may not pan correctly in 3D space. Finewave can automatically convert stereo to mono when needed.
Consider Performance
Consider Performance
Spatial audio calculations happen every frame. For scenes with many audio sources, consider deactivating distant or inaudible sources.
Next Steps
Audio Effects
Add reverb, echo, and distortion to your spatial audio