@motionscript/browser 0.1.0-alpha.8 → 0.1.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/CHANGELOG.md +22 -0
- package/LICENSE +201 -201
- package/NOTICE +49 -49
- package/README.md +141 -141
- package/dist/asset-bytes.js.map +1 -1
- package/dist/audio/bus-graph.js.map +1 -1
- package/dist/audio/effect-graph.js.map +1 -1
- package/dist/audio/index.js.map +1 -1
- package/dist/audio/loop-region.js.map +1 -1
- package/dist/audio/mixer.js.map +1 -1
- package/dist/audio/player.js.map +1 -1
- package/dist/browser/audio.js +1 -1
- package/dist/browser/chunks/{chunk-IILVN4SK.js → chunk-F3AZKPHU.js} +1 -1
- package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
- package/dist/browser/index.js +20 -20
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/ms_renderer_bg.wasm +0 -0
- package/dist/concat.js.map +1 -1
- package/dist/dynamic-nodes.js.map +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/export-audio.js.map +1 -1
- package/dist/exporter.js.map +1 -1
- package/dist/frame-loop.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mix-timeline-audio.js.map +1 -1
- package/dist/parallel/export-parallel.js.map +1 -1
- package/dist/parallel/lane.js.map +1 -1
- package/dist/parallel/run-lanes.js.map +1 -1
- package/dist/parallel/session.js.map +1 -1
- package/dist/renderer.js.map +1 -1
- package/dist/screenshot.js.map +1 -1
- package/dist/still.js.map +1 -1
- package/dist/ticker.js.map +1 -1
- package/package.json +4 -4
- package/dist/audio/filter-graph.d.ts +0 -59
- package/dist/audio/filter-graph.d.ts.map +0 -1
- package/dist/audio/filter-graph.js +0 -241
- package/dist/audio/filter-graph.js.map +0 -1
- package/dist/browser/chunks/chunk-IILVN4SK.js.map +0 -7
- package/dist/canvaskit-renderer.d.ts +0 -8
- package/dist/canvaskit-renderer.d.ts.map +0 -1
- package/dist/canvaskit-renderer.js +0 -23
- package/dist/canvaskit-renderer.js.map +0 -1
- package/dist/decode/image-levels.d.ts +0 -137
- package/dist/decode/image-levels.d.ts.map +0 -1
- package/dist/decode/image-levels.js +0 -477
- package/dist/decode/image-levels.js.map +0 -1
- package/dist/decode/levels.d.ts +0 -37
- package/dist/decode/levels.d.ts.map +0 -1
- package/dist/decode/levels.js +0 -68
- package/dist/decode/levels.js.map +0 -1
- package/dist/decode/video-levels.d.ts +0 -37
- package/dist/decode/video-levels.d.ts.map +0 -1
- package/dist/decode/video-levels.js +0 -95
- package/dist/decode/video-levels.js.map +0 -1
- package/dist/getter.d.ts +0 -13
- package/dist/getter.d.ts.map +0 -1
- package/dist/getter.js +0 -39
- package/dist/getter.js.map +0 -1
- package/dist/measure-context.d.ts +0 -12
- package/dist/measure-context.d.ts.map +0 -1
- package/dist/measure-context.js +0 -12
- package/dist/measure-context.js.map +0 -1
- package/dist/render-context.d.ts +0 -34
- package/dist/render-context.d.ts.map +0 -1
- package/dist/render-context.js +0 -63
- package/dist/render-context.js.map +0 -1
- package/dist/storage-adapter.d.ts +0 -367
- package/dist/storage-adapter.d.ts.map +0 -1
- package/dist/storage-adapter.js +0 -1280
- package/dist/storage-adapter.js.map +0 -1
- package/dist/three/renderer.d.ts +0 -47
- package/dist/three/renderer.d.ts.map +0 -1
- package/dist/three/renderer.js +0 -182
- package/dist/three/renderer.js.map +0 -1
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { isCurve, sourceTimeAtClipElapsed } from "@motionscript/core";
|
|
2
|
-
/**
|
|
3
|
-
* How many sample points per second to bake an eased curve segment into for
|
|
4
|
-
* `setValueCurveAtTime`. 200/s (≈ every 5ms) is smooth to the ear and cheap.
|
|
5
|
-
*/
|
|
6
|
-
const CURVE_SAMPLES_PER_SECOND = 200;
|
|
7
|
-
/**
|
|
8
|
-
* Apply a (possibly time-varying) {@link Param} to a Web Audio {@link AudioParam}.
|
|
9
|
-
*
|
|
10
|
-
* - **number** → set once (today's behavior; zero scheduling overhead).
|
|
11
|
-
* - **Curve** → resolve against `clipDuration` and schedule each segment:
|
|
12
|
-
* - linear segments via `setValueAtTime` + `linearRampToValueAtTime`,
|
|
13
|
-
* - eased segments baked into a `Float32Array` via `setValueCurveAtTime`.
|
|
14
|
-
*
|
|
15
|
-
* `elapsed` (clip-seconds already played when a mid-clip seek starts the source)
|
|
16
|
-
* shifts the schedule back by `elapsed` so "now" reads the curve's value at the
|
|
17
|
-
* clip's *current* position, not its start. A `clamp(v)` hook lets a param keep a
|
|
18
|
-
* valid range (e.g. echo mix 0–1) at every sampled point.
|
|
19
|
-
*/
|
|
20
|
-
function applyParam(ctx, audioParam, param, startTime, clipDuration, elapsed, clamp = (v) => v) {
|
|
21
|
-
// Coerce to a finite value before touching an AudioParam — the platform throws
|
|
22
|
-
// on NaN/Infinity. Falls back to the current param value (never undefined here).
|
|
23
|
-
const finite = (v) => {
|
|
24
|
-
const c = clamp(v);
|
|
25
|
-
return Number.isFinite(c) ? c : audioParam.value;
|
|
26
|
-
};
|
|
27
|
-
if (!isCurve(param)) {
|
|
28
|
-
audioParam.value = finite(param);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// A non-finite clip length yields no usable schedule; hold the curve's start value.
|
|
32
|
-
if (!Number.isFinite(clipDuration) || clipDuration <= 0) {
|
|
33
|
-
audioParam.value = finite(param.staticValue(audioParam.value));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const base = startTime - elapsed; // map curve t=0 to here so seeks line up
|
|
37
|
-
const resolved = param.resolve(clipDuration, audioParam.value);
|
|
38
|
-
if (resolved.length === 0)
|
|
39
|
-
return;
|
|
40
|
-
// Anchor the starting value at `startTime` (the seek point) so there is no
|
|
41
|
-
// jump from the param's default before the first scheduled segment runs.
|
|
42
|
-
const startValue = param.sampleAt(Math.max(0, elapsed), clipDuration, audioParam.value);
|
|
43
|
-
audioParam.setValueAtTime(finite(startValue), startTime);
|
|
44
|
-
for (const seg of resolved) {
|
|
45
|
-
const segStart = base + seg.startTime;
|
|
46
|
-
const segEnd = base + seg.endTime;
|
|
47
|
-
// Skip segments wholly in the past relative to the seek point, or any with a
|
|
48
|
-
// non-finite boundary (degenerate resolve) that would throw on schedule.
|
|
49
|
-
if (segEnd <= startTime || !Number.isFinite(segStart) || !Number.isFinite(segEnd))
|
|
50
|
-
continue;
|
|
51
|
-
const span = seg.endTime - seg.startTime;
|
|
52
|
-
if (span <= 0) {
|
|
53
|
-
audioParam.setValueAtTime(finite(seg.to), Math.max(segStart, startTime));
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
// How far through this segment the seek lands. A segment already under way
|
|
57
|
-
// carries on from the anchor rather than starting over from its `from` —
|
|
58
|
-
// the case a bus hits whenever its first clip enters partway through it.
|
|
59
|
-
const done = Math.max(0, (startTime - segStart) / span);
|
|
60
|
-
const curveStart = Math.max(segStart, startTime);
|
|
61
|
-
if (seg.isLinear) {
|
|
62
|
-
if (done === 0)
|
|
63
|
-
audioParam.setValueAtTime(finite(seg.from), curveStart);
|
|
64
|
-
audioParam.linearRampToValueAtTime(finite(seg.to), segEnd);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const curveDur = segEnd - curveStart;
|
|
68
|
-
if (curveDur <= 0)
|
|
69
|
-
continue;
|
|
70
|
-
const count = Math.max(2, Math.ceil(curveDur * CURVE_SAMPLES_PER_SECOND));
|
|
71
|
-
const samples = new Float32Array(count);
|
|
72
|
-
for (let i = 0; i < count; i++) {
|
|
73
|
-
const local = done + (1 - done) * (i / (count - 1));
|
|
74
|
-
samples[i] = finite(seg.from + (seg.to - seg.from) * seg.ease(local));
|
|
75
|
-
}
|
|
76
|
-
audioParam.setValueCurveAtTime(samples, curveStart, curveDur);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Builds the Web Audio graph for a clip's filter chain, returning the node to
|
|
82
|
-
* connect downstream. Shared by live playback ({@link WebAudioSink}) and
|
|
83
|
-
* offline export (`mixAudio`) so both paths sound identical.
|
|
84
|
-
*
|
|
85
|
-
* Filters apply in array order (index 0 closest to the source). `speed` filters
|
|
86
|
-
* are intentionally ignored here — they're realized via `source.playbackRate`
|
|
87
|
-
* by the caller (and affect timeline scheduling), not as a graph node.
|
|
88
|
-
*
|
|
89
|
-
* `startTime` is the AudioContext time the source starts; `clipDuration` is the
|
|
90
|
-
* clip-time length the curves run over (a clip's, or a bus's span); `elapsed` is
|
|
91
|
-
* clip-seconds already played at a mid-clip seek (0 for a clean start, negative
|
|
92
|
-
* before the span begins). These let curve-valued params schedule and align.
|
|
93
|
-
*
|
|
94
|
-
* Pass the already-created `source` so its `playbackRate` can be set by the
|
|
95
|
-
* caller; this function only wires nodes *after* the source.
|
|
96
|
-
*/
|
|
97
|
-
export function buildAudioFilterGraph(ctx, source, filters, startTime = ctx.currentTime, clipDuration = 0, elapsed = 0) {
|
|
98
|
-
const nodes = [];
|
|
99
|
-
const oscillators = [];
|
|
100
|
-
let cursor = source;
|
|
101
|
-
const series = (node) => {
|
|
102
|
-
cursor.connect(node);
|
|
103
|
-
nodes.push(node);
|
|
104
|
-
cursor = node;
|
|
105
|
-
};
|
|
106
|
-
const apply = (p, v, clamp) => applyParam(ctx, p, v, startTime, clipDuration, elapsed, clamp);
|
|
107
|
-
for (const filter of filters) {
|
|
108
|
-
switch (filter.type) {
|
|
109
|
-
case "gain": {
|
|
110
|
-
const gain = ctx.createGain();
|
|
111
|
-
apply(gain.gain, filter.value);
|
|
112
|
-
series(gain);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
case "highpass":
|
|
116
|
-
case "lowpass": {
|
|
117
|
-
const biquad = ctx.createBiquadFilter();
|
|
118
|
-
biquad.type = filter.type === "highpass" ? "highpass" : "lowpass";
|
|
119
|
-
apply(biquad.frequency, filter.frequency);
|
|
120
|
-
if (filter.q !== undefined)
|
|
121
|
-
apply(biquad.Q, filter.q);
|
|
122
|
-
series(biquad);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
case "tremolo": {
|
|
126
|
-
// Carrier gain whose value is modulated by an LFO. With depth d the
|
|
127
|
-
// carrier base = (1 - d/2) and the LFO swing gain = d/2. The clamp
|
|
128
|
-
// hook applies these transforms whether depth is scalar or a curve.
|
|
129
|
-
const carrier = ctx.createGain();
|
|
130
|
-
const lfo = ctx.createOscillator();
|
|
131
|
-
const lfoDepth = ctx.createGain();
|
|
132
|
-
apply(carrier.gain, filter.depth, (d) => 1 - clamp01(d) / 2);
|
|
133
|
-
apply(lfoDepth.gain, filter.depth, (d) => clamp01(d) / 2);
|
|
134
|
-
apply(lfo.frequency, filter.rate);
|
|
135
|
-
lfo.connect(lfoDepth);
|
|
136
|
-
lfoDepth.connect(carrier.gain);
|
|
137
|
-
nodes.push(lfoDepth);
|
|
138
|
-
oscillators.push(lfo);
|
|
139
|
-
series(carrier);
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
case "echo": {
|
|
143
|
-
// Dry + wet split. The wet path is a delay with feedback; both sum
|
|
144
|
-
// into a merge node that becomes the new cursor.
|
|
145
|
-
const split = cursor;
|
|
146
|
-
const merge = ctx.createGain();
|
|
147
|
-
const dry = ctx.createGain();
|
|
148
|
-
apply(dry.gain, filter.mix ?? 0.5, (m) => 1 - clamp01(m));
|
|
149
|
-
split.connect(dry);
|
|
150
|
-
dry.connect(merge);
|
|
151
|
-
// Delay buffer must accommodate the max delay; size from the static value.
|
|
152
|
-
const maxDelay = staticOf(filter.delay);
|
|
153
|
-
const delay = ctx.createDelay(Math.max(1, maxDelay + 1));
|
|
154
|
-
apply(delay.delayTime, filter.delay);
|
|
155
|
-
const feedbackGain = ctx.createGain();
|
|
156
|
-
apply(feedbackGain.gain, filter.feedback, (f) => Math.max(0, Math.min(0.99, f)));
|
|
157
|
-
const wet = ctx.createGain();
|
|
158
|
-
apply(wet.gain, filter.mix ?? 0.5, (m) => clamp01(m));
|
|
159
|
-
split.connect(delay);
|
|
160
|
-
delay.connect(feedbackGain);
|
|
161
|
-
feedbackGain.connect(delay); // feedback loop
|
|
162
|
-
delay.connect(wet);
|
|
163
|
-
wet.connect(merge);
|
|
164
|
-
nodes.push(dry, delay, feedbackGain, wet, merge);
|
|
165
|
-
cursor = merge;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case "speed":
|
|
169
|
-
// Realized via source.playbackRate by the caller; no graph node.
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return { output: cursor, nodes, oscillators };
|
|
174
|
-
}
|
|
175
|
-
/** Clamp to [0, 1]. */
|
|
176
|
-
function clamp01(v) {
|
|
177
|
-
return Math.max(0, Math.min(1, v));
|
|
178
|
-
}
|
|
179
|
-
/** The static/representative number of a param (number itself, or curve's t=0 value). */
|
|
180
|
-
function staticOf(p) {
|
|
181
|
-
return isCurve(p) ? p.staticValue(0) : p;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Net *constant* playback-rate multiplier from any scalar `speed` filters in the
|
|
185
|
-
* chain (product of all), defaulting to 1. Curve-valued speeds contribute 1 here
|
|
186
|
-
* and are scheduled separately by {@link applySpeedToPlaybackRate}. Mirrors
|
|
187
|
-
* `Sound.effectiveSpeed()` so the renderer applies the same rate the core timeline
|
|
188
|
-
* reserved time for.
|
|
189
|
-
*/
|
|
190
|
-
export function effectiveSpeed(filters) {
|
|
191
|
-
if (!filters)
|
|
192
|
-
return 1;
|
|
193
|
-
let speed = 1;
|
|
194
|
-
for (const f of filters) {
|
|
195
|
-
if (f.type === "speed" && !isCurve(f.value) && f.value > 0)
|
|
196
|
-
speed *= f.value;
|
|
197
|
-
}
|
|
198
|
-
return speed;
|
|
199
|
-
}
|
|
200
|
-
/** The first curve-valued `speed` filter in the chain, if any. */
|
|
201
|
-
export function speedCurveOf(filters) {
|
|
202
|
-
if (!filters)
|
|
203
|
-
return undefined;
|
|
204
|
-
for (const f of filters) {
|
|
205
|
-
if (f.type === "speed" && isCurve(f.value))
|
|
206
|
-
return f.value;
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Schedule a time-varying speed curve onto an `AudioBufferSourceNode.playbackRate`.
|
|
212
|
-
*
|
|
213
|
-
* The curve is authored over **source time** (rate as a function of how far through
|
|
214
|
-
* the source we've played). `setValueAtTime`/`linearRampToValueAtTime` schedule in
|
|
215
|
-
* **context time**, so we walk clip-time forward in small steps, convert each to a
|
|
216
|
-
* source-time offset via the integral inverse, read the curve there, and lay down a
|
|
217
|
-
* value point at the matching context time. `scalar` folds in any constant speed
|
|
218
|
-
* filters (they scale the whole rate uniformly).
|
|
219
|
-
*
|
|
220
|
-
* `elapsed` is clip-seconds already played at a mid-clip seek, so the schedule
|
|
221
|
-
* starts at the seek point and aligns the playbackRate to the clip's true position.
|
|
222
|
-
*/
|
|
223
|
-
export function applySpeedToPlaybackRate(rate, curve, sourceLength, clipDuration, scalar, startTime, elapsed) {
|
|
224
|
-
if (!curve)
|
|
225
|
-
return;
|
|
226
|
-
const step = 1 / CURVE_SAMPLES_PER_SECOND; // clip-time sampling step
|
|
227
|
-
const seekAt = Math.max(0, elapsed);
|
|
228
|
-
// Seed the value exactly at the seek point.
|
|
229
|
-
const seedSrc = sourceTimeAtClipElapsed(curve, sourceLength, seekAt);
|
|
230
|
-
rate.setValueAtTime(Math.max(1e-4, curve.sampleAt(seedSrc, sourceLength, 1) * scalar), startTime);
|
|
231
|
-
for (let s = seekAt + step; s <= clipDuration + step; s += step) {
|
|
232
|
-
const clampedElapsed = Math.min(s, clipDuration);
|
|
233
|
-
const srcT = sourceTimeAtClipElapsed(curve, sourceLength, clampedElapsed);
|
|
234
|
-
const value = Math.max(1e-4, curve.sampleAt(srcT, sourceLength, 1) * scalar);
|
|
235
|
-
const ctxTime = startTime + (clampedElapsed - seekAt);
|
|
236
|
-
rate.linearRampToValueAtTime(value, ctxTime);
|
|
237
|
-
if (clampedElapsed >= clipDuration)
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
//# sourceMappingURL=filter-graph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-graph.js","sourceRoot":"","sources":["../../src/audio/filter-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAkB9F;;;GAGG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,SAAS,UAAU,CACf,GAAqB,EACrB,UAAsB,EACtB,KAAY,EACZ,SAAiB,EACjB,YAAoB,EACpB,OAAe,EACf,QAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEvC,+EAA+E;IAC/E,iFAAiF;IACjF,MAAM,MAAM,GAAG,CAAC,CAAS,EAAU,EAAE;QACjC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IACrD,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO;IACX,CAAC;IAED,oFAAoF;IACpF,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;QACtD,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,OAAO;IACX,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,yCAAyC;IAC3E,MAAM,QAAQ,GAAG,KAA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CAAC,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,cAAc,IAAI,YAAY;YAAE,MAAM;IAC9C,CAAC;AACL,CAAC","sourcesContent":["import { AudioFilterItem, Param, isCurve, sourceTimeAtClipElapsed } from \"@motionscript/core\";\r\n\r\n/**\r\n * Result of building an audio-filter graph for one source.\r\n *\r\n * - `output` is the last node in the chain; connect it downstream (e.g. to the\r\n * per-request gain node).\r\n * - `nodes` are every intermediate node, so callers can `disconnect()` them on\r\n * teardown.\r\n * - `oscillators` are LFOs (from `tremolo`) the caller must `start()` — and may\r\n * `stop()` — alongside the source, since oscillators need an explicit start.\r\n */\r\nexport interface AudioFilterGraph {\r\n output: AudioNode;\r\n nodes: AudioNode[];\r\n oscillators: OscillatorNode[];\r\n}\r\n\r\n/**\r\n * How many sample points per second to bake an eased curve segment into for\r\n * `setValueCurveAtTime`. 200/s (≈ every 5ms) is smooth to the ear and cheap.\r\n */\r\nconst CURVE_SAMPLES_PER_SECOND = 200;\r\n\r\n/**\r\n * Apply a (possibly time-varying) {@link Param} to a Web Audio {@link AudioParam}.\r\n *\r\n * - **number** → set once (today's behavior; zero scheduling overhead).\r\n * - **Curve** → resolve against `clipDuration` and schedule each segment:\r\n * - linear segments via `setValueAtTime` + `linearRampToValueAtTime`,\r\n * - eased segments baked into a `Float32Array` via `setValueCurveAtTime`.\r\n *\r\n * `elapsed` (clip-seconds already played when a mid-clip seek starts the source)\r\n * shifts the schedule back by `elapsed` so \"now\" reads the curve's value at the\r\n * clip's *current* position, not its start. A `clamp(v)` hook lets a param keep a\r\n * valid range (e.g. echo mix 0–1) at every sampled point.\r\n */\r\nfunction applyParam(\r\n ctx: BaseAudioContext,\r\n audioParam: AudioParam,\r\n param: Param,\r\n startTime: number,\r\n clipDuration: number,\r\n elapsed: number,\r\n clamp: (v: number) => number = (v) => v,\r\n): void {\r\n // Coerce to a finite value before touching an AudioParam — the platform throws\r\n // on NaN/Infinity. Falls back to the current param value (never undefined here).\r\n const finite = (v: number): number => {\r\n const c = clamp(v);\r\n return Number.isFinite(c) ? c : audioParam.value;\r\n };\r\n\r\n if (!isCurve(param)) {\r\n audioParam.value = finite(param);\r\n return;\r\n }\r\n\r\n // A non-finite clip length yields no usable schedule; hold the curve's start value.\r\n if (!Number.isFinite(clipDuration) || clipDuration <= 0) {\r\n audioParam.value = finite(param.staticValue(audioParam.value));\r\n return;\r\n }\r\n\r\n const base = startTime - elapsed; // map curve t=0 to here so seeks line up\r\n const resolved = param.resolve(clipDuration, audioParam.value);\r\n if (resolved.length === 0) return;\r\n\r\n // Anchor the starting value at `startTime` (the seek point) so there is no\r\n // jump from the param's default before the first scheduled segment runs.\r\n const startValue = param.sampleAt(Math.max(0, elapsed), clipDuration, audioParam.value);\r\n audioParam.setValueAtTime(finite(startValue), startTime);\r\n\r\n for (const seg of resolved) {\r\n const segStart = base + seg.startTime;\r\n const segEnd = base + seg.endTime;\r\n // Skip segments wholly in the past relative to the seek point, or any with a\r\n // non-finite boundary (degenerate resolve) that would throw on schedule.\r\n if (segEnd <= startTime || !Number.isFinite(segStart) || !Number.isFinite(segEnd)) continue;\r\n\r\n const span = seg.endTime - seg.startTime;\r\n\r\n if (span <= 0) {\r\n audioParam.setValueAtTime(finite(seg.to), Math.max(segStart, startTime));\r\n continue;\r\n }\r\n\r\n // How far through this segment the seek lands. A segment already under way\r\n // carries on from the anchor rather than starting over from its `from` —\r\n // the case a bus hits whenever its first clip enters partway through it.\r\n const done = Math.max(0, (startTime - segStart) / span);\r\n const curveStart = Math.max(segStart, startTime);\r\n\r\n if (seg.isLinear) {\r\n if (done === 0) audioParam.setValueAtTime(finite(seg.from), curveStart);\r\n audioParam.linearRampToValueAtTime(finite(seg.to), segEnd);\r\n } else {\r\n const curveDur = segEnd - curveStart;\r\n if (curveDur <= 0) continue;\r\n const count = Math.max(2, Math.ceil(curveDur * CURVE_SAMPLES_PER_SECOND));\r\n const samples = new Float32Array(count);\r\n for (let i = 0; i < count; i++) {\r\n const local = done + (1 - done) * (i / (count - 1));\r\n samples[i] = finite(seg.from + (seg.to - seg.from) * seg.ease(local));\r\n }\r\n audioParam.setValueCurveAtTime(samples, curveStart, curveDur);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Builds the Web Audio graph for a clip's filter chain, returning the node to\r\n * connect downstream. Shared by live playback ({@link WebAudioSink}) and\r\n * offline export (`mixAudio`) so both paths sound identical.\r\n *\r\n * Filters apply in array order (index 0 closest to the source). `speed` filters\r\n * are intentionally ignored here — they're realized via `source.playbackRate`\r\n * by the caller (and affect timeline scheduling), not as a graph node.\r\n *\r\n * `startTime` is the AudioContext time the source starts; `clipDuration` is the\r\n * clip-time length the curves run over (a clip's, or a bus's span); `elapsed` is\r\n * clip-seconds already played at a mid-clip seek (0 for a clean start, negative\r\n * before the span begins). These let curve-valued params schedule and align.\r\n *\r\n * Pass the already-created `source` so its `playbackRate` can be set by the\r\n * caller; this function only wires nodes *after* the source.\r\n */\r\nexport function buildAudioFilterGraph(\r\n ctx: BaseAudioContext,\r\n source: AudioNode,\r\n filters: readonly AudioFilterItem[],\r\n startTime: number = ctx.currentTime,\r\n clipDuration: number = 0,\r\n elapsed: number = 0,\r\n): AudioFilterGraph {\r\n const nodes: AudioNode[] = [];\r\n const oscillators: OscillatorNode[] = [];\r\n let cursor: AudioNode = source;\r\n\r\n const series = (node: AudioNode): void => {\r\n cursor.connect(node);\r\n nodes.push(node);\r\n cursor = node;\r\n };\r\n\r\n const apply = (p: AudioParam, v: Param, clamp?: (n: number) => number): void =>\r\n applyParam(ctx, p, v, startTime, clipDuration, elapsed, clamp);\r\n\r\n for (const filter of filters) {\r\n switch (filter.type) {\r\n case \"gain\": {\r\n const gain = ctx.createGain();\r\n apply(gain.gain, filter.value);\r\n series(gain);\r\n break;\r\n }\r\n case \"highpass\":\r\n case \"lowpass\": {\r\n const biquad = ctx.createBiquadFilter();\r\n biquad.type = filter.type === \"highpass\" ? \"highpass\" : \"lowpass\";\r\n apply(biquad.frequency, filter.frequency);\r\n if (filter.q !== undefined) apply(biquad.Q, filter.q);\r\n series(biquad);\r\n break;\r\n }\r\n case \"tremolo\": {\r\n // Carrier gain whose value is modulated by an LFO. With depth d the\r\n // carrier base = (1 - d/2) and the LFO swing gain = d/2. The clamp\r\n // hook applies these transforms whether depth is scalar or a curve.\r\n const carrier = ctx.createGain();\r\n const lfo = ctx.createOscillator();\r\n const lfoDepth = ctx.createGain();\r\n\r\n apply(carrier.gain, filter.depth, (d) => 1 - clamp01(d) / 2);\r\n apply(lfoDepth.gain, filter.depth, (d) => clamp01(d) / 2);\r\n apply(lfo.frequency, filter.rate);\r\n\r\n lfo.connect(lfoDepth);\r\n lfoDepth.connect(carrier.gain);\r\n\r\n nodes.push(lfoDepth);\r\n oscillators.push(lfo);\r\n series(carrier);\r\n break;\r\n }\r\n case \"echo\": {\r\n // Dry + wet split. The wet path is a delay with feedback; both sum\r\n // into a merge node that becomes the new cursor.\r\n const split = cursor;\r\n const merge = ctx.createGain();\r\n\r\n const dry = ctx.createGain();\r\n apply(dry.gain, filter.mix ?? 0.5, (m) => 1 - clamp01(m));\r\n split.connect(dry);\r\n dry.connect(merge);\r\n\r\n // Delay buffer must accommodate the max delay; size from the static value.\r\n const maxDelay = staticOf(filter.delay);\r\n const delay = ctx.createDelay(Math.max(1, maxDelay + 1));\r\n apply(delay.delayTime, filter.delay);\r\n const feedbackGain = ctx.createGain();\r\n apply(feedbackGain.gain, filter.feedback, (f) => Math.max(0, Math.min(0.99, f)));\r\n const wet = ctx.createGain();\r\n apply(wet.gain, filter.mix ?? 0.5, (m) => clamp01(m));\r\n\r\n split.connect(delay);\r\n delay.connect(feedbackGain);\r\n feedbackGain.connect(delay); // feedback loop\r\n delay.connect(wet);\r\n wet.connect(merge);\r\n\r\n nodes.push(dry, delay, feedbackGain, wet, merge);\r\n cursor = merge;\r\n break;\r\n }\r\n case \"speed\":\r\n // Realized via source.playbackRate by the caller; no graph node.\r\n break;\r\n }\r\n }\r\n\r\n return { output: cursor, nodes, oscillators };\r\n}\r\n\r\n/** Clamp to [0, 1]. */\r\nfunction clamp01(v: number): number {\r\n return Math.max(0, Math.min(1, v));\r\n}\r\n\r\n/** The static/representative number of a param (number itself, or curve's t=0 value). */\r\nfunction staticOf(p: Param): number {\r\n return isCurve(p) ? p.staticValue(0) : p;\r\n}\r\n\r\n/**\r\n * Net *constant* playback-rate multiplier from any scalar `speed` filters in the\r\n * chain (product of all), defaulting to 1. Curve-valued speeds contribute 1 here\r\n * and are scheduled separately by {@link applySpeedToPlaybackRate}. Mirrors\r\n * `Sound.effectiveSpeed()` so the renderer applies the same rate the core timeline\r\n * reserved time for.\r\n */\r\nexport function effectiveSpeed(filters: readonly AudioFilterItem[] | undefined): number {\r\n if (!filters) return 1;\r\n let speed = 1;\r\n for (const f of filters) {\r\n if (f.type === \"speed\" && !isCurve(f.value) && f.value > 0) speed *= f.value;\r\n }\r\n return speed;\r\n}\r\n\r\n/** The first curve-valued `speed` filter in the chain, if any. */\r\nexport function speedCurveOf(filters: readonly AudioFilterItem[] | undefined) {\r\n if (!filters) return undefined;\r\n for (const f of filters) {\r\n if (f.type === \"speed\" && isCurve(f.value)) return f.value;\r\n }\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Schedule a time-varying speed curve onto an `AudioBufferSourceNode.playbackRate`.\r\n *\r\n * The curve is authored over **source time** (rate as a function of how far through\r\n * the source we've played). `setValueAtTime`/`linearRampToValueAtTime` schedule in\r\n * **context time**, so we walk clip-time forward in small steps, convert each to a\r\n * source-time offset via the integral inverse, read the curve there, and lay down a\r\n * value point at the matching context time. `scalar` folds in any constant speed\r\n * filters (they scale the whole rate uniformly).\r\n *\r\n * `elapsed` is clip-seconds already played at a mid-clip seek, so the schedule\r\n * starts at the seek point and aligns the playbackRate to the clip's true position.\r\n */\r\nexport function applySpeedToPlaybackRate(\r\n rate: AudioParam,\r\n curve: ReturnType<typeof speedCurveOf>,\r\n sourceLength: number,\r\n clipDuration: number,\r\n scalar: number,\r\n startTime: number,\r\n elapsed: number,\r\n): void {\r\n if (!curve) return;\r\n const step = 1 / CURVE_SAMPLES_PER_SECOND; // clip-time sampling step\r\n const seekAt = Math.max(0, elapsed);\r\n // Seed the value exactly at the seek point.\r\n const seedSrc = sourceTimeAtClipElapsed(curve, sourceLength, seekAt);\r\n rate.setValueAtTime(Math.max(1e-4, curve.sampleAt(seedSrc, sourceLength, 1) * scalar), startTime);\r\n\r\n for (let s = seekAt + step; s <= clipDuration + step; s += step) {\r\n const clampedElapsed = Math.min(s, clipDuration);\r\n const srcT = sourceTimeAtClipElapsed(curve, sourceLength, clampedElapsed);\r\n const value = Math.max(1e-4, curve.sampleAt(srcT, sourceLength, 1) * scalar);\r\n const ctxTime = startTime + (clampedElapsed - seekAt);\r\n rate.linearRampToValueAtTime(value, ctxTime);\r\n if (clampedElapsed >= clipDuration) break;\r\n }\r\n}\r\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/asset-bytes.ts", "../../../src/audio/bus-graph.ts", "../../../src/audio/effect-graph.ts", "../../../src/audio/loop-region.ts", "../../../src/audio/mixer.ts", "../../../src/audio/player.ts"],
|
|
4
|
-
"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", "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", "import {\r\n clipTimeAtSource,\r\n isRamp,\r\n resolveRamp,\r\n sampleRamp,\r\n sourceTimeAtClip,\r\n staticValue,\r\n transitionGainAt,\r\n transitionSpans,\r\n type AudioEffect,\r\n type AudioRequest,\r\n type AudioTransition,\r\n type Param,\r\n type Ramp,\r\n} from \"@motionscript/core\";\r\n\r\n/**\r\n * The Web Audio graph for one source's effect chain.\r\n *\r\n * `output` is the last node, to connect downstream; `nodes` are every node to\r\n * `disconnect()` on teardown; `oscillators` are tremolo LFOs the caller starts\r\n * and stops alongside the source.\r\n */\r\nexport interface AudioEffectGraph {\r\n output: AudioNode;\r\n nodes: AudioNode[];\r\n oscillators: OscillatorNode[];\r\n}\r\n\r\n/** Sample points per second an eased segment or a transition is baked into: about every 5 ms. */\r\nconst CURVE_SAMPLES_PER_SECOND = 200;\r\n\r\n/**\r\n * Apply a {@link Param} to a Web Audio {@link AudioParam}: a number once, a\r\n * ramp as a schedule — linear segments as `linearRampToValueAtTime`, eased\r\n * ones baked into `setValueCurveAtTime`.\r\n *\r\n * `elapsed` is the clip seconds already played when a mid-clip seek starts the\r\n * source, so \"now\" reads the ramp at the clip's current position. `clamp` keeps\r\n * every scheduled value in a param's valid range.\r\n */\r\nfunction applyParam(\r\n audioParam: AudioParam,\r\n param: Param,\r\n startTime: number,\r\n clipDuration: number,\r\n elapsed: number,\r\n clamp: (v: number) => number = (v) => v,\r\n): void {\r\n // The platform throws on a non-finite value.\r\n const finite = (v: number): number => {\r\n const c = clamp(v);\r\n return Number.isFinite(c) ? c : audioParam.value;\r\n };\r\n\r\n if (!isRamp(param)) {\r\n audioParam.value = finite(param);\r\n return;\r\n }\r\n if (!Number.isFinite(clipDuration) || clipDuration <= 0) {\r\n audioParam.value = finite(staticValue(param, audioParam.value));\r\n return;\r\n }\r\n\r\n const keys = resolveRamp(param, clipDuration);\r\n if (keys.length === 0) return;\r\n const base = startTime - elapsed;\r\n audioParam.setValueAtTime(finite(sampleRamp(param, Math.max(0, elapsed), clipDuration, audioParam.value)), startTime);\r\n\r\n for (let i = 1; i < keys.length; i++) {\r\n const previous = keys[i - 1];\r\n const key = keys[i];\r\n const segStart = base + previous.time;\r\n const segEnd = base + key.time;\r\n if (segEnd <= startTime) continue;\r\n\r\n const span = key.time - previous.time;\r\n if (span <= 0) {\r\n audioParam.setValueAtTime(finite(key.value), Math.max(segEnd, startTime));\r\n continue;\r\n }\r\n\r\n // A segment already under way when the source starts carries on from\r\n // the value set at `startTime` rather than restarting from its own.\r\n const done = Math.max(0, (startTime - segStart) / span);\r\n const curveStart = Math.max(segStart, startTime);\r\n if (key.linear) {\r\n if (done === 0) audioParam.setValueAtTime(finite(previous.value), curveStart);\r\n audioParam.linearRampToValueAtTime(finite(key.value), segEnd);\r\n } else {\r\n const curveDur = segEnd - curveStart;\r\n const count = Math.max(2, Math.ceil(curveDur * CURVE_SAMPLES_PER_SECOND));\r\n const samples = new Float32Array(count);\r\n for (let n = 0; n < count; n++) {\r\n const local = done + (1 - done) * (n / (count - 1));\r\n samples[n] = finite(previous.value + (key.value - previous.value) * key.ease(local));\r\n }\r\n audioParam.setValueCurveAtTime(samples, curveStart, curveDur);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Builds the Web Audio graph for a clip's effect chain, after an\r\n * already-created `source`. Shared by live playback ({@link WebAudioSink}) and\r\n * offline export (`mixAudio`) so both sound identical.\r\n *\r\n * `startTime` is the context time the source starts; `clipDuration` the clip\r\n * seconds ramps run over (a clip's, or a bus's span); `elapsed` the clip seconds\r\n * already played at a mid-clip seek (0 for a clean start, negative before the\r\n * span begins).\r\n */\r\nexport function buildAudioEffectGraph(\r\n ctx: BaseAudioContext,\r\n source: AudioNode,\r\n effects: readonly AudioEffect[],\r\n startTime: number = ctx.currentTime,\r\n clipDuration: number = 0,\r\n elapsed: number = 0,\r\n): AudioEffectGraph {\r\n const nodes: AudioNode[] = [];\r\n const oscillators: OscillatorNode[] = [];\r\n let cursor: AudioNode = source;\r\n\r\n const series = (node: AudioNode): void => {\r\n cursor.connect(node);\r\n nodes.push(node);\r\n cursor = node;\r\n };\r\n\r\n const apply = (p: AudioParam, v: Param, clamp?: (n: number) => number): void =>\r\n applyParam(p, v, startTime, clipDuration, elapsed, clamp);\r\n\r\n for (const effect of effects) {\r\n switch (effect.type) {\r\n case \"gain\": {\r\n const gain = ctx.createGain();\r\n apply(gain.gain, effect.value);\r\n series(gain);\r\n break;\r\n }\r\n case \"highpass\":\r\n case \"lowpass\": {\r\n const biquad = ctx.createBiquadFilter();\r\n biquad.type = effect.type;\r\n apply(biquad.frequency, effect.frequency);\r\n if (effect.q !== undefined) apply(biquad.Q, effect.q);\r\n series(biquad);\r\n break;\r\n }\r\n case \"tremolo\": {\r\n // A carrier gain an LFO swings: with depth d the carrier sits at\r\n // 1 - d/2 and the swing is d/2.\r\n const carrier = ctx.createGain();\r\n const lfo = ctx.createOscillator();\r\n const lfoDepth = ctx.createGain();\r\n\r\n apply(carrier.gain, effect.depth, (d) => 1 - clamp01(d) / 2);\r\n apply(lfoDepth.gain, effect.depth, (d) => clamp01(d) / 2);\r\n apply(lfo.frequency, effect.rate);\r\n\r\n lfo.connect(lfoDepth);\r\n lfoDepth.connect(carrier.gain);\r\n\r\n nodes.push(lfoDepth);\r\n oscillators.push(lfo);\r\n series(carrier);\r\n break;\r\n }\r\n case \"echo\": {\r\n const split = cursor;\r\n const merge = ctx.createGain();\r\n\r\n const dry = ctx.createGain();\r\n apply(dry.gain, effect.mix ?? 0.5, (m) => 1 - clamp01(m));\r\n split.connect(dry);\r\n dry.connect(merge);\r\n\r\n // The delay line is sized once, so it has to hold the ramp's longest delay.\r\n const delay = ctx.createDelay(Math.max(1, maxOf(effect.delay) + 1));\r\n apply(delay.delayTime, effect.delay);\r\n const feedbackGain = ctx.createGain();\r\n apply(feedbackGain.gain, effect.feedback, (f) => Math.max(0, Math.min(0.99, f)));\r\n const wet = ctx.createGain();\r\n apply(wet.gain, effect.mix ?? 0.5, (m) => clamp01(m));\r\n\r\n split.connect(delay);\r\n delay.connect(feedbackGain);\r\n feedbackGain.connect(delay);\r\n delay.connect(wet);\r\n wet.connect(merge);\r\n\r\n nodes.push(dry, delay, feedbackGain, wet, merge);\r\n cursor = merge;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return { output: cursor, nodes, oscillators };\r\n}\r\n\r\nfunction clamp01(v: number): number {\r\n return Math.max(0, Math.min(1, v));\r\n}\r\n\r\nfunction maxOf(p: Param): number {\r\n return isRamp(p) ? Math.max(0, ...p.keys.map((k) => k.value)) : p;\r\n}\r\n\r\n/**\r\n * Schedule `transitionIn`/`transitionOut` onto a gain over a span `length`\r\n * seconds long, baked like an eased ramp. Between the two it holds at 1.\r\n */\r\nexport function applyTransitions(\r\n gain: AudioParam,\r\n length: number,\r\n transitionIn: AudioTransition | undefined,\r\n transitionOut: AudioTransition | undefined,\r\n startTime: number,\r\n elapsed: number,\r\n): void {\r\n if (!transitionIn && !transitionOut) return;\r\n const seek = Math.max(0, elapsed);\r\n const at = (t: number): number => transitionGainAt(t, length, transitionIn, transitionOut);\r\n gain.setValueAtTime(at(seek), startTime);\r\n\r\n const spans = transitionSpans(length, transitionIn, transitionOut);\r\n const windows: [number, number][] = [];\r\n if (spans.in > 0) windows.push([0, spans.in]);\r\n if (spans.out > 0 && Number.isFinite(length)) windows.push([length - spans.out, length]);\r\n const base = startTime - elapsed;\r\n for (const [from, to] of windows) {\r\n const begin = Math.max(from, seek);\r\n const duration = to - begin;\r\n if (duration <= 0) continue;\r\n const count = Math.max(2, Math.ceil(duration * CURVE_SAMPLES_PER_SECOND));\r\n const samples = new Float32Array(count);\r\n for (let n = 0; n < count; n++) samples[n] = at(begin + duration * (n / (count - 1)));\r\n gain.setValueCurveAtTime(samples, base + begin, duration);\r\n }\r\n}\r\n\r\n/** How one request plays its source: the rate, and the lengths its ramps and transitions run over. */\r\nexport interface Playback {\r\n /** The constant `playbackRate`; 1 under a ramp, which is scheduled instead. */\r\n rate: number;\r\n speedRamp?: Ramp;\r\n /** Source seconds a speed ramp is placed on. */\r\n sourceLength: number;\r\n /** Clip seconds the volume and effect ramps run over. */\r\n clipDuration: number;\r\n /** What the transitions run over: the clip's length, unknown for an open one. */\r\n transitionLength: number;\r\n}\r\n\r\nexport function playbackOf(req: AudioRequest, bufferDuration: number): Playback {\r\n const speed = req.speed ?? 1;\r\n const speedRamp = isRamp(speed) ? speed : undefined;\r\n const rate = speedRamp || !(Number.isFinite(speed) && (speed as number) > 0) ? 1 : (speed as number);\r\n // Placed on the same length core sized the request with, not the decoded buffer.\r\n const sourceLength = req.sourceLength ?? Math.max(0, bufferDuration - req.trimStart);\r\n const bounded = Number.isFinite(req.endAt);\r\n const clipDuration = bounded ? Math.max(0, req.endAt - req.startAt) : clipTimeAtSource(speed, sourceLength);\r\n return { rate, speedRamp, sourceLength, clipDuration, transitionLength: bounded ? clipDuration : Infinity };\r\n}\r\n\r\n/** Source seconds after `trimStart` that `clipElapsed` clip seconds have played. */\r\nexport function sourceOffsetOf(playback: Playback, clipElapsed: number): number {\r\n return playback.speedRamp\r\n ? sourceTimeAtClip(playback.speedRamp, playback.sourceLength, clipElapsed)\r\n : clipElapsed * playback.rate;\r\n}\r\n\r\n/**\r\n * A request's level, then its transitions, after `from`: the gains every\r\n * request plays through on its way to its bus.\r\n */\r\nexport function buildLevel(\r\n ctx: BaseAudioContext,\r\n from: AudioNode,\r\n req: AudioRequest,\r\n playback: Playback,\r\n startTime: number,\r\n elapsed: number,\r\n): { output: AudioNode; nodes: AudioNode[] } {\r\n const level = ctx.createGain();\r\n applyParam(level.gain, req.volume ?? 1, startTime, playback.clipDuration, elapsed);\r\n from.connect(level);\r\n if (!req.transitionIn && !req.transitionOut) return { output: level, nodes: [level] };\r\n const transition = ctx.createGain();\r\n applyTransitions(transition.gain, playback.transitionLength, req.transitionIn, req.transitionOut, startTime, elapsed);\r\n level.connect(transition);\r\n return { output: transition, nodes: [level, transition] };\r\n}\r\n\r\n/**\r\n * Schedule a speed ramp onto an `AudioBufferSourceNode.playbackRate`.\r\n *\r\n * The ramp runs over **source** seconds and Web Audio schedules in context\r\n * seconds, so this walks clip time in small steps, converts each to a source\r\n * offset through the integral inverse, and lays down the rate there. `elapsed`\r\n * is clip seconds already played at a mid-clip seek.\r\n */\r\nexport function applySpeedToPlaybackRate(\r\n rate: AudioParam,\r\n speed: Ramp | undefined,\r\n sourceLength: number,\r\n clipDuration: number,\r\n startTime: number,\r\n elapsed: number,\r\n): void {\r\n if (!speed) return;\r\n const step = 1 / CURVE_SAMPLES_PER_SECOND;\r\n const seekAt = Math.max(0, elapsed);\r\n const valueAt = (clipElapsed: number): number =>\r\n Math.max(1e-4, sampleRamp(speed, sourceTimeAtClip(speed, sourceLength, clipElapsed), sourceLength, 1));\r\n rate.setValueAtTime(valueAt(seekAt), startTime);\r\n\r\n for (let s = seekAt + step; s <= clipDuration + step; s += step) {\r\n const clamped = Math.min(s, clipDuration);\r\n rate.linearRampToValueAtTime(valueAt(clamped), startTime + (clamped - seekAt));\r\n if (clamped >= clipDuration) break;\r\n }\r\n}\r\n", "import type { AudioRequest } from \"@motionscript/core\";\r\n\r\n/** The span of a decoded buffer a looping request repeats, in source seconds. */\r\nexport interface LoopRegion {\r\n start: number;\r\n end: number;\r\n}\r\n\r\n/**\r\n * The region a looping request repeats: from its in-point to its out-point, or to\r\n * the end of the buffer when it has none. `null` for a request that does not loop,\r\n * and for a degenerate region (an out-point at or before the in-point), where the\r\n * device falls back to wrapping the whole buffer.\r\n *\r\n * Shared by the live device and the offline mixer so a preview and an export loop\r\n * the same samples.\r\n */\r\nexport function loopRegionOf(request: AudioRequest, bufferDuration: number): LoopRegion | null {\r\n if (!request.loop) return null;\r\n const start = Math.min(Math.max(0, request.trimStart), bufferDuration);\r\n const end = Math.min(request.trimEnd ?? bufferDuration, bufferDuration);\r\n return end > start ? { start, end } : null;\r\n}\r\n\r\n/**\r\n * Configure `source` to play `request`'s loop: on or off, and over the trimmed\r\n * region rather than the whole buffer (`loopStart`/`loopEnd` default to the\r\n * whole buffer, which is how a trim used to be lost).\r\n */\r\nexport function applyLoop(source: AudioBufferSourceNode, request: AudioRequest): LoopRegion | null {\r\n source.loop = request.loop;\r\n const region = source.buffer ? loopRegionOf(request, source.buffer.duration) : null;\r\n if (region) {\r\n source.loopStart = region.start;\r\n source.loopEnd = region.end;\r\n }\r\n return region;\r\n}\r\n\r\n/**\r\n * Fold a source offset into a loop region.\r\n *\r\n * A seek into the middle of a looping clip lands at `trimStart + elapsed`, which\r\n * can be many passes past the region's end; the device would not wrap an offset\r\n * that starts outside the region, so it is wrapped here.\r\n */\r\nexport function wrapIntoRegion(region: LoopRegion | null, offset: number): number {\r\n if (!region || offset < region.end) return offset;\r\n return region.start + ((offset - region.start) % (region.end - region.start));\r\n}\r\n", "import type { AssetCatalog } from \"@motionscript/core\";\r\nimport type { AudioMixer, ScheduledAudioRequest } from \"../frame-loop\";\r\nimport { fetchAssetBytes, localAssetBytes } from \"../asset-bytes\";\r\nimport { AudioBusGraph } from \"./bus-graph\";\r\nimport { applyLoop } from \"./loop-region\";\r\nimport { applySpeedToPlaybackRate, buildAudioEffectGraph, buildLevel, playbackOf, sourceOffsetOf } from \"./effect-graph\";\r\n\r\n/** Sample rate used when the caller doesn't pick one. */\r\nexport const DEFAULT_SAMPLE_RATE = 44100;\r\n\r\nexport interface MixAudioOptions {\r\n /** Defaults to {@link DEFAULT_SAMPLE_RATE}. */\r\n sampleRate?: number;\r\n /**\r\n * Resolves a request's `src` to the address its bytes live at, as the storage\r\n * adapter does for the live paths. Omitted, a `src` is\r\n * fetched as written — right only while the host keys its manifest by URL.\r\n */\r\n catalog?: AssetCatalog;\r\n}\r\n\r\n/** Audio first, then video: a clip's own soundtrack is requested under the video's key. */\r\nfunction audioUrl(src: string, catalog: AssetCatalog | undefined): string {\r\n if (!catalog) return src;\r\n try {\r\n return catalog.getAudioMeta(src).src || src;\r\n } catch {\r\n try {\r\n return catalog.getVideoMeta(src).src || src;\r\n } catch {\r\n return src;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Reads and decodes an audio source against a scratch `OfflineAudioContext`\r\n * (decoding requires a context but doesn't render through it). The host's byte\r\n * source is asked first, as for every other asset read: a mix that went to the\r\n * network would fail where the preview played, offline or for bytes not yet\r\n * uploaded.\r\n */\r\nasync function fetchAudioBuffer(src: string, ctx: OfflineAudioContext): Promise<AudioBuffer> {\r\n const blob = (await localAssetBytes(src)) ?? (await fetchAssetBytes(src));\r\n return ctx.decodeAudioData(await blob.arrayBuffer());\r\n}\r\n\r\n/**\r\n * Render every scheduled request into one timeline-length buffer.\r\n *\r\n * An `OfflineAudioContext` graph — gain per request, looping/trimming, and the\r\n * same filter chain the live {@link WebAudioSink} builds — rendered in one\r\n * pass rather than scheduled per frame.\r\n *\r\n * Shared by the video exporter and by `mixTimelineAudio`, deliberately: a split\r\n * export and a whole one have to be the same mix, and two implementations of\r\n * \"stack these clips\" would eventually disagree.\r\n *\r\n * Curve-valued filter params and `speed` curves schedule here exactly as they do\r\n * in {@link WebAudioSink.playBuffer}, which is the reference implementation —\r\n * the two must be read side by side when either changes.\r\n *\r\n * One deliberate difference: this schedules at absolute context times, so clip\r\n * starts are sample-accurate here and quantized to `1/fps` in live playback,\r\n * which starts sources at `currentTime` on a clock tick.\r\n */\r\nexport async function mixAudio(\r\n requests: readonly ScheduledAudioRequest[],\r\n totalDuration: number,\r\n options: MixAudioOptions = {},\r\n): Promise<AudioBuffer | null> {\r\n if (requests.length === 0) return null;\r\n const sampleRate = options.sampleRate ?? DEFAULT_SAMPLE_RATE;\r\n const frames = Math.ceil(totalDuration * sampleRate);\r\n if (frames <= 0) return null;\r\n\r\n const uniqueSrcs = [...new Set(requests.map(r => r.request.src))];\r\n const scratchCtx = new OfflineAudioContext(2, frames, sampleRate);\r\n\r\n // A source only a picture's own sound wants may hold no audio at all, which\r\n // is silence rather than a failed mix — see `AudioRequest.optional`.\r\n const asked = new Set(requests.filter(r => !r.request.optional).map(r => r.request.src));\r\n const decoded = new Map<string, AudioBuffer>();\r\n await Promise.all(uniqueSrcs.map(async (src) => {\r\n try {\r\n decoded.set(src, await fetchAudioBuffer(audioUrl(src, options.catalog), scratchCtx));\r\n } catch (cause) {\r\n if (asked.has(src)) throw cause;\r\n }\r\n }));\r\n\r\n const mixCtx = new OfflineAudioContext(2, frames, sampleRate);\r\n // The same shared-chain rule the live device uses, for the same reason: an\r\n // export that flattened buses into per-clip processing would not match what\r\n // the preview sounded like.\r\n const buses = new AudioBusGraph(mixCtx, mixCtx.destination);\r\n\r\n for (const { request: req, globalOffset } of requests) {\r\n const srcBuffer = decoded.get(req.src);\r\n if (!srcBuffer) continue;\r\n\r\n const globalStart = globalOffset + req.startAt;\r\n // `endAt` is `Infinity` for an open clip; either way the timeline bounds it.\r\n const globalEnd = Math.min(globalOffset + req.endAt, totalDuration);\r\n const playDuration = globalEnd - globalStart;\r\n if (playDuration <= 0) continue;\r\n\r\n const source = mixCtx.createBufferSource();\r\n source.buffer = srcBuffer;\r\n applyLoop(source, req);\r\n\r\n // Ramps resolve against the clip's own length, deliberately *not*\r\n // `playDuration`, which is that length truncated by the timeline end:\r\n // resolving against the truncated value would squeeze the whole ramp\r\n // into the surviving part instead of cutting it off. `elapsed` is 0:\r\n // unlike a live seek, the mix always starts a clip at its beginning.\r\n const playback = playbackOf(req, srcBuffer.duration);\r\n if (playback.rate !== 1) source.playbackRate.value = playback.rate;\r\n applySpeedToPlaybackRate(\r\n source.playbackRate, playback.speedRamp, playback.sourceLength, playback.clipDuration, globalStart, 0,\r\n );\r\n\r\n // The same chain as the live WebAudioSink graph, so exports sound like the preview.\r\n const graph = buildAudioEffectGraph(mixCtx, source, req.effects ?? [], globalStart, playback.clipDuration, 0);\r\n const level = buildLevel(mixCtx, graph.output, req, playback, globalStart, 0);\r\n // From the mix's start, whichever clip asks first: a bus's chain is shared,\r\n // so its schedule cannot begin at one clip's start. Context time 0 is\r\n // `-globalOffset` in this request's seconds, which are its stops' too.\r\n level.output.connect(buses.inputFor(req.bus, 0, -globalOffset));\r\n\r\n // start()'s 3rd arg is a source-buffer duration: under a speed ramp the\r\n // buffer consumed over a span of clip time is the integral of the rate,\r\n // not a multiple of it.\r\n const consumed = sourceOffsetOf(playback, playDuration);\r\n\r\n source.start(globalStart, req.trimStart, consumed);\r\n for (const osc of graph.oscillators) osc.start(globalStart);\r\n }\r\n\r\n return mixCtx.startRendering();\r\n}\r\n\r\n/**\r\n * Adapter presenting {@link mixAudio} as the exporter's injected mixer seam.\r\n *\r\n * The sample rate is a constructor argument rather than a third `mix` parameter\r\n * because {@link AudioMixer} — the seam `renderTimeline` calls through — takes\r\n * exactly two, so anything passed as a third would be silently dropped. Fixing\r\n * it here rather than widening the interface keeps the rate a property of *this*\r\n * mixer, which is whose business it is.\r\n */\r\nexport class WebAudioMixer implements AudioMixer<AudioBuffer> {\r\n constructor(\r\n private readonly sampleRate: number = DEFAULT_SAMPLE_RATE,\r\n private readonly catalog?: AssetCatalog,\r\n ) { }\r\n\r\n mix(\r\n requests: readonly ScheduledAudioRequest[],\r\n totalDuration: number,\r\n ): Promise<AudioBuffer | null> {\r\n return mixAudio(requests, totalDuration, {\r\n sampleRate: this.sampleRate,\r\n catalog: this.catalog,\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Encode an `AudioBuffer` as a 16-bit PCM WAV.\r\n *\r\n * The only other encoder in this package is the AAC track inside the mp4 muxer,\r\n * which is reachable solely by exporting a video — so without this a mixdown has\r\n * no file representation at all. WAV because it needs no codec support and is\r\n * lossless; a host wanting mp3/aac can re-encode from here.\r\n */\r\nexport function encodeWav(buffer: AudioBuffer): Uint8Array<ArrayBuffer> {\r\n const channelCount = buffer.numberOfChannels;\r\n const frameCount = buffer.length;\r\n const bytesPerSample = 2;\r\n const blockAlign = channelCount * bytesPerSample;\r\n const dataBytes = frameCount * blockAlign;\r\n\r\n const out = new ArrayBuffer(44 + dataBytes);\r\n const view = new DataView(out);\r\n\r\n const ascii = (offset: number, text: string) => {\r\n for (let i = 0; i < text.length; i++) view.setUint8(offset + i, text.charCodeAt(i));\r\n };\r\n\r\n ascii(0, \"RIFF\");\r\n view.setUint32(4, 36 + dataBytes, true);\r\n ascii(8, \"WAVE\");\r\n ascii(12, \"fmt \");\r\n view.setUint32(16, 16, true); // PCM header length\r\n view.setUint16(20, 1, true); // format: PCM\r\n view.setUint16(22, channelCount, true);\r\n view.setUint32(24, buffer.sampleRate, true);\r\n view.setUint32(28, buffer.sampleRate * blockAlign, true);\r\n view.setUint16(32, blockAlign, true);\r\n view.setUint16(34, 8 * bytesPerSample, true);\r\n ascii(36, \"data\");\r\n view.setUint32(40, dataBytes, true);\r\n\r\n // Pull each channel out once — getChannelData is a live view, but calling it\r\n // per sample inside the interleave loop is measurably slower.\r\n const channels: Float32Array[] = [];\r\n for (let c = 0; c < channelCount; c++) channels.push(buffer.getChannelData(c));\r\n\r\n let offset = 44;\r\n for (let frame = 0; frame < frameCount; frame++) {\r\n for (let c = 0; c < channelCount; c++) {\r\n // Clamp before scaling: the mix bus can exceed [-1,1] where clips\r\n // overlap, and letting that wrap turns a loud passage into noise.\r\n const sample = Math.max(-1, Math.min(1, channels[c][frame]));\r\n view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);\r\n offset += bytesPerSample;\r\n }\r\n }\r\n\r\n return new Uint8Array(out);\r\n}\r\n", "import { AudioSink, AudioRequest } from \"@motionscript/core\";\r\nimport { AudioBusGraph } from \"./bus-graph\";\r\nimport { applyLoop, wrapIntoRegion } from \"./loop-region\";\r\nimport { applySpeedToPlaybackRate, buildAudioEffectGraph, buildLevel, playbackOf, sourceOffsetOf } from \"./effect-graph\";\r\n\r\ntype ActiveSource = {\r\n source: AudioBufferSourceNode;\r\n request: AudioRequest;\r\n /** Effect and level nodes to disconnect on teardown. */\r\n nodes: AudioNode[];\r\n /** Tremolo LFOs to stop on teardown. */\r\n oscillators: OscillatorNode[];\r\n};\r\n\r\n/**\r\n * Web Audio implementation of {@link AudioSink} — decodes and caches source\r\n * buffers, then schedules/plays {@link AudioRequest}s as `AudioBufferSourceNode`s\r\n * through a shared master gain (global mute and volume). `schedule` registers the\r\n * active set of requests for the current frame; `syncTo` then starts/stops\r\n * sources to match `clipTime`, so playback follows scrubbing and seeks.\r\n */\r\nexport class WebAudioSink extends AudioSink {\r\n private readonly borrowed: AudioContext | undefined;\r\n private _context: AudioContext | null = null;\r\n private bufferCache = new Map<string, AudioBuffer>();\r\n private decoding = new Map<string, Promise<void>>();\r\n private active = new Map<string, ActiveSource>();\r\n private scheduled: AudioRequest[] = [];\r\n private disposed: boolean = false;\r\n /** The master gain and the live bus chains (shared across every clip that names one), built with the context. */\r\n private _graph: { master: GainNode; buses: AudioBusGraph } | null = null;\r\n private muted = false;\r\n private volume = 1;\r\n\r\n constructor(context?: AudioContext) {\r\n super();\r\n this.borrowed = context;\r\n }\r\n\r\n /**\r\n * The context, created on first use rather than with the sink: a new\r\n * AudioContext opens the audio device (50–65 ms on a desktop), and a\r\n * session that never plays or decodes sound never needs one.\r\n */\r\n getContext(): AudioContext {\r\n this._context ??= this.borrowed ?? new AudioContext();\r\n return this._context;\r\n }\r\n\r\n private get context(): AudioContext {\r\n return this.getContext();\r\n }\r\n\r\n private get graph(): { master: GainNode; buses: AudioBusGraph } {\r\n if (!this._graph) {\r\n const master = this.context.createGain();\r\n master.connect(this.context.destination);\r\n this._graph = { master, buses: new AudioBusGraph(this.context, master) };\r\n this.applyMasterGain();\r\n }\r\n return this._graph;\r\n }\r\n\r\n /**\r\n * Resume the AudioContext. Must be called from within a user gesture\r\n * (e.g. a click handler) the first time, or browsers keep the context\r\n * suspended and no audio is heard.\r\n */\r\n unlock(): void {\r\n if (this.context.state === \"suspended\") {\r\n this.context.resume();\r\n }\r\n }\r\n\r\n has(src: string): boolean {\r\n return this.bufferCache.has(src);\r\n }\r\n\r\n async append(src: string, data: ArrayBuffer): Promise<void> {\r\n if (this.bufferCache.has(src)) return;\r\n const existing = this.decoding.get(src);\r\n if (existing) return existing;\r\n\r\n // decodeAudioData detaches `data` — that's fine, the caller in\r\n // AssetManager.fetchAudio discards its reference immediately after\r\n // awaiting append. Skipping the defensive .slice(0) saves a multi-MB\r\n // allocation per audio source.\r\n const job = this.context.decodeAudioData(data).then((buffer) => {\r\n this.bufferCache.set(src, buffer);\r\n }).finally(() => {\r\n this.decoding.delete(src);\r\n });\r\n this.decoding.set(src, job);\r\n await job;\r\n }\r\n\r\n /** Drops cached buffers and stops active sources for srcs/requests no longer referenced — called when the asset set changes (e.g. seeking across scene boundaries). */\r\n retain(keep: ReadonlySet<string>): void {\r\n for (const src of [...this.bufferCache.keys()]) {\r\n if (!keep.has(src)) this.bufferCache.delete(src);\r\n }\r\n for (const [id, active] of this.active) {\r\n if (!keep.has(active.request.src)) this.stopSource(id, active);\r\n }\r\n }\r\n\r\n /** Replaces the active request set; stops any currently-playing source whose request is no longer scheduled. Actual start/stop-to-match-time happens in `syncTo`. */\r\n schedule(requests: readonly AudioRequest[]): void {\r\n const next = new Set(requests.map(r => r.id));\r\n for (const [id, active] of this.active) {\r\n if (!next.has(id)) this.stopSource(id, active);\r\n }\r\n this.scheduled = requests.slice();\r\n }\r\n\r\n /** Starts sources whose `[startAt, endAt)` window now contains `clipTime` (computing the correct buffer offset for the seek point) and stops any that have fallen outside it. */\r\n syncTo(clipTime: number): void {\r\n const liveIds = new Set<string>();\r\n\r\n for (const req of this.scheduled) {\r\n // `endAt` is `Infinity` for an open clip, so the comparison needs no\r\n // nullish fallback — see AudioRequest.endAt.\r\n const isInWindow = clipTime >= req.startAt && clipTime < req.endAt;\r\n if (!isInWindow) continue;\r\n\r\n liveIds.add(req.id);\r\n if (!this.active.has(req.id)) {\r\n const buffer = this.bufferCache.get(req.src);\r\n if (buffer) this.playBuffer(buffer, req, clipTime);\r\n }\r\n }\r\n\r\n for (const [id, active] of this.active) {\r\n if (!liveIds.has(id)) this.stopSource(id, active);\r\n }\r\n }\r\n\r\n async play(time: number, _speed: number, _reverse: boolean): Promise<void> {\r\n if (this.context.state === \"suspended\") {\r\n await this.context.resume();\r\n }\r\n this.syncTo(time);\r\n }\r\n\r\n stop(): void {\r\n for (const [id, active] of this.active) {\r\n this.stopSource(id, active);\r\n }\r\n // A bus's curves are scheduled against the clock of the run that built\r\n // it, so the next play, from wherever it lands, builds them again.\r\n this._graph?.buses.dispose();\r\n }\r\n\r\n setMuted(muted: boolean): void {\r\n this.muted = muted;\r\n this.applyMasterGain();\r\n }\r\n\r\n setVolume(volume: number): void {\r\n this.volume = Math.max(0, volume);\r\n this.applyMasterGain();\r\n }\r\n\r\n /** Mute and volume are held separately so unmuting restores the set level. */\r\n private applyMasterGain(): void {\r\n if (this._graph) this._graph.master.gain.value = this.muted ? 0 : this.volume;\r\n }\r\n\r\n /** Starts a buffer source mid-clip if `clipTime` lands after the request's start — the offset accounts for the request's trim, the elapsed time since `startAt`, and its speed. */\r\n private playBuffer(buffer: AudioBuffer, req: AudioRequest, clipTime: number): void {\r\n const startTime = this.context.currentTime;\r\n const playback = playbackOf(req, buffer.duration);\r\n const elapsed = Math.max(0, clipTime - req.startAt);\r\n\r\n const source = this.context.createBufferSource();\r\n source.buffer = buffer;\r\n const loopRegion = applyLoop(source, req);\r\n if (playback.rate !== 1) source.playbackRate.value = playback.rate;\r\n applySpeedToPlaybackRate(\r\n source.playbackRate, playback.speedRamp, playback.sourceLength, playback.clipDuration, startTime, elapsed,\r\n );\r\n\r\n const graph = buildAudioEffectGraph(\r\n this.context, source, req.effects ?? [], startTime, playback.clipDuration, elapsed,\r\n );\r\n const level = buildLevel(this.context, graph.output, req, playback, startTime, elapsed);\r\n // Into this clip's bus chain, or straight to the master when it has none.\r\n // The chain is shared: two clips on one bus reach the same nodes, which is\r\n // what makes a bus effect one tail rather than one per clip.\r\n level.output.connect(this.graph.buses.inputFor(req.bus, startTime, clipTime));\r\n\r\n const audioOffset = req.trimStart + sourceOffsetOf(playback, elapsed);\r\n source.start(startTime, wrapIntoRegion(loopRegion, audioOffset));\r\n for (const osc of graph.oscillators) osc.start(startTime);\r\n\r\n source.onended = () => {\r\n if (this.active.get(req.id)?.source === source) {\r\n this.active.delete(req.id);\r\n }\r\n };\r\n\r\n this.active.set(req.id, {\r\n source,\r\n request: req,\r\n nodes: [...graph.nodes, ...level.nodes],\r\n oscillators: graph.oscillators,\r\n });\r\n }\r\n\r\n private stopSource(id: string, active: ActiveSource): void {\r\n try {\r\n active.source.onended = null;\r\n active.source.stop();\r\n for (const osc of active.oscillators) osc.stop();\r\n active.source.disconnect();\r\n for (const node of active.nodes) node.disconnect();\r\n } catch {\r\n // already stopped\r\n }\r\n this.active.delete(id);\r\n }\r\n\r\n dispose(): void {\r\n if (this.disposed) return;\r\n this.disposed = true;\r\n super.dispose();\r\n this.bufferCache.clear();\r\n this.decoding.clear();\r\n this.scheduled.length = 0;\r\n this._graph?.buses.dispose();\r\n try {\r\n this._graph?.master.disconnect();\r\n } catch {\r\n // already disconnected\r\n }\r\n const owned = this.borrowed ? null : this._context;\r\n if (owned && owned.state !== \"closed\") {\r\n owned.close();\r\n }\r\n }\r\n}\r\n"],
|
|
5
|
-
"mappings": "AAoCA,IAAIA,EAAiC,KAS/B,SAAUC,GAAmBC,EAA4B,CAC3DF,EAASE,CACb,CASA,eAAsBC,EAAgBC,EAAW,CAC7C,GAAI,CAACJ,EAAQ,OAAO,KACpB,GAAI,CACA,OAAO,MAAMA,EAAOI,CAAG,CAC3B,MAAQ,CACJ,OAAO,IACX,CACJ,CAOA,eAAsBC,EAAgBC,EAAW,CAC7C,IAAMC,EAAW,MAAM,MAAMD,CAAG,EAChC,GAAI,CAACC,EAAS,GAAI,CACd,IAAMC,EAASD,EAAS,WAAa,GAAGA,EAAS,MAAM,IAAIA,EAAS,UAAU,GAAK,GAAGA,EAAS,MAAM,GACrG,MAAM,IAAI,MAAM,aAAaD,CAAG,kBAAkBE,CAAM,EAAE,CAC9D,CACA,OAAOD,EAAS,KAAI,CACxB,CAGA,eAAsBE,GAAeL,EAAW,CAC5C,OAAQ,MAAMD,EAAgBC,CAAG,GAAMC,EAAgBD,CAAG,CAC9D,CClFA,OAAS,cAAAM,MAAuD,qBCAhE,OACI,oBAAAC,EACA,UAAAC,EACA,eAAAC,E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E,CAAO,EACpEC,EAAO,MAAMJ,EAAWc,EAAeT,EAAYO,CAAW,CAAC,EAC/D,QAAWG,KAAOP,EAAM,YAAaO,EAAI,MAAMf,CAAS,EAExDI,EAAO,QAAU,IAAK,CACd,KAAK,OAAO,IAAIV,EAAI,EAAE,GAAG,SAAWU,GACpC,KAAK,OAAO,OAAOV,EAAI,EAAE,CAEjC,EAEA,KAAK,OAAO,IAAIA,EAAI,GAAI,CACpB,OAAAU,EACA,QAASV,EACT,MAAO,CAAC,GAAGc,EAAM,MAAO,GAAGE,EAAM,KAAK,EACtC,YAAaF,EAAM,YACtB,CACL,CAEQ,WAAWrB,EAAYC,EAAoB,CAC/C,GAAI,CACAA,EAAO,OAAO,QAAU,KACxBA,EAAO,OAAO,KAAI,EAClB,QAAW2B,KAAO3B,EAAO,YAAa2B,EAAI,KAAI,EAC9C3B,EAAO,OAAO,WAAU,EACxB,QAAW4B,KAAQ5B,EAAO,MAAO4B,EAAK,WAAU,CACpD,MAAQ,CAER,CACA,KAAK,OAAO,OAAO7B,CAAE,CACzB,CAEA,SAAO,CACH,GAAI,KAAK,SAAU,OACnB,KAAK,SAAW,GAChB,MAAM,QAAO,EACb,KAAK,YAAY,MAAK,EACtB,KAAK,SAAS,MAAK,EACnB,KAAK,UAAU,OAAS,EACxB,KAAK,QAAQ,MAAM,QAAO,EAC1B,GAAI,CACA,KAAK,QAAQ,OAAO,WAAU,CAClC,MAAQ,CAER,CACA,IAAM8B,EAAQ,KAAK,SAAW,KAAO,KAAK,SACtCA,GAASA,EAAM,QAAU,UACzBA,EAAM,MAAK,CAEnB",
|
|
6
|
-
"names": ["source", "setAssetByteSource", "next", "localAssetBytes", "src", "fetchAssetBytes", "url", "response", "status", "loadAssetBytes", "busStopKey", "clipTimeAtSource", "isRamp", "resolveRamp", "sampleRamp", "sourceTimeAtClip", "staticValue", "transitionGainAt", "transitionSpans", "CURVE_SAMPLES_PER_SECOND", "applyParam", "audioParam", "param", "startTime", "clipDuration", "elapsed", "clamp", "v", "finite", "c", "keys", "base", "i", "previous", "key", "segStart", "segEnd", "span", "done", "curveStart", "curveDur", "count", "samples", "n", "local", "buildAudioEffectGraph", "ctx", "source", "effects", "nodes", "oscillators", "cursor", "series", "node", "apply", "p", "effect", "gain", "biquad", "carrier", "lfo", "lfoDepth", "d", "clamp01", "split", "merge", "dry", "m", "delay", "maxOf", "feedbackGain", "f", "wet", "k", "applyTransitions", "length", "transitionIn", "transitionOut", "seek", "at", "t", "spans", "windows", "from", "to", "begin", "duration", "playbackOf", "req", "bufferDuration", "speed", "speedRamp", "rate", "sourceLength", "bounded", "sourceOffsetOf", "playback", "clipElapsed", "buildLevel", "level", "transition", "applySpeedToPlaybackRate", "step", "seekAt", "valueAt", "s", "clamped", "AudioBusGraph", "ctx", "destination", "bus", "startTime", "clipTime", "node", "osc", "index", "stop", "key", "busStopKey", "existing", "output", "input", "level", "span", "graph", "buildAudioEffectGraph", "tail", "transition", "applyTransitions", "loopRegionOf", "request", "bufferDuration", "start", "end", "applyLoop", "source", "region", "wrapIntoRegion", "offset", "DEFAULT_SAMPLE_RATE", "audioUrl", "src", "catalog", "fetchAudioBuffer", "ctx", "blob", "localAssetBytes", "fetchAssetBytes", "mixAudio", "requests", "totalDuration", "options", "sampleRate", "frames", "uniqueSrcs", "r", "scratchCtx", "asked", "decoded", "cause", "mixCtx", "buses", "AudioBusGraph", "req", "globalOffset", "srcBuffer", "globalStart", "playDuration", "source", "applyLoop", "playback", "playbackOf", "applySpeedToPlaybackRate", "graph", "buildAudioEffectGraph", "buildLevel", "consumed", "sourceOffsetOf", "osc", "WebAudioMixer", "encodeWav", "buffer", "channelCount", "frameCount", "bytesPerSample", "blockAlign", "dataBytes", "out", "view", "ascii", "offset", "text", "i", "channels", "c", "frame", "sample", "AudioSink", "WebAudioSink", "AudioSink", "context", "master", "AudioBusGraph", "src", "data", "existing", "job", "buffer", "keep", "id", "active", "requests", "next", "r", "clipTime", "liveIds", "req", "time", "_speed", "_reverse", "muted", "volume", "startTime", "playback", "playbackOf", "elapsed", "source", "loopRegion", "applyLoop", "applySpeedToPlaybackRate", "graph", "buildAudioEffectGraph", "level", "buildLevel", "audioOffset", "sourceOffsetOf", "wrapIntoRegion", "osc", "node", "owned"]
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BrowserRenderer } from "./engine";
|
|
2
|
-
import { getCanvasKit } from "./getter";
|
|
3
|
-
import { WebStorageAdapter } from "./storage-adapter";
|
|
4
|
-
/** The default backend: CanvasKit over WebGL. */
|
|
5
|
-
export declare function canvasKitRenderer(canvasKit: Awaited<ReturnType<typeof getCanvasKit>>): BrowserRenderer<WebStorageAdapter>;
|
|
6
|
-
/** `renderer` when a host gave one; else CanvasKit, loaded only now. */
|
|
7
|
-
export declare function resolveRenderer(renderer: BrowserRenderer | undefined, wasmUrl?: string): Promise<BrowserRenderer>;
|
|
8
|
-
//# sourceMappingURL=canvaskit-renderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canvaskit-renderer.d.ts","sourceRoot":"","sources":["../src/canvaskit-renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,iDAAiD;AACjD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,eAAe,CAAC,iBAAiB,CAAC,CAYzH;AAED,wEAAwE;AACxE,wBAAsB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAEvH"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getCanvasKit } from "./getter";
|
|
2
|
-
import { WebMeasureContext } from "./measure-context";
|
|
3
|
-
import { WebRenderContext } from "./render-context";
|
|
4
|
-
import { WebStorageAdapter } from "./storage-adapter";
|
|
5
|
-
/** The default backend: CanvasKit over WebGL. */
|
|
6
|
-
export function canvasKitRenderer(canvasKit) {
|
|
7
|
-
return {
|
|
8
|
-
createStorageAdapter({ catalog, viewport, fps }) {
|
|
9
|
-
return new WebStorageAdapter(canvasKit, catalog, viewport, fps);
|
|
10
|
-
},
|
|
11
|
-
createRenderContext(storage) {
|
|
12
|
-
return new WebRenderContext(canvasKit, storage);
|
|
13
|
-
},
|
|
14
|
-
createMeasureContext(storage) {
|
|
15
|
-
return new WebMeasureContext(storage);
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/** `renderer` when a host gave one; else CanvasKit, loaded only now. */
|
|
20
|
-
export async function resolveRenderer(renderer, wasmUrl) {
|
|
21
|
-
return renderer ?? canvasKitRenderer(await getCanvasKit(wasmUrl));
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=canvaskit-renderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canvaskit-renderer.js","sourceRoot":"","sources":["../src/canvaskit-renderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,iDAAiD;AACjD,MAAM,UAAU,iBAAiB,CAAC,SAAmD;IACjF,OAAO;QACH,oBAAoB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAgB;YACzD,OAAO,IAAI,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QACpE,CAAC;QACD,mBAAmB,CAAC,OAA0B;YAC1C,OAAO,IAAI,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,oBAAoB,CAAC,OAA0B;YAC3C,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;KACJ,CAAC;AACN,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAqC,EAAE,OAAgB;IACzF,OAAO,QAAQ,IAAI,iBAAiB,CAAC,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import type { MeasureContext2D, PlatformDeps } from \"@motionscript/core\";\r\nimport type { BrowserRenderer } from \"./engine\";\r\nimport { getCanvasKit } from \"./getter\";\r\nimport { WebMeasureContext } from \"./measure-context\";\r\nimport { WebRenderContext } from \"./render-context\";\r\nimport { WebStorageAdapter } from \"./storage-adapter\";\r\n\r\n/** The default backend: CanvasKit over WebGL. */\r\nexport function canvasKitRenderer(canvasKit: Awaited<ReturnType<typeof getCanvasKit>>): BrowserRenderer<WebStorageAdapter> {\r\n return {\r\n createStorageAdapter({ catalog, viewport, fps }: PlatformDeps): WebStorageAdapter {\r\n return new WebStorageAdapter(canvasKit, catalog, viewport, fps);\r\n },\r\n createRenderContext(storage: WebStorageAdapter): WebRenderContext {\r\n return new WebRenderContext(canvasKit, storage);\r\n },\r\n createMeasureContext(storage: WebStorageAdapter): MeasureContext2D {\r\n return new WebMeasureContext(storage);\r\n },\r\n };\r\n}\r\n\r\n/** `renderer` when a host gave one; else CanvasKit, loaded only now. */\r\nexport async function resolveRenderer(renderer: BrowserRenderer | undefined, wasmUrl?: string): Promise<BrowserRenderer> {\r\n return renderer ?? canvasKitRenderer(await getCanvasKit(wasmUrl));\r\n}\r\n"]}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { type PixelSize } from "./levels";
|
|
2
|
-
/**
|
|
3
|
-
* Which level a draw is served, and when levels are decoded and released.
|
|
4
|
-
*
|
|
5
|
-
* Browser-free: decoding, uploading and fetching are the host's, so every
|
|
6
|
-
* decision here runs under a plain test runner with a fake clock.
|
|
7
|
-
*/
|
|
8
|
-
/** Mirrors core's `DecodePolicy`, which its barrel does not export yet. */
|
|
9
|
-
export type DecodePolicy = "exact" | "interactive";
|
|
10
|
-
export declare const IMAGE_DECODE_BUDGET_BYTES: number;
|
|
11
|
-
/** Unselected levels older than this go, whatever the budget — bar a {@link RETAINED_LEVEL_BYTES} largest level. */
|
|
12
|
-
export declare const LEVEL_AGE_OUT_MS = 2000;
|
|
13
|
-
/** A preview drawing a level at twice what it needs for this long decodes the smaller one. */
|
|
14
|
-
export declare const DOWNGRADE_AFTER_MS = 5000;
|
|
15
|
-
export declare const IDLE_TO_FLOOR_MS = 30000;
|
|
16
|
-
export declare const IDLE_DROP_SOURCE_MS = 60000;
|
|
17
|
-
export declare const MAX_CONCURRENT_DECODES = 3;
|
|
18
|
-
/** An interactive decode covers this multiple of the demand, so a growing draw re-decodes per octave, not per rung. */
|
|
19
|
-
export declare const UPGRADE_HEADROOM = 2;
|
|
20
|
-
/**
|
|
21
|
-
* A largest level no bigger than this is neither aged out nor downgraded until
|
|
22
|
-
* the budget needs the room: decoding it again the next time a draw grows costs
|
|
23
|
-
* more, in main-thread copies and a blurry frame, than holding it.
|
|
24
|
-
*/
|
|
25
|
-
export declare const RETAINED_LEVEL_BYTES: number;
|
|
26
|
-
export interface ImageLevel<G = unknown> {
|
|
27
|
-
/** The ladder rung this level was decoded for. */
|
|
28
|
-
readonly edge: number;
|
|
29
|
-
readonly width: number;
|
|
30
|
-
readonly height: number;
|
|
31
|
-
readonly pixels: Uint8Array;
|
|
32
|
-
/** The host's GPU copy, counted against the budget alongside the pixels. */
|
|
33
|
-
gpu: G | null;
|
|
34
|
-
lastSelected: number;
|
|
35
|
-
/** The pass that last selected it — "unselected" is judged by pass, since several can share a clock tick. */
|
|
36
|
-
selectedPass: number;
|
|
37
|
-
}
|
|
38
|
-
export interface DecodedImage {
|
|
39
|
-
pixels: Uint8Array;
|
|
40
|
-
width: number;
|
|
41
|
-
height: number;
|
|
42
|
-
intrinsic: PixelSize;
|
|
43
|
-
vector: boolean;
|
|
44
|
-
}
|
|
45
|
-
export interface ImageLevelHost<G> {
|
|
46
|
-
now(): number;
|
|
47
|
-
/**
|
|
48
|
-
* Decode `src` at the rung `chooseEdge` picks once the source's intrinsic
|
|
49
|
-
* size is known — the host may have to fetch or even decode the source to
|
|
50
|
-
* learn it, which is why the choice is a callback rather than an argument.
|
|
51
|
-
*/
|
|
52
|
-
decode(src: string, chooseEdge: (intrinsic: PixelSize, vector: boolean) => number): Promise<DecodedImage & {
|
|
53
|
-
edge: number;
|
|
54
|
-
}>;
|
|
55
|
-
/** A level left the cache. Free what was built from it. */
|
|
56
|
-
released(src: string, level: ImageLevel<G>): void;
|
|
57
|
-
/** Kept compressed bytes for `src`, so an upgrade needs no refetch; 0 when none. */
|
|
58
|
-
sourceBytes(src: string): number;
|
|
59
|
-
dropSource(src: string): void;
|
|
60
|
-
/** Long edge of the surface in device px, for sizing a first interactive load. */
|
|
61
|
-
surfaceEdge(): number;
|
|
62
|
-
onError?(src: string, error: unknown): void;
|
|
63
|
-
}
|
|
64
|
-
export declare class ImageLevelCache<G = unknown> {
|
|
65
|
-
private readonly _host;
|
|
66
|
-
private readonly _budget;
|
|
67
|
-
private _policy;
|
|
68
|
-
private readonly _entries;
|
|
69
|
-
private _pass;
|
|
70
|
-
private _inflight;
|
|
71
|
-
constructor(_host: ImageLevelHost<G>, _budget?: number);
|
|
72
|
-
get policy(): DecodePolicy;
|
|
73
|
-
setPolicy(policy: DecodePolicy): void;
|
|
74
|
-
has(src: string): boolean;
|
|
75
|
-
intrinsicSize(src: string): PixelSize | null;
|
|
76
|
-
/** Make sure `src` has a level to draw with. First loads pick their rung by policy. */
|
|
77
|
-
load(src: string): Promise<void>;
|
|
78
|
-
beginPass(): void;
|
|
79
|
-
/**
|
|
80
|
-
* The level one draw paints with. `footprint` is the long edge in device px
|
|
81
|
-
* the draw needs; absent means the source's own resolution.
|
|
82
|
-
*/
|
|
83
|
-
select(src: string, footprint?: number): ImageLevel<G> | null;
|
|
84
|
-
/** Decide this pass's level changes, now that every draw has reported. */
|
|
85
|
-
endPass(): void;
|
|
86
|
-
/**
|
|
87
|
-
* What a settling caller must wait for before the frame is right: under
|
|
88
|
-
* `exact`, every decode queued or running; under `interactive`, only a source
|
|
89
|
-
* the last pass asked for with nothing resident. An upgrade is {@link hasUpgrades}.
|
|
90
|
-
*/
|
|
91
|
-
hasPending(): boolean;
|
|
92
|
-
/** Await what {@link hasPending} reports, and report whether there was any. */
|
|
93
|
-
warm(): Promise<boolean>;
|
|
94
|
-
/** Whether, under `interactive`, a source the last pass drew below demand has a better level on its way. */
|
|
95
|
-
hasUpgrades(): boolean;
|
|
96
|
-
/** Await the upgrades {@link hasUpgrades} reports; whether one landed. */
|
|
97
|
-
warmUpgrades(): Promise<boolean>;
|
|
98
|
-
stats(): {
|
|
99
|
-
sources: number;
|
|
100
|
-
levels: number;
|
|
101
|
-
levelBytes: number;
|
|
102
|
-
sourceBytes: number;
|
|
103
|
-
inflight: number;
|
|
104
|
-
};
|
|
105
|
-
/** Every level held for `src`, ascending — for tests and stats. */
|
|
106
|
-
levelsOf(src: string): readonly ImageLevel<G>[];
|
|
107
|
-
dispose(): void;
|
|
108
|
-
private _entry;
|
|
109
|
-
private _blocks;
|
|
110
|
-
private _upgrading;
|
|
111
|
-
/** The rung an interactive decode for `demand` asks for: with headroom, capped at the source. */
|
|
112
|
-
private _interactiveEdge;
|
|
113
|
-
private _learn;
|
|
114
|
-
private _add;
|
|
115
|
-
/**
|
|
116
|
-
* Queue a decode of `edge`. An interactive request replaces what is queued,
|
|
117
|
-
* since only the latest demand matters; exact requests accumulate, since a
|
|
118
|
-
* frame may need several rungs of one source.
|
|
119
|
-
*/
|
|
120
|
-
private _request;
|
|
121
|
-
private _pump;
|
|
122
|
-
/**
|
|
123
|
-
* The next queued rung worth decoding. Under `interactive` never one below the
|
|
124
|
-
* latest demand, and no upgrade once what landed meanwhile already covers it.
|
|
125
|
-
*/
|
|
126
|
-
private _nextEdge;
|
|
127
|
-
private _ageOut;
|
|
128
|
-
private _total;
|
|
129
|
-
/**
|
|
130
|
-
* Cheapest loss first: levels nothing drew this pass, then levels a preview
|
|
131
|
-
* holds bigger than it needs, then sources nobody has looked at in a while,
|
|
132
|
-
* then their compressed bytes. A source's last level is never evicted — a
|
|
133
|
-
* draw finding nothing would throw rather than degrade.
|
|
134
|
-
*/
|
|
135
|
-
private _enforceBudget;
|
|
136
|
-
}
|
|
137
|
-
//# sourceMappingURL=image-levels.d.ts.map
|