@babylonjs/core 7.54.1 → 7.54.3

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.
Files changed (100) hide show
  1. package/AudioV2/abstractAudio/audioEngineV2.d.ts +3 -3
  2. package/AudioV2/abstractAudio/audioEngineV2.js +2 -2
  3. package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
  4. package/AudioV2/abstractAudio/staticSound.d.ts +11 -14
  5. package/AudioV2/abstractAudio/staticSound.js +6 -8
  6. package/AudioV2/abstractAudio/staticSound.js.map +1 -1
  7. package/AudioV2/abstractAudio/streamingSound.d.ts +4 -4
  8. package/AudioV2/abstractAudio/streamingSound.js +5 -5
  9. package/AudioV2/abstractAudio/streamingSound.js.map +1 -1
  10. package/AudioV2/abstractAudio/subProperties/abstractAudioAnalyzer.d.ts +2 -2
  11. package/AudioV2/abstractAudio/subProperties/abstractAudioAnalyzer.js.map +1 -1
  12. package/AudioV2/abstractAudio/subProperties/audioAnalyzer.d.ts +1 -1
  13. package/AudioV2/abstractAudio/subProperties/audioAnalyzer.js +3 -3
  14. package/AudioV2/abstractAudio/subProperties/audioAnalyzer.js.map +1 -1
  15. package/AudioV2/webAudio/webAudioEngine.d.ts +4 -4
  16. package/AudioV2/webAudio/webAudioEngine.js +3 -3
  17. package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
  18. package/AudioV2/webAudio/webAudioStaticSound.js +2 -10
  19. package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
  20. package/AudioV2/webAudio/webAudioStreamingSound.js +1 -1
  21. package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
  22. package/AudioV2/webAudio/webAudioUnmuteUI.js +1 -1
  23. package/AudioV2/webAudio/webAudioUnmuteUI.js.map +1 -1
  24. package/Cameras/arcRotateCamera.js +1 -1
  25. package/Cameras/arcRotateCamera.js.map +1 -1
  26. package/Collisions/pickingInfo.js +6 -0
  27. package/Collisions/pickingInfo.js.map +1 -1
  28. package/Debug/debugLayer.d.ts +1 -1
  29. package/Debug/debugLayer.js.map +1 -1
  30. package/Engines/abstractEngine.js +2 -2
  31. package/Engines/abstractEngine.js.map +1 -1
  32. package/Engines/constants.d.ts +5 -1
  33. package/Engines/constants.js +5 -1
  34. package/Engines/constants.js.map +1 -1
  35. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +3 -0
  36. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +13 -0
  37. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  38. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js +16 -0
  39. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
  40. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.d.ts +0 -3
  41. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.js +8 -14
  42. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.js.map +1 -1
  43. package/FrameGraph/Node/Blocks/Textures/clearBlock.d.ts +3 -0
  44. package/FrameGraph/Node/Blocks/Textures/clearBlock.js +13 -0
  45. package/FrameGraph/Node/Blocks/Textures/clearBlock.js.map +1 -1
  46. package/FrameGraph/Node/nodeRenderGraph.js +2 -1
  47. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  48. package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +4 -0
  49. package/FrameGraph/Tasks/Rendering/objectRendererTask.js +6 -0
  50. package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
  51. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +1 -0
  52. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
  53. package/FrameGraph/Tasks/Texture/clearTextureTask.d.ts +4 -0
  54. package/FrameGraph/Tasks/Texture/clearTextureTask.js +11 -2
  55. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  56. package/FrameGraph/frameGraph.d.ts +18 -2
  57. package/FrameGraph/frameGraph.js +26 -1
  58. package/FrameGraph/frameGraph.js.map +1 -1
  59. package/Materials/GreasedLine/greasedLineSimpleMaterial.js +5 -4
  60. package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
  61. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +2 -0
  62. package/Materials/Node/Blocks/PBR/clearCoatBlock.js +14 -7
  63. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  64. package/Materials/Node/Blocks/PBR/index.d.ts +1 -0
  65. package/Materials/Node/Blocks/PBR/index.js +1 -0
  66. package/Materials/Node/Blocks/PBR/index.js.map +1 -1
  67. package/Materials/Node/Blocks/PBR/iridescenceBlock.js +2 -1
  68. package/Materials/Node/Blocks/PBR/iridescenceBlock.js.map +1 -1
  69. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +3 -1
  70. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  71. package/Materials/Textures/renderTargetTexture.d.ts +5 -0
  72. package/Materials/Textures/renderTargetTexture.js +9 -0
  73. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  74. package/Materials/effect.js +2 -2
  75. package/Materials/effect.js.map +1 -1
  76. package/Materials/material.d.ts +5 -1
  77. package/Materials/material.js +9 -2
  78. package/Materials/material.js.map +1 -1
  79. package/Materials/materialPluginBase.js +1 -1
  80. package/Maths/math.vector.d.ts +7 -0
  81. package/Maths/math.vector.js +17 -0
  82. package/Maths/math.vector.js.map +1 -1
  83. package/Rendering/depthPeelingSceneComponent.js +1 -1
  84. package/Rendering/objectRenderer.d.ts +7 -0
  85. package/Rendering/objectRenderer.js +19 -0
  86. package/Rendering/objectRenderer.js.map +1 -1
  87. package/Shaders/ShadersInclude/pbrBlockIridescence.js +1 -0
  88. package/Shaders/ShadersInclude/pbrBlockIridescence.js.map +1 -1
  89. package/Shaders/pbr.fragment.js +1 -0
  90. package/Shaders/pbr.fragment.js.map +1 -1
  91. package/ShadersWGSL/ShadersInclude/pbrBlockIridescence.js +3 -2
  92. package/ShadersWGSL/ShadersInclude/pbrBlockIridescence.js.map +1 -1
  93. package/ShadersWGSL/pbr.fragment.js +1 -0
  94. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  95. package/Sprites/spriteManager.js +1 -1
  96. package/Sprites/spriteManager.js.map +1 -1
  97. package/package.json +1 -1
  98. package/scene.d.ts +10 -0
  99. package/scene.js +18 -1
  100. package/scene.js.map +1 -1
@@ -134,18 +134,18 @@ export declare abstract class AudioEngineV2 {
134
134
  * Pauses the audio engine if it is running.
135
135
  * @returns A promise that resolves when the audio engine is paused.
136
136
  */
137
- abstract pause(): Promise<void>;
137
+ abstract pauseAsync(): Promise<void>;
138
138
  /**
139
139
  * Resumes the audio engine if it is not running.
140
140
  * @returns A promise that resolves when the audio engine is running.
141
141
  */
142
- abstract resume(): Promise<void>;
142
+ abstract resumeAsync(): Promise<void>;
143
143
  /**
144
144
  * Unlocks the audio engine if it is locked.
145
145
  * - Note that the returned promise may already be resolved if the audio engine is already unlocked.
146
146
  * @returns A promise that is resolved when the audio engine is unlocked.
147
147
  */
148
- unlock(): Promise<void>;
148
+ unlockAsync(): Promise<void>;
149
149
  protected _addMainBus(mainBus: MainAudioBus): void;
150
150
  protected _removeMainBus(mainBus: MainAudioBus): void;
151
151
  protected _addNode(node: AbstractNamedAudioNode): void;
@@ -70,8 +70,8 @@ export class AudioEngineV2 {
70
70
  * - Note that the returned promise may already be resolved if the audio engine is already unlocked.
71
71
  * @returns A promise that is resolved when the audio engine is unlocked.
72
72
  */
73
- unlock() {
74
- return this.resume();
73
+ unlockAsync() {
74
+ return this.resumeAsync();
75
75
  }
76
76
  _addMainBus(mainBus) {
77
77
  this._mainBuses.add(mainBus);
@@ -1 +1 @@
1
- {"version":3,"file":"audioEngineV2.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/audioEngineV2.ts"],"names":[],"mappings":"AASA,MAAM,S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,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 { AbstractAudioNode, AbstractNamedAudioNode } from \"./abstractAudioNode\";\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\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 * 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 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 * 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 * @param engine - The audio engine.\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 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\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 pause(): 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 resume(): Promise<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 public unlock(): Promise<void> {\n return this.resume();\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\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 */\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 */\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 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 */\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 engine.createSoundBufferAsync(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 */\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":"AASA,MAAM,SAAS,GAAoB,EAAE,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IAClC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IA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AAO,MAAM,CAAC,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\nimport type { AbstractAudioNode, AbstractNamedAudioNode } from \"./abstractAudioNode\";\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\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 * 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 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 * 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 * @param engine - The audio engine.\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 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\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 * 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 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\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 */\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 */\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 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 */\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 engine.createSoundBufferAsync(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 */\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"]}
@@ -23,6 +23,12 @@ export interface IStaticSoundOptionsBase {
23
23
  *
24
24
  */
25
25
  loopStart: number;
26
+ }
27
+ /**
28
+ * Options stored in a static sound.
29
+ * @internal
30
+ */
31
+ export interface IStaticSoundStoredOptions extends IAbstractSoundStoredOptions, IStaticSoundOptionsBase {
26
32
  /**
27
33
  * The pitch of the sound, in cents. Defaults to `0`.
28
34
  * - Can be combined with {@link playbackRate}.
@@ -34,13 +40,6 @@ export interface IStaticSoundOptionsBase {
34
40
  */
35
41
  playbackRate: number;
36
42
  }
37
- /** @internal */
38
- export interface IStaticSoundPlayOptionsBase {
39
- /**
40
- * The time to wait before playing the sound, in seconds. Defaults to `0`.
41
- */
42
- waitTime: number;
43
- }
44
43
  /**
45
44
  * Options for creating a static sound.
46
45
  */
@@ -49,7 +48,11 @@ export interface IStaticSoundOptions extends IAbstractSoundOptions, IStaticSound
49
48
  /**
50
49
  * Options for playing a static sound.
51
50
  */
52
- export interface IStaticSoundPlayOptions extends IAbstractSoundPlayOptions, IStaticSoundOptionsBase, IStaticSoundPlayOptionsBase {
51
+ export interface IStaticSoundPlayOptions extends IAbstractSoundPlayOptions, IStaticSoundOptionsBase {
52
+ /**
53
+ * The time to wait before playing the sound, in seconds. Defaults to `0`.
54
+ */
55
+ waitTime: number;
53
56
  }
54
57
  /**
55
58
  * Options for stopping a static sound.
@@ -60,12 +63,6 @@ export interface IStaticSoundStopOptions {
60
63
  */
61
64
  waitTime: number;
62
65
  }
63
- /**
64
- * Options stored in a static sound.
65
- * @internal
66
- */
67
- export interface IStaticSoundStoredOptions extends IAbstractSoundStoredOptions, IStaticSoundOptionsBase {
68
- }
69
66
  /**
70
67
  * Abstract class representing a static sound.
71
68
  *
@@ -54,9 +54,9 @@ export class StaticSound extends AbstractSound {
54
54
  }
55
55
  set pitch(value) {
56
56
  this._options.pitch = value;
57
- const instance = this._getNewestInstance();
58
- if (instance) {
59
- instance.pitch = value;
57
+ const it = this._instances.values();
58
+ for (let instance = it.next(); !instance.done; instance = it.next()) {
59
+ instance.value.pitch = value;
60
60
  }
61
61
  }
62
62
  /**
@@ -68,9 +68,9 @@ export class StaticSound extends AbstractSound {
68
68
  }
69
69
  set playbackRate(value) {
70
70
  this._options.playbackRate = value;
71
- const instance = this._getNewestInstance();
72
- if (instance) {
73
- instance.playbackRate = value;
71
+ const it = this._instances.values();
72
+ for (let instance = it.next(); !instance.done; instance = it.next()) {
73
+ instance.value.playbackRate = value;
74
74
  }
75
75
  }
76
76
  /**
@@ -87,8 +87,6 @@ export class StaticSound extends AbstractSound {
87
87
  options.loop ?? (options.loop = this.loop);
88
88
  options.loopStart ?? (options.loopStart = this.loopStart);
89
89
  options.loopEnd ?? (options.loopEnd = this.loopEnd);
90
- options.pitch ?? (options.pitch = this.pitch);
91
- options.playbackRate ?? (options.playbackRate = this.playbackRate);
92
90
  options.startOffset ?? (options.startOffset = this.startOffset);
93
91
  options.volume ?? (options.volume = 1);
94
92
  options.waitTime ?? (options.waitTime = 0);
@@ -1 +1 @@
1
- {"version":3,"file":"staticSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/staticSound.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAuEhD;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,WAAY,SAAQ,aAAa;IAWnD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,IAAW,QAAQ,CAAC,KAAa;QAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;IACnC,CAAC;IAED,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,CAAC,QAAQ,CAAC,SAAS,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,IAAW,OAAO,CAAC,KAAa;QAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC/B,CAAC;IAED,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,OAAO,CAAC,WAAW,GAAK,IAAI,CAAC,WAAW,EAAC;QACzC,OAAO,CAAC,MAAM,KAAd,OAAO,CAAC,MAAM,GAAK,CAAC,EAAC;QACrB,OAAO,CAAC,QAAQ,KAAhB,OAAO,CAAC,QAAQ,GAAK,CAAC,EAAC;QAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACxC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC3B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE1B,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,UAA4C,EAAE;QACtD,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3C,IAAI,CAAC,SAAS,6BAAqB,CAAC;QACxC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,SAAS,4BAAoB,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { SoundState } from \"../soundState\";\nimport type { IAbstractSoundOptions, IAbstractSoundPlayOptions, IAbstractSoundStoredOptions } from \"./abstractSound\";\nimport { AbstractSound } from \"./abstractSound\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { IStaticSoundBufferOptions, StaticSoundBuffer } from \"./staticSoundBuffer\";\nimport type { _StaticSoundInstance } from \"./staticSoundInstance\";\n\n/** @internal */\nexport interface IStaticSoundOptionsBase {\n /**\n * The amount of time to play the sound for, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the sound plays for its full duration.\n */\n duration: number;\n /**\n * The end of the loop range in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop plays for the sound's full duration.\n * - Has no effect if {@link loop} is `false`.\n */\n loopEnd: number;\n /**\n * The start of the loop range in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop starts at the beginning of the sound.\n * - Has no effect if {@link loop} is `false`.\n *\n */\n loopStart: number;\n /**\n * The pitch of the sound, in cents. Defaults to `0`.\n * - Can be combined with {@link playbackRate}.\n */\n pitch: number;\n /**\n * The playback rate of the sound. Defaults to `1`.\n * - Can be combined with {@link pitch}.\n */\n playbackRate: number;\n}\n\n/** @internal */\nexport interface IStaticSoundPlayOptionsBase {\n /**\n * The time to wait before playing the sound, in seconds. Defaults to `0`.\n */\n waitTime: number;\n}\n\n/**\n * Options for creating a static sound.\n */\nexport interface IStaticSoundOptions extends IAbstractSoundOptions, IStaticSoundBufferOptions, IStaticSoundStoredOptions {}\n\n/**\n * Options for playing a static sound.\n */\nexport interface IStaticSoundPlayOptions extends IAbstractSoundPlayOptions, IStaticSoundOptionsBase, IStaticSoundPlayOptionsBase {}\n\n/**\n * Options for stopping a static sound.\n */\nexport interface IStaticSoundStopOptions {\n /**\n * The time to wait before stopping the sound, in seconds. Defaults to `0`.\n */\n waitTime: number;\n}\n\n/**\n * Options stored in a static sound.\n * @internal\n */\nexport interface IStaticSoundStoredOptions extends IAbstractSoundStoredOptions, IStaticSoundOptionsBase {}\n\n/**\n * Abstract class representing a static sound.\n *\n * A static sound has a sound buffer that is loaded into memory all at once. This allows it to have more capabilities\n * than a streaming sound, such as loop points and playback rate changes, but it also means that the sound must be\n * fully downloaded and decoded before it can be played, which may take a long time for sounds with long durations.\n *\n * To prevent downloading and decoding a sound multiple times, a sound's buffer can be shared with other sounds.\n * See {@link CreateSoundBufferAsync}, {@link StaticSoundBuffer} and {@link StaticSound.buffer} for more information.\n *\n * Static sounds are created by the {@link CreateSoundAsync} function.\n */\nexport abstract class StaticSound extends AbstractSound {\n protected override _instances: Set<_StaticSoundInstance>;\n protected abstract override readonly _options: IStaticSoundStoredOptions;\n\n /**\n * The sound buffer that the sound uses.\n *\n * This buffer can be shared with other static sounds.\n */\n public abstract readonly buffer: StaticSoundBuffer;\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n\n /**\n * The amount of time to play the sound for, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the sound plays for its full duration.\n */\n public get duration(): number {\n return this._options.duration;\n }\n\n public set duration(value: number) {\n this._options.duration = value;\n }\n\n /**\n * The start of the loop range, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop starts at the beginning of the sound.\n */\n public get loopStart(): number {\n return this._options.loopStart;\n }\n\n public set loopStart(value: number) {\n this._options.loopStart = value;\n }\n\n /**\n * The end of the loop range, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop plays for the sound's full duration.\n */\n public get loopEnd(): number {\n return this._options.loopEnd;\n }\n\n public set loopEnd(value: number) {\n this._options.loopEnd = value;\n }\n\n /**\n * The pitch of the sound, in cents. Defaults to `0`.\n * - Gets combined with {@link playbackRate} to determine the final pitch.\n */\n public get pitch(): number {\n return this._options.pitch;\n }\n\n public set pitch(value: number) {\n this._options.pitch = value;\n\n const instance = this._getNewestInstance() as _StaticSoundInstance;\n if (instance) {\n instance.pitch = value;\n }\n }\n\n /**\n * The playback rate of the sound. Defaults to `1`.\n * - Gets combined with {@link pitch} to determine the final playback rate.\n */\n public get playbackRate(): number {\n return this._options.playbackRate;\n }\n\n public set playbackRate(value: number) {\n this._options.playbackRate = value;\n\n const instance = this._getNewestInstance() as _StaticSoundInstance;\n if (instance) {\n instance.playbackRate = value;\n }\n }\n\n protected abstract override _createInstance(): _StaticSoundInstance;\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 play(options: Partial<IStaticSoundPlayOptions> = {}): void {\n if (this.state === SoundState.Paused) {\n this.resume();\n return;\n }\n\n options.duration ??= this.duration;\n options.loop ??= this.loop;\n options.loopStart ??= this.loopStart;\n options.loopEnd ??= this.loopEnd;\n options.pitch ??= this.pitch;\n options.playbackRate ??= this.playbackRate;\n options.startOffset ??= this.startOffset;\n options.volume ??= 1;\n options.waitTime ??= 0;\n\n const instance = this._createInstance();\n this._beforePlay(instance);\n instance.play(options);\n this._afterPlay(instance);\n\n this._stopExcessInstances();\n }\n\n /**\n * Stops the sound.\n * - Triggers `onEndedObservable` if the sound is playing.\n * @param options - The options to use when stopping the sound.\n */\n public stop(options: Partial<IStaticSoundStopOptions> = {}): void {\n if (options.waitTime && 0 < options.waitTime) {\n this._setState(SoundState.Stopping);\n } else {\n this._setState(SoundState.Stopped);\n }\n\n if (!this._instances) {\n return;\n }\n\n for (const instance of Array.from(this._instances)) {\n instance.stop(options);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"staticSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/staticSound.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAqEhD;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,WAAY,SAAQ,aAAa;IAWnD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,IAAW,QAAQ,CAAC,KAAa;QAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;IACnC,CAAC;IAED,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,CAAC,Q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AI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { SoundState } from \"../soundState\";\nimport type { IAbstractSoundOptions, IAbstractSoundPlayOptions, IAbstractSoundStoredOptions } from \"./abstractSound\";\nimport { AbstractSound } from \"./abstractSound\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { IStaticSoundBufferOptions, StaticSoundBuffer } from \"./staticSoundBuffer\";\nimport type { _StaticSoundInstance } from \"./staticSoundInstance\";\n\n/** @internal */\nexport interface IStaticSoundOptionsBase {\n /**\n * The amount of time to play the sound for, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the sound plays for its full duration.\n */\n duration: number;\n /**\n * The end of the loop range in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop plays for the sound's full duration.\n * - Has no effect if {@link loop} is `false`.\n */\n loopEnd: number;\n /**\n * The start of the loop range in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop starts at the beginning of the sound.\n * - Has no effect if {@link loop} is `false`.\n *\n */\n loopStart: number;\n}\n\n/**\n * Options stored in a static sound.\n * @internal\n */\nexport interface IStaticSoundStoredOptions extends IAbstractSoundStoredOptions, IStaticSoundOptionsBase {\n /**\n * The pitch of the sound, in cents. Defaults to `0`.\n * - Can be combined with {@link playbackRate}.\n */\n pitch: number;\n /**\n * The playback rate of the sound. Defaults to `1`.\n * - Can be combined with {@link pitch}.\n */\n playbackRate: number;\n}\n\n/**\n * Options for creating a static sound.\n */\nexport interface IStaticSoundOptions extends IAbstractSoundOptions, IStaticSoundBufferOptions, IStaticSoundStoredOptions {}\n\n/**\n * Options for playing a static sound.\n */\nexport interface IStaticSoundPlayOptions extends IAbstractSoundPlayOptions, IStaticSoundOptionsBase {\n /**\n * The time to wait before playing the sound, in seconds. Defaults to `0`.\n */\n waitTime: number;\n}\n\n/**\n * Options for stopping a static sound.\n */\nexport interface IStaticSoundStopOptions {\n /**\n * The time to wait before stopping the sound, in seconds. Defaults to `0`.\n */\n waitTime: number;\n}\n\n/**\n * Abstract class representing a static sound.\n *\n * A static sound has a sound buffer that is loaded into memory all at once. This allows it to have more capabilities\n * than a streaming sound, such as loop points and playback rate changes, but it also means that the sound must be\n * fully downloaded and decoded before it can be played, which may take a long time for sounds with long durations.\n *\n * To prevent downloading and decoding a sound multiple times, a sound's buffer can be shared with other sounds.\n * See {@link CreateSoundBufferAsync}, {@link StaticSoundBuffer} and {@link StaticSound.buffer} for more information.\n *\n * Static sounds are created by the {@link CreateSoundAsync} function.\n */\nexport abstract class StaticSound extends AbstractSound {\n protected override _instances: Set<_StaticSoundInstance>;\n protected abstract override readonly _options: IStaticSoundStoredOptions;\n\n /**\n * The sound buffer that the sound uses.\n *\n * This buffer can be shared with other static sounds.\n */\n public abstract readonly buffer: StaticSoundBuffer;\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n\n /**\n * The amount of time to play the sound for, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the sound plays for its full duration.\n */\n public get duration(): number {\n return this._options.duration;\n }\n\n public set duration(value: number) {\n this._options.duration = value;\n }\n\n /**\n * The start of the loop range, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop starts at the beginning of the sound.\n */\n public get loopStart(): number {\n return this._options.loopStart;\n }\n\n public set loopStart(value: number) {\n this._options.loopStart = value;\n }\n\n /**\n * The end of the loop range, in seconds. Defaults to `0`.\n * - If less than or equal to `0`, the loop plays for the sound's full duration.\n */\n public get loopEnd(): number {\n return this._options.loopEnd;\n }\n\n public set loopEnd(value: number) {\n this._options.loopEnd = value;\n }\n\n /**\n * The pitch of the sound, in cents. Defaults to `0`.\n * - Gets combined with {@link playbackRate} to determine the final pitch.\n */\n public get pitch(): number {\n return this._options.pitch;\n }\n\n public set pitch(value: number) {\n this._options.pitch = value;\n\n const it = this._instances.values();\n for (let instance = it.next(); !instance.done; instance = it.next()) {\n instance.value.pitch = value;\n }\n }\n\n /**\n * The playback rate of the sound. Defaults to `1`.\n * - Gets combined with {@link pitch} to determine the final playback rate.\n */\n public get playbackRate(): number {\n return this._options.playbackRate;\n }\n\n public set playbackRate(value: number) {\n this._options.playbackRate = value;\n\n const it = this._instances.values();\n for (let instance = it.next(); !instance.done; instance = it.next()) {\n instance.value.playbackRate = value;\n }\n }\n\n protected abstract override _createInstance(): _StaticSoundInstance;\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 play(options: Partial<IStaticSoundPlayOptions> = {}): void {\n if (this.state === SoundState.Paused) {\n this.resume();\n return;\n }\n\n options.duration ??= this.duration;\n options.loop ??= this.loop;\n options.loopStart ??= this.loopStart;\n options.loopEnd ??= this.loopEnd;\n options.startOffset ??= this.startOffset;\n options.volume ??= 1;\n options.waitTime ??= 0;\n\n const instance = this._createInstance();\n this._beforePlay(instance);\n instance.play(options);\n this._afterPlay(instance);\n\n this._stopExcessInstances();\n }\n\n /**\n * Stops the sound.\n * - Triggers `onEndedObservable` if the sound is playing.\n * @param options - The options to use when stopping the sound.\n */\n public stop(options: Partial<IStaticSoundStopOptions> = {}): void {\n if (options.waitTime && 0 < options.waitTime) {\n this._setState(SoundState.Stopping);\n } else {\n this._setState(SoundState.Stopped);\n }\n\n if (!this._instances) {\n return;\n }\n\n for (const instance of Array.from(this._instances)) {\n instance.stop(options);\n }\n }\n}\n"]}
@@ -33,8 +33,8 @@ export interface IStreamingSoundStoredOptions extends IAbstractSoundStoredOption
33
33
  *
34
34
  * Due to the way streaming sounds are typically implemented, there can be a significant delay when attempting to play
35
35
  * a streaming sound for the first time. To prevent this delay, it is recommended to preload instances of the sound
36
- * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstance} and
37
- * {@link preloadInstances} methods before calling the `play` method.
36
+ * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstanceAsync} and
37
+ * {@link preloadInstancesAsync} methods before calling the `play` method.
38
38
  *
39
39
  * Streaming sounds are created by the {@link CreateStreamingSoundAsync} function.
40
40
  */
@@ -54,13 +54,13 @@ export declare abstract class StreamingSound extends AbstractSound {
54
54
  * Preloads an instance of the sound.
55
55
  * @returns A promise that resolves when the instance is preloaded.
56
56
  */
57
- preloadInstance(): Promise<void>;
57
+ preloadInstanceAsync(): Promise<void>;
58
58
  /**
59
59
  * Preloads the given number of instances of the sound.
60
60
  * @param count - The number of instances to preload.
61
61
  * @returns A promise that resolves when all instances are preloaded.
62
62
  */
63
- preloadInstances(count: number): Promise<void>;
63
+ preloadInstancesAsync(count: number): Promise<void>;
64
64
  /**
65
65
  * Plays the sound.
66
66
  * - Triggers `onEndedObservable` if played for the full duration and the `loop` option is not set.
@@ -7,8 +7,8 @@ import { AbstractSound } from "./abstractSound.js";
7
7
  *
8
8
  * Due to the way streaming sounds are typically implemented, there can be a significant delay when attempting to play
9
9
  * a streaming sound for the first time. To prevent this delay, it is recommended to preload instances of the sound
10
- * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstance} and
11
- * {@link preloadInstances} methods before calling the `play` method.
10
+ * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstanceAsync} and
11
+ * {@link preloadInstancesAsync} methods before calling the `play` method.
12
12
  *
13
13
  * Streaming sounds are created by the {@link CreateStreamingSoundAsync} function.
14
14
  */
@@ -33,7 +33,7 @@ export class StreamingSound extends AbstractSound {
33
33
  * Preloads an instance of the sound.
34
34
  * @returns A promise that resolves when the instance is preloaded.
35
35
  */
36
- preloadInstance() {
36
+ preloadInstanceAsync() {
37
37
  const instance = this._createInstance();
38
38
  this._addPreloadedInstance(instance);
39
39
  return instance.preloadedPromise;
@@ -43,9 +43,9 @@ export class StreamingSound extends AbstractSound {
43
43
  * @param count - The number of instances to preload.
44
44
  * @returns A promise that resolves when all instances are preloaded.
45
45
  */
46
- async preloadInstances(count) {
46
+ async preloadInstancesAsync(count) {
47
47
  for (let i = 0; i < count; i++) {
48
- this.preloadInstance();
48
+ this.preloadInstanceAsync();
49
49
  }
50
50
  await Promise.all(this._preloadedInstances.map((instance) => instance.preloadedPromise));
51
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"streamingSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/streamingSound.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4BhD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,cAAe,SAAQ,aAAa;IAKtD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QALhB,wBAAmB,GAAG,IAAI,KAAK,EAA2B,CAAC;IAMnE,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAW,qBAAqB;QAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACI,eAAe;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAExC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAErC,OAAO,QAAQ,CAAC,gBAAgB,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,gBAAgB,CAAC,KAAa;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,eAAe,EAAE,CAAC;QAC3B,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,gBAAgB,C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IAAI,CAAC,SAAS,4BAAoB,CAAC;QAEnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;IACL,CAAC;IAIO,qBAAqB,CAAC,QAAiC;QAC3D,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;IAEO,wBAAwB,CAAC,QAAiC;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { SoundState } from \"../soundState\";\nimport type { IAbstractSoundOptions, IAbstractSoundPlayOptions, IAbstractSoundStoredOptions } from \"./abstractSound\";\nimport { AbstractSound } from \"./abstractSound\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { _StreamingSoundInstance } from \"./streamingSoundInstance\";\n\n/** @internal */\nexport interface IStreamingSoundOptionsBase {\n /**\n * The number of instances to preload. Defaults to 1.\n * */\n preloadCount: number;\n}\n\n/**\n * Options for creating a streaming sound.\n */\nexport interface IStreamingSoundOptions extends IAbstractSoundOptions, IStreamingSoundOptionsBase {}\n\n/**\n * Options for playing a streaming sound.\n */\nexport interface IStreamingSoundPlayOptions extends IAbstractSoundPlayOptions {}\n\n/**\n * Options stored in a streaming sound.\n * @internal\n */\nexport interface IStreamingSoundStoredOptions extends IAbstractSoundStoredOptions, IStreamingSoundOptionsBase {}\n\n/**\n * Abstract class representing a streaming sound.\n *\n * A streaming sound has a sound buffer that is loaded into memory in chunks as it is played. This allows it to be played\n * more quickly than a static sound, but it also means that it cannot have loop points or playback rate changes.\n *\n * Due to the way streaming sounds are typically implemented, there can be a significant delay when attempting to play\n * a streaming sound for the first time. To prevent this delay, it is recommended to preload instances of the sound\n * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstance} and\n * {@link preloadInstances} methods before calling the `play` method.\n *\n * Streaming sounds are created by the {@link CreateStreamingSoundAsync} function.\n */\nexport abstract class StreamingSound extends AbstractSound {\n private _preloadedInstances = new Array<_StreamingSoundInstance>();\n\n protected abstract override readonly _options: IStreamingSoundStoredOptions;\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n\n /**\n * The number of instances to preload. Defaults to `1`.\n */\n public get preloadCount(): number {\n return this._options.preloadCount ?? 1;\n }\n\n /**\n * Returns the number of instances that have been preloaded.\n */\n public get preloadCompletedCount(): number {\n return this._preloadedInstances.length;\n }\n\n /**\n * Preloads an instance of the sound.\n * @returns A promise that resolves when the instance is preloaded.\n */\n public preloadInstance(): Promise<void> {\n const instance = this._createInstance();\n\n this._addPreloadedInstance(instance);\n\n return instance.preloadedPromise;\n }\n\n /**\n * Preloads the given number of instances of the sound.\n * @param count - The number of instances to preload.\n * @returns A promise that resolves when all instances are preloaded.\n */\n public async preloadInstances(count: number): Promise<void> {\n for (let i = 0; i < count; i++) {\n this.preloadInstance();\n }\n\n await Promise.all(this._preloadedInstances.map((instance) => instance.preloadedPromise));\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 play(options: Partial<IStreamingSoundPlayOptions> = {}): void {\n if (this.state === SoundState.Paused) {\n this.resume();\n return;\n }\n\n let instance: _StreamingSoundInstance;\n\n if (this.preloadCompletedCount > 0) {\n instance = this._preloadedInstances[0];\n instance.startOffset = this.startOffset;\n this._removePreloadedInstance(instance);\n } else {\n instance = this._createInstance();\n }\n\n const onInstanceStateChanged = () => {\n if (instance.state === SoundState.Started) {\n this._stopExcessInstances();\n instance.onStateChangedObservable.removeCallback(onInstanceStateChanged);\n }\n };\n instance.onStateChangedObservable.add(onInstanceStateChanged);\n\n options.startOffset ??= this.startOffset;\n options.loop ??= this.loop;\n options.volume ??= 1;\n\n this._beforePlay(instance);\n instance.play(options);\n this._afterPlay(instance);\n }\n\n /**\n * Stops the sound.\n */\n public stop(): void {\n this._setState(SoundState.Stopped);\n\n if (!this._instances) {\n return;\n }\n\n for (const instance of Array.from(this._instances)) {\n instance.stop();\n }\n }\n\n protected abstract override _createInstance(): _StreamingSoundInstance;\n\n private _addPreloadedInstance(instance: _StreamingSoundInstance): void {\n if (!this._preloadedInstances.includes(instance)) {\n this._preloadedInstances.push(instance);\n }\n }\n\n private _removePreloadedInstance(instance: _StreamingSoundInstance): void {\n const index = this._preloadedInstances.indexOf(instance);\n if (index !== -1) {\n this._preloadedInstances.splice(index, 1);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"streamingSound.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/streamingSound.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4BhD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,cAAe,SAAQ,aAAa;IAKtD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QALhB,wBAAmB,GAAG,IAAI,KAAK,EAA2B,CAAC;IAMnE,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAW,qBAAqB;QAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC,M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;IACL,CAAC;CACJ","sourcesContent":["import { SoundState } from \"../soundState\";\nimport type { IAbstractSoundOptions, IAbstractSoundPlayOptions, IAbstractSoundStoredOptions } from \"./abstractSound\";\nimport { AbstractSound } from \"./abstractSound\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { _StreamingSoundInstance } from \"./streamingSoundInstance\";\n\n/** @internal */\nexport interface IStreamingSoundOptionsBase {\n /**\n * The number of instances to preload. Defaults to 1.\n * */\n preloadCount: number;\n}\n\n/**\n * Options for creating a streaming sound.\n */\nexport interface IStreamingSoundOptions extends IAbstractSoundOptions, IStreamingSoundOptionsBase {}\n\n/**\n * Options for playing a streaming sound.\n */\nexport interface IStreamingSoundPlayOptions extends IAbstractSoundPlayOptions {}\n\n/**\n * Options stored in a streaming sound.\n * @internal\n */\nexport interface IStreamingSoundStoredOptions extends IAbstractSoundStoredOptions, IStreamingSoundOptionsBase {}\n\n/**\n * Abstract class representing a streaming sound.\n *\n * A streaming sound has a sound buffer that is loaded into memory in chunks as it is played. This allows it to be played\n * more quickly than a static sound, but it also means that it cannot have loop points or playback rate changes.\n *\n * Due to the way streaming sounds are typically implemented, there can be a significant delay when attempting to play\n * a streaming sound for the first time. To prevent this delay, it is recommended to preload instances of the sound\n * using the {@link IStreamingSoundStoredOptions.preloadCount} options, or the {@link preloadInstanceAsync} and\n * {@link preloadInstancesAsync} methods before calling the `play` method.\n *\n * Streaming sounds are created by the {@link CreateStreamingSoundAsync} function.\n */\nexport abstract class StreamingSound extends AbstractSound {\n private _preloadedInstances = new Array<_StreamingSoundInstance>();\n\n protected abstract override readonly _options: IStreamingSoundStoredOptions;\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n\n /**\n * The number of instances to preload. Defaults to `1`.\n */\n public get preloadCount(): number {\n return this._options.preloadCount ?? 1;\n }\n\n /**\n * Returns the number of instances that have been preloaded.\n */\n public get preloadCompletedCount(): number {\n return this._preloadedInstances.length;\n }\n\n /**\n * Preloads an instance of the sound.\n * @returns A promise that resolves when the instance is preloaded.\n */\n public preloadInstanceAsync(): Promise<void> {\n const instance = this._createInstance();\n\n this._addPreloadedInstance(instance);\n\n return instance.preloadedPromise;\n }\n\n /**\n * Preloads the given number of instances of the sound.\n * @param count - The number of instances to preload.\n * @returns A promise that resolves when all instances are preloaded.\n */\n public async preloadInstancesAsync(count: number): Promise<void> {\n for (let i = 0; i < count; i++) {\n this.preloadInstanceAsync();\n }\n\n await Promise.all(this._preloadedInstances.map((instance) => instance.preloadedPromise));\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 play(options: Partial<IStreamingSoundPlayOptions> = {}): void {\n if (this.state === SoundState.Paused) {\n this.resume();\n return;\n }\n\n let instance: _StreamingSoundInstance;\n\n if (this.preloadCompletedCount > 0) {\n instance = this._preloadedInstances[0];\n instance.startOffset = this.startOffset;\n this._removePreloadedInstance(instance);\n } else {\n instance = this._createInstance();\n }\n\n const onInstanceStateChanged = () => {\n if (instance.state === SoundState.Started) {\n this._stopExcessInstances();\n instance.onStateChangedObservable.removeCallback(onInstanceStateChanged);\n }\n };\n instance.onStateChangedObservable.add(onInstanceStateChanged);\n\n options.startOffset ??= this.startOffset;\n options.loop ??= this.loop;\n options.volume ??= 1;\n\n this._beforePlay(instance);\n instance.play(options);\n this._afterPlay(instance);\n }\n\n /**\n * Stops the sound.\n */\n public stop(): void {\n this._setState(SoundState.Stopped);\n\n if (!this._instances) {\n return;\n }\n\n for (const instance of Array.from(this._instances)) {\n instance.stop();\n }\n }\n\n protected abstract override _createInstance(): _StreamingSoundInstance;\n\n private _addPreloadedInstance(instance: _StreamingSoundInstance): void {\n if (!this._preloadedInstances.includes(instance)) {\n this._preloadedInstances.push(instance);\n }\n }\n\n private _removePreloadedInstance(instance: _StreamingSoundInstance): void {\n const index = this._preloadedInstances.indexOf(instance);\n if (index !== -1) {\n this._preloadedInstances.splice(index, 1);\n }\n }\n}\n"]}
@@ -50,7 +50,7 @@ export declare abstract class AbstractAudioAnalyzer {
50
50
  /**
51
51
  * Whether the analyzer is enabled or not.
52
52
  * - The `getByteFrequencyData` and `getFloatFrequencyData` functions return `null` if the analyzer is not enabled.
53
- * @see {@link enable}
53
+ * @see {@link enableAsync}
54
54
  */
55
55
  abstract isEnabled: boolean;
56
56
  /**
@@ -72,7 +72,7 @@ export declare abstract class AbstractAudioAnalyzer {
72
72
  /**
73
73
  * Enables the analyzer
74
74
  */
75
- abstract enable(): Promise<void>;
75
+ abstract enableAsync(): Promise<void>;
76
76
  /**
77
77
  * Gets the current frequency data as a byte array
78
78
  * @returns a Uint8Array if the analyzer is enabled, otherwise `null`
@@ -1 +1 @@
1
- {"version":3,"file":"abstractAudioAnalyzer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subProperties/abstractAudioAnalyzer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,OAAO,EAAE,IAAgC;IACzC,WAAW,EAAE,CAAC,GAAa;IAC3B,WAAW,EAAE,CAAC,EAAY;IAC1B,SAAS,EAAE,GAAa;CAClB,CAAC;AA+BX;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAuC;IAC5E,OAAO,CACH,OAAO,CAAC,eAAe;QACvB,OAAO,CAAC,eAAe,KAAK,SAAS;QACrC,OAAO,CAAC,mBAAmB,KAAK,SAAS;QACzC,OAAO,CAAC,mBAAmB,KAAK,SAAS;QACzC,OAAO,CAAC,iBAAiB,KAAK,SAAS,CAC1C,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,OAAgB,qBAAqB;IAMvC;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IAC5B,CAAC;CA6CJ","sourcesContent":["export type AudioAnalyzerFFTSizeType = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768;\n\nexport const _AudioAnalyzerDefaults = {\n fftSize: 2048 as AudioAnalyzerFFTSizeType,\n minDecibels: -100 as number,\n maxDecibels: -30 as number,\n smoothing: 0.8 as number,\n} as const;\n\n/**\n * Options for the AudioAnalyzer\n */\nexport interface IAudioAnalyzerOptions {\n /**\n * Enable the audio analyzer. Defaults to false.\n */\n analyzerEnabled: boolean;\n /**\n * The size of the FFT (fast fourier transform) to use when converting time-domain data to frequency-domain data. Default is 2048.\n */\n analyzerFFTSize: AudioAnalyzerFFTSizeType;\n\n /**\n * The minimum decibel value for the range of the analyzer. Default is -100.\n */\n analyzerMinDecibels: number;\n\n /**\n * The maximum decibel value for the range of the analyzer. Default is -30.\n */\n analyzerMaxDecibels: number;\n\n /**\n * A number between 0 and 1 that determines how quickly the analyzer's value changes. Default is 0.8.\n */\n analyzerSmoothing: number;\n}\n\n/**\n * @param options The audio analyzer options to check.\n * @returns `true` if audio analyzer options are defined, otherwise `false`.\n */\nexport function _HasAudioAnalyzerOptions(options: Partial<IAudioAnalyzerOptions>): boolean {\n return (\n options.analyzerEnabled ||\n options.analyzerFFTSize !== undefined ||\n options.analyzerMinDecibels !== undefined ||\n options.analyzerMaxDecibels !== undefined ||\n options.analyzerSmoothing !== undefined\n );\n}\n\n/**\n * An AudioAnalyzer converts time-domain audio data into the frequency-domain.\n */\nexport abstract class AbstractAudioAnalyzer {\n /**\n * The size of the FFT (fast fourier transform) to use when converting time-domain data to frequency-domain data. Default is 2048.\n */\n public abstract fftSize: AudioAnalyzerFFTSizeType;\n\n /**\n * The number of data values that will be returned when calling getByteFrequencyData() or getFloatFrequencyData(). This is always half the `fftSize`.\n */\n public get frequencyBinCount(): number {\n return this.fftSize / 2;\n }\n\n /**\n * Whether the analyzer is enabled or not.\n * - The `getByteFrequencyData` and `getFloatFrequencyData` functions return `null` if the analyzer is not enabled.\n * @see {@link enable}\n */\n public abstract isEnabled: boolean;\n\n /**\n * The minimum decibel value for the range of the analyzer. Default is -100.\n */\n public abstract minDecibels: number;\n\n /**\n * The maximum decibel value for the range of the analyzer. Default is -30.\n */\n public abstract maxDecibels: number;\n\n /**\n * A number between 0 and 1 that determines how quickly the analyzer's value changes. Default is 0.8.\n */\n public abstract smoothing: number;\n\n /**\n * Releases associated resources.\n */\n public abstract dispose(): void;\n\n /**\n * Enables the analyzer\n */\n public abstract enable(): Promise<void>;\n\n /**\n * Gets the current frequency data as a byte array\n * @returns a Uint8Array if the analyzer is enabled, otherwise `null`\n */\n public abstract getByteFrequencyData(): Uint8Array;\n\n /**\n * Gets the current frequency data as a float array\n * @returns a Float32Array if the analyzer is enabled, otherwise `null`\n */\n public abstract getFloatFrequencyData(): Float32Array;\n}\n"]}
1
+ {"version":3,"file":"abstractAudioAnalyzer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subProperties/abstractAudioAnalyzer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,OAAO,EAAE,IAAgC;IACzC,WAAW,EAAE,CAAC,GAAa;IAC3B,WAAW,EAAE,CAAC,EAAY;IAC1B,SAAS,EAAE,GAAa;CAClB,CAAC;AA+BX;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAuC;IAC5E,OAAO,CACH,OAAO,CAAC,eAAe;QACvB,OAAO,CAAC,eAAe,KAAK,SAAS;QACrC,OAAO,CAAC,mBAAmB,KAAK,SAAS;QACzC,OAAO,CAAC,mBAAmB,KAAK,SAAS;QACzC,OAAO,CAAC,iBAAiB,KAAK,SAAS,CAC1C,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,OAAgB,qBAAqB;IAMvC;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IAC5B,CAAC;CA6CJ","sourcesContent":["export type AudioAnalyzerFFTSizeType = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768;\n\nexport const _AudioAnalyzerDefaults = {\n fftSize: 2048 as AudioAnalyzerFFTSizeType,\n minDecibels: -100 as number,\n maxDecibels: -30 as number,\n smoothing: 0.8 as number,\n} as const;\n\n/**\n * Options for the AudioAnalyzer\n */\nexport interface IAudioAnalyzerOptions {\n /**\n * Enable the audio analyzer. Defaults to false.\n */\n analyzerEnabled: boolean;\n /**\n * The size of the FFT (fast fourier transform) to use when converting time-domain data to frequency-domain data. Default is 2048.\n */\n analyzerFFTSize: AudioAnalyzerFFTSizeType;\n\n /**\n * The minimum decibel value for the range of the analyzer. Default is -100.\n */\n analyzerMinDecibels: number;\n\n /**\n * The maximum decibel value for the range of the analyzer. Default is -30.\n */\n analyzerMaxDecibels: number;\n\n /**\n * A number between 0 and 1 that determines how quickly the analyzer's value changes. Default is 0.8.\n */\n analyzerSmoothing: number;\n}\n\n/**\n * @param options The audio analyzer options to check.\n * @returns `true` if audio analyzer options are defined, otherwise `false`.\n */\nexport function _HasAudioAnalyzerOptions(options: Partial<IAudioAnalyzerOptions>): boolean {\n return (\n options.analyzerEnabled ||\n options.analyzerFFTSize !== undefined ||\n options.analyzerMinDecibels !== undefined ||\n options.analyzerMaxDecibels !== undefined ||\n options.analyzerSmoothing !== undefined\n );\n}\n\n/**\n * An AudioAnalyzer converts time-domain audio data into the frequency-domain.\n */\nexport abstract class AbstractAudioAnalyzer {\n /**\n * The size of the FFT (fast fourier transform) to use when converting time-domain data to frequency-domain data. Default is 2048.\n */\n public abstract fftSize: AudioAnalyzerFFTSizeType;\n\n /**\n * The number of data values that will be returned when calling getByteFrequencyData() or getFloatFrequencyData(). This is always half the `fftSize`.\n */\n public get frequencyBinCount(): number {\n return this.fftSize / 2;\n }\n\n /**\n * Whether the analyzer is enabled or not.\n * - The `getByteFrequencyData` and `getFloatFrequencyData` functions return `null` if the analyzer is not enabled.\n * @see {@link enableAsync}\n */\n public abstract isEnabled: boolean;\n\n /**\n * The minimum decibel value for the range of the analyzer. Default is -100.\n */\n public abstract minDecibels: number;\n\n /**\n * The maximum decibel value for the range of the analyzer. Default is -30.\n */\n public abstract maxDecibels: number;\n\n /**\n * A number between 0 and 1 that determines how quickly the analyzer's value changes. Default is 0.8.\n */\n public abstract smoothing: number;\n\n /**\n * Releases associated resources.\n */\n public abstract dispose(): void;\n\n /**\n * Enables the analyzer\n */\n public abstract enableAsync(): Promise<void>;\n\n /**\n * Gets the current frequency data as a byte array\n * @returns a Uint8Array if the analyzer is enabled, otherwise `null`\n */\n public abstract getByteFrequencyData(): Uint8Array;\n\n /**\n * Gets the current frequency data as a float array\n * @returns a Float32Array if the analyzer is enabled, otherwise `null`\n */\n public abstract getFloatFrequencyData(): Float32Array;\n}\n"]}
@@ -27,7 +27,7 @@ export declare class _AudioAnalyzer extends AbstractAudioAnalyzer {
27
27
  /** @internal */
28
28
  dispose(): void;
29
29
  /** @internal */
30
- enable(): Promise<void>;
30
+ enableAsync(): Promise<void>;
31
31
  /** @internal */
32
32
  getByteFrequencyData(): Uint8Array;
33
33
  /** @internal */
@@ -65,7 +65,7 @@ export class _AudioAnalyzer extends AbstractAudioAnalyzer {
65
65
  }
66
66
  }
67
67
  /** @internal */
68
- async enable() {
68
+ async enableAsync() {
69
69
  const subNode = _GetAudioAnalyzerSubNode(this._subGraph);
70
70
  if (!subNode) {
71
71
  await this._subGraph.createAndAddSubNode("Analyzer" /* AudioSubNode.ANALYZER */);
@@ -77,7 +77,7 @@ export class _AudioAnalyzer extends AbstractAudioAnalyzer {
77
77
  const subNode = _GetAudioAnalyzerSubNode(this._subGraph);
78
78
  if (!subNode) {
79
79
  Logger.Warn("AudioAnalyzer not enabled");
80
- this.enable();
80
+ this.enableAsync();
81
81
  return _GetEmptyByteFrequencyData();
82
82
  }
83
83
  return subNode.getByteFrequencyData();
@@ -87,7 +87,7 @@ export class _AudioAnalyzer extends AbstractAudioAnalyzer {
87
87
  const subNode = _GetAudioAnalyzerSubNode(this._subGraph);
88
88
  if (!subNode) {
89
89
  Logger.Warn("AudioAnalyzer not enabled");
90
- this.enable();
90
+ this.enableAsync();
91
91
  return _GetEmptyFloatFrequencyData();
92
92
  }
93
93
  return subNode.getFloatFrequencyData();
@@ -1 +1 @@
1
- {"version":3,"file":"audioAnalyzer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subProperties/audioAnalyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yDAAyD,CAAC;AAEhG,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAGlI,IAAI,uBAAuB,GAAyB,IAAI,CAAC;AACzD,IAAI,wBAAwB,GAA2B,IAAI,CAAC;AAE5D,gBAAgB;AAChB,MAAM,UAAU,0BAA0B;IACtC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC3B,uBAAuB,GAAG,IAAI,UAAU,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,uBAAuB,CAAC;AACnC,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,2BAA2B;IACvC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC5B,wBAAwB,GAAG,IAAI,YAAY,EAAE,CAAC;IAClD,CAAC;IACD,OAAO,wBAAwB,CAAC;AACpC,CAAC;AAED,gBAAgB;AAChB,MAAM,OAAO,cAAe,SAAQ,qBAAqB;IAGrD,gBAAgB;IAChB,YAAmB,QAAgC;QAC/C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,yBAAyB,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,IAAW,OAAO,CAAC,KAA+B;QAC9C,yBAAyB,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACh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uB,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB;IACT,oBAAoB;QACvB,MAAM,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO,0BAA0B,EAAE,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAC1C,CAAC;IAED,gBAAgB;IACT,qBAAqB;QACxB,MAAM,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO,2BAA2B,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC3C,CAAC;CACJ","sourcesContent":["import { Logger } from \"../../../Misc/logger\";\nimport type { Nullable } from \"../../../types\";\nimport type { AudioAnalyzerFFTSizeType } from \"../../abstractAudio/subProperties/abstractAudioAnalyzer\";\nimport { AbstractAudioAnalyzer } from \"../../abstractAudio/subProperties/abstractAudioAnalyzer\";\nimport type { _AbstractAudioSubGraph } from \"../subNodes/abstractAudioSubGraph\";\nimport { _GetAudioAnalyzerProperty, _GetAudioAnalyzerSubNode, _SetAudioAnalyzerProperty } from \"../subNodes/audioAnalyzerSubNode\";\nimport { AudioSubNode } from \"../subNodes/audioSubNode\";\n\nlet _emptyByteFrequencyData: Nullable<Uint8Array> = null;\nlet _emptyFloatFrequencyData: Nullable<Float32Array> = null;\n\n/** @internal */\nexport function _GetEmptyByteFrequencyData(): Uint8Array {\n if (!_emptyByteFrequencyData) {\n _emptyByteFrequencyData = new Uint8Array();\n }\n return _emptyByteFrequencyData;\n}\n\n/** @internal */\nexport function _GetEmptyFloatFrequencyData(): Float32Array {\n if (!_emptyFloatFrequencyData) {\n _emptyFloatFrequencyData = new Float32Array();\n }\n return _emptyFloatFrequencyData;\n}\n\n/** @internal */\nexport class _AudioAnalyzer extends AbstractAudioAnalyzer {\n private _subGraph: _AbstractAudioSubGraph;\n\n /** @internal */\n public constructor(subGraph: _AbstractAudioSubGraph) {\n super();\n this._subGraph = subGraph;\n }\n\n /** @internal */\n public get fftSize(): AudioAnalyzerFFTSizeType {\n return _GetAudioAnalyzerProperty(this._subGraph, \"fftSize\");\n }\n\n public set fftSize(value: AudioAnalyzerFFTSizeType) {\n _SetAudioAnalyzerProperty(this._subGraph, \"fftSize\", value);\n }\n\n /** @internal */\n public get isEnabled(): boolean {\n return _GetAudioAnalyzerSubNode(this._subGraph) !== null;\n }\n\n /** @internal */\n public get minDecibels(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"minDecibels\");\n }\n\n public set minDecibels(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"minDecibels\", value);\n }\n\n /** @internal */\n public get maxDecibels(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"maxDecibels\");\n }\n\n public set maxDecibels(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"maxDecibels\", value);\n }\n\n /** @internal */\n public get smoothing(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"smoothing\");\n }\n\n public set smoothing(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"smoothing\", value);\n }\n\n /** @internal */\n public dispose(): void {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (subNode) {\n this._subGraph.removeSubNode(subNode);\n subNode.dispose();\n }\n }\n\n /** @internal */\n public async enable(): Promise<void> {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n await this._subGraph.createAndAddSubNode(AudioSubNode.ANALYZER);\n }\n return Promise.resolve();\n }\n\n /** @internal */\n public getByteFrequencyData(): Uint8Array {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n Logger.Warn(\"AudioAnalyzer not enabled\");\n this.enable();\n return _GetEmptyByteFrequencyData();\n }\n return subNode.getByteFrequencyData();\n }\n\n /** @internal */\n public getFloatFrequencyData(): Float32Array {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n Logger.Warn(\"AudioAnalyzer not enabled\");\n this.enable();\n return _GetEmptyFloatFrequencyData();\n }\n return subNode.getFloatFrequencyData();\n }\n}\n"]}
1
+ {"version":3,"file":"audioAnalyzer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/subProperties/audioAnalyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yDAAyD,CAAC;AAEhG,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAGlI,IAAI,uBAAuB,GAAyB,IAAI,CAAC;AACzD,IAAI,wBAAwB,GAA2B,IAAI,CAAC;AAE5D,gBAAgB;AAChB,MAAM,UAAU,0BAA0B;IACtC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC3B,uBAAuB,GAAG,IAAI,UAAU,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,uBAAuB,CAAC;AACnC,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,2BAA2B;IACvC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC5B,wBAAwB,GAAG,IAAI,YAAY,EAAE,CAAC;IAClD,CAAC;IACD,OAAO,wBAAwB,CAAC;AACpC,CAAC;AAED,gBAAgB;AAChB,MAAM,OAAO,cAAe,SAAQ,qBAAqB;IAGrD,gBAAgB;IAChB,YAAmB,QAAgC;QAC/C,KAAK,EAAE,CAAC;QACR,I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AAC,OAAO,CAAC,CAAC;YACtC,OAAO,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;IACL,CAAC;IAED,gBAAgB;IACT,KAAK,CAAC,WAAW;QACpB,MAAM,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,CAAC,SAAS,CAAC,mBAAmB,wCAAuB,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB;IACT,oBAAoB;QACvB,MAAM,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YACzC,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO,0BAA0B,EAAE,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAC1C,CAAC;IAED,gBAAgB;IACT,qBAAqB;QACxB,MAAM,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YACzC,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO,2BAA2B,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC3C,CAAC;CACJ","sourcesContent":["import { Logger } from \"../../../Misc/logger\";\nimport type { Nullable } from \"../../../types\";\nimport type { AudioAnalyzerFFTSizeType } from \"../../abstractAudio/subProperties/abstractAudioAnalyzer\";\nimport { AbstractAudioAnalyzer } from \"../../abstractAudio/subProperties/abstractAudioAnalyzer\";\nimport type { _AbstractAudioSubGraph } from \"../subNodes/abstractAudioSubGraph\";\nimport { _GetAudioAnalyzerProperty, _GetAudioAnalyzerSubNode, _SetAudioAnalyzerProperty } from \"../subNodes/audioAnalyzerSubNode\";\nimport { AudioSubNode } from \"../subNodes/audioSubNode\";\n\nlet _emptyByteFrequencyData: Nullable<Uint8Array> = null;\nlet _emptyFloatFrequencyData: Nullable<Float32Array> = null;\n\n/** @internal */\nexport function _GetEmptyByteFrequencyData(): Uint8Array {\n if (!_emptyByteFrequencyData) {\n _emptyByteFrequencyData = new Uint8Array();\n }\n return _emptyByteFrequencyData;\n}\n\n/** @internal */\nexport function _GetEmptyFloatFrequencyData(): Float32Array {\n if (!_emptyFloatFrequencyData) {\n _emptyFloatFrequencyData = new Float32Array();\n }\n return _emptyFloatFrequencyData;\n}\n\n/** @internal */\nexport class _AudioAnalyzer extends AbstractAudioAnalyzer {\n private _subGraph: _AbstractAudioSubGraph;\n\n /** @internal */\n public constructor(subGraph: _AbstractAudioSubGraph) {\n super();\n this._subGraph = subGraph;\n }\n\n /** @internal */\n public get fftSize(): AudioAnalyzerFFTSizeType {\n return _GetAudioAnalyzerProperty(this._subGraph, \"fftSize\");\n }\n\n public set fftSize(value: AudioAnalyzerFFTSizeType) {\n _SetAudioAnalyzerProperty(this._subGraph, \"fftSize\", value);\n }\n\n /** @internal */\n public get isEnabled(): boolean {\n return _GetAudioAnalyzerSubNode(this._subGraph) !== null;\n }\n\n /** @internal */\n public get minDecibels(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"minDecibels\");\n }\n\n public set minDecibels(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"minDecibels\", value);\n }\n\n /** @internal */\n public get maxDecibels(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"maxDecibels\");\n }\n\n public set maxDecibels(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"maxDecibels\", value);\n }\n\n /** @internal */\n public get smoothing(): number {\n return _GetAudioAnalyzerProperty(this._subGraph, \"smoothing\");\n }\n\n public set smoothing(value: number) {\n _SetAudioAnalyzerProperty(this._subGraph, \"smoothing\", value);\n }\n\n /** @internal */\n public dispose(): void {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (subNode) {\n this._subGraph.removeSubNode(subNode);\n subNode.dispose();\n }\n }\n\n /** @internal */\n public async enableAsync(): Promise<void> {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n await this._subGraph.createAndAddSubNode(AudioSubNode.ANALYZER);\n }\n return Promise.resolve();\n }\n\n /** @internal */\n public getByteFrequencyData(): Uint8Array {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n Logger.Warn(\"AudioAnalyzer not enabled\");\n this.enableAsync();\n return _GetEmptyByteFrequencyData();\n }\n return subNode.getByteFrequencyData();\n }\n\n /** @internal */\n public getFloatFrequencyData(): Float32Array {\n const subNode = _GetAudioAnalyzerSubNode(this._subGraph);\n if (!subNode) {\n Logger.Warn(\"AudioAnalyzer not enabled\");\n this.enableAsync();\n return _GetEmptyFloatFrequencyData();\n }\n return subNode.getFloatFrequencyData();\n }\n}\n"]}
@@ -5,7 +5,7 @@ import type { AudioEngineV2State, IAudioEngineV2Options } from "../abstractAudio
5
5
  import { AudioEngineV2 } from "../abstractAudio/audioEngineV2";
6
6
  import type { IMainAudioBusOptions, MainAudioBus } from "../abstractAudio/mainAudioBus";
7
7
  import type { IStaticSoundOptions, StaticSound } from "../abstractAudio/staticSound";
8
- import type { StaticSoundBuffer } from "../abstractAudio/staticSoundBuffer";
8
+ import type { IStaticSoundBufferOptions, StaticSoundBuffer } from "../abstractAudio/staticSoundBuffer";
9
9
  import type { IStreamingSoundOptions, StreamingSound } from "../abstractAudio/streamingSound";
10
10
  import type { AbstractSpatialAudioListener } from "../abstractAudio/subProperties/abstractSpatialAudioListener";
11
11
  import { _WebAudioMainOut } from "./webAudioMainOut";
@@ -94,7 +94,7 @@ export declare class _WebAudioEngine extends AudioEngineV2 {
94
94
  /** @internal */
95
95
  createSoundAsync(name: string, source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[], options?: Partial<IStaticSoundOptions>): Promise<StaticSound>;
96
96
  /** @internal */
97
- createSoundBufferAsync(source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[], options?: Partial<IStaticSoundOptions>): Promise<StaticSoundBuffer>;
97
+ createSoundBufferAsync(source: ArrayBuffer | AudioBuffer | StaticSoundBuffer | string | string[], options?: Partial<IStaticSoundBufferOptions>): Promise<StaticSoundBuffer>;
98
98
  /** @internal */
99
99
  createStreamingSoundAsync(name: string, source: HTMLMediaElement | string | string[], options?: Partial<IStreamingSoundOptions>): Promise<StreamingSound>;
100
100
  /** @internal */
@@ -104,9 +104,9 @@ export declare class _WebAudioEngine extends AudioEngineV2 {
104
104
  /** @internal */
105
105
  isFormatValid(format: string): boolean;
106
106
  /** @internal */
107
- pause(): Promise<void>;
107
+ pauseAsync(): Promise<void>;
108
108
  /** @internal */
109
- resume(): Promise<void>;
109
+ resumeAsync(): Promise<void>;
110
110
  /** @internal */
111
111
  _addMainBus(mainBus: MainAudioBus): void;
112
112
  /** @internal */
@@ -68,7 +68,7 @@ export class _WebAudioEngine extends AudioEngineV2 {
68
68
  if (this._audioContextStarted && this._resumeOnPause && !this._pauseCalled) {
69
69
  clearInterval(this._resumeOnPauseTimerId);
70
70
  this._resumeOnPauseTimerId = setInterval(() => {
71
- this.resume();
71
+ this.resumeAsync();
72
72
  }, this._resumeOnPauseRetryInterval);
73
73
  }
74
74
  }
@@ -212,12 +212,12 @@ export class _WebAudioEngine extends AudioEngineV2 {
212
212
  return true;
213
213
  }
214
214
  /** @internal */
215
- async pause() {
215
+ async pauseAsync() {
216
216
  await this._audioContext.suspend();
217
217
  this._pauseCalled = true;
218
218
  }
219
219
  /** @internal */
220
- async resume() {
220
+ resumeAsync() {
221
221
  this._pauseCalled = false;
222
222
  if (this._resumePromise) {
223
223
  return this._resumePromise;