@motionscript/browser 0.1.0-alpha.7 → 0.1.0-alpha.8
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/CHANGELOG.md +6 -0
- package/NOTICE +15 -14
- package/README.md +66 -43
- package/dist/asset-bytes.d.ts +7 -4
- package/dist/asset-bytes.d.ts.map +1 -1
- package/dist/asset-bytes.js +9 -4
- package/dist/asset-bytes.js.map +1 -1
- package/dist/audio/bus-graph.d.ts.map +1 -1
- package/dist/audio/bus-graph.js +15 -6
- package/dist/audio/bus-graph.js.map +1 -1
- package/dist/audio/effect-graph.d.ts +62 -0
- package/dist/audio/effect-graph.d.ts.map +1 -0
- package/dist/audio/effect-graph.js +234 -0
- package/dist/audio/effect-graph.js.map +1 -0
- package/dist/audio/index.d.ts.map +1 -1
- package/dist/audio/index.js +2 -3
- package/dist/audio/index.js.map +1 -1
- package/dist/audio/mixer.d.ts +4 -4
- package/dist/audio/mixer.d.ts.map +1 -1
- package/dist/audio/mixer.js +18 -38
- package/dist/audio/mixer.js.map +1 -1
- package/dist/audio/player.d.ts +12 -6
- package/dist/audio/player.d.ts.map +1 -1
- package/dist/audio/player.js +49 -62
- package/dist/audio/player.js.map +1 -1
- package/dist/browser/THIRD_PARTY_LICENSES.txt +379 -27
- package/dist/browser/audio.js +1 -1
- package/dist/browser/chunks/chunk-IILVN4SK.js +2 -0
- package/dist/browser/chunks/chunk-IILVN4SK.js.map +7 -0
- package/dist/browser/chunks/chunk-KLXMRKTL.js +2 -0
- package/dist/browser/chunks/chunk-L5UFQACH.js +163 -0
- package/dist/browser/chunks/chunk-L5UFQACH.js.map +7 -0
- package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js +14 -0
- package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js.map +7 -0
- package/dist/browser/index.js +51 -1343
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/manifest.json +8 -8
- package/dist/browser/ms_renderer_bg.wasm +0 -0
- package/dist/canvaskit-renderer.d.ts +8 -0
- package/dist/canvaskit-renderer.d.ts.map +1 -0
- package/dist/canvaskit-renderer.js +23 -0
- package/dist/canvaskit-renderer.js.map +1 -0
- package/dist/concat.d.ts +33 -7
- package/dist/concat.d.ts.map +1 -1
- package/dist/concat.js +117 -72
- package/dist/concat.js.map +1 -1
- package/dist/deliver.d.ts +10 -0
- package/dist/deliver.d.ts.map +1 -0
- package/dist/deliver.js +22 -0
- package/dist/deliver.js.map +1 -0
- package/dist/dynamic-nodes.d.ts.map +1 -1
- package/dist/dynamic-nodes.js +2 -3
- package/dist/dynamic-nodes.js.map +1 -1
- package/dist/engine.d.ts +37 -9
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +41 -32
- package/dist/engine.js.map +1 -1
- package/dist/export-audio.d.ts +36 -0
- package/dist/export-audio.d.ts.map +1 -0
- package/dist/export-audio.js +56 -0
- package/dist/export-audio.js.map +1 -0
- package/dist/exporter.d.ts +125 -14
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +133 -89
- package/dist/exporter.js.map +1 -1
- package/dist/formats.d.ts +36 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/formats.js +83 -0
- package/dist/formats.js.map +1 -0
- package/dist/frame-loop.d.ts +190 -0
- package/dist/frame-loop.d.ts.map +1 -0
- package/dist/frame-loop.js +304 -0
- package/dist/frame-loop.js.map +1 -0
- package/dist/getter.d.ts +4 -1
- package/dist/getter.d.ts.map +1 -1
- package/dist/getter.js +7 -6
- package/dist/getter.js.map +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -21
- package/dist/index.js.map +1 -1
- package/dist/mix-timeline-audio.d.ts +5 -5
- package/dist/mix-timeline-audio.d.ts.map +1 -1
- package/dist/mix-timeline-audio.js +10 -12
- package/dist/mix-timeline-audio.js.map +1 -1
- package/dist/parallel/export-parallel.d.ts +32 -0
- package/dist/parallel/export-parallel.d.ts.map +1 -0
- package/dist/parallel/export-parallel.js +114 -0
- package/dist/parallel/export-parallel.js.map +1 -0
- package/dist/parallel/governor.d.ts +57 -0
- package/dist/parallel/governor.d.ts.map +1 -0
- package/dist/parallel/governor.js +79 -0
- package/dist/parallel/governor.js.map +1 -0
- package/dist/parallel/lane.d.ts +45 -0
- package/dist/parallel/lane.d.ts.map +1 -0
- package/dist/parallel/lane.js +2 -0
- package/dist/parallel/lane.js.map +1 -0
- package/dist/parallel/lanes.d.ts +20 -0
- package/dist/parallel/lanes.d.ts.map +1 -0
- package/dist/parallel/lanes.js +152 -0
- package/dist/parallel/lanes.js.map +1 -0
- package/dist/parallel/plan.d.ts +23 -0
- package/dist/parallel/plan.d.ts.map +1 -0
- package/dist/parallel/plan.js +30 -0
- package/dist/parallel/plan.js.map +1 -0
- package/dist/parallel/run-lanes.d.ts +38 -0
- package/dist/parallel/run-lanes.d.ts.map +1 -0
- package/dist/parallel/run-lanes.js +164 -0
- package/dist/parallel/run-lanes.js.map +1 -0
- package/dist/parallel/session.d.ts +9 -0
- package/dist/parallel/session.d.ts.map +1 -0
- package/dist/parallel/session.js +79 -0
- package/dist/parallel/session.js.map +1 -0
- package/dist/render-context.d.ts +2 -0
- package/dist/render-context.d.ts.map +1 -1
- package/dist/render-context.js +8 -4
- package/dist/render-context.js.map +1 -1
- package/dist/renderer.d.ts +22 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +23 -0
- package/dist/renderer.js.map +1 -0
- package/dist/screenshot.d.ts +4 -4
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +3 -3
- package/dist/screenshot.js.map +1 -1
- package/dist/still.d.ts +17 -19
- package/dist/still.d.ts.map +1 -1
- package/dist/still.js +27 -34
- package/dist/still.js.map +1 -1
- package/dist/ticker.d.ts +22 -8
- package/dist/ticker.d.ts.map +1 -1
- package/dist/ticker.js +55 -20
- package/dist/ticker.js.map +1 -1
- package/package.json +9 -10
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js +0 -2
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js.map +0 -7
- package/dist/browser/chunks/SkeletonUtils-XYDMTGTM.js +0 -2
- package/dist/browser/chunks/chunk-2MAFJWBZ.js +0 -2
- package/dist/browser/chunks/chunk-2MAFJWBZ.js.map +0 -7
- package/dist/browser/chunks/chunk-CTLBXZSU.js +0 -4119
- package/dist/browser/chunks/chunk-CTLBXZSU.js.map +0 -7
- package/dist/browser/chunks/chunk-FQ32PDIU.js +0 -2
- package/dist/browser/chunks/chunk-FQ32PDIU.js.map +0 -7
- package/dist/browser/chunks/chunk-FY3BTKY4.js +0 -2
- package/dist/browser/chunks/chunk-FY3BTKY4.js.map +0 -7
- package/dist/browser/chunks/three.module-Z4EOVUWF.js +0 -2
- package/dist/browser/chunks/three.module-Z4EOVUWF.js.map +0 -7
- /package/dist/browser/chunks/{SkeletonUtils-XYDMTGTM.js.map → chunk-KLXMRKTL.js.map} +0 -0
package/CHANGELOG.md
CHANGED
package/NOTICE
CHANGED
|
@@ -4,24 +4,25 @@ Copyright 2026 Motionscript LLC
|
|
|
4
4
|
This product includes the third-party code below, each part under the MIT
|
|
5
5
|
License reproduced at the end of this file.
|
|
6
6
|
|
|
7
|
-
- packages/
|
|
8
|
-
Sine" by David Hoskins (https://www.shadertoy.com/view/4djSRW).
|
|
7
|
+
- packages/renderer/crates/renderer/src/shaders/prim.wgsl (`fn_hash2`):
|
|
8
|
+
"Hash without Sine" by David Hoskins (https://www.shadertoy.com/view/4djSRW).
|
|
9
9
|
Copyright (c) 2014 David Hoskins.
|
|
10
10
|
|
|
11
|
-
- packages/
|
|
12
|
-
|
|
13
|
-
Copyright (c) 2013 Inigo Quilez.
|
|
11
|
+
- packages/renderer/crates/renderer/src/shaders/prim.wgsl (`simplex_noise`): "Noise - simplex - 2D" by Inigo Quilez
|
|
12
|
+
(https://www.shadertoy.com/view/Msf3WH). Copyright (c) 2013 Inigo Quilez.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(https://github.com/ashima/webgl-noise). Copyright (C) 2011 by Ashima Arts.
|
|
14
|
+
- packages/renderer/crates/render3d (in @motionscript/renderer's WebAssembly):
|
|
15
|
+
its shaders (src/shaders/mesh.wgsl) port three.js r185's mesh programs and
|
|
16
|
+
src/geometry.rs its primitive generators (https://threejs.org).
|
|
17
|
+
Copyright (c) 2010-2026 three.js authors.
|
|
20
18
|
|
|
21
|
-
@motionscript/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
packages/
|
|
19
|
+
@motionscript/renderer's WebAssembly (dist/ms_renderer_bg.wasm) compiles in
|
|
20
|
+
Rust crates under MIT, Apache-2.0, Zlib and Unicode-3.0 terms (wgpu, naga,
|
|
21
|
+
harfrust, read-fonts, kurbo, wasm-bindgen and others); their notices are in
|
|
22
|
+
packages/renderer/THIRD_PARTY_NOTICES.txt.
|
|
23
|
+
|
|
24
|
+
MP3 export loads @mediabunny/mp3-encoder (MPL-2.0), a WebAssembly build of
|
|
25
|
+
the LAME MP3 encoder (LGPL, https://lame.sourceforge.io), on first use.
|
|
25
26
|
|
|
26
27
|
The browser builds under dist/browser/ bundle each package's npm dependencies;
|
|
27
28
|
dist/browser/THIRD_PARTY_LICENSES.txt in each package lists them with their
|
package/README.md
CHANGED
|
@@ -1,97 +1,118 @@
|
|
|
1
1
|
# @motionscript/browser
|
|
2
2
|
|
|
3
|
-
The browser
|
|
4
|
-
|
|
3
|
+
The browser platform for [Motion Script](https://motionscript.dev): it draws
|
|
4
|
+
every frame with WebGPU through [`@motionscript/renderer`](https://github.com/motionscript-dev/motionscript/tree/main/packages/renderer), which it
|
|
5
|
+
builds in. It implements the
|
|
5
6
|
`platform`/`render` abstractions from [`@motionscript/core`](https://github.com/motionscript-dev/motionscript/tree/main/packages/core) so
|
|
6
7
|
documents can be drawn to a canvas, played back with synchronized audio, and
|
|
7
8
|
exported to video all in the browser.
|
|
8
9
|
|
|
9
|
-
How a frame is drawn (shapes, fills, strokes, effects, text,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
How a frame is drawn (shapes, fills, strokes, effects, text, 3D) lives in the
|
|
11
|
+
renderer (Rust/wgpu compiled to WebAssembly). This package supplies the browser's
|
|
12
|
+
half: the export frame loop, encoding, Web Audio, the clock and the entry points.
|
|
13
|
+
A browser without WebGPU cannot draw: every entry that draws rejects with
|
|
14
|
+
`WebGpuUnavailableError` (check `isWgpuSupported()` first to say so up front).
|
|
14
15
|
|
|
15
16
|
## What's in here
|
|
16
17
|
|
|
17
18
|
- **Engine**: `createBrowserEngine` wires every platform seam below into a
|
|
18
19
|
`@motionscript/core` `Engine`. Await it once at app start and share it.
|
|
19
|
-
- **Render context**: `WebRenderContext` draws the `@motionscript/core` scene
|
|
20
|
-
graph (shapes, fills, strokes, effects, text, video, masks) onto a CanvasKit
|
|
21
|
-
surface.
|
|
22
20
|
- **Exporter**: `exportVideo` renders a document offline and muxes video and
|
|
23
|
-
audio into an MP4
|
|
21
|
+
audio into an MP4 (H.264 + AAC, the default) or a WebM (VP9 + Opus) using
|
|
22
|
+
[mediabunny](https://github.com/Vanilagy/mediabunny). `exportAudio` writes the
|
|
23
|
+
timeline's mixed audio alone as WAV (the default), MP3 or M4A without rendering
|
|
24
|
+
a frame, and throws `NoAudioError` when nothing plays. `EXPORT_FORMATS` gives
|
|
25
|
+
each format's kind, extension and MIME type. MP3 loads a WASM build of LAME on
|
|
26
|
+
first use, in a worker started from a `blob:` URL, so a host's CSP needs
|
|
27
|
+
`worker-src blob:` for it.
|
|
24
28
|
- **Stills**: `StillRenderer` (from `createStillRenderer`) is a long-lived
|
|
25
29
|
renderer that repaints single frames into a canvas the host owns, for
|
|
26
30
|
thumbnails and previews; `exportScreenshot` is the one-shot wrapper over it.
|
|
27
|
-
- **Concat**: `concatVideoSegments` joins separately encoded MP4
|
|
28
|
-
without re-encoding, so an export can be split across workers. A segment is
|
|
31
|
+
- **Concat**: `concatVideoSegments` joins separately encoded MP4 (or WebM)
|
|
32
|
+
segments into one file of the same container without re-encoding, so an export can be split across workers. A segment is
|
|
29
33
|
`exportVideo({ frames: { start, end } })` (or `session.export({ frames })`):
|
|
30
34
|
that range alone, timestamped from 0 and silent.
|
|
31
35
|
`mixTimelineAudio` mixes the whole timeline's audio once for the joined file.
|
|
32
36
|
Every segment must share one encoder configuration; a mismatch throws
|
|
33
37
|
`ConcatMismatchError`.
|
|
34
|
-
- **
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
- **Parallel export**: `exportVideoParallel` takes `exportVideo`'s parameters
|
|
39
|
+
plus `lanes`, the renderers to spread the frames over: `localLane()` for
|
|
40
|
+
this page, and `messagePortLane(port)` for another realm (a second window or
|
|
41
|
+
process) that answers with `serveExportLane(port, resolve)`. It cuts the
|
|
42
|
+
timeline into key-frame-aligned frame ranges of the whole project, starts on
|
|
43
|
+
the first lane alone and admits the next only while that raises throughput
|
|
44
|
+
(every lane's encoder shares the browser's one GPU process, so light scenes
|
|
45
|
+
gain nothing from a second lane), mixes the audio once while the frames
|
|
46
|
+
render, joins each range as soon as the ones before it are done (into
|
|
47
|
+
`stream` when given) and reports progress by frames drawn.
|
|
48
|
+
`createSegmentJoiner` is the incremental join underneath.
|
|
37
49
|
- **Audio**: `WebAudioPlayer` drives playback through the Web Audio API;
|
|
38
50
|
`mixAudio` and `encodeWav` (also on the `@motionscript/browser/audio`
|
|
39
|
-
subpath, which skips
|
|
40
|
-
- **
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
levels (`src/decode/`); see
|
|
44
|
-
[decode resolution](https://github.com/motionscript-dev/motionscript/blob/main/packages/skia-render/docs/decode-resolution.md).
|
|
45
|
-
`setAssetByteSource` lets a host answer for an asset's bytes (a file the user just
|
|
46
|
-
chose, say) before the adapter goes to the network; it applies to previews,
|
|
47
|
-
exports and stills alike.
|
|
51
|
+
subpath, which skips the renderer) mix down offline.
|
|
52
|
+
- **Assets**: `setAssetByteSource` lets a host answer for an asset's bytes (a file
|
|
53
|
+
the user just chose, say) before the renderer's storage goes to the network; it
|
|
54
|
+
applies to previews, exports and stills alike. `loadAssetBytes` reads through it.
|
|
48
55
|
- **Source-string nodes**: `createBrowserEngine({ nodes })` also accepts TS source
|
|
49
56
|
strings (array form only), each default-exporting a component (`component2d({ key })`),
|
|
50
57
|
compiled with `esbuild-wasm` on first use. A script is written with calls: JSX
|
|
51
58
|
neither compiles nor links. `dynamicNodes` overrides the SDK, extra importable
|
|
52
59
|
`modules` or the compiler, each field defaulting on its own.
|
|
53
60
|
- **Clock**: `WebTicker` synchronizes scene playback to `requestAnimationFrame` while calculating dt from audio context to ensure audio and animation line up.
|
|
54
|
-
- **
|
|
55
|
-
|
|
61
|
+
- **Renderer**: `isWgpuSupported`, `onWgpuEvent` (device loss and recovery), and
|
|
62
|
+
the WGSL shader tools `ShaderPreview`, `validateShader` and `WGSL_PRELUDE`, from
|
|
63
|
+
`@motionscript/renderer`.
|
|
56
64
|
|
|
57
65
|
## Usage
|
|
58
66
|
|
|
59
67
|
```bash
|
|
60
|
-
npm install @motionscript/browser @motionscript/core
|
|
68
|
+
npm install @motionscript/browser @motionscript/core
|
|
61
69
|
```
|
|
62
70
|
|
|
63
71
|
```ts
|
|
64
72
|
import { createBrowserEngine } from '@motionscript/browser';
|
|
65
73
|
|
|
66
|
-
const engine = await createBrowserEngine({
|
|
74
|
+
const engine = await createBrowserEngine({ nodes: [MyNode] });
|
|
67
75
|
const session = engine.open({ document, target: canvasEl });
|
|
68
76
|
session.playback!.play();
|
|
69
77
|
|
|
70
78
|
const mp4 = await session.export();
|
|
71
79
|
```
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
`encode: { download: true }` asks for a browser download
|
|
81
|
+
The renderer's `ms_renderer_bg.wasm` resolves beside its module, which a bundler
|
|
82
|
+
handles; elsewhere serve it and pass its URL as `rendererWasmUrl` (every entry
|
|
83
|
+
that draws takes it). `session.export()` resolves to the MP4 bytes unless
|
|
84
|
+
`encode: { download: true }` asks for a browser download; `encode: { format }`
|
|
85
|
+
picks another format (`'webm'`, or `'wav'`, `'mp3'` or `'m4a'` for audio alone).
|
|
86
|
+
|
|
87
|
+
## Render issues and GPU faults
|
|
88
|
+
|
|
89
|
+
What the renderer drew but not as the document says (a feature it lacks, a shader
|
|
90
|
+
that does not compile, a lost GPU device) is a typed `RenderIssue`: a session
|
|
91
|
+
lists it in `buildErrors`, and `exportVideo`, `exportVideoParallel`,
|
|
92
|
+
`session.export()`, `session.image()` and `StillRenderer.render` hand it to
|
|
93
|
+
`onIssue`. A lost device or a crashed backend fails those instead with a
|
|
94
|
+
`RenderBackendError` (from `@motionscript/core`; `retryable` when the backend
|
|
95
|
+
recovered on a new device).
|
|
96
|
+
|
|
97
|
+
A shader stored in the retired SkSL language (`language: "sksl"`, from documents
|
|
98
|
+
written before WGSL was the only one) draws nothing and is reported as a `shader`
|
|
99
|
+
issue asking for a WGSL port.
|
|
77
100
|
|
|
78
101
|
## CDN build
|
|
79
102
|
|
|
80
103
|
`pnpm build` ends by writing `dist/browser/` (generated, never edited): one minified
|
|
81
|
-
ES module per `exports` entry (`index.js`, `audio.js`), shared and lazy chunks
|
|
82
|
-
(three.js and its glTF loader arrive only through `import()`), `esbuild.wasm`, and a
|
|
104
|
+
ES module per `exports` entry (`index.js`, `audio.js`), shared and lazy chunks, `esbuild.wasm`, `ms_renderer_bg.wasm`, and a
|
|
83
105
|
`manifest.json` mapping each export and binary asset to a package-relative path.
|
|
84
|
-
The peers stay imports, so a host's import map names each
|
|
85
|
-
once, to one copy:
|
|
106
|
+
The renderer is bundled in; the peers stay imports, so a host's import map names each
|
|
107
|
+
of these bare specifiers once, to one copy:
|
|
86
108
|
|
|
87
109
|
```
|
|
88
110
|
@motionscript/core
|
|
89
111
|
@motionscript/core/sdk
|
|
90
|
-
@motionscript/canvaskit
|
|
91
112
|
```
|
|
92
113
|
|
|
93
|
-
Against a CDN module URL the default `
|
|
94
|
-
resolve, so a host passes `
|
|
114
|
+
Against a CDN module URL the default `ms_renderer_bg.wasm` and `esbuild.wasm` URLs do
|
|
115
|
+
not resolve, so a host passes `rendererWasmUrl` and, if it compiles source-string nodes,
|
|
95
116
|
`compilerWasmUrl`. Both binaries are listed in the packages' manifests.
|
|
96
117
|
|
|
97
118
|
See the [docs](https://motionscript.dev/docs) for the full feature set and API
|
|
@@ -106,10 +127,12 @@ pnpm --filter @motionscript/browser build # eslint, tsc, tsc-alias, then the C
|
|
|
106
127
|
pnpm --filter @motionscript/browser test # vitest: real Chromium, plus a Node project
|
|
107
128
|
```
|
|
108
129
|
|
|
109
|
-
The tests run in
|
|
130
|
+
The tests run in Chromium on SwiftShader's WebGPU adapter through
|
|
131
|
+
`@vitest/browser-playwright` (headed with `HEADED=1`, which Linux needs, under
|
|
132
|
+
`xvfb-run`: a headless page there reads a WebGPU canvas back empty), so install it
|
|
110
133
|
once with `pnpm --filter @motionscript/browser exec playwright install --with-deps chromium`.
|
|
111
|
-
They import
|
|
112
|
-
checkout. Files named `*.node.test.ts` run in Node and ask what a consumer's bundler
|
|
134
|
+
They import the **built** `dist/` of core and the renderer: run `pnpm build:lib` (Rust
|
|
135
|
+
needed) first on a fresh checkout. Files named `*.node.test.ts` run in Node and ask what a consumer's bundler
|
|
113
136
|
keeps of this package (`tree-shaking`, `cdn-build`). Suites that need an H.264 or AAC
|
|
114
137
|
encoder skip on a Chromium without one; `REQUIRE_ENCODERS=1` makes them fail instead.
|
|
115
138
|
|
package/dist/asset-bytes.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where a source URL's bytes come from: a host's local store, then the network.
|
|
3
|
+
* The renderer's storage adapter reads every asset through it (`loadBytes`).
|
|
3
4
|
*
|
|
4
5
|
* ## Why the web adapter needs this at all
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* The storage adapter addresses every asset by URL and fetches it. That is
|
|
7
8
|
* right for an asset that lives somewhere, and wrong for one whose bytes the
|
|
8
9
|
* host already has in hand — a file the user has just chosen, a render a local
|
|
9
10
|
* model has just produced, a picture whose upload has not finished or cannot
|
|
@@ -16,9 +17,9 @@
|
|
|
16
17
|
*
|
|
17
18
|
* ## Why it is module-level
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* The storage adapter is constructed at several sites *inside* this package —
|
|
21
|
+
* sessions, the exporter, the audio mixer and the still renderer — none of
|
|
22
|
+
* which a host can reach. A constructor argument would
|
|
22
23
|
* therefore cover the preview and leave export and stills on the network,
|
|
23
24
|
* which is the worst of both: the picture a user sees would come from local
|
|
24
25
|
* bytes and the one they render would not.
|
|
@@ -53,4 +54,6 @@ export declare function localAssetBytes(src: string): Promise<Blob | null>;
|
|
|
53
54
|
* with no face in it.
|
|
54
55
|
*/
|
|
55
56
|
export declare function fetchAssetBytes(url: string): Promise<Blob>;
|
|
57
|
+
/** The bytes for `src`: the host's local store first, then the network. */
|
|
58
|
+
export declare function loadAssetBytes(src: string): Promise<Blob>;
|
|
56
59
|
//# sourceMappingURL=asset-bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-bytes.d.ts","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"asset-bytes.d.ts","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AAIpE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAErE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAOvE;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhE;AAED,2EAA2E;AAC3E,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D"}
|
package/dist/asset-bytes.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where a source URL's bytes come from: a host's local store, then the network.
|
|
3
|
+
* The renderer's storage adapter reads every asset through it (`loadBytes`).
|
|
3
4
|
*
|
|
4
5
|
* ## Why the web adapter needs this at all
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* The storage adapter addresses every asset by URL and fetches it. That is
|
|
7
8
|
* right for an asset that lives somewhere, and wrong for one whose bytes the
|
|
8
9
|
* host already has in hand — a file the user has just chosen, a render a local
|
|
9
10
|
* model has just produced, a picture whose upload has not finished or cannot
|
|
@@ -16,9 +17,9 @@
|
|
|
16
17
|
*
|
|
17
18
|
* ## Why it is module-level
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* The storage adapter is constructed at several sites *inside* this package —
|
|
21
|
+
* sessions, the exporter, the audio mixer and the still renderer — none of
|
|
22
|
+
* which a host can reach. A constructor argument would
|
|
22
23
|
* therefore cover the preview and leave export and stills on the network,
|
|
23
24
|
* which is the worst of both: the picture a user sees would come from local
|
|
24
25
|
* bytes and the one they render would not.
|
|
@@ -70,4 +71,8 @@ export async function fetchAssetBytes(url) {
|
|
|
70
71
|
}
|
|
71
72
|
return response.blob();
|
|
72
73
|
}
|
|
74
|
+
/** The bytes for `src`: the host's local store first, then the network. */
|
|
75
|
+
export async function loadAssetBytes(src) {
|
|
76
|
+
return (await localAssetBytes(src)) ?? fetchAssetBytes(src);
|
|
77
|
+
}
|
|
73
78
|
//# sourceMappingURL=asset-bytes.js.map
|
package/dist/asset-bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-bytes.js","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"asset-bytes.js","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAKH,IAAI,MAAM,GAA2B,IAAI,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAA4B;IAC3D,MAAM,GAAG,IAAI,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC7C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxG,MAAM,IAAI,KAAK,CAAC,aAAa,GAAG,kBAAkB,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW;IAC5C,OAAO,CAAC,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\r\n * Where a source URL's bytes come from: a host's local store, then the network.\r\n * The renderer's storage adapter reads every asset through it (`loadBytes`).\r\n *\r\n * ## Why the web adapter needs this at all\r\n *\r\n * The storage adapter addresses every asset by URL and fetches it. That is\r\n * right for an asset that lives somewhere, and wrong for one whose bytes the\r\n * host already has in hand — a file the user has just chosen, a render a local\r\n * model has just produced, a picture whose upload has not finished or cannot\r\n * start because there is no network. In all three the adapter downloads bytes\r\n * that never needed to travel.\r\n *\r\n * `NodeStorageAdapter` has had the answer since it was written: an injected\r\n * `AssetLoader`, with an `inline` map consulted ahead of the disk. This is the\r\n * same seam for the browser.\r\n *\r\n * ## Why it is module-level\r\n *\r\n * The storage adapter is constructed at several sites *inside* this package —\r\n * sessions, the exporter, the audio mixer and the still renderer — none of\r\n * which a host can reach. A constructor argument would\r\n * therefore cover the preview and leave export and stills on the network,\r\n * which is the worst of both: the picture a user sees would come from local\r\n * bytes and the one they render would not.\r\n *\r\n * So this is an *injection point*, not a cache. The adapter still owns every\r\n * decode, every cache, every size ceiling and every eviction rule; all this\r\n * changes is where the compressed bytes came from. A source that answers `null`\r\n * — which is what an unregistered URL, an evicted entry or a host with no local\r\n * store does — leaves the adapter exactly as it was.\r\n */\r\n\r\n/** Local bytes for a source URL, or `null` to go to the network. */\r\nexport type AssetByteSource = (src: string) => Promise<Blob | null>;\r\n\r\nlet source: AssetByteSource | null = null;\r\n\r\n/**\r\n * Installs the byte source for this browsing context, or clears it with `null`.\r\n *\r\n * Called once per window that renders. Later calls replace the previous source\r\n * rather than stacking, because two sources disagreeing about one URL has no\r\n * sensible answer.\r\n */\r\nexport function setAssetByteSource(next: AssetByteSource | null): void {\r\n source = next;\r\n}\r\n\r\n/**\r\n * The bytes for `src`, or `null`.\r\n *\r\n * Swallows a throwing source on purpose. A host's local store failing is a\r\n * cache miss, not a render failure — the caller falls through to `fetch`, which\r\n * is what it would have done had the source never been installed.\r\n */\r\nexport async function localAssetBytes(src: string): Promise<Blob | null> {\r\n if (!source) return null;\r\n try {\r\n return await source(src);\r\n } catch {\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * The network's bytes for `url`. A response that is not OK is a failed load,\r\n * never bytes: a 404 page handed to the font manager marked a family loaded\r\n * with no face in it.\r\n */\r\nexport async function fetchAssetBytes(url: string): Promise<Blob> {\r\n const response = await fetch(url);\r\n if (!response.ok) {\r\n const status = response.statusText ? `${response.status} ${response.statusText}` : `${response.status}`;\r\n throw new Error(`Fetching \"${url}\" failed: HTTP ${status}`);\r\n }\r\n return response.blob();\r\n}\r\n\r\n/** The bytes for `src`: the host's local store first, then the network. */\r\nexport async function loadAssetBytes(src: string): Promise<Blob> {\r\n return (await localAssetBytes(src)) ?? fetchAssetBytes(src);\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bus-graph.d.ts","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"bus-graph.d.ts","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAGrF;;;;;;;;GAQG;AACH,qBAAa,aAAa;IAElB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAFX,GAAG,EAAE,gBAAgB;IACtC,+EAA+E;IAC9D,WAAW,EAAE,SAAS;IAG3C;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,GAAG,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS;IAKlG,+GAA+G;IAC/G,OAAO,IAAI,IAAI;IAYf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;IAEpD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,SAAS;CAuCpB"}
|
package/dist/audio/bus-graph.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { busStopKey } from "@motionscript/core";
|
|
2
|
-
import {
|
|
2
|
+
import { applyTransitions, buildAudioEffectGraph } from "./effect-graph";
|
|
3
3
|
/**
|
|
4
4
|
* The live chains for one audio context's buses.
|
|
5
5
|
*
|
|
@@ -80,14 +80,23 @@ export class AudioBusGraph {
|
|
|
80
80
|
return existing;
|
|
81
81
|
const output = this.chainFrom(bus, index + 1, startTime, clipTime);
|
|
82
82
|
// A pass-through head every clip connects to, so the bus has one input
|
|
83
|
-
// whatever its
|
|
83
|
+
// whatever its effects turn out to be.
|
|
84
84
|
const input = this.ctx.createGain();
|
|
85
85
|
input.gain.value = 1;
|
|
86
|
-
// The level is a gain after the
|
|
87
|
-
//
|
|
86
|
+
// The level is a gain after the effects, as a sound's own level is, so a
|
|
87
|
+
// ramp on it is scheduled exactly as one in `effects` is.
|
|
88
88
|
const level = { type: "gain", value: stop.mute ? 0 : stop.volume };
|
|
89
|
-
const
|
|
90
|
-
graph.
|
|
89
|
+
const span = stop.endAt - stop.startAt;
|
|
90
|
+
const graph = buildAudioEffectGraph(this.ctx, input, [...(stop.effects ?? []), level], startTime, span, clipTime - stop.startAt);
|
|
91
|
+
let tail = graph.output;
|
|
92
|
+
if (stop.transitionIn || stop.transitionOut) {
|
|
93
|
+
const transition = this.ctx.createGain();
|
|
94
|
+
applyTransitions(transition.gain, span, stop.transitionIn, stop.transitionOut, startTime, clipTime - stop.startAt);
|
|
95
|
+
tail.connect(transition);
|
|
96
|
+
this.nodes.push(transition);
|
|
97
|
+
tail = transition;
|
|
98
|
+
}
|
|
99
|
+
tail.connect(output);
|
|
91
100
|
this.nodes.push(input, ...graph.nodes);
|
|
92
101
|
this.oscillators.push(...graph.oscillators);
|
|
93
102
|
for (const osc of graph.oscillators)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bus-graph.js","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"bus-graph.js","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuC,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IAED;IAEA;IAHrB,YACqB,GAAqB;IACtC,+EAA+E;IAC9D,WAAsB;QAFtB,QAAG,GAAH,GAAG,CAAkB;QAErB,gBAAW,GAAX,WAAW,CAAW;IACvC,CAAC;IAEL;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,GAAwC,EAAE,SAAiB,EAAE,QAAgB;QAClF,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC;QACtD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC;gBAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC;QAChE,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,IAAI,CAAC;gBAAC,GAAG,CAAC,IAAI,EAA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AO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import { busStopKey, type AudioBusStop, type AudioEffect } from \"@motionscript/core\";\r\nimport { applyTransitions, buildAudioEffectGraph } from \"./effect-graph\";\r\n\r\n/**\r\n * The live chains for one audio context's buses.\r\n *\r\n * Held per context rather than per clip, because that is the whole difference\r\n * between a bus and per-clip processing: every clip naming a bus connects into\r\n * the *same* nodes, so a reverb on a bus is one tail the group shares rather\r\n * than one tail each. Flattening the levels into per-clip gain would sound\r\n * right; flattening the effects would not.\r\n */\r\nexport class AudioBusGraph {\r\n constructor(\r\n private readonly ctx: BaseAudioContext,\r\n /** Where the last bus in a chain connects — the master, or the destination. */\r\n private readonly destination: AudioNode,\r\n ) { }\r\n\r\n /**\r\n * The input node a clip on `bus` should connect to, building the chain the\r\n * first time it is asked for.\r\n *\r\n * `bus` is source-adjacent first, so `bus[0]` is the one the clip feeds and\r\n * each stop after it is that bus's own parent. An empty or absent chain\r\n * returns the destination, which is what every clip did before buses\r\n * existed.\r\n *\r\n * `startTime` is the context time a new chain's schedule starts from, and\r\n * `clipTime` the same instant in the stops' own seconds. A curve on a stop\r\n * runs over its `startAt`–`endAt`, so the two are what place it.\r\n */\r\n inputFor(bus: readonly AudioBusStop[] | undefined, startTime: number, clipTime: number): AudioNode {\r\n if (!bus || bus.length === 0) return this.destination;\r\n return this.chainFrom(bus, 0, startTime, clipTime);\r\n }\r\n\r\n /** Disconnect every live bus node, so the next {@link inputFor} builds afresh. Safe to call more than once. */\r\n dispose(): void {\r\n for (const node of this.nodes) {\r\n try { node.disconnect(); } catch { /* already torn down */ }\r\n }\r\n for (const osc of this.oscillators) {\r\n try { osc.stop(); } catch { /* never started, or already stopped */ }\r\n }\r\n this.nodes.length = 0;\r\n this.oscillators.length = 0;\r\n this.inputs.clear();\r\n }\r\n\r\n private readonly inputs = new Map<string, AudioNode>();\r\n private readonly nodes: AudioNode[] = [];\r\n private readonly oscillators: OscillatorNode[] = [];\r\n\r\n /**\r\n * Build (or reuse) the chain for `bus[index]`, connected to whatever\r\n * `bus[index + 1]` resolves to.\r\n *\r\n * Recursive rather than iterative because a bus's *output* has to exist\r\n * before its own nodes can connect to it, and the outermost bus is the last\r\n * entry.\r\n *\r\n * Reused by everything that changes what it sounds like, down to the master,\r\n * not by id alone: a bus edited under a playing device, or one id on two\r\n * tracks, is a different chain, and one built for the first would play the\r\n * second through stale levels and a curve anchored to the wrong span.\r\n */\r\n private chainFrom(bus: readonly AudioBusStop[], index: number, startTime: number, clipTime: number): AudioNode {\r\n if (index >= bus.length) return this.destination;\r\n\r\n const stop = bus[index];\r\n const key = bus.slice(index).map(busStopKey).join(\">\");\r\n const existing = this.inputs.get(key);\r\n if (existing) return existing;\r\n\r\n const output = this.chainFrom(bus, index + 1, startTime, clipTime);\r\n\r\n // A pass-through head every clip connects to, so the bus has one input\r\n // whatever its effects turn out to be.\r\n const input = this.ctx.createGain();\r\n input.gain.value = 1;\r\n\r\n // The level is a gain after the effects, as a sound's own level is, so a\r\n // ramp on it is scheduled exactly as one in `effects` is.\r\n const level: AudioEffect = { type: \"gain\", value: stop.mute ? 0 : stop.volume };\r\n const span = stop.endAt - stop.startAt;\r\n const graph = buildAudioEffectGraph(\r\n this.ctx, input, [...(stop.effects ?? []), level], startTime, span, clipTime - stop.startAt,\r\n );\r\n let tail = graph.output;\r\n if (stop.transitionIn || stop.transitionOut) {\r\n const transition = this.ctx.createGain();\r\n applyTransitions(transition.gain, span, stop.transitionIn, stop.transitionOut, startTime, clipTime - stop.startAt);\r\n tail.connect(transition);\r\n this.nodes.push(transition);\r\n tail = transition;\r\n }\r\n tail.connect(output);\r\n\r\n this.nodes.push(input, ...graph.nodes);\r\n this.oscillators.push(...graph.oscillators);\r\n for (const osc of graph.oscillators) osc.start(startTime);\r\n\r\n this.inputs.set(key, input);\r\n return input;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type AudioEffect, type AudioRequest, type AudioTransition, type Ramp } from "@motionscript/core";
|
|
2
|
+
/**
|
|
3
|
+
* The Web Audio graph for one source's effect chain.
|
|
4
|
+
*
|
|
5
|
+
* `output` is the last node, to connect downstream; `nodes` are every node to
|
|
6
|
+
* `disconnect()` on teardown; `oscillators` are tremolo LFOs the caller starts
|
|
7
|
+
* and stops alongside the source.
|
|
8
|
+
*/
|
|
9
|
+
export interface AudioEffectGraph {
|
|
10
|
+
output: AudioNode;
|
|
11
|
+
nodes: AudioNode[];
|
|
12
|
+
oscillators: OscillatorNode[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the Web Audio graph for a clip's effect chain, after an
|
|
16
|
+
* already-created `source`. Shared by live playback ({@link WebAudioSink}) and
|
|
17
|
+
* offline export (`mixAudio`) so both sound identical.
|
|
18
|
+
*
|
|
19
|
+
* `startTime` is the context time the source starts; `clipDuration` the clip
|
|
20
|
+
* seconds ramps run over (a clip's, or a bus's span); `elapsed` the clip seconds
|
|
21
|
+
* already played at a mid-clip seek (0 for a clean start, negative before the
|
|
22
|
+
* span begins).
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildAudioEffectGraph(ctx: BaseAudioContext, source: AudioNode, effects: readonly AudioEffect[], startTime?: number, clipDuration?: number, elapsed?: number): AudioEffectGraph;
|
|
25
|
+
/**
|
|
26
|
+
* Schedule `transitionIn`/`transitionOut` onto a gain over a span `length`
|
|
27
|
+
* seconds long, baked like an eased ramp. Between the two it holds at 1.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyTransitions(gain: AudioParam, length: number, transitionIn: AudioTransition | undefined, transitionOut: AudioTransition | undefined, startTime: number, elapsed: number): void;
|
|
30
|
+
/** How one request plays its source: the rate, and the lengths its ramps and transitions run over. */
|
|
31
|
+
export interface Playback {
|
|
32
|
+
/** The constant `playbackRate`; 1 under a ramp, which is scheduled instead. */
|
|
33
|
+
rate: number;
|
|
34
|
+
speedRamp?: Ramp;
|
|
35
|
+
/** Source seconds a speed ramp is placed on. */
|
|
36
|
+
sourceLength: number;
|
|
37
|
+
/** Clip seconds the volume and effect ramps run over. */
|
|
38
|
+
clipDuration: number;
|
|
39
|
+
/** What the transitions run over: the clip's length, unknown for an open one. */
|
|
40
|
+
transitionLength: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function playbackOf(req: AudioRequest, bufferDuration: number): Playback;
|
|
43
|
+
/** Source seconds after `trimStart` that `clipElapsed` clip seconds have played. */
|
|
44
|
+
export declare function sourceOffsetOf(playback: Playback, clipElapsed: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* A request's level, then its transitions, after `from`: the gains every
|
|
47
|
+
* request plays through on its way to its bus.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildLevel(ctx: BaseAudioContext, from: AudioNode, req: AudioRequest, playback: Playback, startTime: number, elapsed: number): {
|
|
50
|
+
output: AudioNode;
|
|
51
|
+
nodes: AudioNode[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Schedule a speed ramp onto an `AudioBufferSourceNode.playbackRate`.
|
|
55
|
+
*
|
|
56
|
+
* The ramp runs over **source** seconds and Web Audio schedules in context
|
|
57
|
+
* seconds, so this walks clip time in small steps, converts each to a source
|
|
58
|
+
* offset through the integral inverse, and lays down the rate there. `elapsed`
|
|
59
|
+
* is clip seconds already played at a mid-clip seek.
|
|
60
|
+
*/
|
|
61
|
+
export declare function applySpeedToPlaybackRate(rate: AudioParam, speed: Ramp | undefined, sourceLength: number, clipDuration: number, startTime: number, elapsed: number): void;
|
|
62
|
+
//# sourceMappingURL=effect-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect-graph.d.ts","sourceRoot":"","sources":["../../src/audio/effect-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,eAAe,EAEpB,KAAK,IAAI,EACZ,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC7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