Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7375134
Reimplement legacy `Sound` class with new audio engine
docEdub Nov 14, 2025
eb0bcc4
Fix case where `Sound` is constructed but audio engine is not available
docEdub Nov 17, 2025
870db99
Fix sound not setting playback `loop` option correctly
docEdub Nov 17, 2025
8fb0eb7
Show unmute button when sound is set to autoplay and engine is locked
docEdub Nov 17, 2025
f2464f6
Fix `autoplay` property not being set correctly after `Sound` is cons…
docEdub Nov 18, 2025
ca391fe
Fix audio engine unlock when `useCustomUnlockedButton` is `true`
docEdub Nov 18, 2025
f26c933
Fix lint errors re: promises
docEdub Nov 18, 2025
811662b
Wait for Firefox to unlock audio context before playing after legit b…
docEdub Nov 18, 2025
8132365
Change `cancelScheduledValues` arg to `0` to ensure they're canceled …
docEdub Nov 18, 2025
1635d77
Fix autoplay issue
docEdub Nov 18, 2025
8b386d1
Return valid `GainNode` from `Sound.getSoundGain()`
docEdub Nov 18, 2025
d208ba9
Remove `stereoPan` option so stereo panner node doesn't override spat…
docEdub Nov 18, 2025
0c69771
Fix spatial `maxDistance` default for old `Sound` class
docEdub Nov 18, 2025
c7ab966
Fix spatial `distanceModel` default for old `Sound` class
docEdub Nov 18, 2025
f955b7a
Merge branch 'master' into 251114-reimplement-old-sound-class
docEdub Nov 24, 2025
cb7c031
Cleanup
docEdub Nov 24, 2025
5ca80ba
Fix `Sound.setVolume` when called before sound is ready
docEdub Nov 24, 2025
078dda0
Ensure `maxDistance = Number.MAX_VALUE` when `useCustomAttenuation = …
docEdub Nov 25, 2025
a4335cc
Fix initial volume when `useCustomAttenuation = true`
docEdub Nov 25, 2025
561690f
Make sure `maxDistance` get set to legacy default correctly if not sp…
docEdub Nov 25, 2025
4b4534c
Fix spatial audio Vector3 and Quaternion defaults getting changed
docEdub Nov 25, 2025
c2acd3d
Relax acceptable value ranges for realtime audio contexts
docEdub Nov 25, 2025
e9f715a
Relax acceptable value ranges for realtime audio contexts on flaky te…
docEdub Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dev/core/src/Audio/Interfaces/ISoundOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ISoundOptions {
* Define the distance attenuation model the sound will follow.
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
*/
distanceModel?: string;
distanceModel?: "linear" | "inverse" | "exponential";
/**
* Defines the playback speed (1 by default)
*/
Expand Down
23 changes: 13 additions & 10 deletions packages/dev/core/src/Audio/audioEngine.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Analyser } from "./analyser";

import type { Nullable } from "../types";
import { Observable } from "../Misc/observable";
import { AbstractEngine } from "../Engines/abstractEngine";
import type { IAudioEngine } from "./Interfaces/IAudioEngine";
import { _WebAudioEngine } from "../AudioV2/webAudio/webAudioEngine";
import type { _WebAudioMainBus } from "../AudioV2/webAudio/webAudioMainBus";
import { AbstractEngine } from "../Engines/abstractEngine";
import { Observable } from "../Misc/observable";
import type { Nullable } from "../types";
import type { Analyser } from "./analyser";
import type { IAudioEngine } from "./Interfaces/IAudioEngine";

// Sets the default audio engine to Babylon.js
AbstractEngine.AudioEngineFactory = (
Expand All @@ -22,7 +21,6 @@ AbstractEngine.AudioEngineFactory = (
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
*/
export class AudioEngine implements IAudioEngine {
private _audioContext: Nullable<AudioContext> = null;
private _masterGain: GainNode;
private _tryToRun = false;
private _useCustomUnlockedButton: boolean = false;
Expand Down Expand Up @@ -176,7 +174,7 @@ export class AudioEngine implements IAudioEngine {
* This is helpful to resume play once browser policies have been satisfied.
*/
public unlock() {
if (this._audioContext?.state === "running") {
if (this._v2._audioContext?.state === "running") {
if (!this.unlocked) {
// Notify users that the audio stack is unlocked/unmuted
this.unlocked = true;
Expand All @@ -192,10 +190,10 @@ export class AudioEngine implements IAudioEngine {

/** @internal */
public _resumeAudioContextOnStateChange(): void {
this._audioContext?.addEventListener(
this._v2._audioContext?.addEventListener(
"statechange",
() => {
if (this.unlocked && this._audioContext?.state !== "running") {
if (this.unlocked && this._v2._audioContext?.state !== "running") {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this._resumeAudioContextAsync();
}
Expand All @@ -214,6 +212,10 @@ export class AudioEngine implements IAudioEngine {
return Promise.resolve();
}

if (this._v2._audioContext.state === "suspended" && !this._useCustomUnlockedButton) {
this._v2._unmuteUIEnabled = true;
}

return this._v2._audioContext.resume();
}

Expand Down Expand Up @@ -261,6 +263,7 @@ export class AudioEngine implements IAudioEngine {

private async _triggerRunningStateAsync() {
if (this._tryToRun) {
void this._v2._audioContext.resume();
return;
}
this._tryToRun = true;
Expand Down
Loading
Loading