-
Notifications
You must be signed in to change notification settings - Fork 4
Audio
The Audio library handles loading and caching audio buffers loaded from a file. It also supports playing audio, looping audio, as well as mixing ambient noises (in development).
Before playing your sounds, you'll need to load them individually or many by file (preferred). Sounds are loaded via the Web Audio API.
Many Sounds
If you want to have a set (or all) of your sounds loaded at once, say, before starting the render loop, you can call
await Audio.get().loadAllFromFile('path/to/sounds.json');
Where sounds.json
is a file containing a manifest of all audio files you would like to load.
{
"example": {
"extension": "wav",
"volume": 0.5
}
}
Individual Sound
In order to load an individual sound, you'll need to call
const sound = await Audio.get().loadSound(directory, name, options);
In order to play the sounds you've loaded, simply call
Audio.get().playSound(name);
For continuous looping audio (such as engine sounds, lights humming, etc), you can use
Audio.get().playSoundOnLoop(name);
The Audio library does not support mixing looped audio, so you'll need to make sure your audio loops properly.
Ambient sound mixing is not yet ready for use.
- Three.js currently supports Audio via the Web Audio API as well. It might be wise to integrate these Audio objects (especially positional audio) into ERA.