@motionscript/audio 0.1.0 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/browser/chunks/chunk-WUH3G22N.js +2 -0
- package/dist/browser/chunks/chunk-WUH3G22N.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/kit.d.ts +1 -9
- package/dist/kit.d.ts.map +1 -1
- package/dist/kit.js +2 -9
- package/dist/kit.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -12
- package/dist/nodes.js.map +1 -1
- package/dist/waveform/envelope.d.ts +27 -98
- package/dist/waveform/envelope.d.ts.map +1 -1
- package/dist/waveform/envelope.js +17 -77
- package/dist/waveform/envelope.js.map +1 -1
- package/dist/waveform/full-waveform.d.ts +32 -61
- package/dist/waveform/full-waveform.d.ts.map +1 -1
- package/dist/waveform/full-waveform.js +25 -66
- package/dist/waveform/full-waveform.js.map +1 -1
- package/dist/waveform/index.d.ts +0 -16
- package/dist/waveform/index.d.ts.map +1 -1
- package/dist/waveform/index.js +0 -14
- package/dist/waveform/index.js.map +1 -1
- package/dist/waveform/live-waveform.d.ts +33 -70
- package/dist/waveform/live-waveform.d.ts.map +1 -1
- package/dist/waveform/live-waveform.js +24 -74
- package/dist/waveform/live-waveform.js.map +1 -1
- package/dist/waveform/shared.d.ts +21 -62
- package/dist/waveform/shared.d.ts.map +1 -1
- package/dist/waveform/shared.js +33 -71
- package/dist/waveform/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/kit.ts +1 -9
- package/src/nodes.ts +0 -12
- package/src/waveform/envelope.ts +28 -100
- package/src/waveform/full-waveform.ts +25 -67
- package/src/waveform/index.ts +0 -16
- package/src/waveform/live-waveform.ts +24 -74
- package/src/waveform/shared.ts +33 -78
- package/dist/browser/chunks/chunk-DD3KHRUL.js +0 -2
- package/dist/browser/chunks/chunk-DD3KHRUL.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @motionscript/audio
|
|
2
2
|
|
|
3
|
+
## 0.1.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e279864: **Breaking:** the component kits drop exports nothing used.
|
|
8
|
+
|
|
9
|
+
- **math:** the hand-mirrored `*Props` interfaces of 24 components (`AngleMarkProps`, `CurlyBraceProps`, `EmphasisMarkProps`, `CurveAreaProps`, `DropLinesProps`, `PlotPointProps`, `RiemannSumProps`, `TangentLineProps`, `VectorArrowProps`, `PointsPlotProps`, `StreamLinesProps`, `TracedPathProps`, `VectorFieldProps`, `NetworkGraphProps`, `SampleSpaceProps`, `NumberLineProps`, `NumberPlaneProps`, `PolarPlaneProps`, `LatexMatrixProps`, `Axes3dProps`, `CurvePlot3dProps`, `PlotPoint3dProps`, `SurfacePlot3dProps`, `VectorArrow3dProps`), `FILL_PAINT`, `STROKE_PAINT`, `OUTLINE_TRIM` and `spaceOf` from `./kit`, and `LatexPathResult.commands`.
|
|
10
|
+
- **charts:** `LineChartProps`, `BarChartProps`, `PieChartProps`, `PieRingProps`, `PieLegendProps`, `ChartBarsProps`, `CategoryAxisProps`, `ChartBorderProps`, `ChartCanvasProps`, `ChartLegendProps`, `VerticalAxisProps`, and from `./kit` `axisTweenTarget`, `resolvePalettePaint`, `legendShows`, `MarkerLabel`, `clampUnit` (use the SDK's `clamp`). `niceStep` and `enterBudget` stay reachable from `@motionscript/sdk/component`.
|
|
11
|
+
- **audio:** `FullWaveformProps`, `LiveWaveformProps`, and `clamp01` from `./kit`.
|
|
12
|
+
- **patterns:** `DotGridPatternProps`, `GridPatternProps`, `LineGridPatternProps`.
|
|
13
|
+
- **code:** `DEFAULT_THEMES`, `splitTokensAt`, `LINE_ALIGN_CELLS`, `EDIT_ALIGN_CELLS`, and `phasesFor` (use `defaultCodePhases`). `ensureHighlighter`, `loadCodeLanguage`, `initSyntaxHighlighter` and `canHighlight` lose their ignored theme argument.
|
|
14
|
+
- **grids:** the `findNode2D` and `frameIn` re-exports (import them from `@motionscript/sdk`), `ArrangementKind`, `PathGridShape`, `RectangularGridProps`, `RadialGridProps`, `PathGridProps`, `SphereGridProps`.
|
|
15
|
+
- **geography:** `GeoBorderProps`.
|
|
16
|
+
|
|
17
|
+
Migration: no stored document is affected; only TypeScript imports change. Code that imported a removed `*Props` interface states the props it passes inline, and code that used a removed helper uses the replacement named beside it above.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [e279864]
|
|
20
|
+
- @motionscript/sdk@0.1.1-alpha.0
|
|
21
|
+
|
|
3
22
|
## 0.1.0
|
|
4
23
|
|
|
5
24
|
## 0.1.0-alpha.10
|
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ gradient or an image, so a voice declares no asset.
|
|
|
71
71
|
`@motionscript/audio` exports the two nodes, `NODES`, the envelope type and
|
|
72
72
|
`EMPTY_ENVELOPE`, and the pure helpers (`sampleEnvelope`, `forSpeaker`, `layOutBars`,
|
|
73
73
|
`paintBars`, `groupByPaint`, `voiceColor`). `@motionscript/audio/kit` (`src/kit.ts`)
|
|
74
|
-
exports the same helpers plus `
|
|
74
|
+
exports the same helpers plus `livePaintKey`. A copy of `full-waveform` or
|
|
75
75
|
`live-waveform` (`registry.json`) takes three files into the project (`envelope.ts`,
|
|
76
76
|
`shared.ts` and the node); the copy's imports stay relative, so none is rewritten to
|
|
77
77
|
the kit specifier.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y={magnitude:new Float32Array(0),duration:0,speaker:null,speakers:0};function A(t,o,n,e){let r=Math.max(0,Math.floor(e)),c=new Array(r);for(let i=0;i<r;i++)c[i]={magnitude:0,speaker:-1};let l=t.magnitude.length;if(r===0||l===0||t.duration<=0)return c;let m=l/t.duration,u=(n-o)/r;for(let i=0;i<r;i++){let f=(o+u*i)*m,x=(o+u*(i+1))*m,p=Math.floor(f),s=Math.max(p,Math.ceil(x)-1),g=0,d=-1;for(let a=p;a<=s;a++){if(a<0||a>=l)continue;let h=t.magnitude[a];h<g||(g=h,d=t.speaker?t.speaker[a]:-1)}c[i]={magnitude:g,speaker:d}}return c}function b(t,o){return o===null?t:t.map(n=>n.speaker===o?n:{magnitude:0,speaker:n.speaker})}import{Graphics2D as w,clamp as k}from"@motionscript/sdk";var O=["center","bottom"],P=["bars","line","blocks"],M=["#6366f1","#14b8a6","#f59e0b","#ec4899","#22c55e","#3b82f6","#f97316","#a855f7"];function E(t){return M[(t%M.length+M.length)%M.length]}function S(t,o){let{width:n,height:e,gap:r,align:c,gain:l,floor:m}=o,u=t.length;if(u===0||n<=0||e<=0)return[];let i=n/u,f=Math.max(1,i*(1-k(r,0,1))),x=c==="center"?e/2:e,p=new Array(u);for(let s=0;s<u;s++){let g=k(t[s].magnitude*l,0,1),d=Math.max(x*k(m,0,1),x*g),a=-n/2+i*s+(i-f)/2,h=Math.max(1,c==="center"?d*2:d);p[s]=c==="center"?{x:a,y:-h/2,width:f,height:h}:{x:a,y:e/2-h,width:f,height:h}}return p}function T(t,o,n){if(t.length===0||o.length===0)return null;let e=new w;for(let r of t)e.rect({x:r.x+r.width/2,y:-(r.y+r.height/2),width:r.width,height:r.height,cornerRadius:Math.min(n,r.width/2,r.height/2)});return e.fill(o)}function L(t,o){let n=new Map;for(let e=0;e<t.length;e++){let r=o(e),c=n.get(r);c?c.push(t[e]):n.set(r,[t[e]])}return n}function _(t,o,n){let e=Number(t.slice(6));return!Number.isFinite(e)||e<0?n:o[e]??E(e)}function v(t,o,n){return n!==null?`voice:${n}`:o?`voice:${t}`:"all"}export{y as a,A as b,b as c,O as d,P as e,M as f,E as g,S as h,T as i,L as j,_ as k,v as l};
|
|
2
|
+
//# sourceMappingURL=chunk-WUH3G22N.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/waveform/envelope.ts", "../../../src/waveform/shared.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The host decodes audio into an {@link AudioEnvelope} once per file, before the\n * build, and hands it to the node; nothing here decodes or listens. It is baked\n * because an export has no audio device or analyser, and the picture must be a\n * pure function of time.\n *\n * In a document an envelope is plain JSON, which `ArrayLike<number>` accepts.\n * A `Float32Array` is not JSON-serialisable (`JSON.stringify` writes an object\n * of indices), so convert with `Array.from` before storing it.\n */\n\n/**\n * A recording reduced to a uniform grid of loudness, plus who is talking in each\n * bucket when the host knows. The speaker track comes from a diarized transcript,\n * not the decoder; it lives here because every reader of it also reads the\n * magnitudes at the same index.\n */\nexport interface AudioEnvelope {\n /** Peak magnitude per bucket, 0 to 1; buckets span {@link duration} evenly. */\n magnitude: ArrayLike<number>\n /** Seconds. */\n duration: number\n /** Voice index per bucket (`-1` for nobody), parallel to {@link magnitude}, or `null` when never diarized. */\n speaker: ArrayLike<number> | null\n /** Zero when the diarizer did not run. */\n speakers: number\n}\n\n/** The envelope of a track that has not loaded or is not there. */\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\n magnitude: new Float32Array(0),\n duration: 0,\n speaker: null,\n speakers: 0,\n}\n\nexport interface EnvelopeBar {\n /** 0 to 1. */\n magnitude: number\n /** Voice index, or -1. */\n speaker: number\n}\n\n/**\n * Resamples `[from, to)` seconds down to `bars` columns, keeping peaks rather\n * than averaging: averaging flattens the transients that make a drawing read as\n * speech. A column's speaker is that of its loudest bucket. A window past either\n * end yields silent, unattributed columns rather than clamping onto the nearest\n * real one, which would smear the first bucket across a live window's run-up.\n */\nexport function sampleEnvelope(\n envelope: AudioEnvelope,\n from: number,\n to: number,\n bars: number\n): EnvelopeBar[] {\n const count = Math.max(0, Math.floor(bars))\n const out: EnvelopeBar[] = new Array(count)\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\n\n const buckets = envelope.magnitude.length\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\n\n const perSecond = buckets / envelope.duration\n const span = (to - from) / count\n\n for (let i = 0; i < count; i++) {\n const start = (from + span * i) * perSecond\n const end = (from + span * (i + 1)) * perSecond\n\n // At least one bucket per column, so a zoomed-in window draws the sample it stands on.\n const first = Math.floor(start)\n const last = Math.max(first, Math.ceil(end) - 1)\n\n let loudest = 0\n let speaker = -1\n for (let b = first; b <= last; b++) {\n if (b < 0 || b >= buckets) continue\n const value = envelope.magnitude[b]\n if (value < loudest) continue\n loudest = value\n speaker = envelope.speaker ? envelope.speaker[b] : -1\n }\n\n out[i] = { magnitude: loudest, speaker }\n }\n\n return out\n}\n\n/**\n * The same window with everything but `voice` silenced, not dropped, so a\n * filtered visualiser goes quiet while the other host talks instead of cutting\n * their turn out. `null` returns the bars untouched.\n */\nexport function forSpeaker(\n bars: EnvelopeBar[],\n voice: number | null\n): EnvelopeBar[] {\n if (voice === null) return bars\n return bars.map((bar) =>\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\n )\n}\n", "import { Graphics2D, clamp, type Fill, type FillResolved } from \"@motionscript/sdk\"\n\nimport type { EnvelopeBar } from \"./envelope\"\n\n/** How a bar is grown out of its baseline. */\nexport const WAVEFORM_ALIGNMENTS = [\"center\", \"bottom\"] as const\nexport type WaveformAlignment = (typeof WAVEFORM_ALIGNMENTS)[number]\n\nexport const WAVEFORM_STYLES = [\"bars\", \"line\", \"blocks\"] as const\nexport type WaveformStyle = (typeof WAVEFORM_STYLES)[number]\n\n/** Eight distinct hues handed out by voice index. Literals, because a scene builds headless with no database in scope; a host that names its voices supplies its own. */\nexport const VOICE_PALETTE = [\n \"#6366f1\",\n \"#14b8a6\",\n \"#f59e0b\",\n \"#ec4899\",\n \"#22c55e\",\n \"#3b82f6\",\n \"#f97316\",\n \"#a855f7\",\n] as const\n\n/** The colour a voice takes, wrapping past the end of the palette. */\nexport function voiceColor(index: number): string {\n return VOICE_PALETTE[\n ((index % VOICE_PALETTE.length) + VOICE_PALETTE.length) %\n VOICE_PALETTE.length\n ]\n}\n\n/** A bar's top-left corner and size in the node's pixels, with y pointing down from the middle of the box; {@link paintBars} turns it into the centred y-up rect. */\nexport interface BarBox {\n x: number\n y: number\n width: number\n height: number\n}\n\n/**\n * Lays a row of bars across a box. The gap is a fraction of the pitch, not px:\n * the bar count is a control, and a px gap would become a solid block at 200\n * bars and a picket fence at 20. A bar is never thinner or shorter than a\n * hairline, so a silent passage reads as audio with nothing in it, not a hole.\n */\nexport function layOutBars(\n bars: readonly EnvelopeBar[],\n options: {\n width: number\n height: number\n gap: number\n align: WaveformAlignment\n gain: number\n /** Fraction of the box a silent bar still occupies. */\n floor: number\n }\n): BarBox[] {\n const { width, height, gap, align, gain, floor } = options\n const count = bars.length\n if (count === 0 || width <= 0 || height <= 0) return []\n\n const pitch = width / count\n const barWidth = Math.max(1, pitch * (1 - clamp(gap, 0, 1)))\n // Centre-aligned bars grow both ways, so half the height is what a magnitude of 1 fills.\n const full = align === \"center\" ? height / 2 : height\n\n const out: BarBox[] = new Array(count)\n for (let i = 0; i < count; i++) {\n const magnitude = clamp(bars[i].magnitude * gain, 0, 1)\n const reach = Math.max(full * clamp(floor, 0, 1), full * magnitude)\n const x = -width / 2 + pitch * i + (pitch - barWidth) / 2\n\n // The hairline minimum is taken before the position, or a 1px bar placed as if zero-height would hang outside the box.\n const h = Math.max(1, align === \"center\" ? reach * 2 : reach)\n out[i] =\n align === \"center\"\n ? { x, y: -h / 2, width: barWidth, height: h }\n : { x, y: height / 2 - h, width: barWidth, height: h }\n }\n return out\n}\n\n/**\n * Draws a run of bars in one paint. Callers batch by colour: every `Graphics2D`\n * handed to `ctx.draw` is a surface the renderer composites, so a bar apiece\n * would be a thousand surfaces a frame. One `Graphics2D` per run also maps a\n * gradient across the whole run instead of restarting inside every bar.\n */\nexport function paintBars(\n boxes: readonly BarBox[],\n fill: Fill,\n radius: number\n): Graphics2D | null {\n if (boxes.length === 0) return null\n if ((fill as FillResolved[]).length === 0) return null\n\n const graphics = new Graphics2D()\n for (const box of boxes) {\n graphics.rect({\n x: box.x + box.width / 2,\n // The box is y-down and the rect y-up; only a bottom-aligned bar shows the flip.\n y: -(box.y + box.height / 2),\n width: box.width,\n height: box.height,\n // A thin bar rounder than it is wide becomes a lozenge.\n cornerRadius: Math.min(radius, box.width / 2, box.height / 2),\n })\n }\n return graphics.fill(fill)\n}\n\n/** Groups bars by the paint they take, in order within each group: a diarized waveform has as many colours as voices, so two people is two draws however long it runs. */\nexport function groupByPaint<K>(\n boxes: readonly BarBox[],\n keyOf: (index: number) => K\n): Map<K, BarBox[]> {\n const groups = new Map<K, BarBox[]>()\n for (let i = 0; i < boxes.length; i++) {\n const key = keyOf(i)\n const run = groups.get(key)\n if (run) run.push(boxes[i])\n else groups.set(key, [boxes[i]])\n }\n return groups\n}\n\n/**\n * The colour of a `voice:N` group key, or `fallback` for a bad index. Always a\n * colour string, never one of the node's fills: a voice is identified by hue, so\n * a gradient or image would defeat the point, and it keeps these paints from\n * declaring assets.\n */\nexport function voiceFill(key: string, voiceColors: readonly string[], fallback: Fill): Fill {\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return fallback\n return voiceColors[voice] ?? voiceColor(voice)\n}\n\n/**\n * The {@link groupByPaint} key of one live bar. Filtered to a voice, every bar\n * takes that voice's key: {@link forSpeaker} zeroes a bar's magnitude but leaves\n * its `speaker`, so the usual per-bar key would paint the silenced stretches in\n * whoever used to talk there, in flickers too short to read as anything but noise.\n */\nexport function livePaintKey(\n barSpeaker: number,\n byVoice: boolean,\n filteredVoice: number | null\n): string {\n if (filteredVoice !== null) return `voice:${filteredVoice}`\n return byVoice ? `voice:${barSpeaker}` : \"all\"\n}\n"],
|
|
5
|
+
"mappings": "AA6BO,IAAMA,EAAgC,CAC3C,UAAW,IAAI,aAAa,CAAC,EAC7B,SAAU,EACV,QAAS,KACT,SAAU,GAiBN,SAAU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,KAAOJ,EAChBG,EAAS,KAAK,CACZ,EAAGC,EAAI,EAAIA,EAAI,MAAQ,EAEvB,EAAG,EAAEA,EAAI,EAAIA,EAAI,OAAS,GAC1B,MAAOA,EAAI,MACX,OAAQA,EAAI,OAEZ,aAAc,KAAK,IAAIF,EAAQE,EAAI,MAAQ,EAAGA,EAAI,OAAS,CAAC,EAC7D,EAEH,OAAOD,EAAS,KAAKF,CAAI,CAC3B,CAGM,SAAUI,EACdL,EACAM,EAA2B,CAE3B,IAAMC,EAAS,IAAI,IACnB,QAASZ,EAAI,EAAGA,EAAIK,EAAM,OAAQL,IAAK,CACrC,IAAMa,EAAMF,EAAMX,CAAC,EACbc,EAAMF,EAAO,IAAIC,CAAG,EACtBC,EAAKA,EAAI,KAAKT,EAAML,CAAC,CAAC,EACrBY,EAAO,IAAIC,EAAK,CAACR,EAAML,CAAC,CAAC,CAAC,CACjC,CACA,OAAOY,CACT,CAQM,SAAUG,EAAUF,EAAaG,EAAgCC,EAAc,CACnF,IAAMC,EAAQ,OAAOL,EAAI,MAAM,CAAe,CAAC,EAC/C,MAAI,CAAC,OAAO,SAASK,CAAK,GAAKA,EAAQ,EAAUD,EAC1CD,EAAYE,CAAK,GAAKlC,EAAWkC,CAAK,CAC/C,CAQM,SAAUC,EACdC,EACAC,EACAC,EAA4B,CAE5B,OAAIA,IAAkB,KAAa,SAASA,CAAa,GAClDD,EAAU,SAASD,CAAU,GAAK,KAC3C",
|
|
6
|
+
"names": ["EMPTY_ENVELOPE", "sampleEnvelope", "envelope", "from", "to", "bars", "count", "out", "buckets", "perSecond", "span", "start", "end", "first", "last", "loudest", "speaker", "b", "value", "forSpeaker", "voice", "bar", "Graphics2D", "clamp", "WAVEFORM_ALIGNMENTS", "WAVEFORM_STYLES", "VOICE_PALETTE", "voiceColor", "index", "layOutBars", "bars", "options", "width", "height", "gap", "align", "gain", "floor", "count", "pitch", "barWidth", "full", "out", "i", "magnitude", "reach", "x", "paintBars", "boxes", "fill", "radius", "graphics", "box", "groupByPaint", "keyOf", "groups", "key", "run", "voiceFill", "voiceColors", "fallback", "voice", "livePaintKey", "barSpeaker", "byVoice", "filteredVoice"]
|
|
7
|
+
}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as p,b as
|
|
1
|
+
import{a as p,b as f,c as w,d as L,e as T,f as N,g as S,h as s,i as c,j as u,k as y,l as k}from"./chunks/chunk-WUH3G22N.js";import{Types as E,clamp as B,component2d as C,easeInOut as _,fillOps as P}from"@motionscript/sdk";var x=o=>E.custom(o,{resolve:P.resolve,lerp:P.lerp}),O=C({key:"fullWaveform",state:{envelope:E.custom(p),bars:120,gap:.3,radius:2,progress:0,follow:!1,gain:1,floor:.015,align:E.custom("center"),byVoice:!1,voiceColors:E.custom([]),fill:x("#5b5b7a"),playedFill:x("#6366f1")},load:(o,e)=>{o.fill(e.fill),o.fill(e.playedFill)},commands:{sweep:(o,e)=>{let r=o.easing?null:_(),n=e.progress;return o.animate(t=>({progress:n+(1-n)*(r?r(t):t)}))}},render:(o,e)=>{A(o,e),o.children()}});function A(o,e){let{width:r,height:n}=o.size;if(r<=0||n<=0)return;let t=Math.max(1,Math.round(e.bars)),l=f(e.envelope,0,e.envelope.duration,t),a=s(l,{width:r,height:n,gap:e.gap,align:e.align,gain:e.gain,floor:e.floor});if(a.length===0)return;let g=Y(o,e)*a.length,d=u(a,i=>e.byVoice?`voice:${l[i].speaker}`:i<g?"played":"ahead");for(let[i,v]of d){let h=c(v,I(e,i),e.radius);h&&o.draw(h)}}function Y(o,e){if(!e.follow)return B(e.progress,0,1);let r=e.envelope.duration;return r<=0?0:B(o.time.elapsed/r,0,1)}function I(o,e){return e==="played"?o.playedFill:e==="ahead"?o.fill:y(e,o.voiceColors,o.fill)}import{Types as m,clamp as z,component2d as D,fillOps as V}from"@motionscript/sdk";var F=D({key:"liveWaveform",state:{envelope:m.custom(p),bars:48,gap:.35,radius:4,window:3,offset:0,playing:!0,gain:1.4,floor:.04,align:m.custom("center"),style:m.custom("bars"),speaker:-1,byVoice:!1,voiceColors:m.custom([]),fill:m.custom("#6366f1",{resolve:V.resolve,lerp:V.lerp})},load:(o,e)=>o.fill(e.fill),render:(o,e)=>{G(o,e),o.children()}});function R(o,e){return e.offset+(e.playing?Math.max(0,o.time.elapsed):0)}function G(o,e){let{width:r,height:n}=o.size;if(r<=0||n<=0)return;let t=Math.max(1,Math.round(e.bars)),l=Math.max(.05,e.window),a=R(o,e),g=e.speaker<0?null:Math.round(e.speaker),d=w(f(e.envelope,a-l/2,a+l/2,t),g),i=e.style==="line"?$(d):d,v=s(i,{width:r,height:n,gap:e.style==="blocks"?.12:e.gap,align:e.align,gain:e.gain,floor:e.floor});if(v.length===0)return;let h=u(v,M=>k(i[M].speaker,e.byVoice,g));for(let[M,W]of h){let b=c(W,K(e,M),e.radius);b&&o.draw(b)}}function K(o,e){return e==="all"?o.fill:y(e,o.voiceColors,o.fill)}function $(o){let e=o.length;if(e<3)return[...o];let r=Math.max(1,Math.floor(e/5));return o.map((n,t)=>{let l=Math.min(t,e-1-t),a=z(l/r,0,1);return{magnitude:n.magnitude*a,speaker:n.speaker}})}var j=[O,F];export{p as EMPTY_ENVELOPE,O as FullWaveform,F as LiveWaveform,j as NODES,N as VOICE_PALETTE,L as WAVEFORM_ALIGNMENTS,T as WAVEFORM_STYLES,w as forSpeaker,u as groupByPaint,s as layOutBars,c as paintBars,f as sampleEnvelope,S as voiceColor};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/waveform/full-waveform.ts", "../../src/waveform/live-waveform.ts", "../../src/nodes.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n Types,\n component2d,\n easeInOut,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * `follow` is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With `byVoice` on, the played/ahead split is replaced by one colour per\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many columns the whole file is drawn as. */\n bars: 120,\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: 0.3,\n /** Corner radius of a bar, capped at half its width. */\n radius: 2,\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead of the prop. */\n follow: false,\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: 1,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n /** …and the bars behind it. */\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`. Eased in-out\n * unless it is given an easing of its own.\n */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** Where the fill has reached, from whichever source is in charge. */\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp01(s.progress)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp01(ctx.time.elapsed / length)\n}\n\n/**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why `load` only has to account\n * for the two real fill props.\n */\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\n}\n", "import {\n Types,\n component2d,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport {\n EMPTY_ENVELOPE,\n forSpeaker,\n sampleEnvelope,\n type AudioEnvelope,\n type EnvelopeBar,\n} from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n type WaveformStyle,\n} from \"./shared\"\n\n/**\n * A **live audio visualiser**: bars that move with the recording as it plays.\n *\n * The thing every podcast-to-video tool puts beside the artwork. It is not a\n * picture of the file — that is {@link FullWaveform} — it is a picture of *this\n * moment*, and what it is for is making a static frame of a talking head feel\n * like it is playing.\n *\n * ## \"Live\" without listening\n *\n * Nothing here reads an audio device. The bars are sampled out of a baked\n * envelope at the node's own elapsed time, which is what makes the visualiser\n * survive the thing it exists for: an **export**, where there is no playback to\n * analyse and frames may be rendered out of order or in parallel. A frame is a\n * pure function of its time, so scrubbing back and forth over the visualiser\n * redraws exactly what it drew the first time — which an analyser node, by\n * construction, cannot promise. See {@link AudioEnvelope}.\n *\n * ## The speaker filter\n *\n * `speaker` narrows the node to one voice of a diarized recording, and it\n * is the reason this node knows about transcripts at all. Two visualisers beside\n * two headshots, each filtered to its own host, is a podcast edit that would\n * otherwise be done by hand for every turn — and because the filter *silences*\n * rather than skips (see {@link forSpeaker}), the quiet host visibly stops\n * talking instead of vanishing. Nothing about that requires the words: only who\n * is talking when, which is what the diarizer produces.\n *\n * A filter naming a voice the recording doesn't have draws a resting row rather\n * than everything — a picture of \"this person never speaks here\", which is\n * true, where falling back to the unfiltered mix would be a silent lie about\n * whose voice you were watching.\n */\nexport const LiveWaveform = component2d({\n key: \"liveWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many bars the visualiser is made of. */\n bars: 48,\n /** Space between bars, as a fraction of the pitch. */\n gap: 0.35,\n radius: 4,\n /** How many seconds of audio are on screen at once. */\n window: 3,\n /** Seconds into the file the node's first frame shows. */\n offset: 0,\n /** Advance with the scene clock. Off freezes the picture at `offset`. */\n playing: true,\n /** Multiplies every magnitude before it is clamped. */\n gain: 1.4,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.04,\n align: Types.custom<WaveformAlignment>(\"center\"),\n style: Types.custom<WaveformStyle>(\"bars\"),\n /**\n * Show only this voice's activity, by index into the recording's own\n * numbering. `-1` — the default — is every voice.\n */\n speaker: -1,\n /** Colour each bar by whoever is speaking in it. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n fill: Types.custom<Fill, FillResolved[]>(\"#6366f1\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n },\n // Nothing declares a component's paints but itself.\n load: (loader, state) => loader.fill(state.fill),\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type LiveWaveform = NodeOf<typeof LiveWaveform>\nexport type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>\n\ninterface LiveState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly window: number\n readonly offset: number\n readonly playing: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly style: WaveformStyle\n readonly speaker: number\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n}\n\n/**\n * The second of the recording the visualiser is showing.\n *\n * Off the node's own clock rather than the scene's, which is what \"from the\n * moment this node appeared\" means — the same clock the engine's own\n * `Video` times its picture from, and the same one that makes a node dropped\n * halfway through a clip start its recording at its entrance rather than\n * partway in.\n */\nfunction at(ctx: RenderContext, s: LiveState): number {\n return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0)\n}\n\nfunction drawBars(ctx: RenderContext, s: LiveState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const span = Math.max(0.05, s.window)\n const now = at(ctx, s)\n const voice = s.speaker < 0 ? null : Math.round(s.speaker)\n\n // The window is centred on the playhead, so the bars run *toward* the\n // middle and away again — the arrangement every mixer's meter uses, and the\n // one that reads as sound arriving rather than as a strip scrolling past.\n const sampled = forSpeaker(\n sampleEnvelope(s.envelope, now - span / 2, now + span / 2, count),\n voice\n )\n\n const shaped = s.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: s.style === \"blocks\" ? 0.12 : s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, s.byVoice, voice)\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** See `FullWaveform`'s paints — a voice is a hue, never a gradient. */\nfunction paintFor(s: LiveState, key: string): Fill {\n if (key === \"all\") return s.fill\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\n}\n\n/**\n * Rolls the ends of a window off toward silence.\n *\n * What separates the `line` style from `bars`: a hard-edged window makes the\n * loud bar entering at the right edge appear from nothing, which reads as a\n * glitch rather than as sound arriving. Fading the outer fifth turns the same\n * data into a shape that grows out of the baseline — the profile a spectrum\n * display has, and the reason it looks like one object rather than a row of\n * separate meters.\n */\nfunction taper(bars: readonly EnvelopeBar[]): EnvelopeBar[] {\n const count = bars.length\n if (count < 3) return [...bars]\n const edge = Math.max(1, Math.floor(count / 5))\n\n return bars.map((bar, i) => {\n const fromEnd = Math.min(i, count - 1 - i)\n const weight = clamp01(fromEnd / edge)\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\n })\n}\n", "import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each component's key.\n * Defining a component only *declares* that key: nothing is registered by\n * importing a module, so a registry holds exactly what its owner asked for.\n *\n * Listing the component **values** is also what survives bundling: this package\n * declares `sideEffects: false`, and a document names a node type by string, so\n * an import kept only for its side effect is exactly what gets shaken out.\n */\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];\n"],
|
|
5
|
-
"mappings": "4HAAA,OACE,SAAAA,EACA,eAAAC,EACA,aAAAC,EACA,WAAAC,MAQK,
|
|
6
|
-
"names": ["Types", "component2d", "easeInOut", "fillOps", "paint", "initial", "Types", "fillOps", "FullWaveform", "component2d", "EMPTY_ENVELOPE", "loader", "state", "timeline", "ease", "easeInOut", "from", "ctx", "drawBars", "s", "width", "height", "count", "sampled", "sampleEnvelope", "boxes", "layOutBars", "edge", "played", "groups", "groupByPaint", "key", "run", "graphics", "paintBars", "paintFor", "
|
|
4
|
+
"sourcesContent": ["import {\n Types,\n clamp,\n component2d,\n easeInOut,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n groupByPaint,\n layOutBars,\n paintBars,\n voiceFill,\n type WaveformAlignment,\n} from \"./shared\"\n\n/** A fill entry whose kind is read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\n\n/**\n * The whole recording's shape drawn at once, with a played portion that\n * advances: a picture of the file where {@link LiveWaveform} is of the moment.\n *\n * `follow` is off by default because a scene cannot see where the recording sits\n * on the video's audio lane (placed, trimmed, sped up); the author sweeps\n * `progress` with a command, and `follow` is the opt-in for a node that appears\n * exactly as the track starts. `byVoice` replaces the played/ahead split with\n * one colour per voice rather than combining with it: a bar cannot mean two\n * things at once.\n */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording; see {@link AudioEnvelope}. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n bars: 120,\n /** Space between bars as a fraction of the pitch; see {@link layOutBars}. */\n gap: 0.3,\n /** Capped at half the bar's width. */\n radius: 2,\n /** The share of the file that reads as played, `0`-`1`. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead. */\n follow: false,\n /** Multiplies every magnitude, pulling a quiet track up to fill its box. */\n gain: 1,\n /** The share of the box a silent bar still occupies, `0`-`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n byVoice: false,\n /** A colour per voice index; short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\n /** Fill the waveform in, left to right; eased in-out unless given an easing. */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour, not per bar (see {@link paintBars}); the key is a string so it is comparable.\n const edge = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp(s.progress, 0, 1)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp(ctx.time.elapsed / length, 0, 1)\n}\n\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n return voiceFill(key, s.voiceColors, s.fill)\n}\n", "import {\n Types,\n clamp,\n component2d,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport {\n EMPTY_ENVELOPE,\n forSpeaker,\n sampleEnvelope,\n type AudioEnvelope,\n type EnvelopeBar,\n} from \"./envelope\"\nimport {\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceFill,\n type WaveformAlignment,\n type WaveformStyle,\n} from \"./shared\"\n\n/**\n * A visualiser whose bars move with the recording: a picture of this moment\n * where {@link FullWaveform} is of the file. The bars are sampled from a baked\n * envelope at the node's own elapsed time, so a frame is a pure function of time\n * and an export, which has no playback to analyse and may render out of order,\n * draws what the preview drew.\n *\n * `speaker` narrows the node to one voice of a diarized recording; it silences\n * the other voices (see {@link forSpeaker}) so the quiet host visibly stops. A\n * voice the recording does not have draws a resting row, not the unfiltered mix,\n * which would be a silent lie about whose voice you are watching.\n */\nexport const LiveWaveform = component2d({\n key: \"liveWaveform\",\n state: {\n /** The baked recording; see {@link AudioEnvelope}. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n bars: 48,\n /** Space between bars as a fraction of the pitch. */\n gap: 0.35,\n radius: 4,\n /** Seconds of audio on screen at once. */\n window: 3,\n /** Seconds into the file the first frame shows. */\n offset: 0,\n /** Advance with the scene clock; off freezes the picture at `offset`. */\n playing: true,\n gain: 1.4,\n /** The share of the box a silent bar still occupies, `0`-`1`. */\n floor: 0.04,\n align: Types.custom<WaveformAlignment>(\"center\"),\n style: Types.custom<WaveformStyle>(\"bars\"),\n /** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */\n speaker: -1,\n /** Colour each bar by whoever is speaking in it. */\n byVoice: false,\n /** A colour per voice index; short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n fill: Types.custom<Fill, FillResolved[]>(\"#6366f1\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n },\n load: (loader, state) => loader.fill(state.fill),\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type LiveWaveform = NodeOf<typeof LiveWaveform>\n\ninterface LiveState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly window: number\n readonly offset: number\n readonly playing: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly style: WaveformStyle\n readonly speaker: number\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n}\n\n/** The second of the recording on show, off the node's own clock (as `Video`'s is), so a node entering halfway through a clip starts its recording at its entrance. */\nfunction at(ctx: RenderContext, s: LiveState): number {\n return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0)\n}\n\nfunction drawBars(ctx: RenderContext, s: LiveState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const span = Math.max(0.05, s.window)\n const now = at(ctx, s)\n const voice = s.speaker < 0 ? null : Math.round(s.speaker)\n\n // Centred on the playhead, so sound reads as arriving rather than a strip scrolling past.\n const sampled = forSpeaker(\n sampleEnvelope(s.envelope, now - span / 2, now + span / 2, count),\n voice\n )\n\n const shaped = s.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: s.style === \"blocks\" ? 0.12 : s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, s.byVoice, voice)\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\nfunction paintFor(s: LiveState, key: string): Fill {\n if (key === \"all\") return s.fill\n return voiceFill(key, s.voiceColors, s.fill)\n}\n\n/** Fades the outer fifth of the window to silence, the `line` style: a hard edge makes a loud bar appear from nothing, which reads as a glitch. */\nfunction taper(bars: readonly EnvelopeBar[]): EnvelopeBar[] {\n const count = bars.length\n if (count < 3) return [...bars]\n const edge = Math.max(1, Math.floor(count / 5))\n\n return bars.map((bar, i) => {\n const fromEnd = Math.min(i, count - 1 - i)\n const weight = clamp(fromEnd / edge, 0, 1)\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\n })\n}\n", "import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];\n"],
|
|
5
|
+
"mappings": "4HAAA,OACE,SAAAA,EACA,SAAAC,EACA,eAAAC,EACA,aAAAC,EACA,WAAAC,MAQK,oBAYP,IAAMC,EAASC,GACbC,EAAM,OAA6BD,EAAS,CAAE,QAASE,EAAQ,QAAS,KAAMA,EAAQ,IAAI,CAAE,EAajFC,EAAeC,EAAY,CACtC,IAAK,eACL,MAAO,CAEL,SAAUH,EAAM,OAAsBI,CAAc,EACpD,KAAM,IAEN,IAAK,GAEL,OAAQ,EAER,SAAU,EAEV,OAAQ,GAER,KAAM,EAEN,MAAO,KACP,MAAOJ,EAAM,OAA0B,QAAQ,EAC/C,QAAS,GAET,YAAaA,EAAM,OAAiB,CAAA,CAAE,EAEtC,KAAMF,EAAM,SAAS,EACrB,WAA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AAUF,EAAM,EAAG,CAAC,EACzC,MAAO,CAAE,UAAWC,EAAI,UAAYE,EAAQ,QAASF,EAAI,OAAO,CAClE,CAAC,CACH,CCvJO,IAAMI,EAAuD,CAACC,EAAcC,CAAY",
|
|
6
|
+
"names": ["Types", "clamp", "component2d", "easeInOut", "fillOps", "paint", "initial", "Types", "fillOps", "FullWaveform", "component2d", "EMPTY_ENVELOPE", "loader", "state", "timeline", "ease", "easeInOut", "from", "ctx", "drawBars", "s", "width", "height", "count", "sampled", "sampleEnvelope", "boxes", "layOutBars", "edge", "played", "groups", "groupByPaint", "key", "run", "graphics", "paintBars", "paintFor", "clamp", "length", "voiceFill", "Types", "clamp", "component2d", "fillOps", "LiveWaveform", "component2d", "Types", "EMPTY_ENVELOPE", "fillOps", "loader", "state", "ctx", "drawBars", "at", "s", "width", "height", "count", "span", "now", "voice", "sampled", "forSpeaker", "sampleEnvelope", "shaped", "taper", "boxes", "layOutBars", "groups", "groupByPaint", "i", "livePaintKey", "key", "run", "graphics", "paintBars", "paintFor", "voiceFill", "bars", "edge", "bar", "fromEnd", "weight", "clamp", "NODES", "FullWaveform", "LiveWaveform"]
|
|
7
7
|
}
|
package/dist/browser/kit.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as E,b as e,c as o,d as r,e as a,f as p,g as
|
|
1
|
+
import{a as E,b as e,c as o,d as r,e as a,f as p,g as t,h as i,i as l,j as O,l as P}from"./chunks/chunk-WUH3G22N.js";export{E as EMPTY_ENVELOPE,p as VOICE_PALETTE,r as WAVEFORM_ALIGNMENTS,a as WAVEFORM_STYLES,o as forSpeaker,O as groupByPaint,i as layOutBars,P as livePaintKey,l as paintBars,e as sampleEnvelope,t as voiceColor};
|
|
2
2
|
//# sourceMappingURL=kit.js.map
|
package/dist/kit.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the two waveform nodes share, importable without copying it.
|
|
3
|
-
*
|
|
4
|
-
* A registry item copies `envelope.ts` and `shared.ts` beside its node: they
|
|
5
|
-
* hold no class and no registered state, so a fork owning its own copy splits
|
|
6
|
-
* no identity. This is the same surface for a host that samples envelopes or
|
|
7
|
-
* lays bars out itself, and for a fork that keeps only its node file.
|
|
8
|
-
*/
|
|
9
1
|
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./waveform/envelope.js";
|
|
10
2
|
export type { AudioEnvelope, EnvelopeBar } from "./waveform/envelope.js";
|
|
11
|
-
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES,
|
|
3
|
+
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
|
|
12
4
|
export type { BarBox, WaveformAlignment, WaveformStyle } from "./waveform/shared.js";
|
|
13
5
|
//# sourceMappingURL=kit.d.ts.map
|
package/dist/kit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAChF,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/kit.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* What the two waveform nodes share, importable without copying it.
|
|
3
|
-
*
|
|
4
|
-
* A registry item copies `envelope.ts` and `shared.ts` beside its node: they
|
|
5
|
-
* hold no class and no registered state, so a fork owning its own copy splits
|
|
6
|
-
* no identity. This is the same surface for a host that samples envelopes or
|
|
7
|
-
* lays bars out itself, and for a fork that keeps only its node file.
|
|
8
|
-
*/
|
|
1
|
+
// A registry item copies `envelope.ts` and `shared.ts` beside its node (no class or registered state, so a copy splits no identity); this is the same surface for a host or a fork that keeps only its node file.
|
|
9
2
|
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./waveform/envelope.js";
|
|
10
|
-
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES,
|
|
3
|
+
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
|
|
11
4
|
//# sourceMappingURL=kit.js.map
|
package/dist/kit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kit.js","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"kit.js","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA,kNAAkN;AAClN,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEhF,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA","sourcesContent":["// A registry item copies `envelope.ts` and `shared.ts` beside its node (no class or registered state, so a copy splits no identity); this is the same surface for a host or a fork that keeps only its node file.\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./waveform/envelope\"\nexport type { AudioEnvelope, EnvelopeBar } from \"./waveform/envelope\"\nexport {\n VOICE_PALETTE,\n WAVEFORM_ALIGNMENTS,\n WAVEFORM_STYLES,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n} from \"./waveform/shared\"\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./waveform/shared\"\n"]}
|
package/dist/nodes.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import { FullWaveform } from "./waveform/full-waveform.js";
|
|
2
2
|
import { LiveWaveform } from "./waveform/live-waveform.js";
|
|
3
|
-
/**
|
|
4
|
-
* Every node type this package publishes.
|
|
5
|
-
*
|
|
6
|
-
* A host registers these by handing the array to an engine —
|
|
7
|
-
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
8
|
-
* Defining a component only *declares* that key: nothing is registered by
|
|
9
|
-
* importing a module, so a registry holds exactly what its owner asked for.
|
|
10
|
-
*
|
|
11
|
-
* Listing the component **values** is also what survives bundling: this package
|
|
12
|
-
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
13
|
-
* an import kept only for its side effect is exactly what gets shaken out.
|
|
14
|
-
*/
|
|
15
3
|
export declare const NODES: (typeof FullWaveform | typeof LiveWaveform)[];
|
|
16
4
|
//# sourceMappingURL=nodes.d.ts.map
|
package/dist/nodes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,eAAO,MAAM,KAAK,EAAE,CAAC,OAAO,YAAY,GAAG,OAAO,YAAY,CAAC,EAAiC,CAAC"}
|
package/dist/nodes.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { FullWaveform } from "./waveform/full-waveform.js";
|
|
2
2
|
import { LiveWaveform } from "./waveform/live-waveform.js";
|
|
3
|
-
/**
|
|
4
|
-
* Every node type this package publishes.
|
|
5
|
-
*
|
|
6
|
-
* A host registers these by handing the array to an engine —
|
|
7
|
-
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
8
|
-
* Defining a component only *declares* that key: nothing is registered by
|
|
9
|
-
* importing a module, so a registry holds exactly what its owner asked for.
|
|
10
|
-
*
|
|
11
|
-
* Listing the component **values** is also what survives bundling: this package
|
|
12
|
-
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
13
|
-
* an import kept only for its side effect is exactly what gets shaken out.
|
|
14
|
-
*/
|
|
15
3
|
// Typed by name, so the declaration names each component rather than spelling out its type through core.
|
|
16
4
|
export const NODES = [FullWaveform, LiveWaveform];
|
|
17
5
|
//# sourceMappingURL=nodes.js.map
|
package/dist/nodes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,yGAAyG;AACzG,MAAM,CAAC,MAAM,KAAK,GAAkD,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];\n"]}
|
|
@@ -1,120 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* before the document is built. Where the recording sits on the audio lane is
|
|
11
|
-
* the author's timing too, which is why `FullWaveform.follow` is opt-in.
|
|
12
|
-
*
|
|
13
|
-
* ### The JSON form
|
|
14
|
-
*
|
|
15
|
-
* A document holds the envelope as plain JSON, because a prop value in a
|
|
16
|
-
* document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
|
|
17
|
-
* it; `ArrayLike<number>` also accepts the plain arrays a document stores:
|
|
18
|
-
*
|
|
19
|
-
* ```json
|
|
20
|
-
* {
|
|
21
|
-
* "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
|
|
22
|
-
* "duration": 6,
|
|
23
|
-
* "speaker": [0, 0, 0, 1, 1, -1],
|
|
24
|
-
* "speakers": 2
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
|
|
29
|
-
* seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
|
|
30
|
-
* index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
|
|
31
|
-
* `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
|
|
32
|
-
* (`JSON.stringify` writes an object of indices), so a host that holds the typed
|
|
33
|
-
* form converts with `Array.from` before storing it in a document.
|
|
34
|
-
*
|
|
35
|
-
* ## Why the data is baked rather than listened to
|
|
36
|
-
*
|
|
37
|
-
* A scene has to render identically in the preview and in a headless export,
|
|
38
|
-
* and an export has no audio device, no `AudioContext` and no playback to
|
|
39
|
-
* analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
|
|
40
|
-
* reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
|
|
41
|
-
* then a pure function of time, which is what makes scrubbing backwards, jumping
|
|
42
|
-
* to frame 900, and rendering out of order all produce the same frame.
|
|
43
|
-
*
|
|
44
|
-
* The decode happens in the host, once per file, and arrives here through the
|
|
45
|
-
* build — the same arrangement a chart's rows and a protein's atoms already use,
|
|
46
|
-
* and for the same reason: the build is synchronous and cannot await a fetch.
|
|
47
|
-
*
|
|
48
|
-
* ## Why magnitude rather than min/max
|
|
49
|
-
*
|
|
50
|
-
* An editor's waveform is drawn from per-bucket minima *and* maxima, because an
|
|
51
|
-
* editor is a measuring instrument. These nodes are neither — they are a bar
|
|
52
|
-
* chart of loudness that happens to be shaped like a recording — and audio is
|
|
53
|
-
* near enough symmetric that a mirrored magnitude is indistinguishable at the
|
|
54
|
-
* size a node draws. Half the numbers, and one array to reason about.
|
|
2
|
+
* The host decodes audio into an {@link AudioEnvelope} once per file, before the
|
|
3
|
+
* build, and hands it to the node; nothing here decodes or listens. It is baked
|
|
4
|
+
* because an export has no audio device or analyser, and the picture must be a
|
|
5
|
+
* pure function of time.
|
|
6
|
+
*
|
|
7
|
+
* In a document an envelope is plain JSON, which `ArrayLike<number>` accepts.
|
|
8
|
+
* A `Float32Array` is not JSON-serialisable (`JSON.stringify` writes an object
|
|
9
|
+
* of indices), so convert with `Array.from` before storing it.
|
|
55
10
|
*/
|
|
56
11
|
/**
|
|
57
|
-
* A
|
|
58
|
-
* host knows
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* diarized transcript and is folded in by the host before the build. It lives
|
|
62
|
-
* here rather than in a parallel structure because every reader of it is also a
|
|
63
|
-
* reader of the magnitudes at the same index, and two arrays that must stay the
|
|
64
|
-
* same length are better as one object than as two arguments.
|
|
12
|
+
* A recording reduced to a uniform grid of loudness, plus who is talking in each
|
|
13
|
+
* bucket when the host knows. The speaker track comes from a diarized transcript,
|
|
14
|
+
* not the decoder; it lives here because every reader of it also reads the
|
|
15
|
+
* magnitudes at the same index.
|
|
65
16
|
*/
|
|
66
17
|
export interface AudioEnvelope {
|
|
67
|
-
/**
|
|
68
|
-
* Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A
|
|
69
|
-
* `Float32Array`, or the plain `number[]` a document stores.
|
|
70
|
-
*/
|
|
18
|
+
/** Peak magnitude per bucket, 0 to 1; buckets span {@link duration} evenly. */
|
|
71
19
|
magnitude: ArrayLike<number>;
|
|
72
|
-
/**
|
|
20
|
+
/** Seconds. */
|
|
73
21
|
duration: number;
|
|
74
|
-
/**
|
|
75
|
-
* Which voice is speaking in each bucket, as an index into the recording's
|
|
76
|
-
* own numbering, or `-1` for "nobody identified". Parallel to
|
|
77
|
-
* {@link magnitude}, or `null` when the track was never diarized.
|
|
78
|
-
*/
|
|
22
|
+
/** Voice index per bucket (`-1` for nobody), parallel to {@link magnitude}, or `null` when never diarized. */
|
|
79
23
|
speaker: ArrayLike<number> | null;
|
|
80
|
-
/**
|
|
24
|
+
/** Zero when the diarizer did not run. */
|
|
81
25
|
speakers: number;
|
|
82
26
|
}
|
|
83
|
-
/** The envelope of a track that
|
|
27
|
+
/** The envelope of a track that has not loaded or is not there. */
|
|
84
28
|
export declare const EMPTY_ENVELOPE: AudioEnvelope;
|
|
85
|
-
/** One drawn bar: how loud, and whose. */
|
|
86
29
|
export interface EnvelopeBar {
|
|
87
|
-
/** 0
|
|
30
|
+
/** 0 to 1. */
|
|
88
31
|
magnitude: number;
|
|
89
|
-
/**
|
|
32
|
+
/** Voice index, or -1. */
|
|
90
33
|
speaker: number;
|
|
91
34
|
}
|
|
92
35
|
/**
|
|
93
|
-
* Resamples `[from, to)` seconds
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* speech rather than as noise. The speaker of a column is the speaker of its
|
|
99
|
-
* *loudest* bucket, on the same reasoning — a column straddling a turn belongs
|
|
100
|
-
* to whoever is actually audible in it.
|
|
101
|
-
*
|
|
102
|
-
* A window past either end of the recording yields silent, unattributed
|
|
103
|
-
* columns rather than clamping onto the nearest real one. That matters for the
|
|
104
|
-
* live visualiser, which is handed a window centred on the playhead and would
|
|
105
|
-
* otherwise smear the first bucket across the whole run-up to a track's start.
|
|
36
|
+
* Resamples `[from, to)` seconds down to `bars` columns, keeping peaks rather
|
|
37
|
+
* than averaging: averaging flattens the transients that make a drawing read as
|
|
38
|
+
* speech. A column's speaker is that of its loudest bucket. A window past either
|
|
39
|
+
* end yields silent, unattributed columns rather than clamping onto the nearest
|
|
40
|
+
* real one, which would smear the first bucket across a live window's run-up.
|
|
106
41
|
*/
|
|
107
42
|
export declare function sampleEnvelope(envelope: AudioEnvelope, from: number, to: number, bars: number): EnvelopeBar[];
|
|
108
43
|
/**
|
|
109
|
-
* The same window
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* *drops*: a podcast visualiser filtered to one host should go quiet while the
|
|
113
|
-
* other one talks, not compress their turn out of existence. Keeping the bars
|
|
114
|
-
* and zeroing them is what makes the picture read as "this person is not
|
|
115
|
-
* speaking right now" instead of as a jump cut.
|
|
116
|
-
*
|
|
117
|
-
* `voice` of `null` returns the bars untouched, which is the unfiltered node.
|
|
44
|
+
* The same window with everything but `voice` silenced, not dropped, so a
|
|
45
|
+
* filtered visualiser goes quiet while the other host talks instead of cutting
|
|
46
|
+
* their turn out. `null` returns the bars untouched.
|
|
118
47
|
*/
|
|
119
48
|
export declare function forSpeaker(bars: EnvelopeBar[], voice: number | null): EnvelopeBar[];
|
|
120
49
|
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC5B,eAAe;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,8GAA8G;IAC9G,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;IACjC,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,aAK5B,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,cAAc;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,WAAW,EAAE,CAiCf;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,WAAW,EAAE,CAKf"}
|
|
@@ -1,59 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The host decodes audio into an {@link AudioEnvelope} once per file, before the
|
|
3
|
+
* build, and hands it to the node; nothing here decodes or listens. It is baked
|
|
4
|
+
* because an export has no audio device or analyser, and the picture must be a
|
|
5
|
+
* pure function of time.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* does not read a `sound` node's `src`, declares no audio asset and is not tied
|
|
8
|
-
* to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`
|
|
9
|
-
* prop. Decoding a file into an envelope is the host's job, done once per file
|
|
10
|
-
* before the document is built. Where the recording sits on the audio lane is
|
|
11
|
-
* the author's timing too, which is why `FullWaveform.follow` is opt-in.
|
|
12
|
-
*
|
|
13
|
-
* ### The JSON form
|
|
14
|
-
*
|
|
15
|
-
* A document holds the envelope as plain JSON, because a prop value in a
|
|
16
|
-
* document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
|
|
17
|
-
* it; `ArrayLike<number>` also accepts the plain arrays a document stores:
|
|
18
|
-
*
|
|
19
|
-
* ```json
|
|
20
|
-
* {
|
|
21
|
-
* "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
|
|
22
|
-
* "duration": 6,
|
|
23
|
-
* "speaker": [0, 0, 0, 1, 1, -1],
|
|
24
|
-
* "speakers": 2
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
|
|
29
|
-
* seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
|
|
30
|
-
* index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
|
|
31
|
-
* `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
|
|
32
|
-
* (`JSON.stringify` writes an object of indices), so a host that holds the typed
|
|
33
|
-
* form converts with `Array.from` before storing it in a document.
|
|
34
|
-
*
|
|
35
|
-
* ## Why the data is baked rather than listened to
|
|
36
|
-
*
|
|
37
|
-
* A scene has to render identically in the preview and in a headless export,
|
|
38
|
-
* and an export has no audio device, no `AudioContext` and no playback to
|
|
39
|
-
* analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
|
|
40
|
-
* reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
|
|
41
|
-
* then a pure function of time, which is what makes scrubbing backwards, jumping
|
|
42
|
-
* to frame 900, and rendering out of order all produce the same frame.
|
|
43
|
-
*
|
|
44
|
-
* The decode happens in the host, once per file, and arrives here through the
|
|
45
|
-
* build — the same arrangement a chart's rows and a protein's atoms already use,
|
|
46
|
-
* and for the same reason: the build is synchronous and cannot await a fetch.
|
|
47
|
-
*
|
|
48
|
-
* ## Why magnitude rather than min/max
|
|
49
|
-
*
|
|
50
|
-
* An editor's waveform is drawn from per-bucket minima *and* maxima, because an
|
|
51
|
-
* editor is a measuring instrument. These nodes are neither — they are a bar
|
|
52
|
-
* chart of loudness that happens to be shaped like a recording — and audio is
|
|
53
|
-
* near enough symmetric that a mirrored magnitude is indistinguishable at the
|
|
54
|
-
* size a node draws. Half the numbers, and one array to reason about.
|
|
7
|
+
* In a document an envelope is plain JSON, which `ArrayLike<number>` accepts.
|
|
8
|
+
* A `Float32Array` is not JSON-serialisable (`JSON.stringify` writes an object
|
|
9
|
+
* of indices), so convert with `Array.from` before storing it.
|
|
55
10
|
*/
|
|
56
|
-
/** The envelope of a track that
|
|
11
|
+
/** The envelope of a track that has not loaded or is not there. */
|
|
57
12
|
export const EMPTY_ENVELOPE = {
|
|
58
13
|
magnitude: new Float32Array(0),
|
|
59
14
|
duration: 0,
|
|
@@ -61,19 +16,11 @@ export const EMPTY_ENVELOPE = {
|
|
|
61
16
|
speakers: 0,
|
|
62
17
|
};
|
|
63
18
|
/**
|
|
64
|
-
* Resamples `[from, to)` seconds
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* speech rather than as noise. The speaker of a column is the speaker of its
|
|
70
|
-
* *loudest* bucket, on the same reasoning — a column straddling a turn belongs
|
|
71
|
-
* to whoever is actually audible in it.
|
|
72
|
-
*
|
|
73
|
-
* A window past either end of the recording yields silent, unattributed
|
|
74
|
-
* columns rather than clamping onto the nearest real one. That matters for the
|
|
75
|
-
* live visualiser, which is handed a window centred on the playhead and would
|
|
76
|
-
* otherwise smear the first bucket across the whole run-up to a track's start.
|
|
19
|
+
* Resamples `[from, to)` seconds down to `bars` columns, keeping peaks rather
|
|
20
|
+
* than averaging: averaging flattens the transients that make a drawing read as
|
|
21
|
+
* speech. A column's speaker is that of its loudest bucket. A window past either
|
|
22
|
+
* end yields silent, unattributed columns rather than clamping onto the nearest
|
|
23
|
+
* real one, which would smear the first bucket across a live window's run-up.
|
|
77
24
|
*/
|
|
78
25
|
export function sampleEnvelope(envelope, from, to, bars) {
|
|
79
26
|
const count = Math.max(0, Math.floor(bars));
|
|
@@ -88,8 +35,7 @@ export function sampleEnvelope(envelope, from, to, bars) {
|
|
|
88
35
|
for (let i = 0; i < count; i++) {
|
|
89
36
|
const start = (from + span * i) * perSecond;
|
|
90
37
|
const end = (from + span * (i + 1)) * perSecond;
|
|
91
|
-
// At least one bucket per column, so a
|
|
92
|
-
// the sample it is standing on rather than an empty band.
|
|
38
|
+
// At least one bucket per column, so a zoomed-in window draws the sample it stands on.
|
|
93
39
|
const first = Math.floor(start);
|
|
94
40
|
const last = Math.max(first, Math.ceil(end) - 1);
|
|
95
41
|
let loudest = 0;
|
|
@@ -108,15 +54,9 @@ export function sampleEnvelope(envelope, from, to, bars) {
|
|
|
108
54
|
return out;
|
|
109
55
|
}
|
|
110
56
|
/**
|
|
111
|
-
* The same window
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* *drops*: a podcast visualiser filtered to one host should go quiet while the
|
|
115
|
-
* other one talks, not compress their turn out of existence. Keeping the bars
|
|
116
|
-
* and zeroing them is what makes the picture read as "this person is not
|
|
117
|
-
* speaking right now" instead of as a jump cut.
|
|
118
|
-
*
|
|
119
|
-
* `voice` of `null` returns the bars untouched, which is the unfiltered node.
|
|
57
|
+
* The same window with everything but `voice` silenced, not dropped, so a
|
|
58
|
+
* filtered visualiser goes quiet while the other host talks instead of cutting
|
|
59
|
+
* their turn out. `null` returns the bars untouched.
|
|
120
60
|
*/
|
|
121
61
|
export function forSpeaker(bars, voice) {
|
|
122
62
|
if (voice === null)
|