Overview
Audio sources are the primary way to play audio in Atlas Engine. You can use either the low-levelAudioSource class or the high-level AudioPlayer component.
Loading Audio Files
Using AudioPlayer Component
TheAudioPlayer component is the recommended way to add audio to game objects:
test/main.cpp shows how to:
- Get the AudioPlayer component from the object
- Load an audio resource from the workspace
- Enable spatial audio for 3D positioning
- Set the audio to loop continuously
- Start playback
Using AudioSource Directly
For more control, you can useAudioSource directly:
Sharing Audio Data
For sounds that are played frequently, you can load the data once and share it:Playback Control
Basic Controls
Check Playback State
Play From Specific Time
Audio Properties
Volume
Control the volume of individual audio sources (0.0 to 1.0):Pitch
Adjust the playback speed and pitch:Looping
Set audio to repeat continuously:Supported Audio Formats
Finewave supports common audio formats including:- MP3: Compressed, good for music
- WAV: Uncompressed, low latency for sound effects
- OGG: Compressed, open format
Complete Example: Background Music
Complete Example: Sound Effects
Best Practices
Use AudioPlayer for Game Objects
Use AudioPlayer for Game Objects
The AudioPlayer component automatically handles updates and integrates with the component system. Use it for audio attached to objects in your scene.
Preload Frequently Used Sounds
Preload Frequently Used Sounds
Load AudioData once and share it across multiple AudioSource instances to save memory and loading time.
Set Appropriate Volume Levels
Set Appropriate Volume Levels
Balance your audio by setting relative volumes. Background music typically ranges from 0.3 to 0.7, while sound effects can be louder.
Use Correct Formats
Use Correct Formats
Use WAV for short, frequently played sound effects (low latency). Use MP3 or OGG for longer music tracks (smaller file size).
Next Steps
Spatial Audio
Learn how to add 3D positional audio to your sources