@babylonjs/core 8.36.0 → 8.37.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/Actions/action.d.ts +5 -0
- package/Actions/action.js.map +1 -1
- package/Actions/actionManager.js +6 -2
- package/Actions/actionManager.js.map +1 -1
- package/Animations/runtimeAnimation.d.ts +0 -2
- package/Animations/runtimeAnimation.js +3 -5
- package/Animations/runtimeAnimation.js.map +1 -1
- package/AudioV2/abstractAudio/abstractSound.js +1 -0
- package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
- package/AudioV2/abstractAudio/audioEngineV2.d.ts +0 -4
- package/AudioV2/abstractAudio/audioEngineV2.js +0 -4
- package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
- package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js +1 -1
- package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js.map +1 -1
- package/AudioV2/audioParameter.d.ts +5 -1
- package/AudioV2/audioParameter.js +4 -0
- package/AudioV2/audioParameter.js.map +1 -1
- package/AudioV2/webAudio/components/webAudioParameterComponent.d.ts +0 -18
- package/AudioV2/webAudio/components/webAudioParameterComponent.js +7 -67
- package/AudioV2/webAudio/components/webAudioParameterComponent.js.map +1 -1
- package/AudioV2/webAudio/webAudioStaticSound.js +8 -3
- package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
- package/Cameras/camera.js +1 -0
- package/Cameras/camera.js.map +1 -1
- package/Cameras/targetCamera.js +0 -4
- package/Cameras/targetCamera.js.map +1 -1
- package/Collisions/gpuPicker.js +0 -1
- package/Collisions/gpuPicker.js.map +1 -1
- package/Culling/ray.core.js +1 -1
- package/Culling/ray.core.js.map +1 -1
- package/Debug/debugLayer.d.ts +1 -1
- package/Debug/debugLayer.js.map +1 -1
- package/Decorators/nodeDecorator.d.ts +3 -1
- package/Decorators/nodeDecorator.js +2 -0
- package/Decorators/nodeDecorator.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +1 -1
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheSampler.js +4 -0
- package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/nativeEngine.js +12 -13
- package/Engines/nativeEngine.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/anaglyphPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/anaglyphPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/anaglyphPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.d.ts +44 -0
- package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js +152 -0
- package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/chromaticAberrationPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/chromaticAberrationPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/chromaticAberrationPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/colorCorrectionPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/colorCorrectionPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/colorCorrectionPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/convolutionPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/convolutionPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/convolutionPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/filterPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/filterPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/filterPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/fxaaPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/fxaaPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/fxaaPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/grainPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/grainPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/grainPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/imageProcessingPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/imageProcessingPostProcessBlock.js +3 -3
- package/FrameGraph/Node/Blocks/PostProcesses/imageProcessingPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/motionBlurPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/motionBlurPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/motionBlurPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.d.ts +3 -3
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js +3 -3
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/screenSpaceCurvaturePostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/screenSpaceCurvaturePostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/screenSpaceCurvaturePostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/sharpenPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/sharpenPostProcessBlock.js +4 -4
- package/FrameGraph/Node/Blocks/PostProcesses/sharpenPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/taaPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/taaPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/taaPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/tonemapPostProcessBlock.d.ts +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/tonemapPostProcessBlock.js +2 -2
- package/FrameGraph/Node/Blocks/PostProcesses/tonemapPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +1 -1
- package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +1 -1
- package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.d.ts +20 -1
- package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js +83 -0
- package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/index.d.ts +1 -0
- package/FrameGraph/Node/Blocks/index.js +1 -0
- package/FrameGraph/Node/Blocks/index.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.d.ts +7 -1
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +8 -2
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/taaTask.d.ts +1 -1
- package/FrameGraph/Tasks/PostProcesses/taaTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +4 -4
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +3 -4
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +4 -4
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js +3 -3
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +2 -3
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +1 -2
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.d.ts +3 -1
- package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.js +11 -1
- package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.d.ts +11 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js +10 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
- package/FrameGraph/frameGraphContext.d.ts +8 -1
- package/FrameGraph/frameGraphContext.js +9 -0
- package/FrameGraph/frameGraphContext.js.map +1 -1
- package/FrameGraph/frameGraphRenderContext.d.ts +5 -2
- package/FrameGraph/frameGraphRenderContext.js +32 -7
- package/FrameGraph/frameGraphRenderContext.js.map +1 -1
- package/FrameGraph/frameGraphTask.d.ts +8 -0
- package/FrameGraph/frameGraphTask.js +12 -0
- package/FrameGraph/frameGraphTask.js.map +1 -1
- package/Materials/PBR/openpbrMaterial.js +2 -1
- package/Materials/PBR/openpbrMaterial.js.map +1 -1
- package/Materials/Textures/mirrorTexture.js +4 -1
- package/Materials/Textures/mirrorTexture.js.map +1 -1
- package/Materials/floatingOriginMatrixOverrides.js +19 -0
- package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
- package/Maths/math.like.d.ts +2 -7
- package/Maths/math.like.js.map +1 -1
- package/Maths/math.vector.functions.d.ts +7 -10
- package/Maths/math.vector.functions.js +3 -14
- package/Maths/math.vector.functions.js.map +1 -1
- package/Meshes/Node/Blocks/randomBlock.js +11 -11
- package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
- package/Misc/copyTextureToTexture.d.ts +18 -1
- package/Misc/copyTextureToTexture.js +31 -2
- package/Misc/copyTextureToTexture.js.map +1 -1
- package/Particles/EmitterTypes/coneParticleEmitter.d.ts +3 -3
- package/Particles/EmitterTypes/coneParticleEmitter.js +11 -11
- package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/customParticleEmitter.d.ts +5 -3
- package/Particles/EmitterTypes/customParticleEmitter.js +8 -6
- package/Particles/EmitterTypes/customParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/sphereParticleEmitter.d.ts +3 -1
- package/Particles/EmitterTypes/sphereParticleEmitter.js +7 -1
- package/Particles/EmitterTypes/sphereParticleEmitter.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/boxShapeBlock.d.ts +1 -1
- package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +2 -1
- package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/coneShapeBlock.d.ts +6 -4
- package/Particles/Node/Blocks/Emitters/coneShapeBlock.js +34 -35
- package/Particles/Node/Blocks/Emitters/coneShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/createParticleBlock.d.ts +0 -4
- package/Particles/Node/Blocks/Emitters/createParticleBlock.js +2 -9
- package/Particles/Node/Blocks/Emitters/createParticleBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/customShapeBlock.d.ts +13 -9
- package/Particles/Node/Blocks/Emitters/customShapeBlock.js +36 -23
- package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.d.ts +10 -1
- package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +50 -17
- package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/emitters.functions.d.ts +6 -0
- package/Particles/Node/Blocks/Emitters/emitters.functions.js +13 -0
- package/Particles/Node/Blocks/Emitters/emitters.functions.js.map +1 -0
- package/Particles/Node/Blocks/Emitters/meshShapeBlock.d.ts +2 -2
- package/Particles/Node/Blocks/Emitters/meshShapeBlock.js +5 -1
- package/Particles/Node/Blocks/Emitters/meshShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/pointShapeBlock.d.ts +1 -1
- package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +3 -1
- package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.d.ts +16 -1
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +67 -14
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/particleInputBlock.js +1 -0
- package/Particles/Node/Blocks/particleInputBlock.js.map +1 -1
- package/Particles/Node/Blocks/particleRandomBlock.js +10 -10
- package/Particles/Node/Blocks/particleRandomBlock.js.map +1 -1
- package/Particles/Node/Blocks/systemBlock.d.ts +3 -3
- package/Particles/Node/Blocks/systemBlock.js +10 -6
- package/Particles/Node/Blocks/systemBlock.js.map +1 -1
- package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +3 -1
- package/Particles/Node/Enums/nodeParticleContextualSources.js +2 -0
- package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -1
- package/Particles/Node/nodeParticleBuildState.js +5 -0
- package/Particles/Node/nodeParticleBuildState.js.map +1 -1
- package/Particles/Node/nodeParticleSystemSet.helper.js +132 -36
- package/Particles/Node/nodeParticleSystemSet.helper.js.map +1 -1
- package/Particles/Node/nodeParticleSystemSet.js +1 -1
- package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
- package/Particles/thinParticleSystem.function.d.ts +2 -2
- package/Particles/thinParticleSystem.function.js +2 -2
- package/Particles/thinParticleSystem.function.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +27 -4
- package/Physics/v2/Plugins/havokPlugin.js +72 -8
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsEngine.d.ts +12 -2
- package/Physics/v2/physicsEngine.js +15 -1
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +2 -1
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
- package/Rendering/prePassRenderer.js +4 -1
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Shaders/copyTextureToTexture.fragment.js +2 -2
- package/Shaders/copyTextureToTexture.fragment.js.map +1 -1
- package/Shaders/picking.fragment.js +1 -1
- package/Shaders/picking.fragment.js.map +1 -1
- package/Shaders/picking.vertex.js +1 -1
- package/Shaders/picking.vertex.js.map +1 -1
- package/ShadersWGSL/copyTextureToTexture.fragment.js +3 -3
- package/ShadersWGSL/copyTextureToTexture.fragment.js.map +1 -1
- package/ShadersWGSL/picking.fragment.js +1 -1
- package/ShadersWGSL/picking.fragment.js.map +1 -1
- package/ShadersWGSL/picking.vertex.js +1 -1
- package/ShadersWGSL/picking.vertex.js.map +1 -1
- package/Sprites/spriteRenderer.js +10 -8
- package/Sprites/spriteRenderer.js.map +1 -1
- package/XR/features/WebXRLightEstimation.d.ts +8 -0
- package/XR/features/WebXRLightEstimation.js +6 -1
- package/XR/features/WebXRLightEstimation.js.map +1 -1
- package/XR/webXRSessionManager.js +4 -0
- package/XR/webXRSessionManager.js.map +1 -1
- package/assetContainer.d.ts +1 -1
- package/assetContainer.js +1 -1
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +2 -4
- package/scene.js +9 -12
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstractSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/abstractSound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,OAAO,EAAE,mBAAmB,EAA4B,MAAM,uBAAuB,CAAC;AA4CtF;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,mBAAmB;IAa3D,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,+CAAuC,CAAC,CAAC,4BAA4B;QAbnF,oBAAe,GAAqC,IAAI,CAAC;QACzD,sBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;QACtD,WAAM,8BAAkC;QAEtC,eAAU,GAAwC,IAAI,CAAC,iBAAiB,CAAC;QAGnF;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AS,CAAC,KAAiB;QACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAIS,oBAAoB;QAC1B,IAAI,IAAI,CAAC,YAAY,GAAG,QAAQ,EAAE,CAAC;YAC/B,MAAM,uBAAuB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,+BAAuB,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YACnJ,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,uBAAuB,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;gBACjC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpB,CAAC;QACL,CAAC;IACL,CAAC;CAcJ","sourcesContent":["import { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport { SoundState } from \"../soundState\";\nimport { AudioNodeType } from \"./abstractAudioNode\";\nimport type { _AbstractSoundInstance } from \"./abstractSoundInstance\";\nimport { AbstractSoundSource, type ISoundSourceOptions } from \"./abstractSoundSource\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\n\n/** @internal */\nexport interface IAbstractSoundOptionsBase {\n /**\n * Whether the sound should start playing automatically. Defaults to `false`.\n */\n autoplay: boolean;\n /**\n * The maximum number of instances that can play at the same time. Defaults to `Infinity`.\n */\n maxInstances: number;\n}\n\n/** @internal */\nexport interface IAbstractSoundPlayOptionsBase {\n /**\n * Whether the sound should loop. Defaults to `false`.\n */\n loop: boolean;\n /**\n * The time within the sound buffer to start playing at, in seconds. Defaults to `0`.\n */\n startOffset: number;\n}\n\n/**\n * Options for creating a sound.\n */\nexport interface IAbstractSoundOptions extends IAbstractSoundOptionsBase, IAbstractSoundPlayOptions, ISoundSourceOptions {}\n\n/**\n * Options for playing a sound.\n */\nexport interface IAbstractSoundPlayOptions extends IAbstractSoundPlayOptionsBase, IVolumeAudioOptions {}\n\n/**\n * Options stored in a sound.\n * @internal\n */\nexport interface IAbstractSoundStoredOptions extends IAbstractSoundOptionsBase, IAbstractSoundPlayOptionsBase {}\n\n/**\n * Abstract class representing a sound in the audio engine.\n */\nexport abstract class AbstractSound extends AbstractSoundSource {\n private _newestInstance: Nullable<_AbstractSoundInstance> = null;\n private _privateInstances = new Set<_AbstractSoundInstance>();\n private _state: SoundState = SoundState.Stopped;\n\n protected _instances: ReadonlySet<_AbstractSoundInstance> = this._privateInstances;\n protected abstract readonly _options: IAbstractSoundStoredOptions;\n\n /**\n * Observable for when the sound stops playing.\n */\n public readonly onEndedObservable = new Observable<AbstractSound>();\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine, AudioNodeType.HAS_INPUTS_AND_OUTPUTS); // Inputs are for instances.\n }\n\n /**\n * The number of active instances of the sound that are currently playing.\n */\n public get activeInstancesCount(): number {\n return this._instances.size;\n }\n\n /**\n * Whether the sound should start playing automatically. Defaults to `false`.\n */\n public get autoplay(): boolean {\n return this._options.autoplay;\n }\n\n /**\n * The current playback time of the sound, in seconds.\n */\n public get currentTime(): number {\n const instance = this._getNewestInstance();\n return instance ? instance.currentTime : 0;\n }\n\n public set currentTime(value: number) {\n this.startOffset = value;\n\n const instance = this._getNewestInstance();\n if (instance) {\n instance.currentTime = value;\n }\n }\n\n /**\n * Whether the sound should loop. Defaults to `false`.\n */\n public get loop(): boolean {\n return this._options.loop;\n }\n\n public set loop(value: boolean) {\n this._options.loop = value;\n }\n\n /**\n * The maximum number of instances that can play at the same time. Defaults to `Infinity`.\n */\n public get maxInstances(): number {\n return this._options.maxInstances;\n }\n\n public set maxInstances(value: number) {\n this._options.maxInstances = value;\n }\n\n /**\n * The time within the sound buffer to start playing at, in seconds. Defaults to `0`.\n */\n public get startOffset(): number {\n return this._options.startOffset;\n }\n\n public set startOffset(value: number) {\n this._options.startOffset = value;\n }\n\n /**\n * The state of the sound.\n */\n public get state(): SoundState {\n return this._state;\n }\n\n /**\n * Releases associated resources.\n */\n public override dispose(): void {\n super.dispose();\n\n this.stop();\n\n this._newestInstance = null;\n\n this._privateInstances.clear();\n this.onEndedObservable.clear();\n }\n\n /**\n * Plays the sound.\n * - Triggers `onEndedObservable` if played for the full duration and the `loop` option is not set.\n * @param options The options to use when playing the sound. Options set here override the sound's options.\n */\n public abstract play(options?: Partial<IAbstractSoundPlayOptions>): void;\n\n /**\n * Pauses the sound.\n */\n public pause(): void {\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n next.value.pause();\n }\n\n this._state = SoundState.Paused;\n }\n\n /**\n * Resumes the sound.\n */\n public resume(): void {\n if (this._state !== SoundState.Paused) {\n return;\n }\n\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n next.value.resume();\n }\n\n this._state = SoundState.Started;\n }\n\n /**\n * Stops the sound.\n * - Triggers `onEndedObservable` if the sound is playing.\n */\n public abstract stop(): void;\n\n protected _beforePlay(instance: _AbstractSoundInstance): void {\n if (this.state === SoundState.Paused && this._instances.size > 0) {\n this.resume();\n return;\n }\n\n instance.onEndedObservable.addOnce(this._onInstanceEnded);\n this._privateInstances.add(instance);\n this._newestInstance = instance;\n }\n\n protected _afterPlay(instance: _AbstractSoundInstance): void {\n this._state = instance.state;\n }\n\n protected _getNewestInstance(): Nullable<_AbstractSoundInstance> {\n if (this._instances.size === 0) {\n return null;\n }\n\n if (!this._newestInstance) {\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n this._newestInstance = next.value;\n }\n }\n\n return this._newestInstance;\n }\n\n protected _setState(state: SoundState): void {\n this._state = state;\n }\n\n protected abstract _createInstance(): _AbstractSoundInstance;\n\n protected _stopExcessInstances(): void {\n if (this.maxInstances < Infinity) {\n const numberOfInstancesToStop = Array.from(this._instances).filter((instance) => instance.state === SoundState.Started).length - this.maxInstances;\n const it = this._instances.values();\n\n for (let i = 0; i < numberOfInstancesToStop; i++) {\n const instance = it.next().value;\n instance.stop();\n }\n }\n }\n\n private _onInstanceEnded: (instance: _AbstractSoundInstance) => void = (instance) => {\n if (this._newestInstance === instance) {\n this._newestInstance = null;\n }\n\n this._privateInstances.delete(instance);\n\n if (this._instances.size === 0) {\n this._state = SoundState.Stopped;\n this.onEndedObservable.notifyObservers(this);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"abstractSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/abstractSound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,OAAO,EAAE,mBAAmB,EAA4B,MAAM,uBAAuB,CAAC;AA4CtF;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,mBAAmB;IAa3D,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,+CAAuC,CAAC,CAAC,4BAA4B;QAbnF,oBAAe,GAAqC,IAAI,CAAC;QACzD,sBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;QACtD,WAAM,8BAAkC;QAEtC,eAAU,GAAwC,IAAI,CAAC,iBAAiB,CAAC;QAGnF;;WAEG;QACa,sBAAiB,GAAG,IAAI,UAAU,EAAiB,CAAC;QAoL5D,qBAAgB,GAA+C,CAAC,QAAQ,EAAE,EAAE;YAChF,IAAI,IAAI,CAAC,eAAe,KAAK,QAAQ,EAAE,CAAC;gBACpC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAChC,CAAC;YAED,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAExC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,C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C,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YACnJ,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,uBAAuB,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;gBACjC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpB,CAAC;QACL,CAAC;IACL,CAAC;CAgBJ","sourcesContent":["import { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport { SoundState } from \"../soundState\";\nimport { AudioNodeType } from \"./abstractAudioNode\";\nimport type { _AbstractSoundInstance } from \"./abstractSoundInstance\";\nimport { AbstractSoundSource, type ISoundSourceOptions } from \"./abstractSoundSource\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\n\n/** @internal */\nexport interface IAbstractSoundOptionsBase {\n /**\n * Whether the sound should start playing automatically. Defaults to `false`.\n */\n autoplay: boolean;\n /**\n * The maximum number of instances that can play at the same time. Defaults to `Infinity`.\n */\n maxInstances: number;\n}\n\n/** @internal */\nexport interface IAbstractSoundPlayOptionsBase {\n /**\n * Whether the sound should loop. Defaults to `false`.\n */\n loop: boolean;\n /**\n * The time within the sound buffer to start playing at, in seconds. Defaults to `0`.\n */\n startOffset: number;\n}\n\n/**\n * Options for creating a sound.\n */\nexport interface IAbstractSoundOptions extends IAbstractSoundOptionsBase, IAbstractSoundPlayOptions, ISoundSourceOptions {}\n\n/**\n * Options for playing a sound.\n */\nexport interface IAbstractSoundPlayOptions extends IAbstractSoundPlayOptionsBase, IVolumeAudioOptions {}\n\n/**\n * Options stored in a sound.\n * @internal\n */\nexport interface IAbstractSoundStoredOptions extends IAbstractSoundOptionsBase, IAbstractSoundPlayOptionsBase {}\n\n/**\n * Abstract class representing a sound in the audio engine.\n */\nexport abstract class AbstractSound extends AbstractSoundSource {\n private _newestInstance: Nullable<_AbstractSoundInstance> = null;\n private _privateInstances = new Set<_AbstractSoundInstance>();\n private _state: SoundState = SoundState.Stopped;\n\n protected _instances: ReadonlySet<_AbstractSoundInstance> = this._privateInstances;\n protected abstract readonly _options: IAbstractSoundStoredOptions;\n\n /**\n * Observable for when the sound stops playing.\n */\n public readonly onEndedObservable = new Observable<AbstractSound>();\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine, AudioNodeType.HAS_INPUTS_AND_OUTPUTS); // Inputs are for instances.\n }\n\n /**\n * The number of active instances of the sound that are currently playing.\n */\n public get activeInstancesCount(): number {\n return this._instances.size;\n }\n\n /**\n * Whether the sound should start playing automatically. Defaults to `false`.\n */\n public get autoplay(): boolean {\n return this._options.autoplay;\n }\n\n /**\n * The current playback time of the sound, in seconds.\n */\n public get currentTime(): number {\n const instance = this._getNewestInstance();\n return instance ? instance.currentTime : 0;\n }\n\n public set currentTime(value: number) {\n this.startOffset = value;\n\n const instance = this._getNewestInstance();\n if (instance) {\n instance.currentTime = value;\n }\n }\n\n /**\n * Whether the sound should loop. Defaults to `false`.\n */\n public get loop(): boolean {\n return this._options.loop;\n }\n\n public set loop(value: boolean) {\n this._options.loop = value;\n }\n\n /**\n * The maximum number of instances that can play at the same time. Defaults to `Infinity`.\n */\n public get maxInstances(): number {\n return this._options.maxInstances;\n }\n\n public set maxInstances(value: number) {\n this._options.maxInstances = value;\n }\n\n /**\n * The time within the sound buffer to start playing at, in seconds. Defaults to `0`.\n */\n public get startOffset(): number {\n return this._options.startOffset;\n }\n\n public set startOffset(value: number) {\n this._options.startOffset = value;\n }\n\n /**\n * The state of the sound.\n */\n public get state(): SoundState {\n return this._state;\n }\n\n /**\n * Releases associated resources.\n */\n public override dispose(): void {\n super.dispose();\n\n this.stop();\n\n this._newestInstance = null;\n\n this._privateInstances.clear();\n this.onEndedObservable.clear();\n }\n\n /**\n * Plays the sound.\n * - Triggers `onEndedObservable` if played for the full duration and the `loop` option is not set.\n * @param options The options to use when playing the sound. Options set here override the sound's options.\n */\n public abstract play(options?: Partial<IAbstractSoundPlayOptions>): void;\n\n /**\n * Pauses the sound.\n */\n public pause(): void {\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n next.value.pause();\n }\n\n this._state = SoundState.Paused;\n }\n\n /**\n * Resumes the sound.\n */\n public resume(): void {\n if (this._state !== SoundState.Paused) {\n return;\n }\n\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n next.value.resume();\n }\n\n this._state = SoundState.Started;\n }\n\n /**\n * Stops the sound.\n * - Triggers `onEndedObservable` if the sound is playing.\n */\n public abstract stop(): void;\n\n protected _beforePlay(instance: _AbstractSoundInstance): void {\n if (this.state === SoundState.Paused && this._instances.size > 0) {\n this.resume();\n return;\n }\n\n instance.onEndedObservable.addOnce(this._onInstanceEnded);\n this._privateInstances.add(instance);\n this._newestInstance = instance;\n }\n\n protected _afterPlay(instance: _AbstractSoundInstance): void {\n this._state = instance.state;\n }\n\n protected _getNewestInstance(): Nullable<_AbstractSoundInstance> {\n if (this._instances.size === 0) {\n return null;\n }\n\n if (!this._newestInstance) {\n const it = this._instances.values();\n for (let next = it.next(); !next.done; next = it.next()) {\n this._newestInstance = next.value;\n }\n }\n\n return this._newestInstance;\n }\n\n protected _setState(state: SoundState): void {\n this._state = state;\n }\n\n protected abstract _createInstance(): _AbstractSoundInstance;\n\n protected _stopExcessInstances(): void {\n if (this.maxInstances < Infinity) {\n const numberOfInstancesToStop = Array.from(this._instances).filter((instance) => instance.state === SoundState.Started).length - this.maxInstances;\n const it = this._instances.values();\n\n for (let i = 0; i < numberOfInstancesToStop; i++) {\n const instance = it.next().value;\n instance.stop();\n }\n }\n }\n\n private _onInstanceEnded: (instance: _AbstractSoundInstance) => void = (instance) => {\n if (this._newestInstance === instance) {\n this._newestInstance = null;\n }\n\n this._privateInstances.delete(instance);\n\n if (this._instances.size === 0) {\n this._state = SoundState.Stopped;\n this.onEndedObservable.notifyObservers(this);\n }\n\n instance.dispose();\n };\n}\n"]}
|
|
@@ -83,10 +83,6 @@ export declare abstract class AudioEngineV2 {
|
|
|
83
83
|
abstract volume: number;
|
|
84
84
|
/**
|
|
85
85
|
* The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).
|
|
86
|
-
*
|
|
87
|
-
* Due to limitations in some browsers, it is not recommended to set this value to longer than `0.01` seconds.
|
|
88
|
-
*
|
|
89
|
-
* Setting this value to longer than `0.01` seconds may result in errors being throw when setting audio parameters.
|
|
90
86
|
*/
|
|
91
87
|
get parameterRampDuration(): number;
|
|
92
88
|
set parameterRampDuration(value: number);
|
|
@@ -45,10 +45,6 @@ export class AudioEngineV2 {
|
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).
|
|
48
|
-
*
|
|
49
|
-
* Due to limitations in some browsers, it is not recommended to set this value to longer than `0.01` seconds.
|
|
50
|
-
*
|
|
51
|
-
* Setting this value to longer than `0.01` seconds may result in errors being throw when setting audio parameters.
|
|
52
48
|
*/
|
|
53
49
|
get parameterRampDuration() {
|
|
54
50
|
return this._parameterRampDuration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audioEngineV2.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/audioEngineV2.ts"],"names":[],"mappings":"AAYA,MAAM,SAAS,GAAoB,EAAE,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IAClC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC;AAsBD;;;;GAIG;AACH,MAAM,OAAgB,aAAa;IAa/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3F,MAAM,UAAU,yBAAyB,CACrC,IAAY,EACZ,MAA4C,EAC5C,UAA2C,EAAE,EAC7C,SAAkC,IAAI;IAEtC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\nimport type { IAudioParameterRampOptions } from \"../audioParameter\";\nimport type { AbstractAudioNode, AbstractNamedAudioNode } from \"./abstractAudioNode\";\nimport type { AbstractSound } from \"./abstractSound\";\nimport type { AbstractSoundSource, ISoundSourceOptions } from \"./abstractSoundSource\";\nimport type { AudioBus, IAudioBusOptions } from \"./audioBus\";\nimport type { IMainAudioBusOptions, MainAudioBus } from \"./mainAudioBus\";\nimport type { IStaticSoundOptions, StaticSound } from \"./staticSound\";\nimport type { IStaticSoundBufferOptions, StaticSoundBuffer } from \"./staticSoundBuffer\";\nimport type { IStreamingSoundOptions, StreamingSound } from \"./streamingSound\";\nimport type { AbstractSpatialAudioListener, ISpatialAudioListenerOptions } from \"./subProperties/abstractSpatialAudioListener\";\n\nconst Instances: AudioEngineV2[] = [];\n\n/**\n * Gets the most recently created v2 audio engine.\n * @returns The most recently created v2 audio engine.\n */\nexport function LastCreatedAudioEngine(): Nullable<AudioEngineV2> {\n if (Instances.length === 0) {\n return null;\n }\n\n return Instances[Instances.length - 1];\n}\n\n/**\n * Options for creating a v2 audio engine.\n */\nexport interface IAudioEngineV2Options extends ISpatialAudioListenerOptions {\n /**\n * The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).\n */\n parameterRampDuration: number;\n /**\n * The initial output volume of the audio engine. Defaults to `1`.\n */\n volume: number;\n}\n\n/**\n * The state of a v2 audio engine.\n * @see {@link AudioEngineV2.state}\n */\nexport type AudioEngineV2State = \"closed\" | \"interrupted\" | \"running\" | \"suspended\";\n\n/**\n * Abstract base class for v2 audio engines.\n *\n * A v2 audio engine based on the WebAudio API can be created with the {@link CreateAudioEngineAsync} function.\n */\nexport abstract class AudioEngineV2 {\n /** Not owned, but all items should be in `_nodes` container, too, which is owned. */\n private readonly _mainBuses = new Set<MainAudioBus>();\n private readonly _sounds = new Set<AbstractSound>();\n private _soundsArray: Nullable<Array<AbstractSound>> = null;\n\n /** Owned top-level sound and bus nodes. */\n private readonly _nodes = new Set<AbstractNamedAudioNode>();\n\n private _defaultMainBus: Nullable<MainAudioBus> = null;\n\n private _parameterRampDuration: number = 0.01;\n\n protected constructor(options: Partial<IAudioEngineV2Options>) {\n Instances.push(this);\n\n if (typeof options.parameterRampDuration === \"number\") {\n this.parameterRampDuration = options.parameterRampDuration;\n }\n }\n\n /**\n * The elapsed time since the audio engine was started, in seconds.\n */\n public abstract readonly currentTime: number;\n\n /**\n * The default main bus that will be used for audio buses and sounds if their `outBus` option is not set.\n * @see {@link IAudioBusOptions.outBus}\n * @see {@link IAbstractSoundOptions.outBus}\n */\n public get defaultMainBus(): Nullable<MainAudioBus> {\n if (this._mainBuses.size === 0) {\n return null;\n }\n\n if (!this._defaultMainBus) {\n this._defaultMainBus = Array.from(this._mainBuses)[0];\n }\n\n return this._defaultMainBus;\n }\n\n /**\n * The spatial audio listener properties for the audio engine.\n * - Each audio engine has exactly one listener.\n */\n public abstract readonly listener: AbstractSpatialAudioListener;\n\n /**\n * The main output node.\n * - This is the last node in the audio graph before the audio is sent to the speakers.\n */\n public abstract readonly mainOut: AbstractAudioNode;\n\n /**\n * The current state of the audio engine.\n *\n * Possible values are:\n * - `\"closed\"`: The audio engine has been closed.\n * - `\"interrupted\"`: The audio engine has been interrupted and is not running.\n * - `\"running\"`: The audio engine is running normally.\n * - `\"suspended\"`: The audio engine is suspended and is not running.\n */\n public abstract readonly state: AudioEngineV2State;\n\n /**\n * The output volume of the audio engine.\n */\n public abstract volume: number;\n\n /**\n * The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).\n *\n * Due to limitations in some browsers, it is not recommended to set this value to longer than `0.01` seconds.\n *\n * Setting this value to longer than `0.01` seconds may result in errors being throw when setting audio parameters.\n */\n public get parameterRampDuration(): number {\n return this._parameterRampDuration;\n }\n\n public set parameterRampDuration(value: number) {\n this._parameterRampDuration = Math.max(0, value);\n }\n\n /**\n * The list of static and streaming sounds created by the audio engine.\n */\n public get sounds(): ReadonlyArray<AbstractSound> {\n if (!this._soundsArray) {\n this._soundsArray = Array.from(this._sounds);\n }\n return this._soundsArray;\n }\n\n /**\n * Creates a new audio bus.\n * @param name - The name of the audio bus.\n * @param options - The options to use when creating the audio bus.\n * @returns A promise that resolves with the created audio bus.\n */\n public abstract createBusAsync(name: string, options?: Partial<IAudioBusOptions>): Promise<AudioBus>;\n\n /**\n * Creates a new main audio bus.\n * @param name - The name of the main audio bus.\n * @param options - The options to use when creating the main audio bus.\n * @returns A promise that resolves with the created main audio bus.\n */\n public abstract createMainBusAsync(name: string, options?: Partial<IMainAudioBusOptions>): Promise<MainAudioBus>;\n\n /**\n * Creates a new microphone sound source.\n * @param name - The name of the sound.\n * @param options - The options for the sound source.\n * @returns A promise that resolves to the created sound source.\n */\n public abstract createMicrophoneSoundSourceAsync(name: string, options?: Partial<ISoundSourceOptions>): Promise<AbstractSoundSource>;\n\n /**\n * Creates a new static sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the static sound.\n * @returns A promise that resolves to the created static sound.\n */\n public abstract createSoundAsync(\n name: string,\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options?: Partial<IStaticSoundOptions>\n ): Promise<StaticSound>;\n\n /**\n * Creates a new static sound buffer.\n * @param source - The source of the sound buffer.\n * @param options - The options for the static sound buffer.\n * @returns A promise that resolves to the created static sound buffer.\n */\n public abstract createSoundBufferAsync(\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options?: Partial<IStaticSoundBufferOptions>\n ): Promise<StaticSoundBuffer>;\n\n /**\n * Creates a new sound source.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the sound source.\n * @returns A promise that resolves to the created sound source.\n */\n public abstract createSoundSourceAsync(name: string, source: AudioNode, options?: Partial<ISoundSourceOptions>): Promise<AbstractSoundSource>;\n\n /**\n * Creates a new streaming sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the streaming sound.\n * @returns A promise that resolves to the created streaming sound.\n */\n public abstract createStreamingSoundAsync(name: string, source: HTMLMediaElement | string | string[], options?: Partial<IStreamingSoundOptions>): Promise<StreamingSound>;\n\n /**\n * Releases associated resources.\n */\n public dispose(): void {\n if (Instances.includes(this)) {\n Instances.splice(Instances.indexOf(this), 1);\n }\n\n const nodeIt = this._nodes.values();\n for (let next = nodeIt.next(); !next.done; next = nodeIt.next()) {\n next.value.dispose();\n }\n\n this._mainBuses.clear();\n this._nodes.clear();\n this._sounds.clear();\n\n this._disposeSoundsArray();\n\n this._defaultMainBus = null;\n }\n\n /**\n * Checks if the specified format is valid.\n * @param format The format to check as an audio file extension like \"mp3\" or \"wav\".\n * @returns `true` if the format is valid; otherwise `false`.\n */\n public abstract isFormatValid(format: string): boolean;\n\n /**\n * Pauses the audio engine if it is running.\n * @returns A promise that resolves when the audio engine is paused.\n */\n public abstract pauseAsync(): Promise<void>;\n\n /**\n * Resumes the audio engine if it is not running.\n * @returns A promise that resolves when the audio engine is running.\n */\n public abstract resumeAsync(): Promise<void>;\n\n /**\n * Sets the audio output volume with optional ramping.\n * If the duration is 0 then the volume is set immediately, otherwise it is ramped to the new value over the given duration using the given shape.\n * If a ramp is already in progress then the volume is not set and an error is thrown.\n * @param value The value to set the volume to.\n * @param options The options to use for ramping the volume change.\n */\n public abstract setVolume(value: number, options?: Partial<IAudioParameterRampOptions>): void;\n\n /**\n * Unlocks the audio engine if it is locked.\n * - Note that the returned promise may already be resolved if the audio engine is already unlocked.\n * @returns A promise that is resolved when the audio engine is unlocked.\n */\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\n public unlockAsync(): Promise<void> {\n return this.resumeAsync();\n }\n\n protected _addMainBus(mainBus: MainAudioBus): void {\n this._mainBuses.add(mainBus);\n\n this._addNode(mainBus);\n }\n\n protected _removeMainBus(mainBus: MainAudioBus): void {\n this._mainBuses.delete(mainBus);\n this._defaultMainBus = null;\n\n this._removeNode(mainBus);\n }\n\n protected _addNode(node: AbstractNamedAudioNode): void {\n this._nodes.add(node);\n }\n\n protected _removeNode(node: AbstractNamedAudioNode): void {\n this._nodes.delete(node);\n }\n\n protected _addSound(sound: AbstractSound): void {\n this._disposeSoundsArray();\n this._sounds.add(sound);\n this._addNode(sound);\n }\n\n protected _removeSound(sound: AbstractSound): void {\n this._disposeSoundsArray();\n this._sounds.delete(sound);\n this._removeNode(sound);\n }\n\n private _disposeSoundsArray(): void {\n if (this._soundsArray) {\n this._soundsArray.length = 0;\n this._soundsArray = null;\n }\n }\n}\n\n/**\n * @internal\n * @param engine - The given audio engine. If `null` then the last created audio engine is used.\n * @returns the given audio engine or the last created audio engine.\n * @throws An error if the resulting engine is `null`.\n */\nexport function _GetAudioEngine(engine: Nullable<AudioEngineV2>): AudioEngineV2 {\n if (!engine) {\n engine = LastCreatedAudioEngine();\n }\n\n if (engine) {\n return engine;\n }\n\n throw new Error(\"No audio engine.\");\n}\n\n/**\n * Creates a new audio bus.\n * @param name - The name of the audio bus.\n * @param options - The options to use when creating the audio bus.\n * @param engine - The audio engine.\n * @returns A promise that resolves with the created audio bus.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateAudioBusAsync(name: string, options: Partial<IAudioBusOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<AudioBus> {\n engine = _GetAudioEngine(engine);\n return engine.createBusAsync(name, options);\n}\n\n/**\n * Creates a new main audio bus.\n * @param name - The name of the main audio bus.\n * @param options - The options to use when creating the main audio bus.\n * @param engine - The audio engine.\n * @returns A promise that resolves with the created main audio bus.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateMainAudioBusAsync(name: string, options: Partial<IMainAudioBusOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<MainAudioBus> {\n engine = _GetAudioEngine(engine);\n return engine.createMainBusAsync(name, options);\n}\n\n/**\n * Creates a new microphone sound source.\n * @param name - The name of the sound.\n * @param options - The options for the sound source.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created sound source.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateMicrophoneSoundSourceAsync(name: string, options: Partial<ISoundSourceOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<AbstractSoundSource> {\n engine = _GetAudioEngine(engine);\n return engine.createMicrophoneSoundSourceAsync(name, options);\n}\n\n/**\n * Creates a new static sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the static sound.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created static sound.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateSoundAsync(\n name: string,\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StaticSound> {\n engine = _GetAudioEngine(engine);\n return engine.createSoundAsync(name, source, options);\n}\n\n/**\n * Creates a new static sound buffer.\n * @param source - The source of the sound buffer.\n * @param options - The options for the static sound buffer.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created static sound buffer.\n */\nexport async function CreateSoundBufferAsync(\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundBufferOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StaticSoundBuffer> {\n engine = _GetAudioEngine(engine);\n return await engine.createSoundBufferAsync(source, options);\n}\n\n/**\n * Creates a new sound source.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the sound source.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created sound source.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateSoundSourceAsync(\n name: string,\n source: AudioNode,\n options: Partial<ISoundSourceOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<AbstractSoundSource> {\n engine = _GetAudioEngine(engine);\n return engine.createSoundSourceAsync(name, source, options);\n}\n\n/**\n * Creates a new streaming sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the streaming sound.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created streaming sound.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateStreamingSoundAsync(\n name: string,\n source: HTMLMediaElement | string | string[],\n options: Partial<IStreamingSoundOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StreamingSound> {\n engine = _GetAudioEngine(engine);\n return engine.createStreamingSoundAsync(name, source, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"audioEngineV2.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/audioEngineV2.ts"],"names":[],"mappings":"AAYA,MAAM,SAAS,GAAoB,EAAE,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IAClC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC;AAsBD;;;;GAIG;AACH,MAAM,OAAgB,aAAa;IAa/B,YAAsB,OAAuC;QAZ7D,qFAAqF;QACpE,eAAU,GAAG,IAAI,GAAG,EAAgB,CAAC;QACrC,YAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;QAC5C,iBAAY,GAAmC,IAAI,CAAC;QAE5D,2CAA2C;QAC1B,WAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;QAEp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E,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\nimport type { IAudioParameterRampOptions } from \"../audioParameter\";\nimport type { AbstractAudioNode, AbstractNamedAudioNode } from \"./abstractAudioNode\";\nimport type { AbstractSound } from \"./abstractSound\";\nimport type { AbstractSoundSource, ISoundSourceOptions } from \"./abstractSoundSource\";\nimport type { AudioBus, IAudioBusOptions } from \"./audioBus\";\nimport type { IMainAudioBusOptions, MainAudioBus } from \"./mainAudioBus\";\nimport type { IStaticSoundOptions, StaticSound } from \"./staticSound\";\nimport type { IStaticSoundBufferOptions, StaticSoundBuffer } from \"./staticSoundBuffer\";\nimport type { IStreamingSoundOptions, StreamingSound } from \"./streamingSound\";\nimport type { AbstractSpatialAudioListener, ISpatialAudioListenerOptions } from \"./subProperties/abstractSpatialAudioListener\";\n\nconst Instances: AudioEngineV2[] = [];\n\n/**\n * Gets the most recently created v2 audio engine.\n * @returns The most recently created v2 audio engine.\n */\nexport function LastCreatedAudioEngine(): Nullable<AudioEngineV2> {\n if (Instances.length === 0) {\n return null;\n }\n\n return Instances[Instances.length - 1];\n}\n\n/**\n * Options for creating a v2 audio engine.\n */\nexport interface IAudioEngineV2Options extends ISpatialAudioListenerOptions {\n /**\n * The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).\n */\n parameterRampDuration: number;\n /**\n * The initial output volume of the audio engine. Defaults to `1`.\n */\n volume: number;\n}\n\n/**\n * The state of a v2 audio engine.\n * @see {@link AudioEngineV2.state}\n */\nexport type AudioEngineV2State = \"closed\" | \"interrupted\" | \"running\" | \"suspended\";\n\n/**\n * Abstract base class for v2 audio engines.\n *\n * A v2 audio engine based on the WebAudio API can be created with the {@link CreateAudioEngineAsync} function.\n */\nexport abstract class AudioEngineV2 {\n /** Not owned, but all items should be in `_nodes` container, too, which is owned. */\n private readonly _mainBuses = new Set<MainAudioBus>();\n private readonly _sounds = new Set<AbstractSound>();\n private _soundsArray: Nullable<Array<AbstractSound>> = null;\n\n /** Owned top-level sound and bus nodes. */\n private readonly _nodes = new Set<AbstractNamedAudioNode>();\n\n private _defaultMainBus: Nullable<MainAudioBus> = null;\n\n private _parameterRampDuration: number = 0.01;\n\n protected constructor(options: Partial<IAudioEngineV2Options>) {\n Instances.push(this);\n\n if (typeof options.parameterRampDuration === \"number\") {\n this.parameterRampDuration = options.parameterRampDuration;\n }\n }\n\n /**\n * The elapsed time since the audio engine was started, in seconds.\n */\n public abstract readonly currentTime: number;\n\n /**\n * The default main bus that will be used for audio buses and sounds if their `outBus` option is not set.\n * @see {@link IAudioBusOptions.outBus}\n * @see {@link IAbstractSoundOptions.outBus}\n */\n public get defaultMainBus(): Nullable<MainAudioBus> {\n if (this._mainBuses.size === 0) {\n return null;\n }\n\n if (!this._defaultMainBus) {\n this._defaultMainBus = Array.from(this._mainBuses)[0];\n }\n\n return this._defaultMainBus;\n }\n\n /**\n * The spatial audio listener properties for the audio engine.\n * - Each audio engine has exactly one listener.\n */\n public abstract readonly listener: AbstractSpatialAudioListener;\n\n /**\n * The main output node.\n * - This is the last node in the audio graph before the audio is sent to the speakers.\n */\n public abstract readonly mainOut: AbstractAudioNode;\n\n /**\n * The current state of the audio engine.\n *\n * Possible values are:\n * - `\"closed\"`: The audio engine has been closed.\n * - `\"interrupted\"`: The audio engine has been interrupted and is not running.\n * - `\"running\"`: The audio engine is running normally.\n * - `\"suspended\"`: The audio engine is suspended and is not running.\n */\n public abstract readonly state: AudioEngineV2State;\n\n /**\n * The output volume of the audio engine.\n */\n public abstract volume: number;\n\n /**\n * The smoothing duration to use when changing audio parameters, in seconds. Defaults to `0.01` (10 milliseconds).\n */\n public get parameterRampDuration(): number {\n return this._parameterRampDuration;\n }\n\n public set parameterRampDuration(value: number) {\n this._parameterRampDuration = Math.max(0, value);\n }\n\n /**\n * The list of static and streaming sounds created by the audio engine.\n */\n public get sounds(): ReadonlyArray<AbstractSound> {\n if (!this._soundsArray) {\n this._soundsArray = Array.from(this._sounds);\n }\n return this._soundsArray;\n }\n\n /**\n * Creates a new audio bus.\n * @param name - The name of the audio bus.\n * @param options - The options to use when creating the audio bus.\n * @returns A promise that resolves with the created audio bus.\n */\n public abstract createBusAsync(name: string, options?: Partial<IAudioBusOptions>): Promise<AudioBus>;\n\n /**\n * Creates a new main audio bus.\n * @param name - The name of the main audio bus.\n * @param options - The options to use when creating the main audio bus.\n * @returns A promise that resolves with the created main audio bus.\n */\n public abstract createMainBusAsync(name: string, options?: Partial<IMainAudioBusOptions>): Promise<MainAudioBus>;\n\n /**\n * Creates a new microphone sound source.\n * @param name - The name of the sound.\n * @param options - The options for the sound source.\n * @returns A promise that resolves to the created sound source.\n */\n public abstract createMicrophoneSoundSourceAsync(name: string, options?: Partial<ISoundSourceOptions>): Promise<AbstractSoundSource>;\n\n /**\n * Creates a new static sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the static sound.\n * @returns A promise that resolves to the created static sound.\n */\n public abstract createSoundAsync(\n name: string,\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options?: Partial<IStaticSoundOptions>\n ): Promise<StaticSound>;\n\n /**\n * Creates a new static sound buffer.\n * @param source - The source of the sound buffer.\n * @param options - The options for the static sound buffer.\n * @returns A promise that resolves to the created static sound buffer.\n */\n public abstract createSoundBufferAsync(\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options?: Partial<IStaticSoundBufferOptions>\n ): Promise<StaticSoundBuffer>;\n\n /**\n * Creates a new sound source.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the sound source.\n * @returns A promise that resolves to the created sound source.\n */\n public abstract createSoundSourceAsync(name: string, source: AudioNode, options?: Partial<ISoundSourceOptions>): Promise<AbstractSoundSource>;\n\n /**\n * Creates a new streaming sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the streaming sound.\n * @returns A promise that resolves to the created streaming sound.\n */\n public abstract createStreamingSoundAsync(name: string, source: HTMLMediaElement | string | string[], options?: Partial<IStreamingSoundOptions>): Promise<StreamingSound>;\n\n /**\n * Releases associated resources.\n */\n public dispose(): void {\n if (Instances.includes(this)) {\n Instances.splice(Instances.indexOf(this), 1);\n }\n\n const nodeIt = this._nodes.values();\n for (let next = nodeIt.next(); !next.done; next = nodeIt.next()) {\n next.value.dispose();\n }\n\n this._mainBuses.clear();\n this._nodes.clear();\n this._sounds.clear();\n\n this._disposeSoundsArray();\n\n this._defaultMainBus = null;\n }\n\n /**\n * Checks if the specified format is valid.\n * @param format The format to check as an audio file extension like \"mp3\" or \"wav\".\n * @returns `true` if the format is valid; otherwise `false`.\n */\n public abstract isFormatValid(format: string): boolean;\n\n /**\n * Pauses the audio engine if it is running.\n * @returns A promise that resolves when the audio engine is paused.\n */\n public abstract pauseAsync(): Promise<void>;\n\n /**\n * Resumes the audio engine if it is not running.\n * @returns A promise that resolves when the audio engine is running.\n */\n public abstract resumeAsync(): Promise<void>;\n\n /**\n * Sets the audio output volume with optional ramping.\n * If the duration is 0 then the volume is set immediately, otherwise it is ramped to the new value over the given duration using the given shape.\n * If a ramp is already in progress then the volume is not set and an error is thrown.\n * @param value The value to set the volume to.\n * @param options The options to use for ramping the volume change.\n */\n public abstract setVolume(value: number, options?: Partial<IAudioParameterRampOptions>): void;\n\n /**\n * Unlocks the audio engine if it is locked.\n * - Note that the returned promise may already be resolved if the audio engine is already unlocked.\n * @returns A promise that is resolved when the audio engine is unlocked.\n */\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\n public unlockAsync(): Promise<void> {\n return this.resumeAsync();\n }\n\n protected _addMainBus(mainBus: MainAudioBus): void {\n this._mainBuses.add(mainBus);\n\n this._addNode(mainBus);\n }\n\n protected _removeMainBus(mainBus: MainAudioBus): void {\n this._mainBuses.delete(mainBus);\n this._defaultMainBus = null;\n\n this._removeNode(mainBus);\n }\n\n protected _addNode(node: AbstractNamedAudioNode): void {\n this._nodes.add(node);\n }\n\n protected _removeNode(node: AbstractNamedAudioNode): void {\n this._nodes.delete(node);\n }\n\n protected _addSound(sound: AbstractSound): void {\n this._disposeSoundsArray();\n this._sounds.add(sound);\n this._addNode(sound);\n }\n\n protected _removeSound(sound: AbstractSound): void {\n this._disposeSoundsArray();\n this._sounds.delete(sound);\n this._removeNode(sound);\n }\n\n private _disposeSoundsArray(): void {\n if (this._soundsArray) {\n this._soundsArray.length = 0;\n this._soundsArray = null;\n }\n }\n}\n\n/**\n * @internal\n * @param engine - The given audio engine. If `null` then the last created audio engine is used.\n * @returns the given audio engine or the last created audio engine.\n * @throws An error if the resulting engine is `null`.\n */\nexport function _GetAudioEngine(engine: Nullable<AudioEngineV2>): AudioEngineV2 {\n if (!engine) {\n engine = LastCreatedAudioEngine();\n }\n\n if (engine) {\n return engine;\n }\n\n throw new Error(\"No audio engine.\");\n}\n\n/**\n * Creates a new audio bus.\n * @param name - The name of the audio bus.\n * @param options - The options to use when creating the audio bus.\n * @param engine - The audio engine.\n * @returns A promise that resolves with the created audio bus.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateAudioBusAsync(name: string, options: Partial<IAudioBusOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<AudioBus> {\n engine = _GetAudioEngine(engine);\n return engine.createBusAsync(name, options);\n}\n\n/**\n * Creates a new main audio bus.\n * @param name - The name of the main audio bus.\n * @param options - The options to use when creating the main audio bus.\n * @param engine - The audio engine.\n * @returns A promise that resolves with the created main audio bus.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateMainAudioBusAsync(name: string, options: Partial<IMainAudioBusOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<MainAudioBus> {\n engine = _GetAudioEngine(engine);\n return engine.createMainBusAsync(name, options);\n}\n\n/**\n * Creates a new microphone sound source.\n * @param name - The name of the sound.\n * @param options - The options for the sound source.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created sound source.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateMicrophoneSoundSourceAsync(name: string, options: Partial<ISoundSourceOptions> = {}, engine: Nullable<AudioEngineV2> = null): Promise<AbstractSoundSource> {\n engine = _GetAudioEngine(engine);\n return engine.createMicrophoneSoundSourceAsync(name, options);\n}\n\n/**\n * Creates a new static sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the static sound.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created static sound.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateSoundAsync(\n name: string,\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StaticSound> {\n engine = _GetAudioEngine(engine);\n return engine.createSoundAsync(name, source, options);\n}\n\n/**\n * Creates a new static sound buffer.\n * @param source - The source of the sound buffer.\n * @param options - The options for the static sound buffer.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created static sound buffer.\n */\nexport async function CreateSoundBufferAsync(\n source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[],\n options: Partial<IStaticSoundBufferOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StaticSoundBuffer> {\n engine = _GetAudioEngine(engine);\n return await engine.createSoundBufferAsync(source, options);\n}\n\n/**\n * Creates a new sound source.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the sound source.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created sound source.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateSoundSourceAsync(\n name: string,\n source: AudioNode,\n options: Partial<ISoundSourceOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<AbstractSoundSource> {\n engine = _GetAudioEngine(engine);\n return engine.createSoundSourceAsync(name, source, options);\n}\n\n/**\n * Creates a new streaming sound.\n * @param name - The name of the sound.\n * @param source - The source of the sound.\n * @param options - The options for the streaming sound.\n * @param engine - The audio engine.\n * @returns A promise that resolves to the created streaming sound.\n */\n// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\nexport function CreateStreamingSoundAsync(\n name: string,\n source: HTMLMediaElement | string | string[],\n options: Partial<IStreamingSoundOptions> = {},\n engine: Nullable<AudioEngineV2> = null\n): Promise<StreamingSound> {\n engine = _GetAudioEngine(engine);\n return engine.createStreamingSoundAsync(name, source, options);\n}\n"]}
|
|
@@ -10,7 +10,7 @@ export class _VolumeAudioSubNode extends _AbstractAudioSubNode {
|
|
|
10
10
|
}
|
|
11
11
|
/** @internal */
|
|
12
12
|
setOptions(options) {
|
|
13
|
-
this.
|
|
13
|
+
this.setVolume(options.volume ?? _VolumeAudioDefaults.volume, { shape: "none" /* AudioParameterRampShape.None */ });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"volumeAudioSubNode.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"volumeAudioSubNode.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAChC,MAAM,EAAE,CAAW;CACb,CAAC;AAYX,gBAAgB;AAChB,MAAM,OAAgB,mBAAoB,SAAQ,qBAAqB;IACnE,YAAsB,MAAqB;QACvC,KAAK,qCAAsB,MAAM,CAAC,CAAC;IACvC,CAAC;IAID,gBAAgB;IACT,UAAU,CAAC,OAAqC;QACnD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,IAAI,oBAAoB,CAAC,MAAM,EAAE,EAAE,KAAK,2CAA8B,EAAE,CAAC,CAAC;IAC3G,CAAC;CAIJ;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,QAAgC;IACnE,OAAO,QAAQ,CAAC,UAAU,oCAA0C,CAAC;AACzE,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAA8C,QAAgC,EAAE,QAAW;IAC9H,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["import type { Nullable } from \"../../../types\";\nimport type { IAudioParameterRampOptions } from \"../../audioParameter\";\nimport { AudioParameterRampShape } from \"../../audioParameter\";\nimport type { AudioEngineV2 } from \"../audioEngineV2\";\nimport { _AbstractAudioSubNode } from \"../subNodes/abstractAudioSubNode\";\nimport { AudioSubNode } from \"../subNodes/audioSubNode\";\nimport type { _AbstractAudioSubGraph } from \"./abstractAudioSubGraph\";\n\n/** @internal */\nexport const _VolumeAudioDefaults = {\n volume: 1 as number,\n} as const;\n\n/**\n * Volume options.\n */\nexport interface IVolumeAudioOptions {\n /**\n * The volume/gain. Defaults to 1.\n */\n volume: number;\n}\n\n/** @internal */\nexport abstract class _VolumeAudioSubNode extends _AbstractAudioSubNode {\n protected constructor(engine: AudioEngineV2) {\n super(AudioSubNode.VOLUME, engine);\n }\n\n public abstract volume: number;\n\n /** @internal */\n public setOptions(options: Partial<IVolumeAudioOptions>): void {\n this.setVolume(options.volume ?? _VolumeAudioDefaults.volume, { shape: AudioParameterRampShape.None });\n }\n\n /** @internal */\n public abstract setVolume(value: number, options?: Nullable<Partial<IAudioParameterRampOptions>>): void;\n}\n\n/** @internal */\nexport function _GetVolumeAudioSubNode(subGraph: _AbstractAudioSubGraph): Nullable<_VolumeAudioSubNode> {\n return subGraph.getSubNode<_VolumeAudioSubNode>(AudioSubNode.VOLUME);\n}\n\n/** @internal */\nexport function _GetVolumeAudioProperty<K extends keyof typeof _VolumeAudioDefaults>(subGraph: _AbstractAudioSubGraph, property: K): (typeof _VolumeAudioDefaults)[K] {\n return _GetVolumeAudioSubNode(subGraph)?.[property] ?? _VolumeAudioDefaults[property];\n}\n"]}
|
|
@@ -13,7 +13,11 @@ export declare enum AudioParameterRampShape {
|
|
|
13
13
|
/**
|
|
14
14
|
* The ramp is logarithmic.
|
|
15
15
|
*/
|
|
16
|
-
Logarithmic = "logarithmic"
|
|
16
|
+
Logarithmic = "logarithmic",
|
|
17
|
+
/**
|
|
18
|
+
* No ramp is used; the value is set immediately.
|
|
19
|
+
*/
|
|
20
|
+
None = "none"
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Options for ramping an audio parameter's value.
|
|
@@ -15,5 +15,9 @@ export var AudioParameterRampShape;
|
|
|
15
15
|
* The ramp is logarithmic.
|
|
16
16
|
*/
|
|
17
17
|
AudioParameterRampShape["Logarithmic"] = "logarithmic";
|
|
18
|
+
/**
|
|
19
|
+
* No ramp is used; the value is set immediately.
|
|
20
|
+
*/
|
|
21
|
+
AudioParameterRampShape["None"] = "none";
|
|
18
22
|
})(AudioParameterRampShape || (AudioParameterRampShape = {}));
|
|
19
23
|
//# sourceMappingURL=audioParameter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audioParameter.js","sourceRoot":"","sources":["../../../../dev/core/src/AudioV2/audioParameter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAkB,
|
|
1
|
+
{"version":3,"file":"audioParameter.js","sourceRoot":"","sources":["../../../../dev/core/src/AudioV2/audioParameter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAkB,uBAiBjB;AAjBD,WAAkB,uBAAuB;IACrC;;OAEG;IACH,4CAAiB,CAAA;IACjB;;OAEG;IACH,sDAA2B,CAAA;IAC3B;;OAEG;IACH,sDAA2B,CAAA;IAC3B;;OAEG;IACH,wCAAa,CAAA;AACjB,CAAC,EAjBiB,uBAAuB,KAAvB,uBAAuB,QAiBxC","sourcesContent":["/**\n * The shape of the audio ramp used to set an audio parameter's value, such as a sound's volume.\n */\nexport const enum AudioParameterRampShape {\n /**\n * The ramp is linear.\n */\n Linear = \"linear\",\n /**\n * The ramp is exponential.\n */\n Exponential = \"exponential\",\n /**\n * The ramp is logarithmic.\n */\n Logarithmic = \"logarithmic\",\n /**\n * No ramp is used; the value is set immediately.\n */\n None = \"none\",\n}\n\n/**\n * Options for ramping an audio parameter's value.\n */\nexport interface IAudioParameterRampOptions {\n /**\n * The ramp time, in seconds. Must be greater than 0. Defaults to 0.01 seconds.\n * The audio parameter's value will reach the target value at the end of the duration.\n */\n duration: number;\n /**\n * The shape of the ramp to use for the parameter change. Defaults to {@link AudioParameterRampShape.Linear}.\n */\n shape: AudioParameterRampShape;\n}\n"]}
|
|
@@ -3,9 +3,6 @@ import type { IAudioParameterRampOptions } from "../../audioParameter.js";
|
|
|
3
3
|
import type { _WebAudioEngine } from "../webAudioEngine.js";
|
|
4
4
|
/** @internal */
|
|
5
5
|
export declare class _WebAudioParameterComponent {
|
|
6
|
-
private _deferredRampOptions;
|
|
7
|
-
private _deferredTargetValue;
|
|
8
|
-
private _isObservingUpdates;
|
|
9
6
|
private _rampEndTime;
|
|
10
7
|
private _engine;
|
|
11
8
|
private _param;
|
|
@@ -24,22 +21,7 @@ export declare class _WebAudioParameterComponent {
|
|
|
24
21
|
/**
|
|
25
22
|
* Sets the target value of the audio parameter with an optional ramping duration and shape.
|
|
26
23
|
*
|
|
27
|
-
* If a ramp is close to finishing, it will wait for the ramp to finish before setting the new value; otherwise it
|
|
28
|
-
* will throw an error because of a bug in Firefox that prevents active ramps from being cancelled with
|
|
29
|
-
* `cancelScheduledValues`. See https://bugzilla.mozilla.org/show_bug.cgi?id=1752775. Other browsers do not have
|
|
30
|
-
* this issue, but we throw an error in all browsers to ensure consistent behavior.
|
|
31
|
-
*
|
|
32
|
-
* There are other similar WebAudio APIs for ramping parameters, (e.g. `linearRampToValueAtTime` and
|
|
33
|
-
* `exponentialRampToValueAtTime`) but they don't work in Firefox and Meta Quest Chrome.
|
|
34
|
-
*
|
|
35
|
-
* It may be better in the long run to implement our own ramping logic with a WASM audio worklet instead of using
|
|
36
|
-
* `setValueCurveAtTime`. Another alternative is to use `setValueAtTime` wtih a custom shape, but that will
|
|
37
|
-
* probably be a performance hit to maintain quality at audio rates.
|
|
38
|
-
*
|
|
39
24
|
* @internal
|
|
40
25
|
*/
|
|
41
26
|
setTargetValue(value: number, options?: Nullable<Partial<IAudioParameterRampOptions>>): void;
|
|
42
|
-
private _deferRamp;
|
|
43
|
-
private _applyDeferredRamp;
|
|
44
|
-
private _clearDeferredRamp;
|
|
45
27
|
}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import { _GetAudioParamCurveValues } from "../../audioUtils.js";
|
|
2
|
-
/**
|
|
3
|
-
* Maximum time in seconds to wait for an active ramp to finish before starting a new ramp.
|
|
4
|
-
*
|
|
5
|
-
* New ramps will throw an error if the active ramp has more than this amount of time remaining.
|
|
6
|
-
*
|
|
7
|
-
* This is needed because short ramps are used to avoid pops and clicks when setting audio parameters, and we
|
|
8
|
-
* don't want to throw an error if a short ramp is active.
|
|
9
|
-
*
|
|
10
|
-
* This constant is set to 11 milliseconds, which is short enough to avoid perceptual differences in most cases, but
|
|
11
|
-
* long enough to allow for short ramps to be completed in a reasonable time frame.
|
|
12
|
-
*/
|
|
13
|
-
const MaxWaitTime = 0.011;
|
|
14
2
|
/**
|
|
15
3
|
* Minimum duration in seconds for a ramp to be considered valid.
|
|
16
4
|
*
|
|
@@ -22,18 +10,7 @@ const MinRampDuration = 0.000001;
|
|
|
22
10
|
export class _WebAudioParameterComponent {
|
|
23
11
|
/** @internal */
|
|
24
12
|
constructor(engine, param) {
|
|
25
|
-
this._deferredRampOptions = {
|
|
26
|
-
duration: 0,
|
|
27
|
-
shape: "linear" /* AudioParameterRampShape.Linear */,
|
|
28
|
-
};
|
|
29
|
-
this._deferredTargetValue = -1;
|
|
30
|
-
this._isObservingUpdates = false;
|
|
31
13
|
this._rampEndTime = 0;
|
|
32
|
-
this._applyDeferredRamp = () => {
|
|
33
|
-
if (0 < this._deferredRampOptions.duration && this._rampEndTime < this._engine.currentTime) {
|
|
34
|
-
this.setTargetValue(this._deferredTargetValue, this._deferredRampOptions);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
14
|
this._engine = engine;
|
|
38
15
|
this._param = param;
|
|
39
16
|
this._targetValue = param.value;
|
|
@@ -55,68 +32,31 @@ export class _WebAudioParameterComponent {
|
|
|
55
32
|
}
|
|
56
33
|
/** @internal */
|
|
57
34
|
dispose() {
|
|
58
|
-
this._clearDeferredRamp();
|
|
59
35
|
this._param = null;
|
|
60
36
|
this._engine = null;
|
|
61
37
|
}
|
|
62
38
|
/**
|
|
63
39
|
* Sets the target value of the audio parameter with an optional ramping duration and shape.
|
|
64
40
|
*
|
|
65
|
-
* If a ramp is close to finishing, it will wait for the ramp to finish before setting the new value; otherwise it
|
|
66
|
-
* will throw an error because of a bug in Firefox that prevents active ramps from being cancelled with
|
|
67
|
-
* `cancelScheduledValues`. See https://bugzilla.mozilla.org/show_bug.cgi?id=1752775. Other browsers do not have
|
|
68
|
-
* this issue, but we throw an error in all browsers to ensure consistent behavior.
|
|
69
|
-
*
|
|
70
|
-
* There are other similar WebAudio APIs for ramping parameters, (e.g. `linearRampToValueAtTime` and
|
|
71
|
-
* `exponentialRampToValueAtTime`) but they don't work in Firefox and Meta Quest Chrome.
|
|
72
|
-
*
|
|
73
|
-
* It may be better in the long run to implement our own ramping logic with a WASM audio worklet instead of using
|
|
74
|
-
* `setValueCurveAtTime`. Another alternative is to use `setValueAtTime` wtih a custom shape, but that will
|
|
75
|
-
* probably be a performance hit to maintain quality at audio rates.
|
|
76
|
-
*
|
|
77
41
|
* @internal
|
|
78
42
|
*/
|
|
79
43
|
setTargetValue(value, options = null) {
|
|
80
|
-
if (this._targetValue === value) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
44
|
const shape = typeof options?.shape === "string" ? options.shape : "linear" /* AudioParameterRampShape.Linear */;
|
|
84
|
-
let duration = typeof options?.duration === "number" ? Math.max(options.duration, this._engine.parameterRampDuration) : this._engine.parameterRampDuration;
|
|
85
45
|
const startTime = this._engine.currentTime;
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
else {
|
|
92
|
-
this._deferRamp(value, duration, shape);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
46
|
+
if (shape === "none" /* AudioParameterRampShape.None */) {
|
|
47
|
+
this._param.cancelScheduledValues(startTime);
|
|
48
|
+
this._param.value = this._targetValue = value;
|
|
49
|
+
this._rampEndTime = startTime;
|
|
50
|
+
return;
|
|
95
51
|
}
|
|
52
|
+
let duration = typeof options?.duration === "number" ? Math.max(options.duration, this._engine.parameterRampDuration) : this._engine.parameterRampDuration;
|
|
96
53
|
if ((duration = Math.max(this._engine.parameterRampDuration, duration)) < MinRampDuration) {
|
|
97
54
|
this._param.setValueAtTime((this._targetValue = value), startTime);
|
|
98
55
|
return;
|
|
99
56
|
}
|
|
100
57
|
this._param.cancelScheduledValues(startTime);
|
|
101
|
-
this._param.setValueCurveAtTime(_GetAudioParamCurveValues(shape, this.
|
|
102
|
-
this._clearDeferredRamp();
|
|
58
|
+
this._param.setValueCurveAtTime(_GetAudioParamCurveValues(shape, this._param.value, (this._targetValue = value)), startTime, duration);
|
|
103
59
|
this._rampEndTime = startTime + duration;
|
|
104
60
|
}
|
|
105
|
-
_deferRamp(value, duration, shape) {
|
|
106
|
-
this._deferredRampOptions.duration = duration;
|
|
107
|
-
this._deferredRampOptions.shape = shape;
|
|
108
|
-
this._deferredTargetValue = value;
|
|
109
|
-
if (!this._isObservingUpdates) {
|
|
110
|
-
this._engine._addUpdateObserver(this._applyDeferredRamp);
|
|
111
|
-
this._isObservingUpdates = true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
_clearDeferredRamp() {
|
|
115
|
-
this._deferredRampOptions.duration = 0;
|
|
116
|
-
if (this._isObservingUpdates) {
|
|
117
|
-
this._engine._removeUpdateObserver(this._applyDeferredRamp);
|
|
118
|
-
this._isObservingUpdates = false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
61
|
}
|
|
122
62
|
//# sourceMappingURL=webAudioParameterComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webAudioParameterComponent.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/webAudio/components/webAudioParameterComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAG7D
|
|
1
|
+
{"version":3,"file":"webAudioParameterComponent.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/webAudio/components/webAudioParameterComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAG7D;;;;;GAKG;AACH,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC,gBAAgB;AAChB,MAAM,OAAO,2BAA2B;IAMpC,gBAAgB;IAChB,YAAY,MAAuB,EAAE,KAAiB;QAN9C,iBAAY,GAAW,CAAC,CAAC;QAO7B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC;IACpC,CAAC;IAED,gBAAgB;IAChB,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;IACxD,CAAC;IAED,gBAAgB;IAChB,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAW,WAAW,CAAC,KAAa;QAChC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,gBA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SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEvI,IAAI,CAAC,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC7C,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../../types\";\nimport type { IAudioParameterRampOptions } from \"../../audioParameter\";\nimport { AudioParameterRampShape } from \"../../audioParameter\";\nimport { _GetAudioParamCurveValues } from \"../../audioUtils\";\nimport type { _WebAudioEngine } from \"../webAudioEngine\";\n\n/**\n * Minimum duration in seconds for a ramp to be considered valid.\n *\n * If the duration is less than this value, the value will be set immediately instead of being ramped smoothly since\n * there is no perceptual difference for such short durations, so a ramp is not needed.\n */\nconst MinRampDuration = 0.000001;\n\n/** @internal */\nexport class _WebAudioParameterComponent {\n private _rampEndTime: number = 0;\n private _engine: _WebAudioEngine;\n private _param: AudioParam;\n private _targetValue: number;\n\n /** @internal */\n constructor(engine: _WebAudioEngine, param: AudioParam) {\n this._engine = engine;\n this._param = param;\n this._targetValue = param.value;\n }\n\n /** @internal */\n public get isRamping(): boolean {\n return this._engine.currentTime < this._rampEndTime;\n }\n\n /** @internal */\n public get targetValue(): number {\n return this._targetValue;\n }\n\n public set targetValue(value: number) {\n this.setTargetValue(value);\n }\n\n /** @internal */\n public get value(): number {\n return this._param.value;\n }\n\n /** @internal */\n public dispose(): void {\n this._param = null!;\n this._engine = null!;\n }\n\n /**\n * Sets the target value of the audio parameter with an optional ramping duration and shape.\n *\n * @internal\n */\n public setTargetValue(value: number, options: Nullable<Partial<IAudioParameterRampOptions>> = null): void {\n const shape = typeof options?.shape === \"string\" ? options.shape : AudioParameterRampShape.Linear;\n\n const startTime = this._engine.currentTime;\n\n if (shape === AudioParameterRampShape.None) {\n this._param.cancelScheduledValues(startTime);\n this._param.value = this._targetValue = value;\n this._rampEndTime = startTime;\n return;\n }\n\n let duration = typeof options?.duration === \"number\" ? Math.max(options.duration, this._engine.parameterRampDuration) : this._engine.parameterRampDuration;\n\n if ((duration = Math.max(this._engine.parameterRampDuration, duration)) < MinRampDuration) {\n this._param.setValueAtTime((this._targetValue = value), startTime);\n return;\n }\n\n this._param.cancelScheduledValues(startTime);\n this._param.setValueCurveAtTime(_GetAudioParamCurveValues(shape, this._param.value, (this._targetValue = value)), startTime, duration);\n\n this._rampEndTime = startTime + duration;\n }\n}\n"]}
|
|
@@ -275,8 +275,11 @@ class _WebAudioStaticSoundInstance extends _StaticSoundInstance {
|
|
|
275
275
|
set currentTime(value) {
|
|
276
276
|
const restart = this._state === 2 /* SoundState.Starting */ || this._state === 3 /* SoundState.Started */;
|
|
277
277
|
if (restart) {
|
|
278
|
-
|
|
278
|
+
// Stop source node without sending `onEndedObservable` so instance's `dispose` function is not called.
|
|
279
|
+
const sourceNode = this._sourceNode;
|
|
279
280
|
this._deinitSourceNode();
|
|
281
|
+
sourceNode?.stop();
|
|
282
|
+
this._state = 1 /* SoundState.Stopped */;
|
|
280
283
|
}
|
|
281
284
|
this._options.startOffset = value;
|
|
282
285
|
if (restart) {
|
|
@@ -363,10 +366,12 @@ class _WebAudioStaticSoundInstance extends _StaticSoundInstance {
|
|
|
363
366
|
if (this._state === 1 /* SoundState.Stopped */) {
|
|
364
367
|
return;
|
|
365
368
|
}
|
|
366
|
-
this._setState(1 /* SoundState.Stopped */);
|
|
367
369
|
const engineStopTime = this.engine.currentTime + (options.waitTime ?? 0);
|
|
368
370
|
this._sourceNode?.stop(engineStopTime);
|
|
369
|
-
|
|
371
|
+
if (options.waitTime === undefined || options.waitTime <= 0) {
|
|
372
|
+
this._setState(1 /* SoundState.Stopped */);
|
|
373
|
+
this.engine.stateChangedObservable.removeCallback(this._onEngineStateChanged);
|
|
374
|
+
}
|
|
370
375
|
}
|
|
371
376
|
_connect(node) {
|
|
372
377
|
const connected = super._connect(node);
|