alpha2 0.4.6 → 0.5.1

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 (123) hide show
  1. package/README.md +5 -4
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/dist/abort.d.ts +12 -0
  4. package/dist/abort.js +48 -0
  5. package/dist/active-clock.d.ts +35 -0
  6. package/dist/active-clock.js +99 -0
  7. package/dist/assets.d.ts +51 -22
  8. package/dist/assets.js +8 -12
  9. package/dist/audio-layout.d.ts +52 -74
  10. package/dist/audio-layout.js +114 -148
  11. package/dist/audio-timeline.d.ts +89 -117
  12. package/dist/audio-timeline.js +102 -118
  13. package/dist/audio-worker.d.ts +12 -21
  14. package/dist/audio-worker.js +8 -13
  15. package/dist/audio-worklet-processor.js +45 -58
  16. package/dist/audio-worklet.d.ts +45 -76
  17. package/dist/audio-worklet.js +44 -79
  18. package/dist/audio.d.ts +15 -23
  19. package/dist/audio.js +9 -13
  20. package/dist/builder.d.ts +45 -63
  21. package/dist/builder.js +49 -45
  22. package/dist/capabilities.d.ts +99 -16
  23. package/dist/capabilities.js +2 -2
  24. package/dist/captions.d.ts +45 -22
  25. package/dist/captions.js +60 -15
  26. package/dist/chroma-siting.d.ts +24 -41
  27. package/dist/chroma-siting.js +38 -71
  28. package/dist/containers.d.ts +41 -30
  29. package/dist/containers.js +59 -27
  30. package/dist/decoder-fallback.d.ts +13 -0
  31. package/dist/decoder-fallback.js +38 -0
  32. package/dist/decoder-order.d.ts +24 -39
  33. package/dist/decoder-order.js +28 -42
  34. package/dist/edit.d.ts +77 -154
  35. package/dist/edit.js +98 -180
  36. package/dist/effects.d.ts +125 -176
  37. package/dist/effects.js +7 -9
  38. package/dist/export-destination.d.ts +25 -41
  39. package/dist/export-destination.js +20 -32
  40. package/dist/export-failure.d.ts +34 -59
  41. package/dist/export-failure.js +54 -48
  42. package/dist/export-metrics.d.ts +116 -0
  43. package/dist/export-metrics.js +74 -0
  44. package/dist/export-retry.d.ts +46 -29
  45. package/dist/export-retry.js +86 -51
  46. package/dist/exporter.d.ts +67 -116
  47. package/dist/exporter.js +133 -133
  48. package/dist/extensions.d.ts +69 -115
  49. package/dist/extensions.js +55 -82
  50. package/dist/frame-intake.d.ts +92 -0
  51. package/dist/frame-intake.js +114 -0
  52. package/dist/frame-supply.d.ts +96 -162
  53. package/dist/frame-supply.js +181 -171
  54. package/dist/frames.d.ts +23 -0
  55. package/dist/frames.js +34 -0
  56. package/dist/generated/project-schema.d.ts +712 -485
  57. package/dist/generated/project-schema.js +55 -2
  58. package/dist/generated/project-shape.js +276 -16
  59. package/dist/geometry.d.ts +28 -34
  60. package/dist/geometry.js +18 -23
  61. package/dist/gpu-recovery.d.ts +92 -0
  62. package/dist/gpu-recovery.js +135 -0
  63. package/dist/hdr-frames.d.ts +82 -67
  64. package/dist/hdr-frames.js +112 -49
  65. package/dist/index.d.ts +6 -0
  66. package/dist/index.js +6 -0
  67. package/dist/json-text.d.ts +13 -23
  68. package/dist/json-text.js +10 -20
  69. package/dist/layout-values.d.ts +14 -22
  70. package/dist/layout-values.js +18 -21
  71. package/dist/layout.d.ts +48 -63
  72. package/dist/layout.js +37 -37
  73. package/dist/loudness.d.ts +27 -32
  74. package/dist/loudness.js +19 -23
  75. package/dist/media.d.ts +85 -237
  76. package/dist/media.js +133 -287
  77. package/dist/mediabunny.d.ts +178 -246
  78. package/dist/mediabunny.js +781 -583
  79. package/dist/paint.d.ts +23 -0
  80. package/dist/paint.js +37 -0
  81. package/dist/physical-frames.d.ts +5 -17
  82. package/dist/physical-frames.js +4 -11
  83. package/dist/player.d.ts +56 -47
  84. package/dist/player.js +155 -40
  85. package/dist/presented-frames.d.ts +2 -7
  86. package/dist/presented-frames.js +3 -8
  87. package/dist/project.d.ts +74 -118
  88. package/dist/project.js +384 -445
  89. package/dist/rate-control.d.ts +9 -23
  90. package/dist/rate-control.js +7 -18
  91. package/dist/renderer-choice.d.ts +41 -0
  92. package/dist/renderer-choice.js +82 -0
  93. package/dist/repacked-bytes.d.ts +0 -2
  94. package/dist/repacked-bytes.js +2 -5
  95. package/dist/robustness.d.ts +25 -37
  96. package/dist/robustness.js +71 -54
  97. package/dist/sha256.d.ts +5 -13
  98. package/dist/sha256.js +9 -24
  99. package/dist/text.d.ts +97 -71
  100. package/dist/text.js +33 -70
  101. package/dist/video-frames.d.ts +7 -25
  102. package/dist/video-frames.js +12 -29
  103. package/dist/waveform.d.ts +5 -11
  104. package/dist/waveform.js +4 -9
  105. package/dist/worker-error.d.ts +5 -20
  106. package/dist/worker-error.js +8 -25
  107. package/dist/worker.d.ts +82 -95
  108. package/dist/worker.js +235 -143
  109. package/package.json +26 -2
  110. package/wasm/alpha2_audio_worklet.wasm +0 -0
  111. package/wasm/alpha2_extensions.d.ts +26 -47
  112. package/wasm/alpha2_extensions.js +26 -47
  113. package/wasm/alpha2_extensions_bg.wasm +0 -0
  114. package/wasm/alpha2_wasm.d.ts +501 -587
  115. package/wasm/alpha2_wasm.js +661 -616
  116. package/wasm/alpha2_wasm_bg.wasm +0 -0
  117. package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
  118. package/wasm/rust-crate-licenses.md +2 -2
  119. package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
  120. package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
  121. package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
  122. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
  123. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
@@ -1,11 +1,9 @@
1
- /** The most frames the DSP module processes in one call (`MAX_FRAMES` in its source). */
1
+ /** Must match `MAX_FRAMES` in the DSP module. */
2
2
  const MODULE_MAX_FRAMES = 4096;
3
- /** The render quantum of every context that cannot choose another. */
4
3
  const DEFAULT_QUANTUM = 128;
5
4
  /**
6
- * Frames per module call: the scope's render quantum where it says one the module can take whole,
7
- * so a quantum is one call, and the default quantum otherwise. `process` splits any longer quantum
8
- * into calls of this size.
5
+ * Frames per module call: the scope's render quantum when the module can take it whole, else the
6
+ * default quantum. `process` splits longer quanta into calls of this size.
9
7
  */
10
8
  function moduleFrames() {
11
9
  const quantum = globalThis
@@ -17,7 +15,7 @@ function moduleFrames() {
17
15
  ? quantum
18
16
  : DEFAULT_QUANTUM;
19
17
  }
20
- /** UTF-8 to a string without `TextDecoder`, which worklet scopes lack. */
18
+ /** Worklet scopes lack `TextDecoder`. */
21
19
  function decodeUtf8(bytes) {
22
20
  let text = "";
23
21
  for (let index = 0; index < bytes.length;) {
@@ -32,11 +30,8 @@ function decodeUtf8(bytes) {
32
30
  return text;
33
31
  }
34
32
  /**
35
- * Reader half of the package's shared audio ring.
36
- *
37
- * The index arithmetic is inlined here because a worklet module cannot rely on bundler-resolved
38
- * imports. `AudioRingBuffer` in `alpha2/audio-timeline` is the writer half and the tested reference
39
- * for this layout.
33
+ * Reader half of the shared audio ring. Inlined because a worklet module cannot rely on bundler
34
+ * imports; `AudioRingBuffer` in `alpha2/audio-timeline` is the writer and the tested reference.
40
35
  */
41
36
  class RingReader {
42
37
  #control;
@@ -54,8 +49,8 @@ class RingReader {
54
49
  }
55
50
  }
56
51
  /**
57
- * Fills the first `frames` samples of each target channel and returns how many real samples were
58
- * produced. Channels fold as `#readInput` describes.
52
+ * Fills `frames` samples of each target and returns how many came from the ring. Channels fold
53
+ * as in `#readInput`.
59
54
  */
60
55
  read(targets, frames) {
61
56
  // Slots: 0 read, 1 write, 2 clear target, 3 clear epoch, 4 cleared epoch. A clear is the
@@ -96,7 +91,6 @@ class RingReader {
96
91
  return produced;
97
92
  }
98
93
  }
99
- /** No input connected: WebAudio passes no channels. */
100
94
  const NO_CHANNELS = Object.freeze([]);
101
95
  class Alpha2Processor extends AudioWorkletProcessor {
102
96
  #exports;
@@ -107,16 +101,17 @@ class Alpha2Processor extends AudioWorkletProcessor {
107
101
  #channels = 0;
108
102
  #ring;
109
103
  #underruns = 0;
104
+ #firstReadReported = false;
110
105
  #shapeReported = false;
111
106
  #views = [];
112
107
  // Once set, `process` returns false so the audio thread retires the node.
113
108
  #disposed = false;
114
- // The master chain is the identity, so the input is copied straight through without the module.
109
+ // The master chain is the identity, so input bypasses the module.
115
110
  #transparent = false;
116
- // The samples the master chain delays its input by, as last posted to the host.
111
+ // Latency in samples as last posted to the host.
117
112
  #latency = 0;
118
- // Where the module takes ring samples at the project's rate to convert to the context's, and
119
- // their per-channel stride; 0 when the ring carries the context's rate.
113
+ // Module buffer for project-rate ring samples and its per-channel stride; 0 when no rate
114
+ // conversion is needed.
120
115
  #sourcePointer = 0;
121
116
  #sourceFrames = 0;
122
117
  #sourceViews;
@@ -143,9 +138,8 @@ class Alpha2Processor extends AudioWorkletProcessor {
143
138
  catch (thrown) {
144
139
  error = thrown instanceof Error ? thrown.message : String(thrown);
145
140
  }
146
- // The answer follows everything applying the request posted (`alpha2-latency` included), so
147
- // the host knows the outcome before the next quantum resolves. Without an id, a refusal is
148
- // an error.
141
+ // Posted after any `alpha2-latency` the request caused. Without an id, a refusal is an
142
+ // error.
149
143
  if (message.id !== undefined)
150
144
  this.port.postMessage(error === undefined
151
145
  ? { type: "alpha2-applied", id: message.id }
@@ -156,10 +150,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
156
150
  };
157
151
  this.port.postMessage({ type: "alpha2-stage", stage: "processor-created" });
158
152
  }
159
- /**
160
- * Starts the module for `channels` at the context's rate. A ring carrying `sourceRate` (the
161
- * project's) is converted to the context's rate when the two differ.
162
- */
153
+ /** Starts the module; a ring at another `sourceRate` is converted to the context's rate. */
163
154
  async #initialize(wasm, channels, sourceRate) {
164
155
  try {
165
156
  this.port.postMessage({
@@ -167,7 +158,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
167
158
  stage: "wasm-instantiating",
168
159
  });
169
160
  const instance = (await WebAssembly.instantiate(wasm, {})).instance;
170
- // Disposed while the module compiled: it never gets an instance to leak.
161
+ // Disposed during compilation.
171
162
  if (this.#disposed)
172
163
  return;
173
164
  this.port.postMessage({
@@ -217,24 +208,20 @@ class Alpha2Processor extends AudioWorkletProcessor {
217
208
  this.#views = [];
218
209
  this.#sourceViews = undefined;
219
210
  }
220
- /** The message the module recorded for its last panic, if any. */
221
211
  #panicMessage(exports) {
222
212
  const length = exports.alpha2_worklet_panic_length();
223
213
  if (length === 0)
224
214
  return undefined;
225
215
  return decodeUtf8(new Uint8Array(exports.memory.buffer, exports.alpha2_worklet_panic_message(), length));
226
216
  }
227
- /**
228
- * Applies a ring, master-chain or reset message. Returns why it could not, or undefined once it
229
- * is in place.
230
- */
217
+ /** Applies a ring, master-chain or reset message. Returns an error message on failure. */
231
218
  #apply(message) {
232
219
  if (message.type === "alpha2-ring") {
233
- // Without a ring the node processes whatever WebAudio feeds its input.
220
+ // Without a ring the node processes its WebAudio input.
234
221
  this.#ring =
235
222
  message.ring === undefined ? undefined : new RingReader(message.ring);
236
223
  this.#underruns = 0;
237
- // The conversion delays only what comes through the ring.
224
+ // Rate conversion latency applies only to ring input.
238
225
  this.#reportLatency();
239
226
  return undefined;
240
227
  }
@@ -248,7 +235,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
248
235
  this.#refreshTransparency();
249
236
  return undefined;
250
237
  }
251
- /** Installs a master-chain record. Returns the module's verdict: why it refused, if it did. */
238
+ /** Installs a master-chain record. Returns an error message when the module refuses it. */
252
239
  #configure(config) {
253
240
  const exports = this.#exports;
254
241
  if (exports === undefined || this.#handle === 0)
@@ -265,10 +252,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
265
252
  ? undefined
266
253
  : `master configuration was rejected (${result})`;
267
254
  }
268
- /**
269
- * Posts `alpha2-latency` when the master chain's delay changed: the host's clock subtracts it, as
270
- * the sound comes out that much after the samples the processor took.
271
- */
255
+ /** Posts `alpha2-latency` when the delay changed; the host's clock subtracts it. */
272
256
  #reportLatency() {
273
257
  const exports = this.#exports;
274
258
  if (exports === undefined || this.#handle === 0)
@@ -289,7 +273,6 @@ class Alpha2Processor extends AudioWorkletProcessor {
289
273
  this.#handle !== 0 &&
290
274
  exports.alpha2_worklet_transparent(this.#handle) === 1;
291
275
  }
292
- /** The cached channel views, remade when memory grew or `frames` changed. */
293
276
  #viewsFor(exports, frames) {
294
277
  const buffer = exports.memory.buffer;
295
278
  for (const views of this.#views) {
@@ -304,7 +287,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
304
287
  input: indices.map((index) => channel(this.#inputPointer, index)),
305
288
  output: indices.map((index) => channel(this.#outputPointer, index)),
306
289
  };
307
- // Views over a detached buffer are dropped; otherwise the older length goes.
290
+ // Drop views over a detached buffer, then the older length.
308
291
  this.#views = this.#views.filter((kept) => kept.buffer === buffer);
309
292
  if (this.#views.length >= 2)
310
293
  this.#views.shift();
@@ -312,14 +295,11 @@ class Alpha2Processor extends AudioWorkletProcessor {
312
295
  return views;
313
296
  }
314
297
  /**
315
- * Reads `frames` samples into the start of each of `targets`: the next ones from the ring, or
316
- * WebAudio's input from `offset` in the quantum. A sample that is not a number is read as silence
317
- * on either path.
298
+ * Reads `frames` samples into each target, from the ring or from WebAudio's input at `offset`.
299
+ * Non-finite samples become silence.
318
300
  *
319
- * Both paths fold channels as WebAudio's speaker rules do: a target past the source's channels
320
- * takes channel 0, and a single target fed two channels takes their average. The node asks
321
- * WebAudio for exactly the module's channels, so its input needs this only when a host changed
322
- * the node's channel mode.
301
+ * Channels fold as WebAudio's speaker rules do: extra targets take channel 0, and a single target
302
+ * fed two channels takes their average.
323
303
  */
324
304
  #readInput(inputs, targets, frames, offset) {
325
305
  if (this.#ring === undefined) {
@@ -347,8 +327,19 @@ class Alpha2Processor extends AudioWorkletProcessor {
347
327
  }
348
328
  this.#readRing(this.#ring, targets, frames);
349
329
  }
350
- /** Reads the next `frames` ring samples into `targets`, reporting a gap. */
330
+ /**
331
+ * Reads the next `frames` ring samples, reporting underruns. The first read also reports
332
+ * `currentFrame`, which the host uses to align ring samples with output timestamps.
333
+ */
351
334
  #readRing(ring, targets, frames) {
335
+ if (!this.#firstReadReported) {
336
+ this.#firstReadReported = true;
337
+ const frame = globalThis.currentFrame;
338
+ this.port.postMessage({
339
+ type: "alpha2-first-read",
340
+ frame: typeof frame === "number" ? frame : null,
341
+ });
342
+ }
352
343
  const produced = ring.read(targets, frames);
353
344
  if (produced < frames) {
354
345
  this.#underruns += 1;
@@ -360,7 +351,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
360
351
  this.#underruns = 0;
361
352
  }
362
353
  }
363
- /** The module's source planes, remade when its memory grew. */
354
+ /** Source plane views, remade when memory grew. */
364
355
  #sourcePlanes(exports) {
365
356
  const buffer = exports.memory.buffer;
366
357
  if (this.#sourceViews?.buffer !== buffer) {
@@ -373,10 +364,8 @@ class Alpha2Processor extends AudioWorkletProcessor {
373
364
  return this.#sourceViews.planes;
374
365
  }
375
366
  /**
376
- * Plays the next `frames` of the ring, which carries the project's rate, converted to the
377
- * context's: the module asks for the ring samples the outputs weigh, converts them into its input
378
- * planes, and runs the master over them (or they are copied out as they are, for a transparent
379
- * master). Returns false once the module failed, after reporting why.
367
+ * Plays the next `frames` of a project-rate ring, resampled to the context's rate and run
368
+ * through the master chain. Returns false after reporting a module failure.
380
369
  */
381
370
  #processConverted(exports, ring, output, frames) {
382
371
  for (let start = 0; start < frames; start += this.#maxFrames) {
@@ -422,8 +411,7 @@ class Alpha2Processor extends AudioWorkletProcessor {
422
411
  return true;
423
412
  const frames = output[0]?.length ?? 0;
424
413
  if (output.length !== this.#channels) {
425
- // WebAudio sizes the output from the node's options, so a mismatch is a host configuration
426
- // error.
414
+ // A mismatch means the host created the node with the wrong `outputChannelCount`.
427
415
  if (!this.#shapeReported) {
428
416
  this.#shapeReported = true;
429
417
  this.port.postMessage({
@@ -442,7 +430,6 @@ class Alpha2Processor extends AudioWorkletProcessor {
442
430
  this.#readInput(inputs, output, frames, 0);
443
431
  return true;
444
432
  }
445
- // The context chooses the quantum; the module takes at most its prepared size per call.
446
433
  for (let start = 0; start < frames; start += this.#maxFrames) {
447
434
  const length = Math.min(this.#maxFrames, frames - start);
448
435
  this.#readInput(inputs, this.#viewsFor(exports, length).input, length, start);
@@ -459,14 +446,14 @@ class Alpha2Processor extends AudioWorkletProcessor {
459
446
  return false;
460
447
  }
461
448
  if (status !== 0) {
462
- // Returning false retires this node for good; this message is the host's only signal.
449
+ // Returning false retires the node; this message is the host's only signal.
463
450
  this.port.postMessage({
464
451
  type: "alpha2-error",
465
452
  message: `AudioWorklet processing failed (${status}); the node has stopped`,
466
453
  });
467
454
  return false;
468
455
  }
469
- // Recheck the views anyway: a stale one would read a detached buffer as empty.
456
+ // Recheck: processing may have grown memory and detached the views.
470
457
  const produced = this.#viewsFor(exports, length).output;
471
458
  for (let channel = 0; channel < this.#channels; channel += 1) {
472
459
  const view = produced[channel];
@@ -2,10 +2,7 @@ import type { AudioRingTransfer } from "./audio-timeline.js";
2
2
  import type { MasterAudio } from "./project.js";
3
3
  /** Options for {@link Alpha2AudioWorkletHost.create}. */
4
4
  export interface AudioWorkletHostOptions {
5
- /**
6
- * URL of the worklet processor module added to `audioWorklet`. Defaults to
7
- * {@link alpha2AudioWorkletProcessorUrl}.
8
- */
5
+ /** Processor module URL. Defaults to {@link alpha2AudioWorkletProcessorUrl}. */
9
6
  readonly processorUrl?: string | URL;
10
7
  /** Name the processor module passes to `registerProcessor` (default `alpha2-processor`). */
11
8
  readonly processorName?: string;
@@ -13,40 +10,31 @@ export interface AudioWorkletHostOptions {
13
10
  readonly numberOfInputs?: number;
14
11
  /** Default 1. */
15
12
  readonly numberOfOutputs?: number;
16
- /**
17
- * Channels of each output. Defaults to two for every output, which is also what the DSP module
18
- * mixes; the module's channel count is the first entry. Leaving it to WebAudio would size the
19
- * output from whatever is connected.
20
- */
13
+ /** Channels per output (default 2 each). The first entry sets the DSP module's channel count. */
21
14
  readonly outputChannelCount?: readonly number[];
22
15
  /**
23
- * The sample rate of the audio the node plays from a ring ({@link useAudioRing}): the project's,
24
- * which an `AudioPump` mixes at. Defaults to the context's. A context at another rate (one that
25
- * did not grant the rate a host asked for) plays the ring converted to its own rate with the
26
- * engine's band-limited converter, so the audio keeps its speed and pitch, and reports
27
- * `resampled` through `onDiagnostic`. A node's WebAudio input is at the context's rate already
28
- * and is never converted. A positive integer; any other value is refused with a `RangeError`.
16
+ * Sample rate of ring audio ({@link useAudioRing}), normally the project's. Defaults to the
17
+ * context's. When it differs from the context's, ring audio is resampled with the engine's
18
+ * band-limited converter and `resampled` is reported through `onDiagnostic`. WebAudio input is
19
+ * never resampled. Must be a positive integer.
29
20
  */
30
21
  readonly projectSampleRate?: number;
31
22
  /**
32
- * Called once the node runs with what it does differently from the export: `resampled` when it
33
- * converts the ring from `projectSampleRate` to the context's rate, so what is heard is not
34
- * bit-identical to what an export renders. Defaults to `console.warn`.
23
+ * Called once at startup when playback will differ from an export (currently only `resampled`).
24
+ * Defaults to `console.warn`.
35
25
  */
36
26
  readonly onDiagnostic?: (diagnostic: AudioWorkletDiagnostic) => void;
37
- /** Aborts creation; `create` then rejects with the signal's reason and disposes the node. */
27
+ /** Aborts creation; `create` rejects with the signal's reason and disposes the node. */
38
28
  readonly signal?: AbortSignal;
39
29
  /**
40
- * Called for every error the running node reports: a processor exception, a rejected
41
- * configuration, a trap in the DSP module, or an output it cannot fill. Defaults to
42
- * `console.error`, so none of them is silent.
30
+ * Called for every error the running node reports, such as a processor exception, a DSP trap or
31
+ * an unfillable output. Defaults to `console.error`.
43
32
  */
44
33
  readonly onError?: (error: Error) => void;
45
34
  }
46
35
  /**
47
- * What a node does differently from the export ({@link AudioWorkletHostOptions.onDiagnostic}).
48
- * `resampled`: the context runs at another rate than the project, so the node converts the ring's
49
- * audio to the context's rate.
36
+ * See {@link AudioWorkletHostOptions.onDiagnostic}. `resampled` means the context rate differs
37
+ * from the project rate.
50
38
  */
51
39
  export interface AudioWorkletDiagnostic {
52
40
  readonly kind: "resampled";
@@ -54,8 +42,7 @@ export interface AudioWorkletDiagnostic {
54
42
  readonly contextSampleRate: number;
55
43
  }
56
44
  /**
57
- * How late a node's output is behind the samples it takes, in samples at the context's rate. An
58
- * `AudioPlaybackClock` subtracts it (its `processing` argument).
45
+ * Node output delay in context-rate samples, for `AudioPlaybackClock`'s `processing` option.
59
46
  */
60
47
  export interface AudioProcessingDelay {
61
48
  readonly latencySamples: number;
@@ -64,87 +51,69 @@ export interface AudioProcessingDelay {
64
51
  export declare const alpha2AudioWorkletProcessorUrl: URL;
65
52
  /** URL of the C-ABI DSP wasm module distributed with the alpha2 package. */
66
53
  export declare const alpha2AudioWorkletWasmUrl: URL;
67
- /** Fetches the packaged DSP bytes for transfer into the AudioWorklet realm. */
54
+ /** Fetches the packaged DSP wasm bytes. */
68
55
  export declare function loadAlpha2AudioWorkletWasm(url?: string | URL): Promise<ArrayBuffer>;
69
56
  /** Browser host for the C-ABI DSP wasm module; no wasm-bindgen glue is used. */
70
57
  export declare class Alpha2AudioWorkletHost {
71
58
  /**
72
- * Adds the processor module to `context`, creates the node and starts the DSP module in it from
73
- * a copy of `wasm` (the caller's buffer is not detached). Resolves once the processor reports
74
- * ready; later errors go to `options.onError`.
59
+ * Adds the processor module, creates the node and starts the DSP module from a copy of `wasm`.
60
+ * Resolves once the processor is ready; later errors go to `options.onError`.
75
61
  *
76
- * Rejects when the module cannot be added, the processor fails or reports an error while
77
- * starting, it is not ready within 5 seconds, or `options.signal` aborts. A node that fails to
78
- * start is disposed.
62
+ * Rejects (and disposes the node) when the module cannot be added, the processor fails while
63
+ * starting, it is not ready within 5 seconds, or `options.signal` aborts.
79
64
  *
80
65
  * @throws RangeError When `options.projectSampleRate` is not a positive integer.
81
66
  */
82
67
  static create(context: BaseAudioContext, wasm: BufferSource, options: AudioWorkletHostOptions): Promise<AudioWorkletNode>;
83
68
  /**
84
- * The node's delay, live, in samples at the context's rate: the samples its master chain holds
85
- * its input back by (the lookahead of the master's compressors; the limiter has none), and, while
86
- * it converts a ring at the project's rate to the context's, the source samples the converter
87
- * reads past the one it plays (16 to 18 at the usual rates), so its output is that much behind
88
- * what it takes from the ring or its input. Zero without either (an engine-mixed node at the
89
- * project's rate), and for a node `create` did not make.
69
+ * The node's live output delay in context-rate samples: master compressor lookahead plus, when
70
+ * resampling ring audio, the converter's lookahead (16 to 18 samples at common rates). Zero for an
71
+ * engine-mixed node at the project rate and for nodes `create` did not make.
90
72
  *
91
- * The engine reads ahead by its own latency, so its mix is never late; the worklet cannot read
92
- * ahead of live input. The value follows each configuration once the processor has installed it,
93
- * which it reports on its port; pass the object to `AudioPlaybackClock` so the clock says
94
- * what is being heard.
73
+ * The returned object updates as configurations are applied; pass it to `AudioPlaybackClock` so
74
+ * the clock reports what is being heard.
95
75
  */
96
76
  static latency(node: AudioWorkletNode): AudioProcessingDelay;
97
77
  }
98
78
  /**
99
- * Points the node at a shared audio ring instead of its WebAudio input.
100
- *
101
- * Pass `undefined` to return the node to input processing. Both sides must agree to clear the ring
102
- * at a seek.
79
+ * Points the node at a shared audio ring instead of its WebAudio input; `undefined` switches back.
80
+ * Both sides must agree to clear the ring at a seek.
103
81
  *
104
- * Resolves once the processor plays from the ring (and {@link Alpha2AudioWorkletHost.latency}
105
- * includes a conversion's delay): the processor takes messages between render quanta, so a quantum
106
- * rendered before then plays the input. Await it before an `OfflineAudioContext`'s
107
- * `startRendering()`, whose first quanta may otherwise render without the ring. Rejects when the
108
- * node is disposed or its processor throws before it answers.
82
+ * Resolves once the processor plays from the ring and {@link Alpha2AudioWorkletHost.latency} is
83
+ * updated. Await it before `OfflineAudioContext.startRendering()`, or the first quanta may render
84
+ * without the ring. Rejects when the node is disposed or its processor throws first.
109
85
  */
110
86
  export declare function useAudioRing(node: AudioWorkletNode, ring: AudioRingTransfer | undefined): Promise<void>;
111
87
  /**
112
- * Installs a project master bus in the running worklet, as an edit: the effects it keeps, and those
113
- * it changes in place, keep their history, so moving a master control does not restart the reverb's
114
- * tail or empty the compressor's lookahead.
88
+ * Installs a project master bus in the running worklet as an edit. Kept and changed effects keep
89
+ * their state, so adjusting a control does not cut a reverb tail or reset compressor lookahead.
115
90
  *
116
- * The worklet applies the master as the engine does (effects, then gain, then limiter), except the
117
- * loudness normalization a host sets on the engine, which the master bus does not carry.
91
+ * Applied as the engine does (effects, gain, limiter), without the engine's loudness normalization
92
+ * gain, which the master bus does not carry.
118
93
  *
119
- * Resolves once the processor runs the new master, with {@link Alpha2AudioWorkletHost.latency}
120
- * already its delay. Rejects with a `RangeError`, posting nothing, for a keyframed master gain
121
- * ({@link encodeMasterAudio}); with the processor's reason when it refuses the record (the chain it
122
- * was running keeps running); and when the node is disposed or its processor throws before it
123
- * answers.
94
+ * Resolves once the new master runs and {@link Alpha2AudioWorkletHost.latency} reflects it.
95
+ * Rejects with a `RangeError` for a keyframed master gain (nothing is posted), with the processor's
96
+ * reason when it refuses the record (the old chain keeps running), or when the node is disposed or
97
+ * its processor throws first.
124
98
  */
125
99
  export declare function configureMasterAudio(node: AudioWorkletNode, master: MasterAudio | undefined): Promise<void>;
126
100
  /**
127
- * Configures the worklet as a transparent transport for engine-mixed audio.
128
- *
129
- * `renderAudio` has already applied the project master gain, effects, and limiter. Ring-buffer
130
- * preview must therefore bypass the worklet master chain or preview would process it twice while
131
- * offline export processes it once.
101
+ * Makes the worklet a transparent transport for engine-mixed audio, since `renderAudio` has already
102
+ * applied the master chain.
132
103
  *
133
104
  * Resolves once the processor is transparent; rejects as {@link configureMasterAudio} does.
134
105
  */
135
106
  export declare function configureEngineMixedAudio(node: AudioWorkletNode): Promise<void>;
136
107
  /**
137
- * Clears the worklet's DSP history and transport position. Resolves once the processor has cleared
138
- * them; rejects when the node is disposed or its processor throws before it answers.
108
+ * Clears the worklet's DSP state and transport position. Rejects when the node is disposed or its
109
+ * processor throws first.
139
110
  */
140
111
  export declare function resetAudioWorklet(node: AudioWorkletNode): Promise<void>;
141
112
  /**
142
- * Stops the node for good and disconnects it.
113
+ * Permanently stops and disconnects the node.
143
114
  *
144
- * A processor runs until its `AudioContext` closes unless it is told to stop: disconnecting alone
145
- * leaves it processing every quantum and holding its DSP module's memory. This frees the module and
146
- * retires the processor, including one still starting. Call it for every node a host stops using
147
- * while the context lives on. A configuration the processor has not answered yet, and any made
148
- * afterwards, rejects.
115
+ * Disconnecting alone leaves the processor running and holding DSP memory until the context
116
+ * closes, so call this for every node no longer used. Pending and later configuration requests
117
+ * reject.
149
118
  */
150
119
  export declare function disposeAudioWorklet(node: AudioWorkletNode): void;