@driftengine/audio 3.61.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 (88) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +11 -0
  4. package/dist/ambientLoop.d.ts +45 -0
  5. package/dist/ambientLoop.js +88 -0
  6. package/dist/audioHarness.d.ts +180 -0
  7. package/dist/audioHarness.js +244 -0
  8. package/dist/filters.d.ts +91 -0
  9. package/dist/filters.js +103 -0
  10. package/dist/formats.d.ts +18 -0
  11. package/dist/formats.js +19 -0
  12. package/dist/graph.d.ts +406 -0
  13. package/dist/graph.js +656 -0
  14. package/dist/index.d.ts +47 -0
  15. package/dist/index.js +39 -0
  16. package/dist/manifest.d.ts +28 -0
  17. package/dist/manifest.js +71 -0
  18. package/dist/mix/bus.d.ts +203 -0
  19. package/dist/mix/bus.js +293 -0
  20. package/dist/mix/console.d.ts +96 -0
  21. package/dist/mix/console.js +131 -0
  22. package/dist/mix/defaultLayout.d.ts +37 -0
  23. package/dist/mix/defaultLayout.js +63 -0
  24. package/dist/mix/inserts.d.ts +64 -0
  25. package/dist/mix/inserts.js +187 -0
  26. package/dist/mix/returns.d.ts +38 -0
  27. package/dist/mix/returns.js +86 -0
  28. package/dist/mix/snapshot.d.ts +30 -0
  29. package/dist/mix/snapshot.js +55 -0
  30. package/dist/positional.d.ts +37 -0
  31. package/dist/positional.js +47 -0
  32. package/dist/registry.d.ts +91 -0
  33. package/dist/registry.js +128 -0
  34. package/dist/rhythm/bands.d.ts +60 -0
  35. package/dist/rhythm/bands.js +12 -0
  36. package/dist/rhythm/beatGrid.d.ts +32 -0
  37. package/dist/rhythm/beatGrid.js +98 -0
  38. package/dist/rhythm/beatMap.d.ts +42 -0
  39. package/dist/rhythm/beatMap.js +405 -0
  40. package/dist/rhythm/kickCore.d.ts +79 -0
  41. package/dist/rhythm/kickCore.js +166 -0
  42. package/dist/rhythm/kickDetector.d.ts +65 -0
  43. package/dist/rhythm/kickDetector.js +202 -0
  44. package/dist/rhythm/renderedPulse.d.ts +15 -0
  45. package/dist/rhythm/renderedPulse.js +138 -0
  46. package/dist/session.d.ts +62 -0
  47. package/dist/session.js +83 -0
  48. package/dist/spatial/ambisonic.d.ts +135 -0
  49. package/dist/spatial/ambisonic.js +299 -0
  50. package/dist/spatial/listener.d.ts +109 -0
  51. package/dist/spatial/listener.js +186 -0
  52. package/dist/spatial/occlusion.d.ts +39 -0
  53. package/dist/spatial/occlusion.js +92 -0
  54. package/dist/spatial/source.d.ts +185 -0
  55. package/dist/spatial/source.js +366 -0
  56. package/dist/spatial/zones.d.ts +129 -0
  57. package/dist/spatial/zones.js +166 -0
  58. package/dist/synth.d.ts +92 -0
  59. package/dist/synth.js +282 -0
  60. package/package.json +54 -0
  61. package/src/ambientLoop.ts +101 -0
  62. package/src/audioHarness.ts +280 -0
  63. package/src/filters.ts +109 -0
  64. package/src/formats.ts +22 -0
  65. package/src/graph.ts +805 -0
  66. package/src/index.ts +84 -0
  67. package/src/manifest.ts +73 -0
  68. package/src/mix/bus.ts +356 -0
  69. package/src/mix/console.ts +181 -0
  70. package/src/mix/defaultLayout.ts +118 -0
  71. package/src/mix/inserts.ts +242 -0
  72. package/src/mix/returns.ts +114 -0
  73. package/src/mix/snapshot.ts +75 -0
  74. package/src/positional.ts +47 -0
  75. package/src/registry.ts +167 -0
  76. package/src/rhythm/bands.ts +45 -0
  77. package/src/rhythm/beatGrid.ts +106 -0
  78. package/src/rhythm/beatMap.ts +514 -0
  79. package/src/rhythm/kickCore.ts +197 -0
  80. package/src/rhythm/kickDetector.ts +233 -0
  81. package/src/rhythm/renderedPulse.ts +147 -0
  82. package/src/session.ts +93 -0
  83. package/src/spatial/ambisonic.ts +358 -0
  84. package/src/spatial/listener.ts +249 -0
  85. package/src/spatial/occlusion.ts +95 -0
  86. package/src/spatial/source.ts +452 -0
  87. package/src/spatial/zones.ts +213 -0
  88. package/src/synth.ts +351 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Drift Technologies
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ DriftEngine
2
+ Copyright 2026 Drift Technologies
3
+
4
+ This product includes software developed at Drift Technologies
5
+ (https://github.com/drftrun/driftengine).
6
+
7
+ Licensed under the Apache License, Version 2.0. Section 4(d) of that licence
8
+ requires this NOTICE to be reproduced in any derivative work you distribute,
9
+ in the source, the documentation, or a display generated by the work.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @driftengine/audio
2
+
3
+ Layered stems, synthesis, rhythm and kick detection, distance and stereo placement, HRTF-panned
4
+ sources, reverb zones a **source** can be inside as well as the listener, and first-order
5
+ ambisonic soundfields decoded through six virtual speakers.
6
+
7
+ **Cost: 6.0 KB gzipped on top of core.** Measured by `scripts/size-gate.test.mjs`, which fails if it drifts more than
8
+ 3% — the number is a fact about the build rather than a claim in a document.
9
+
10
+ Part of [DriftEngine](../../README.md). See [`docs/ARCHITECTURE.md`](../../docs/ARCHITECTURE.md)
11
+ for how the packages divide, and why some features are compiled into core on demand instead.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Where "now" comes from, for work this loop schedules.
3
+ *
4
+ * Supplied rather than read off the context, because a *rendered* mix has no
5
+ * "now": an `OfflineAudioContext` holds `currentTime` at zero for as long as the
6
+ * caller is describing the timeline, so a loop reading it directly would stack
7
+ * every level change a clip ever makes onto instant zero and play the last one
8
+ * for the whole file. A fire the character sprints past would sit at its parting
9
+ * distance from the opening frame.
10
+ *
11
+ * The graph that owns the loop already has exactly one answer to this question
12
+ * for exactly this reason; this is how a loop gets to share it.
13
+ */
14
+ export type ScheduleClock = () => number;
15
+ export declare class AmbientLoop {
16
+ private readonly scheduleAt;
17
+ private readonly source;
18
+ private readonly gainNode;
19
+ private readonly panNode;
20
+ private lastGain;
21
+ private lastPan;
22
+ private stopped;
23
+ /**
24
+ * @param scheduleAt the instant this loop's changes land on. See `ScheduleClock`.
25
+ * @param source the looping buffer source, already started.
26
+ * @param gainNode its level, initially silent.
27
+ * @param panNode present only where the browser supports stereo panning.
28
+ */
29
+ constructor(scheduleAt: ScheduleClock, source: AudioBufferSourceNode, gainNode: GainNode, panNode: StereoPannerNode | null);
30
+ private rate;
31
+ /** 0 is silent, 1 is the buffer at its authored level. */
32
+ setGain(gain: number): void;
33
+ /**
34
+ * Pitch the bed, for a loop whose *state* should be audible.
35
+ *
36
+ * Ramped like gain and pan rather than set, because a stepped playback rate
37
+ * on a continuous source is a click. Change-gated by the same rule: a rate
38
+ * written every frame would schedule sixty ramps a second.
39
+ */
40
+ setRate(rate: number): void;
41
+ /** -1 hard left, 0 centre, 1 hard right. A no-op without stereo panning. */
42
+ setPan(pan: number): void;
43
+ stop(): void;
44
+ private ramp;
45
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * A continuous environmental sound: a looping buffer whose level and stereo
3
+ * position are driven every frame by whatever the game decides is nearby.
4
+ *
5
+ * Not a full spatial audio node. A panner per source with an HRTF would be the
6
+ * general answer, but the sources this is for — a fire, a shoreline, wind —
7
+ * are diffuse and often several at once, and what actually communicates them is
8
+ * "how close" and "which side". Those are two numbers, and paying for a panner
9
+ * graph per brazier to produce them would be the expensive way to get the same
10
+ * result.
11
+ *
12
+ * Both setters are change-gated. They are called once per frame, and scheduling
13
+ * an `AudioParam` ramp sixty times a second for a value that has not moved is
14
+ * work the audio thread does not need.
15
+ */
16
+ const RAMP = 0.12;
17
+ /** Below this the ramp is inaudible; above it, skipping the update is not. */
18
+ const EPSILON = 0.004;
19
+ export class AmbientLoop {
20
+ scheduleAt;
21
+ source;
22
+ gainNode;
23
+ panNode;
24
+ lastGain = 0;
25
+ lastPan = 0;
26
+ stopped = false;
27
+ /**
28
+ * @param scheduleAt the instant this loop's changes land on. See `ScheduleClock`.
29
+ * @param source the looping buffer source, already started.
30
+ * @param gainNode its level, initially silent.
31
+ * @param panNode present only where the browser supports stereo panning.
32
+ */
33
+ constructor(scheduleAt, source, gainNode, panNode) {
34
+ this.scheduleAt = scheduleAt;
35
+ this.source = source;
36
+ this.gainNode = gainNode;
37
+ this.panNode = panNode;
38
+ }
39
+ rate = 1;
40
+ /** 0 is silent, 1 is the buffer at its authored level. */
41
+ setGain(gain) {
42
+ const next = Number.isFinite(gain) ? Math.min(Math.max(gain, 0), 1) : 0;
43
+ if (Math.abs(next - this.lastGain) < EPSILON)
44
+ return;
45
+ this.lastGain = next;
46
+ this.ramp(this.gainNode.gain, next);
47
+ }
48
+ /**
49
+ * Pitch the bed, for a loop whose *state* should be audible.
50
+ *
51
+ * Ramped like gain and pan rather than set, because a stepped playback rate
52
+ * on a continuous source is a click. Change-gated by the same rule: a rate
53
+ * written every frame would schedule sixty ramps a second.
54
+ */
55
+ setRate(rate) {
56
+ const next = Math.max(0.05, rate);
57
+ if (Math.abs(next - this.rate) < 0.005)
58
+ return;
59
+ this.rate = next;
60
+ this.ramp(this.source.playbackRate, next);
61
+ }
62
+ /** -1 hard left, 0 centre, 1 hard right. A no-op without stereo panning. */
63
+ setPan(pan) {
64
+ if (this.panNode === null)
65
+ return;
66
+ const next = Number.isFinite(pan) ? Math.min(Math.max(pan, -1), 1) : 0;
67
+ if (Math.abs(next - this.lastPan) < EPSILON)
68
+ return;
69
+ this.lastPan = next;
70
+ this.ramp(this.panNode.pan, next);
71
+ }
72
+ stop() {
73
+ if (this.stopped)
74
+ return;
75
+ this.stopped = true;
76
+ try {
77
+ this.source.stop();
78
+ }
79
+ catch {
80
+ // Never started, or already stopped. Nothing to undo.
81
+ }
82
+ }
83
+ ramp(param, value) {
84
+ const at = this.scheduleAt();
85
+ param.cancelScheduledValues(at);
86
+ param.setTargetAtTime(value, at, RAMP);
87
+ }
88
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * A Web Audio context that answers everything, for tests that need a graph and not a browser.
3
+ *
4
+ * **Not a `.test.ts` file, and that is the point.** Vitest registers a test when the file declaring
5
+ * it is imported, so a test file importing a stub from beside another file's tests would re-run
6
+ * every test in that file too. Split out so importing the harness costs nothing but the harness —
7
+ * the same reasoning, and the same shape, as `rendererHarness.ts` in core.
8
+ *
9
+ * **It exists because there were three of these.** `autoplay.test.ts`, `graph.test.ts` and
10
+ * `mixOutput.test.ts` each carried their own `StubNode` and their own `param()`, and they had
11
+ * already drifted: one recorded what was connected to it and two did not, one had an
12
+ * `fftSize` of 512 and another 2048, one could decode audio and the others could not. `AGENTS.md`'s
13
+ * 2026-08-17 rule is exactly this — two implementations of one decision drift, and they drift
14
+ * invisibly when the constants look identical.
15
+ *
16
+ * **A stub is not a contract and nothing here is tested directly.** What it must do is let the real
17
+ * graph build and let a test read back what the graph did. Where a member exists only so a
18
+ * constructor does not throw, it does nothing and says so.
19
+ */
20
+ /** A parameter that remembers every move asked of it, so a test can ask when a fade was scheduled. */
21
+ export interface StubParam {
22
+ value: number;
23
+ readonly ramps: {
24
+ value: number;
25
+ at: number;
26
+ }[];
27
+ setValueAtTime(value: number, at: number): void;
28
+ linearRampToValueAtTime(value: number, at: number): void;
29
+ cancelScheduledValues(at: number): void;
30
+ setTargetAtTime(value: number, at: number, tc: number): void;
31
+ }
32
+ export declare function stubParam(): StubParam;
33
+ /**
34
+ * A node that remembers what was connected to it. Enough graph to build against.
35
+ *
36
+ * `inputs` is what makes a topology assertable at all: the browser's own graph is write-only, so a
37
+ * test asking "is the send taken from the output or the input" has nowhere else to look.
38
+ */
39
+ export declare class StubNode {
40
+ readonly inputs: StubNode[];
41
+ /** Instants `stop` was asked for, so a test can see whether a fade preceded one. */
42
+ readonly stops: number[];
43
+ /** Instants `start` was asked for, so a test can see an offline launch has no lead. */
44
+ readonly starts: number[];
45
+ type: string;
46
+ buffer: unknown;
47
+ loop: boolean;
48
+ readonly gain: StubParam;
49
+ readonly frequency: StubParam;
50
+ readonly Q: StubParam;
51
+ readonly delayTime: StubParam;
52
+ readonly playbackRate: StubParam;
53
+ readonly pan: StubParam;
54
+ fftSize: number;
55
+ smoothingTimeConstant: number;
56
+ readonly frequencyBinCount = 1024;
57
+ /** A buffer source answers this; the spatial layer drives it for doppler. */
58
+ readonly detune: StubParam;
59
+ /**
60
+ * The channel plumbing a multi-channel source needs.
61
+ *
62
+ * `channelInterpretation` is the one that matters and is the one a test asserts: the default
63
+ * up-mixes or down-mixes by *meaning*, and W, Y, Z, X are not left, right, centre and low
64
+ * frequency, so a field read that way comes out as a blur that still plays.
65
+ */
66
+ channelCount: number;
67
+ channelCountMode: string;
68
+ channelInterpretation: string;
69
+ panningModel: string;
70
+ distanceModel: string;
71
+ refDistance: number;
72
+ maxDistance: number;
73
+ rolloffFactor: number;
74
+ readonly positionX: StubParam;
75
+ readonly positionY: StubParam;
76
+ readonly positionZ: StubParam;
77
+ /**
78
+ * `output` is accepted and ignored, which is enough for what these tests ask.
79
+ *
80
+ * A splitter's outputs go to different nodes, and what a test here checks is *which node* was
81
+ * connected rather than from which output — the coefficient gains are one per (speaker, channel)
82
+ * pair, so the pair is already carried by the node's identity.
83
+ */
84
+ connect(target: StubNode, output?: number): StubNode;
85
+ disconnect(): void;
86
+ start(at?: number): void;
87
+ stop(at?: number): void;
88
+ getByteFrequencyData(): void;
89
+ getFloatFrequencyData(): void;
90
+ }
91
+ /**
92
+ * The listener, in both shapes a browser might offer it.
93
+ *
94
+ * Both are present deliberately, because the code under test picks one and the choice is a feature
95
+ * detection rather than a preference: a test that only had the modern form could not tell whether
96
+ * the legacy branch was ever written. `positions` records the legacy calls so a test can assert
97
+ * which branch ran.
98
+ */
99
+ export declare class StubListener {
100
+ readonly positionX: StubParam;
101
+ readonly positionY: StubParam;
102
+ readonly positionZ: StubParam;
103
+ readonly forwardX: StubParam;
104
+ readonly forwardY: StubParam;
105
+ readonly forwardZ: StubParam;
106
+ readonly upX: StubParam;
107
+ readonly upY: StubParam;
108
+ readonly upZ: StubParam;
109
+ readonly positions: number[][];
110
+ readonly orientations: number[][];
111
+ setPosition(x: number, y: number, z: number): void;
112
+ setOrientation(fx: number, fy: number, fz: number, ux: number, uy: number, uz: number): void;
113
+ }
114
+ export interface StubContextOptions {
115
+ /** `suspended` is a browser that has not been given a gesture yet. */
116
+ readonly state?: string;
117
+ /** A context that refuses to resume, which is what a blocked autoplay policy looks like. */
118
+ readonly refuseResume?: boolean;
119
+ /** Absent on a browser too old for it; `createLoop` falls back rather than skipping the loop. */
120
+ readonly stereoPanner?: boolean;
121
+ /** Absent where the browser has only the deprecated `setPosition`/`setOrientation` pair. */
122
+ readonly listenerParams?: boolean;
123
+ }
124
+ export declare class StubContext {
125
+ private readonly options;
126
+ readonly destination: StubNode;
127
+ /** Every buffer source built, in order, so a test can inspect the transport. */
128
+ readonly sources: StubNode[];
129
+ readonly listener: StubListener;
130
+ /** Every panner built, in order, so a test can inspect what was placed in the world. */
131
+ readonly panners: StubNode[];
132
+ /**
133
+ * Every convolver built, in order.
134
+ *
135
+ * Counted because "a second routing rather than a second convolver" is a claim about how many of
136
+ * them exist, and a convolver is the most expensive node in this graph. A test that asserted the
137
+ * send worked would not notice one being built per source.
138
+ */
139
+ readonly convolvers: StubNode[];
140
+ outputLatency: number;
141
+ readonly tap: StubNode & {
142
+ stream: MediaStream;
143
+ };
144
+ state: string;
145
+ currentTime: number;
146
+ sampleRate: number;
147
+ /** How many times a resume was attempted, for the tests about a context that will not start. */
148
+ resumeCalls: number;
149
+ constructor(options?: StubContextOptions);
150
+ createGain(): StubNode;
151
+ createBiquadFilter(): StubNode;
152
+ createConvolver(): StubNode;
153
+ createWaveShaper(): StubNode;
154
+ createDelay(): StubNode;
155
+ createAnalyser(): StubNode;
156
+ createPanner(): StubNode;
157
+ createBufferSource(): StubNode;
158
+ createStereoPanner(): StubNode;
159
+ createMediaStreamDestination(): StubNode;
160
+ createChannelSplitter(): StubNode;
161
+ createChannelMerger(): StubNode;
162
+ createBuffer(channels: number, length: number): {
163
+ numberOfChannels: number;
164
+ length: number;
165
+ getChannelData(): Float32Array;
166
+ };
167
+ decodeAudioData(): Promise<AudioBuffer>;
168
+ resume(): Promise<void>;
169
+ close(): Promise<void>;
170
+ }
171
+ /** The context most tests want: running, complete, and recording what was done to it. */
172
+ export declare function stubContext(options?: StubContextOptions): StubContext;
173
+ /**
174
+ * Install a stub as the page's `AudioContext` and hand back the one that gets built.
175
+ *
176
+ * The graph constructs its own context through the global, so a test that wants to look at the
177
+ * nodes has to intercept the construction rather than pass one in. Returns a getter rather than
178
+ * the context, because nothing exists until the code under test asks for it.
179
+ */
180
+ export declare function installStubAudioContext(options?: StubContextOptions): () => StubContext | null;