Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 28f144ba67509618c4f229308e9311c536e353bc
parent ca21d22b0dfe3e2d00294cfc3108e0326250eb17
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 16:27:12 -0500

umtool: the teaser's trailer hit factored into trailer-hits.mjs -- its tiers, its swell, its level and its ffmpeg generator (trailerHitsGraph, labels by prefix; trailerHitSamples for a browser) -- so a post item's slam plays the same hit; the teaser's graph is byte for byte what it was (teaser-audio, chrome-teaser, dip tests green; the ferret cut's key unchanged)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/report-to-video/build-video.mjs | 91+++++++------------------------------------------------------------------------
Mumtool/report-to-video/deck.mjs | 11++++-------
Mumtool/report-to-video/package.json | 1+
Aumtool/report-to-video/trailer-hits.mjs | 152+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 165 insertions(+), 90 deletions(-)

diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -216,6 +216,7 @@ import { // The snap itself (a montage's window snaps with it too), re-exported for the tests. import { snap } from "./snap.mjs"; import { buildPostSegment } from "./post-render.mjs"; +import { TRAILER_AUDIO, trailerHitsGraph } from "./trailer-hits.mjs"; import { planContext, planContextOf } from "./post-conversation.mjs"; /** The item before post item `id` with its own context (post-join.mjs: what the item opens on), or null. */ @@ -2702,94 +2703,18 @@ async function buildNarratedCardSegment(card, render, outDir, nodes, framing, re export const teaserRecordPath = (seg) => seg.replace(/\.mp4$/, ".teaser.json"); /** The teaser sound's level and ceiling: `limit` is −6 dBFS; `level` is set against the ferret cut's loudness (README). */ -export const TEASER_AUDIO = Object.freeze({ level: 1.4, limit: 0.5 }); - -/** A number for an aevalsrc expression: 6 decimals, no trailing zeros. */ -const ev6 = (v) => { - const s = (Math.round(Number(v) * 1e6) / 1e6).toFixed(6).replace(/\.?0+$/, ""); - return s === "-0" ? "0" : s; -}; +export const TEASER_AUDIO = TRAILER_AUDIO; /** * The teaser's sound, as one filtergraph fragment from no inputs to `[ta]`: - * `hits` (`teaserHits`) synthesised in ffmpeg, no samples. - * - * A hit is three layers, each summed over every hit in one `aevalsrc` and - * gated to its own span, so each starts on the sample its time names: - * - the boom: a sine whose pitch drops from f0 to f1 (most of the way in - * ~0.4 s), with its octave for body, on an exponential decay (`decay` is - * the time constant; it is inaudible by ~7×) after a 3 ms attack; - * - the punch: a burst of noise (50 ms time constant), band-passed (180 Hz–3.2 kHz); - * - the tail: a low noise decay (low-passed at 260 Hz) under it. - * A swell is the boom's sine rising f0 → f1 under an envelope that peaks - * three quarters of the way through `dur` and settles, with a breath of the - * low noise. A riser (a dip's, under the black) is a sub whose pitch climbs - * f0 → f1 over `dur` and a noise swell -- its own layer, band-passed - * 400 Hz–6.5 kHz, present only when there is a riser -- both rising (the sub - * squared, the noise cubed) to their peak at the first hit and released over - * `decay`. The noise is a hash of the sample number, not `random()`, so it - * is the same whatever else is in the graph. The sum takes a short low-passed - * echo, then `level`, then a limiter at −6 dBFS (`limit`, no auto-level, - * latency compensated) so hits that overlap still sum cleanly; trimmed and - * padded to exactly `seconds`. No hits: digital silence. + * `hits` (`teaserHits`) synthesised in ffmpeg, no samples -- the trailer hits' + * generator (trailer-hits.mjs trailerHitsGraph, which a post item's slam plays + * too), its labels the teaser's own (`t`). The layers, the echo, the level and + * the limiter are described there; the graph is byte for byte what it was + * before the generator was factored out. */ export function teaserAudioGraph(hits, { seconds, render, level = TEASER_AUDIO.level, limit = TEASER_AUDIO.limit }) { - const rate = render.audioRate; - const layout = render.audioChannels === 1 ? "mono" : "stereo"; - const len = ev6(seconds); - const tail = `atrim=end=${len},apad=whole_dur=${len},asetpts=PTS-STARTPTS[ta]`; - if (!hits.length) return `anullsrc=channel_layout=${layout}:sample_rate=${rate},${tail}`; - const noise = "(2*(sin(n*12.9898+78.233)*43758.5453-floor(sin(n*12.9898+78.233)*43758.5453))-1)"; - const boom = []; - const punch = []; - const rumble = []; - const whoosh = []; - for (const h of hits) { - const a = ev6(h.at); - const u = `(t-${a})`; - const g = ev6(h.gain); - if (h.kind === "riser") { - const D = ev6(h.dur); - const v = `min(${u},${D})`; - const phase = `(${ev6(h.f0)}*${v}+${ev6((h.f1 - h.f0) / (2 * h.dur))}*${v}*${v}+${ev6(h.f1)}*(${u}-${v}))`; - const rel = `clip((${ev6(h.dur + h.decay)}-${u})/${ev6(h.decay)},0,1)`; - const span = ev6(h.dur + h.decay); - boom.push(`if(between(t,${a},${a}+${span}),${g}*0.5*pow(${v}/${D},2)*${rel}*sin(2*PI*${phase}),0)`); - whoosh.push(`if(between(t,${a},${a}+${span}),${g}*0.6*pow(${v}/${D},3)*${rel}*${noise},0)`); - continue; - } - if (h.kind === "swell") { - const D = h.dur; - const peak = ev6(D * 0.75); - const v = `min(${u},${ev6(D)})`; - const phase = `(${ev6(h.f0)}*${v}+${ev6((h.f1 - h.f0) / (2 * D))}*${v}*${v}+${ev6(h.f1)}*(${u}-${v}))`; - const env = `pow(sin(PI/2*min(1,${u}/${peak})),2)*exp(-max(0,${u}-${peak})/${ev6(h.decay)})`; - const span = ev6(D * 0.75 + h.decay * 7); - boom.push(`if(between(t,${a},${a}+${span}),${g}*0.42*${env}*sin(2*PI*${phase}),0)`); - rumble.push(`if(between(t,${a},${a}+${span}),${g}*0.5*${env}*${noise},0)`); - continue; - } - const k = 0.13; // the pitch drop's time constant - const phase = `(${ev6(h.f1)}*${u}+${ev6((h.f0 - h.f1) * k)}*(1-exp(-${u}/${k})))`; - const span = ev6(h.decay * 7); - boom.push( - `if(between(t,${a},${a}+${span}),${g}*0.3*min(1,${u}/0.003)*exp(-${u}/${ev6(h.decay)})*` + - `(sin(2*PI*${phase})+0.6*exp(-${u}/${ev6(h.decay * 0.6)})*sin(4*PI*${phase})),0)`, - ); - punch.push(`if(between(t,${a},${a}+0.25),${g}*0.5*exp(-${u}/0.05)*${noise},0)`); - rumble.push(`if(between(t,${a},${a}+${ev6(Math.min(2.6, h.decay * 6))}),${g}*0.32*min(1,${u}/0.02)*exp(-${u}/${ev6(h.decay * 1.3)})*${noise},0)`); - } - const src = (terms) => `aevalsrc=exprs='${terms.length ? terms.join("+") : "0"}':s=${rate}:c=${layout}:d=${len}`; - // The riser's layer only when there is one: a teaser without a dip writes the graph it always did. - const w = whoosh.length ? [`${src(whoosh)},highpass=f=400,lowpass=f=6500[tw]`] : []; - return [ - `${src(boom)}[tb]`, - `${src(punch)},highpass=f=180,lowpass=f=3200[tp]`, - `${src(rumble)},lowpass=f=260,lowpass=f=260[tr]`, - ...w, - `[tb][tp][tr]${w.length ? "[tw]" : ""}amix=inputs=${3 + w.length}:normalize=0,aecho=1:1:90|190:0.18|0.09,lowpass=f=5000,` + - `volume=${ev6(level)},alimiter=limit=${ev6(limit)}:level=0:latency=1:attack=2:release=80,${tail}`, - ].join(";"); + return trailerHitsGraph(hits, { seconds, rate: render.audioRate, layout: render.audioChannels === 1 ? "mono" : "stereo", level, limit, prefix: "t" }); } /** The teaser segment's encode: its frames, its sound, the shared parameters. */ diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -27,6 +27,7 @@ import { claimOf, marksOf, originalUrlAt, resolveFactcheck, roundStamps, stampSchedule, stampsWithFinale, tallyOf, tallyVerdicts, validateFactcheck, } from "./factcheck.mjs"; import { resolveCounter } from "./counter.mjs"; +import { TRAILER_HIT_TIERS, TRAILER_SWELL } from "./trailer-hits.mjs"; import { DECK_PAD_X, COUNTER_CELL } from "./modules/design.mjs"; import { DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, markerShapeErrors, @@ -3160,12 +3161,8 @@ export function teaserHits(entry, D = 0.5, fps = 30) { const { gain, f0, f1 } = DIP_RISER; out.push({ kind: "riser", at, role: "dip", gain, decay: 0.04, f0, f1, dur: Math.round((end - at) * 10000) / 10000 }); } - const HIT = { - title: { gain: 1, decay: 0.42, f0: 92, f1: 40 }, - overline: { gain: 0.72, decay: 0.34, f0: 96, f1: 44 }, - kicker: { gain: 0.8, decay: 0.36, f0: 94, f1: 42 }, - sub: { gain: 0.42, decay: 0.16, f0: 120, f1: 64 }, - }; + // The tiers are the trailer hits' (trailer-hits.mjs, which a post item's slam plays too). + const HIT = TRAILER_HIT_TIERS; lines.forEach((l, i) => { out.push({ kind: "hit", at: times.lines[i].impact, role: l.role, ...HIT[l.role] }); if (l.sub && !l.together && times.lines[i].subAt != null) { @@ -3173,7 +3170,7 @@ export function teaserHits(entry, D = 0.5, fps = 30) { } }); if (tail && times.tailAt != null) { - out.push({ kind: "swell", at: times.tailAt, role: "tail", gain: 0.34, decay: 0.7, f0: 46, f1: 62, dur: times.tailDur }); + out.push({ kind: "swell", at: times.tailAt, role: "tail", ...TRAILER_SWELL, dur: times.tailDur }); } return out; } diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json @@ -80,6 +80,7 @@ "./word-zoom": "./word-zoom.mjs", "./post-caption": "./post-caption.mjs", "./post-clock": "./post-clock.mjs", + "./trailer-hits": "./trailer-hits.mjs", "./read-follow": "./read-follow.mjs", "./presets": "./presets.mjs", "./prune-frames": "./prune-frames.mjs", diff --git a/umtool/report-to-video/trailer-hits.mjs b/umtool/report-to-video/trailer-hits.mjs @@ -0,0 +1,152 @@ +// TRAILER HITS: the movie-trailer boom the teaser card plays under each pop +// (deck.mjs teaserHits, build-video.mjs teaserAudioGraph -- the ferret-rescue +// finale's), factored out so a post item's SLAM (post-slam.mjs) plays the same +// generator: one hit per glyph, the title tier, and optionally the tail's swell. +// +// Synthesised in ffmpeg, no samples: nothing is downloaded or bundled. The +// teaser's graph is byte for byte what it was before this module (its tests, +// and so the ferret cut's render key, are unchanged); the slam's names its own +// labels (`prefix`) so the graph can sit inside a post segment's. +// +// Plain ESM, no imports: build-video, deck, post-render and the browser (Play's +// live sound, trailerHitSamples) all read it. + +/** + * The hits' tiers (gains relative: the main title is 1): a title's hit is the + * biggest, an overline's and a kicker's a little smaller, a second tier's + * lighter and shorter. `decay` is the boom's time constant, `f0 → f1` its pitch drop. + */ +export const TRAILER_HIT_TIERS = Object.freeze({ + title: Object.freeze({ gain: 1, decay: 0.42, f0: 92, f1: 40 }), + overline: Object.freeze({ gain: 0.72, decay: 0.34, f0: 96, f1: 44 }), + kicker: Object.freeze({ gain: 0.8, decay: 0.36, f0: 94, f1: 42 }), + sub: Object.freeze({ gain: 0.42, decay: 0.16, f0: 120, f1: 64 }), +}); + +/** The tail's swell (a low rise under a slow entrance): its gain, decay and pitch, the duration the caller's. */ +export const TRAILER_SWELL = Object.freeze({ gain: 0.34, decay: 0.7, f0: 46, f1: 62 }); + +/** The sound's level and ceiling: `limit` is −6 dBFS; `level` is set against the ferret cut's loudness (README). */ +export const TRAILER_AUDIO = Object.freeze({ level: 1.4, limit: 0.5 }); + +/** A number for an aevalsrc expression: 6 decimals, no trailing zeros. */ +export const ev6 = (v) => { + const s = (Math.round(Number(v) * 1e6) / 1e6).toFixed(6).replace(/\.?0+$/, ""); + return s === "-0" ? "0" : s; +}; + +/** The hash noise every layer uses (the same whatever else is in the graph), as an expression of the sample `n`. */ +const NOISE = "(2*(sin(n*12.9898+78.233)*43758.5453-floor(sin(n*12.9898+78.233)*43758.5453))-1)"; + +/** + * The hits' sound, as one filtergraph fragment from no inputs to `[<prefix>a]` + * (`prefix` "t": the teaser's `[ta]`, and its inner labels `[tb] [tp] [tr] [tw]`). + * + * A hit is three layers, each summed over every hit in one `aevalsrc` and + * gated to its own span, so each starts on the sample its time names: + * - the boom: a sine whose pitch drops from f0 to f1 (most of the way in + * ~0.4 s), with its octave for body, on an exponential decay (`decay` is + * the time constant; it is inaudible by ~7×) after a 3 ms attack; + * - the punch: a burst of noise (50 ms time constant), band-passed (180 Hz–3.2 kHz); + * - the tail: a low noise decay (low-passed at 260 Hz) under it. + * A swell is the boom's sine rising f0 → f1 under an envelope that peaks + * three quarters of the way through `dur` and settles, with a breath of the + * low noise. A riser (a dip's, under the black) is a sub whose pitch climbs + * f0 → f1 over `dur` and a noise swell -- its own layer, band-passed + * 400 Hz–6.5 kHz, present only when there is a riser -- both rising (the sub + * squared, the noise cubed) to their peak at the first hit and released over + * `decay`. The sum takes a short low-passed echo, then `level`, then a limiter + * at `limit` (no auto-level, latency compensated) so hits that overlap still + * sum cleanly; trimmed and padded to exactly `seconds`. No hits: digital silence. + * + * @param {Array<{ kind: string, at: number, gain: number, decay: number, f0: number, f1: number, dur?: number }>} hits + * @param {{ seconds: number, rate: number, layout?: string, level?: number, limit?: number, prefix?: string }} o + */ +export function trailerHitsGraph(hits, { seconds, rate, layout = "stereo", level = TRAILER_AUDIO.level, limit = TRAILER_AUDIO.limit, prefix = "t" }) { + const p = prefix; + const len = ev6(seconds); + const tail = `atrim=end=${len},apad=whole_dur=${len},asetpts=PTS-STARTPTS[${p}a]`; + if (!hits.length) return `anullsrc=channel_layout=${layout}:sample_rate=${rate},${tail}`; + const noise = NOISE; + const boom = []; + const punch = []; + const rumble = []; + const whoosh = []; + for (const h of hits) { + const a = ev6(h.at); + const u = `(t-${a})`; + const g = ev6(h.gain); + if (h.kind === "riser") { + const D = ev6(h.dur); + const v = `min(${u},${D})`; + const phase = `(${ev6(h.f0)}*${v}+${ev6((h.f1 - h.f0) / (2 * h.dur))}*${v}*${v}+${ev6(h.f1)}*(${u}-${v}))`; + const rel = `clip((${ev6(h.dur + h.decay)}-${u})/${ev6(h.decay)},0,1)`; + const span = ev6(h.dur + h.decay); + boom.push(`if(between(t,${a},${a}+${span}),${g}*0.5*pow(${v}/${D},2)*${rel}*sin(2*PI*${phase}),0)`); + whoosh.push(`if(between(t,${a},${a}+${span}),${g}*0.6*pow(${v}/${D},3)*${rel}*${noise},0)`); + continue; + } + if (h.kind === "swell") { + const D = h.dur; + const peak = ev6(D * 0.75); + const v = `min(${u},${ev6(D)})`; + const phase = `(${ev6(h.f0)}*${v}+${ev6((h.f1 - h.f0) / (2 * D))}*${v}*${v}+${ev6(h.f1)}*(${u}-${v}))`; + const env = `pow(sin(PI/2*min(1,${u}/${peak})),2)*exp(-max(0,${u}-${peak})/${ev6(h.decay)})`; + const span = ev6(D * 0.75 + h.decay * 7); + boom.push(`if(between(t,${a},${a}+${span}),${g}*0.42*${env}*sin(2*PI*${phase}),0)`); + rumble.push(`if(between(t,${a},${a}+${span}),${g}*0.5*${env}*${noise},0)`); + continue; + } + const k = HIT_PITCH_TAU; + const phase = `(${ev6(h.f1)}*${u}+${ev6((h.f0 - h.f1) * k)}*(1-exp(-${u}/${k})))`; + const span = ev6(h.decay * 7); + boom.push( + `if(between(t,${a},${a}+${span}),${g}*0.3*min(1,${u}/0.003)*exp(-${u}/${ev6(h.decay)})*` + + `(sin(2*PI*${phase})+0.6*exp(-${u}/${ev6(h.decay * 0.6)})*sin(4*PI*${phase})),0)`, + ); + punch.push(`if(between(t,${a},${a}+0.25),${g}*0.5*exp(-${u}/0.05)*${noise},0)`); + rumble.push(`if(between(t,${a},${a}+${ev6(Math.min(2.6, h.decay * 6))}),${g}*0.32*min(1,${u}/0.02)*exp(-${u}/${ev6(h.decay * 1.3)})*${noise},0)`); + } + const src = (terms) => `aevalsrc=exprs='${terms.length ? terms.join("+") : "0"}':s=${rate}:c=${layout}:d=${len}`; + // The riser's layer only when there is one: a teaser without a dip writes the graph it always did. + const w = whoosh.length ? [`${src(whoosh)},highpass=f=400,lowpass=f=6500[${p}w]`] : []; + return [ + `${src(boom)}[${p}b]`, + `${src(punch)},highpass=f=180,lowpass=f=3200[${p}p]`, + `${src(rumble)},lowpass=f=260,lowpass=f=260[${p}r]`, + ...w, + `[${p}b][${p}p][${p}r]${w.length ? `[${p}w]` : ""}amix=inputs=${3 + w.length}:normalize=0,aecho=1:1:90|190:0.18|0.09,lowpass=f=5000,` + + `volume=${ev6(level)},alimiter=limit=${ev6(limit)}:level=0:latency=1:attack=2:release=80,${tail}`, + ].join(";"); +} + +/** The hit's pitch drop's time constant, seconds. */ +export const HIT_PITCH_TAU = 0.13; + +/** + * ONE HIT's raw layers as samples (Play's live sound: the same formulas as + * trailerHitsGraph's `aevalsrc`, which a browser then filters as the graph does + * -- the punch band-passed 180 Hz–3.2 kHz, the rumble low-passed at 260 Hz). + * `{ boom, punch, rumble }`, Float32Arrays of `seconds` at `rate`, from the hit's + * own start (sample 0 is its `at`). + * @param {{ gain: number, decay: number, f0: number, f1: number }} h + * @param {number} rate + */ +export function trailerHitSamples(h, rate = 48000) { + const seconds = Math.min(3, h.decay * 7); + const n = Math.max(1, Math.round(seconds * rate)); + const boom = new Float32Array(n); + const punch = new Float32Array(n); + const rumble = new Float32Array(n); + const k = HIT_PITCH_TAU; + const fr = (x) => x - Math.floor(x); + for (let i = 0; i < n; i += 1) { + const u = i / rate; + const phase = h.f1 * u + (h.f0 - h.f1) * k * (1 - Math.exp(-u / k)); + boom[i] = h.gain * 0.3 * Math.min(1, u / 0.003) * Math.exp(-u / h.decay) * (Math.sin(2 * Math.PI * phase) + 0.6 * Math.exp(-u / (h.decay * 0.6)) * Math.sin(4 * Math.PI * phase)); + const nz = 2 * fr(Math.sin(i * 12.9898 + 78.233) * 43758.5453) - 1; + punch[i] = u <= 0.25 ? h.gain * 0.5 * Math.exp(-u / 0.05) * nz : 0; + rumble[i] = u <= Math.min(2.6, h.decay * 6) ? h.gain * 0.32 * Math.min(1, u / 0.02) * Math.exp(-u / (h.decay * 1.3)) * nz : 0; + } + return { boom, punch, rumble, seconds }; +}