Migrating From The Old Audio Engine
Babylon 8.0 brought a new audio engine, which is faster, more powerful, and easier to use than the old audio engine.
How to continue using the old audio engine
The old audio engine is not going away! It is turned off by default now, but it can be enabled by setting the audioEngine option to true when creating the graphics engine with the Engine constructor, for example:
import { Engine } from "@babylonjs/core/Engines/engine";const engine = new Engine(canvas, true, { audioEngine: true }, true);Audio engine objects are created with functions
The old audio engine's Sound and SoundTrack objects are created using constructors and are dependent on the graphics engine and scene.
The new audio engine is fully decoupled from the graphics engine and scene, and its audio objects are created using async functions instead of constructors. Use the following functions to create new audio engine objects:
CreateAudioEngineAsyncCreateSoundAsyncCreateStreamingSoundAsyncCreateSoundBufferAsyncCreateAudioBusAsyncCreateMainAudioBusAsync
Or call the equivalent functions on the audio engine directly:
AudioEngineV2.createSoundAsyncAudioEngineV2.createStreamingSoundAsyncAudioEngineV2.createSoundBufferAsyncAudioEngineV2.createBusAsyncAudioEngineV2.createMainBusAsync
Sounds and streaming sounds are now separate classes
In the old audio engine, there is one Sound class for both static sounds and streaming sounds, and the streaming option is used to differentiate them. This is confusing because some sound options only apply to static sounds, and some streaming features do not work well across browsers so they should not be used.
To address these issues, the new audio engine has separate classes for static and streaming sounds, with a clear separation between the available options and features.
See the sound and streaming sound documentation for more information.
Sound tracks are now called audio buses
In the old audio engine, SoundTrack objects are used for audio routing and managing groups of sounds, and they can only route sounds, not other sound tracks. This makes creating extended audio routing chains impossible. Another limitation of sound tracks is they have no stereo or spatial audio features.
In the new audio engine, sound tracks are replaced by audio buses, which implement stereo and spatial audio, and allow their audio output to be routed to other audio bus objects using the AudioBus.outBus property.
Migration examples
| Description | Old playground | New playground | Notes |
|---|---|---|---|
| Spatial audio | #2AH4YH | #2AH4YH#188 | Thanks to dad72 |
Feature requests and bug fixes
To request new features or bug fixes, create a new topic at https://forum.babylonjs.com and tag @docEdub. Thanks!