@babylonjs/core 7.52.0 → 7.52.2

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 (75) hide show
  1. package/AudioV2/abstractAudio/abstractSound.d.ts +1 -2
  2. package/AudioV2/abstractAudio/abstractSound.js +1 -5
  3. package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
  4. package/AudioV2/abstractAudio/audioBus.d.ts +1 -2
  5. package/AudioV2/abstractAudio/audioBus.js +1 -5
  6. package/AudioV2/abstractAudio/audioBus.js.map +1 -1
  7. package/AudioV2/abstractAudio/audioEngineV2.d.ts +1 -2
  8. package/AudioV2/abstractAudio/audioEngineV2.js +1 -5
  9. package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
  10. package/AudioV2/abstractAudio/components/spatialAudioAttacherComponent.d.ts +43 -0
  11. package/AudioV2/abstractAudio/components/spatialAudioAttacherComponent.js +71 -0
  12. package/AudioV2/abstractAudio/components/spatialAudioAttacherComponent.js.map +1 -0
  13. package/AudioV2/abstractAudio/staticSound.d.ts +1 -1
  14. package/AudioV2/abstractAudio/staticSound.js +2 -2
  15. package/AudioV2/abstractAudio/staticSound.js.map +1 -1
  16. package/AudioV2/abstractAudio/streamingSound.d.ts +1 -1
  17. package/AudioV2/abstractAudio/streamingSound.js +2 -2
  18. package/AudioV2/abstractAudio/streamingSound.js.map +1 -1
  19. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.d.ts +15 -0
  20. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js +38 -3
  21. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js.map +1 -1
  22. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.d.ts +29 -8
  23. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js +1 -0
  24. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js.map +1 -1
  25. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.d.ts +28 -1
  26. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js +5 -1
  27. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js.map +1 -1
  28. package/AudioV2/abstractAudio/subProperties/spatialAudio.d.ts +16 -1
  29. package/AudioV2/abstractAudio/subProperties/spatialAudio.js +48 -14
  30. package/AudioV2/abstractAudio/subProperties/spatialAudio.js.map +1 -1
  31. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.d.ts +21 -0
  32. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js +39 -4
  33. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js.map +1 -1
  34. package/AudioV2/index.d.ts +1 -0
  35. package/AudioV2/index.js +1 -0
  36. package/AudioV2/index.js.map +1 -1
  37. package/AudioV2/spatialAudioAttachmentType.d.ts +5 -0
  38. package/AudioV2/spatialAudioAttachmentType.js +7 -0
  39. package/AudioV2/spatialAudioAttachmentType.js.map +1 -0
  40. package/AudioV2/webAudio/components/spatialWebAudioUpdaterComponent.d.ts +13 -0
  41. package/AudioV2/webAudio/components/spatialWebAudioUpdaterComponent.js +38 -0
  42. package/AudioV2/webAudio/components/spatialWebAudioUpdaterComponent.js.map +1 -0
  43. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.d.ts +13 -14
  44. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js +39 -39
  45. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js.map +1 -1
  46. package/AudioV2/webAudio/subProperties/spatialWebAudio.d.ts +6 -2
  47. package/AudioV2/webAudio/subProperties/spatialWebAudio.js +13 -15
  48. package/AudioV2/webAudio/subProperties/spatialWebAudio.js.map +1 -1
  49. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.d.ts +1 -1
  50. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js +41 -56
  51. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js.map +1 -1
  52. package/AudioV2/webAudio/webAudioBus.d.ts +3 -0
  53. package/AudioV2/webAudio/webAudioBus.js +23 -2
  54. package/AudioV2/webAudio/webAudioBus.js.map +1 -1
  55. package/AudioV2/webAudio/webAudioEngine.d.ts +3 -1
  56. package/AudioV2/webAudio/webAudioEngine.js +11 -3
  57. package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
  58. package/AudioV2/webAudio/webAudioStaticSound.d.ts +3 -0
  59. package/AudioV2/webAudio/webAudioStaticSound.js +23 -2
  60. package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
  61. package/AudioV2/webAudio/webAudioStreamingSound.d.ts +3 -0
  62. package/AudioV2/webAudio/webAudioStreamingSound.js +23 -2
  63. package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
  64. package/Engines/abstractEngine.d.ts +2 -1
  65. package/Engines/abstractEngine.js +6 -5
  66. package/Engines/abstractEngine.js.map +1 -1
  67. package/Meshes/geometry.js +14 -7
  68. package/Meshes/geometry.js.map +1 -1
  69. package/Meshes/mesh.vertexData.d.ts +1 -1
  70. package/Meshes/mesh.vertexData.js +2 -1
  71. package/Meshes/mesh.vertexData.js.map +1 -1
  72. package/Misc/fileTools.d.ts +3 -1
  73. package/Misc/fileTools.js +2 -2
  74. package/Misc/fileTools.js.map +1 -1
  75. package/package.json +1 -1
@@ -63,13 +63,12 @@ export declare abstract class AbstractSound extends AbstractNamedAudioNode {
63
63
  private _state;
64
64
  protected _instances: ReadonlySet<_AbstractSoundInstance>;
65
65
  protected abstract readonly _options: IAbstractSoundStoredOptions;
66
- protected _spatialAutoUpdate: boolean;
67
66
  protected abstract _subGraph: _AbstractAudioSubGraph;
68
67
  /**
69
68
  * Observable for when the sound stops playing.
70
69
  */
71
70
  readonly onEndedObservable: Observable<AbstractSound>;
72
- protected constructor(name: string, engine: AudioEngineV2, options: Partial<IAbstractSoundOptions>);
71
+ protected constructor(name: string, engine: AudioEngineV2);
73
72
  /**
74
73
  * Whether the sound should start playing automatically. Defaults to `false`.
75
74
  */
@@ -5,14 +5,13 @@ import { _GetVolumeAudioProperty, _GetVolumeAudioSubNode } from "./subNodes/volu
5
5
  * Abstract class representing a sound in the audio engine.
6
6
  */
7
7
  export class AbstractSound extends AbstractNamedAudioNode {
8
- constructor(name, engine, options) {
8
+ constructor(name, engine) {
9
9
  super(name, engine, 3 /* AudioNodeType.HAS_INPUTS_AND_OUTPUTS */); // Inputs are for instances.
10
10
  this._newestInstance = null;
11
11
  this._outBus = null;
12
12
  this._privateInstances = new Set();
13
13
  this._state = 1 /* SoundState.Stopped */;
14
14
  this._instances = this._privateInstances;
15
- this._spatialAutoUpdate = true;
16
15
  /**
17
16
  * Observable for when the sound stops playing.
18
17
  */
@@ -30,9 +29,6 @@ export class AbstractSound extends AbstractNamedAudioNode {
30
29
  this._onOutBusDisposed = () => {
31
30
  this.outBus = null;
32
31
  };
33
- if (typeof options.spatialAutoUpdate === "boolean") {
34
- this._spatialAutoUpdate = options.spatialAutoUpdate;
35
- }
36
32
  }
37
33
  /**
38
34
  * Whether the sound should start playing automatically. Defaults to `false`.
@@ -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;AAGnD,OAAO,EAAE,sBAAsB,EAAiB,MAAM,qBAAqB,CAAC;AAM5E,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAmDhG;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,sBAAsB;IAgB9D,YAAsB,IAAY,EAAE,MAAqB,EAAE,OAAuC;QAC9F,KAAK,CAAC,IAAI,EAAE,MAAM,+CAAuC,CAAC,CAAC,4BAA4B;QAhBnF,oBAAe,GAAqC,IAAI,CAAC;QACzD,YAAO,GAA8B,IAAI,CAAC;QAC1C,sBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;QACtD,WAAM,8BAAkC;QAEtC,eAAU,GA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AuB,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;IAEO,kBAAkB;QACtB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACpC,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;YACtC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;CAkBJ","sourcesContent":["import { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport { SoundState } from \"../soundState\";\nimport { AbstractNamedAudioNode, AudioNodeType } from \"./abstractAudioNode\";\nimport type { _AbstractSoundInstance } from \"./abstractSoundInstance\";\nimport type { PrimaryAudioBus } from \"./audioBus\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { _AbstractAudioSubGraph } from \"./subNodes/abstractAudioSubGraph\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\nimport { _GetVolumeAudioProperty, _GetVolumeAudioSubNode } from \"./subNodes/volumeAudioSubNode\";\nimport type { AbstractSpatialAudio, ISpatialAudioOptions } from \"./subProperties/abstractSpatialAudio\";\nimport type { AbstractStereoAudio, IStereoAudioOptions } from \"./subProperties/abstractStereoAudio\";\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, ISpatialAudioOptions, IStereoAudioOptions {\n /**\n * The output bus for the sound. Defaults to `null`.\n * - If not set or `null`, the sound is automatically connected to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n outBus: Nullable<PrimaryAudioBus>;\n}\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 AbstractNamedAudioNode {\n private _newestInstance: Nullable<_AbstractSoundInstance> = null;\n private _outBus: Nullable<PrimaryAudioBus> = 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 protected _spatialAutoUpdate: boolean = true;\n protected abstract _subGraph: _AbstractAudioSubGraph;\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, options: Partial<IAbstractSoundOptions>) {\n super(name, engine, AudioNodeType.HAS_INPUTS_AND_OUTPUTS); // Inputs are for instances.\n\n if (typeof options.spatialAutoUpdate === \"boolean\") {\n this._spatialAutoUpdate = options.spatialAutoUpdate;\n }\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 output bus for the sound. Defaults to `null`.\n * - If not set or `null`, the sound is automatically connected to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n public get outBus(): Nullable<PrimaryAudioBus> {\n return this._outBus;\n }\n\n public set outBus(outBus: Nullable<PrimaryAudioBus>) {\n if (this._outBus === outBus) {\n return;\n }\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);\n if (!this._disconnect(this._outBus)) {\n throw new Error(\"Disconnect failed\");\n }\n }\n\n this._outBus = outBus;\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.add(this._onOutBusDisposed);\n if (!this._connect(this._outBus)) {\n throw new Error(\"Connect failed\");\n }\n }\n }\n\n /**\n * The spatial properties of the sound.\n */\n public abstract spatial: AbstractSpatialAudio;\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 * The stereo properties of the sound.\n */\n public abstract stereo: AbstractStereoAudio;\n\n /**\n * The output volume of the sound.\n */\n public get volume(): number {\n return _GetVolumeAudioProperty(this._subGraph, \"volume\");\n }\n\n public set volume(value: number) {\n // The volume subnode is created on initialization and should always exist.\n const node = _GetVolumeAudioSubNode(this._subGraph);\n if (!node) {\n throw new Error(\"No volume subnode\");\n }\n\n node.volume = value;\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 this._outBus = 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 _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 _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 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 private _onOutBusDisposed = () => {\n this.outBus = null;\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;AAGnD,OAAO,EAAE,sBAAsB,EAAiB,MAAM,qBAAqB,CAAC;AAM5E,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAmDhG;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,sBAAsB;IAe9D,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,+CAAuC,CAAC,CAAC,4BAA4B;QAfnF,oBAAe,GAAqC,IAAI,CAAC;QACzD,YAAO,GAA8B,IAAI,CAAC;QAC1C,sBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;QACtD,WAAM,8BAAkC;QAEtC,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AAE,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;IAEO,kBAAkB;QACtB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACpC,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;YACtC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;CAkBJ","sourcesContent":["import { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport { SoundState } from \"../soundState\";\nimport { AbstractNamedAudioNode, AudioNodeType } from \"./abstractAudioNode\";\nimport type { _AbstractSoundInstance } from \"./abstractSoundInstance\";\nimport type { PrimaryAudioBus } from \"./audioBus\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { _AbstractAudioSubGraph } from \"./subNodes/abstractAudioSubGraph\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\nimport { _GetVolumeAudioProperty, _GetVolumeAudioSubNode } from \"./subNodes/volumeAudioSubNode\";\nimport type { AbstractSpatialAudio, ISpatialAudioOptions } from \"./subProperties/abstractSpatialAudio\";\nimport type { AbstractStereoAudio, IStereoAudioOptions } from \"./subProperties/abstractStereoAudio\";\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, ISpatialAudioOptions, IStereoAudioOptions {\n /**\n * The output bus for the sound. Defaults to `null`.\n * - If not set or `null`, the sound is automatically connected to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n outBus: Nullable<PrimaryAudioBus>;\n}\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 AbstractNamedAudioNode {\n private _newestInstance: Nullable<_AbstractSoundInstance> = null;\n private _outBus: Nullable<PrimaryAudioBus> = 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 protected abstract _subGraph: _AbstractAudioSubGraph;\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 * 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 output bus for the sound. Defaults to `null`.\n * - If not set or `null`, the sound is automatically connected to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n public get outBus(): Nullable<PrimaryAudioBus> {\n return this._outBus;\n }\n\n public set outBus(outBus: Nullable<PrimaryAudioBus>) {\n if (this._outBus === outBus) {\n return;\n }\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);\n if (!this._disconnect(this._outBus)) {\n throw new Error(\"Disconnect failed\");\n }\n }\n\n this._outBus = outBus;\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.add(this._onOutBusDisposed);\n if (!this._connect(this._outBus)) {\n throw new Error(\"Connect failed\");\n }\n }\n }\n\n /**\n * The spatial properties of the sound.\n */\n public abstract spatial: AbstractSpatialAudio;\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 * The stereo properties of the sound.\n */\n public abstract stereo: AbstractStereoAudio;\n\n /**\n * The output volume of the sound.\n */\n public get volume(): number {\n return _GetVolumeAudioProperty(this._subGraph, \"volume\");\n }\n\n public set volume(value: number) {\n // The volume subnode is created on initialization and should always exist.\n const node = _GetVolumeAudioSubNode(this._subGraph);\n if (!node) {\n throw new Error(\"No volume subnode\");\n }\n\n node.volume = value;\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 this._outBus = 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 _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 _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 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 private _onOutBusDisposed = () => {\n this.outBus = null;\n };\n}\n"]}
@@ -25,8 +25,7 @@ export interface IAudioBusOptions extends ISpatialAudioOptions, IStereoAudioOpti
25
25
  */
26
26
  export declare abstract class AudioBus extends AbstractAudioBus {
27
27
  private _outBus;
28
- protected _spatialAutoUpdate: boolean;
29
- protected constructor(name: string, engine: AudioEngineV2, options: Partial<IAudioBusOptions>);
28
+ protected constructor(name: string, engine: AudioEngineV2);
30
29
  /**
31
30
  * The output bus of the audio bus. Defaults to the audio engine's default main bus.
32
31
  */
@@ -7,16 +7,12 @@ import { AbstractAudioBus } from "./abstractAudioBus.js";
7
7
  * Audio buses are created by the {@link CreateAudioBusAsync} function.
8
8
  */
9
9
  export class AudioBus extends AbstractAudioBus {
10
- constructor(name, engine, options) {
10
+ constructor(name, engine) {
11
11
  super(name, engine);
12
12
  this._outBus = null;
13
- this._spatialAutoUpdate = true;
14
13
  this._onOutBusDisposed = () => {
15
14
  this.outBus = this.engine.defaultMainBus;
16
15
  };
17
- if (typeof options.spatialAutoUpdate === "boolean") {
18
- this._spatialAutoUpdate = options.spatialAutoUpdate;
19
- }
20
16
  }
21
17
  /**
22
18
  * The output bus of the audio bus. Defaults to the audio engine's default main bus.
@@ -1 +1 @@
1
- {"version":3,"file":"audioBus.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/audioBus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,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gBAC/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACtC,CAAC;QACL,CAAC;IACL,CAAC;IAYD;;OAEG;IACa,OAAO;QACnB,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;CAKJ","sourcesContent":["import type { Nullable } from \"../../types\";\nimport { AbstractAudioBus } from \"./abstractAudioBus\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { MainAudioBus } from \"./mainAudioBus\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\nimport type { AbstractSpatialAudio, ISpatialAudioOptions } from \"./subProperties/abstractSpatialAudio\";\nimport type { AbstractStereoAudio, IStereoAudioOptions } from \"./subProperties/abstractStereoAudio\";\n\n// NB: Secondary audio buses will be added later.\nexport type PrimaryAudioBus = MainAudioBus | AudioBus;\n\n/**\n * Options for creating an audio bus.\n */\nexport interface IAudioBusOptions extends ISpatialAudioOptions, IStereoAudioOptions, IVolumeAudioOptions {\n /**\n * The output bus of the audio bus. Defaults to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n outBus: PrimaryAudioBus;\n}\n\n/**\n * Abstract class for an audio bus that has spatial audio and stereo output capabilities.\n *\n * Instances of this class can be connected to other audio buses.\n *\n * Audio buses are created by the {@link CreateAudioBusAsync} function.\n */\nexport abstract class AudioBus extends AbstractAudioBus {\n private _outBus: Nullable<PrimaryAudioBus> = null;\n\n protected _spatialAutoUpdate: boolean = true;\n\n protected constructor(name: string, engine: AudioEngineV2, options: Partial<IAudioBusOptions>) {\n super(name, engine);\n\n if (typeof options.spatialAutoUpdate === \"boolean\") {\n this._spatialAutoUpdate = options.spatialAutoUpdate;\n }\n }\n\n /**\n * The output bus of the audio bus. Defaults to the audio engine's default main bus.\n */\n public get outBus(): Nullable<PrimaryAudioBus> {\n return this._outBus;\n }\n\n public set outBus(outBus: Nullable<PrimaryAudioBus>) {\n if (this._outBus === outBus) {\n return;\n }\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);\n\n if (!this._disconnect(this._outBus)) {\n throw new Error(\"Disconnect failed\");\n }\n }\n\n this._outBus = outBus;\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.add(this._onOutBusDisposed);\n\n if (!this._connect(this._outBus)) {\n throw new Error(\"Connect failed\");\n }\n }\n }\n\n /**\n * The spatial audio properties of the audio bus.\n */\n public abstract readonly spatial: AbstractSpatialAudio;\n\n /**\n * The stereo audio properties of the audio bus.\n */\n public abstract readonly stereo: AbstractStereoAudio;\n\n /**\n * Releases associated resources.\n */\n public override dispose(): void {\n super.dispose();\n this._outBus = null;\n }\n\n private _onOutBusDisposed = () => {\n this.outBus = this.engine.defaultMainBus;\n };\n}\n"]}
1
+ {"version":3,"file":"audioBus.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/audioBus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqBtD;;;;;;GAMG;AACH,MAAM,OAAgB,QAAS,SAAQ,gBAAgB;IAGnD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAHhB,YAAO,GAA8B,IAAI,CAAC;QAuD1C,sBAAiB,GAAG,GAAG,EAAE;YAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;QAC7C,CAAC,CAAC;IArDF,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAW,MAAM,CAAC,MAAiC;QAC/C,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;YAC1B,OAAO;QACX,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAExE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACzC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAE7D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACtC,CAAC;QACL,CAAC;IACL,CAAC;IAYD;;OAEG;IACa,OAAO;QACnB,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;CAKJ","sourcesContent":["import type { Nullable } from \"../../types\";\nimport { AbstractAudioBus } from \"./abstractAudioBus\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { MainAudioBus } from \"./mainAudioBus\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\nimport type { AbstractSpatialAudio, ISpatialAudioOptions } from \"./subProperties/abstractSpatialAudio\";\nimport type { AbstractStereoAudio, IStereoAudioOptions } from \"./subProperties/abstractStereoAudio\";\n\n// NB: Secondary audio buses will be added later.\nexport type PrimaryAudioBus = MainAudioBus | AudioBus;\n\n/**\n * Options for creating an audio bus.\n */\nexport interface IAudioBusOptions extends ISpatialAudioOptions, IStereoAudioOptions, IVolumeAudioOptions {\n /**\n * The output bus of the audio bus. Defaults to the audio engine's default main bus.\n * @see {@link AudioEngineV2.defaultMainBus}\n */\n outBus: PrimaryAudioBus;\n}\n\n/**\n * Abstract class for an audio bus that has spatial audio and stereo output capabilities.\n *\n * Instances of this class can be connected to other audio buses.\n *\n * Audio buses are created by the {@link CreateAudioBusAsync} function.\n */\nexport abstract class AudioBus extends AbstractAudioBus {\n private _outBus: Nullable<PrimaryAudioBus> = null;\n\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n\n /**\n * The output bus of the audio bus. Defaults to the audio engine's default main bus.\n */\n public get outBus(): Nullable<PrimaryAudioBus> {\n return this._outBus;\n }\n\n public set outBus(outBus: Nullable<PrimaryAudioBus>) {\n if (this._outBus === outBus) {\n return;\n }\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);\n\n if (!this._disconnect(this._outBus)) {\n throw new Error(\"Disconnect failed\");\n }\n }\n\n this._outBus = outBus;\n\n if (this._outBus) {\n this._outBus.onDisposeObservable.add(this._onOutBusDisposed);\n\n if (!this._connect(this._outBus)) {\n throw new Error(\"Connect failed\");\n }\n }\n }\n\n /**\n * The spatial audio properties of the audio bus.\n */\n public abstract readonly spatial: AbstractSpatialAudio;\n\n /**\n * The stereo audio properties of the audio bus.\n */\n public abstract readonly stereo: AbstractStereoAudio;\n\n /**\n * Releases associated resources.\n */\n public override dispose(): void {\n super.dispose();\n this._outBus = null;\n }\n\n private _onOutBusDisposed = () => {\n this.outBus = this.engine.defaultMainBus;\n };\n}\n"]}
@@ -36,8 +36,7 @@ export declare abstract class AudioEngineV2 {
36
36
  /** Owned top-level sound and bus nodes. */
37
37
  private readonly _nodes;
38
38
  private _defaultMainBus;
39
- protected _listenerAutoUpdate: boolean;
40
- protected constructor(options: Partial<IAudioEngineV2Options>);
39
+ protected constructor();
41
40
  /**
42
41
  * The elapsed time since the audio engine was started, in seconds.
43
42
  */
@@ -15,17 +15,13 @@ export function LastCreatedAudioEngine() {
15
15
  * A v2 audio engine based on the WebAudio API can be created with the {@link CreateAudioEngineAsync} function.
16
16
  */
17
17
  export class AudioEngineV2 {
18
- constructor(options) {
18
+ constructor() {
19
19
  /** Not owned, but all items should be in `_nodes` container, too, which is owned. */
20
20
  this._mainBuses = new Set();
21
21
  /** Owned top-level sound and bus nodes. */
22
22
  this._nodes = new Set();
23
23
  this._defaultMainBus = null;
24
- this._listenerAutoUpdate = true;
25
24
  Instances.push(this);
26
- if (typeof options.listenerAutoUpdate === "boolean") {
27
- this._listenerAutoUpdate = options.listenerAutoUpdate;
28
- }
29
25
  }
30
26
  /**
31
27
  * The default main bus that will be used for audio buses and sounds if their `outBus` option is not set.
@@ -1 +1 @@
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,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC;AAkBD;;;;GAIG;AACH,MAAM,OAAgB,aAAa;IAW/B,YAAsB,OAAuC;QAV7D,qFAAqF;QACpE,eAAU,GAAG,IAAI,GAAG,EAAgB,CAAC;QAEtD,2CAA2C;QAC1B,WAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;QAEpD,oBAAe,GAA2B,IAAI,CAAC;QAE7C,wBAAmB,GAAY,IAAI,CAAC;QAG1C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErB,IAAI,OAAO,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;YAClD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAC1D,CAAC;IACL,CAAC;IAOD;;;;OAIG;IACH,IAAW,cAAc;QACrB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,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sBAAsB,CACxC,MAAyE,EACzE,UAA8C,EAAE,EAChD,SAAkC,IAAI;IAEtC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;GAOG;AACH,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 { 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 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 protected _listenerAutoUpdate: boolean = true;\n\n protected constructor(options: Partial<IAudioEngineV2Options>) {\n Instances.push(this);\n\n if (typeof options.listenerAutoUpdate === \"boolean\") {\n this._listenerAutoUpdate = options.listenerAutoUpdate;\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 * 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,IAAI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AY,EAAE,UAAyC,EAAE,EAAE,SAAkC,IAAI;IACrI,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC5B,IAAY,EACZ,MAAyE,EACzE,UAAwC,EAAE,EAC1C,SAAkC,IAAI;IAEtC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CACxC,MAAyE,EACzE,UAA8C,EAAE,EAChD,SAAkC,IAAI;IAEtC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;GAOG;AACH,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 { 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 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 protected constructor() {\n Instances.push(this);\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 * 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"]}
@@ -0,0 +1,43 @@
1
+ import type { Node } from "../../../node";
2
+ import { SpatialAudioAttachmentType } from "../../spatialAudioAttachmentType";
3
+ import type { _SpatialAudioSubNode } from "../subNodes/spatialAudioSubNode";
4
+ import type { _SpatialAudioListener } from "../subProperties/spatialAudioListener";
5
+ /**
6
+ * Provides a common interface for attaching an audio listener or source to a specific entity, ensuring only one entity
7
+ * is attached at a time.
8
+ * @internal
9
+ */
10
+ export declare class _SpatialAudioAttacherComponent {
11
+ /** @internal */
12
+ private _attachmentType;
13
+ private readonly _position;
14
+ private readonly _rotationQuaternion;
15
+ private _sceneNode;
16
+ private readonly _spatialAudioNode;
17
+ private _useBoundingBox;
18
+ /** @internal */
19
+ constructor(spatialAudioNode: _SpatialAudioSubNode | _SpatialAudioListener);
20
+ /**
21
+ * Returns `true` if the audio listener or source is attached to an entity; otherwise returns `false`.
22
+ */
23
+ get isAttached(): boolean;
24
+ /**
25
+ * Attaches a scene object.
26
+ * @param sceneNode The scene node to attach to.
27
+ * @param useBoundingBox Whether to use the bounding box of the node for positioning. Defaults to `false`.
28
+ * @param attachmentType Whather to attach to the node's position and/or rotation. Defaults to `PositionAndRotation`.
29
+ */
30
+ attach(sceneNode: Node, useBoundingBox: boolean, attachmentType: SpatialAudioAttachmentType): void;
31
+ /**
32
+ * Detaches the attached entity.
33
+ */
34
+ detach(): void;
35
+ /**
36
+ * Releases associated resources.
37
+ */
38
+ dispose: () => void;
39
+ /**
40
+ * Updates the audio listener or source.
41
+ */
42
+ update(): void;
43
+ }
@@ -0,0 +1,71 @@
1
+ import { Quaternion, Vector3 } from "../../../Maths/math.vector.js";
2
+ /**
3
+ * Provides a common interface for attaching an audio listener or source to a specific entity, ensuring only one entity
4
+ * is attached at a time.
5
+ * @internal
6
+ */
7
+ export class _SpatialAudioAttacherComponent {
8
+ /** @internal */
9
+ constructor(spatialAudioNode) {
10
+ /** @internal */
11
+ this._attachmentType = 3 /* SpatialAudioAttachmentType.PositionAndRotation */;
12
+ this._position = new Vector3();
13
+ this._rotationQuaternion = new Quaternion();
14
+ this._sceneNode = null;
15
+ this._useBoundingBox = false;
16
+ /**
17
+ * Releases associated resources.
18
+ */
19
+ this.dispose = () => {
20
+ this.detach();
21
+ };
22
+ this._spatialAudioNode = spatialAudioNode;
23
+ }
24
+ /**
25
+ * Returns `true` if the audio listener or source is attached to an entity; otherwise returns `false`.
26
+ */
27
+ get isAttached() {
28
+ return this._sceneNode !== null;
29
+ }
30
+ /**
31
+ * Attaches a scene object.
32
+ * @param sceneNode The scene node to attach to.
33
+ * @param useBoundingBox Whether to use the bounding box of the node for positioning. Defaults to `false`.
34
+ * @param attachmentType Whather to attach to the node's position and/or rotation. Defaults to `PositionAndRotation`.
35
+ */
36
+ attach(sceneNode, useBoundingBox, attachmentType) {
37
+ this.detach();
38
+ this._attachmentType = attachmentType;
39
+ this._sceneNode = sceneNode;
40
+ this._sceneNode.onDisposeObservable.add(this.dispose);
41
+ this._useBoundingBox = useBoundingBox;
42
+ }
43
+ /**
44
+ * Detaches the attached entity.
45
+ */
46
+ detach() {
47
+ this._sceneNode?.onDisposeObservable.removeCallback(this.dispose);
48
+ this._sceneNode = null;
49
+ }
50
+ /**
51
+ * Updates the audio listener or source.
52
+ */
53
+ update() {
54
+ if (this._attachmentType & 1 /* SpatialAudioAttachmentType.Position */) {
55
+ if (this._useBoundingBox && this._sceneNode.getBoundingInfo) {
56
+ this._position.copyFrom(this._sceneNode.getBoundingInfo().boundingBox.centerWorld);
57
+ }
58
+ else {
59
+ this._position.copyFrom(this._sceneNode.position);
60
+ }
61
+ this._spatialAudioNode.position.copyFrom(this._position);
62
+ this._spatialAudioNode.updatePosition();
63
+ }
64
+ if (this._attachmentType & 2 /* SpatialAudioAttachmentType.Rotation */) {
65
+ this._sceneNode?.getWorldMatrix().decompose(undefined, this._rotationQuaternion, undefined);
66
+ this._spatialAudioNode.rotationQuaternion.copyFrom(this._rotationQuaternion);
67
+ this._spatialAudioNode.updateRotation();
68
+ }
69
+ }
70
+ }
71
+ //# sourceMappingURL=spatialAudioAttacherComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spatialAudioAttacherComponent.js","sourceRoot":"","sources":["../../../../../../dev/core/src/AudioV2/abstractAudio/components/spatialAudioAttacherComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAQjE;;;;GAIG;AACH,MAAM,OAAO,8BAA8B;IASvC,gBAAgB;IAChB,YAAmB,gBAA8D;QATjF,gBAAgB;QACR,oBAAe,0DAA8E;QACpF,cAAS,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,wBAAmB,GAAG,IAAI,UAAU,EAAE,CAAC;QAChD,eAAU,GAAmB,IAAI,CAAC;QAElC,oBAAe,GAAY,KAAK,CAAC;QAuCzC;;WAEG;QACI,YAAO,GAAG,GAAG,EAAE;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC,CAAC;QAxCE,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAe,EAAE,cAAuB,EAAE,cAA0C;QAC9F,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QAEtC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEtD,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,MAAM;QACT,IAAI,CAAC,UAAU,EAAE,mBAAmB,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC3B,CAAC;IASD;;OAEG;IACI,MAAM;QACT,IAAI,IAAI,CAAC,eAAe,8CAAsC,EAAE,CAAC;YAC7D,IAAI,IAAI,CAAC,eAAe,IAAK,IAAI,CAAC,UAA2B,CAAC,eAAe,EAAE,CAAC;gBAC5E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAE,IAAI,CAAC,UAA2B,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YACzG,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAE,IAAI,CAAC,UAAkB,CAAC,QAAQ,CAAC,CAAC;YAC/D,CAAC;YAED,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACzD,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,8CAAsC,EAAE,CAAC;YAC7D,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;YAE5F,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YAC7E,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Quaternion, Vector3 } from \"../../../Maths/math.vector\";\nimport type { AbstractMesh } from \"../../../Meshes/abstractMesh\";\nimport type { Node } from \"../../../node\";\nimport type { Nullable } from \"../../../types\";\nimport { SpatialAudioAttachmentType } from \"../../spatialAudioAttachmentType\";\nimport type { _SpatialAudioSubNode } from \"../subNodes/spatialAudioSubNode\";\nimport type { _SpatialAudioListener } from \"../subProperties/spatialAudioListener\";\n\n/**\n * Provides a common interface for attaching an audio listener or source to a specific entity, ensuring only one entity\n * is attached at a time.\n * @internal\n */\nexport class _SpatialAudioAttacherComponent {\n /** @internal */\n private _attachmentType: SpatialAudioAttachmentType = SpatialAudioAttachmentType.PositionAndRotation;\n private readonly _position = new Vector3();\n private readonly _rotationQuaternion = new Quaternion();\n private _sceneNode: Nullable<Node> = null;\n private readonly _spatialAudioNode: _SpatialAudioSubNode | _SpatialAudioListener;\n private _useBoundingBox: boolean = false;\n\n /** @internal */\n public constructor(spatialAudioNode: _SpatialAudioSubNode | _SpatialAudioListener) {\n this._spatialAudioNode = spatialAudioNode;\n }\n\n /**\n * Returns `true` if the audio listener or source is attached to an entity; otherwise returns `false`.\n */\n public get isAttached(): boolean {\n return this._sceneNode !== null;\n }\n\n /**\n * Attaches a scene object.\n * @param sceneNode The scene node to attach to.\n * @param useBoundingBox Whether to use the bounding box of the node for positioning. Defaults to `false`.\n * @param attachmentType Whather to attach to the node's position and/or rotation. Defaults to `PositionAndRotation`.\n */\n public attach(sceneNode: Node, useBoundingBox: boolean, attachmentType: SpatialAudioAttachmentType): void {\n this.detach();\n\n this._attachmentType = attachmentType;\n\n this._sceneNode = sceneNode;\n this._sceneNode.onDisposeObservable.add(this.dispose);\n\n this._useBoundingBox = useBoundingBox;\n }\n\n /**\n * Detaches the attached entity.\n */\n public detach() {\n this._sceneNode?.onDisposeObservable.removeCallback(this.dispose);\n this._sceneNode = null;\n }\n\n /**\n * Releases associated resources.\n */\n public dispose = () => {\n this.detach();\n };\n\n /**\n * Updates the audio listener or source.\n */\n public update() {\n if (this._attachmentType & SpatialAudioAttachmentType.Position) {\n if (this._useBoundingBox && (this._sceneNode as AbstractMesh).getBoundingInfo) {\n this._position.copyFrom((this._sceneNode as AbstractMesh).getBoundingInfo().boundingBox.centerWorld);\n } else {\n this._position.copyFrom((this._sceneNode as any).position);\n }\n\n this._spatialAudioNode.position.copyFrom(this._position);\n this._spatialAudioNode.updatePosition();\n }\n\n if (this._attachmentType & SpatialAudioAttachmentType.Rotation) {\n this._sceneNode?.getWorldMatrix().decompose(undefined, this._rotationQuaternion, undefined);\n\n this._spatialAudioNode.rotationQuaternion.copyFrom(this._rotationQuaternion);\n this._spatialAudioNode.updateRotation();\n }\n }\n}\n"]}
@@ -87,7 +87,7 @@ export declare abstract class StaticSound extends AbstractSound {
87
87
  * This buffer can be shared with other static sounds.
88
88
  */
89
89
  abstract readonly buffer: StaticSoundBuffer;
90
- protected constructor(name: string, engine: AudioEngineV2, options: Partial<IStaticSoundOptions>);
90
+ protected constructor(name: string, engine: AudioEngineV2);
91
91
  /**
92
92
  * The amount of time to play the sound for, in seconds.
93
93
  * - If less than or equal to `0`, the sound plays for its full duration.
@@ -12,8 +12,8 @@ import { AbstractSound } from "./abstractSound.js";
12
12
  * Static sounds are created by the {@link CreateSoundAsync} function.
13
13
  */
14
14
  export class StaticSound extends AbstractSound {
15
- constructor(name, engine, options) {
16
- super(name, engine, options);
15
+ constructor(name, engine) {
16
+ super(name, engine);
17
17
  }
18
18
  /**
19
19
  * The amount of time to play the sound for, in seconds.
@@ -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,EAAE,OAAqC;QAC5F,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,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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AK,IAAI,CAAC,OAAO,EAAC;QACjC,OAAO,CAAC,KAAK,KAAb,OAAO,CAAC,KAAK,GAAK,IAAI,CAAC,KAAK,EAAC;QAC7B,OAAO,CAAC,YAAY,KAApB,OAAO,CAAC,YAAY,GAAK,IAAI,CAAC,YAAY,EAAC;QAC3C,OAAO,CAAC,WAAW,KAAnB,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.\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.\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, options: Partial<IStaticSoundOptions>) {\n super(name, engine, options);\n }\n\n /**\n * The amount of time to play the sound for, in seconds.\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.\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\n /**\n * The playback rate of the sound.\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\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;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;IAC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AAO,CAAC,YAAY,KAApB,OAAO,CAAC,YAAY,GAAK,IAAI,CAAC,YAAY,EAAC;QAC3C,OAAO,CAAC,WAAW,KAAnB,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.\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.\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.\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.\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\n /**\n * The playback rate of the sound.\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\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"]}
@@ -41,7 +41,7 @@ export interface IStreamingSoundStoredOptions extends IAbstractSoundStoredOption
41
41
  export declare abstract class StreamingSound extends AbstractSound {
42
42
  private _preloadedInstances;
43
43
  protected abstract readonly _options: IStreamingSoundStoredOptions;
44
- protected constructor(name: string, engine: AudioEngineV2, options: Partial<IStreamingSoundOptions>);
44
+ protected constructor(name: string, engine: AudioEngineV2);
45
45
  /**
46
46
  * The number of instances to preload.
47
47
  */
@@ -13,8 +13,8 @@ import { AbstractSound } from "./abstractSound.js";
13
13
  * Streaming sounds are created by the {@link CreateStreamingSoundAsync} function.
14
14
  */
15
15
  export class StreamingSound extends AbstractSound {
16
- constructor(name, engine, options) {
17
- super(name, engine, options);
16
+ constructor(name, engine) {
17
+ super(name, engine);
18
18
  this._preloadedInstances = new Array();
19
19
  }
20
20
  /**
@@ -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,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AAQ,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, options: Partial<IStreamingSoundOptions>) {\n super(name, engine, options);\n }\n\n /**\n * The number of instances to preload.\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,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,CAA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C,EAAC;QAErB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC3B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,IAAI;QACP,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.\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,5 +1,7 @@
1
1
  import type { Quaternion, Vector3 } from "../../../Maths/math.vector";
2
+ import type { Node } from "../../../node";
2
3
  import type { Nullable } from "../../../types";
4
+ import type { SpatialAudioAttachmentType } from "../../spatialAudioAttachmentType";
3
5
  import type { AudioEngineV2 } from "../audioEngineV2";
4
6
  import type { ISpatialAudioOptions } from "../subProperties/abstractSpatialAudio";
5
7
  import { _SpatialAudioDefaults } from "../subProperties/abstractSpatialAudio";
@@ -7,6 +9,7 @@ import type { _AbstractAudioSubGraph } from "./abstractAudioSubGraph";
7
9
  import { _AbstractAudioSubNode } from "./abstractAudioSubNode";
8
10
  /** @internal */
9
11
  export declare abstract class _SpatialAudioSubNode extends _AbstractAudioSubNode {
12
+ private _attacherComponent;
10
13
  protected constructor(engine: AudioEngineV2);
11
14
  abstract coneInnerAngle: number;
12
15
  abstract coneOuterAngle: number;
@@ -21,7 +24,19 @@ export declare abstract class _SpatialAudioSubNode extends _AbstractAudioSubNode
21
24
  abstract rotationQuaternion: Quaternion;
22
25
  abstract inNode: AudioNode;
23
26
  /** @internal */
27
+ get isAttached(): boolean;
28
+ /** @internal */
29
+ attach(sceneNode: Node, useBoundingBox: boolean, attachmentType: SpatialAudioAttachmentType): void;
30
+ /** @internal */
31
+ detach(): void;
32
+ /** @internal */
33
+ dispose(): void;
34
+ /** @internal */
24
35
  setOptions(options: Partial<ISpatialAudioOptions>): void;
36
+ /** @internal */
37
+ update(): void;
38
+ abstract updatePosition(): void;
39
+ abstract updateRotation(): void;
25
40
  }
26
41
  /** @internal */
27
42
  export declare function _GetSpatialAudioSubNode(subGraph: _AbstractAudioSubGraph): Nullable<_SpatialAudioSubNode>;