AudioEngineV2 - Playing StaticSound on top of StreamingSound decreases FPS in iOS Safari

Should be pretty self-explanatory.

Repro Playground Link: https://playground.babylonjs.com/#32KBYA#1

It does take a bit for the FPS to drop after pressing play SFX but from my testing it does drop consistently.

It also depends on the hardware. The bug happens on an iPhone 11 but not on an iPad Pro 6th Gen.

One more thing to add is that even if you got rid of the StreamingSound, spamming the Play SFX button also decreases FPS, even though it recovers back to 60 for that. This is a huge problem for me as I am making a rhythm game and it has a lot of tap inputs with SFX feedback in a short while.

I actually had a similar problem a while back as well: Link.

EDIT: It also makes no difference when the BGM is a StaticSound as well.

Let me add @RaananW to the thread

Checking.

I can say that, with older devices (apple or not) it is sometimes hard to fix the issue, especially if it is a hardware problem. I’ll try to reproduce this locally and will keep you updated.

Can you try with the snapshot of thie PR - Add opt-out for iOS ringer switch audio workaround by RaananW · Pull Request #18886 · BabylonJS/Babylon.js · GitHub and let me know what the results of your tests?

Ok. I have tested it. It is just as you said in the PR description.

disableIOSRingerSwitchWorkaround: true increases the FPS back to normal, but audio doesn’t play if the ringer is silent.

Update: It appears this issue happens on the later hardware (iPad Pro 6th Gen) as well. It just takes quite a while longer for the FPS to drop. That’s why I didn’t notice it before.

it is sadly an iOS limitation. hmm…
Let me try moving around it. still thinking about the best solution for us.

So, your test confirms that the FPS degradation is caused by Babylon’s iOS ringer-switch workaround, rather than by StaticSound or StreamingSound specifically.

AudioEngineV2 currently plays a looping silent HTMLAudioElement while sounds are active so Web Audio remains audible when the physical ringer switch is set to silent. On affected iOS/iPadOS devices, keeping that media playback session active can reduce rendering performance.

I opened PR #18886, which adds an application-controlled opt-out:

const audioEngine = await BABYLON.CreateAudioEngineAsync({
    disableIOSRingerSwitchWorkaround: true,
});

The default behavior remains unchanged. Enabling the option avoids creating the silent media element and restores performance in this reproduction, but Web Audio will then obey the device’s silent switch and may be inaudible while silent mode is enabled.

At the moment, we do not have a verified solution that provides both normal rendering performance and silent-switch bypass. The Web Audio Audio Session API may be worth investigating separately on physical devices.

Thank you for your work! I guess this will have to do for now. It is a shame Apple always treats the web as second-class citizens.