@babylonjs/core 7.51.3 → 7.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/Audio/Interfaces/IAudioEngineOptions.d.ts +2 -0
  2. package/Audio/Interfaces/IAudioEngineOptions.js.map +1 -1
  3. package/AudioV2/abstractAudio/abstractAudioBus.d.ts +22 -0
  4. package/AudioV2/abstractAudio/abstractAudioBus.js +35 -0
  5. package/AudioV2/abstractAudio/abstractAudioBus.js.map +1 -0
  6. package/AudioV2/abstractAudio/abstractAudioNode.d.ts +99 -0
  7. package/AudioV2/abstractAudio/abstractAudioNode.js +149 -0
  8. package/AudioV2/abstractAudio/abstractAudioNode.js.map +1 -0
  9. package/AudioV2/abstractAudio/abstractSound.d.ts +152 -0
  10. package/AudioV2/abstractAudio/abstractSound.js +202 -0
  11. package/AudioV2/abstractAudio/abstractSound.js.map +1 -0
  12. package/AudioV2/abstractAudio/abstractSoundInstance.d.ts +34 -0
  13. package/AudioV2/abstractAudio/abstractSoundInstance.js +35 -0
  14. package/AudioV2/abstractAudio/abstractSoundInstance.js.map +1 -0
  15. package/AudioV2/abstractAudio/audioBus.d.ts +48 -0
  16. package/AudioV2/abstractAudio/audioBus.js +53 -0
  17. package/AudioV2/abstractAudio/audioBus.js.map +1 -0
  18. package/AudioV2/abstractAudio/audioEngineV2.d.ts +193 -0
  19. package/AudioV2/abstractAudio/audioEngineV2.js +155 -0
  20. package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -0
  21. package/AudioV2/abstractAudio/index.d.ts +10 -0
  22. package/AudioV2/abstractAudio/index.js +12 -0
  23. package/AudioV2/abstractAudio/index.js.map +1 -0
  24. package/AudioV2/abstractAudio/mainAudioBus.d.ts +22 -0
  25. package/AudioV2/abstractAudio/mainAudioBus.js +18 -0
  26. package/AudioV2/abstractAudio/mainAudioBus.js.map +1 -0
  27. package/AudioV2/abstractAudio/mainAudioOut.d.ts +13 -0
  28. package/AudioV2/abstractAudio/mainAudioOut.js +15 -0
  29. package/AudioV2/abstractAudio/mainAudioOut.js.map +1 -0
  30. package/AudioV2/abstractAudio/staticSound.d.ts +134 -0
  31. package/AudioV2/abstractAudio/staticSound.js +113 -0
  32. package/AudioV2/abstractAudio/staticSound.js.map +1 -0
  33. package/AudioV2/abstractAudio/staticSoundBuffer.d.ts +46 -0
  34. package/AudioV2/abstractAudio/staticSoundBuffer.js +17 -0
  35. package/AudioV2/abstractAudio/staticSoundBuffer.js.map +1 -0
  36. package/AudioV2/abstractAudio/staticSoundInstance.d.ts +15 -0
  37. package/AudioV2/abstractAudio/staticSoundInstance.js +5 -0
  38. package/AudioV2/abstractAudio/staticSoundInstance.js.map +1 -0
  39. package/AudioV2/abstractAudio/streamingSound.d.ts +77 -0
  40. package/AudioV2/abstractAudio/streamingSound.js +109 -0
  41. package/AudioV2/abstractAudio/streamingSound.js.map +1 -0
  42. package/AudioV2/abstractAudio/streamingSoundInstance.d.ts +25 -0
  43. package/AudioV2/abstractAudio/streamingSoundInstance.js +29 -0
  44. package/AudioV2/abstractAudio/streamingSoundInstance.js.map +1 -0
  45. package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.d.ts +53 -0
  46. package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js +97 -0
  47. package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js.map +1 -0
  48. package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.d.ts +13 -0
  49. package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.js +33 -0
  50. package/AudioV2/abstractAudio/subNodes/abstractAudioSubNode.js.map +1 -0
  51. package/AudioV2/abstractAudio/subNodes/audioSubNode.d.ts +6 -0
  52. package/AudioV2/abstractAudio/subNodes/audioSubNode.js +8 -0
  53. package/AudioV2/abstractAudio/subNodes/audioSubNode.js.map +1 -0
  54. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.d.ts +31 -0
  55. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js +46 -0
  56. package/AudioV2/abstractAudio/subNodes/spatialAudioSubNode.js.map +1 -0
  57. package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.d.ts +19 -0
  58. package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.js +27 -0
  59. package/AudioV2/abstractAudio/subNodes/stereoAudioSubNode.js.map +1 -0
  60. package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.d.ts +28 -0
  61. package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js +24 -0
  62. package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js.map +1 -0
  63. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.d.ts +187 -0
  64. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js +41 -0
  65. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudio.js.map +1 -0
  66. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.d.ts +59 -0
  67. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js +21 -0
  68. package/AudioV2/abstractAudio/subProperties/abstractSpatialAudioListener.js.map +1 -0
  69. package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.d.ts +38 -0
  70. package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.js +18 -0
  71. package/AudioV2/abstractAudio/subProperties/abstractStereoAudio.js.map +1 -0
  72. package/AudioV2/abstractAudio/subProperties/index.d.ts +3 -0
  73. package/AudioV2/abstractAudio/subProperties/index.js +4 -0
  74. package/AudioV2/abstractAudio/subProperties/index.js.map +1 -0
  75. package/AudioV2/abstractAudio/subProperties/spatialAudio.d.ts +49 -0
  76. package/AudioV2/abstractAudio/subProperties/spatialAudio.js +129 -0
  77. package/AudioV2/abstractAudio/subProperties/spatialAudio.js.map +1 -0
  78. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.d.ts +9 -0
  79. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js +22 -0
  80. package/AudioV2/abstractAudio/subProperties/spatialAudioListener.js.map +1 -0
  81. package/AudioV2/abstractAudio/subProperties/stereoAudio.d.ts +11 -0
  82. package/AudioV2/abstractAudio/subProperties/stereoAudio.js +18 -0
  83. package/AudioV2/abstractAudio/subProperties/stereoAudio.js.map +1 -0
  84. package/AudioV2/audioUtils.d.ts +3 -0
  85. package/AudioV2/audioUtils.js +6 -0
  86. package/AudioV2/audioUtils.js.map +1 -0
  87. package/AudioV2/index.d.ts +3 -0
  88. package/AudioV2/index.js +5 -0
  89. package/AudioV2/index.js.map +1 -0
  90. package/AudioV2/soundState.d.ts +29 -0
  91. package/AudioV2/soundState.js +31 -0
  92. package/AudioV2/soundState.js.map +1 -0
  93. package/AudioV2/webAudio/index.d.ts +5 -0
  94. package/AudioV2/webAudio/index.js +6 -0
  95. package/AudioV2/webAudio/index.js.map +1 -0
  96. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.d.ts +59 -0
  97. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js +156 -0
  98. package/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.js.map +1 -0
  99. package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.d.ts +24 -0
  100. package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.js +55 -0
  101. package/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.js.map +1 -0
  102. package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.d.ts +24 -0
  103. package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.js +55 -0
  104. package/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.js.map +1 -0
  105. package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.d.ts +26 -0
  106. package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.js +54 -0
  107. package/AudioV2/webAudio/subNodes/webAudioBaseSubGraph.js.map +1 -0
  108. package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.d.ts +21 -0
  109. package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.js +112 -0
  110. package/AudioV2/webAudio/subNodes/webAudioBusAndSoundSubGraph.js.map +1 -0
  111. package/AudioV2/webAudio/subProperties/spatialWebAudio.d.ts +10 -0
  112. package/AudioV2/webAudio/subProperties/spatialWebAudio.js +26 -0
  113. package/AudioV2/webAudio/subProperties/spatialWebAudio.js.map +1 -0
  114. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.d.ts +4 -0
  115. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js +108 -0
  116. package/AudioV2/webAudio/subProperties/spatialWebAudioListener.js.map +1 -0
  117. package/AudioV2/webAudio/webAudioBus.d.ts +35 -0
  118. package/AudioV2/webAudio/webAudioBus.js +63 -0
  119. package/AudioV2/webAudio/webAudioBus.js.map +1 -0
  120. package/AudioV2/webAudio/webAudioEngine.d.ts +110 -0
  121. package/AudioV2/webAudio/webAudioEngine.js +227 -0
  122. package/AudioV2/webAudio/webAudioEngine.js.map +1 -0
  123. package/AudioV2/webAudio/webAudioMainBus.d.ts +29 -0
  124. package/AudioV2/webAudio/webAudioMainBus.js +64 -0
  125. package/AudioV2/webAudio/webAudioMainBus.js.map +1 -0
  126. package/AudioV2/webAudio/webAudioMainOut.d.ts +20 -0
  127. package/AudioV2/webAudio/webAudioMainOut.js +35 -0
  128. package/AudioV2/webAudio/webAudioMainOut.js.map +1 -0
  129. package/AudioV2/webAudio/webAudioNode.d.ts +24 -0
  130. package/AudioV2/webAudio/webAudioNode.js +2 -0
  131. package/AudioV2/webAudio/webAudioNode.js.map +1 -0
  132. package/AudioV2/webAudio/webAudioStaticSound.d.ts +106 -0
  133. package/AudioV2/webAudio/webAudioStaticSound.js +368 -0
  134. package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -0
  135. package/AudioV2/webAudio/webAudioStreamingSound.d.ts +94 -0
  136. package/AudioV2/webAudio/webAudioStreamingSound.js +358 -0
  137. package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -0
  138. package/Engines/abstractEngine.d.ts +4 -0
  139. package/Engines/abstractEngine.js +4 -2
  140. package/Engines/abstractEngine.js.map +1 -1
  141. package/Engines/engine.common.js +0 -4
  142. package/Engines/engine.common.js.map +1 -1
  143. package/Engines/engine.d.ts +0 -1
  144. package/Engines/engine.js +0 -1
  145. package/Engines/engine.js.map +1 -1
  146. package/Lights/Shadows/cascadedShadowGenerator.js +33 -20
  147. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  148. package/Materials/Textures/hdrCubeTexture.js +4 -1
  149. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  150. package/Meshes/geometry.js +7 -15
  151. package/Meshes/geometry.js.map +1 -1
  152. package/Shaders/ShadersInclude/shadowMapFragment.js +1 -0
  153. package/Shaders/ShadersInclude/shadowMapFragment.js.map +1 -1
  154. package/Shaders/iblCdfDebug.fragment.js +2 -2
  155. package/Shaders/iblCdfDebug.fragment.js.map +1 -1
  156. package/ShadersWGSL/ShadersInclude/shadowMapFragment.js +1 -0
  157. package/ShadersWGSL/ShadersInclude/shadowMapFragment.js.map +1 -1
  158. package/ShadersWGSL/iblCdfDebug.fragment.js +2 -2
  159. package/ShadersWGSL/iblCdfDebug.fragment.js.map +1 -1
  160. package/index.d.ts +1 -0
  161. package/index.js +1 -0
  162. package/index.js.map +1 -1
  163. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ const Instances = [];
2
+ /**
3
+ * Gets the most recently created v2 audio engine.
4
+ * @returns The most recently created v2 audio engine.
5
+ */
6
+ export function LastCreatedAudioEngine() {
7
+ if (Instances.length === 0) {
8
+ return null;
9
+ }
10
+ return Instances[Instances.length - 1];
11
+ }
12
+ /**
13
+ * Abstract base class for v2 audio engines.
14
+ *
15
+ * A v2 audio engine based on the WebAudio API can be created with the {@link CreateAudioEngineAsync} function.
16
+ */
17
+ export class AudioEngineV2 {
18
+ constructor(options) {
19
+ /** Not owned, but all items should be in `_nodes` container, too, which is owned. */
20
+ this._mainBuses = new Set();
21
+ /** Owned top-level sound and bus nodes. */
22
+ this._nodes = new Set();
23
+ this._defaultMainBus = null;
24
+ this._listenerAutoUpdate = true;
25
+ Instances.push(this);
26
+ if (typeof options.listenerAutoUpdate === "boolean") {
27
+ this._listenerAutoUpdate = options.listenerAutoUpdate;
28
+ }
29
+ }
30
+ /**
31
+ * The default main bus that will be used for audio buses and sounds if their `outBus` option is not set.
32
+ * @see {@link IAudioBusOptions.outBus}
33
+ * @see {@link IAbstractSoundOptions.outBus}
34
+ */
35
+ get defaultMainBus() {
36
+ if (this._mainBuses.size === 0) {
37
+ return null;
38
+ }
39
+ if (!this._defaultMainBus) {
40
+ this._defaultMainBus = Array.from(this._mainBuses)[0];
41
+ }
42
+ return this._defaultMainBus;
43
+ }
44
+ /**
45
+ * Releases associated resources.
46
+ */
47
+ dispose() {
48
+ if (Instances.includes(this)) {
49
+ Instances.splice(Instances.indexOf(this), 1);
50
+ }
51
+ const nodeIt = this._nodes.values();
52
+ for (let next = nodeIt.next(); !next.done; next = nodeIt.next()) {
53
+ next.value.dispose();
54
+ }
55
+ this._mainBuses.clear();
56
+ this._nodes.clear();
57
+ this._defaultMainBus = null;
58
+ }
59
+ /**
60
+ * Unlocks the audio engine if it is locked.
61
+ * - Note that the returned promise may already be resolved if the audio engine is already unlocked.
62
+ * @returns A promise that is resolved when the audio engine is unlocked.
63
+ */
64
+ unlock() {
65
+ return this.resume();
66
+ }
67
+ _addMainBus(mainBus) {
68
+ this._mainBuses.add(mainBus);
69
+ this._addNode(mainBus);
70
+ }
71
+ _removeMainBus(mainBus) {
72
+ this._mainBuses.delete(mainBus);
73
+ this._defaultMainBus = null;
74
+ this._removeNode(mainBus);
75
+ }
76
+ _addNode(node) {
77
+ this._nodes.add(node);
78
+ }
79
+ _removeNode(node) {
80
+ this._nodes.delete(node);
81
+ }
82
+ }
83
+ /**
84
+ * @internal
85
+ * @param engine - The given audio engine. If `null` then the last created audio engine is used.
86
+ * @returns the given audio engine or the last created audio engine.
87
+ * @throws An error if the resulting engine is `null`.
88
+ */
89
+ export function _GetAudioEngine(engine) {
90
+ if (!engine) {
91
+ engine = LastCreatedAudioEngine();
92
+ }
93
+ if (engine) {
94
+ return engine;
95
+ }
96
+ throw new Error("No audio engine.");
97
+ }
98
+ /**
99
+ * Creates a new audio bus.
100
+ * @param name - The name of the audio bus.
101
+ * @param options - The options to use when creating the audio bus.
102
+ * @param engine - The audio engine.
103
+ * @returns A promise that resolves with the created audio bus.
104
+ */
105
+ export function CreateAudioBusAsync(name, options = {}, engine = null) {
106
+ engine = _GetAudioEngine(engine);
107
+ return engine.createBusAsync(name, options);
108
+ }
109
+ /**
110
+ * Creates a new main audio bus.
111
+ * @param name - The name of the main audio bus.
112
+ * @param options - The options to use when creating the main audio bus.
113
+ * @param engine - The audio engine.
114
+ * @returns A promise that resolves with the created main audio bus.
115
+ */
116
+ export function CreateMainAudioBusAsync(name, options = {}, engine = null) {
117
+ engine = _GetAudioEngine(engine);
118
+ return engine.createMainBusAsync(name, options);
119
+ }
120
+ /**
121
+ * Creates a new static sound.
122
+ * @param name - The name of the sound.
123
+ * @param source - The source of the sound.
124
+ * @param options - The options for the static sound.
125
+ * @param engine - The audio engine.
126
+ * @returns A promise that resolves to the created static sound.
127
+ */
128
+ export function CreateSoundAsync(name, source, options = {}, engine = null) {
129
+ engine = _GetAudioEngine(engine);
130
+ return engine.createSoundAsync(name, source, options);
131
+ }
132
+ /**
133
+ * Creates a new static sound buffer.
134
+ * @param source - The source of the sound buffer.
135
+ * @param options - The options for the static sound buffer.
136
+ * @param engine - The audio engine.
137
+ * @returns A promise that resolves to the created static sound buffer.
138
+ */
139
+ export async function CreateSoundBufferAsync(source, options = {}, engine = null) {
140
+ engine = _GetAudioEngine(engine);
141
+ return engine.createSoundBufferAsync(source, options);
142
+ }
143
+ /**
144
+ * Creates a new streaming sound.
145
+ * @param name - The name of the sound.
146
+ * @param source - The source of the sound.
147
+ * @param options - The options for the streaming sound.
148
+ * @param engine - The audio engine.
149
+ * @returns A promise that resolves to the created streaming sound.
150
+ */
151
+ export function CreateStreamingSoundAsync(name, source, options = {}, engine = null) {
152
+ engine = _GetAudioEngine(engine);
153
+ return engine.createStreamingSoundAsync(name, source, options);
154
+ }
155
+ //# sourceMappingURL=audioEngineV2.js.map
@@ -0,0 +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,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAA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,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"]}
@@ -0,0 +1,10 @@
1
+ export * from "./abstractAudioBus";
2
+ export * from "./abstractAudioNode";
3
+ export * from "./abstractSound";
4
+ export * from "./audioBus";
5
+ export * from "./audioEngineV2";
6
+ export * from "./mainAudioBus";
7
+ export * from "./staticSound";
8
+ export * from "./staticSoundBuffer";
9
+ export * from "./streamingSound";
10
+ export * from "./subProperties/index";
@@ -0,0 +1,12 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ export * from "./abstractAudioBus.js";
3
+ export * from "./abstractAudioNode.js";
4
+ export * from "./abstractSound.js";
5
+ export * from "./audioBus.js";
6
+ export * from "./audioEngineV2.js";
7
+ export * from "./mainAudioBus.js";
8
+ export * from "./staticSound.js";
9
+ export * from "./staticSoundBuffer.js";
10
+ export * from "./streamingSound.js";
11
+ export * from "./subProperties/index.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nexport * from \"./abstractAudioBus\";\nexport * from \"./abstractAudioNode\";\nexport * from \"./abstractSound\";\nexport * from \"./audioBus\";\nexport * from \"./audioEngineV2\";\nexport * from \"./mainAudioBus\";\nexport * from \"./staticSound\";\nexport * from \"./staticSoundBuffer\";\nexport * from \"./streamingSound\";\nexport * from \"./subProperties/index\";\n"]}
@@ -0,0 +1,22 @@
1
+ import { AbstractAudioBus } from "./abstractAudioBus";
2
+ import type { AudioEngineV2 } from "./audioEngineV2";
3
+ import type { IVolumeAudioOptions } from "./subNodes/volumeAudioSubNode";
4
+ /**
5
+ * Options for creating a main audio bus.
6
+ */
7
+ export interface IMainAudioBusOptions extends IVolumeAudioOptions {
8
+ }
9
+ /**
10
+ * Abstract class representing a main audio bus.
11
+ *
12
+ * Main audio buses are the last bus in the audio graph.
13
+ *
14
+ * Unlike {@link AudioBus} instances, `MainAudioBus` instances have no spatial audio and stereo output capabilities,
15
+ * and they cannot be connected downstream to another audio bus. They only connect downstream to the audio engine's
16
+ * main output.
17
+ *
18
+ * Main audio buses are created by the {@link CreateMainAudioBusAsync} function.
19
+ */
20
+ export declare abstract class MainAudioBus extends AbstractAudioBus {
21
+ protected constructor(name: string, engine: AudioEngineV2);
22
+ }
@@ -0,0 +1,18 @@
1
+ import { AbstractAudioBus } from "./abstractAudioBus.js";
2
+ /**
3
+ * Abstract class representing a main audio bus.
4
+ *
5
+ * Main audio buses are the last bus in the audio graph.
6
+ *
7
+ * Unlike {@link AudioBus} instances, `MainAudioBus` instances have no spatial audio and stereo output capabilities,
8
+ * and they cannot be connected downstream to another audio bus. They only connect downstream to the audio engine's
9
+ * main output.
10
+ *
11
+ * Main audio buses are created by the {@link CreateMainAudioBusAsync} function.
12
+ */
13
+ export class MainAudioBus extends AbstractAudioBus {
14
+ constructor(name, engine) {
15
+ super(name, engine);
16
+ }
17
+ }
18
+ //# sourceMappingURL=mainAudioBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mainAudioBus.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/mainAudioBus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,YAAa,SAAQ,gBAAgB;IACvD,YAAsB,IAAY,EAAE,MAAqB;QACrD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;CACJ","sourcesContent":["import { AbstractAudioBus } from \"./abstractAudioBus\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\nimport type { IVolumeAudioOptions } from \"./subNodes/volumeAudioSubNode\";\n\n/**\n * Options for creating a main audio bus.\n */\nexport interface IMainAudioBusOptions extends IVolumeAudioOptions {}\n\n/**\n * Abstract class representing a main audio bus.\n *\n * Main audio buses are the last bus in the audio graph.\n *\n * Unlike {@link AudioBus} instances, `MainAudioBus` instances have no spatial audio and stereo output capabilities,\n * and they cannot be connected downstream to another audio bus. They only connect downstream to the audio engine's\n * main output.\n *\n * Main audio buses are created by the {@link CreateMainAudioBusAsync} function.\n */\nexport abstract class MainAudioBus extends AbstractAudioBus {\n protected constructor(name: string, engine: AudioEngineV2) {\n super(name, engine);\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { AbstractAudioNode } from "./abstractAudioNode";
2
+ import type { AudioEngineV2 } from "./audioEngineV2";
3
+ /**
4
+ * Abstract class for the main audio output node.
5
+ *
6
+ * A main audio output is the last audio node in the audio graph before the audio is sent to the speakers.
7
+ *
8
+ * @see {@link AudioEngineV2.mainOut}
9
+ * @internal
10
+ */
11
+ export declare abstract class _MainAudioOut extends AbstractAudioNode {
12
+ protected constructor(engine: AudioEngineV2);
13
+ }
@@ -0,0 +1,15 @@
1
+ import { AbstractAudioNode } from "./abstractAudioNode.js";
2
+ /**
3
+ * Abstract class for the main audio output node.
4
+ *
5
+ * A main audio output is the last audio node in the audio graph before the audio is sent to the speakers.
6
+ *
7
+ * @see {@link AudioEngineV2.mainOut}
8
+ * @internal
9
+ */
10
+ export class _MainAudioOut extends AbstractAudioNode {
11
+ constructor(engine) {
12
+ super(engine, 1 /* AudioNodeType.HAS_INPUTS */);
13
+ }
14
+ }
15
+ //# sourceMappingURL=mainAudioOut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mainAudioOut.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/mainAudioOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGvE;;;;;;;GAOG;AACH,MAAM,OAAgB,aAAc,SAAQ,iBAAiB;IACzD,YAAsB,MAAqB;QACvC,KAAK,CAAC,MAAM,mCAA2B,CAAC;IAC5C,CAAC;CACJ","sourcesContent":["import { AudioNodeType, AbstractAudioNode } from \"./abstractAudioNode\";\nimport type { AudioEngineV2 } from \"./audioEngineV2\";\n\n/**\n * Abstract class for the main audio output node.\n *\n * A main audio output is the last audio node in the audio graph before the audio is sent to the speakers.\n *\n * @see {@link AudioEngineV2.mainOut}\n * @internal\n */\nexport abstract class _MainAudioOut extends AbstractAudioNode {\n protected constructor(engine: AudioEngineV2) {\n super(engine, AudioNodeType.HAS_INPUTS);\n }\n}\n"]}
@@ -0,0 +1,134 @@
1
+ import type { IAbstractSoundOptions, IAbstractSoundPlayOptions, IAbstractSoundStoredOptions } from "./abstractSound";
2
+ import { AbstractSound } from "./abstractSound";
3
+ import type { AudioEngineV2 } from "./audioEngineV2";
4
+ import type { IStaticSoundBufferOptions, StaticSoundBuffer } from "./staticSoundBuffer";
5
+ import type { _StaticSoundInstance } from "./staticSoundInstance";
6
+ /** @internal */
7
+ export interface IStaticSoundOptionsBase {
8
+ /**
9
+ * The amount of time to play the sound for, in seconds. Defaults to `0`.
10
+ * - If less than or equal to `0`, the sound plays for its full duration.
11
+ */
12
+ duration: number;
13
+ /**
14
+ * The end of the loop range in seconds. Defaults to `0`.
15
+ * - If less than or equal to `0`, the loop plays for the sound's full duration.
16
+ * - Has no effect if {@link loop} is `false`.
17
+ */
18
+ loopEnd: number;
19
+ /**
20
+ * The start of the loop range in seconds. Defaults to `0`.
21
+ * - If less than or equal to `0`, the loop starts at the beginning of the sound.
22
+ * - Has no effect if {@link loop} is `false`.
23
+ *
24
+ */
25
+ loopStart: number;
26
+ /**
27
+ * The pitch of the sound, in cents. Defaults to `0`.
28
+ * - Can be combined with {@link playbackRate}.
29
+ */
30
+ pitch: number;
31
+ /**
32
+ * The playback rate of the sound. Defaults to `1`.
33
+ * - Can be combined with {@link pitch}.
34
+ */
35
+ playbackRate: number;
36
+ }
37
+ /** @internal */
38
+ export interface IStaticSoundPlayOptionsBase {
39
+ /**
40
+ * The time to wait before playing the sound, in seconds.
41
+ */
42
+ waitTime: number;
43
+ }
44
+ /**
45
+ * Options for creating a static sound.
46
+ */
47
+ export interface IStaticSoundOptions extends IAbstractSoundOptions, IStaticSoundBufferOptions, IStaticSoundStoredOptions {
48
+ }
49
+ /**
50
+ * Options for playing a static sound.
51
+ */
52
+ export interface IStaticSoundPlayOptions extends IAbstractSoundPlayOptions, IStaticSoundOptionsBase, IStaticSoundPlayOptionsBase {
53
+ }
54
+ /**
55
+ * Options for stopping a static sound.
56
+ */
57
+ export interface IStaticSoundStopOptions {
58
+ /**
59
+ * The time to wait before stopping the sound, in seconds.
60
+ */
61
+ waitTime: number;
62
+ }
63
+ /**
64
+ * Options stored in a static sound.
65
+ * @internal
66
+ */
67
+ export interface IStaticSoundStoredOptions extends IAbstractSoundStoredOptions, IStaticSoundOptionsBase {
68
+ }
69
+ /**
70
+ * Abstract class representing a static sound.
71
+ *
72
+ * A static sound has a sound buffer that is loaded into memory all at once. This allows it to have more capabilities
73
+ * than a streaming sound, such as loop points and playback rate changes, but it also means that the sound must be
74
+ * fully downloaded and decoded before it can be played, which may take a long time for sounds with long durations.
75
+ *
76
+ * To prevent downloading and decoding a sound multiple times, a sound's buffer can be shared with other sounds.
77
+ * See {@link CreateSoundBufferAsync}, {@link StaticSoundBuffer} and {@link StaticSound.buffer} for more information.
78
+ *
79
+ * Static sounds are created by the {@link CreateSoundAsync} function.
80
+ */
81
+ export declare abstract class StaticSound extends AbstractSound {
82
+ protected _instances: Set<_StaticSoundInstance>;
83
+ protected abstract readonly _options: IStaticSoundStoredOptions;
84
+ /**
85
+ * The sound buffer that the sound uses.
86
+ *
87
+ * This buffer can be shared with other static sounds.
88
+ */
89
+ abstract readonly buffer: StaticSoundBuffer;
90
+ protected constructor(name: string, engine: AudioEngineV2, options: Partial<IStaticSoundOptions>);
91
+ /**
92
+ * The amount of time to play the sound for, in seconds.
93
+ * - If less than or equal to `0`, the sound plays for its full duration.
94
+ */
95
+ get duration(): number;
96
+ set duration(value: number);
97
+ /**
98
+ * The start of the loop range, in seconds. Defaults to `0`.
99
+ * - If less than or equal to `0`, the loop starts at the beginning of the sound.
100
+ */
101
+ get loopStart(): number;
102
+ set loopStart(value: number);
103
+ /**
104
+ * The end of the loop range, in seconds. Defaults to `0`.
105
+ * - If less than or equal to `0`, the loop plays for the sound's full duration.
106
+ */
107
+ get loopEnd(): number;
108
+ set loopEnd(value: number);
109
+ /**
110
+ * The pitch of the sound, in cents.
111
+ * - Gets combined with {@link playbackRate} to determine the final pitch.
112
+ */
113
+ get pitch(): number;
114
+ set pitch(value: number);
115
+ /**
116
+ * The playback rate of the sound.
117
+ * - Gets combined with {@link pitch} to determine the final playback rate.
118
+ */
119
+ get playbackRate(): number;
120
+ set playbackRate(value: number);
121
+ protected abstract _createInstance(): _StaticSoundInstance;
122
+ /**
123
+ * Plays the sound.
124
+ * - Triggers `onEndedObservable` if played for the full duration and the `loop` option is not set.
125
+ * @param options The options to use when playing the sound. Options set here override the sound's options.
126
+ */
127
+ play(options?: Partial<IStaticSoundPlayOptions>): void;
128
+ /**
129
+ * Stops the sound.
130
+ * - Triggers `onEndedObservable` if the sound is playing.
131
+ * @param options - The options to use when stopping the sound.
132
+ */
133
+ stop(options?: Partial<IStaticSoundStopOptions>): void;
134
+ }
@@ -0,0 +1,113 @@
1
+ import { AbstractSound } from "./abstractSound.js";
2
+ /**
3
+ * Abstract class representing a static sound.
4
+ *
5
+ * A static sound has a sound buffer that is loaded into memory all at once. This allows it to have more capabilities
6
+ * than a streaming sound, such as loop points and playback rate changes, but it also means that the sound must be
7
+ * fully downloaded and decoded before it can be played, which may take a long time for sounds with long durations.
8
+ *
9
+ * To prevent downloading and decoding a sound multiple times, a sound's buffer can be shared with other sounds.
10
+ * See {@link CreateSoundBufferAsync}, {@link StaticSoundBuffer} and {@link StaticSound.buffer} for more information.
11
+ *
12
+ * Static sounds are created by the {@link CreateSoundAsync} function.
13
+ */
14
+ export class StaticSound extends AbstractSound {
15
+ constructor(name, engine, options) {
16
+ super(name, engine, options);
17
+ }
18
+ /**
19
+ * The amount of time to play the sound for, in seconds.
20
+ * - If less than or equal to `0`, the sound plays for its full duration.
21
+ */
22
+ get duration() {
23
+ return this._options.duration;
24
+ }
25
+ set duration(value) {
26
+ this._options.duration = value;
27
+ }
28
+ /**
29
+ * The start of the loop range, in seconds. Defaults to `0`.
30
+ * - If less than or equal to `0`, the loop starts at the beginning of the sound.
31
+ */
32
+ get loopStart() {
33
+ return this._options.loopStart;
34
+ }
35
+ set loopStart(value) {
36
+ this._options.loopStart = value;
37
+ }
38
+ /**
39
+ * The end of the loop range, in seconds. Defaults to `0`.
40
+ * - If less than or equal to `0`, the loop plays for the sound's full duration.
41
+ */
42
+ get loopEnd() {
43
+ return this._options.loopEnd;
44
+ }
45
+ set loopEnd(value) {
46
+ this._options.loopEnd = value;
47
+ }
48
+ /**
49
+ * The pitch of the sound, in cents.
50
+ * - Gets combined with {@link playbackRate} to determine the final pitch.
51
+ */
52
+ get pitch() {
53
+ return this._options.pitch;
54
+ }
55
+ set pitch(value) {
56
+ this._options.pitch = value;
57
+ }
58
+ /**
59
+ * The playback rate of the sound.
60
+ * - Gets combined with {@link pitch} to determine the final playback rate.
61
+ */
62
+ get playbackRate() {
63
+ return this._options.playbackRate;
64
+ }
65
+ set playbackRate(value) {
66
+ this._options.playbackRate = value;
67
+ }
68
+ /**
69
+ * Plays the sound.
70
+ * - Triggers `onEndedObservable` if played for the full duration and the `loop` option is not set.
71
+ * @param options The options to use when playing the sound. Options set here override the sound's options.
72
+ */
73
+ play(options = {}) {
74
+ if (this.state === 5 /* SoundState.Paused */) {
75
+ this.resume();
76
+ return;
77
+ }
78
+ options.duration ?? (options.duration = this.duration);
79
+ options.loop ?? (options.loop = this.loop);
80
+ options.loopStart ?? (options.loopStart = this.loopStart);
81
+ options.loopEnd ?? (options.loopEnd = this.loopEnd);
82
+ options.pitch ?? (options.pitch = this.pitch);
83
+ options.playbackRate ?? (options.playbackRate = this.playbackRate);
84
+ options.startOffset ?? (options.startOffset = this.startOffset);
85
+ options.volume ?? (options.volume = 1);
86
+ options.waitTime ?? (options.waitTime = 0);
87
+ const instance = this._createInstance();
88
+ this._beforePlay(instance);
89
+ instance.play(options);
90
+ this._afterPlay(instance);
91
+ this._stopExcessInstances();
92
+ }
93
+ /**
94
+ * Stops the sound.
95
+ * - Triggers `onEndedObservable` if the sound is playing.
96
+ * @param options - The options to use when stopping the sound.
97
+ */
98
+ stop(options = {}) {
99
+ if (options.waitTime && 0 < options.waitTime) {
100
+ this._setState(0 /* SoundState.Stopping */);
101
+ }
102
+ else {
103
+ this._setState(1 /* SoundState.Stopped */);
104
+ }
105
+ if (!this._instances) {
106
+ return;
107
+ }
108
+ for (const instance of Array.from(this._instances)) {
109
+ instance.stop(options);
110
+ }
111
+ }
112
+ }
113
+ //# sourceMappingURL=staticSound.js.map
@@ -0,0 +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,GAAG,KAAK,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;IACnC,CAAC;IAED,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,CAAC,QAAQ,CAAC,SAAS,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,IAAW,OAAO,CAAC,KAAa;QAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAW,KAAK;QACZ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e,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"]}
@@ -0,0 +1,46 @@
1
+ import type { AudioEngineV2 } from "./audioEngineV2";
2
+ /**
3
+ * Options for creating a static sound buffer.
4
+ */
5
+ export interface IStaticSoundBufferOptions {
6
+ /**
7
+ * Whether to skip codec checking before attempting to load each source URL when `source` is a string array. Defaults to `false`.
8
+ * - Has no effect if the sound's source is not a string array.
9
+ * @see {@link CreateSoundAsync} `source` parameter.
10
+ */
11
+ skipCodecCheck: boolean;
12
+ }
13
+ /**
14
+ * Abstract class representing a static sound buffer.
15
+ *
16
+ * A static sound buffer is a fully downloaded and decoded array of audio data that is ready to be played.
17
+ *
18
+ * Static sound buffers can be reused multiple times by different {@link StaticSound} instances.
19
+ *
20
+ * Static sound buffers are created by the {@link CreateSoundBufferAsync} function.
21
+ *
22
+ * @see {@link StaticSound.buffer}
23
+ */
24
+ export declare abstract class StaticSoundBuffer {
25
+ /**
26
+ * The engine that the sound buffer belongs to.
27
+ */
28
+ readonly engine: AudioEngineV2;
29
+ protected constructor(engine: AudioEngineV2);
30
+ /**
31
+ * The sample rate of the sound buffer.
32
+ */
33
+ abstract readonly sampleRate: number;
34
+ /**
35
+ * The length of the sound buffer, in sample frames.
36
+ */
37
+ abstract readonly length: number;
38
+ /**
39
+ * The duration of the sound buffer, in seconds.
40
+ */
41
+ abstract readonly duration: number;
42
+ /**
43
+ * The number of channels in the sound buffer.
44
+ */
45
+ abstract readonly channelCount: number;
46
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Abstract class representing a static sound buffer.
3
+ *
4
+ * A static sound buffer is a fully downloaded and decoded array of audio data that is ready to be played.
5
+ *
6
+ * Static sound buffers can be reused multiple times by different {@link StaticSound} instances.
7
+ *
8
+ * Static sound buffers are created by the {@link CreateSoundBufferAsync} function.
9
+ *
10
+ * @see {@link StaticSound.buffer}
11
+ */
12
+ export class StaticSoundBuffer {
13
+ constructor(engine) {
14
+ this.engine = engine;
15
+ }
16
+ }
17
+ //# sourceMappingURL=staticSoundBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticSoundBuffer.js","sourceRoot":"","sources":["../../../../../dev/core/src/AudioV2/abstractAudio/staticSoundBuffer.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,iBAAiB;IAMnC,YAAsB,MAAqB;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CAqBJ","sourcesContent":["import type { AudioEngineV2 } from \"./audioEngineV2\";\n\n/**\n * Options for creating a static sound buffer.\n */\nexport interface IStaticSoundBufferOptions {\n /**\n * Whether to skip codec checking before attempting to load each source URL when `source` is a string array. Defaults to `false`.\n * - Has no effect if the sound's source is not a string array.\n * @see {@link CreateSoundAsync} `source` parameter.\n */\n skipCodecCheck: boolean;\n}\n\n/**\n * Abstract class representing a static sound buffer.\n *\n * A static sound buffer is a fully downloaded and decoded array of audio data that is ready to be played.\n *\n * Static sound buffers can be reused multiple times by different {@link StaticSound} instances.\n *\n * Static sound buffers are created by the {@link CreateSoundBufferAsync} function.\n *\n * @see {@link StaticSound.buffer}\n */\nexport abstract class StaticSoundBuffer {\n /**\n * The engine that the sound buffer belongs to.\n */\n public readonly engine: AudioEngineV2;\n\n protected constructor(engine: AudioEngineV2) {\n this.engine = engine;\n }\n\n /**\n * The sample rate of the sound buffer.\n */\n public abstract readonly sampleRate: number;\n\n /**\n * The length of the sound buffer, in sample frames.\n */\n public abstract readonly length: number;\n\n /**\n * The duration of the sound buffer, in seconds.\n */\n public abstract readonly duration: number;\n\n /**\n * The number of channels in the sound buffer.\n */\n public abstract readonly channelCount: number;\n}\n"]}