Legacy Audio Engine Enabled Not Working

So @docEdub … Here is a small repo to test sound not working:

Viewer.tsx

 const engine = new Engine(canvas, antialias, { audioEngine: true }, adaptToDeviceRatio);

App.tsx

    const sx = new BABYLON.Sound(
        "loading",
        "https://raw.githubusercontent.com/onekit/gardener/master/public/sounds/loader/loading.ogg",
        scene,
        null,
        { autoplay: true, loop:true }
    );
    console.log("Legacy Sound: ", sx);

It might well have something to do with the 7.52.2 version since it was commented that it was working with the 7.51.3 version. Although that might not be the case since this example works perfectly well with 7.52.2.

I’ve tried to take that example and simulate it using my setup (with a audioEngine: true) but I just can’t get it to work. In my setup, that example failures while accessing the channels:

testing.1.2.3.testing:292 Uncaught TypeError: Cannot read properties of undefined (reading 'getChannelData')
    at createRibbonForNote (testing.1.2.3.testing:292:61)

What exactly does the playground do to get legacy audio to work?

There must be something else other than just audioEngine: true.

For backward compatibility they are enabling the old audio engine in playgrounds that contain BABYLON.Sound, even if the engine’s audioEngine option is set to false like in this playground: https://playground.babylonjs.com/#QARKUZ#5.

PR 16273 should fix the issue. When that PR is merged.

Exactly but when I do that with audioEngine: true in my setup, the old sound does not work. That’s what I can’t get my head around - there is something else - IMHO - going on in the playground to make the “old” audio engine still work.

Is there another external JS lib that needs to be included? Some addon?

Either way, something isn’t working … :-/

Awesome! Thank you. I found the issue and fixed it with PR 16278. The audioEngine: true option should work again when that PR gets merged and released.

You are awesome @docEdub

1 Like

As per usual the error was 40cm from the screen …

I just removed this include from my .html and audio began working:

<script src="https://cdn.babylonjs.com/recast.js"></script>

If I include that and use audioEngine: true, nothing happens - audio doesn’t work. Removing the recast.js and using audioEngine: true works as expected.

Sorry for the confusion!

1 Like

I tried to remove recast.js but I STILL dont hear any audio (Spatial or Regular). Hopefully the next PR fixes it for me :slight_smile:

This should be fixed with Babylon.js version 7.52.3, available now.

1 Like

How do unlock audio now that BABYLON.Engine.audioEngine.unlock is no more ?

Are you trying to unlock the old legacy audio engine, or a new one you created? Maybe post some example code of what you’re trying to do?

Unlock the old way… We used to do this:

    if (!BABYLON.Engine.audioEngine.unlocked)
    {
        BABYLON.Engine.audioEngine.unlock();
    }

Says deprecated and use Audio Engine 2. So wondering how to unlock when we want to use legacy audio engine

That should work if you’re using the old audio engine.

If you’re trying to unlock the new audio engine the same way, then that won’t work. You’ll have to call unlock on the new audio engine instance returned by CreateAudioEngineAsync.

Yep,I already do that

So your saying keep using the BABYLON.Engine.audioEngine.unlock() for legacy audio ?

Ya, you should be able to use the old audio engine exactly the same way it worked before as long as you turn it on with the audioEngine: true option in the graphics engine constructor.

Thanks :slight_smile: