@motionscript/browser 0.0.0-stage → 0.1.0-alpha.10

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 (133) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +140 -3
  5. package/dist/asset-bytes.d.ts +59 -0
  6. package/dist/asset-bytes.d.ts.map +1 -0
  7. package/dist/asset-bytes.js +78 -0
  8. package/dist/asset-bytes.js.map +1 -0
  9. package/dist/audio/bus-graph.d.ts +52 -0
  10. package/dist/audio/bus-graph.d.ts.map +1 -0
  11. package/dist/audio/bus-graph.js +108 -0
  12. package/dist/audio/bus-graph.js.map +1 -0
  13. package/dist/audio/effect-graph.d.ts +62 -0
  14. package/dist/audio/effect-graph.d.ts.map +1 -0
  15. package/dist/audio/effect-graph.js +234 -0
  16. package/dist/audio/effect-graph.js.map +1 -0
  17. package/dist/audio/index.d.ts +5 -0
  18. package/dist/audio/index.d.ts.map +1 -0
  19. package/dist/audio/index.js +11 -0
  20. package/dist/audio/index.js.map +1 -0
  21. package/dist/audio/loop-region.d.ts +31 -0
  22. package/dist/audio/loop-region.d.ts.map +1 -0
  23. package/dist/audio/loop-region.js +43 -0
  24. package/dist/audio/loop-region.js.map +1 -0
  25. package/dist/audio/mixer.d.ts +59 -0
  26. package/dist/audio/mixer.d.ts.map +1 -0
  27. package/dist/audio/mixer.js +192 -0
  28. package/dist/audio/mixer.js.map +1 -0
  29. package/dist/audio/player.d.ts +55 -0
  30. package/dist/audio/player.d.ts.map +1 -0
  31. package/dist/audio/player.js +217 -0
  32. package/dist/audio/player.js.map +1 -0
  33. package/dist/browser/THIRD_PARTY_LICENSES.txt +784 -0
  34. package/dist/browser/audio.js +2 -0
  35. package/dist/browser/audio.js.map +7 -0
  36. package/dist/browser/chunks/chunk-F3AZKPHU.js +2 -0
  37. package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
  38. package/dist/browser/chunks/chunk-KLXMRKTL.js +2 -0
  39. package/dist/browser/chunks/chunk-KLXMRKTL.js.map +7 -0
  40. package/dist/browser/chunks/chunk-L5UFQACH.js +163 -0
  41. package/dist/browser/chunks/chunk-L5UFQACH.js.map +7 -0
  42. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js +14 -0
  43. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js.map +7 -0
  44. package/dist/browser/esbuild.wasm +0 -0
  45. package/dist/browser/index.js +734 -0
  46. package/dist/browser/index.js.map +7 -0
  47. package/dist/browser/manifest.json +32 -0
  48. package/dist/browser/ms_renderer_bg.wasm +0 -0
  49. package/dist/concat.d.ts +121 -0
  50. package/dist/concat.d.ts.map +1 -0
  51. package/dist/concat.js +219 -0
  52. package/dist/concat.js.map +1 -0
  53. package/dist/deliver.d.ts +10 -0
  54. package/dist/deliver.d.ts.map +1 -0
  55. package/dist/deliver.js +22 -0
  56. package/dist/deliver.js.map +1 -0
  57. package/dist/dynamic-nodes.d.ts +9 -0
  58. package/dist/dynamic-nodes.d.ts.map +1 -0
  59. package/dist/dynamic-nodes.js +53 -0
  60. package/dist/dynamic-nodes.js.map +1 -0
  61. package/dist/engine.d.ts +87 -0
  62. package/dist/engine.d.ts.map +1 -0
  63. package/dist/engine.js +193 -0
  64. package/dist/engine.js.map +1 -0
  65. package/dist/export-audio.d.ts +36 -0
  66. package/dist/export-audio.d.ts.map +1 -0
  67. package/dist/export-audio.js +56 -0
  68. package/dist/export-audio.js.map +1 -0
  69. package/dist/exporter.d.ts +282 -0
  70. package/dist/exporter.d.ts.map +1 -0
  71. package/dist/exporter.js +308 -0
  72. package/dist/exporter.js.map +1 -0
  73. package/dist/formats.d.ts +36 -0
  74. package/dist/formats.d.ts.map +1 -0
  75. package/dist/formats.js +83 -0
  76. package/dist/formats.js.map +1 -0
  77. package/dist/frame-loop.d.ts +190 -0
  78. package/dist/frame-loop.d.ts.map +1 -0
  79. package/dist/frame-loop.js +304 -0
  80. package/dist/frame-loop.js.map +1 -0
  81. package/dist/index.d.ts +24 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +43 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/mix-timeline-audio.d.ts +42 -0
  86. package/dist/mix-timeline-audio.d.ts.map +1 -0
  87. package/dist/mix-timeline-audio.js +60 -0
  88. package/dist/mix-timeline-audio.js.map +1 -0
  89. package/dist/parallel/export-parallel.d.ts +32 -0
  90. package/dist/parallel/export-parallel.d.ts.map +1 -0
  91. package/dist/parallel/export-parallel.js +114 -0
  92. package/dist/parallel/export-parallel.js.map +1 -0
  93. package/dist/parallel/governor.d.ts +57 -0
  94. package/dist/parallel/governor.d.ts.map +1 -0
  95. package/dist/parallel/governor.js +79 -0
  96. package/dist/parallel/governor.js.map +1 -0
  97. package/dist/parallel/lane.d.ts +45 -0
  98. package/dist/parallel/lane.d.ts.map +1 -0
  99. package/dist/parallel/lane.js +2 -0
  100. package/dist/parallel/lane.js.map +1 -0
  101. package/dist/parallel/lanes.d.ts +20 -0
  102. package/dist/parallel/lanes.d.ts.map +1 -0
  103. package/dist/parallel/lanes.js +152 -0
  104. package/dist/parallel/lanes.js.map +1 -0
  105. package/dist/parallel/plan.d.ts +23 -0
  106. package/dist/parallel/plan.d.ts.map +1 -0
  107. package/dist/parallel/plan.js +30 -0
  108. package/dist/parallel/plan.js.map +1 -0
  109. package/dist/parallel/run-lanes.d.ts +38 -0
  110. package/dist/parallel/run-lanes.d.ts.map +1 -0
  111. package/dist/parallel/run-lanes.js +164 -0
  112. package/dist/parallel/run-lanes.js.map +1 -0
  113. package/dist/parallel/session.d.ts +9 -0
  114. package/dist/parallel/session.d.ts.map +1 -0
  115. package/dist/parallel/session.js +79 -0
  116. package/dist/parallel/session.js.map +1 -0
  117. package/dist/renderer.d.ts +22 -0
  118. package/dist/renderer.d.ts.map +1 -0
  119. package/dist/renderer.js +23 -0
  120. package/dist/renderer.js.map +1 -0
  121. package/dist/screenshot.d.ts +45 -0
  122. package/dist/screenshot.d.ts.map +1 -0
  123. package/dist/screenshot.js +31 -0
  124. package/dist/screenshot.js.map +1 -0
  125. package/dist/still.d.ts +159 -0
  126. package/dist/still.d.ts.map +1 -0
  127. package/dist/still.js +222 -0
  128. package/dist/still.js.map +1 -0
  129. package/dist/ticker.d.ts +74 -0
  130. package/dist/ticker.d.ts.map +1 -0
  131. package/dist/ticker.js +215 -0
  132. package/dist/ticker.js.map +1 -0
  133. package/package.json +75 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-graph.js","sourceRoot":"","sources":["../../src/audio/effect-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAChB,MAAM,EACN,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAMlB,MAAM,oBAAoB,CAAC;AAe5B,iGAAiG;AACjG,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;;;GAQG;AACH,SAAS,UAAU,CACf,UAAsB,EACtB,KAAY,EACZ,SAAiB,EACjB,YAAoB,EACpB,OAAe,EACf,QAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEvC,6CAA6C;IAC7C,MAAM,MAAM,GAAG,CAAC,CAAS,EAAU,EAAE;QACjC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IACrD,CAAC,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO;IACX,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;QACt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CAAC;IAEhD,KAAK,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,IAAI,YAAY,GAAG,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;QAC1C,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;QAC/E,IAAI,OAAO,IAAI,YAAY;YAAE,MAAM;IACvC,CAAC;AACL,CAAC","sourcesContent":["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"]}
@@ -0,0 +1,5 @@
1
+ export { mixAudio, encodeWav, WebAudioMixer, DEFAULT_SAMPLE_RATE } from "./mixer";
2
+ export type { MixAudioOptions } from "./mixer";
3
+ export { WebAudioSink, WebAudioSink as WebAudioPlayer } from "./player";
4
+ export { AudioBusGraph } from "./bus-graph";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAClF,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAIxE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,11 @@
1
+ // @motionscript/browser/audio — stacked-audio playback and mixdown, with no
2
+ // renderer attached.
3
+ //
4
+ // A separate entry point from the package barrel on purpose: nothing here draws,
5
+ // so a host building an audio timeline should not load the renderer.
6
+ export { mixAudio, encodeWav, WebAudioMixer, DEFAULT_SAMPLE_RATE } from "./mixer";
7
+ export { WebAudioSink, WebAudioSink as WebAudioPlayer } from "./player";
8
+ // The bus layer both of those share. Exported so a host writing its own device
9
+ // or mixer builds the same chains, rather than a second set that drifts.
10
+ export { AudioBusGraph } from "./bus-graph";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,qBAAqB;AACrB,EAAE;AACF,iFAAiF;AACjF,qEAAqE;AAErE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGlF,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAExE,+EAA+E;AAC/E,yEAAyE;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC","sourcesContent":["// @motionscript/browser/audio — stacked-audio playback and mixdown, with no\n// renderer attached.\n//\n// A separate entry point from the package barrel on purpose: nothing here draws,\n// so a host building an audio timeline should not load the renderer.\n\nexport { mixAudio, encodeWav, WebAudioMixer, DEFAULT_SAMPLE_RATE } from \"./mixer\";\nexport type { MixAudioOptions } from \"./mixer\";\n\nexport { WebAudioSink, WebAudioSink as WebAudioPlayer } from \"./player\";\n\n// The bus layer both of those share. Exported so a host writing its own device\n// or mixer builds the same chains, rather than a second set that drifts.\nexport { AudioBusGraph } from \"./bus-graph\";\n"]}
@@ -0,0 +1,31 @@
1
+ import type { AudioRequest } from "@motionscript/core";
2
+ /** The span of a decoded buffer a looping request repeats, in source seconds. */
3
+ export interface LoopRegion {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ /**
8
+ * The region a looping request repeats: from its in-point to its out-point, or to
9
+ * the end of the buffer when it has none. `null` for a request that does not loop,
10
+ * and for a degenerate region (an out-point at or before the in-point), where the
11
+ * device falls back to wrapping the whole buffer.
12
+ *
13
+ * Shared by the live device and the offline mixer so a preview and an export loop
14
+ * the same samples.
15
+ */
16
+ export declare function loopRegionOf(request: AudioRequest, bufferDuration: number): LoopRegion | null;
17
+ /**
18
+ * Configure `source` to play `request`'s loop: on or off, and over the trimmed
19
+ * region rather than the whole buffer (`loopStart`/`loopEnd` default to the
20
+ * whole buffer, which is how a trim used to be lost).
21
+ */
22
+ export declare function applyLoop(source: AudioBufferSourceNode, request: AudioRequest): LoopRegion | null;
23
+ /**
24
+ * Fold a source offset into a loop region.
25
+ *
26
+ * A seek into the middle of a looping clip lands at `trimStart + elapsed`, which
27
+ * can be many passes past the region's end; the device would not wrap an offset
28
+ * that starts outside the region, so it is wrapped here.
29
+ */
30
+ export declare function wrapIntoRegion(region: LoopRegion | null, offset: number): number;
31
+ //# sourceMappingURL=loop-region.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-region.d.ts","sourceRoot":"","sources":["../../src/audio/loop-region.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAK7F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,qBAAqB,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU,GAAG,IAAI,CAQjG;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGhF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The region a looping request repeats: from its in-point to its out-point, or to
3
+ * the end of the buffer when it has none. `null` for a request that does not loop,
4
+ * and for a degenerate region (an out-point at or before the in-point), where the
5
+ * device falls back to wrapping the whole buffer.
6
+ *
7
+ * Shared by the live device and the offline mixer so a preview and an export loop
8
+ * the same samples.
9
+ */
10
+ export function loopRegionOf(request, bufferDuration) {
11
+ if (!request.loop)
12
+ return null;
13
+ const start = Math.min(Math.max(0, request.trimStart), bufferDuration);
14
+ const end = Math.min(request.trimEnd ?? bufferDuration, bufferDuration);
15
+ return end > start ? { start, end } : null;
16
+ }
17
+ /**
18
+ * Configure `source` to play `request`'s loop: on or off, and over the trimmed
19
+ * region rather than the whole buffer (`loopStart`/`loopEnd` default to the
20
+ * whole buffer, which is how a trim used to be lost).
21
+ */
22
+ export function applyLoop(source, request) {
23
+ source.loop = request.loop;
24
+ const region = source.buffer ? loopRegionOf(request, source.buffer.duration) : null;
25
+ if (region) {
26
+ source.loopStart = region.start;
27
+ source.loopEnd = region.end;
28
+ }
29
+ return region;
30
+ }
31
+ /**
32
+ * Fold a source offset into a loop region.
33
+ *
34
+ * A seek into the middle of a looping clip lands at `trimStart + elapsed`, which
35
+ * can be many passes past the region's end; the device would not wrap an offset
36
+ * that starts outside the region, so it is wrapped here.
37
+ */
38
+ export function wrapIntoRegion(region, offset) {
39
+ if (!region || offset < region.end)
40
+ return offset;
41
+ return region.start + ((offset - region.start) % (region.end - region.start));
42
+ }
43
+ //# sourceMappingURL=loop-region.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-region.js","sourceRoot":"","sources":["../../src/audio/loop-region.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAAqB,EAAE,cAAsB;IACtE,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC;IACvE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,cAAc,EAAE,cAAc,CAAC,CAAC;IACxE,OAAO,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAA6B,EAAE,OAAqB;IAC1E,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpF,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC;QAChC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAyB,EAAE,MAAc;IACpE,IAAI,CAAC,MAAM,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IAClD,OAAO,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["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"]}
@@ -0,0 +1,59 @@
1
+ import type { AssetCatalog } from "@motionscript/core";
2
+ import type { AudioMixer, ScheduledAudioRequest } from "../frame-loop";
3
+ /** Sample rate used when the caller doesn't pick one. */
4
+ export declare const DEFAULT_SAMPLE_RATE = 44100;
5
+ export interface MixAudioOptions {
6
+ /** Defaults to {@link DEFAULT_SAMPLE_RATE}. */
7
+ sampleRate?: number;
8
+ /**
9
+ * Resolves a request's `src` to the address its bytes live at, as the storage
10
+ * adapter does for the live paths. Omitted, a `src` is
11
+ * fetched as written — right only while the host keys its manifest by URL.
12
+ */
13
+ catalog?: AssetCatalog;
14
+ }
15
+ /**
16
+ * Render every scheduled request into one timeline-length buffer.
17
+ *
18
+ * An `OfflineAudioContext` graph — gain per request, looping/trimming, and the
19
+ * same filter chain the live {@link WebAudioSink} builds — rendered in one
20
+ * pass rather than scheduled per frame.
21
+ *
22
+ * Shared by the video exporter and by `mixTimelineAudio`, deliberately: a split
23
+ * export and a whole one have to be the same mix, and two implementations of
24
+ * "stack these clips" would eventually disagree.
25
+ *
26
+ * Curve-valued filter params and `speed` curves schedule here exactly as they do
27
+ * in {@link WebAudioSink.playBuffer}, which is the reference implementation —
28
+ * the two must be read side by side when either changes.
29
+ *
30
+ * One deliberate difference: this schedules at absolute context times, so clip
31
+ * starts are sample-accurate here and quantized to `1/fps` in live playback,
32
+ * which starts sources at `currentTime` on a clock tick.
33
+ */
34
+ export declare function mixAudio(requests: readonly ScheduledAudioRequest[], totalDuration: number, options?: MixAudioOptions): Promise<AudioBuffer | null>;
35
+ /**
36
+ * Adapter presenting {@link mixAudio} as the exporter's injected mixer seam.
37
+ *
38
+ * The sample rate is a constructor argument rather than a third `mix` parameter
39
+ * because {@link AudioMixer} — the seam `renderTimeline` calls through — takes
40
+ * exactly two, so anything passed as a third would be silently dropped. Fixing
41
+ * it here rather than widening the interface keeps the rate a property of *this*
42
+ * mixer, which is whose business it is.
43
+ */
44
+ export declare class WebAudioMixer implements AudioMixer<AudioBuffer> {
45
+ private readonly sampleRate;
46
+ private readonly catalog?;
47
+ constructor(sampleRate?: number, catalog?: AssetCatalog | undefined);
48
+ mix(requests: readonly ScheduledAudioRequest[], totalDuration: number): Promise<AudioBuffer | null>;
49
+ }
50
+ /**
51
+ * Encode an `AudioBuffer` as a 16-bit PCM WAV.
52
+ *
53
+ * The only other encoder in this package is the AAC track inside the mp4 muxer,
54
+ * which is reachable solely by exporting a video — so without this a mixdown has
55
+ * no file representation at all. WAV because it needs no codec support and is
56
+ * lossless; a host wanting mp3/aac can re-encode from here.
57
+ */
58
+ export declare function encodeWav(buffer: AudioBuffer): Uint8Array<ArrayBuffer>;
59
+ //# sourceMappingURL=mixer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixer.d.ts","sourceRoot":"","sources":["../../src/audio/mixer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAMvE,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,MAAM,WAAW,eAAe;IAC5B,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;CAC1B;AA4BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,QAAQ,CAC1B,QAAQ,EAAE,SAAS,qBAAqB,EAAE,EAC1C,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,eAAoB,GAC9B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAsE7B;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,UAAU,CAAC,WAAW,CAAC;IAErD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBADR,UAAU,GAAE,MAA4B,EACxC,OAAO,CAAC,EAAE,YAAY,YAAA;IAG3C,GAAG,CACC,QAAQ,EAAE,SAAS,qBAAqB,EAAE,EAC1C,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAMjC;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,CA6CtE"}
@@ -0,0 +1,192 @@
1
+ import { fetchAssetBytes, localAssetBytes } from "../asset-bytes";
2
+ import { AudioBusGraph } from "./bus-graph";
3
+ import { applyLoop } from "./loop-region";
4
+ import { applySpeedToPlaybackRate, buildAudioEffectGraph, buildLevel, playbackOf, sourceOffsetOf } from "./effect-graph";
5
+ /** Sample rate used when the caller doesn't pick one. */
6
+ export const DEFAULT_SAMPLE_RATE = 44100;
7
+ /** Audio first, then video: a clip's own soundtrack is requested under the video's key. */
8
+ function audioUrl(src, catalog) {
9
+ if (!catalog)
10
+ return src;
11
+ try {
12
+ return catalog.getAudioMeta(src).src || src;
13
+ }
14
+ catch {
15
+ try {
16
+ return catalog.getVideoMeta(src).src || src;
17
+ }
18
+ catch {
19
+ return src;
20
+ }
21
+ }
22
+ }
23
+ /**
24
+ * Reads and decodes an audio source against a scratch `OfflineAudioContext`
25
+ * (decoding requires a context but doesn't render through it). The host's byte
26
+ * source is asked first, as for every other asset read: a mix that went to the
27
+ * network would fail where the preview played, offline or for bytes not yet
28
+ * uploaded.
29
+ */
30
+ async function fetchAudioBuffer(src, ctx) {
31
+ const blob = (await localAssetBytes(src)) ?? (await fetchAssetBytes(src));
32
+ return ctx.decodeAudioData(await blob.arrayBuffer());
33
+ }
34
+ /**
35
+ * Render every scheduled request into one timeline-length buffer.
36
+ *
37
+ * An `OfflineAudioContext` graph — gain per request, looping/trimming, and the
38
+ * same filter chain the live {@link WebAudioSink} builds — rendered in one
39
+ * pass rather than scheduled per frame.
40
+ *
41
+ * Shared by the video exporter and by `mixTimelineAudio`, deliberately: a split
42
+ * export and a whole one have to be the same mix, and two implementations of
43
+ * "stack these clips" would eventually disagree.
44
+ *
45
+ * Curve-valued filter params and `speed` curves schedule here exactly as they do
46
+ * in {@link WebAudioSink.playBuffer}, which is the reference implementation —
47
+ * the two must be read side by side when either changes.
48
+ *
49
+ * One deliberate difference: this schedules at absolute context times, so clip
50
+ * starts are sample-accurate here and quantized to `1/fps` in live playback,
51
+ * which starts sources at `currentTime` on a clock tick.
52
+ */
53
+ export async function mixAudio(requests, totalDuration, options = {}) {
54
+ if (requests.length === 0)
55
+ return null;
56
+ const sampleRate = options.sampleRate ?? DEFAULT_SAMPLE_RATE;
57
+ const frames = Math.ceil(totalDuration * sampleRate);
58
+ if (frames <= 0)
59
+ return null;
60
+ const uniqueSrcs = [...new Set(requests.map(r => r.request.src))];
61
+ const scratchCtx = new OfflineAudioContext(2, frames, sampleRate);
62
+ // A source only a picture's own sound wants may hold no audio at all, which
63
+ // is silence rather than a failed mix — see `AudioRequest.optional`.
64
+ const asked = new Set(requests.filter(r => !r.request.optional).map(r => r.request.src));
65
+ const decoded = new Map();
66
+ await Promise.all(uniqueSrcs.map(async (src) => {
67
+ try {
68
+ decoded.set(src, await fetchAudioBuffer(audioUrl(src, options.catalog), scratchCtx));
69
+ }
70
+ catch (cause) {
71
+ if (asked.has(src))
72
+ throw cause;
73
+ }
74
+ }));
75
+ const mixCtx = new OfflineAudioContext(2, frames, sampleRate);
76
+ // The same shared-chain rule the live device uses, for the same reason: an
77
+ // export that flattened buses into per-clip processing would not match what
78
+ // the preview sounded like.
79
+ const buses = new AudioBusGraph(mixCtx, mixCtx.destination);
80
+ for (const { request: req, globalOffset } of requests) {
81
+ const srcBuffer = decoded.get(req.src);
82
+ if (!srcBuffer)
83
+ continue;
84
+ const globalStart = globalOffset + req.startAt;
85
+ // `endAt` is `Infinity` for an open clip; either way the timeline bounds it.
86
+ const globalEnd = Math.min(globalOffset + req.endAt, totalDuration);
87
+ const playDuration = globalEnd - globalStart;
88
+ if (playDuration <= 0)
89
+ continue;
90
+ const source = mixCtx.createBufferSource();
91
+ source.buffer = srcBuffer;
92
+ applyLoop(source, req);
93
+ // Ramps resolve against the clip's own length, deliberately *not*
94
+ // `playDuration`, which is that length truncated by the timeline end:
95
+ // resolving against the truncated value would squeeze the whole ramp
96
+ // into the surviving part instead of cutting it off. `elapsed` is 0:
97
+ // unlike a live seek, the mix always starts a clip at its beginning.
98
+ const playback = playbackOf(req, srcBuffer.duration);
99
+ if (playback.rate !== 1)
100
+ source.playbackRate.value = playback.rate;
101
+ applySpeedToPlaybackRate(source.playbackRate, playback.speedRamp, playback.sourceLength, playback.clipDuration, globalStart, 0);
102
+ // The same chain as the live WebAudioSink graph, so exports sound like the preview.
103
+ const graph = buildAudioEffectGraph(mixCtx, source, req.effects ?? [], globalStart, playback.clipDuration, 0);
104
+ const level = buildLevel(mixCtx, graph.output, req, playback, globalStart, 0);
105
+ // From the mix's start, whichever clip asks first: a bus's chain is shared,
106
+ // so its schedule cannot begin at one clip's start. Context time 0 is
107
+ // `-globalOffset` in this request's seconds, which are its stops' too.
108
+ level.output.connect(buses.inputFor(req.bus, 0, -globalOffset));
109
+ // start()'s 3rd arg is a source-buffer duration: under a speed ramp the
110
+ // buffer consumed over a span of clip time is the integral of the rate,
111
+ // not a multiple of it.
112
+ const consumed = sourceOffsetOf(playback, playDuration);
113
+ source.start(globalStart, req.trimStart, consumed);
114
+ for (const osc of graph.oscillators)
115
+ osc.start(globalStart);
116
+ }
117
+ return mixCtx.startRendering();
118
+ }
119
+ /**
120
+ * Adapter presenting {@link mixAudio} as the exporter's injected mixer seam.
121
+ *
122
+ * The sample rate is a constructor argument rather than a third `mix` parameter
123
+ * because {@link AudioMixer} — the seam `renderTimeline` calls through — takes
124
+ * exactly two, so anything passed as a third would be silently dropped. Fixing
125
+ * it here rather than widening the interface keeps the rate a property of *this*
126
+ * mixer, which is whose business it is.
127
+ */
128
+ export class WebAudioMixer {
129
+ sampleRate;
130
+ catalog;
131
+ constructor(sampleRate = DEFAULT_SAMPLE_RATE, catalog) {
132
+ this.sampleRate = sampleRate;
133
+ this.catalog = catalog;
134
+ }
135
+ mix(requests, totalDuration) {
136
+ return mixAudio(requests, totalDuration, {
137
+ sampleRate: this.sampleRate,
138
+ catalog: this.catalog,
139
+ });
140
+ }
141
+ }
142
+ /**
143
+ * Encode an `AudioBuffer` as a 16-bit PCM WAV.
144
+ *
145
+ * The only other encoder in this package is the AAC track inside the mp4 muxer,
146
+ * which is reachable solely by exporting a video — so without this a mixdown has
147
+ * no file representation at all. WAV because it needs no codec support and is
148
+ * lossless; a host wanting mp3/aac can re-encode from here.
149
+ */
150
+ export function encodeWav(buffer) {
151
+ const channelCount = buffer.numberOfChannels;
152
+ const frameCount = buffer.length;
153
+ const bytesPerSample = 2;
154
+ const blockAlign = channelCount * bytesPerSample;
155
+ const dataBytes = frameCount * blockAlign;
156
+ const out = new ArrayBuffer(44 + dataBytes);
157
+ const view = new DataView(out);
158
+ const ascii = (offset, text) => {
159
+ for (let i = 0; i < text.length; i++)
160
+ view.setUint8(offset + i, text.charCodeAt(i));
161
+ };
162
+ ascii(0, "RIFF");
163
+ view.setUint32(4, 36 + dataBytes, true);
164
+ ascii(8, "WAVE");
165
+ ascii(12, "fmt ");
166
+ view.setUint32(16, 16, true); // PCM header length
167
+ view.setUint16(20, 1, true); // format: PCM
168
+ view.setUint16(22, channelCount, true);
169
+ view.setUint32(24, buffer.sampleRate, true);
170
+ view.setUint32(28, buffer.sampleRate * blockAlign, true);
171
+ view.setUint16(32, blockAlign, true);
172
+ view.setUint16(34, 8 * bytesPerSample, true);
173
+ ascii(36, "data");
174
+ view.setUint32(40, dataBytes, true);
175
+ // Pull each channel out once — getChannelData is a live view, but calling it
176
+ // per sample inside the interleave loop is measurably slower.
177
+ const channels = [];
178
+ for (let c = 0; c < channelCount; c++)
179
+ channels.push(buffer.getChannelData(c));
180
+ let offset = 44;
181
+ for (let frame = 0; frame < frameCount; frame++) {
182
+ for (let c = 0; c < channelCount; c++) {
183
+ // Clamp before scaling: the mix bus can exceed [-1,1] where clips
184
+ // overlap, and letting that wrap turns a loud passage into noise.
185
+ const sample = Math.max(-1, Math.min(1, channels[c][frame]));
186
+ view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);
187
+ offset += bytesPerSample;
188
+ }
189
+ }
190
+ return new Uint8Array(out);
191
+ }
192
+ //# sourceMappingURL=mixer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixer.js","sourceRoot":"","sources":["../../src/audio/mixer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzH,yDAAyD;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAazC,2FAA2F;AAC3F,SAAS,QAAQ,CAAC,GAAW,EAAE,OAAiC;IAC5D,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG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EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/E,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,kEAAkE;YAClE,kEAAkE;YAClE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5E,MAAM,IAAI,cAAc,CAAC;QAC7B,CAAC;IACL,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["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"]}
@@ -0,0 +1,55 @@
1
+ import { AudioSink, AudioRequest } from "@motionscript/core";
2
+ /**
3
+ * Web Audio implementation of {@link AudioSink} — decodes and caches source
4
+ * buffers, then schedules/plays {@link AudioRequest}s as `AudioBufferSourceNode`s
5
+ * through a shared master gain (global mute and volume). `schedule` registers the
6
+ * active set of requests for the current frame; `syncTo` then starts/stops
7
+ * sources to match `clipTime`, so playback follows scrubbing and seeks.
8
+ */
9
+ export declare class WebAudioSink extends AudioSink {
10
+ private readonly borrowed;
11
+ private _context;
12
+ private bufferCache;
13
+ private decoding;
14
+ private active;
15
+ private scheduled;
16
+ private disposed;
17
+ /** The master gain and the live bus chains (shared across every clip that names one), built with the context. */
18
+ private _graph;
19
+ private muted;
20
+ private volume;
21
+ constructor(context?: AudioContext);
22
+ /**
23
+ * The context, created on first use rather than with the sink: a new
24
+ * AudioContext opens the audio device (50–65 ms on a desktop), and a
25
+ * session that never plays or decodes sound never needs one.
26
+ */
27
+ getContext(): AudioContext;
28
+ private get context();
29
+ private get graph();
30
+ /**
31
+ * Resume the AudioContext. Must be called from within a user gesture
32
+ * (e.g. a click handler) the first time, or browsers keep the context
33
+ * suspended and no audio is heard.
34
+ */
35
+ unlock(): void;
36
+ has(src: string): boolean;
37
+ append(src: string, data: ArrayBuffer): Promise<void>;
38
+ /** 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). */
39
+ retain(keep: ReadonlySet<string>): void;
40
+ /** 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`. */
41
+ schedule(requests: readonly AudioRequest[]): void;
42
+ /** 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. */
43
+ syncTo(clipTime: number): void;
44
+ play(time: number, _speed: number, _reverse: boolean): Promise<void>;
45
+ stop(): void;
46
+ setMuted(muted: boolean): void;
47
+ setVolume(volume: number): void;
48
+ /** Mute and volume are held separately so unmuting restores the set level. */
49
+ private applyMasterGain;
50
+ /** 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. */
51
+ private playBuffer;
52
+ private stopSource;
53
+ dispose(): void;
54
+ }
55
+ //# sourceMappingURL=player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../src/audio/player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAc7D;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;IACpD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,QAAQ,CAAkB;IAClC,i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