alpha2 0.4.5 → 0.5.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 (119) 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 +28 -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 +109 -173
  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 +98 -157
  53. package/dist/frame-supply.js +191 -162
  54. package/dist/generated/project-schema.d.ts +742 -464
  55. package/dist/generated/project-schema.js +63 -2
  56. package/dist/generated/project-shape.js +663 -118
  57. package/dist/geometry.d.ts +28 -34
  58. package/dist/geometry.js +18 -23
  59. package/dist/gpu-recovery.d.ts +92 -0
  60. package/dist/gpu-recovery.js +135 -0
  61. package/dist/hdr-frames.d.ts +88 -62
  62. package/dist/hdr-frames.js +123 -46
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.js +4 -0
  65. package/dist/json-text.d.ts +13 -23
  66. package/dist/json-text.js +10 -20
  67. package/dist/layout-values.d.ts +14 -22
  68. package/dist/layout-values.js +18 -21
  69. package/dist/layout.d.ts +55 -55
  70. package/dist/layout.js +37 -36
  71. package/dist/loudness.d.ts +27 -32
  72. package/dist/loudness.js +19 -23
  73. package/dist/media.d.ts +85 -237
  74. package/dist/media.js +133 -287
  75. package/dist/mediabunny.d.ts +173 -237
  76. package/dist/mediabunny.js +943 -518
  77. package/dist/physical-frames.d.ts +5 -17
  78. package/dist/physical-frames.js +4 -11
  79. package/dist/player.d.ts +56 -47
  80. package/dist/player.js +155 -40
  81. package/dist/presented-frames.d.ts +2 -7
  82. package/dist/presented-frames.js +3 -8
  83. package/dist/project.d.ts +83 -110
  84. package/dist/project.js +421 -447
  85. package/dist/rate-control.d.ts +9 -23
  86. package/dist/rate-control.js +7 -18
  87. package/dist/renderer-choice.d.ts +41 -0
  88. package/dist/renderer-choice.js +82 -0
  89. package/dist/repacked-bytes.d.ts +0 -2
  90. package/dist/repacked-bytes.js +2 -5
  91. package/dist/robustness.d.ts +25 -37
  92. package/dist/robustness.js +71 -54
  93. package/dist/sha256.d.ts +5 -13
  94. package/dist/sha256.js +9 -24
  95. package/dist/text.d.ts +106 -63
  96. package/dist/text.js +44 -69
  97. package/dist/video-frames.d.ts +7 -25
  98. package/dist/video-frames.js +12 -29
  99. package/dist/waveform.d.ts +5 -11
  100. package/dist/waveform.js +4 -9
  101. package/dist/worker-error.d.ts +5 -20
  102. package/dist/worker-error.js +8 -25
  103. package/dist/worker.d.ts +82 -92
  104. package/dist/worker.js +239 -144
  105. package/package.json +26 -2
  106. package/wasm/alpha2_audio_worklet.wasm +0 -0
  107. package/wasm/alpha2_extensions.d.ts +26 -47
  108. package/wasm/alpha2_extensions.js +26 -47
  109. package/wasm/alpha2_extensions_bg.wasm +0 -0
  110. package/wasm/alpha2_wasm.d.ts +487 -543
  111. package/wasm/alpha2_wasm.js +669 -572
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
@@ -1,106 +1,84 @@
1
1
  import type { MasterAudio } from "./project.js";
2
2
  /** Byte length of an {@link AudioRingTransfer}'s `control` buffer. */
3
3
  export declare const AUDIO_RING_CONTROL_BYTES: number;
4
- /**
5
- * Whether shared memory is usable for the audio ring: `SharedArrayBuffer` exists and the document
6
- * is cross-origin isolated.
7
- */
4
+ /** Whether `SharedArrayBuffer` exists and the document is cross-origin isolated. */
8
5
  export declare function canShareAudioMemory(): boolean;
9
6
  /** Transferable description of one ring, posted to the worklet and worker. */
10
7
  export interface AudioRingTransfer {
11
- /** The index header, at least {@link AUDIO_RING_CONTROL_BYTES} long. */
8
+ /** At least {@link AUDIO_RING_CONTROL_BYTES} long. */
12
9
  readonly control: SharedArrayBuffer;
13
- /** `channels` planes of `capacity` 32-bit floats, one after another. */
10
+ /** `channels` consecutive planes of `capacity` 32-bit floats. */
14
11
  readonly samples: SharedArrayBuffer;
15
12
  readonly channels: number;
16
- /** Samples per channel; a power of two. */
13
+ /** Samples per channel, a power of two. */
17
14
  readonly capacity: number;
18
15
  }
19
16
  /**
20
- * A lock-free planar audio ring shared by one writer and one reader.
17
+ * A lock-free planar audio ring for exactly one writer and one reader.
21
18
  *
22
- * Indices are monotonic sample counts that wrap at 2^32. The capacity is a power of two, so it
23
- * divides 2^32 and an index keeps its slot across the wrap. Each side publishes its index with a
24
- * sequentially consistent `Atomics.store` after writing or reading the samples, and the other side
25
- * loads it with `Atomics.load`, so neither side blocks and neither sees samples before they are
26
- * written. This holds only for one writer and one reader.
19
+ * Indices are sample counts wrapping at 2^32; a power-of-two capacity keeps slots stable across
20
+ * the wrap. Each side publishes its index with `Atomics.store` after touching the samples, so the
21
+ * other side never sees samples before they are written.
27
22
  */
28
23
  export declare class AudioRingBuffer {
29
24
  #private;
30
25
  private constructor();
31
26
  /**
32
- * Allocates a ring holding at least `capacity` samples per channel, rounded up to a power of two.
27
+ * Allocates a ring of at least `capacity` samples per channel, rounded up to a power of two.
33
28
  *
34
29
  * @param channels 1 or 2.
35
- * @param capacity From 2 to 2^30. A fraction is rounded up with the rest, so a ring sized from
36
- * an odd sample rate (`sampleRate / 2` at 11 025 Hz) holds at least that much.
30
+ * @param capacity From 2 to 2^30; fractions round up.
37
31
  * @throws RangeError for a channel count or capacity out of range.
38
32
  * @throws Error when shared memory is unavailable ({@link canShareAudioMemory} is false).
39
33
  */
40
34
  static create(channels: number, capacity: number): AudioRingBuffer;
41
35
  /**
42
- * Attaches to a ring described by a transferred handle, sharing its memory.
36
+ * Attaches to a transferred ring, sharing its memory.
43
37
  *
44
38
  * @throws RangeError when the capacity is not a power of two or the control buffer is too small.
45
39
  */
46
40
  static attach(transfer: AudioRingTransfer): AudioRingBuffer;
47
- /** The handle to post to the other thread; posting it shares, not copies, the ring. */
41
+ /** Handle to post to the other thread; the memory is shared, not copied. */
48
42
  get transfer(): AudioRingTransfer;
49
43
  get channels(): number;
50
44
  get capacity(): number;
51
- /**
52
- * Samples per channel the reader will still play: everything written since the last clear, even
53
- * before the reader has carried that clear out.
54
- */
45
+ /** Samples per channel written since the last clear, even if the reader has not applied it. */
55
46
  get available(): number;
56
47
  /**
57
- * Samples per channel the writer may still push.
58
- *
59
- * Audio a pending clear discards still occupies its slots until the reader moves past it, so it
60
- * counts against the space here.
48
+ * Samples per channel the writer may still push. Audio a pending clear discards still occupies
49
+ * its slots until the reader applies the clear.
61
50
  */
62
51
  get writable(): number;
63
52
  /**
64
- * Writes the first `frames` samples of each plane. Writer side only.
65
- *
66
- * A channel with no plane of its own takes `planes[0]`; a non-finite sample is written as 0.
67
- * Returns how many samples per channel were accepted, which is less than `frames` when the reader
68
- * has not drained enough.
53
+ * Writer side: writes up to `frames` samples per channel and returns how many were accepted.
54
+ * Missing planes take `planes[0]`; non-finite samples become 0.
69
55
  *
70
56
  * @throws RangeError when `frames` is not a non-negative whole number, before any index moves.
71
57
  */
72
58
  write(planes: readonly Float32Array[], frames: number): number;
73
59
  /**
74
- * Reads `frames` samples per channel into caller-owned planes, carrying out a pending clear
75
- * first. Reader side only.
76
- *
77
- * Returns how many samples per channel were produced; the rest of each plane is filled with
78
- * silence, so an underrun is heard as a gap rather than as stale audio. Channels are mixed as
79
- * WebAudio's speaker rules mix them: a plane past the ring's channel count receives channel 0,
80
- * and a single plane read from a stereo ring receives the average of both.
60
+ * Reader side: applies a pending clear, then reads up to `frames` samples per channel and returns
61
+ * how many were produced. The rest is filled with silence. Channels fold as WebAudio's speaker
62
+ * rules do: extra planes take channel 0, and a mono read of a stereo ring averages both.
81
63
  *
82
64
  * @throws RangeError when `frames` is not a non-negative whole number, before any index moves.
83
65
  */
84
66
  read(planes: readonly Float32Array[], frames: number): number;
85
67
  /**
86
- * Writer side: discards everything written so far, as a seek needs. The reader carries it out at
87
- * its next read, so the writer may keep writing the new position's audio at once.
68
+ * Writer side: discards everything written so far. The reader applies it at its next read, so the
69
+ * writer may immediately write audio for the new position.
88
70
  */
89
71
  clear(): void;
90
72
  }
91
- /** The engine surface the pump drives. A worker implements it over the wasm module. */
73
+ /** Engine surface the pump drives, implemented by a worker over the wasm module. */
92
74
  export interface TimelineAudioSource {
93
- /** Project sample rate of every mixed block. */
75
+ /** Project sample rate. */
94
76
  readonly sampleRate: number;
95
- /** Channel count of every mixed block. */
96
77
  readonly channels: number;
97
78
  /**
98
- * Mixes `frames` samples per channel starting at absolute sample index `startSample`. Resolves
99
- * with at least `frames` samples in each of `channels` planes, or with the sources whose media
100
- * must be supplied first.
101
- *
102
- * `signal` aborts when the pump seeks away from `startSample`, so a source may stop decoding
103
- * for it. The pump drops whatever a mix it aborted resolves or rejects with.
79
+ * Mixes `frames` samples per channel from absolute sample `startSample`, or reports the sources
80
+ * whose media must be supplied first. `signal` aborts when the pump seeks away; the result of an
81
+ * aborted mix is dropped.
104
82
  */
105
83
  mix(startSample: number, frames: number, signal: AbortSignal): Promise<{
106
84
  readonly kind: "mixed";
@@ -113,118 +91,112 @@ export interface TimelineAudioSource {
113
91
  /** Tuning for an {@link AudioPump}. */
114
92
  export interface AudioPumpOptions {
115
93
  /**
116
- * Samples per channel mixed per step, a positive whole number. Defaults to 1024. A source that
117
- * mixes with the engine's `renderAudio` mixes at most its `audioMaxBlock` per call, so keep this
118
- * within that. Round a block computed from a duration (`Math.ceil(sampleRate * 0.02)`).
94
+ * Samples per channel per mix step (default 1024). Keep it within the engine's `audioMaxBlock`
95
+ * when mixing with `renderAudio`. Must be a whole number.
119
96
  */
120
97
  readonly blockFrames?: number;
121
- /**
122
- * Ring fill the pump maintains, in samples per channel, a positive whole number. Defaults to
123
- * half the ring capacity.
124
- */
98
+ /** Ring fill to maintain, in samples per channel. Defaults to half the ring capacity. */
125
99
  readonly targetFrames?: number;
126
100
  /**
127
- * Called with the missing source IDs when a mix step needs media the host has not supplied.
128
- * {@link AudioPump.fill} awaits it, then stops; the host calls `fill` again once the media is in.
101
+ * Called with missing source IDs. {@link AudioPump.fill} awaits it and then stops; call `fill`
102
+ * again once the media is supplied.
129
103
  */
130
104
  readonly onRefill?: (missingSources: readonly string[]) => Promise<void> | void;
131
105
  }
132
106
  /**
133
- * Keeps an {@link AudioRingBuffer} ahead of the audio thread.
134
- *
135
- * The pump is driven by the host's own scheduler (a timer, a message, or the
136
- * worklet's own fill notifications) so this package never owns a clock.
107
+ * Keeps an {@link AudioRingBuffer} ahead of the audio thread. The host drives it from its own
108
+ * scheduler; this package owns no clock.
137
109
  *
138
- * The constructor throws `RangeError` when `startSample` is not a non-negative integer, or a
139
- * `blockFrames` or `targetFrames` option is not a positive one.
110
+ * The constructor throws `RangeError` when `startSample` is not a non-negative integer, or
111
+ * `blockFrames` or `targetFrames` is not a positive one.
140
112
  */
141
113
  export declare class AudioPump {
142
114
  #private;
143
115
  constructor(source: TimelineAudioSource, ring: AudioRingBuffer, startSample?: number, options?: AudioPumpOptions);
144
- /** The rate the pump mixes at: its source's, the project's. */
116
+ /** The project sample rate. */
145
117
  get sampleRate(): number;
146
118
  /** Absolute sample index the next mixed block starts at. */
147
119
  get position(): number;
148
120
  /** Absolute sample index playback last started at or was sought to. */
149
121
  get startSample(): number;
150
122
  /**
151
- * Moves the pump to `startSample` and clears buffered audio, as a seek needs.
152
- *
153
- * A mix still running for the old position is aborted, and what it returns is dropped: a fill
154
- * in progress goes on from `startSample`, so the first sample written after a seek is always
155
- * the target's.
123
+ * Moves the pump to `startSample` and clears buffered audio. An in-flight mix is aborted and
124
+ * dropped; a running fill continues from the new position.
156
125
  *
157
126
  * @throws RangeError when `startSample` is not a non-negative integer.
158
127
  */
159
128
  seek(startSample: number): void;
160
129
  /**
161
- * Mixes until the ring holds its target fill or the engine needs media.
162
- *
163
- * Resolves with the number of samples per channel written. A call made while another is running
164
- * resolves with 0 at once, so a host may call this from several events; after a seek, the
165
- * running call carries on from the new position. Rejects when the source's `mix` or `onRefill`
166
- * rejects, except for a mix that a seek made stale.
130
+ * Mixes until the ring reaches its target fill or the engine needs media, resolving with the
131
+ * samples per channel written. A concurrent call resolves with 0 immediately. Rejects when `mix`
132
+ * or `onRefill` rejects, unless a seek made the mix stale.
167
133
  */
168
134
  fill(): Promise<number>;
169
135
  }
170
- /**
171
- * What the audio output reports about its own delay. An `AudioContext` satisfies it directly.
172
- */
136
+ /** Audio output timing; an `AudioContext` satisfies it. */
173
137
  export interface AudioOutputTiming {
174
138
  readonly sampleRate: number;
175
- /** Seconds from the audio thread to the speaker, where the browser knows. */
139
+ /** Seconds from the audio thread to the speaker, when known. */
176
140
  readonly outputLatency?: number;
177
- /** Seconds of the audio thread's own processing delay. */
178
141
  readonly baseLatency?: number;
142
+ readonly currentTime?: number;
143
+ getOutputTimestamp?(): AudioTimestamp;
144
+ }
145
+ /**
146
+ * Source of an {@link AudioPlaybackClock}'s output latency, in order of preference: a positive
147
+ * `outputLatency`, the output timestamp, or `baseLatency` alone (which omits device and wireless
148
+ * delay).
149
+ */
150
+ export type AudioLatencySource = "output-latency" | "output-timestamp" | "base-only";
151
+ export interface AudioPlaybackClockOptions {
152
+ /**
153
+ * Delay of the ring's player, read at every query; pass `Alpha2AudioWorkletHost.latency(node)`
154
+ * for a worklet that runs the master chain.
155
+ */
156
+ readonly processing?: {
157
+ readonly latencySamples: number;
158
+ };
159
+ /**
160
+ * Seconds added to the measured latency for unreported delay, such as a wireless link. Positive
161
+ * shows the picture later. Default 0.
162
+ */
163
+ readonly latencyOffsetSeconds?: number;
179
164
  }
180
165
  /**
181
- * The timeline position a listener is hearing now, for presenting video against the audio (closed
182
- * loop).
166
+ * The timeline position being heard now, for presenting video against the audio clock.
183
167
  *
184
- * `Alpha2Player.present(time)` shows whatever time the host passes. Deriving that time from a wall
185
- * clock (`performance.now()`) is open loop: the audio device runs on its own crystal, so video and
186
- * sound drift apart by the difference of the two clocks (tens of milliseconds over ten minutes at
187
- * 50 ppm), and every audio underrun or seek adds a step. This clock instead counts what the audio
188
- * thread has taken from the ring (everything the pump mixed, less what is still buffered) and
189
- * subtracts the output's latency, so a host that presents `timelineTicks` on each animation frame
190
- * shows the picture that belongs to the sound being heard, without drift.
168
+ * A wall clock drifts from the audio device's crystal and ignores underruns. This clock counts
169
+ * samples the audio thread has consumed from the ring and subtracts output latency and the manual
170
+ * offset, so presenting `timelineTicks` each animation frame stays in sync without drift.
191
171
  *
192
- * Before playback reaches the speaker, the position holds at the start or seek target instead of
193
- * going earlier. Positions are the pump's samples, at the project's rate; the output's latency is
194
- * converted from seconds and `processing` from the output's samples, so a context at another rate
195
- * (whose worklet converts the ring to it) keeps time. The constructor throws `RangeError` for an
196
- * output or pump sample rate that is not positive.
172
+ * The position never goes before the start or seek target. Positions are at the project rate;
173
+ * latency is converted from seconds and `processing` from output-rate samples, so a resampling
174
+ * context keeps time.
175
+ *
176
+ * The constructor throws `RangeError` for a non-positive sample rate or a non-finite offset.
197
177
  */
198
178
  export declare class AudioPlaybackClock {
199
179
  #private;
200
- /**
201
- * `processing` is the delay of what plays the ring before the output, read at every query: for a
202
- * worklet that runs the master itself, `Alpha2AudioWorkletHost.latency(node)` (its compressors'
203
- * lookahead). An engine-mixed node delays nothing.
204
- */
205
- constructor(pump: AudioPump, ring: AudioRingBuffer, output: AudioOutputTiming, processing?: {
206
- readonly latencySamples: number;
207
- });
208
- /** Absolute sample index being heard now, at the pump's (the project's) rate. */
180
+ constructor(pump: AudioPump, ring: AudioRingBuffer, output: AudioOutputTiming, { processing, latencyOffsetSeconds }?: AudioPlaybackClockOptions);
181
+ /** Manual offset in seconds; a non-finite value throws `RangeError`. */
182
+ get latencyOffsetSeconds(): number;
183
+ set latencyOffsetSeconds(seconds: number);
184
+ get latencySource(): AudioLatencySource;
185
+ /** Output latency in seconds, excluding the manual offset. */
186
+ get latencySeconds(): number;
187
+ /** Absolute sample being heard now, at the project rate. */
209
188
  get sample(): number;
210
189
  /** Timeline ticks being heard now, for `Alpha2Player.present`. */
211
190
  get timelineTicks(): bigint;
212
191
  }
213
192
  /**
214
- * Encodes a project master bus into the worklet's fixed-width record.
215
- *
216
- * The worklet carries no JSON parser, so the host writes this record into the module's
217
- * configuration region and calls `alpha2_worklet_configure`. The layout is little-endian and
218
- * versioned (version u32, gain f32, limiter flag u8, limiter threshold f32, limiter release f32,
219
- * node count u32, then the nodes); the module rejects anything it cannot read without disturbing
220
- * the chain it is already running.
193
+ * Encodes a master bus into the worklet's binary record, since the worklet has no JSON parser.
221
194
  *
222
- * Fields the master leaves out take the project schema's defaults, as the engine reads them: unity
223
- * gain and the 0 dBFS, 50 ms limiter. Only `limiter: null` removes the limiter. An EQ effect
224
- * becomes one node per band.
195
+ * Little-endian layout: version u32, gain f32, limiter flag u8, limiter threshold f32, limiter
196
+ * release f32, node count u32, then the nodes. Missing fields take schema defaults (unity gain,
197
+ * 0 dBFS 50 ms limiter); only `limiter: null` removes the limiter. Each EQ band becomes one node.
225
198
  *
226
- * @throws RangeError for a keyframed master gain, which the record's one static gain cannot play.
227
- * Preview such a master through engine-mixed audio (`configureEngineMixedAudio`), which applies
228
- * it as the export does, or pass the gain evaluated at the time being heard.
199
+ * @throws RangeError for a keyframed master gain. Use `configureEngineMixedAudio`, or pass the gain
200
+ * evaluated at the time being heard.
229
201
  */
230
202
  export declare function encodeMasterAudio(master: MasterAudio | undefined): Uint8Array;