Add partial support to Audio through Miniaudio#1765
Open
yuripourre wants to merge 6 commits into
Open
Conversation
Introduce the WebAudio polyfill with browser-aligned AudioContext lifecycle, scheduled buffer-source start times, a built-in document stub, and platform PreparePlayback hooks for mobile session setup.
Initialize the polyfill from Runtime, suspend/resume playback with app lifecycle, and wire iOS AVAudioSession plus Android audio-focus handling.
Cover suspended-by-default contexts, resume, automation, analysers, natural ended events, and scheduled buffer-source start times for headless CI.
Bundle and load audio.js on iOS and Android, copy babylonjs.addons.js into Android assets, and resume AudioContext on user gesture for mobile autoplay.
Point readers to the WebAudio polyfill readme for platform coverage and mobile validation guidance.
Resume AudioContext on audio.js load so legacy Sound autoplay works on desktop, and add createTextNode to the built-in document stub for Babylon v9 audio engine initialization.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a miniaudio-backed Web Audio polyfill so Babylon.js audio works on native Embedding hosts (desktop and mobile).
New Polyfills/WebAudio
Implements the Web Audio subset Babylon.js uses: AudioContext (starts suspended), decodeAudioData, buffer sources with scheduled start(when), gain/panner/stereo panner, AudioListener, AudioParam automation, AnalyserNode, and HTMLAudioElement.canPlayType. Playback device is opened lazily on first resume().
Platform hooks
PreparePlayback / interruption callbacks for iOS (AVAudioSession) and Android (audio focus via JNI). Any app linking BabylonNativeEmbedding gets session setup without custom native code.
Embedding integration
WebAudio::Initialize from Runtime; Suspend/Resume pauses the shared audio device when the app backgrounds; built-in document stub when globalThis.document is missing.
CI / headless
BABYLON_NATIVE_WEBAUDIO_BACKEND=null uses a software clock so graph/lifecycle tests run without hardware.
Tests
New JavaScript.All WebAudio cases (suspended context, resume(), automation, analysers, natural ended, scheduled start(when)).
Playground harness
New Scripts/audio.js (click-to-beep + optional spatial BABYLON.Sound). iOS/Android Playground entry points load audio.js + playground_runner.js instead of experience.js for on-device audio validation. Android Gradle also copies missing babylonjs.addons.js into assets.
Design notes