@motionscript/browser 0.1.0-alpha.9 → 0.1.1-alpha.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 +35 -0
- package/dist/asset-bytes.d.ts +12 -50
- package/dist/asset-bytes.d.ts.map +1 -1
- package/dist/asset-bytes.js +20 -52
- package/dist/asset-bytes.js.map +1 -1
- package/dist/audio/bus-graph.d.ts +4 -39
- package/dist/audio/bus-graph.d.ts.map +1 -1
- package/dist/audio/bus-graph.js +4 -38
- package/dist/audio/bus-graph.js.map +1 -1
- package/dist/audio/effect-graph.d.ts +4 -29
- package/dist/audio/effect-graph.d.ts.map +1 -1
- package/dist/audio/effect-graph.js +4 -31
- package/dist/audio/effect-graph.js.map +1 -1
- package/dist/audio/loop-region.d.ts +3 -21
- package/dist/audio/loop-region.d.ts.map +1 -1
- package/dist/audio/loop-region.js +3 -21
- package/dist/audio/loop-region.js.map +1 -1
- package/dist/audio/mixer.d.ts +9 -41
- package/dist/audio/mixer.d.ts.map +1 -1
- package/dist/audio/mixer.js +11 -44
- package/dist/audio/mixer.js.map +1 -1
- package/dist/audio/player.d.ts +3 -17
- package/dist/audio/player.d.ts.map +1 -1
- package/dist/audio/player.js +4 -23
- package/dist/audio/player.js.map +1 -1
- package/dist/browser/audio.js +1 -1
- package/dist/browser/chunks/chunk-NDJYMKIV.js +2 -0
- package/dist/browser/chunks/chunk-NDJYMKIV.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.d.ts +25 -84
- package/dist/concat.d.ts.map +1 -1
- package/dist/concat.js +19 -69
- package/dist/concat.js.map +1 -1
- package/dist/dynamic-nodes.d.ts +1 -6
- package/dist/dynamic-nodes.d.ts.map +1 -1
- package/dist/dynamic-nodes.js +3 -24
- package/dist/dynamic-nodes.js.map +1 -1
- package/dist/engine.d.ts +9 -42
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +10 -44
- package/dist/engine.js.map +1 -1
- package/dist/export-audio.d.ts +1 -6
- package/dist/export-audio.d.ts.map +1 -1
- package/dist/export-audio.js +1 -6
- package/dist/export-audio.js.map +1 -1
- package/dist/exporter.d.ts +28 -141
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +15 -90
- package/dist/exporter.js.map +1 -1
- package/dist/frame-loop.d.ts +19 -105
- package/dist/frame-loop.d.ts.map +1 -1
- package/dist/frame-loop.js +20 -82
- package/dist/frame-loop.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -15
- package/dist/index.js.map +1 -1
- package/dist/mix-timeline-audio.d.ts +7 -24
- package/dist/mix-timeline-audio.d.ts.map +1 -1
- package/dist/mix-timeline-audio.js +7 -23
- package/dist/mix-timeline-audio.js.map +1 -1
- package/dist/native-export.d.ts +29 -0
- package/dist/native-export.d.ts.map +1 -0
- package/dist/native-export.js +99 -0
- package/dist/native-export.js.map +1 -0
- package/dist/parallel/export-parallel.d.ts +2 -16
- package/dist/parallel/export-parallel.d.ts.map +1 -1
- package/dist/parallel/export-parallel.js +1 -11
- package/dist/parallel/export-parallel.js.map +1 -1
- package/dist/parallel/governor.d.ts +2 -15
- package/dist/parallel/governor.d.ts.map +1 -1
- package/dist/parallel/governor.js +1 -5
- package/dist/parallel/governor.js.map +1 -1
- package/dist/parallel/lane.d.ts +1 -5
- package/dist/parallel/lane.d.ts.map +1 -1
- package/dist/parallel/lane.js.map +1 -1
- package/dist/parallel/plan.d.ts +3 -7
- package/dist/parallel/plan.d.ts.map +1 -1
- package/dist/parallel/plan.js +1 -6
- package/dist/parallel/plan.js.map +1 -1
- package/dist/parallel/run-lanes.d.ts +4 -18
- package/dist/parallel/run-lanes.d.ts.map +1 -1
- package/dist/parallel/run-lanes.js +1 -12
- package/dist/parallel/run-lanes.js.map +1 -1
- package/dist/screenshot.d.ts +1 -12
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +1 -12
- package/dist/screenshot.js.map +1 -1
- package/dist/still.d.ts +17 -74
- package/dist/still.d.ts.map +1 -1
- package/dist/still.js +13 -50
- package/dist/still.js.map +1 -1
- package/dist/ticker.d.ts +10 -39
- package/dist/ticker.d.ts.map +1 -1
- package/dist/ticker.js +13 -45
- package/dist/ticker.js.map +1 -1
- package/package.json +4 -4
- package/dist/browser/chunks/chunk-F3AZKPHU.js +0 -2
- package/dist/browser/chunks/chunk-F3AZKPHU.js.map +0 -7
package/dist/ticker.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { Ticker } from "@motionscript/core";
|
|
2
|
-
/**
|
|
3
|
-
* Ticker backed by a Web Audio AudioContext. Clip time follows
|
|
4
|
-
* `audioContext.currentTime` (within a few ms, see `startLoop`), so any
|
|
5
|
-
* AudioBufferSourceNodes scheduled on the same context play in sync.
|
|
6
|
-
*
|
|
7
|
-
* When paused we suspend the context (audio stops, currentTime freezes);
|
|
8
|
-
* when playing we resume and a rAF loop publishes ticks at the target fps.
|
|
9
|
-
*
|
|
10
|
-
* A single silent buffer covering the full timeline is started on play(),
|
|
11
|
-
* which keeps the context active and gives the browser a stable audio
|
|
12
|
-
* graph to schedule against even on scenes that contain no audio nodes.
|
|
13
|
-
*/
|
|
2
|
+
/** Ticker backed by a Web Audio AudioContext: clip time follows `audioContext.currentTime` (within a few ms, see `startLoop`), so AudioBufferSourceNodes on the same context play in sync. Paused suspends the context (currentTime freezes); playing resumes it and a rAF loop publishes ticks at the target fps. A silent buffer covering the full timeline starts on play() to keep the context active even for scenes with no audio nodes. */
|
|
14
3
|
export class WebTicker extends Ticker {
|
|
15
4
|
contextOf;
|
|
16
5
|
ownsContext;
|
|
@@ -24,11 +13,7 @@ export class WebTicker extends Ticker {
|
|
|
24
13
|
/** Bumped by every `seek`, so the loop can tell that a listener or tick callback moved the playhead under it. */
|
|
25
14
|
seekEpoch = 0;
|
|
26
15
|
silentSource = null;
|
|
27
|
-
/**
|
|
28
|
-
* `context` may be a getter, called on the first `play`: a session hands
|
|
29
|
-
* over its audio sink's, which is created on first use, so a session that
|
|
30
|
-
* never plays never opens the audio device.
|
|
31
|
-
*/
|
|
16
|
+
/** `context` may be a getter, called on the first `play`, so a session that never plays never opens the audio device. */
|
|
32
17
|
constructor(opts) {
|
|
33
18
|
super();
|
|
34
19
|
const { context } = opts;
|
|
@@ -52,14 +37,7 @@ export class WebTicker extends Ticker {
|
|
|
52
37
|
this.seekEpoch++;
|
|
53
38
|
this.setCurrentTime(clamped);
|
|
54
39
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Anchors elapsed-time tracking to the current `context.currentTime`, starts the silent ticker
|
|
57
|
-
* + rAF tick loop and asks a suspended context to resume.
|
|
58
|
-
*
|
|
59
|
-
* Synchronous, as {@link Ticker.play} is: a `pause` or `seek` in the same turn must find a
|
|
60
|
-
* running clock to stop. A suspended context's `currentTime` is frozen, so the clock holds at
|
|
61
|
-
* the anchor until the resume lands — outside a user gesture that is never.
|
|
62
|
-
*/
|
|
40
|
+
/** Anchors elapsed-time tracking to `context.currentTime`, starts the silent ticker and rAF loop, and asks a suspended context to resume. Synchronous, as {@link Ticker.play} is: a `pause` or `seek` in the same turn must find a running clock to stop. A suspended context's `currentTime` is frozen, so the clock holds at the anchor until the resume lands (outside a user gesture, never). */
|
|
63
41
|
play(speed = 1, reverse = false) {
|
|
64
42
|
this.speed = speed;
|
|
65
43
|
this.reverse = reverse;
|
|
@@ -89,7 +67,7 @@ export class WebTicker extends Ticker {
|
|
|
89
67
|
}
|
|
90
68
|
super.pause();
|
|
91
69
|
}
|
|
92
|
-
/** (Re)starts the silent buffer source covering the remaining timeline
|
|
70
|
+
/** (Re)starts the silent buffer source covering the remaining timeline (see the class note). */
|
|
93
71
|
startSilentTicker() {
|
|
94
72
|
this.stopSilentTicker();
|
|
95
73
|
const remaining = Math.max(0.001, this.duration - this.seekOffset);
|
|
@@ -109,7 +87,6 @@ export class WebTicker extends Ticker {
|
|
|
109
87
|
this.silentSource.disconnect();
|
|
110
88
|
}
|
|
111
89
|
catch {
|
|
112
|
-
// already stopped
|
|
113
90
|
}
|
|
114
91
|
this.silentSource = null;
|
|
115
92
|
}
|
|
@@ -124,19 +101,12 @@ export class WebTicker extends Ticker {
|
|
|
124
101
|
return { time, ended: this.reverse ? time <= 0 : time >= this.duration };
|
|
125
102
|
}
|
|
126
103
|
/**
|
|
127
|
-
* Drives ticks off `requestAnimationFrame`, firing `tick()` when the playhead reaches another
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* by each animation frame's own interval, pulled 5% of the way to the audio clock every frame
|
|
134
|
-
* and snapped to it when they disagree by more than 50 ms (a stall, a seek). It stays within
|
|
135
|
-
* a few ms of the audio and moves one frame per frame.
|
|
136
|
-
*
|
|
137
|
-
* A listener may `seek` (a host looping wraps to 0 when it hears the end), so the end is
|
|
138
|
-
* re-read after the listeners and the tick callbacks have run: a run that was seeked out of
|
|
139
|
-
* its end carries on, and one that was not pauses itself.
|
|
104
|
+
* Drives ticks off `requestAnimationFrame`, firing `tick()` when the playhead reaches another project frame, and
|
|
105
|
+
* once more at the end of the run. `context.currentTime` moves in whole render quanta handed over in bursts (at
|
|
106
|
+
* 48 kHz on a 60 Hz display 8, 10.67, 18.67 or 21.33 ms between frames), so a playhead read straight off it skipped
|
|
107
|
+
* up to a third of the frames. The playhead therefore advances by each animation frame's own interval, pulled 5% of
|
|
108
|
+
* the way to the audio clock every frame and snapped to it past 50 ms apart (a stall, a seek). A listener may `seek`
|
|
109
|
+
* (a host looping wraps to 0 on the end), so the end is re-read after listeners and tick callbacks run.
|
|
140
110
|
*/
|
|
141
111
|
startLoop() {
|
|
142
112
|
if (this.rafId !== null)
|
|
@@ -162,11 +132,9 @@ export class WebTicker extends Ticker {
|
|
|
162
132
|
let epoch = this.seekEpoch;
|
|
163
133
|
const position = steadied(now);
|
|
164
134
|
let ended = position.ended;
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
// hear about it once per frame. The end of the run always reports, or the final
|
|
169
|
-
// position would never reach a host. See `Ticker.setCurrentTime`.
|
|
135
|
+
// The loop runs at the display's refresh rate (2-3x the render rate on 120/144Hz), so the clock advances every
|
|
136
|
+
// round (`play`/`pause` maths need it exact) while listeners hear once per frame. The end of the run always
|
|
137
|
+
// reports or the final position never reaches a host. See `Ticker.setCurrentTime`.
|
|
170
138
|
const crossed = frameOf(position.time) !== lastFrame;
|
|
171
139
|
const report = crossed || ended;
|
|
172
140
|
this.setCurrentTime(position.time, report);
|
package/dist/ticker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ticker.js","sourceRoot":"","sources":["../src/ticker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,SAAU,SAAQ,MAAM;IAChB,SAAS,CAAqB;IAC9B,WAAW,CAAU;IAC9B,QAAQ,GAAwB,IAAI,CAAC;IACrC,GAAG,CAAS;IAEZ,gBAAgB,GAAW,CAAC,CAAC;IAC7B,UAAU,GAAW,CAAC,CAAC;IACvB,KAAK,GAAW,CAAC,CAAC;IAClB,OAAO,GAAY,KAAK,CAAC;IAEzB,KAAK,GAAkB,IAAI,CAAC;IACpC,iHAAiH;IACzG,SAAS,GAAW,CAAC,CAAC;IACtB,YAAY,GAAiC,IAAI,CAAC;IAE1D;;;;OAIG;IACH,YAAY,IAAoE;QAC5E,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,IAAI,IAAI,Y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,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEO,QAAQ;QACZ,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACtB,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,CAAC;IACL,CAAC;IAED,OAAO;QACH,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAChC,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import { Ticker } from \"@motionscript/core\";\n\n/**\n * Ticker backed by a Web Audio AudioContext. Clip time follows\n * `audioContext.currentTime` (within a few ms, see `startLoop`), so any\n * AudioBufferSourceNodes scheduled on the same context play in sync.\n *\n * When paused we suspend the context (audio stops, currentTime freezes);\n * when playing we resume and a rAF loop publishes ticks at the target fps.\n *\n * A single silent buffer covering the full timeline is started on play(),\n * which keeps the context active and gives the browser a stable audio\n * graph to schedule against even on scenes that contain no audio nodes.\n */\nexport class WebTicker extends Ticker {\n private readonly contextOf: () => AudioContext;\n private readonly ownsContext: boolean;\n private _context: AudioContext | null = null;\n private fps: number;\n\n private playStartCtxTime: number = 0;\n private seekOffset: number = 0;\n private speed: number = 1;\n private reverse: boolean = false;\n\n private rafId: number | null = null;\n /** Bumped by every `seek`, so the loop can tell that a listener or tick callback moved the playhead under it. */\n private seekEpoch: number = 0;\n private silentSource: AudioBufferSourceNode | null = null;\n\n /**\n * `context` may be a getter, called on the first `play`: a session hands\n * over its audio sink's, which is created on first use, so a session that\n * never plays never opens the audio device.\n */\n constructor(opts: { context?: AudioContext | (() => AudioContext); fps: number }) {\n super();\n const { context } = opts;\n this.contextOf = typeof context === \"function\" ? context : () => context ?? new AudioContext();\n this.ownsContext = !context;\n this.fps = opts.fps;\n }\n\n getContext(): AudioContext {\n this._context ??= this.contextOf();\n return this._context;\n }\n\n private get context(): AudioContext {\n return this.getContext();\n }\n\n seek(t: number): void {\n const clamped = Math.max(0, Math.min(t, this.duration));\n this.seekOffset = clamped;\n // The clock is read only while playing; `play` anchors it afresh.\n if (this.isPlaying) this.playStartCtxTime = this.context.currentTime;\n this.seekEpoch++;\n this.setCurrentTime(clamped);\n }\n\n /**\n * Anchors elapsed-time tracking to the current `context.currentTime`, starts the silent ticker\n * + rAF tick loop and asks a suspended context to resume.\n *\n * Synchronous, as {@link Ticker.play} is: a `pause` or `seek` in the same turn must find a\n * running clock to stop. A suspended context's `currentTime` is frozen, so the clock holds at\n * the anchor until the resume lands — outside a user gesture that is never.\n */\n play(speed: number = 1, reverse: boolean = false): void {\n this.speed = speed;\n this.reverse = reverse;\n this.seekOffset = this.currentTime;\n\n if (this.context.state === \"suspended\") {\n this.context.resume().then(\n () => {\n // A pause that arrived while the resume was pending could not suspend it.\n if (!this.isPlaying && this.context.state === \"running\") void this.context.suspend();\n },\n (error) => {\n console.error(\"[WebTicker] The audio context could not resume:\", error);\n this.pause();\n },\n );\n }\n\n this.playStartCtxTime = this.context.currentTime;\n this.startSilentTicker();\n super.play(speed, reverse);\n this.startLoop();\n }\n\n /** Stops the tick loop and silent ticker, then suspends the context — freezing `currentTime` so elapsed-time math stays correct across the pause. */\n pause(): void {\n this.seekOffset = this.currentTime;\n this.stopLoop();\n this.stopSilentTicker();\n if (this._context?.state === \"running\") {\n this._context.suspend();\n }\n super.pause();\n }\n\n /** (Re)starts the silent buffer source covering the remaining timeline — keeps the AudioContext active and gives a stable graph for other AudioBufferSourceNodes to schedule against, per the class-level note. */\n private startSilentTicker(): void {\n this.stopSilentTicker();\n const remaining = Math.max(0.001, this.duration - this.seekOffset);\n const sampleRate = this.context.sampleRate;\n const buffer = this.context.createBuffer(1, Math.ceil(remaining * sampleRate), sampleRate);\n const source = this.context.createBufferSource();\n source.buffer = buffer;\n source.connect(this.context.destination);\n source.start();\n this.silentSource = source;\n }\n\n private stopSilentTicker(): void {\n if (this.silentSource) {\n try {\n this.silentSource.onended = null;\n this.silentSource.stop();\n this.silentSource.disconnect();\n } catch {\n // already stopped\n }\n this.silentSource = null;\n }\n }\n\n /** Where the playhead is now, from elapsed `context.currentTime` (so it stays sample-accurate), and whether that is the end of the run. */\n private position(): { time: number; ended: boolean } {\n const elapsed = (this.context.currentTime - this.playStartCtxTime) * this.speed;\n const next = this.reverse\n ? this.seekOffset - elapsed\n : this.seekOffset + elapsed;\n const time = Math.max(0, Math.min(next, this.duration));\n return { time, ended: this.reverse ? time <= 0 : time >= this.duration };\n }\n\n /**\n * Drives ticks off `requestAnimationFrame`, firing `tick()` when the playhead reaches another\n * project frame — and once more at the end of the run, whether or not it landed on a boundary.\n *\n * `context.currentTime` moves in whole render quanta handed over in bursts: at 48 kHz on a\n * 60 Hz display it advances 8, 10.67, 18.67 or 21.33 ms between animation frames, and a\n * playhead read straight off it skipped up to a third of the frames. So the playhead advances\n * by each animation frame's own interval, pulled 5% of the way to the audio clock every frame\n * and snapped to it when they disagree by more than 50 ms (a stall, a seek). It stays within\n * a few ms of the audio and moves one frame per frame.\n *\n * A listener may `seek` (a host looping wraps to 0 when it hears the end), so the end is\n * re-read after the listeners and the tick callbacks have run: a run that was seeked out of\n * its end carries on, and one that was not pauses itself.\n */\n private startLoop(): void {\n if (this.rafId !== null) return;\n const frameOf = (t: number) => Math.floor(t * this.fps + 1e-6);\n let lastFrame = frameOf(this.currentTime);\n let steady: { time: number; at: number; epoch: number } | null = null;\n const steadied = (now: number): { time: number; ended: boolean } => {\n const audio = this.position();\n let time = audio.time;\n if (!audio.ended && steady && steady.epoch === this.seekEpoch) {\n const step = ((now - steady.at) / 1000) * this.speed;\n const predicted = this.reverse ? steady.time - step : steady.time + step;\n const drift = audio.time - predicted;\n const next = predicted + drift * 0.05;\n if (Math.abs(drift) <= 0.05 && next > 0 && next < this.duration) time = next;\n }\n steady = { time, at: now, epoch: this.seekEpoch };\n return { time, ended: audio.ended };\n };\n\n const loop = async (now: number) => {\n let epoch = this.seekEpoch;\n const position = steadied(now);\n let ended = position.ended;\n // This loop runs at the display's refresh rate, which on a 120 or 144Hz panel is two\n // or three times the rate anything is rendered at — so the clock advances every time\n // round (the elapsed maths in `play`/`pause` depend on it being exact) while listeners\n // hear about it once per frame. The end of the run always reports, or the final\n // position would never reach a host. See `Ticker.setCurrentTime`.\n const crossed = frameOf(position.time) !== lastFrame;\n const report = crossed || ended;\n this.setCurrentTime(position.time, report);\n\n const reread = () => {\n if (this.seekEpoch === epoch) return;\n epoch = this.seekEpoch;\n lastFrame = frameOf(this.currentTime);\n ended = this.position().ended;\n };\n reread();\n\n if (report) {\n lastFrame = frameOf(this.currentTime);\n // Await so that a slow tick (asset load on a clip\n // boundary) doesn't queue a second concurrent tick.\n await this.tick();\n reread();\n }\n\n // If pause() cleared the rafId while we were awaiting tick(),\n // do not resume the loop.\n if (this.rafId === null) return;\n if (ended) {\n this.pause();\n return;\n }\n this.rafId = requestAnimationFrame(loop);\n };\n\n this.rafId = requestAnimationFrame(loop);\n }\n\n private stopLoop(): void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n }\n\n dispose(): void {\n this.stopLoop();\n this.stopSilentTicker();\n if (this.ownsContext) {\n void this._context?.close();\n }\n super.dispose();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ticker.js","sourceRoot":"","sources":["../src/ticker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,kbAAkb;AAClb,MAAM,OAAO,SAAU,SAAQ,MAAM;IAChB,SAAS,CAAqB;IAC9B,WAAW,CAAU;IAC9B,QAAQ,GAAwB,IAAI,CAAC;IACrC,GAAG,CAAS;IAEZ,gBAAgB,GAAW,CAAC,CAAC;IA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CAAC,CAAC;gBACtC,kDAAkD;gBAClD,oDAAoD;gBACpD,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,MAAM,EAAE,CAAC;YACb,CAAC;YAED,8DAA8D;YAC9D,0BAA0B;YAC1B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;gBAAE,OAAO;YAChC,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,OAAO;YACX,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEO,QAAQ;QACZ,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACtB,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,CAAC;IACL,CAAC;IAED,OAAO;QACH,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAChC,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import { Ticker } from \"@motionscript/core\";\n\n/** Ticker backed by a Web Audio AudioContext: clip time follows `audioContext.currentTime` (within a few ms, see `startLoop`), so AudioBufferSourceNodes on the same context play in sync. Paused suspends the context (currentTime freezes); playing resumes it and a rAF loop publishes ticks at the target fps. A silent buffer covering the full timeline starts on play() to keep the context active even for scenes with no audio nodes. */\nexport class WebTicker extends Ticker {\n private readonly contextOf: () => AudioContext;\n private readonly ownsContext: boolean;\n private _context: AudioContext | null = null;\n private fps: number;\n\n private playStartCtxTime: number = 0;\n private seekOffset: number = 0;\n private speed: number = 1;\n private reverse: boolean = false;\n\n private rafId: number | null = null;\n /** Bumped by every `seek`, so the loop can tell that a listener or tick callback moved the playhead under it. */\n private seekEpoch: number = 0;\n private silentSource: AudioBufferSourceNode | null = null;\n\n /** `context` may be a getter, called on the first `play`, so a session that never plays never opens the audio device. */\n constructor(opts: { context?: AudioContext | (() => AudioContext); fps: number }) {\n super();\n const { context } = opts;\n this.contextOf = typeof context === \"function\" ? context : () => context ?? new AudioContext();\n this.ownsContext = !context;\n this.fps = opts.fps;\n }\n\n getContext(): AudioContext {\n this._context ??= this.contextOf();\n return this._context;\n }\n\n private get context(): AudioContext {\n return this.getContext();\n }\n\n seek(t: number): void {\n const clamped = Math.max(0, Math.min(t, this.duration));\n this.seekOffset = clamped;\n // The clock is read only while playing; `play` anchors it afresh.\n if (this.isPlaying) this.playStartCtxTime = this.context.currentTime;\n this.seekEpoch++;\n this.setCurrentTime(clamped);\n }\n\n /** Anchors elapsed-time tracking to `context.currentTime`, starts the silent ticker and rAF loop, and asks a suspended context to resume. Synchronous, as {@link Ticker.play} is: a `pause` or `seek` in the same turn must find a running clock to stop. A suspended context's `currentTime` is frozen, so the clock holds at the anchor until the resume lands (outside a user gesture, never). */\n play(speed: number = 1, reverse: boolean = false): void {\n this.speed = speed;\n this.reverse = reverse;\n this.seekOffset = this.currentTime;\n\n if (this.context.state === \"suspended\") {\n this.context.resume().then(\n () => {\n // A pause that arrived while the resume was pending could not suspend it.\n if (!this.isPlaying && this.context.state === \"running\") void this.context.suspend();\n },\n (error) => {\n console.error(\"[WebTicker] The audio context could not resume:\", error);\n this.pause();\n },\n );\n }\n\n this.playStartCtxTime = this.context.currentTime;\n this.startSilentTicker();\n super.play(speed, reverse);\n this.startLoop();\n }\n\n /** Stops the tick loop and silent ticker, then suspends the context — freezing `currentTime` so elapsed-time math stays correct across the pause. */\n pause(): void {\n this.seekOffset = this.currentTime;\n this.stopLoop();\n this.stopSilentTicker();\n if (this._context?.state === \"running\") {\n this._context.suspend();\n }\n super.pause();\n }\n\n /** (Re)starts the silent buffer source covering the remaining timeline (see the class note). */\n private startSilentTicker(): void {\n this.stopSilentTicker();\n const remaining = Math.max(0.001, this.duration - this.seekOffset);\n const sampleRate = this.context.sampleRate;\n const buffer = this.context.createBuffer(1, Math.ceil(remaining * sampleRate), sampleRate);\n const source = this.context.createBufferSource();\n source.buffer = buffer;\n source.connect(this.context.destination);\n source.start();\n this.silentSource = source;\n }\n\n private stopSilentTicker(): void {\n if (this.silentSource) {\n try {\n this.silentSource.onended = null;\n this.silentSource.stop();\n this.silentSource.disconnect();\n } catch {\n }\n this.silentSource = null;\n }\n }\n\n /** Where the playhead is now, from elapsed `context.currentTime` (so it stays sample-accurate), and whether that is the end of the run. */\n private position(): { time: number; ended: boolean } {\n const elapsed = (this.context.currentTime - this.playStartCtxTime) * this.speed;\n const next = this.reverse\n ? this.seekOffset - elapsed\n : this.seekOffset + elapsed;\n const time = Math.max(0, Math.min(next, this.duration));\n return { time, ended: this.reverse ? time <= 0 : time >= this.duration };\n }\n\n /**\n * Drives ticks off `requestAnimationFrame`, firing `tick()` when the playhead reaches another project frame, and\n * once more at the end of the run. `context.currentTime` moves in whole render quanta handed over in bursts (at\n * 48 kHz on a 60 Hz display 8, 10.67, 18.67 or 21.33 ms between frames), so a playhead read straight off it skipped\n * up to a third of the frames. The playhead therefore advances by each animation frame's own interval, pulled 5% of\n * the way to the audio clock every frame and snapped to it past 50 ms apart (a stall, a seek). A listener may `seek`\n * (a host looping wraps to 0 on the end), so the end is re-read after listeners and tick callbacks run.\n */\n private startLoop(): void {\n if (this.rafId !== null) return;\n const frameOf = (t: number) => Math.floor(t * this.fps + 1e-6);\n let lastFrame = frameOf(this.currentTime);\n let steady: { time: number; at: number; epoch: number } | null = null;\n const steadied = (now: number): { time: number; ended: boolean } => {\n const audio = this.position();\n let time = audio.time;\n if (!audio.ended && steady && steady.epoch === this.seekEpoch) {\n const step = ((now - steady.at) / 1000) * this.speed;\n const predicted = this.reverse ? steady.time - step : steady.time + step;\n const drift = audio.time - predicted;\n const next = predicted + drift * 0.05;\n if (Math.abs(drift) <= 0.05 && next > 0 && next < this.duration) time = next;\n }\n steady = { time, at: now, epoch: this.seekEpoch };\n return { time, ended: audio.ended };\n };\n\n const loop = async (now: number) => {\n let epoch = this.seekEpoch;\n const position = steadied(now);\n let ended = position.ended;\n // The loop runs at the display's refresh rate (2-3x the render rate on 120/144Hz), so the clock advances every\n // round (`play`/`pause` maths need it exact) while listeners hear once per frame. The end of the run always\n // reports or the final position never reaches a host. See `Ticker.setCurrentTime`.\n const crossed = frameOf(position.time) !== lastFrame;\n const report = crossed || ended;\n this.setCurrentTime(position.time, report);\n\n const reread = () => {\n if (this.seekEpoch === epoch) return;\n epoch = this.seekEpoch;\n lastFrame = frameOf(this.currentTime);\n ended = this.position().ended;\n };\n reread();\n\n if (report) {\n lastFrame = frameOf(this.currentTime);\n // Await so that a slow tick (asset load on a clip\n // boundary) doesn't queue a second concurrent tick.\n await this.tick();\n reread();\n }\n\n // If pause() cleared the rafId while we were awaiting tick(),\n // do not resume the loop.\n if (this.rafId === null) return;\n if (ended) {\n this.pause();\n return;\n }\n this.rafId = requestAnimationFrame(loop);\n };\n\n this.rafId = requestAnimationFrame(loop);\n }\n\n private stopLoop(): void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n }\n\n dispose(): void {\n this.stopLoop();\n this.stopSilentTicker();\n if (this.ownsContext) {\n void this._context?.close();\n }\n super.dispose();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionscript/browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Motion Script in the browser: WebGPU rendering through @motionscript/renderer, video and still export, audio playback.",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@motionscript/core": "^0.1.
|
|
41
|
+
"@motionscript/core": "^0.1.1-alpha.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@vitest/browser": "4.1.7",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"typescript": "^6.0.3",
|
|
54
54
|
"typescript-eslint": "^8.48.0",
|
|
55
55
|
"vitest": "^4.1.5",
|
|
56
|
-
"@motionscript/core": "0.1.
|
|
56
|
+
"@motionscript/core": "0.1.1-alpha.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@mediabunny/mp3-encoder": "^1.49.0",
|
|
60
60
|
"esbuild-wasm": "^0.28.1",
|
|
61
61
|
"mediabunny": "^1.40.1",
|
|
62
|
-
"@motionscript/renderer": "^0.1.
|
|
62
|
+
"@motionscript/renderer": "^0.1.1-alpha.0"
|
|
63
63
|
},
|
|
64
64
|
"motionscriptBrowser": {
|
|
65
65
|
"assets": {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var _=null;function nt(e){_=e}async function F(e){if(!_)return null;try{return await _(e)}catch{return null}}async function B(e){let t=await fetch(e);if(!t.ok){let n=t.statusText?`${t.status} ${t.statusText}`:`${t.status}`;throw new Error(`Fetching "${e}" failed: HTTP ${n}`)}return t.blob()}async function st(e){return await F(e)??B(e)}import{busStopKey as X}from"@motionscript/core";import{clipTimeAtSource as H,isRamp as E,resolveRamp as K,sampleRamp as T,sourceTimeAtClip as U,staticValue as P,transitionGainAt as Q,transitionSpans as z}from"@motionscript/core";var L=200;function I(e,t,n,s,r,i=c=>c){let c=u=>{let f=i(u);return Number.isFinite(f)?f:e.value};if(!E(t)){e.value=c(t);return}if(!Number.isFinite(s)||s<=0){e.value=c(P(t,e.value));return}let a=K(t,s);if(a.length===0)return;let d=n-r;e.setValueAtTime(c(T(t,Math.max(0,r),s,e.value)),n);for(let u=1;u<a.length;u++){let f=a[u-1],o=a[u],l=d+f.time,h=d+o.time;if(h<=n)continue;let p=o.time-f.time;if(p<=0){e.setValueAtTime(c(o.value),Math.max(h,n));continue}let m=Math.max(0,(n-l)/p),x=Math.max(l,n);if(o.linear)m===0&&e.setValueAtTime(c(f.value),x),e.linearRampToValueAtTime(c(o.value),h);else{let y=h-x,g=Math.max(2,Math.ceil(y*L)),v=new Float32Array(g);for(let w=0;w<g;w++){let O=m+(1-m)*(w/(g-1));v[w]=c(f.value+(o.value-f.value)*o.ease(O))}e.setValueCurveAtTime(v,x,y)}}}function b(e,t,n,s=e.currentTime,r=0,i=0){let c=[],a=[],d=t,u=o=>{d.connect(o),c.push(o),d=o},f=(o,l,h)=>I(o,l,s,r,i,h);for(let o of n)switch(o.type){case"gain":{let l=e.createGain();f(l.gain,o.value),u(l);break}case"highpass":case"lowpass":{let l=e.createBiquadFilter();l.type=o.type,f(l.frequency,o.frequency),o.q!==void 0&&f(l.Q,o.q),u(l);break}case"tremolo":{let l=e.createGain(),h=e.createOscillator(),p=e.createGain();f(l.gain,o.depth,m=>1-M(m)/2),f(p.gain,o.depth,m=>M(m)/2),f(h.frequency,o.rate),h.connect(p),p.connect(l.gain),c.push(p),a.push(h),u(l);break}case"echo":{let l=d,h=e.createGain(),p=e.createGain();f(p.gain,o.mix??.5,g=>1-M(g)),l.connect(p),p.connect(h);let m=e.createDelay(Math.max(1,J(o.delay)+1));f(m.delayTime,o.delay);let x=e.createGain();f(x.gain,o.feedback,g=>Math.max(0,Math.min(.99,g)));let y=e.createGain();f(y.gain,o.mix??.5,g=>M(g)),l.connect(m),m.connect(x),x.connect(m),m.connect(y),y.connect(h),c.push(p,m,x,y,h),d=h;break}}return{output:d,nodes:c,oscillators:a}}function M(e){return Math.max(0,Math.min(1,e))}function J(e){return E(e)?Math.max(0,...e.keys.map(t=>t.value)):e}function V(e,t,n,s,r,i){if(!n&&!s)return;let c=Math.max(0,i),a=o=>Q(o,t,n,s);e.setValueAtTime(a(c),r);let d=z(t,n,s),u=[];d.in>0&&u.push([0,d.in]),d.out>0&&Number.isFinite(t)&&u.push([t-d.out,t]);let f=r-i;for(let[o,l]of u){let h=Math.max(o,c),p=l-h;if(p<=0)continue;let m=Math.max(2,Math.ceil(p*L)),x=new Float32Array(m);for(let y=0;y<m;y++)x[y]=a(h+p*(y/(m-1)));e.setValueCurveAtTime(x,f+h,p)}}function R(e,t){let n=e.speed??1,s=E(n)?n:void 0,r=s||!(Number.isFinite(n)&&n>0)?1:n,i=e.sourceLength??Math.max(0,t-e.trimStart),c=Number.isFinite(e.endAt),a=c?Math.max(0,e.endAt-e.startAt):H(n,i);return{rate:r,speedRamp:s,sourceLength:i,clipDuration:a,transitionLength:c?a:1/0}}function S(e,t){return e.speedRamp?U(e.speedRamp,e.sourceLength,t):t*e.rate}function k(e,t,n,s,r,i){let c=e.createGain();if(I(c.gain,n.volume??1,r,s.clipDuration,i),t.connect(c),!n.transitionIn&&!n.transitionOut)return{output:c,nodes:[c]};let a=e.createGain();return V(a.gain,s.transitionLength,n.transitionIn,n.transitionOut,r,i),c.connect(a),{output:a,nodes:[c,a]}}function C(e,t,n,s,r,i){if(!t)return;let c=1/L,a=Math.max(0,i),d=u=>Math.max(1e-4,T(t,U(t,n,u),n,1));e.setValueAtTime(d(a),r);for(let u=a+c;u<=s+c;u+=c){let f=Math.min(u,s);if(e.linearRampToValueAtTime(d(f),r+(f-a)),f>=s)break}}var A=class{ctx;destination;constructor(t,n){this.ctx=t,this.destination=n}inputFor(t,n,s){return!t||t.length===0?this.destination:this.chainFrom(t,0,n,s)}dispose(){for(let t of this.nodes)try{t.disconnect()}catch{}for(let t of this.oscillators)try{t.stop()}catch{}this.nodes.length=0,this.oscillators.length=0,this.inputs.clear()}inputs=new Map;nodes=[];oscillators=[];chainFrom(t,n,s,r){if(n>=t.length)return this.destination;let i=t[n],c=t.slice(n).map(X).join(">"),a=this.inputs.get(c);if(a)return a;let d=this.chainFrom(t,n+1,s,r),u=this.ctx.createGain();u.gain.value=1;let f={type:"gain",value:i.mute?0:i.volume},o=i.endAt-i.startAt,l=b(this.ctx,u,[...i.effects??[],f],s,o,r-i.startAt),h=l.output;if(i.transitionIn||i.transitionOut){let p=this.ctx.createGain();V(p.gain,o,i.transitionIn,i.transitionOut,s,r-i.startAt),h.connect(p),this.nodes.push(p),h=p}h.connect(d),this.nodes.push(u,...l.nodes),this.oscillators.push(...l.oscillators);for(let p of l.oscillators)p.start(s);return this.inputs.set(c,u),u}};function Y(e,t){if(!e.loop)return null;let n=Math.min(Math.max(0,e.trimStart),t),s=Math.min(e.trimEnd??t,t);return s>n?{start:n,end:s}:null}function G(e,t){e.loop=t.loop;let n=e.buffer?Y(t,e.buffer.duration):null;return n&&(e.loopStart=n.start,e.loopEnd=n.end),n}function D(e,t){return!e||t<e.end?t:e.start+(t-e.start)%(e.end-e.start)}var $=44100;function Z(e,t){if(!t)return e;try{return t.getAudioMeta(e).src||e}catch{try{return t.getVideoMeta(e).src||e}catch{return e}}}async function q(e,t){let n=await F(e)??await B(e);return t.decodeAudioData(await n.arrayBuffer())}async function tt(e,t,n={}){if(e.length===0)return null;let s=n.sampleRate??$,r=Math.ceil(t*s);if(r<=0)return null;let i=[...new Set(e.map(o=>o.request.src))],c=new OfflineAudioContext(2,r,s),a=new Set(e.filter(o=>!o.request.optional).map(o=>o.request.src)),d=new Map;await Promise.all(i.map(async o=>{try{d.set(o,await q(Z(o,n.catalog),c))}catch(l){if(a.has(o))throw l}}));let u=new OfflineAudioContext(2,r,s),f=new A(u,u.destination);for(let{request:o,globalOffset:l}of e){let h=d.get(o.src);if(!h)continue;let p=l+o.startAt,x=Math.min(l+o.endAt,t)-p;if(x<=0)continue;let y=u.createBufferSource();y.buffer=h,G(y,o);let g=R(o,h.duration);g.rate!==1&&(y.playbackRate.value=g.rate),C(y.playbackRate,g.speedRamp,g.sourceLength,g.clipDuration,p,0);let v=b(u,y,o.effects??[],p,g.clipDuration,0);k(u,v.output,o,g,p,0).output.connect(f.inputFor(o.bus,0,-l));let O=S(g,x);y.start(p,o.trimStart,O);for(let W of v.oscillators)W.start(p)}return u.startRendering()}var N=class{sampleRate;catalog;constructor(t=$,n){this.sampleRate=t,this.catalog=n}mix(t,n){return tt(t,n,{sampleRate:this.sampleRate,catalog:this.catalog})}};function mt(e){let t=e.numberOfChannels,n=e.length,s=2,r=t*s,i=n*r,c=new ArrayBuffer(44+i),a=new DataView(c),d=(o,l)=>{for(let h=0;h<l.length;h++)a.setUint8(o+h,l.charCodeAt(h))};d(0,"RIFF"),a.setUint32(4,36+i,!0),d(8,"WAVE"),d(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,t,!0),a.setUint32(24,e.sampleRate,!0),a.setUint32(28,e.sampleRate*r,!0),a.setUint16(32,r,!0),a.setUint16(34,8*s,!0),d(36,"data"),a.setUint32(40,i,!0);let u=[];for(let o=0;o<t;o++)u.push(e.getChannelData(o));let f=44;for(let o=0;o<n;o++)for(let l=0;l<t;l++){let h=Math.max(-1,Math.min(1,u[l][o]));a.setInt16(f,h<0?h*32768:h*32767,!0),f+=s}return new Uint8Array(c)}import{AudioSink as et}from"@motionscript/core";var j=class extends et{borrowed;_context=null;bufferCache=new Map;decoding=new Map;active=new Map;scheduled=[];disposed=!1;_graph=null;muted=!1;volume=1;constructor(t){super(),this.borrowed=t}getContext(){return this._context??=this.borrowed??new AudioContext,this._context}get context(){return this.getContext()}get graph(){if(!this._graph){let t=this.context.createGain();t.connect(this.context.destination),this._graph={master:t,buses:new A(this.context,t)},this.applyMasterGain()}return this._graph}unlock(){this.context.state==="suspended"&&this.context.resume()}has(t){return this.bufferCache.has(t)}async append(t,n){if(this.bufferCache.has(t))return;let s=this.decoding.get(t);if(s)return s;let r=this.context.decodeAudioData(n).then(i=>{this.bufferCache.set(t,i)}).finally(()=>{this.decoding.delete(t)});this.decoding.set(t,r),await r}retain(t){for(let n of[...this.bufferCache.keys()])t.has(n)||this.bufferCache.delete(n);for(let[n,s]of this.active)t.has(s.request.src)||this.stopSource(n,s)}schedule(t){let n=new Set(t.map(s=>s.id));for(let[s,r]of this.active)n.has(s)||this.stopSource(s,r);this.scheduled=t.slice()}syncTo(t){let n=new Set;for(let s of this.scheduled)if(t>=s.startAt&&t<s.endAt&&(n.add(s.id),!this.active.has(s.id))){let i=this.bufferCache.get(s.src);i&&this.playBuffer(i,s,t)}for(let[s,r]of this.active)n.has(s)||this.stopSource(s,r)}async play(t,n,s){this.context.state==="suspended"&&await this.context.resume(),this.syncTo(t)}stop(){for(let[t,n]of this.active)this.stopSource(t,n);this._graph?.buses.dispose()}setMuted(t){this.muted=t,this.applyMasterGain()}setVolume(t){this.volume=Math.max(0,t),this.applyMasterGain()}applyMasterGain(){this._graph&&(this._graph.master.gain.value=this.muted?0:this.volume)}playBuffer(t,n,s){let r=this.context.currentTime,i=R(n,t.duration),c=Math.max(0,s-n.startAt),a=this.context.createBufferSource();a.buffer=t;let d=G(a,n);i.rate!==1&&(a.playbackRate.value=i.rate),C(a.playbackRate,i.speedRamp,i.sourceLength,i.clipDuration,r,c);let u=b(this.context,a,n.effects??[],r,i.clipDuration,c),f=k(this.context,u.output,n,i,r,c);f.output.connect(this.graph.buses.inputFor(n.bus,r,s));let o=n.trimStart+S(i,c);a.start(r,D(d,o));for(let l of u.oscillators)l.start(r);a.onended=()=>{this.active.get(n.id)?.source===a&&this.active.delete(n.id)},this.active.set(n.id,{source:a,request:n,nodes:[...u.nodes,...f.nodes],oscillators:u.oscillators})}stopSource(t,n){try{n.source.onended=null,n.source.stop();for(let s of n.oscillators)s.stop();n.source.disconnect();for(let s of n.nodes)s.disconnect()}catch{}this.active.delete(t)}dispose(){if(this.disposed)return;this.disposed=!0,super.dispose(),this.bufferCache.clear(),this.decoding.clear(),this.scheduled.length=0,this._graph?.buses.dispose();try{this._graph?.master.disconnect()}catch{}let t=this.borrowed?null:this._context;t&&t.state!=="closed"&&t.close()}};export{nt as a,st as b,A as c,$ as d,tt as e,N as f,mt as g,j as h};
|
|
2
|
-
//# sourceMappingURL=chunk-F3AZKPHU.js.map
|
|
@@ -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": ["/**\n * Where a source URL's bytes come from: a host's local store, then the network.\n * The renderer's storage adapter reads every asset through it (`loadBytes`).\n *\n * ## Why the web adapter needs this at all\n *\n * The storage adapter addresses every asset by URL and fetches it. That is\n * right for an asset that lives somewhere, and wrong for one whose bytes the\n * host already has in hand — a file the user has just chosen, a render a local\n * model has just produced, a picture whose upload has not finished or cannot\n * start because there is no network. In all three the adapter downloads bytes\n * that never needed to travel.\n *\n * `NodeStorageAdapter` has had the answer since it was written: an injected\n * `AssetLoader`, with an `inline` map consulted ahead of the disk. This is the\n * same seam for the browser.\n *\n * ## Why it is module-level\n *\n * The storage adapter is constructed at several sites *inside* this package —\n * sessions, the exporter, the audio mixer and the still renderer — none of\n * which a host can reach. A constructor argument would\n * therefore cover the preview and leave export and stills on the network,\n * which is the worst of both: the picture a user sees would come from local\n * bytes and the one they render would not.\n *\n * So this is an *injection point*, not a cache. The adapter still owns every\n * decode, every cache, every size ceiling and every eviction rule; all this\n * changes is where the compressed bytes came from. A source that answers `null`\n * — which is what an unregistered URL, an evicted entry or a host with no local\n * store does — leaves the adapter exactly as it was.\n */\n\n/** Local bytes for a source URL, or `null` to go to the network. */\nexport type AssetByteSource = (src: string) => Promise<Blob | null>;\n\nlet source: AssetByteSource | null = null;\n\n/**\n * Installs the byte source for this browsing context, or clears it with `null`.\n *\n * Called once per window that renders. Later calls replace the previous source\n * rather than stacking, because two sources disagreeing about one URL has no\n * sensible answer.\n */\nexport function setAssetByteSource(next: AssetByteSource | null): void {\n source = next;\n}\n\n/**\n * The bytes for `src`, or `null`.\n *\n * Swallows a throwing source on purpose. A host's local store failing is a\n * cache miss, not a render failure — the caller falls through to `fetch`, which\n * is what it would have done had the source never been installed.\n */\nexport async function localAssetBytes(src: string): Promise<Blob | null> {\n if (!source) return null;\n try {\n return await source(src);\n } catch {\n return null;\n }\n}\n\n/**\n * The network's bytes for `url`. A response that is not OK is a failed load,\n * never bytes: a 404 page handed to the font manager marked a family loaded\n * with no face in it.\n */\nexport async function fetchAssetBytes(url: string): Promise<Blob> {\n const response = await fetch(url);\n if (!response.ok) {\n const status = response.statusText ? `${response.status} ${response.statusText}` : `${response.status}`;\n throw new Error(`Fetching \"${url}\" failed: HTTP ${status}`);\n }\n return response.blob();\n}\n\n/** The bytes for `src`: the host's local store first, then the network. */\nexport async function loadAssetBytes(src: string): Promise<Blob> {\n return (await localAssetBytes(src)) ?? fetchAssetBytes(src);\n}\n", "import { busStopKey, type AudioBusStop, type AudioEffect } from \"@motionscript/core\";\nimport { applyTransitions, buildAudioEffectGraph } from \"./effect-graph\";\n\n/**\n * The live chains for one audio context's buses.\n *\n * Held per context rather than per clip, because that is the whole difference\n * between a bus and per-clip processing: every clip naming a bus connects into\n * the *same* nodes, so a reverb on a bus is one tail the group shares rather\n * than one tail each. Flattening the levels into per-clip gain would sound\n * right; flattening the effects would not.\n */\nexport class AudioBusGraph {\n constructor(\n private readonly ctx: BaseAudioContext,\n /** Where the last bus in a chain connects — the master, or the destination. */\n private readonly destination: AudioNode,\n ) { }\n\n /**\n * The input node a clip on `bus` should connect to, building the chain the\n * first time it is asked for.\n *\n * `bus` is source-adjacent first, so `bus[0]` is the one the clip feeds and\n * each stop after it is that bus's own parent. An empty or absent chain\n * returns the destination, which is what every clip did before buses\n * existed.\n *\n * `startTime` is the context time a new chain's schedule starts from, and\n * `clipTime` the same instant in the stops' own seconds. A curve on a stop\n * runs over its `startAt`–`endAt`, so the two are what place it.\n */\n inputFor(bus: readonly AudioBusStop[] | undefined, startTime: number, clipTime: number): AudioNode {\n if (!bus || bus.length === 0) return this.destination;\n return this.chainFrom(bus, 0, startTime, clipTime);\n }\n\n /** Disconnect every live bus node, so the next {@link inputFor} builds afresh. Safe to call more than once. */\n dispose(): void {\n for (const node of this.nodes) {\n try { node.disconnect(); } catch { /* already torn down */ }\n }\n for (const osc of this.oscillators) {\n try { osc.stop(); } catch { /* never started, or already stopped */ }\n }\n this.nodes.length = 0;\n this.oscillators.length = 0;\n this.inputs.clear();\n }\n\n private readonly inputs = new Map<string, AudioNode>();\n private readonly nodes: AudioNode[] = [];\n private readonly oscillators: OscillatorNode[] = [];\n\n /**\n * Build (or reuse) the chain for `bus[index]`, connected to whatever\n * `bus[index + 1]` resolves to.\n *\n * Recursive rather than iterative because a bus's *output* has to exist\n * before its own nodes can connect to it, and the outermost bus is the last\n * entry.\n *\n * Reused by everything that changes what it sounds like, down to the master,\n * not by id alone: a bus edited under a playing device, or one id on two\n * tracks, is a different chain, and one built for the first would play the\n * second through stale levels and a curve anchored to the wrong span.\n */\n private chainFrom(bus: readonly AudioBusStop[], index: number, startTime: number, clipTime: number): AudioNode {\n if (index >= bus.length) return this.destination;\n\n const stop = bus[index];\n const key = bus.slice(index).map(busStopKey).join(\">\");\n const existing = this.inputs.get(key);\n if (existing) return existing;\n\n const output = this.chainFrom(bus, index + 1, startTime, clipTime);\n\n // A pass-through head every clip connects to, so the bus has one input\n // whatever its effects turn out to be.\n const input = this.ctx.createGain();\n input.gain.value = 1;\n\n // The level is a gain after the effects, as a sound's own level is, so a\n // ramp on it is scheduled exactly as one in `effects` is.\n const level: AudioEffect = { type: \"gain\", value: stop.mute ? 0 : stop.volume };\n const span = stop.endAt - stop.startAt;\n const graph = buildAudioEffectGraph(\n this.ctx, input, [...(stop.effects ?? []), level], startTime, span, clipTime - stop.startAt,\n );\n let tail = graph.output;\n if (stop.transitionIn || stop.transitionOut) {\n const transition = this.ctx.createGain();\n applyTransitions(transition.gain, span, stop.transitionIn, stop.transitionOut, startTime, clipTime - stop.startAt);\n tail.connect(transition);\n this.nodes.push(transition);\n tail = transition;\n }\n tail.connect(output);\n\n this.nodes.push(input, ...graph.nodes);\n this.oscillators.push(...graph.oscillators);\n for (const osc of graph.oscillators) osc.start(startTime);\n\n this.inputs.set(key, input);\n return input;\n }\n}\n", "import {\n clipTimeAtSource,\n isRamp,\n resolveRamp,\n sampleRamp,\n sourceTimeAtClip,\n staticValue,\n transitionGainAt,\n transitionSpans,\n type AudioEffect,\n type AudioRequest,\n type AudioTransition,\n type Param,\n type Ramp,\n} from \"@motionscript/core\";\n\n/**\n * The Web Audio graph for one source's effect chain.\n *\n * `output` is the last node, to connect downstream; `nodes` are every node to\n * `disconnect()` on teardown; `oscillators` are tremolo LFOs the caller starts\n * and stops alongside the source.\n */\nexport interface AudioEffectGraph {\n output: AudioNode;\n nodes: AudioNode[];\n oscillators: OscillatorNode[];\n}\n\n/** Sample points per second an eased segment or a transition is baked into: about every 5 ms. */\nconst CURVE_SAMPLES_PER_SECOND = 200;\n\n/**\n * Apply a {@link Param} to a Web Audio {@link AudioParam}: a number once, a\n * ramp as a schedule — linear segments as `linearRampToValueAtTime`, eased\n * ones baked into `setValueCurveAtTime`.\n *\n * `elapsed` is the clip seconds already played when a mid-clip seek starts the\n * source, so \"now\" reads the ramp at the clip's current position. `clamp` keeps\n * every scheduled value in a param's valid range.\n */\nfunction applyParam(\n audioParam: AudioParam,\n param: Param,\n startTime: number,\n clipDuration: number,\n elapsed: number,\n clamp: (v: number) => number = (v) => v,\n): void {\n // The platform throws on a non-finite value.\n const finite = (v: number): number => {\n const c = clamp(v);\n return Number.isFinite(c) ? c : audioParam.value;\n };\n\n if (!isRamp(param)) {\n audioParam.value = finite(param);\n return;\n }\n if (!Number.isFinite(clipDuration) || clipDuration <= 0) {\n audioParam.value = finite(staticValue(param, audioParam.value));\n return;\n }\n\n const keys = resolveRamp(param, clipDuration);\n if (keys.length === 0) return;\n const base = startTime - elapsed;\n audioParam.setValueAtTime(finite(sampleRamp(param, Math.max(0, elapsed), clipDuration, audioParam.value)), startTime);\n\n for (let i = 1; i < keys.length; i++) {\n const previous = keys[i - 1];\n const key = keys[i];\n const segStart = base + previous.time;\n const segEnd = base + key.time;\n if (segEnd <= startTime) continue;\n\n const span = key.time - previous.time;\n if (span <= 0) {\n audioParam.setValueAtTime(finite(key.value), Math.max(segEnd, startTime));\n continue;\n }\n\n // A segment already under way when the source starts carries on from\n // the value set at `startTime` rather than restarting from its own.\n const done = Math.max(0, (startTime - segStart) / span);\n const curveStart = Math.max(segStart, startTime);\n if (key.linear) {\n if (done === 0) audioParam.setValueAtTime(finite(previous.value), curveStart);\n audioParam.linearRampToValueAtTime(finite(key.value), segEnd);\n } else {\n const curveDur = segEnd - curveStart;\n const count = Math.max(2, Math.ceil(curveDur * CURVE_SAMPLES_PER_SECOND));\n const samples = new Float32Array(count);\n for (let n = 0; n < count; n++) {\n const local = done + (1 - done) * (n / (count - 1));\n samples[n] = finite(previous.value + (key.value - previous.value) * key.ease(local));\n }\n audioParam.setValueCurveAtTime(samples, curveStart, curveDur);\n }\n }\n}\n\n/**\n * Builds the Web Audio graph for a clip's effect chain, after an\n * already-created `source`. Shared by live playback ({@link WebAudioSink}) and\n * offline export (`mixAudio`) so both sound identical.\n *\n * `startTime` is the context time the source starts; `clipDuration` the clip\n * seconds ramps run over (a clip's, or a bus's span); `elapsed` the clip seconds\n * already played at a mid-clip seek (0 for a clean start, negative before the\n * span begins).\n */\nexport function buildAudioEffectGraph(\n ctx: BaseAudioContext,\n source: AudioNode,\n effects: readonly AudioEffect[],\n startTime: number = ctx.currentTime,\n clipDuration: number = 0,\n elapsed: number = 0,\n): AudioEffectGraph {\n const nodes: AudioNode[] = [];\n const oscillators: OscillatorNode[] = [];\n let cursor: AudioNode = source;\n\n const series = (node: AudioNode): void => {\n cursor.connect(node);\n nodes.push(node);\n cursor = node;\n };\n\n const apply = (p: AudioParam, v: Param, clamp?: (n: number) => number): void =>\n applyParam(p, v, startTime, clipDuration, elapsed, clamp);\n\n for (const effect of effects) {\n switch (effect.type) {\n case \"gain\": {\n const gain = ctx.createGain();\n apply(gain.gain, effect.value);\n series(gain);\n break;\n }\n case \"highpass\":\n case \"lowpass\": {\n const biquad = ctx.createBiquadFilter();\n biquad.type = effect.type;\n apply(biquad.frequency, effect.frequency);\n if (effect.q !== undefined) apply(biquad.Q, effect.q);\n series(biquad);\n break;\n }\n case \"tremolo\": {\n // A carrier gain an LFO swings: with depth d the carrier sits at\n // 1 - d/2 and the swing is d/2.\n const carrier = ctx.createGain();\n const lfo = ctx.createOscillator();\n const lfoDepth = ctx.createGain();\n\n apply(carrier.gain, effect.depth, (d) => 1 - clamp01(d) / 2);\n apply(lfoDepth.gain, effect.depth, (d) => clamp01(d) / 2);\n apply(lfo.frequency, effect.rate);\n\n lfo.connect(lfoDepth);\n lfoDepth.connect(carrier.gain);\n\n nodes.push(lfoDepth);\n oscillators.push(lfo);\n series(carrier);\n break;\n }\n case \"echo\": {\n const split = cursor;\n const merge = ctx.createGain();\n\n const dry = ctx.createGain();\n apply(dry.gain, effect.mix ?? 0.5, (m) => 1 - clamp01(m));\n split.connect(dry);\n dry.connect(merge);\n\n // The delay line is sized once, so it has to hold the ramp's longest delay.\n const delay = ctx.createDelay(Math.max(1, maxOf(effect.delay) + 1));\n apply(delay.delayTime, effect.delay);\n const feedbackGain = ctx.createGain();\n apply(feedbackGain.gain, effect.feedback, (f) => Math.max(0, Math.min(0.99, f)));\n const wet = ctx.createGain();\n apply(wet.gain, effect.mix ?? 0.5, (m) => clamp01(m));\n\n split.connect(delay);\n delay.connect(feedbackGain);\n feedbackGain.connect(delay);\n delay.connect(wet);\n wet.connect(merge);\n\n nodes.push(dry, delay, feedbackGain, wet, merge);\n cursor = merge;\n break;\n }\n }\n }\n\n return { output: cursor, nodes, oscillators };\n}\n\nfunction clamp01(v: number): number {\n return Math.max(0, Math.min(1, v));\n}\n\nfunction maxOf(p: Param): number {\n return isRamp(p) ? Math.max(0, ...p.keys.map((k) => k.value)) : p;\n}\n\n/**\n * Schedule `transitionIn`/`transitionOut` onto a gain over a span `length`\n * seconds long, baked like an eased ramp. Between the two it holds at 1.\n */\nexport function applyTransitions(\n gain: AudioParam,\n length: number,\n transitionIn: AudioTransition | undefined,\n transitionOut: AudioTransition | undefined,\n startTime: number,\n elapsed: number,\n): void {\n if (!transitionIn && !transitionOut) return;\n const seek = Math.max(0, elapsed);\n const at = (t: number): number => transitionGainAt(t, length, transitionIn, transitionOut);\n gain.setValueAtTime(at(seek), startTime);\n\n const spans = transitionSpans(length, transitionIn, transitionOut);\n const windows: [number, number][] = [];\n if (spans.in > 0) windows.push([0, spans.in]);\n if (spans.out > 0 && Number.isFinite(length)) windows.push([length - spans.out, length]);\n const base = startTime - elapsed;\n for (const [from, to] of windows) {\n const begin = Math.max(from, seek);\n const duration = to - begin;\n if (duration <= 0) continue;\n const count = Math.max(2, Math.ceil(duration * CURVE_SAMPLES_PER_SECOND));\n const samples = new Float32Array(count);\n for (let n = 0; n < count; n++) samples[n] = at(begin + duration * (n / (count - 1)));\n gain.setValueCurveAtTime(samples, base + begin, duration);\n }\n}\n\n/** How one request plays its source: the rate, and the lengths its ramps and transitions run over. */\nexport interface Playback {\n /** The constant `playbackRate`; 1 under a ramp, which is scheduled instead. */\n rate: number;\n speedRamp?: Ramp;\n /** Source seconds a speed ramp is placed on. */\n sourceLength: number;\n /** Clip seconds the volume and effect ramps run over. */\n clipDuration: number;\n /** What the transitions run over: the clip's length, unknown for an open one. */\n transitionLength: number;\n}\n\nexport function playbackOf(req: AudioRequest, bufferDuration: number): Playback {\n const speed = req.speed ?? 1;\n const speedRamp = isRamp(speed) ? speed : undefined;\n const rate = speedRamp || !(Number.isFinite(speed) && (speed as number) > 0) ? 1 : (speed as number);\n // Placed on the same length core sized the request with, not the decoded buffer.\n const sourceLength = req.sourceLength ?? Math.max(0, bufferDuration - req.trimStart);\n const bounded = Number.isFinite(req.endAt);\n const clipDuration = bounded ? Math.max(0, req.endAt - req.startAt) : clipTimeAtSource(speed, sourceLength);\n return { rate, speedRamp, sourceLength, clipDuration, transitionLength: bounded ? clipDuration : Infinity };\n}\n\n/** Source seconds after `trimStart` that `clipElapsed` clip seconds have played. */\nexport function sourceOffsetOf(playback: Playback, clipElapsed: number): number {\n return playback.speedRamp\n ? sourceTimeAtClip(playback.speedRamp, playback.sourceLength, clipElapsed)\n : clipElapsed * playback.rate;\n}\n\n/**\n * A request's level, then its transitions, after `from`: the gains every\n * request plays through on its way to its bus.\n */\nexport function buildLevel(\n ctx: BaseAudioContext,\n from: AudioNode,\n req: AudioRequest,\n playback: Playback,\n startTime: number,\n elapsed: number,\n): { output: AudioNode; nodes: AudioNode[] } {\n const level = ctx.createGain();\n applyParam(level.gain, req.volume ?? 1, startTime, playback.clipDuration, elapsed);\n from.connect(level);\n if (!req.transitionIn && !req.transitionOut) return { output: level, nodes: [level] };\n const transition = ctx.createGain();\n applyTransitions(transition.gain, playback.transitionLength, req.transitionIn, req.transitionOut, startTime, elapsed);\n level.connect(transition);\n return { output: transition, nodes: [level, transition] };\n}\n\n/**\n * Schedule a speed ramp onto an `AudioBufferSourceNode.playbackRate`.\n *\n * The ramp runs over **source** seconds and Web Audio schedules in context\n * seconds, so this walks clip time in small steps, converts each to a source\n * offset through the integral inverse, and lays down the rate there. `elapsed`\n * is clip seconds already played at a mid-clip seek.\n */\nexport function applySpeedToPlaybackRate(\n rate: AudioParam,\n speed: Ramp | undefined,\n sourceLength: number,\n clipDuration: number,\n startTime: number,\n elapsed: number,\n): void {\n if (!speed) return;\n const step = 1 / CURVE_SAMPLES_PER_SECOND;\n const seekAt = Math.max(0, elapsed);\n const valueAt = (clipElapsed: number): number =>\n Math.max(1e-4, sampleRamp(speed, sourceTimeAtClip(speed, sourceLength, clipElapsed), sourceLength, 1));\n rate.setValueAtTime(valueAt(seekAt), startTime);\n\n for (let s = seekAt + step; s <= clipDuration + step; s += step) {\n const clamped = Math.min(s, clipDuration);\n rate.linearRampToValueAtTime(valueAt(clamped), startTime + (clamped - seekAt));\n if (clamped >= clipDuration) break;\n }\n}\n", "import type { AudioRequest } from \"@motionscript/core\";\n\n/** The span of a decoded buffer a looping request repeats, in source seconds. */\nexport interface LoopRegion {\n start: number;\n end: number;\n}\n\n/**\n * The region a looping request repeats: from its in-point to its out-point, or to\n * the end of the buffer when it has none. `null` for a request that does not loop,\n * and for a degenerate region (an out-point at or before the in-point), where the\n * device falls back to wrapping the whole buffer.\n *\n * Shared by the live device and the offline mixer so a preview and an export loop\n * the same samples.\n */\nexport function loopRegionOf(request: AudioRequest, bufferDuration: number): LoopRegion | null {\n if (!request.loop) return null;\n const start = Math.min(Math.max(0, request.trimStart), bufferDuration);\n const end = Math.min(request.trimEnd ?? bufferDuration, bufferDuration);\n return end > start ? { start, end } : null;\n}\n\n/**\n * Configure `source` to play `request`'s loop: on or off, and over the trimmed\n * region rather than the whole buffer (`loopStart`/`loopEnd` default to the\n * whole buffer, which is how a trim used to be lost).\n */\nexport function applyLoop(source: AudioBufferSourceNode, request: AudioRequest): LoopRegion | null {\n source.loop = request.loop;\n const region = source.buffer ? loopRegionOf(request, source.buffer.duration) : null;\n if (region) {\n source.loopStart = region.start;\n source.loopEnd = region.end;\n }\n return region;\n}\n\n/**\n * Fold a source offset into a loop region.\n *\n * A seek into the middle of a looping clip lands at `trimStart + elapsed`, which\n * can be many passes past the region's end; the device would not wrap an offset\n * that starts outside the region, so it is wrapped here.\n */\nexport function wrapIntoRegion(region: LoopRegion | null, offset: number): number {\n if (!region || offset < region.end) return offset;\n return region.start + ((offset - region.start) % (region.end - region.start));\n}\n", "import type { AssetCatalog } from \"@motionscript/core\";\nimport type { AudioMixer, ScheduledAudioRequest } from \"../frame-loop\";\nimport { fetchAssetBytes, localAssetBytes } from \"../asset-bytes\";\nimport { AudioBusGraph } from \"./bus-graph\";\nimport { applyLoop } from \"./loop-region\";\nimport { applySpeedToPlaybackRate, buildAudioEffectGraph, buildLevel, playbackOf, sourceOffsetOf } from \"./effect-graph\";\n\n/** Sample rate used when the caller doesn't pick one. */\nexport const DEFAULT_SAMPLE_RATE = 44100;\n\nexport interface MixAudioOptions {\n /** Defaults to {@link DEFAULT_SAMPLE_RATE}. */\n sampleRate?: number;\n /**\n * Resolves a request's `src` to the address its bytes live at, as the storage\n * adapter does for the live paths. Omitted, a `src` is\n * fetched as written — right only while the host keys its manifest by URL.\n */\n catalog?: AssetCatalog;\n}\n\n/** Audio first, then video: a clip's own soundtrack is requested under the video's key. */\nfunction audioUrl(src: string, catalog: AssetCatalog | undefined): string {\n if (!catalog) return src;\n try {\n return catalog.getAudioMeta(src).src || src;\n } catch {\n try {\n return catalog.getVideoMeta(src).src || src;\n } catch {\n return src;\n }\n }\n}\n\n/**\n * Reads and decodes an audio source against a scratch `OfflineAudioContext`\n * (decoding requires a context but doesn't render through it). The host's byte\n * source is asked first, as for every other asset read: a mix that went to the\n * network would fail where the preview played, offline or for bytes not yet\n * uploaded.\n */\nasync function fetchAudioBuffer(src: string, ctx: OfflineAudioContext): Promise<AudioBuffer> {\n const blob = (await localAssetBytes(src)) ?? (await fetchAssetBytes(src));\n return ctx.decodeAudioData(await blob.arrayBuffer());\n}\n\n/**\n * Render every scheduled request into one timeline-length buffer.\n *\n * An `OfflineAudioContext` graph — gain per request, looping/trimming, and the\n * same filter chain the live {@link WebAudioSink} builds — rendered in one\n * pass rather than scheduled per frame.\n *\n * Shared by the video exporter and by `mixTimelineAudio`, deliberately: a split\n * export and a whole one have to be the same mix, and two implementations of\n * \"stack these clips\" would eventually disagree.\n *\n * Curve-valued filter params and `speed` curves schedule here exactly as they do\n * in {@link WebAudioSink.playBuffer}, which is the reference implementation —\n * the two must be read side by side when either changes.\n *\n * One deliberate difference: this schedules at absolute context times, so clip\n * starts are sample-accurate here and quantized to `1/fps` in live playback,\n * which starts sources at `currentTime` on a clock tick.\n */\nexport async function mixAudio(\n requests: readonly ScheduledAudioRequest[],\n totalDuration: number,\n options: MixAudioOptions = {},\n): Promise<AudioBuffer | null> {\n if (requests.length === 0) return null;\n const sampleRate = options.sampleRate ?? DEFAULT_SAMPLE_RATE;\n const frames = Math.ceil(totalDuration * sampleRate);\n if (frames <= 0) return null;\n\n const uniqueSrcs = [...new Set(requests.map(r => r.request.src))];\n const scratchCtx = new OfflineAudioContext(2, frames, sampleRate);\n\n // A source only a picture's own sound wants may hold no audio at all, which\n // is silence rather than a failed mix — see `AudioRequest.optional`.\n const asked = new Set(requests.filter(r => !r.request.optional).map(r => r.request.src));\n const decoded = new Map<string, AudioBuffer>();\n await Promise.all(uniqueSrcs.map(async (src) => {\n try {\n decoded.set(src, await fetchAudioBuffer(audioUrl(src, options.catalog), scratchCtx));\n } catch (cause) {\n if (asked.has(src)) throw cause;\n }\n }));\n\n const mixCtx = new OfflineAudioContext(2, frames, sampleRate);\n // The same shared-chain rule the live device uses, for the same reason: an\n // export that flattened buses into per-clip processing would not match what\n // the preview sounded like.\n const buses = new AudioBusGraph(mixCtx, mixCtx.destination);\n\n for (const { request: req, globalOffset } of requests) {\n const srcBuffer = decoded.get(req.src);\n if (!srcBuffer) continue;\n\n const globalStart = globalOffset + req.startAt;\n // `endAt` is `Infinity` for an open clip; either way the timeline bounds it.\n const globalEnd = Math.min(globalOffset + req.endAt, totalDuration);\n const playDuration = globalEnd - globalStart;\n if (playDuration <= 0) continue;\n\n const source = mixCtx.createBufferSource();\n source.buffer = srcBuffer;\n applyLoop(source, req);\n\n // Ramps resolve against the clip's own length, deliberately *not*\n // `playDuration`, which is that length truncated by the timeline end:\n // resolving against the truncated value would squeeze the whole ramp\n // into the surviving part instead of cutting it off. `elapsed` is 0:\n // unlike a live seek, the mix always starts a clip at its beginning.\n const playback = playbackOf(req, srcBuffer.duration);\n if (playback.rate !== 1) source.playbackRate.value = playback.rate;\n applySpeedToPlaybackRate(\n source.playbackRate, playback.speedRamp, playback.sourceLength, playback.clipDuration, globalStart, 0,\n );\n\n // The same chain as the live WebAudioSink graph, so exports sound like the preview.\n const graph = buildAudioEffectGraph(mixCtx, source, req.effects ?? [], globalStart, playback.clipDuration, 0);\n const level = buildLevel(mixCtx, graph.output, req, playback, globalStart, 0);\n // From the mix's start, whichever clip asks first: a bus's chain is shared,\n // so its schedule cannot begin at one clip's start. Context time 0 is\n // `-globalOffset` in this request's seconds, which are its stops' too.\n level.output.connect(buses.inputFor(req.bus, 0, -globalOffset));\n\n // start()'s 3rd arg is a source-buffer duration: under a speed ramp the\n // buffer consumed over a span of clip time is the integral of the rate,\n // not a multiple of it.\n const consumed = sourceOffsetOf(playback, playDuration);\n\n source.start(globalStart, req.trimStart, consumed);\n for (const osc of graph.oscillators) osc.start(globalStart);\n }\n\n return mixCtx.startRendering();\n}\n\n/**\n * Adapter presenting {@link mixAudio} as the exporter's injected mixer seam.\n *\n * The sample rate is a constructor argument rather than a third `mix` parameter\n * because {@link AudioMixer} — the seam `renderTimeline` calls through — takes\n * exactly two, so anything passed as a third would be silently dropped. Fixing\n * it here rather than widening the interface keeps the rate a property of *this*\n * mixer, which is whose business it is.\n */\nexport class WebAudioMixer implements AudioMixer<AudioBuffer> {\n constructor(\n private readonly sampleRate: number = DEFAULT_SAMPLE_RATE,\n private readonly catalog?: AssetCatalog,\n ) { }\n\n mix(\n requests: readonly ScheduledAudioRequest[],\n totalDuration: number,\n ): Promise<AudioBuffer | null> {\n return mixAudio(requests, totalDuration, {\n sampleRate: this.sampleRate,\n catalog: this.catalog,\n });\n }\n}\n\n/**\n * Encode an `AudioBuffer` as a 16-bit PCM WAV.\n *\n * The only other encoder in this package is the AAC track inside the mp4 muxer,\n * which is reachable solely by exporting a video — so without this a mixdown has\n * no file representation at all. WAV because it needs no codec support and is\n * lossless; a host wanting mp3/aac can re-encode from here.\n */\nexport function encodeWav(buffer: AudioBuffer): Uint8Array<ArrayBuffer> {\n const channelCount = buffer.numberOfChannels;\n const frameCount = buffer.length;\n const bytesPerSample = 2;\n const blockAlign = channelCount * bytesPerSample;\n const dataBytes = frameCount * blockAlign;\n\n const out = new ArrayBuffer(44 + dataBytes);\n const view = new DataView(out);\n\n const ascii = (offset: number, text: string) => {\n for (let i = 0; i < text.length; i++) view.setUint8(offset + i, text.charCodeAt(i));\n };\n\n ascii(0, \"RIFF\");\n view.setUint32(4, 36 + dataBytes, true);\n ascii(8, \"WAVE\");\n ascii(12, \"fmt \");\n view.setUint32(16, 16, true); // PCM header length\n view.setUint16(20, 1, true); // format: PCM\n view.setUint16(22, channelCount, true);\n view.setUint32(24, buffer.sampleRate, true);\n view.setUint32(28, buffer.sampleRate * blockAlign, true);\n view.setUint16(32, blockAlign, true);\n view.setUint16(34, 8 * bytesPerSample, true);\n ascii(36, \"data\");\n view.setUint32(40, dataBytes, true);\n\n // Pull each channel out once — getChannelData is a live view, but calling it\n // per sample inside the interleave loop is measurably slower.\n const channels: Float32Array[] = [];\n for (let c = 0; c < channelCount; c++) channels.push(buffer.getChannelData(c));\n\n let offset = 44;\n for (let frame = 0; frame < frameCount; frame++) {\n for (let c = 0; c < channelCount; c++) {\n // Clamp before scaling: the mix bus can exceed [-1,1] where clips\n // overlap, and letting that wrap turns a loud passage into noise.\n const sample = Math.max(-1, Math.min(1, channels[c][frame]));\n view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);\n offset += bytesPerSample;\n }\n }\n\n return new Uint8Array(out);\n}\n", "import { AudioSink, AudioRequest } from \"@motionscript/core\";\nimport { AudioBusGraph } from \"./bus-graph\";\nimport { applyLoop, wrapIntoRegion } from \"./loop-region\";\nimport { applySpeedToPlaybackRate, buildAudioEffectGraph, buildLevel, playbackOf, sourceOffsetOf } from \"./effect-graph\";\n\ntype ActiveSource = {\n source: AudioBufferSourceNode;\n request: AudioRequest;\n /** Effect and level nodes to disconnect on teardown. */\n nodes: AudioNode[];\n /** Tremolo LFOs to stop on teardown. */\n oscillators: OscillatorNode[];\n};\n\n/**\n * Web Audio implementation of {@link AudioSink} — decodes and caches source\n * buffers, then schedules/plays {@link AudioRequest}s as `AudioBufferSourceNode`s\n * through a shared master gain (global mute and volume). `schedule` registers the\n * active set of requests for the current frame; `syncTo` then starts/stops\n * sources to match `clipTime`, so playback follows scrubbing and seeks.\n */\nexport class WebAudioSink extends AudioSink {\n private readonly borrowed: AudioContext | undefined;\n private _context: AudioContext | null = null;\n private bufferCache = new Map<string, AudioBuffer>();\n private decoding = new Map<string, Promise<void>>();\n private active = new Map<string, ActiveSource>();\n private scheduled: AudioRequest[] = [];\n private disposed: boolean = false;\n /** The master gain and the live bus chains (shared across every clip that names one), built with the context. */\n private _graph: { master: GainNode; buses: AudioBusGraph } | null = null;\n private muted = false;\n private volume = 1;\n\n constructor(context?: AudioContext) {\n super();\n this.borrowed = context;\n }\n\n /**\n * The context, created on first use rather than with the sink: a new\n * AudioContext opens the audio device (50–65 ms on a desktop), and a\n * session that never plays or decodes sound never needs one.\n */\n getContext(): AudioContext {\n this._context ??= this.borrowed ?? new AudioContext();\n return this._context;\n }\n\n private get context(): AudioContext {\n return this.getContext();\n }\n\n private get graph(): { master: GainNode; buses: AudioBusGraph } {\n if (!this._graph) {\n const master = this.context.createGain();\n master.connect(this.context.destination);\n this._graph = { master, buses: new AudioBusGraph(this.context, master) };\n this.applyMasterGain();\n }\n return this._graph;\n }\n\n /**\n * Resume the AudioContext. Must be called from within a user gesture\n * (e.g. a click handler) the first time, or browsers keep the context\n * suspended and no audio is heard.\n */\n unlock(): void {\n if (this.context.state === \"suspended\") {\n this.context.resume();\n }\n }\n\n has(src: string): boolean {\n return this.bufferCache.has(src);\n }\n\n async append(src: string, data: ArrayBuffer): Promise<void> {\n if (this.bufferCache.has(src)) return;\n const existing = this.decoding.get(src);\n if (existing) return existing;\n\n // decodeAudioData detaches `data` — that's fine, the caller in\n // AssetManager.fetchAudio discards its reference immediately after\n // awaiting append. Skipping the defensive .slice(0) saves a multi-MB\n // allocation per audio source.\n const job = this.context.decodeAudioData(data).then((buffer) => {\n this.bufferCache.set(src, buffer);\n }).finally(() => {\n this.decoding.delete(src);\n });\n this.decoding.set(src, job);\n await job;\n }\n\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). */\n retain(keep: ReadonlySet<string>): void {\n for (const src of [...this.bufferCache.keys()]) {\n if (!keep.has(src)) this.bufferCache.delete(src);\n }\n for (const [id, active] of this.active) {\n if (!keep.has(active.request.src)) this.stopSource(id, active);\n }\n }\n\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`. */\n schedule(requests: readonly AudioRequest[]): void {\n const next = new Set(requests.map(r => r.id));\n for (const [id, active] of this.active) {\n if (!next.has(id)) this.stopSource(id, active);\n }\n this.scheduled = requests.slice();\n }\n\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. */\n syncTo(clipTime: number): void {\n const liveIds = new Set<string>();\n\n for (const req of this.scheduled) {\n // `endAt` is `Infinity` for an open clip, so the comparison needs no\n // nullish fallback — see AudioRequest.endAt.\n const isInWindow = clipTime >= req.startAt && clipTime < req.endAt;\n if (!isInWindow) continue;\n\n liveIds.add(req.id);\n if (!this.active.has(req.id)) {\n const buffer = this.bufferCache.get(req.src);\n if (buffer) this.playBuffer(buffer, req, clipTime);\n }\n }\n\n for (const [id, active] of this.active) {\n if (!liveIds.has(id)) this.stopSource(id, active);\n }\n }\n\n async play(time: number, _speed: number, _reverse: boolean): Promise<void> {\n if (this.context.state === \"suspended\") {\n await this.context.resume();\n }\n this.syncTo(time);\n }\n\n stop(): void {\n for (const [id, active] of this.active) {\n this.stopSource(id, active);\n }\n // A bus's curves are scheduled against the clock of the run that built\n // it, so the next play, from wherever it lands, builds them again.\n this._graph?.buses.dispose();\n }\n\n setMuted(muted: boolean): void {\n this.muted = muted;\n this.applyMasterGain();\n }\n\n setVolume(volume: number): void {\n this.volume = Math.max(0, volume);\n this.applyMasterGain();\n }\n\n /** Mute and volume are held separately so unmuting restores the set level. */\n private applyMasterGain(): void {\n if (this._graph) this._graph.master.gain.value = this.muted ? 0 : this.volume;\n }\n\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. */\n private playBuffer(buffer: AudioBuffer, req: AudioRequest, clipTime: number): void {\n const startTime = this.context.currentTime;\n const playback = playbackOf(req, buffer.duration);\n const elapsed = Math.max(0, clipTime - req.startAt);\n\n const source = this.context.createBufferSource();\n source.buffer = buffer;\n const loopRegion = applyLoop(source, req);\n if (playback.rate !== 1) source.playbackRate.value = playback.rate;\n applySpeedToPlaybackRate(\n source.playbackRate, playback.speedRamp, playback.sourceLength, playback.clipDuration, startTime, elapsed,\n );\n\n const graph = buildAudioEffectGraph(\n this.context, source, req.effects ?? [], startTime, playback.clipDuration, elapsed,\n );\n const level = buildLevel(this.context, graph.output, req, playback, startTime, elapsed);\n // Into this clip's bus chain, or straight to the master when it has none.\n // The chain is shared: two clips on one bus reach the same nodes, which is\n // what makes a bus effect one tail rather than one per clip.\n level.output.connect(this.graph.buses.inputFor(req.bus, startTime, clipTime));\n\n const audioOffset = req.trimStart + sourceOffsetOf(playback, elapsed);\n source.start(startTime, wrapIntoRegion(loopRegion, audioOffset));\n for (const osc of graph.oscillators) osc.start(startTime);\n\n source.onended = () => {\n if (this.active.get(req.id)?.source === source) {\n this.active.delete(req.id);\n }\n };\n\n this.active.set(req.id, {\n source,\n request: req,\n nodes: [...graph.nodes, ...level.nodes],\n oscillators: graph.oscillators,\n });\n }\n\n private stopSource(id: string, active: ActiveSource): void {\n try {\n active.source.onended = null;\n active.source.stop();\n for (const osc of active.oscillators) osc.stop();\n active.source.disconnect();\n for (const node of active.nodes) node.disconnect();\n } catch {\n // already stopped\n }\n this.active.delete(id);\n }\n\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n super.dispose();\n this.bufferCache.clear();\n this.decoding.clear();\n this.scheduled.length = 0;\n this._graph?.buses.dispose();\n try {\n this._graph?.master.disconnect();\n } catch {\n // already disconnected\n }\n const owned = this.borrowed ? null : this._context;\n if (owned && owned.state !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2B,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
|
-
}
|