Its really not that bad. @docEdub did an excellent job in implementing the new audio engine (Kudos to him).
The main thing to take away is that you have to create (and save a reference to) an AudioEngineV2 object. Think of it like a master mixer and the volume like properties at the this master mixer level is for ALL the sounds playing.
So you create your main audio engine (can be one line of code):
const audioEngine = await BABYLON.CreateAudioEngineAsync(...options...go...here);
await audioEngine.unlock(); // Note: You can optionally unlock audio here or before you play a track
audioEngine.volume = 0.5; // Note: This is optional to set the master volume level
Then create your sound type. So instead of directly instantiating a legacy new BABYLON.Sound object, after you create an audio engine. You create an instance of the sound type want, static, streaming or buffer:
const sound = await BABYLON.CreateSoundAsync("Sound 1", "assets/sounds/test.mp3", { loop: true, autoplay: true });
sound.volume = 1.0; // Note: This is optional to set the track volume level
So you can still create and play a sound with just a few lines of code:
// Create master audio engine
const audioEngine = await BABYLON.CreateAudioEngineAsync(...options...go...here);
await audioEngine.unlock();
// Create and auto play a track
await BABYLON.CreateSoundAsync("Sound 1", "assets/sounds/test.mp3", { loop: true, autoplay: true });
Ok, I do appreciate your help here. This indeed looks easy. But if you have, in your existing app, sounds defined as attributes of many different object, this messes things up quite a bit.
In that case you can enable the legacy audio engine when you create your BABYLON.Engine or BABYLON.WebEngine. Then you dont have to change your existing code.
Its actually audioEngine not audioEnabled
var engine = BABYLON.Engine(canvas, true, { audioEngine: true }, true);
Yo @docEdub … Can you add your two cents about how long the legacy audio engine will be supported, Always ? Or will it eventually be phased out ?
I use audioEngine.createSoundAsync instead of BABYLON.CreateAudioEngineAsync. But its all probably the same underneath. I just like the flow better, Create my audio engine and use that to create my sounds. I use BABYLON.StaticSound mostly… and it has the normal play, stop, pause, pitch, volume, etc properties.
Hey all, just a quick heads up that I changed the names of the async functions for the 8.0 release to have Async at the end to make them consistent with the rest of the Babylon.js framework. So for example audioEngine.unlock() is now audioEngine.unlockAsync().