alpha2 0.4.6 → 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.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +108 -177
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/generated/project-schema.d.ts +701 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +261 -16
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +48 -63
- package/dist/layout.js +37 -37
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +166 -245
- package/dist/mediabunny.js +741 -580
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +73 -117
- package/dist/project.js +384 -445
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +97 -71
- package/dist/text.js +33 -70
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -95
- package/dist/worker.js +235 -143
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +460 -567
- package/wasm/alpha2_wasm.js +594 -594
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/audio-worklet.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { throwIfAborted } from "./abort.js";
|
|
1
2
|
import { encodeMasterAudio } from "./audio-timeline.js";
|
|
2
|
-
/**
|
|
3
|
+
/** Live delay of each node created by {@link Alpha2AudioWorkletHost.create}. */
|
|
3
4
|
const delays = new WeakMap();
|
|
4
|
-
/** The delay of a node this module did not make: none. */
|
|
5
5
|
const NO_DELAY = Object.freeze({ latencySamples: 0 });
|
|
6
6
|
/** URL of the processor module distributed with the alpha2 package. */
|
|
7
7
|
export const alpha2AudioWorkletProcessorUrl = new URL("./audio-worklet-processor.js", import.meta.url);
|
|
8
8
|
/** URL of the C-ABI DSP wasm module distributed with the alpha2 package. */
|
|
9
9
|
export const alpha2AudioWorkletWasmUrl = new URL("../wasm/alpha2_audio_worklet.wasm", import.meta.url);
|
|
10
|
-
/** Fetches the packaged DSP bytes
|
|
10
|
+
/** Fetches the packaged DSP wasm bytes. */
|
|
11
11
|
export async function loadAlpha2AudioWorkletWasm(url = alpha2AudioWorkletWasmUrl) {
|
|
12
12
|
const response = await fetch(url);
|
|
13
13
|
if (!response.ok) {
|
|
@@ -18,13 +18,11 @@ export async function loadAlpha2AudioWorkletWasm(url = alpha2AudioWorkletWasmUrl
|
|
|
18
18
|
/** Browser host for the C-ABI DSP wasm module; no wasm-bindgen glue is used. */
|
|
19
19
|
export class Alpha2AudioWorkletHost {
|
|
20
20
|
/**
|
|
21
|
-
* Adds the processor module
|
|
22
|
-
*
|
|
23
|
-
* ready; later errors go to `options.onError`.
|
|
21
|
+
* Adds the processor module, creates the node and starts the DSP module from a copy of `wasm`.
|
|
22
|
+
* Resolves once the processor is ready; later errors go to `options.onError`.
|
|
24
23
|
*
|
|
25
|
-
* Rejects when the module cannot be added, the processor fails
|
|
26
|
-
* starting, it is not ready within 5 seconds, or `options.signal` aborts.
|
|
27
|
-
* start is disposed.
|
|
24
|
+
* Rejects (and disposes the node) when the module cannot be added, the processor fails while
|
|
25
|
+
* starting, it is not ready within 5 seconds, or `options.signal` aborts.
|
|
28
26
|
*
|
|
29
27
|
* @throws RangeError When `options.projectSampleRate` is not a positive integer.
|
|
30
28
|
*/
|
|
@@ -45,13 +43,12 @@ export class Alpha2AudioWorkletHost {
|
|
|
45
43
|
outputChannelCount: options.outputChannelCount
|
|
46
44
|
? [...options.outputChannelCount]
|
|
47
45
|
: Array.from({ length: numberOfOutputs }, () => channels),
|
|
48
|
-
//
|
|
49
|
-
// would pass a mono source as one channel.
|
|
46
|
+
// Up-mix by speaker rules; the default "max" would pass mono through as one channel.
|
|
50
47
|
channelCount: channels,
|
|
51
48
|
channelCountMode: "explicit",
|
|
52
49
|
channelInterpretation: "speakers",
|
|
53
50
|
});
|
|
54
|
-
//
|
|
51
|
+
// Listen before starting so the initial latency report is not missed.
|
|
55
52
|
const untrack = trackLatency(node);
|
|
56
53
|
try {
|
|
57
54
|
await initializeNode(node, payload, channels, projectSampleRate, options.signal);
|
|
@@ -66,8 +63,7 @@ export class Alpha2AudioWorkletHost {
|
|
|
66
63
|
return node;
|
|
67
64
|
}
|
|
68
65
|
catch (error) {
|
|
69
|
-
// The processor may still be starting
|
|
70
|
-
// context closes.
|
|
66
|
+
// The processor may still be starting and would otherwise run until the context closes.
|
|
71
67
|
disposeAudioWorklet(node);
|
|
72
68
|
untrack();
|
|
73
69
|
node.port.close();
|
|
@@ -75,26 +71,18 @@ export class Alpha2AudioWorkletHost {
|
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
/**
|
|
78
|
-
* The node's
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* reads past the one it plays (16 to 18 at the usual rates), so its output is that much behind
|
|
82
|
-
* what it takes from the ring or its input. Zero without either (an engine-mixed node at the
|
|
83
|
-
* project's rate), and for a node `create` did not make.
|
|
74
|
+
* The node's live output delay in context-rate samples: master compressor lookahead plus, when
|
|
75
|
+
* resampling ring audio, the converter's lookahead (16 to 18 samples at common rates). Zero for an
|
|
76
|
+
* engine-mixed node at the project rate and for nodes `create` did not make.
|
|
84
77
|
*
|
|
85
|
-
* The
|
|
86
|
-
*
|
|
87
|
-
* which it reports on its port; pass the object to `AudioPlaybackClock` so the clock says
|
|
88
|
-
* what is being heard.
|
|
78
|
+
* The returned object updates as configurations are applied; pass it to `AudioPlaybackClock` so
|
|
79
|
+
* the clock reports what is being heard.
|
|
89
80
|
*/
|
|
90
81
|
static latency(node) {
|
|
91
82
|
return delays.get(node) ?? NO_DELAY;
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Keeps the delay the processor reports for {@link Alpha2AudioWorkletHost.latency}. Returns what
|
|
96
|
-
* stops it, for a node that failed to start.
|
|
97
|
-
*/
|
|
85
|
+
/** Tracks the processor's reported delay; returns a function that stops tracking. */
|
|
98
86
|
function trackLatency(node) {
|
|
99
87
|
const delay = { latencySamples: 0 };
|
|
100
88
|
delays.set(node, delay);
|
|
@@ -108,7 +96,7 @@ function trackLatency(node) {
|
|
|
108
96
|
delays.delete(node);
|
|
109
97
|
};
|
|
110
98
|
}
|
|
111
|
-
/**
|
|
99
|
+
/** Forwards the running node's errors to `report`. */
|
|
112
100
|
function reportErrors(node, report) {
|
|
113
101
|
node.addEventListener("processorerror", () => {
|
|
114
102
|
report(new Error("AudioWorklet processor threw; the node has stopped"));
|
|
@@ -168,19 +156,14 @@ function initializeNode(node, wasm, channels, sourceRate, signal) {
|
|
|
168
156
|
}
|
|
169
157
|
});
|
|
170
158
|
}
|
|
171
|
-
/**
|
|
159
|
+
/** Copies the bytes so the transfer does not detach the caller's buffer. */
|
|
172
160
|
function copyWasmBytes(source) {
|
|
173
161
|
if (source instanceof ArrayBuffer)
|
|
174
162
|
return source.slice(0);
|
|
175
163
|
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice().buffer;
|
|
176
164
|
}
|
|
177
|
-
function throwIfAborted(signal) {
|
|
178
|
-
if (signal?.aborted === true) {
|
|
179
|
-
throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
165
|
const requests = new WeakMap();
|
|
183
|
-
/**
|
|
166
|
+
/** Request state for `node`, created with its answer listener on first use. */
|
|
184
167
|
function requestsOf(node) {
|
|
185
168
|
const existing = requests.get(node);
|
|
186
169
|
if (existing !== undefined)
|
|
@@ -204,7 +187,7 @@ function requestsOf(node) {
|
|
|
204
187
|
node.port.start();
|
|
205
188
|
return created;
|
|
206
189
|
}
|
|
207
|
-
/** Rejects
|
|
190
|
+
/** Rejects pending and future requests with `reason`. */
|
|
208
191
|
function closeRequests(node, reason) {
|
|
209
192
|
const state = requests.get(node);
|
|
210
193
|
if (state === undefined) {
|
|
@@ -218,9 +201,8 @@ function closeRequests(node, reason) {
|
|
|
218
201
|
request.reject(reason);
|
|
219
202
|
}
|
|
220
203
|
/**
|
|
221
|
-
* Posts `message`
|
|
222
|
-
*
|
|
223
|
-
* it, or when the node is disposed or its processor throws first.
|
|
204
|
+
* Posts `message` and resolves once the processor has applied it, so the next quantum uses it.
|
|
205
|
+
* Rejects with the processor's refusal, or when the node is disposed or its processor throws.
|
|
224
206
|
*/
|
|
225
207
|
function request(node, message) {
|
|
226
208
|
const state = requestsOf(node);
|
|
@@ -240,33 +222,27 @@ function request(node, message) {
|
|
|
240
222
|
});
|
|
241
223
|
}
|
|
242
224
|
/**
|
|
243
|
-
* Points the node at a shared audio ring instead of its WebAudio input.
|
|
244
|
-
*
|
|
245
|
-
* Pass `undefined` to return the node to input processing. Both sides must agree to clear the ring
|
|
246
|
-
* at a seek.
|
|
225
|
+
* Points the node at a shared audio ring instead of its WebAudio input; `undefined` switches back.
|
|
226
|
+
* Both sides must agree to clear the ring at a seek.
|
|
247
227
|
*
|
|
248
|
-
* Resolves once the processor plays from the ring
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* `startRendering()`, whose first quanta may otherwise render without the ring. Rejects when the
|
|
252
|
-
* node is disposed or its processor throws before it answers.
|
|
228
|
+
* Resolves once the processor plays from the ring and {@link Alpha2AudioWorkletHost.latency} is
|
|
229
|
+
* updated. Await it before `OfflineAudioContext.startRendering()`, or the first quanta may render
|
|
230
|
+
* without the ring. Rejects when the node is disposed or its processor throws first.
|
|
253
231
|
*/
|
|
254
232
|
export function useAudioRing(node, ring) {
|
|
255
233
|
return request(node, { type: "alpha2-ring", ring });
|
|
256
234
|
}
|
|
257
235
|
/**
|
|
258
|
-
* Installs a project master bus in the running worklet
|
|
259
|
-
*
|
|
260
|
-
* tail or empty the compressor's lookahead.
|
|
236
|
+
* Installs a project master bus in the running worklet as an edit. Kept and changed effects keep
|
|
237
|
+
* their state, so adjusting a control does not cut a reverb tail or reset compressor lookahead.
|
|
261
238
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
239
|
+
* Applied as the engine does (effects, gain, limiter), without the engine's loudness normalization
|
|
240
|
+
* gain, which the master bus does not carry.
|
|
264
241
|
*
|
|
265
|
-
* Resolves once the
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* answers.
|
|
242
|
+
* Resolves once the new master runs and {@link Alpha2AudioWorkletHost.latency} reflects it.
|
|
243
|
+
* Rejects with a `RangeError` for a keyframed master gain (nothing is posted), with the processor's
|
|
244
|
+
* reason when it refuses the record (the old chain keeps running), or when the node is disposed or
|
|
245
|
+
* its processor throws first.
|
|
270
246
|
*/
|
|
271
247
|
export function configureMasterAudio(node, master) {
|
|
272
248
|
let config;
|
|
@@ -279,11 +255,8 @@ export function configureMasterAudio(node, master) {
|
|
|
279
255
|
return request(node, { type: "alpha2-config", config });
|
|
280
256
|
}
|
|
281
257
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* `renderAudio` has already applied the project master gain, effects, and limiter. Ring-buffer
|
|
285
|
-
* preview must therefore bypass the worklet master chain or preview would process it twice while
|
|
286
|
-
* offline export processes it once.
|
|
258
|
+
* Makes the worklet a transparent transport for engine-mixed audio, since `renderAudio` has already
|
|
259
|
+
* applied the master chain.
|
|
287
260
|
*
|
|
288
261
|
* Resolves once the processor is transparent; rejects as {@link configureMasterAudio} does.
|
|
289
262
|
*/
|
|
@@ -294,33 +267,25 @@ export function configureEngineMixedAudio(node) {
|
|
|
294
267
|
});
|
|
295
268
|
}
|
|
296
269
|
/**
|
|
297
|
-
* Clears the worklet's DSP
|
|
298
|
-
*
|
|
270
|
+
* Clears the worklet's DSP state and transport position. Rejects when the node is disposed or its
|
|
271
|
+
* processor throws first.
|
|
299
272
|
*/
|
|
300
273
|
export function resetAudioWorklet(node) {
|
|
301
274
|
return request(node, { type: "alpha2-reset" });
|
|
302
275
|
}
|
|
303
276
|
/**
|
|
304
|
-
*
|
|
277
|
+
* Permanently stops and disconnects the node.
|
|
305
278
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* while the context lives on. A configuration the processor has not answered yet, and any made
|
|
310
|
-
* afterwards, rejects.
|
|
279
|
+
* Disconnecting alone leaves the processor running and holding DSP memory until the context
|
|
280
|
+
* closes, so call this for every node no longer used. Pending and later configuration requests
|
|
281
|
+
* reject.
|
|
311
282
|
*/
|
|
312
283
|
export function disposeAudioWorklet(node) {
|
|
313
284
|
closeRequests(node, new Error("the AudioWorklet node was disposed"));
|
|
314
285
|
node.port.postMessage({ type: "alpha2-dispose" });
|
|
315
286
|
node.disconnect();
|
|
316
287
|
}
|
|
317
|
-
/**
|
|
318
|
-
* The reason a signal carries, as an `Error` a caller can reject with.
|
|
319
|
-
*
|
|
320
|
-
* `AbortSignal.reason` is typed `any` and a caller may abort with a value that is not an `Error`,
|
|
321
|
-
* which would reject without a stack. An `Error` passes through untouched, so an `AbortError` keeps
|
|
322
|
-
* its name.
|
|
323
|
-
*/
|
|
288
|
+
/** The signal's reason as an `Error`; non-`Error` reasons become an `AbortError`. */
|
|
324
289
|
function abortError(signal) {
|
|
325
290
|
const reason = signal?.reason;
|
|
326
291
|
if (reason instanceof Error)
|
package/dist/audio.d.ts
CHANGED
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
import type { BrowserAudioBlock } from "./media.js";
|
|
2
|
-
/**
|
|
3
|
-
* Where {@link renderOfflineAudio} delivers rendered audio, owned by the host
|
|
4
|
-
* (an encoder, a file writer, a test collector).
|
|
5
|
-
*/
|
|
2
|
+
/** Host-owned destination for {@link renderOfflineAudio} output. */
|
|
6
3
|
export interface BrowserAudioBlockSink {
|
|
7
4
|
/**
|
|
8
|
-
* Takes the next block
|
|
9
|
-
*
|
|
5
|
+
* Takes the next block in timeline order. The next block is not rendered until the promise
|
|
6
|
+
* settles; a rejection aborts the render.
|
|
10
7
|
*/
|
|
11
8
|
writeAudio(block: BrowserAudioBlock): Promise<void>;
|
|
12
9
|
/** Called once after the last block was written. */
|
|
13
10
|
finish(): Promise<void>;
|
|
14
11
|
/**
|
|
15
|
-
* Called once instead of `finish` when
|
|
16
|
-
*
|
|
12
|
+
* Called once instead of `finish` when the render fails or is aborted; `reason` is the error the
|
|
13
|
+
* render rejects with.
|
|
17
14
|
*/
|
|
18
15
|
abort(reason: Error): Promise<void> | void;
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
|
-
* Renders `frameCount` frames
|
|
22
|
-
*
|
|
23
|
-
* `frameCount` samples.
|
|
18
|
+
* Renders `frameCount` frames starting at project-rate sample `startSample`. Every channel of the
|
|
19
|
+
* returned block must hold exactly `frameCount` samples.
|
|
24
20
|
*/
|
|
25
21
|
export type OfflineAudioRenderer = (startSample: bigint, frameCount: number) => Promise<BrowserAudioBlock>;
|
|
26
22
|
/**
|
|
27
|
-
* Renders `totalFrames` frames through `render` into `sink`,
|
|
28
|
-
* sizes
|
|
29
|
-
* reproduced exactly on every run.
|
|
23
|
+
* Renders `totalFrames` frames through `render` into `sink`, one block at a time, with block
|
|
24
|
+
* sizes cycling through `blockSizes`.
|
|
30
25
|
*
|
|
31
|
-
*
|
|
32
|
-
* `
|
|
33
|
-
*
|
|
34
|
-
* `abort` is awaited with the error and the promise rejects with it
|
|
35
|
-
* (`signal.reason`, or an `AbortError`, for an abort). An `abort` that throws
|
|
36
|
-
* does not replace that error ({@link recordCleanupFailure}).
|
|
26
|
+
* On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
|
|
27
|
+
* the promise resolves, the sink's `abort` is awaited and the promise rejects with the error
|
|
28
|
+
* (`signal.reason` or an `AbortError` for an abort). An error thrown by `abort` does not replace it.
|
|
37
29
|
*
|
|
38
|
-
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or
|
|
39
|
-
*
|
|
40
|
-
*
|
|
30
|
+
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
|
|
31
|
+
* not a positive safe integer (checked before the sink is touched), or `render` returns a block
|
|
32
|
+
* of the wrong length.
|
|
41
33
|
*/
|
|
42
34
|
export declare function renderOfflineAudio(totalFrames: bigint, blockSizes: readonly number[], render: OfflineAudioRenderer, sink: BrowserAudioBlockSink, signal?: AbortSignal): Promise<void>;
|
package/dist/audio.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { recordCleanupFailure } from "./export-failure.js";
|
|
2
2
|
/**
|
|
3
|
-
* Renders `totalFrames` frames through `render` into `sink`,
|
|
4
|
-
* sizes
|
|
5
|
-
* reproduced exactly on every run.
|
|
3
|
+
* Renders `totalFrames` frames through `render` into `sink`, one block at a time, with block
|
|
4
|
+
* sizes cycling through `blockSizes`.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
* `abort` is awaited with the error and the promise rejects with it
|
|
11
|
-
* (`signal.reason`, or an `AbortError`, for an abort). An `abort` that throws
|
|
12
|
-
* does not replace that error ({@link recordCleanupFailure}).
|
|
6
|
+
* On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
|
|
7
|
+
* the promise resolves, the sink's `abort` is awaited and the promise rejects with the error
|
|
8
|
+
* (`signal.reason` or an `AbortError` for an abort). An error thrown by `abort` does not replace it.
|
|
13
9
|
*
|
|
14
|
-
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or
|
|
15
|
-
*
|
|
16
|
-
*
|
|
10
|
+
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
|
|
11
|
+
* not a positive safe integer (checked before the sink is touched), or `render` returns a block
|
|
12
|
+
* of the wrong length.
|
|
17
13
|
*/
|
|
18
14
|
export async function renderOfflineAudio(totalFrames, blockSizes, render, sink, signal) {
|
|
19
15
|
if (totalFrames < 0n ||
|
|
@@ -23,7 +19,7 @@ export async function renderOfflineAudio(totalFrames, blockSizes, render, sink,
|
|
|
23
19
|
}
|
|
24
20
|
let position = 0n;
|
|
25
21
|
let block = 0;
|
|
26
|
-
//
|
|
22
|
+
// Also checked after `finish`, so a late cancel never reports success.
|
|
27
23
|
const throwIfAborted = () => {
|
|
28
24
|
if (signal?.aborted === true)
|
|
29
25
|
throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
package/dist/builder.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* seconds (or exact ticks) and ids generated deterministically.
|
|
2
|
+
* Fluent builder for project documents. Times are seconds or exact ticks; ids are deterministic.
|
|
4
3
|
*
|
|
5
4
|
* ```ts
|
|
6
5
|
* const project = new ProjectBuilder({ name: "Intro", width: 1920, height: 1080, frameRate: 30 });
|
|
@@ -9,31 +8,30 @@
|
|
|
9
8
|
* const document = project.build(); // passes validateProject, or throws
|
|
10
9
|
* ```
|
|
11
10
|
*/
|
|
12
|
-
import type { TextStyle, Clip, ClipEffect, ClipTransition, CompositionNode, Generator, Project, Rgb, Track } from "./generated/project-schema.js";
|
|
13
|
-
/** An exact time in ticks
|
|
11
|
+
import type { TextContent, TextStyle, TextStylePatch, Clip, ClipEffect, ClipTransition, CompositionNode, Generator, Project, Rgb, Track } from "./generated/project-schema.js";
|
|
12
|
+
/** An exact time in ticks. */
|
|
14
13
|
export interface Ticks {
|
|
15
14
|
readonly ticks: number;
|
|
16
15
|
}
|
|
17
16
|
/** Seconds, or exact {@link ticks}. */
|
|
18
17
|
export type Time = number | Ticks;
|
|
19
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* An exact time of `count` ticks.
|
|
20
|
+
*
|
|
21
|
+
* @throws RangeError Unless `count` is a safe integer.
|
|
22
|
+
*/
|
|
20
23
|
export declare function ticks(count: number): Ticks;
|
|
21
24
|
/**
|
|
22
|
-
*
|
|
25
|
+
* Converts to ticks, rounding seconds to the nearest tick.
|
|
23
26
|
*
|
|
24
|
-
* @throws RangeError For seconds
|
|
27
|
+
* @throws RangeError For non-finite seconds.
|
|
25
28
|
*/
|
|
26
29
|
export declare function toTicks(time: Time): number;
|
|
27
|
-
/** What a generated id names. */
|
|
28
30
|
export type IdKind = "source" | "track" | "clip" | "composition";
|
|
29
|
-
/**
|
|
30
|
-
* Makes ids: called with what the id names, in build order. A builder skips an id it already holds
|
|
31
|
-
* of that kind, given explicitly or generated, and calls again.
|
|
32
|
-
*/
|
|
31
|
+
/** Called in build order; the builder calls again when an id of that kind is already taken. */
|
|
33
32
|
export type IdGenerator = (kind: IdKind) => string;
|
|
34
|
-
/** `source-1`, `track-1`, `clip-1
|
|
33
|
+
/** Generates `source-1`, `track-1`, `clip-1` and so on, counted per kind. */
|
|
35
34
|
export declare function sequentialIds(): IdGenerator;
|
|
36
|
-
/** The settings a {@link ProjectBuilder} starts from. */
|
|
37
35
|
export interface ProjectBuilderOptions {
|
|
38
36
|
readonly name: string;
|
|
39
37
|
/** Project id (default `project`). */
|
|
@@ -47,15 +45,11 @@ export interface ProjectBuilderOptions {
|
|
|
47
45
|
};
|
|
48
46
|
/** Audio sample rate (default 48 000). */
|
|
49
47
|
readonly sampleRate?: number;
|
|
50
|
-
/** Canvas color behind every track
|
|
48
|
+
/** Canvas color behind every track. */
|
|
51
49
|
readonly background?: Rgb;
|
|
52
|
-
/**
|
|
53
|
-
* How generated ids are made (default {@link sequentialIds}). An id the builder already holds
|
|
54
|
-
* is skipped, so explicit ids such as `clip-2` and generated ones mix freely.
|
|
55
|
-
*/
|
|
50
|
+
/** Default {@link sequentialIds}. Ids already taken are skipped, so explicit ids mix freely. */
|
|
56
51
|
readonly ids?: IdGenerator;
|
|
57
52
|
}
|
|
58
|
-
/** A clip to place: where on the timeline, how long, and from where in the source. */
|
|
59
53
|
export interface ClipOptions {
|
|
60
54
|
readonly source: string;
|
|
61
55
|
/** Timeline start. */
|
|
@@ -63,77 +57,69 @@ export interface ClipOptions {
|
|
|
63
57
|
readonly duration: Time;
|
|
64
58
|
/** Source start (default 0). */
|
|
65
59
|
readonly sourceIn?: Time;
|
|
66
|
-
/**
|
|
67
|
-
* Source duration (default `duration`: untouched speed). Twice `duration` plays twice as fast.
|
|
68
|
-
*/
|
|
60
|
+
/** Source duration (default `duration`). Twice `duration` plays twice as fast. */
|
|
69
61
|
readonly sourceDuration?: Time;
|
|
70
|
-
/**
|
|
62
|
+
/** Time-stretches instead of resampling at non-unit speed (sets `audio.preserve_pitch`). */
|
|
63
|
+
readonly preservePitch?: boolean;
|
|
71
64
|
readonly id?: string;
|
|
72
65
|
/**
|
|
73
|
-
* Effects applied in order
|
|
74
|
-
*
|
|
75
|
-
* `with.composition` together are refused.
|
|
66
|
+
* Effects applied in order, added as a composition chain for this clip. Cannot be combined with
|
|
67
|
+
* `with.composition`.
|
|
76
68
|
*/
|
|
77
69
|
readonly effects?: readonly ClipEffect[];
|
|
78
|
-
/** Any other clip fields
|
|
70
|
+
/** Any other clip fields, such as visual, blend mode or masks. */
|
|
79
71
|
readonly with?: Partial<Omit<Clip, "id" | "source_id" | "timeline_range" | "source_range">>;
|
|
80
72
|
}
|
|
81
|
-
/** A cue to show on a caption track. */
|
|
82
73
|
export interface CueOptions {
|
|
83
74
|
readonly at: Time;
|
|
84
75
|
readonly duration: Time;
|
|
85
|
-
|
|
76
|
+
/** A string or runs. A run's `time` is in ticks from the cue start (for karaoke timing). */
|
|
77
|
+
readonly text: TextContent;
|
|
78
|
+
/** A track style with this name applies when the cue names no `style`. */
|
|
79
|
+
readonly speaker?: string;
|
|
80
|
+
/** Name of a track style, applied over the track's base style. */
|
|
81
|
+
readonly style?: string;
|
|
86
82
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Builds one project document. Nothing is checked until {@link ProjectBuilder.build}
|
|
89
|
-
* validates the whole document.
|
|
90
|
-
*/
|
|
83
|
+
/** Builds one project document. Validation happens only in {@link ProjectBuilder.build}. */
|
|
91
84
|
export declare class ProjectBuilder {
|
|
92
85
|
#private;
|
|
93
86
|
constructor(options: ProjectBuilderOptions);
|
|
94
|
-
/** Adds a media source
|
|
87
|
+
/** Adds a host-resolved media source and returns its id. */
|
|
95
88
|
source(kind: "video" | "audio" | "image", locator: string, options?: {
|
|
96
89
|
readonly id?: string;
|
|
97
90
|
readonly hasAudio?: boolean;
|
|
98
91
|
}): string;
|
|
99
92
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
93
|
+
* Source ids mapped to locators, usable as the `assets` of a native export (`@alpha2-sh/node`)
|
|
94
|
+
* when locators are file paths. Relative paths resolve against the exporting process's working
|
|
95
|
+
* directory.
|
|
103
96
|
*/
|
|
104
97
|
assets(): Record<string, string>;
|
|
105
|
-
/** Adds a source
|
|
98
|
+
/** Adds a generated source and returns its id. */
|
|
106
99
|
generated(generator: Generator, options?: {
|
|
107
100
|
readonly id?: string;
|
|
108
101
|
}): string;
|
|
109
|
-
/**
|
|
110
|
-
* Adds a composition graph for clips to show (with `ClipOptions.with`'s `composition`); returns
|
|
111
|
-
* its id.
|
|
112
|
-
*/
|
|
102
|
+
/** Adds a composition graph for clips to reference via `with.composition`; returns its id. */
|
|
113
103
|
composition(nodes: readonly CompositionNode[], output: string | null, options?: {
|
|
114
104
|
readonly id?: string;
|
|
115
105
|
}): string;
|
|
116
|
-
/** Adds a visual track, drawn over
|
|
106
|
+
/** Adds a visual track, drawn over earlier tracks. */
|
|
117
107
|
videoTrack(options?: {
|
|
118
108
|
readonly id?: string;
|
|
119
109
|
readonly name?: string;
|
|
120
110
|
}): TrackBuilder;
|
|
121
|
-
/** Adds an audio track. */
|
|
122
111
|
audioTrack(options?: {
|
|
123
112
|
readonly id?: string;
|
|
124
113
|
readonly name?: string;
|
|
125
114
|
}): TrackBuilder;
|
|
126
|
-
/** Adds a caption track
|
|
115
|
+
/** Adds a caption track. Cues pick from the named `styles` by `style` or `speaker`. */
|
|
127
116
|
captionTrack(options?: {
|
|
128
117
|
readonly id?: string;
|
|
129
118
|
readonly name?: string;
|
|
130
119
|
readonly style?: TextStyle;
|
|
120
|
+
readonly styles?: Readonly<Record<string, TextStylePatch>>;
|
|
131
121
|
}): CaptionTrackBuilder;
|
|
132
|
-
/**
|
|
133
|
-
* The document.
|
|
134
|
-
*
|
|
135
|
-
* @throws {RangeError} Listing every problem when it does not validate.
|
|
136
|
-
*/
|
|
122
|
+
/** @throws {RangeError} Listing every problem when the document does not validate. */
|
|
137
123
|
build(): Project;
|
|
138
124
|
}
|
|
139
125
|
/** Clips and transitions of one visual or audio track. */
|
|
@@ -141,22 +127,19 @@ export declare class TrackBuilder {
|
|
|
141
127
|
#private;
|
|
142
128
|
/** @internal */
|
|
143
129
|
constructor(id: string, name: string, kind: "video" | "audio", clipId: (explicit: string | undefined) => string, chain: (effects: readonly ClipEffect[]) => string);
|
|
144
|
-
/** The track's id. */
|
|
145
130
|
get id(): string;
|
|
146
131
|
/**
|
|
147
|
-
* Places a clip
|
|
148
|
-
* is added to the project and the clip shows it.
|
|
132
|
+
* Places a clip and returns its id. `effects` adds a composition chaining them.
|
|
149
133
|
*
|
|
150
|
-
* @throws RangeError For `effects`
|
|
151
|
-
*
|
|
134
|
+
* @throws RangeError For `effects` with `with.composition`, or a non-finite time; nothing is
|
|
135
|
+
* added then.
|
|
152
136
|
*/
|
|
153
137
|
clip(options: ClipOptions): string;
|
|
154
138
|
/**
|
|
155
|
-
*
|
|
156
|
-
* meet.
|
|
139
|
+
* Adds a transition from `from` to `to` over the time the two clips overlap.
|
|
157
140
|
*
|
|
158
|
-
* @throws RangeError When either clip is not on this track. An overlap
|
|
159
|
-
*
|
|
141
|
+
* @throws RangeError When either clip is not on this track. An invalid overlap is reported by
|
|
142
|
+
* {@link ProjectBuilder.build}.
|
|
160
143
|
*/
|
|
161
144
|
transition(from: string, to: string, effect: ClipTransition["effect"], easing?: ClipTransition["easing"]): this;
|
|
162
145
|
/** @internal */
|
|
@@ -166,10 +149,9 @@ export declare class TrackBuilder {
|
|
|
166
149
|
export declare class CaptionTrackBuilder {
|
|
167
150
|
#private;
|
|
168
151
|
/** @internal */
|
|
169
|
-
constructor(id: string, name: string, style: TextStyle);
|
|
170
|
-
/** The track's id. */
|
|
152
|
+
constructor(id: string, name: string, style: TextStyle, styles: Readonly<Record<string, TextStylePatch>>);
|
|
171
153
|
get id(): string;
|
|
172
|
-
/**
|
|
154
|
+
/** Adds a cue. Cues may be added in any order. */
|
|
173
155
|
cue(options: CueOptions): this;
|
|
174
156
|
/** @internal */
|
|
175
157
|
build(): Track;
|