@babylonjs/core 7.51.2 → 7.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Audio/Interfaces/IAudioEngineOptions.d.ts +2 -0
- package/Audio/Interfaces/IAudioEngineOptions.js.map +1 -1
- package/AudioV2/abstractAudio/abstractAudioBus.d.ts +22 -0
- package/AudioV2/abstractAudio/abstractAudioBus.js +35 -0
- package/AudioV2/abstractAudio/abstractAudioBus.js.map +1 -0
- package/AudioV2/abstractAudio/abstractAudioNode.d.ts +99 -0
- package/AudioV2/abstractAudio/abstractAudioNode.js +149 -0
- package/AudioV2/abstractAudio/abstractAudioNode.js.map +1 -0
- package/AudioV2/abstractAudio/abstractSound.d.ts +152 -0
- package/AudioV2/abstractAudio/abstractSound.js +202 -0
- package/AudioV2/abstractAudio/abstractSound.js.map +1 -0
- package/AudioV2/abstractAudio/abstractSoundInstance.d.ts +34 -0
- package/AudioV2/abstractAudio/abstractSoundInstance.js +35 -0
- package/AudioV2/abstractAudio/abstractSoundInstance.js.map +1 -0
- package/AudioV2/abstractAudio/audioBus.d.ts +48 -0
- package/AudioV2/abstractAudio/audioBus.js +53 -0
- package/AudioV2/abstractAudio/audioBus.js.map +1 -0
- package/AudioV2/abstractAudio/audioEngineV2.d.ts +193 -0
- package/AudioV2/abstractAudio/audioEngineV2.js +155 -0
- package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -0
- package/AudioV2/abstractAudio/index.d.ts +10 -0
- package/AudioV2/abstractAudio/index.js +12 -0
- package/AudioV2/abstractAudio/index.js.map +1 -0
- package/AudioV2/abstractAudio/mainAudioBus.d.ts +22 -0
- package/AudioV2/abstractAudio/mainAudioBus.js +18 -0
- package/AudioV2/abstractAudio/mainAudioBus.js.map +1 -0
- package/AudioV2/abstractAudio/mainAudioOut.d.ts +13 -0
- package/AudioV2/abstractAudio/mainAudioOut.js +15 -0
- package/AudioV2/abstractAudio/mainAudioOut.js.map +1 -0
- package/AudioV2/abstractAudio/staticSound.d.ts +134 -0
- package/AudioV2/abstractAudio/staticSound.js +113 -0
- package/AudioV2/abstractAudio/staticSound.js.map +1 -0
- package/AudioV2/abstractAudio/staticSoundBuffer.d.ts +46 -0
- package/AudioV2/abstractAudio/staticSoundBuffer.js +17 -0
- package/AudioV2/abstractAudio/staticSoundBuffer.js.map +1 -0
- package/AudioV2/abstractAudio/staticSoundInstance.d.ts +15 -0
- package/AudioV2/abstractAudio/staticSoundInstance.js +5 -0
- package/AudioV2/abstractAudio/staticSoundInstance.js.map +1 -0
- package/AudioV2/abstractAudio/streamingSound.d.ts +77 -0
- package/AudioV2/abstractAudio/streamingSound.js +109 -0
- package/AudioV2/abstractAudio/streamingSound.js.map +1 -0
- package/AudioV2/abstractAudio/streamingSoundInstance.d.ts +25 -0
- package/AudioV2/abstractAudio/streamingSoundInstance.js +29 -0
- package/AudioV2/abstractAudio/streamingSoundInstance.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.d.ts +53 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js +97 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.d.ts +13 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.js +33 -0
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/audioSubNode.d.ts +6 -0
- package/AudioV2/abstractAudio/subNodes/audioSubNode.js +8 -0
- package/AudioV2/abstractAudio/subNodes/audioSubNode.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.d.ts +31 -0
- package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js +46 -0
- package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.d.ts +19 -0
- package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.js +27 -0
- package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.js.map +1 -0
- package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.d.ts +28 -0
- package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js +24 -0
- package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.d.ts +187 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js +41 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.d.ts +59 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js +21 -0
- package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.d.ts +38 -0
- package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.js +18 -0
- package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/index.d.ts +3 -0
- package/AudioV2/abstractAudio/subProperties/index.js +4 -0
- package/AudioV2/abstractAudio/subProperties/index.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudio.d.ts +49 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudio.js +129 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudio.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudioListener.d.ts +9 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js +22 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js.map +1 -0
- package/AudioV2/abstractAudio/subProperties/stereoAudio.d.ts +11 -0
- package/AudioV2/abstractAudio/subProperties/stereoAudio.js +18 -0
- package/AudioV2/abstractAudio/subProperties/stereoAudio.js.map +1 -0
- package/AudioV2/audioUtils.d.ts +3 -0
- package/AudioV2/audioUtils.js +6 -0
- package/AudioV2/audioUtils.js.map +1 -0
- package/AudioV2/index.d.ts +3 -0
- package/AudioV2/index.js +5 -0
- package/AudioV2/index.js.map +1 -0
- package/AudioV2/soundState.d.ts +29 -0
- package/AudioV2/soundState.js +31 -0
- package/AudioV2/soundState.js.map +1 -0
- package/AudioV2/webAudio/index.d.ts +5 -0
- package/AudioV2/webAudio/index.js +6 -0
- package/AudioV2/webAudio/index.js.map +1 -0
- package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.d.ts +59 -0
- package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js +156 -0
- package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js.map +1 -0
- package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.d.ts +24 -0
- package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.js +55 -0
- package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.js.map +1 -0
- package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.d.ts +24 -0
- package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.js +55 -0
- package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.js.map +1 -0
- package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.d.ts +26 -0
- package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.js +54 -0
- package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.js.map +1 -0
- package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.d.ts +21 -0
- package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.js +112 -0
- package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.js.map +1 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudio.d.ts +10 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudio.js +26 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudio.js.map +1 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudioListener.d.ts +4 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js +108 -0
- package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js.map +1 -0
- package/AudioV2/webAudio/webAudioBus.d.ts +35 -0
- package/AudioV2/webAudio/webAudioBus.js +63 -0
- package/AudioV2/webAudio/webAudioBus.js.map +1 -0
- package/AudioV2/webAudio/webAudioEngine.d.ts +110 -0
- package/AudioV2/webAudio/webAudioEngine.js +227 -0
- package/AudioV2/webAudio/webAudioEngine.js.map +1 -0
- package/AudioV2/webAudio/webAudioMainBus.d.ts +29 -0
- package/AudioV2/webAudio/webAudioMainBus.js +64 -0
- package/AudioV2/webAudio/webAudioMainBus.js.map +1 -0
- package/AudioV2/webAudio/webAudioMainOut.d.ts +20 -0
- package/AudioV2/webAudio/webAudioMainOut.js +35 -0
- package/AudioV2/webAudio/webAudioMainOut.js.map +1 -0
- package/AudioV2/webAudio/webAudioNode.d.ts +24 -0
- package/AudioV2/webAudio/webAudioNode.js +2 -0
- package/AudioV2/webAudio/webAudioNode.js.map +1 -0
- package/AudioV2/webAudio/webAudioStaticSound.d.ts +106 -0
- package/AudioV2/webAudio/webAudioStaticSound.js +368 -0
- package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -0
- package/AudioV2/webAudio/webAudioStreamingSound.d.ts +94 -0
- package/AudioV2/webAudio/webAudioStreamingSound.js +358 -0
- package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -0
- package/Engines/ICanvas.d.ts +96 -1
- package/Engines/ICanvas.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +7 -1
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureManager.js +3 -3
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
- package/Engines/abstractEngine.d.ts +11 -1
- package/Engines/abstractEngine.js +12 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.common.js +0 -4
- package/Engines/engine.common.js.map +1 -1
- package/Engines/engine.d.ts +0 -1
- package/Engines/engine.js +0 -1
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.d.ts +7 -1
- package/Engines/nativeEngine.js +12 -0
- package/Engines/nativeEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.d.ts +5 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.js +16 -5
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.js.map +1 -1
- package/Layers/effectLayer.d.ts +5 -0
- package/Layers/effectLayer.js +7 -0
- package/Layers/effectLayer.js.map +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.js +33 -20
- package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
- package/Loading/sceneLoader.d.ts +25 -11
- package/Loading/sceneLoader.js +28 -11
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Textures/hdrCubeTexture.js +4 -1
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/material.js +1 -0
- package/Materials/material.js.map +1 -1
- package/Meshes/csg2.d.ts +2 -2
- package/Meshes/csg2.js +2 -2
- package/Meshes/csg2.js.map +1 -1
- package/Meshes/geometry.js +7 -15
- package/Meshes/geometry.js.map +1 -1
- package/Meshes/instancedMesh.d.ts +5 -0
- package/Meshes/instancedMesh.js +6 -0
- package/Meshes/instancedMesh.js.map +1 -1
- package/Misc/environmentTextureTools.js +2 -2
- package/Misc/environmentTextureTools.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +26 -18
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
- package/Shaders/ShadersInclude/shadowMapFragment.js +1 -0
- package/Shaders/ShadersInclude/shadowMapFragment.js.map +1 -1
- package/Shaders/iblCdfDebug.fragment.js +2 -2
- package/Shaders/iblCdfDebug.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/shadowMapFragment.js +1 -0
- package/ShadersWGSL/ShadersInclude/shadowMapFragment.js.map +1 -1
- package/ShadersWGSL/iblCdfDebug.fragment.js +2 -2
- package/ShadersWGSL/iblCdfDebug.fragment.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +8 -0
- package/scene.js.map +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AudioBus } from "../abstractAudio/audioBus.js";
|
|
2
|
+
import { _StereoAudio } from "../abstractAudio/subProperties/stereoAudio.js";
|
|
3
|
+
import { _WebAudioBusAndSoundSubGraph } from "./subNodes/webAudioBusAndSoundSubGraph.js";
|
|
4
|
+
import { _SpatialWebAudio } from "./subProperties/spatialWebAudio.js";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export class _WebAudioBus extends AudioBus {
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(name, engine, options) {
|
|
9
|
+
super(name, engine, options);
|
|
10
|
+
this._spatial = null;
|
|
11
|
+
this._stereo = null;
|
|
12
|
+
this._subGraph = new _WebAudioBus._SubGraph(this);
|
|
13
|
+
this.audioContext = engine.audioContext;
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
async init(options) {
|
|
17
|
+
if (options.outBus) {
|
|
18
|
+
this.outBus = options.outBus;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await this.engine.isReadyPromise;
|
|
22
|
+
this.outBus = this.engine.defaultMainBus;
|
|
23
|
+
}
|
|
24
|
+
await this._subGraph.init(options);
|
|
25
|
+
this.engine.addNode(this);
|
|
26
|
+
}
|
|
27
|
+
/** @internal */
|
|
28
|
+
dispose() {
|
|
29
|
+
super.dispose();
|
|
30
|
+
this._spatial = null;
|
|
31
|
+
this._stereo = null;
|
|
32
|
+
this.engine.removeNode(this);
|
|
33
|
+
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
get inNode() {
|
|
36
|
+
return this._subGraph.inNode;
|
|
37
|
+
}
|
|
38
|
+
/** @internal */
|
|
39
|
+
get outNode() {
|
|
40
|
+
return this._subGraph.outNode;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
get spatial() {
|
|
44
|
+
return this._spatial ?? (this._spatial = new _SpatialWebAudio(this._subGraph, this._spatialAutoUpdate));
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
get stereo() {
|
|
48
|
+
return this._stereo ?? (this._stereo = new _StereoAudio(this._subGraph));
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
getClassName() {
|
|
52
|
+
return "_WebAudioBus";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_WebAudioBus._SubGraph = class extends _WebAudioBusAndSoundSubGraph {
|
|
56
|
+
get _downstreamNodes() {
|
|
57
|
+
return this._owner._downstreamNodes ?? null;
|
|
58
|
+
}
|
|
59
|
+
get _upstreamNodes() {
|
|
60
|
+
return this._owner._upstreamNodes ?? null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=webAudioBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webAudioBus.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/webAudio/webAudioBus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAInE,gBAAgB;AAChB,MAAM,OAAO,YAAa,SAAQ,QAAQ;IAYtC,gBAAgB;IAChB,YAAmB,IAAY,EAAE,MAAuB,EAAE,OAAkC;QACxF,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAbzB,aAAQ,GAA4B,IAAI,CAAC;QACzC,YAAO,GAA2B,IAAI,CAAC;QAc3C,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,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AAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,gBAAgB;IACT,YAAY;QACf,OAAO,cAAc,CAAC;IAC1B,CAAC;;AAEc,sBAAS,GAAG,KAAM,SAAQ,4BAA4B;IAGjE,IAAc,gBAAgB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAChD,CAAC;IAED,IAAc,cAAc;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;IAC9C,CAAC;CACJ,AAVuB,CAUtB","sourcesContent":["import type { Nullable } from \"core/types\";\nimport type { AbstractAudioNode } from \"../abstractAudio/abstractAudioNode\";\nimport type { IAudioBusOptions } from \"../abstractAudio/audioBus\";\nimport { AudioBus } from \"../abstractAudio/audioBus\";\nimport type { _SpatialAudio } from \"../abstractAudio/subProperties/spatialAudio\";\nimport { _StereoAudio } from \"../abstractAudio/subProperties/stereoAudio\";\nimport { _WebAudioBusAndSoundSubGraph } from \"./subNodes/webAudioBusAndSoundSubGraph\";\nimport { _SpatialWebAudio } from \"./subProperties/spatialWebAudio\";\nimport type { _WebAudioEngine } from \"./webAudioEngine\";\nimport type { IWebAudioSuperNode } from \"./webAudioNode\";\n\n/** @internal */\nexport class _WebAudioBus extends AudioBus implements IWebAudioSuperNode {\n private _spatial: Nullable<_SpatialAudio> = null;\n private _stereo: Nullable<_StereoAudio> = null;\n\n protected _subGraph: _WebAudioBusAndSoundSubGraph;\n\n /** @internal */\n public override readonly engine: _WebAudioEngine;\n\n /** @internal */\n public readonly audioContext: AudioContext;\n\n /** @internal */\n public constructor(name: string, engine: _WebAudioEngine, options: Partial<IAudioBusOptions>) {\n super(name, engine, options);\n\n this._subGraph = new _WebAudioBus._SubGraph(this);\n\n this.audioContext = engine.audioContext;\n }\n\n /** @internal */\n public async init(options: Partial<IAudioBusOptions>): Promise<void> {\n if (options.outBus) {\n this.outBus = options.outBus;\n } else {\n await this.engine.isReadyPromise;\n this.outBus = this.engine.defaultMainBus;\n }\n\n await this._subGraph.init(options);\n\n this.engine.addNode(this);\n }\n\n /** @internal */\n public override dispose(): void {\n super.dispose();\n\n this._spatial = null;\n this._stereo = null;\n\n this.engine.removeNode(this);\n }\n\n /** @internal */\n public get inNode() {\n return this._subGraph.inNode;\n }\n\n /** @internal */\n public get outNode() {\n return this._subGraph.outNode;\n }\n\n /** @internal */\n public override get spatial(): _SpatialAudio {\n return this._spatial ?? (this._spatial = new _SpatialWebAudio(this._subGraph, this._spatialAutoUpdate));\n }\n\n /** @internal */\n public override get stereo(): _StereoAudio {\n return this._stereo ?? (this._stereo = new _StereoAudio(this._subGraph));\n }\n\n /** @internal */\n public getClassName(): string {\n return \"_WebAudioBus\";\n }\n\n private static _SubGraph = class extends _WebAudioBusAndSoundSubGraph {\n protected override _owner: _WebAudioBus;\n\n protected get _downstreamNodes(): Nullable<Set<AbstractAudioNode>> {\n return this._owner._downstreamNodes ?? null;\n }\n\n protected get _upstreamNodes(): Nullable<Set<AbstractAudioNode>> {\n return this._owner._upstreamNodes ?? null;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Observable } from "../../Misc/observable";
|
|
2
|
+
import type { AbstractNamedAudioNode } from "../abstractAudio/abstractAudioNode";
|
|
3
|
+
import type { AudioBus, IAudioBusOptions } from "../abstractAudio/audioBus";
|
|
4
|
+
import type { AudioEngineV2State, IAudioEngineV2Options } from "../abstractAudio/audioEngineV2";
|
|
5
|
+
import { AudioEngineV2 } from "../abstractAudio/audioEngineV2";
|
|
6
|
+
import type { IMainAudioBusOptions, MainAudioBus } from "../abstractAudio/mainAudioBus";
|
|
7
|
+
import type { IStaticSoundOptions, StaticSound } from "../abstractAudio/staticSound";
|
|
8
|
+
import type { StaticSoundBuffer } from "../abstractAudio/staticSoundBuffer";
|
|
9
|
+
import type { IStreamingSoundOptions, StreamingSound } from "../abstractAudio/streamingSound";
|
|
10
|
+
import type { AbstractSpatialAudioListener } from "../abstractAudio/subProperties/abstractSpatialAudioListener";
|
|
11
|
+
import { _WebAudioMainOut } from "./webAudioMainOut";
|
|
12
|
+
/**
|
|
13
|
+
* Options for creating a v2 audio engine that uses the WebAudio API.
|
|
14
|
+
*/
|
|
15
|
+
export interface IWebAudioEngineOptions extends IAudioEngineV2Options {
|
|
16
|
+
/**
|
|
17
|
+
* The audio context to be used by the engine.
|
|
18
|
+
*/
|
|
19
|
+
audioContext: AudioContext;
|
|
20
|
+
/**
|
|
21
|
+
* Set to `true` to automatically resume the audio context when the user interacts with the page. Defaults to `true`.
|
|
22
|
+
*/
|
|
23
|
+
resumeOnInteraction: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Set to `true` to automatically resume the audio context when the browser pauses audio playback. Defaults to `true`.
|
|
26
|
+
*/
|
|
27
|
+
resumeOnPause: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The interval in milliseconds to try resuming audio playback when `resumeOnPause` is `true`. Defaults to `1000`.
|
|
30
|
+
*/
|
|
31
|
+
resumeOnPauseRetryInterval: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new v2 audio engine that uses the WebAudio API.
|
|
35
|
+
* @param options - The options for creating the audio engine.
|
|
36
|
+
* @returns A promise that resolves with the created audio engine.
|
|
37
|
+
*/
|
|
38
|
+
export declare function CreateAudioEngineAsync(options?: Partial<IWebAudioEngineOptions>): Promise<AudioEngineV2>;
|
|
39
|
+
/** @internal */
|
|
40
|
+
export declare class _WebAudioEngine extends AudioEngineV2 {
|
|
41
|
+
private _audioContextStarted;
|
|
42
|
+
private _invalidFormats;
|
|
43
|
+
private _listener;
|
|
44
|
+
private _mainOut;
|
|
45
|
+
private _resumeOnInteraction;
|
|
46
|
+
private _resumeOnPause;
|
|
47
|
+
private _resumeOnPauseRetryInterval;
|
|
48
|
+
private _resumeOnPauseTimerId;
|
|
49
|
+
private _resumePromise;
|
|
50
|
+
private _validFormats;
|
|
51
|
+
private _volume;
|
|
52
|
+
/** @internal */
|
|
53
|
+
readonly audioContext: AudioContext;
|
|
54
|
+
/** @internal */
|
|
55
|
+
readonly isReadyPromise: Promise<void>;
|
|
56
|
+
/** @internal */
|
|
57
|
+
stateChangedObservable: Observable<string>;
|
|
58
|
+
/** @internal */
|
|
59
|
+
userGestureObservable: Observable<void>;
|
|
60
|
+
/** @internal */
|
|
61
|
+
constructor(options?: Partial<IWebAudioEngineOptions>);
|
|
62
|
+
/** @internal */
|
|
63
|
+
init(options: Partial<IWebAudioEngineOptions>): Promise<void>;
|
|
64
|
+
/** @internal */
|
|
65
|
+
get currentTime(): number;
|
|
66
|
+
/** @internal */
|
|
67
|
+
get inNode(): AudioNode;
|
|
68
|
+
/** @internal */
|
|
69
|
+
get mainOut(): _WebAudioMainOut;
|
|
70
|
+
/** @internal */
|
|
71
|
+
get listener(): AbstractSpatialAudioListener;
|
|
72
|
+
/** @internal */
|
|
73
|
+
get state(): AudioEngineV2State;
|
|
74
|
+
/** @internal */
|
|
75
|
+
get volume(): number;
|
|
76
|
+
/** @internal */
|
|
77
|
+
set volume(value: number);
|
|
78
|
+
/** @internal */
|
|
79
|
+
createBusAsync(name: string, options?: Partial<IAudioBusOptions>): Promise<AudioBus>;
|
|
80
|
+
/** @internal */
|
|
81
|
+
createMainBusAsync(name: string, options?: Partial<IMainAudioBusOptions>): Promise<MainAudioBus>;
|
|
82
|
+
/** @internal */
|
|
83
|
+
createSoundAsync(name: string, source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[], options?: Partial<IStaticSoundOptions>): Promise<StaticSound>;
|
|
84
|
+
/** @internal */
|
|
85
|
+
createSoundBufferAsync(source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[], options?: Partial<IStaticSoundOptions>): Promise<StaticSoundBuffer>;
|
|
86
|
+
/** @internal */
|
|
87
|
+
createStreamingSoundAsync(name: string, source: HTMLMediaElement | string | string[], options?: Partial<IStreamingSoundOptions>): Promise<StreamingSound>;
|
|
88
|
+
/** @internal */
|
|
89
|
+
dispose(): void;
|
|
90
|
+
/** @internal */
|
|
91
|
+
flagInvalidFormat(format: string): void;
|
|
92
|
+
/** @internal */
|
|
93
|
+
isFormatValid(format: string): boolean;
|
|
94
|
+
/** @internal */
|
|
95
|
+
pause(): Promise<void>;
|
|
96
|
+
/** @internal */
|
|
97
|
+
resume(): Promise<void>;
|
|
98
|
+
/** @internal */
|
|
99
|
+
addMainBus(mainBus: MainAudioBus): void;
|
|
100
|
+
/** @internal */
|
|
101
|
+
removeMainBus(mainBus: MainAudioBus): void;
|
|
102
|
+
/** @internal */
|
|
103
|
+
addNode(node: AbstractNamedAudioNode): void;
|
|
104
|
+
/** @internal */
|
|
105
|
+
removeNode(node: AbstractNamedAudioNode): void;
|
|
106
|
+
private _initAudioContext;
|
|
107
|
+
private _onAudioContextStateChange;
|
|
108
|
+
private _onUserGesture;
|
|
109
|
+
private _resolveIsReadyPromise;
|
|
110
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { Observable } from "../../Misc/observable.js";
|
|
2
|
+
import { AudioEngineV2 } from "../abstractAudio/audioEngineV2.js";
|
|
3
|
+
import { _HasSpatialAudioListenerOptions } from "../abstractAudio/subProperties/abstractSpatialAudioListener.js";
|
|
4
|
+
import { _CreateSpatialAudioListener } from "./subProperties/spatialWebAudioListener.js";
|
|
5
|
+
import { _WebAudioMainOut } from "./webAudioMainOut.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new v2 audio engine that uses the WebAudio API.
|
|
8
|
+
* @param options - The options for creating the audio engine.
|
|
9
|
+
* @returns A promise that resolves with the created audio engine.
|
|
10
|
+
*/
|
|
11
|
+
export async function CreateAudioEngineAsync(options = {}) {
|
|
12
|
+
const engine = new _WebAudioEngine(options);
|
|
13
|
+
await engine.init(options);
|
|
14
|
+
return engine;
|
|
15
|
+
}
|
|
16
|
+
const FormatMimeTypes = {
|
|
17
|
+
aac: "audio/aac",
|
|
18
|
+
ac3: "audio/ac3",
|
|
19
|
+
flac: "audio/flac",
|
|
20
|
+
m4a: "audio/mp4",
|
|
21
|
+
mp3: 'audio/mpeg; codecs="mp3"',
|
|
22
|
+
mp4: "audio/mp4",
|
|
23
|
+
ogg: 'audio/ogg; codecs="vorbis"',
|
|
24
|
+
wav: "audio/wav",
|
|
25
|
+
webm: 'audio/webm; codecs="vorbis"',
|
|
26
|
+
};
|
|
27
|
+
/** @internal */
|
|
28
|
+
export class _WebAudioEngine extends AudioEngineV2 {
|
|
29
|
+
/** @internal */
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
super(options);
|
|
32
|
+
this._audioContextStarted = false;
|
|
33
|
+
this._invalidFormats = new Set();
|
|
34
|
+
this._listener = null;
|
|
35
|
+
this._resumeOnInteraction = true;
|
|
36
|
+
this._resumeOnPause = true;
|
|
37
|
+
this._resumeOnPauseRetryInterval = 1000;
|
|
38
|
+
this._resumeOnPauseTimerId = null;
|
|
39
|
+
this._resumePromise = null;
|
|
40
|
+
this._validFormats = new Set();
|
|
41
|
+
this._volume = 1;
|
|
42
|
+
/** @internal */
|
|
43
|
+
this.isReadyPromise = new Promise((resolve) => {
|
|
44
|
+
this._resolveIsReadyPromise = resolve;
|
|
45
|
+
});
|
|
46
|
+
/** @internal */
|
|
47
|
+
this.stateChangedObservable = new Observable();
|
|
48
|
+
/** @internal */
|
|
49
|
+
this.userGestureObservable = new Observable();
|
|
50
|
+
this._initAudioContext = async () => {
|
|
51
|
+
this.audioContext.addEventListener("statechange", this._onAudioContextStateChange);
|
|
52
|
+
this._mainOut = new _WebAudioMainOut(this);
|
|
53
|
+
this._mainOut.volume = this._volume;
|
|
54
|
+
await this.createMainBusAsync("default");
|
|
55
|
+
};
|
|
56
|
+
this._onAudioContextStateChange = () => {
|
|
57
|
+
if (this.state === "running") {
|
|
58
|
+
clearInterval(this._resumeOnPauseTimerId);
|
|
59
|
+
this._audioContextStarted = true;
|
|
60
|
+
this._resumePromise = null;
|
|
61
|
+
}
|
|
62
|
+
if (this.state === "suspended" || this.state === "interrupted") {
|
|
63
|
+
if (this._audioContextStarted && this._resumeOnPause) {
|
|
64
|
+
clearInterval(this._resumeOnPauseTimerId);
|
|
65
|
+
this._resumeOnPauseTimerId = setInterval(() => {
|
|
66
|
+
this.resume();
|
|
67
|
+
}, this._resumeOnPauseRetryInterval);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.stateChangedObservable.notifyObservers(this.state);
|
|
71
|
+
};
|
|
72
|
+
this._onUserGesture = async () => {
|
|
73
|
+
if (this._resumeOnInteraction) {
|
|
74
|
+
await this.audioContext.resume();
|
|
75
|
+
}
|
|
76
|
+
this.userGestureObservable.notifyObservers();
|
|
77
|
+
};
|
|
78
|
+
this._volume = options.volume ?? 1;
|
|
79
|
+
this.audioContext = options.audioContext ?? new AudioContext();
|
|
80
|
+
}
|
|
81
|
+
/** @internal */
|
|
82
|
+
async init(options) {
|
|
83
|
+
this._resumeOnInteraction = typeof options.resumeOnInteraction === "boolean" ? options.resumeOnInteraction : true;
|
|
84
|
+
this._resumeOnPause = typeof options.resumeOnPause === "boolean" ? options.resumeOnPause : true;
|
|
85
|
+
this._resumeOnPauseRetryInterval = options.resumeOnPauseRetryInterval ?? 1000;
|
|
86
|
+
document.addEventListener("click", this._onUserGesture);
|
|
87
|
+
await this._initAudioContext();
|
|
88
|
+
if (_HasSpatialAudioListenerOptions(options)) {
|
|
89
|
+
this._listener = _CreateSpatialAudioListener(this, this._listenerAutoUpdate);
|
|
90
|
+
this._listener.setOptions(options);
|
|
91
|
+
}
|
|
92
|
+
this._resolveIsReadyPromise();
|
|
93
|
+
}
|
|
94
|
+
/** @internal */
|
|
95
|
+
get currentTime() {
|
|
96
|
+
return this.audioContext.currentTime ?? 0;
|
|
97
|
+
}
|
|
98
|
+
/** @internal */
|
|
99
|
+
get inNode() {
|
|
100
|
+
return this.audioContext.destination;
|
|
101
|
+
}
|
|
102
|
+
/** @internal */
|
|
103
|
+
get mainOut() {
|
|
104
|
+
return this._mainOut;
|
|
105
|
+
}
|
|
106
|
+
/** @internal */
|
|
107
|
+
get listener() {
|
|
108
|
+
return this._listener ?? (this._listener = _CreateSpatialAudioListener(this, this._listenerAutoUpdate));
|
|
109
|
+
}
|
|
110
|
+
/** @internal */
|
|
111
|
+
get state() {
|
|
112
|
+
return this.audioContext.state;
|
|
113
|
+
}
|
|
114
|
+
/** @internal */
|
|
115
|
+
get volume() {
|
|
116
|
+
return this._volume;
|
|
117
|
+
}
|
|
118
|
+
/** @internal */
|
|
119
|
+
set volume(value) {
|
|
120
|
+
if (this._volume === value) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this._volume = value;
|
|
124
|
+
if (this._mainOut) {
|
|
125
|
+
this._mainOut.volume = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** @internal */
|
|
129
|
+
async createBusAsync(name, options = {}) {
|
|
130
|
+
const module = await import("./webAudioBus.js");
|
|
131
|
+
const bus = new module._WebAudioBus(name, this, options);
|
|
132
|
+
await bus.init(options);
|
|
133
|
+
return bus;
|
|
134
|
+
}
|
|
135
|
+
/** @internal */
|
|
136
|
+
async createMainBusAsync(name, options = {}) {
|
|
137
|
+
const module = await import("./webAudioMainBus.js");
|
|
138
|
+
const bus = new module._WebAudioMainBus(name, this);
|
|
139
|
+
await bus.init(options);
|
|
140
|
+
return bus;
|
|
141
|
+
}
|
|
142
|
+
/** @internal */
|
|
143
|
+
async createSoundAsync(name, source, options = {}) {
|
|
144
|
+
const module = await import("./webAudioStaticSound.js");
|
|
145
|
+
const sound = new module._WebAudioStaticSound(name, this, options);
|
|
146
|
+
await sound.init(source, options);
|
|
147
|
+
return sound;
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
async createSoundBufferAsync(source, options = {}) {
|
|
151
|
+
const module = await import("./webAudioStaticSound.js");
|
|
152
|
+
const soundBuffer = new module._WebAudioStaticSoundBuffer(this);
|
|
153
|
+
await soundBuffer.init(source, options);
|
|
154
|
+
return soundBuffer;
|
|
155
|
+
}
|
|
156
|
+
/** @internal */
|
|
157
|
+
async createStreamingSoundAsync(name, source, options = {}) {
|
|
158
|
+
const module = await import("./webAudioStreamingSound.js");
|
|
159
|
+
const sound = new module._WebAudioStreamingSound(name, this, options);
|
|
160
|
+
await sound.init(source, options);
|
|
161
|
+
return sound;
|
|
162
|
+
}
|
|
163
|
+
/** @internal */
|
|
164
|
+
dispose() {
|
|
165
|
+
super.dispose();
|
|
166
|
+
this._listener?.dispose();
|
|
167
|
+
this._listener = null;
|
|
168
|
+
if (this.audioContext.state !== "closed") {
|
|
169
|
+
this.audioContext.close();
|
|
170
|
+
}
|
|
171
|
+
document.removeEventListener("click", this._onUserGesture);
|
|
172
|
+
this.audioContext.removeEventListener("statechange", this._onAudioContextStateChange);
|
|
173
|
+
}
|
|
174
|
+
/** @internal */
|
|
175
|
+
flagInvalidFormat(format) {
|
|
176
|
+
this._invalidFormats.add(format);
|
|
177
|
+
}
|
|
178
|
+
/** @internal */
|
|
179
|
+
isFormatValid(format) {
|
|
180
|
+
if (this._validFormats.has(format)) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
if (this._invalidFormats.has(format)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const mimeType = FormatMimeTypes[format];
|
|
187
|
+
if (mimeType === undefined) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const audio = new Audio();
|
|
191
|
+
if (audio.canPlayType(mimeType) === "") {
|
|
192
|
+
this._invalidFormats.add(format);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
this._validFormats.add(format);
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/** @internal */
|
|
199
|
+
async pause() {
|
|
200
|
+
await this.audioContext.suspend();
|
|
201
|
+
}
|
|
202
|
+
/** @internal */
|
|
203
|
+
async resume() {
|
|
204
|
+
if (this._resumePromise) {
|
|
205
|
+
return this._resumePromise;
|
|
206
|
+
}
|
|
207
|
+
this._resumePromise = this.audioContext.resume();
|
|
208
|
+
return this._resumePromise;
|
|
209
|
+
}
|
|
210
|
+
/** @internal */
|
|
211
|
+
addMainBus(mainBus) {
|
|
212
|
+
this._addMainBus(mainBus);
|
|
213
|
+
}
|
|
214
|
+
/** @internal */
|
|
215
|
+
removeMainBus(mainBus) {
|
|
216
|
+
this._removeMainBus(mainBus);
|
|
217
|
+
}
|
|
218
|
+
/** @internal */
|
|
219
|
+
addNode(node) {
|
|
220
|
+
this._addNode(node);
|
|
221
|
+
}
|
|
222
|
+
/** @internal */
|
|
223
|
+
removeNode(node) {
|
|
224
|
+
this._removeNode(node);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=webAudioEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webAudioEngine.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/webAudio/webAudioEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAM/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,6DAA6D,CAAC;AAE9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAwBrD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,UAA2C,EAAE;IACtF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,eAAe,GAA8B;IAC/C,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;IA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C,OAAqB;QACtC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,gBAAgB;IACT,OAAO,CAAC,IAA4B;QACvC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,UAAU,CAAC,IAA4B;QAC1C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CAuCJ","sourcesContent":["import { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport type { AbstractNamedAudioNode } from \"../abstractAudio/abstractAudioNode\";\nimport type { AudioBus, IAudioBusOptions } from \"../abstractAudio/audioBus\";\nimport type { AudioEngineV2State, IAudioEngineV2Options } from \"../abstractAudio/audioEngineV2\";\nimport { AudioEngineV2 } from \"../abstractAudio/audioEngineV2\";\nimport type { IMainAudioBusOptions, MainAudioBus } from \"../abstractAudio/mainAudioBus\";\nimport type { IStaticSoundOptions, StaticSound } from \"../abstractAudio/staticSound\";\nimport type { StaticSoundBuffer } from \"../abstractAudio/staticSoundBuffer\";\nimport type { IStreamingSoundOptions, StreamingSound } from \"../abstractAudio/streamingSound\";\nimport type { AbstractSpatialAudioListener } from \"../abstractAudio/subProperties/abstractSpatialAudioListener\";\nimport { _HasSpatialAudioListenerOptions } from \"../abstractAudio/subProperties/abstractSpatialAudioListener\";\nimport type { _SpatialAudioListener } from \"../abstractAudio/subProperties/spatialAudioListener\";\nimport { _CreateSpatialAudioListener } from \"./subProperties/spatialWebAudioListener\";\nimport { _WebAudioMainOut } from \"./webAudioMainOut\";\n\n/**\n * Options for creating a v2 audio engine that uses the WebAudio API.\n */\nexport interface IWebAudioEngineOptions extends IAudioEngineV2Options {\n /**\n * The audio context to be used by the engine.\n */\n audioContext: AudioContext;\n /**\n * Set to `true` to automatically resume the audio context when the user interacts with the page. Defaults to `true`.\n */\n resumeOnInteraction: boolean;\n /**\n * Set to `true` to automatically resume the audio context when the browser pauses audio playback. Defaults to `true`.\n */\n resumeOnPause: boolean;\n /**\n * The interval in milliseconds to try resuming audio playback when `resumeOnPause` is `true`. Defaults to `1000`.\n */\n resumeOnPauseRetryInterval: number;\n}\n\n/**\n * Creates a new v2 audio engine that uses the WebAudio API.\n * @param options - The options for creating the audio engine.\n * @returns A promise that resolves with the created audio engine.\n */\nexport async function CreateAudioEngineAsync(options: Partial<IWebAudioEngineOptions> = {}): Promise<AudioEngineV2> {\n const engine = new _WebAudioEngine(options);\n await engine.init(options);\n return engine;\n}\n\nconst FormatMimeTypes: { [key: string]: string } = {\n aac: \"audio/aac\",\n ac3: \"audio/ac3\",\n flac: \"audio/flac\",\n m4a: \"audio/mp4\",\n mp3: 'audio/mpeg; codecs=\"mp3\"',\n mp4: \"audio/mp4\",\n ogg: 'audio/ogg; codecs=\"vorbis\"',\n wav: \"audio/wav\",\n webm: 'audio/webm; codecs=\"vorbis\"',\n};\n\n/** @internal */\nexport class _WebAudioEngine extends AudioEngineV2 {\n private _audioContextStarted = false;\n private _invalidFormats = new Set<string>();\n private _listener: Nullable<_SpatialAudioListener> = null;\n private _mainOut: _WebAudioMainOut;\n private _resumeOnInteraction = true;\n private _resumeOnPause = true;\n private _resumeOnPauseRetryInterval = 1000;\n private _resumeOnPauseTimerId: any = null;\n private _resumePromise: Nullable<Promise<void>> = null;\n private _validFormats = new Set<string>();\n private _volume = 1;\n\n /** @internal */\n public readonly audioContext: AudioContext;\n\n /** @internal */\n public readonly isReadyPromise: Promise<void> = new Promise((resolve) => {\n this._resolveIsReadyPromise = resolve;\n });\n\n /** @internal */\n public stateChangedObservable: Observable<string> = new Observable();\n\n /** @internal */\n public userGestureObservable: Observable<void> = new Observable();\n\n /** @internal */\n public constructor(options: Partial<IWebAudioEngineOptions> = {}) {\n super(options);\n\n this._volume = options.volume ?? 1;\n this.audioContext = options.audioContext ?? new AudioContext();\n }\n\n /** @internal */\n public async init(options: Partial<IWebAudioEngineOptions>): Promise<void> {\n this._resumeOnInteraction = typeof options.resumeOnInteraction === \"boolean\" ? options.resumeOnInteraction : true;\n this._resumeOnPause = typeof options.resumeOnPause === \"boolean\" ? options.resumeOnPause : true;\n this._resumeOnPauseRetryInterval = options.resumeOnPauseRetryInterval ?? 1000;\n\n document.addEventListener(\"click\", this._onUserGesture);\n\n await this._initAudioContext();\n\n if (_HasSpatialAudioListenerOptions(options)) {\n this._listener = _CreateSpatialAudioListener(this, this._listenerAutoUpdate);\n this._listener.setOptions(options);\n }\n\n this._resolveIsReadyPromise();\n }\n\n /** @internal */\n public get currentTime(): number {\n return this.audioContext.currentTime ?? 0;\n }\n\n /** @internal */\n public get inNode(): AudioNode {\n return this.audioContext.destination;\n }\n\n /** @internal */\n public get mainOut(): _WebAudioMainOut {\n return this._mainOut;\n }\n\n /** @internal */\n public get listener(): AbstractSpatialAudioListener {\n return this._listener ?? (this._listener = _CreateSpatialAudioListener(this, this._listenerAutoUpdate));\n }\n\n /** @internal */\n public get state(): AudioEngineV2State {\n return this.audioContext.state;\n }\n\n /** @internal */\n public get volume(): number {\n return this._volume;\n }\n\n /** @internal */\n public set volume(value: number) {\n if (this._volume === value) {\n return;\n }\n\n this._volume = value;\n\n if (this._mainOut) {\n this._mainOut.volume = value;\n }\n }\n\n /** @internal */\n public async createBusAsync(name: string, options: Partial<IAudioBusOptions> = {}): Promise<AudioBus> {\n const module = await import(\"./webAudioBus\");\n\n const bus = new module._WebAudioBus(name, this, options);\n await bus.init(options);\n\n return bus;\n }\n\n /** @internal */\n public async createMainBusAsync(name: string, options: Partial<IMainAudioBusOptions> = {}): Promise<MainAudioBus> {\n const module = await import(\"./webAudioMainBus\");\n\n const bus = new module._WebAudioMainBus(name, this);\n await bus.init(options);\n\n return bus;\n }\n\n /** @internal */\n public async createSoundAsync(\n name: string,\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundOptions> = {}\n ): Promise<StaticSound> {\n const module = await import(\"./webAudioStaticSound\");\n\n const sound = new module._WebAudioStaticSound(name, this, options);\n await sound.init(source, options);\n\n return sound;\n }\n\n /** @internal */\n public async createSoundBufferAsync(\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundOptions> = {}\n ): Promise<StaticSoundBuffer> {\n const module = await import(\"./webAudioStaticSound\");\n\n const soundBuffer = new module._WebAudioStaticSoundBuffer(this);\n await soundBuffer.init(source, options);\n\n return soundBuffer;\n }\n\n /** @internal */\n public async createStreamingSoundAsync(name: string, source: HTMLMediaElement | string | string[], options: Partial<IStreamingSoundOptions> = {}): Promise<StreamingSound> {\n const module = await import(\"./webAudioStreamingSound\");\n\n const sound = new module._WebAudioStreamingSound(name, this, options);\n await sound.init(source, options);\n\n return sound;\n }\n\n /** @internal */\n public override dispose(): void {\n super.dispose();\n\n this._listener?.dispose();\n this._listener = null;\n\n if (this.audioContext.state !== \"closed\") {\n this.audioContext.close();\n }\n\n document.removeEventListener(\"click\", this._onUserGesture);\n this.audioContext.removeEventListener(\"statechange\", this._onAudioContextStateChange);\n }\n\n /** @internal */\n public flagInvalidFormat(format: string): void {\n this._invalidFormats.add(format);\n }\n\n /** @internal */\n public isFormatValid(format: string): boolean {\n if (this._validFormats.has(format)) {\n return true;\n }\n\n if (this._invalidFormats.has(format)) {\n return false;\n }\n\n const mimeType = FormatMimeTypes[format];\n if (mimeType === undefined) {\n return false;\n }\n\n const audio = new Audio();\n if (audio.canPlayType(mimeType) === \"\") {\n this._invalidFormats.add(format);\n return false;\n }\n\n this._validFormats.add(format);\n\n return true;\n }\n\n /** @internal */\n public override async pause(): Promise<void> {\n await this.audioContext.suspend();\n }\n\n /** @internal */\n public override async resume(): Promise<void> {\n if (this._resumePromise) {\n return this._resumePromise;\n }\n\n this._resumePromise = this.audioContext.resume();\n return this._resumePromise;\n }\n\n /** @internal */\n public addMainBus(mainBus: MainAudioBus): void {\n this._addMainBus(mainBus);\n }\n\n /** @internal */\n public removeMainBus(mainBus: MainAudioBus): void {\n this._removeMainBus(mainBus);\n }\n\n /** @internal */\n public addNode(node: AbstractNamedAudioNode): void {\n this._addNode(node);\n }\n\n /** @internal */\n public removeNode(node: AbstractNamedAudioNode): void {\n this._removeNode(node);\n }\n\n private _initAudioContext: () => Promise<void> = async () => {\n this.audioContext.addEventListener(\"statechange\", this._onAudioContextStateChange);\n\n this._mainOut = new _WebAudioMainOut(this);\n this._mainOut.volume = this._volume;\n\n await this.createMainBusAsync(\"default\");\n };\n\n private _onAudioContextStateChange = () => {\n if (this.state === \"running\") {\n clearInterval(this._resumeOnPauseTimerId);\n this._audioContextStarted = true;\n this._resumePromise = null;\n }\n if (this.state === \"suspended\" || this.state === \"interrupted\") {\n if (this._audioContextStarted && this._resumeOnPause) {\n clearInterval(this._resumeOnPauseTimerId);\n\n this._resumeOnPauseTimerId = setInterval(() => {\n this.resume();\n }, this._resumeOnPauseRetryInterval);\n }\n }\n\n this.stateChangedObservable.notifyObservers(this.state);\n };\n\n private _onUserGesture: () => void = async () => {\n if (this._resumeOnInteraction) {\n await this.audioContext.resume();\n }\n\n this.userGestureObservable.notifyObservers();\n };\n\n private _resolveIsReadyPromise: () => void;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Nullable } from "../../types";
|
|
2
|
+
import type { IMainAudioBusOptions } from "../abstractAudio/mainAudioBus";
|
|
3
|
+
import { MainAudioBus } from "../abstractAudio/mainAudioBus";
|
|
4
|
+
import { _WebAudioBaseSubGraph } from "./subNodes/webAudioBaseSubGraph";
|
|
5
|
+
import type { _WebAudioEngine } from "./webAudioEngine";
|
|
6
|
+
import type { IWebAudioInNode, IWebAudioSuperNode } from "./webAudioNode";
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare class _WebAudioMainBus extends MainAudioBus implements IWebAudioSuperNode {
|
|
9
|
+
protected _subGraph: _WebAudioBaseSubGraph;
|
|
10
|
+
/** @internal */
|
|
11
|
+
readonly engine: _WebAudioEngine;
|
|
12
|
+
/** @internal */
|
|
13
|
+
audioContext: AudioContext;
|
|
14
|
+
/** @internal */
|
|
15
|
+
constructor(name: string, engine: _WebAudioEngine);
|
|
16
|
+
/** @internal */
|
|
17
|
+
init(options: Partial<IMainAudioBusOptions>): Promise<void>;
|
|
18
|
+
/** @internal */
|
|
19
|
+
dispose(): void;
|
|
20
|
+
/** @internal */
|
|
21
|
+
get inNode(): Nullable<AudioNode>;
|
|
22
|
+
/** @internal */
|
|
23
|
+
get outNode(): Nullable<AudioNode>;
|
|
24
|
+
protected _connect(node: IWebAudioInNode): boolean;
|
|
25
|
+
protected _disconnect(node: IWebAudioInNode): boolean;
|
|
26
|
+
/** @internal */
|
|
27
|
+
getClassName(): string;
|
|
28
|
+
private static _SubGraph;
|
|
29
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MainAudioBus } from "../abstractAudio/mainAudioBus.js";
|
|
2
|
+
import { _WebAudioBaseSubGraph } from "./subNodes/webAudioBaseSubGraph.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export class _WebAudioMainBus extends MainAudioBus {
|
|
5
|
+
/** @internal */
|
|
6
|
+
constructor(name, engine) {
|
|
7
|
+
super(name, engine);
|
|
8
|
+
this._subGraph = new _WebAudioMainBus._SubGraph(this);
|
|
9
|
+
this.audioContext = engine.audioContext;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
async init(options) {
|
|
13
|
+
await this._subGraph.init(options);
|
|
14
|
+
if (this.engine.mainOut) {
|
|
15
|
+
if (!this._connect(this.engine.mainOut)) {
|
|
16
|
+
throw new Error("Connect failed");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
this.engine.addMainBus(this);
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
dispose() {
|
|
23
|
+
super.dispose();
|
|
24
|
+
this.engine.removeMainBus(this);
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
get inNode() {
|
|
28
|
+
return this._subGraph.inNode;
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
get outNode() {
|
|
32
|
+
return this._subGraph.outNode;
|
|
33
|
+
}
|
|
34
|
+
_connect(node) {
|
|
35
|
+
const connected = super._connect(node);
|
|
36
|
+
if (!connected) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (node.inNode) {
|
|
40
|
+
this.outNode?.connect(node.inNode);
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
_disconnect(node) {
|
|
45
|
+
const disconnected = super._disconnect(node);
|
|
46
|
+
if (!disconnected) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (node.inNode) {
|
|
50
|
+
this.outNode?.disconnect(node.inNode);
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/** @internal */
|
|
55
|
+
getClassName() {
|
|
56
|
+
return "_WebAudioMainBus";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_WebAudioMainBus._SubGraph = class extends _WebAudioBaseSubGraph {
|
|
60
|
+
get _downstreamNodes() {
|
|
61
|
+
return this._owner._downstreamNodes ?? null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=webAudioMainBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webAudioMainBus.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/webAudio/webAudioMainBus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAIxE,gBAAgB;AAChB,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAS9C,gBAAgB;IAChB,YAAmB,IAAY,EAAE,MAAuB;QACpD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEpB,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,SAAS,CA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AE7C,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,gBAAgB;IACT,YAAY;QACf,OAAO,kBAAkB,CAAC;IAC9B,CAAC;;AAEc,0BAAS,GAAG,KAAM,SAAQ,qBAAqB;IAG1D,IAAc,gBAAgB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAChD,CAAC;CACJ,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\nimport type { AbstractAudioNode } from \"../abstractAudio/abstractAudioNode\";\nimport type { IMainAudioBusOptions } from \"../abstractAudio/mainAudioBus\";\nimport { MainAudioBus } from \"../abstractAudio/mainAudioBus\";\nimport { _WebAudioBaseSubGraph } from \"./subNodes/webAudioBaseSubGraph\";\nimport type { _WebAudioEngine } from \"./webAudioEngine\";\nimport type { IWebAudioInNode, IWebAudioSuperNode } from \"./webAudioNode\";\n\n/** @internal */\nexport class _WebAudioMainBus extends MainAudioBus implements IWebAudioSuperNode {\n protected _subGraph: _WebAudioBaseSubGraph;\n\n /** @internal */\n public override readonly engine: _WebAudioEngine;\n\n /** @internal */\n public audioContext: AudioContext;\n\n /** @internal */\n public constructor(name: string, engine: _WebAudioEngine) {\n super(name, engine);\n\n this._subGraph = new _WebAudioMainBus._SubGraph(this);\n this.audioContext = engine.audioContext;\n }\n\n /** @internal */\n public async init(options: Partial<IMainAudioBusOptions>): Promise<void> {\n await this._subGraph.init(options);\n\n if (this.engine.mainOut) {\n if (!this._connect(this.engine.mainOut)) {\n throw new Error(\"Connect failed\");\n }\n }\n\n this.engine.addMainBus(this);\n }\n\n /** @internal */\n public override dispose(): void {\n super.dispose();\n\n this.engine.removeMainBus(this);\n }\n\n /** @internal */\n public get inNode() {\n return this._subGraph.inNode;\n }\n\n /** @internal */\n public get outNode() {\n return this._subGraph.outNode;\n }\n\n protected override _connect(node: IWebAudioInNode): boolean {\n const connected = super._connect(node);\n\n if (!connected) {\n return false;\n }\n\n if (node.inNode) {\n this.outNode?.connect(node.inNode);\n }\n\n return true;\n }\n\n protected override _disconnect(node: IWebAudioInNode): boolean {\n const disconnected = super._disconnect(node);\n\n if (!disconnected) {\n return false;\n }\n\n if (node.inNode) {\n this.outNode?.disconnect(node.inNode);\n }\n\n return true;\n }\n\n /** @internal */\n public getClassName(): string {\n return \"_WebAudioMainBus\";\n }\n\n private static _SubGraph = class extends _WebAudioBaseSubGraph {\n protected override _owner: _WebAudioMainBus;\n\n protected get _downstreamNodes(): Nullable<Set<AbstractAudioNode>> {\n return this._owner._downstreamNodes ?? null;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { _MainAudioOut } from "../abstractAudio/mainAudioOut";
|
|
2
|
+
import type { _WebAudioEngine } from "./webAudioEngine";
|
|
3
|
+
import type { IWebAudioInNode } from "./webAudioNode";
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare class _WebAudioMainOut extends _MainAudioOut implements IWebAudioInNode {
|
|
6
|
+
private _destinationNode;
|
|
7
|
+
private _gainNode;
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor(engine: _WebAudioEngine);
|
|
10
|
+
/** @internal */
|
|
11
|
+
get inNode(): AudioNode;
|
|
12
|
+
/** @internal */
|
|
13
|
+
get volume(): number;
|
|
14
|
+
/** @internal */
|
|
15
|
+
set volume(value: number);
|
|
16
|
+
/** @internal */
|
|
17
|
+
dispose(): void;
|
|
18
|
+
/** @internal */
|
|
19
|
+
getClassName(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { _MainAudioOut } from "../abstractAudio/mainAudioOut.js";
|
|
2
|
+
/** @internal */
|
|
3
|
+
export class _WebAudioMainOut extends _MainAudioOut {
|
|
4
|
+
/** @internal */
|
|
5
|
+
constructor(engine) {
|
|
6
|
+
super(engine);
|
|
7
|
+
const audioContext = engine.audioContext;
|
|
8
|
+
this._gainNode = new GainNode(audioContext);
|
|
9
|
+
this._destinationNode = audioContext.destination;
|
|
10
|
+
this._gainNode.connect(this._destinationNode);
|
|
11
|
+
}
|
|
12
|
+
/** @internal */
|
|
13
|
+
get inNode() {
|
|
14
|
+
return this._gainNode;
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
get volume() {
|
|
18
|
+
return this._gainNode.gain.value;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
set volume(value) {
|
|
22
|
+
this._gainNode.gain.value = value;
|
|
23
|
+
}
|
|
24
|
+
/** @internal */
|
|
25
|
+
dispose() {
|
|
26
|
+
super.dispose();
|
|
27
|
+
this._gainNode.disconnect();
|
|
28
|
+
this._destinationNode.disconnect();
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
getClassName() {
|
|
32
|
+
return "_WebAudioMainOut";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=webAudioMainOut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webAudioMainOut.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/webAudio/webAudioMainOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9D,gBAAgB;AAChB,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAI/C,gBAAgB;IAChB,YAAmB,MAAuB;QACtC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QAEzC,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,gBAAgB,GAAG,YAAY,CAAC,WAAW,CAAC;QAEjD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;IAED,gBAAgB;IAChB,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,gBAAgB;IAChB,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;IACrC,CAAC;IAED,gBAAgB;IAChB,IAAW,MAAM,CAAC,KAAa;QAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACtC,CAAC;IAED,gBAAgB;IACA,OAAO;QACnB,KAAK,CAAC,OAAO,EAAE,CAAC;QAEhB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED,gBAAgB;IACT,YAAY;QACf,OAAO,kBAAkB,CAAC;IAC9B,CAAC;CACJ","sourcesContent":["import { _MainAudioOut } from \"../abstractAudio/mainAudioOut\";\nimport type { _WebAudioEngine } from \"./webAudioEngine\";\nimport type { IWebAudioInNode } from \"./webAudioNode\";\n\n/** @internal */\nexport class _WebAudioMainOut extends _MainAudioOut implements IWebAudioInNode {\n private _destinationNode: AudioDestinationNode;\n private _gainNode: GainNode;\n\n /** @internal */\n public constructor(engine: _WebAudioEngine) {\n super(engine);\n\n const audioContext = engine.audioContext;\n\n this._gainNode = new GainNode(audioContext);\n this._destinationNode = audioContext.destination;\n\n this._gainNode.connect(this._destinationNode);\n }\n\n /** @internal */\n public get inNode(): AudioNode {\n return this._gainNode;\n }\n\n /** @internal */\n public get volume(): number {\n return this._gainNode.gain.value;\n }\n\n /** @internal */\n public set volume(value: number) {\n this._gainNode.gain.value = value;\n }\n\n /** @internal */\n public override dispose(): void {\n super.dispose();\n\n this._gainNode.disconnect();\n this._destinationNode.disconnect();\n }\n\n /** @internal */\n public getClassName(): string {\n return \"_WebAudioMainOut\";\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Nullable } from "../../types";
|
|
2
|
+
import type { AbstractAudioNode } from "../abstractAudio/abstractAudioNode";
|
|
3
|
+
import type { _AbstractAudioSubNode } from "../abstractAudio/subNodes/abstractAudioSubNode";
|
|
4
|
+
import type { _WebAudioEngine } from "./webAudioEngine";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export interface IWebAudioInNode extends AbstractAudioNode {
|
|
7
|
+
/** @internal */
|
|
8
|
+
inNode: Nullable<AudioNode>;
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export interface IWebAudioOutNode extends AbstractAudioNode {
|
|
12
|
+
/** @internal */
|
|
13
|
+
outNode: Nullable<AudioNode>;
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
export interface IWebAudioSubNode extends _AbstractAudioSubNode {
|
|
17
|
+
/** @internal */
|
|
18
|
+
node: AudioNode;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
export interface IWebAudioSuperNode extends IWebAudioInNode, IWebAudioOutNode {
|
|
22
|
+
/** @internal */
|
|
23
|
+
engine: _WebAudioEngine;
|
|
24
|
+
}
|