@motionscript/browser 0.1.0-alpha.7 → 0.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -48
  4. package/README.md +141 -118
  5. package/dist/asset-bytes.d.ts +7 -4
  6. package/dist/asset-bytes.d.ts.map +1 -1
  7. package/dist/asset-bytes.js +9 -4
  8. package/dist/asset-bytes.js.map +1 -1
  9. package/dist/audio/bus-graph.d.ts.map +1 -1
  10. package/dist/audio/bus-graph.js +15 -6
  11. package/dist/audio/bus-graph.js.map +1 -1
  12. package/dist/audio/effect-graph.d.ts +62 -0
  13. package/dist/audio/effect-graph.d.ts.map +1 -0
  14. package/dist/audio/effect-graph.js +234 -0
  15. package/dist/audio/effect-graph.js.map +1 -0
  16. package/dist/audio/index.d.ts.map +1 -1
  17. package/dist/audio/index.js +2 -3
  18. package/dist/audio/index.js.map +1 -1
  19. package/dist/audio/loop-region.js.map +1 -1
  20. package/dist/audio/mixer.d.ts +4 -4
  21. package/dist/audio/mixer.d.ts.map +1 -1
  22. package/dist/audio/mixer.js +18 -38
  23. package/dist/audio/mixer.js.map +1 -1
  24. package/dist/audio/player.d.ts +12 -6
  25. package/dist/audio/player.d.ts.map +1 -1
  26. package/dist/audio/player.js +49 -62
  27. package/dist/audio/player.js.map +1 -1
  28. package/dist/browser/THIRD_PARTY_LICENSES.txt +379 -27
  29. package/dist/browser/audio.js +1 -1
  30. package/dist/browser/chunks/chunk-F3AZKPHU.js +2 -0
  31. package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
  32. package/dist/browser/chunks/chunk-KLXMRKTL.js +2 -0
  33. package/dist/browser/chunks/chunk-L5UFQACH.js +163 -0
  34. package/dist/browser/chunks/chunk-L5UFQACH.js.map +7 -0
  35. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js +14 -0
  36. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js.map +7 -0
  37. package/dist/browser/index.js +51 -1343
  38. package/dist/browser/index.js.map +4 -4
  39. package/dist/browser/manifest.json +8 -8
  40. package/dist/browser/ms_renderer_bg.wasm +0 -0
  41. package/dist/concat.d.ts +33 -7
  42. package/dist/concat.d.ts.map +1 -1
  43. package/dist/concat.js +117 -72
  44. package/dist/concat.js.map +1 -1
  45. package/dist/deliver.d.ts +10 -0
  46. package/dist/deliver.d.ts.map +1 -0
  47. package/dist/deliver.js +22 -0
  48. package/dist/deliver.js.map +1 -0
  49. package/dist/dynamic-nodes.d.ts.map +1 -1
  50. package/dist/dynamic-nodes.js +2 -3
  51. package/dist/dynamic-nodes.js.map +1 -1
  52. package/dist/engine.d.ts +37 -9
  53. package/dist/engine.d.ts.map +1 -1
  54. package/dist/engine.js +41 -32
  55. package/dist/engine.js.map +1 -1
  56. package/dist/export-audio.d.ts +36 -0
  57. package/dist/export-audio.d.ts.map +1 -0
  58. package/dist/export-audio.js +56 -0
  59. package/dist/export-audio.js.map +1 -0
  60. package/dist/exporter.d.ts +125 -14
  61. package/dist/exporter.d.ts.map +1 -1
  62. package/dist/exporter.js +133 -89
  63. package/dist/exporter.js.map +1 -1
  64. package/dist/formats.d.ts +36 -0
  65. package/dist/formats.d.ts.map +1 -0
  66. package/dist/formats.js +83 -0
  67. package/dist/formats.js.map +1 -0
  68. package/dist/frame-loop.d.ts +190 -0
  69. package/dist/frame-loop.d.ts.map +1 -0
  70. package/dist/frame-loop.js +304 -0
  71. package/dist/frame-loop.js.map +1 -0
  72. package/dist/index.d.ts +12 -11
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +17 -21
  75. package/dist/index.js.map +1 -1
  76. package/dist/mix-timeline-audio.d.ts +5 -5
  77. package/dist/mix-timeline-audio.d.ts.map +1 -1
  78. package/dist/mix-timeline-audio.js +10 -12
  79. package/dist/mix-timeline-audio.js.map +1 -1
  80. package/dist/parallel/export-parallel.d.ts +32 -0
  81. package/dist/parallel/export-parallel.d.ts.map +1 -0
  82. package/dist/parallel/export-parallel.js +114 -0
  83. package/dist/parallel/export-parallel.js.map +1 -0
  84. package/dist/parallel/governor.d.ts +57 -0
  85. package/dist/parallel/governor.d.ts.map +1 -0
  86. package/dist/parallel/governor.js +79 -0
  87. package/dist/parallel/governor.js.map +1 -0
  88. package/dist/parallel/lane.d.ts +45 -0
  89. package/dist/parallel/lane.d.ts.map +1 -0
  90. package/dist/parallel/lane.js +2 -0
  91. package/dist/parallel/lane.js.map +1 -0
  92. package/dist/parallel/lanes.d.ts +20 -0
  93. package/dist/parallel/lanes.d.ts.map +1 -0
  94. package/dist/parallel/lanes.js +152 -0
  95. package/dist/parallel/lanes.js.map +1 -0
  96. package/dist/parallel/plan.d.ts +23 -0
  97. package/dist/parallel/plan.d.ts.map +1 -0
  98. package/dist/parallel/plan.js +30 -0
  99. package/dist/parallel/plan.js.map +1 -0
  100. package/dist/parallel/run-lanes.d.ts +38 -0
  101. package/dist/parallel/run-lanes.d.ts.map +1 -0
  102. package/dist/parallel/run-lanes.js +164 -0
  103. package/dist/parallel/run-lanes.js.map +1 -0
  104. package/dist/parallel/session.d.ts +9 -0
  105. package/dist/parallel/session.d.ts.map +1 -0
  106. package/dist/parallel/session.js +79 -0
  107. package/dist/parallel/session.js.map +1 -0
  108. package/dist/renderer.d.ts +22 -0
  109. package/dist/renderer.d.ts.map +1 -0
  110. package/dist/renderer.js +23 -0
  111. package/dist/renderer.js.map +1 -0
  112. package/dist/screenshot.d.ts +4 -4
  113. package/dist/screenshot.d.ts.map +1 -1
  114. package/dist/screenshot.js +3 -3
  115. package/dist/screenshot.js.map +1 -1
  116. package/dist/still.d.ts +17 -19
  117. package/dist/still.d.ts.map +1 -1
  118. package/dist/still.js +27 -34
  119. package/dist/still.js.map +1 -1
  120. package/dist/ticker.d.ts +22 -8
  121. package/dist/ticker.d.ts.map +1 -1
  122. package/dist/ticker.js +55 -20
  123. package/dist/ticker.js.map +1 -1
  124. package/package.json +9 -10
  125. package/dist/audio/filter-graph.d.ts +0 -59
  126. package/dist/audio/filter-graph.d.ts.map +0 -1
  127. package/dist/audio/filter-graph.js +0 -241
  128. package/dist/audio/filter-graph.js.map +0 -1
  129. package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js +0 -2
  130. package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js.map +0 -7
  131. package/dist/browser/chunks/SkeletonUtils-XYDMTGTM.js +0 -2
  132. package/dist/browser/chunks/chunk-2MAFJWBZ.js +0 -2
  133. package/dist/browser/chunks/chunk-2MAFJWBZ.js.map +0 -7
  134. package/dist/browser/chunks/chunk-CTLBXZSU.js +0 -4119
  135. package/dist/browser/chunks/chunk-CTLBXZSU.js.map +0 -7
  136. package/dist/browser/chunks/chunk-FQ32PDIU.js +0 -2
  137. package/dist/browser/chunks/chunk-FQ32PDIU.js.map +0 -7
  138. package/dist/browser/chunks/chunk-FY3BTKY4.js +0 -2
  139. package/dist/browser/chunks/chunk-FY3BTKY4.js.map +0 -7
  140. package/dist/browser/chunks/three.module-Z4EOVUWF.js +0 -2
  141. package/dist/browser/chunks/three.module-Z4EOVUWF.js.map +0 -7
  142. package/dist/decode/image-levels.d.ts +0 -137
  143. package/dist/decode/image-levels.d.ts.map +0 -1
  144. package/dist/decode/image-levels.js +0 -477
  145. package/dist/decode/image-levels.js.map +0 -1
  146. package/dist/decode/levels.d.ts +0 -37
  147. package/dist/decode/levels.d.ts.map +0 -1
  148. package/dist/decode/levels.js +0 -68
  149. package/dist/decode/levels.js.map +0 -1
  150. package/dist/decode/video-levels.d.ts +0 -37
  151. package/dist/decode/video-levels.d.ts.map +0 -1
  152. package/dist/decode/video-levels.js +0 -95
  153. package/dist/decode/video-levels.js.map +0 -1
  154. package/dist/getter.d.ts +0 -10
  155. package/dist/getter.d.ts.map +0 -1
  156. package/dist/getter.js +0 -38
  157. package/dist/getter.js.map +0 -1
  158. package/dist/measure-context.d.ts +0 -12
  159. package/dist/measure-context.d.ts.map +0 -1
  160. package/dist/measure-context.js +0 -12
  161. package/dist/measure-context.js.map +0 -1
  162. package/dist/render-context.d.ts +0 -32
  163. package/dist/render-context.d.ts.map +0 -1
  164. package/dist/render-context.js +0 -59
  165. package/dist/render-context.js.map +0 -1
  166. package/dist/storage-adapter.d.ts +0 -367
  167. package/dist/storage-adapter.d.ts.map +0 -1
  168. package/dist/storage-adapter.js +0 -1280
  169. package/dist/storage-adapter.js.map +0 -1
  170. package/dist/three/renderer.d.ts +0 -47
  171. package/dist/three/renderer.d.ts.map +0 -1
  172. package/dist/three/renderer.js +0 -182
  173. package/dist/three/renderer.js.map +0 -1
  174. /package/dist/browser/chunks/{SkeletonUtils-XYDMTGTM.js.map → chunk-KLXMRKTL.js.map} +0 -0
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/asset-bytes.ts", "../../../src/audio/bus-graph.ts", "../../../src/audio/filter-graph.ts", "../../../src/audio/mixer.ts", "../../../src/audio/loop-region.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 *\r\n * ## Why the web adapter needs this at all\r\n *\r\n * `WebStorageAdapter` 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 * `WebStorageAdapter` is constructed at five sites *inside* these packages —\r\n * the React player backend, the exporter, the audio mixer, and both still\r\n * renderers — none of 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", "import { busStopKey, type AudioBusStop, type AudioFilterItem } from \"@motionscript/core\";\r\nimport { buildAudioFilterGraph } from \"./filter-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 filters 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 filters, as a sound's own level is, so a\r\n // curve on it is scheduled exactly as one in `filters` is.\r\n const level: AudioFilterItem = { type: \"gain\", value: stop.mute ? 0 : stop.volume };\r\n const graph = buildAudioFilterGraph(\r\n this.ctx, input, [...(stop.filters ?? []), level],\r\n startTime, stop.endAt - stop.startAt, clipTime - stop.startAt,\r\n );\r\n graph.output.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 { 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", "import { sourceTimeAtClipElapsed, type AssetCatalog } from \"@motionscript/core\";\r\nimport type { AudioMixer, ScheduledAudioRequest } from \"@motionscript/skia-render/export\";\r\nimport { fetchAssetBytes, localAssetBytes } from \"../asset-bytes\";\r\nimport { AudioBusGraph } from \"./bus-graph\";\r\nimport { applyLoop } from \"./loop-region\";\r\nimport {\r\n applySpeedToPlaybackRate,\r\n buildAudioFilterGraph,\r\n effectiveSpeed,\r\n speedCurveOf,\r\n} from \"./filter-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, the same job\r\n * `WebStorageAdapter.assetUrl` 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 const scalarSpeed = effectiveSpeed(req.filters);\r\n const rate = Number.isFinite(scalarSpeed) && scalarSpeed > 0 ? scalarSpeed : 1;\r\n const speedCurve = speedCurveOf(req.filters);\r\n // With a curve the scalar is folded into the scheduled ramp below, so\r\n // setting it here as well would apply it twice.\r\n if (rate !== 1 && !speedCurve) source.playbackRate.value = rate;\r\n\r\n const gain = mixCtx.createGain();\r\n gain.gain.value = Number.isFinite(req.volume) ? req.volume : 1;\r\n\r\n // The trimmed source length the filter and speed curves are authored over.\r\n const sourceLength = Math.max(0, srcBuffer.duration - req.trimStart);\r\n // The clip's own clip-time length — what a curve resolves against.\r\n // Deliberately *not* `playDuration`, which is that length truncated by the\r\n // timeline end: resolving against the truncated value would squeeze the\r\n // whole curve into the surviving part instead of cutting it off.\r\n const clipDuration = Number.isFinite(req.endAt)\r\n ? Math.max(0, req.endAt - req.startAt)\r\n : sourceLength / rate;\r\n\r\n // Filter chain sits between the source and the per-request gain, matching\r\n // the live WebAudioSink graph so exports sound identical to preview.\r\n // Passing the start time and clip duration is what lets curve-valued params\r\n // schedule — with the defaults they collapse to a single static value.\r\n // `elapsed` is 0: unlike a live seek, the mix always starts a clip at its\r\n // own beginning.\r\n const graph = buildAudioFilterGraph(\r\n mixCtx, source, req.filters ?? [], globalStart, clipDuration, 0,\r\n );\r\n graph.output.connect(gain);\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 gain.connect(buses.inputFor(req.bus, 0, -globalOffset));\r\n\r\n if (speedCurve) {\r\n applySpeedToPlaybackRate(\r\n source.playbackRate, speedCurve, sourceLength, clipDuration, rate, globalStart, 0,\r\n );\r\n }\r\n\r\n // start()'s 3rd arg is a source-buffer duration. A constant rate scales it\r\n // linearly, but under a speed curve the buffer consumed over a span of\r\n // clip time is the integral of the rate, not a multiple of it.\r\n const consumed = speedCurve\r\n ? sourceTimeAtClipElapsed(speedCurve, sourceLength, playDuration)\r\n : playDuration * rate;\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 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 { AudioSink, AudioRequest, sourceTimeAtClipElapsed } from \"@motionscript/core\";\r\nimport { AudioBusGraph } from \"./bus-graph\";\r\nimport { applyLoop, wrapIntoRegion } from \"./loop-region\";\r\nimport { buildAudioFilterGraph, effectiveSpeed, speedCurveOf, applySpeedToPlaybackRate } from \"./filter-graph\";\r\n\r\ntype ActiveSource = {\r\n source: AudioBufferSourceNode;\r\n gainNode: GainNode;\r\n request: AudioRequest;\r\n /** Filter-graph nodes to disconnect on teardown. */\r\n filterNodes: 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 context: AudioContext;\r\n private ownsContext: boolean;\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 private masterGain: GainNode;\r\n /** The live bus chains, shared across every clip that names one. */\r\n private buses: AudioBusGraph;\r\n private muted = false;\r\n private volume = 1;\r\n\r\n constructor(context?: AudioContext) {\r\n super();\r\n this.context = context ?? new AudioContext();\r\n this.ownsContext = !context;\r\n this.masterGain = this.context.createGain();\r\n this.masterGain.connect(this.context.destination);\r\n this.buses = new AudioBusGraph(this.context, this.masterGain);\r\n }\r\n\r\n getContext(): AudioContext {\r\n return this.context;\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.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 this.masterGain.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 — `audioOffset` accounts for the request's trim, the elapsed time since `startAt`, and any speed (playbackRate) change. */\r\n private playBuffer(buffer: AudioBuffer, req: AudioRequest, clipTime: number): void {\r\n const startTime = this.context.currentTime;\r\n const gainNode = this.context.createGain();\r\n // Guard against a missing/NaN volume — a non-finite AudioParam value throws.\r\n gainNode.gain.value = Number.isFinite(req.volume) ? req.volume : 1;\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 gainNode.connect(this.buses.inputFor(req.bus, startTime, clipTime));\r\n\r\n const source = this.context.createBufferSource();\r\n source.buffer = buffer;\r\n const loopRegion = applyLoop(source, req);\r\n\r\n const scalarSpeed = effectiveSpeed(req.filters);\r\n const rate = Number.isFinite(scalarSpeed) && scalarSpeed > 0 ? scalarSpeed : 1;\r\n const speedCurve = speedCurveOf(req.filters);\r\n if (rate !== 1 && !speedCurve) source.playbackRate.value = rate;\r\n\r\n const elapsed = Math.max(0, clipTime - req.startAt);\r\n // Trimmed source length the filter curves / speed curve are authored over.\r\n const sourceLength = Math.max(0, buffer.duration - req.trimStart);\r\n // Clip-time length of the clip. Prefer the bounded [startAt, endAt) span; if\r\n // endAt is unbounded (an open/looping clip reaching the device unresolved),\r\n // fall back to the source length scaled by speed so curve params still resolve\r\n // (a clipDuration of 0 would otherwise silently drop every fade/sweep).\r\n const clipDuration = isFinite(req.endAt)\r\n ? Math.max(0, req.endAt - req.startAt)\r\n : sourceLength / (rate || 1);\r\n\r\n // Insert the filter chain between the source and the per-request gain. Pass\r\n // the start time, clip duration, and elapsed so curve-valued params schedule\r\n // and align to a mid-clip seek.\r\n const graph = buildAudioFilterGraph(\r\n this.context, source, req.filters ?? [], startTime, clipDuration, elapsed,\r\n );\r\n graph.output.connect(gainNode);\r\n\r\n // Source-time offset for a mid-clip seek. Scalar speed scales linearly; a\r\n // speed curve uses the integral inverse to find the true source position.\r\n let audioOffset: number;\r\n if (speedCurve) {\r\n audioOffset = req.trimStart + sourceTimeAtClipElapsed(speedCurve, sourceLength, elapsed);\r\n // Schedule the time-varying playbackRate (folds in any scalar speed too).\r\n applySpeedToPlaybackRate(\r\n source.playbackRate, speedCurve, sourceLength, clipDuration, rate, startTime, elapsed,\r\n );\r\n } else {\r\n audioOffset = req.trimStart + elapsed * rate;\r\n }\r\n\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 gainNode,\r\n request: req,\r\n filterNodes: graph.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.filterNodes) node.disconnect();\r\n active.gainNode.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.buses.dispose();\r\n try {\r\n this.masterGain.disconnect();\r\n } catch {\r\n // already disconnected\r\n }\r\n if (this.ownsContext && this.context.state !== \"closed\") {\r\n this.context.close();\r\n }\r\n }\r\n}\r\n"],
5
- "mappings": "AAmCA,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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O,QAAQZ,CAAQ,EAI7B,IAAIc,EACAP,GACAO,EAAcrB,EAAI,UAAYsB,EAAwBR,EAAYG,EAAcD,CAAO,EAEvFO,EACIf,EAAO,aAAcM,EAAYG,EAAcC,EAAcL,EAAMP,EAAWU,CAAO,GAGzFK,EAAcrB,EAAI,UAAYgB,EAAUH,EAG5CL,EAAO,MAAMF,EAAWkB,EAAef,EAAYY,CAAW,CAAC,EAC/D,QAAWI,KAAON,EAAM,YAAaM,EAAI,MAAMnB,CAAS,EAExDE,EAAO,QAAU,IAAK,CACd,KAAK,OAAO,IAAIR,EAAI,EAAE,GAAG,SAAWQ,GACpC,KAAK,OAAO,OAAOR,EAAI,EAAE,CAEjC,EAEA,KAAK,OAAO,IAAIA,EAAI,GAAI,CACpB,OAAAQ,EACA,SAAAD,EACA,QAASP,EACT,YAAamB,EAAM,MACnB,YAAaA,EAAM,YACtB,CACL,CAEQ,WAAW1B,EAAYC,EAAoB,CAC/C,GAAI,CACAA,EAAO,OAAO,QAAU,KACxBA,EAAO,OAAO,KAAI,EAClB,QAAW+B,KAAO/B,EAAO,YAAa+B,EAAI,KAAI,EAC9C/B,EAAO,OAAO,WAAU,EACxB,QAAWgC,KAAQhC,EAAO,YAAagC,EAAK,WAAU,EACtDhC,EAAO,SAAS,WAAU,CAC9B,MAAQ,CAER,CACA,KAAK,OAAO,OAAOD,CAAE,CACzB,CAEA,SAAO,CACH,GAAI,MAAK,SACT,MAAK,SAAW,GAChB,MAAM,QAAO,EACb,KAAK,YAAY,MAAK,EACtB,KAAK,SAAS,MAAK,EACnB,KAAK,UAAU,OAAS,EACxB,KAAK,MAAM,QAAO,EAClB,GAAI,CACA,KAAK,WAAW,WAAU,CAC9B,MAAQ,CAER,CACI,KAAK,aAAe,KAAK,QAAQ,QAAU,UAC3C,KAAK,QAAQ,MAAK,EAE1B",
6
- "names": ["source", "setAssetByteSource", "next", "localAssetBytes", "src", "fetchAssetBytes", "url", "response", "status", "busStopKey", "isCurve", "sourceTimeAtClipElapsed", "CURVE_SAMPLES_PER_SECOND", "applyParam", "ctx", "audioParam", "param", "startTime", "clipDuration", "elapsed", "clamp", "v", "finite", "c", "base", "resolved", "startValue", "seg", "segStart", "segEnd", "span", "done", "curveStart", "curveDur", "count", "samples", "i", "local", "buildAudioFilterGraph", "source", "filters", "nodes", "oscillators", "cursor", "series", "node", "apply", "p", "filter", "gain", "biquad", "carrier", "lfo", "lfoDepth", "d", "clamp01", "split", "merge", "dry", "m", "maxDelay", "staticOf", "delay", "feedbackGain", "f", "wet", "effectiveSpeed", "speed", "speedCurveOf", "applySpeedToPlaybackRate", "rate", "curve", "sourceLength", "scalar", "step", "seekAt", "seedSrc", "s", "clampedElapsed", "srcT", "value", "ctxTime", "AudioBusGraph", "ctx", "destination", "bus", "startTime", "clipTime", "node", "osc", "index", "stop", "key", "busStopKey", "existing", "output", "input", "level", "graph", "buildAudioFilterGraph", "sourceTimeAtClipElapsed", "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", "scalarSpeed", "effectiveSpeed", "rate", "speedCurve", "speedCurveOf", "gain", "sourceLength", "clipDuration", "graph", "buildAudioFilterGraph", "applySpeedToPlaybackRate", "consumed", "sourceTimeAtClipElapsed", "osc", "WebAudioMixer", "encodeWav", "buffer", "channelCount", "frameCount", "bytesPerSample", "blockAlign", "dataBytes", "out", "view", "ascii", "offset", "text", "i", "channels", "c", "frame", "sample", "AudioSink", "sourceTimeAtClipElapsed", "WebAudioSink", "AudioSink", "context", "AudioBusGraph", "src", "data", "existing", "job", "buffer", "keep", "id", "active", "requests", "next", "r", "clipTime", "liveIds", "req", "time", "_speed", "_reverse", "muted", "volume", "startTime", "gainNode", "source", "loopRegion", "applyLoop", "scalarSpeed", "effectiveSpeed", "rate", "speedCurve", "speedCurveOf", "elapsed", "sourceLength", "clipDuration", "graph", "buildAudioFilterGraph", "audioOffset", "sourceTimeAtClipElapsed", "applySpeedToPlaybackRate", "wrapIntoRegion", "osc", "node"]
7
- }