How to override current audio ramp in audio engine v2

Hey there,

I am migrating my audio v1 code to the new v2 engine and noticed that using setVolume in quick successions now throws errors:

My use case is to toggle a music by clicking a button: click to fade-in, click again to fade-out. This means the second click can happen before the end of the fade-in ramp, thus throwing the error like in the PG.

What is the V2-friendly way to override the ramp in this case?

cc @docEdub

When a ramp has started, there is no way to override it. This is due to a limitation in Firefox. Mozilla has a fix for it that hasn’t made it into the latest Firefox release, yet. See 1752775 - WebAudio: cancelScheduledValues does not cancel in progress curve events.

There is a Codepen that reproduces the issue on Firefox: https://codepen.io/wemyss/pen/BamjNLW?editors=1011. When this works we can remove this limitation in the audio engine.

Until then, you can disable the button until the ramp ends, like in the documentation Playground: https://playground.babylonjs.com/#HDPCXJ#6, starting at line 69.

Alright! I think I will keep using V1 until this is fixed in Firefox and Babylon. Thanks for the info :slight_smile:

How are you doing the fade in/out in the V1 audio engine?

I have been using the setVolume(targetVolume, duration) method of v1 Sound instances. Calling it when a ramp was not finished simply stopped the ramp and started the new one.

Firefox supports canceling audio ramps, now, and the latest version of Babylon.js has been updated to cancel old ramps when new ones are created with setVolume.

That’s one unexpected good news :ok_hand: Thanks a lot! So no more throwing errors on setVolume?

Yep, no more errors on setVolume!

2 Likes