Archilyzer · Source

archilyzer

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

commit bedf57c0a6afebc5a2895e3642838794e1a3b9de
parent 56dc37196f40d4f3d091899fc78219fffb855635
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun, 18 Oct 2026 01:48:47 -0400

umtool: the synced wall aligns its tiles to each other — consensus over speech bands, anchored on the group's rise; the grouped wall's sound re-stamped

On the slow-news tail, whisper's token offsets and the cue estimates both sit up to ~±0.4 s off the sound,
and one clip's loudness rise cannot tell "slow" from the word before it. So a synced wall (3+ tiles) now
matches each tile's 8-band speech spectrum over its phrase to the mean of the others' (consensusLags, ±0.4 s,
median shift zero), then moves the group onto its mean loudness's rise (templateOnset, ±0.3 s); fewer tiles
keep refineOnset. Exact to the 5 ms hop on synthetic takes. The wall's record keeps by/r per tile and the
syncAnchor. The grouped compose's mix is re-stamped by sample count before its fades: on real tiles amix's
clock ran ahead and the fade silenced everything after the first tile. Today's wall is untouched (bytes as
main's).

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

Diffstat:
Mumtool/report-to-video/README.md | 15+++++++++++----
Mumtool/report-to-video/build-video.mjs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Mumtool/report-to-video/montage.mjs | 190++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/report-to-video/montage.test.mjs | 41++++++++++++++++++++++++++++++++++++-----
4 files changed, 294 insertions(+), 26 deletions(-)

diff --git a/umtool/report-to-video/README.md b/umtool/report-to-video/README.md @@ -747,8 +747,9 @@ stutter's `every` counts the same number; the ramp counts places. "counter": { "style": "chip", "position": "top-left", "of": false, "showDate": true, "showSource": true }, "punch": { "mode": "snap", "scale": 1.15, "anchor": "upper" }, "stutter": { "every": 5, "clips": ["s12"], "times": 3, "length": 0.35, "step": 0.04 }, - "ramp": { "from": 4, "to": 1.4 }, - "wall": { "at": "end", "tiles": 16, "build": 8, "year": true }, + "ramp": { "from": 4, "to": 1.4 }, // or { "from": 3.5, "into": "wall" } + "wall": { "at": "end", "tiles": 16, "build": 8, "year": true, + "groups": "double", "sync": true, "clips": "tail", "exclusive": true }, "yearStamp": true } } ``` @@ -760,8 +761,12 @@ stutter's `every` counts the same number; the ramp counts places. | `counter` | An overlay, never a card. `chip`: "#12 · 2 May 2019 · YouTube" on a translucent ground, the whole clip. `big`: the number, large in the accent colour, slamming in on each cut and gone by 1.5 s, the date under it. `tally`: tick marks in fives, the newest landing in the accent. `of: true` adds "of N". Corners: `top-left`, `top-right`, `bottom-left`, `bottom-right`. | | `punch` | `snap`: the picture jumps to `scale` (1.15) at the phrase's onset. `drift`: a slow zoom from 1 to `scale` (1.08) over the clip. `anchor: "upper"` holds the upper third (where a face usually is); `"center"` the middle. | | `stutter` | On every `every`th clip and on the clips named in `clips`: the phrase's last `length` seconds are heard `times` times in all (2–4), each repeat `step` more zoomed — "…news day-day-day". The clip is that much longer. | -| `ramp` | Clip k's cut is at most lerp(`from`, `to`, k/(N−1)) seconds — the first `from`, the last `to` — trimmed evenly around the phrase, never into it. Needs `tighten: "phrase"`. | +| `ramp` | Clip k's cut is at most lerp(`from`, `to`, k/(N−1)) seconds — the first `from`, the last `to` — trimmed evenly around the phrase, never into it. Needs `tighten: "phrase"`. `into: "wall"` (with a `wall`) ends the ramp on the wall's first gap instead of `to`, so the cut runs straight into the wall at its pace. | | `wall` | One more segment at the `end` (or `start`): a grid of 9, 16 or 25 tiles, each playing a clip's phrase (clips spread first to last; fewer clips than tiles go round again). Tile i appears at build·(1−(1−i/tiles)²) seconds, so the last come fastest; the newest tile is heard, the rest ducked; at `build` every tile says it together, then the cut. `year: true` labels each tile with its year. Its chapter is "All together". | +| `wall.groups` | `"single"` (default): the tiles one at a time, as above. `"double"`: in groups of 1, 1, 2, 4, 8 … (9 tiles: 1,1,2,5; 16: 1,1,2,4,8; 25: 1,1,2,4,8,9 — a leftover smaller than the group before joins it). Each group arrives together on a beat, sliding in from the right over four frames; the gaps between beats fall evenly from the first to half of it across `build`. A group's tiles say their phrase in unison and fall silent (a 40 ms fade) just before the next group's beat; then every tile together. | +| `wall.sync` | Default `true` with `"double"` groups, else `false`. Each tile is cut to start 0.12 s before its phrase's onset and end 0.25 s after the phrase, and is shown that 0.12 s before its beat, so the onset lands exactly on its group's beat and on the final beat: the crowd says it on one frame. The estimate is whisper's word offset when the corpus's `transcript.json` keeps them, else the cue estimate (character position). Neither is good to better than a few hundred milliseconds, and the loudness of one clip cannot tell "slow" from the word before it, so the tiles are aligned to EACH OTHER: each tile's speech-band spectrum (8 bands, 5 ms frames) over its phrase is matched to the mean of the others' within ±0.4 s of its estimate, four rounds, the median shift kept at zero (`consensusLags`); then all of them move together onto where their mean loudness rises (`templateOnset`, within ±0.3 s). Under three tiles: the sharpest loudness rise near each estimate (`refineOnset`). The wall's `.cut.json` records each tile's estimate, onset, `by` and its correlation with the rest (`r`), and the common `syncAnchor`. | +| `wall.clips` | `"spread"` (default): tiles from clips spread first to last. `"tail"`: the last `tiles` clips of the cut, in date order — group 1 is the earliest of them, the last group the latest. | +| `wall.exclusive` | `true`: the wall's clips are tiles only. They leave the run of clips (no segment, no chapter), so the counter, the tally and the ramp count the clips before the wall, and the wall condenses the repetition rather than repeating it. With fewer than 2 clips left outside the wall it is an error. A tile clip with no segment is cut from its window like any clip (`--no-network` holds). | | `yearStamp` | On the first clip of each year, the year large in the corner across from the counter for about a second. | **Where it is made.** Everything except the wall is inside each clip's own @@ -779,7 +784,9 @@ values in words that say which, and a montage beside `render.chrome` (the deck), **Named styles.** `montage-styles.mjs` holds the styles worth auditioning as merge patches (RFC 7386) on the manifest: `straight`, `flash-count`, -`accelerate`, `stutter`, `wall-finale`, `whip-years`. Each sets every montage +`accelerate`, `stutter`, `wall-finale`, `whip-years`, and `build-to-wall` +(whip cuts, a ramp from 3.5 s into the wall, a slow zoom, the tally, then an +exclusive tail wall of the latest 25 in synced groups 1,1,2,4,8,9 with years). Each sets every montage key, so one over another leaves exactly the second. umtool's take form lists them; from the terminal: diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -180,6 +180,7 @@ import { markPng, renderThumbnail, THUMB_MAX_BYTES } from "./brand-cards.mjs"; import { clipPhrase, cutStyleParts, locatePhrase, montageFont, montageOn, montageOverlayFilters, montagePieces, montagePiecesGraph, montageSplit, montageWindow, parseClipDate, planMontage, refineOnset, resolveMontage, + bandFeatures, consensusLags, templateOnset, validateMontage, wallComposeArgs, WALL_ENTRY, WALL_LEAD, WALL_TAIL, wallPlan, wallTileArgs, wallTileClips, whisperWords, } from "./montage.mjs"; import { resolveVideoDir } from "yt-dlp-transcript-common/lib/videoDir-server.mjs"; @@ -1475,21 +1476,60 @@ async function montageWallSource({ entry, M, render, provenance, local, opts }) } /** - * A synced tile's onset, refined against its sound (montage.mjs - * refineOnset): the speech band (high-passed at 200 Hz, 16 kHz mono) of - * ±0.6 s around the estimate, read once with ffmpeg. The estimate when no - * clear rise is found. + * `seconds` of a source's sound from `from` (raw-file seconds, may be + * negative), speech band (high-passed at 200 Hz), 16 kHz mono, as samples; + * silence where the file has none, so the excerpt is always that long. */ -async function refinedOnset(raw, est) { - const from = Math.max(0, est - 0.6); - const rate = 16000; +async function speechExcerpt(raw, from, seconds, rate = 16000) { + const at = Math.max(0, from); const { stdout } = await execFileP(FFMPEG, [ - "-nostdin", "-v", "error", "-ss", from.toFixed(3), "-t", "1.2", "-i", raw, + "-nostdin", "-v", "error", "-ss", at.toFixed(3), "-t", (seconds - (at - from)).toFixed(3), "-i", raw, "-vn", "-ac", "1", "-ar", String(rate), "-af", "highpass=f=200", "-f", "s16le", "-", ], { encoding: "buffer", maxBuffer: 1 << 24 }); - const samples = new Int16Array(stdout.buffer, stdout.byteOffset, Math.floor(stdout.length / 2)); - const r = refineOnset(samples, rate, est - from, { window: 0.4 }); - return r ? { at: from + r.at, rise: r.rise } : null; + const got = new Int16Array(stdout.buffer, stdout.byteOffset, Math.floor(stdout.length / 2)); + const out = new Int16Array(Math.round(seconds * rate)); + out.set(got.subarray(0, out.length - Math.round((at - from) * rate)), Math.round((at - from) * rate)); + return out; +} + +/** How far before and after its estimate a tile's sound is compared, seconds. */ +const ONSET_PRE = 0.8; +const ONSET_LEN = 2.4; +const ONSET_HOP = 0.005; + +/** + * Every synced tile's phrase onset, by id, on its raw file's clock. With + * three tiles or more: aligned to one another (montage.mjs consensusLags -- + * each tile's speech-band spectrum over its phrase matched to the mean of the + * others', within ±0.4 s of its estimate, the median shift kept at zero), so + * the crowd says it together; `by: "consensus"`, with the tile's correlation + * `r`. With fewer: the sharpest rise of loudness within ±0.4 s + * (refineOnset), `by: "rise"`, else the estimate, `by: "estimate"`. The + * estimate is whisper's word offset or the cue estimate (`via`). + */ +async function wallOnsets(tiles) { + const rate = 16000; + const out = new Map(); + const ex = []; + for (const t of tiles) ex.push(await speechExcerpt(t.raw, t.phrase.start - ONSET_PRE, ONSET_LEN, rate).catch(() => null)); + if (tiles.length >= 3 && ex.every(Boolean)) { + const feats = ex.map((x) => bandFeatures(x, rate, { hop: ONSET_HOP })); + const origin = Math.round((ONSET_PRE - 256 / rate) / ONSET_HOP); + const { lags, r } = consensusLags(feats, { origin, pre: 10, span: 160, search: Math.round(0.4 / ONSET_HOP) }); + // Then all of them together onto where their mean loudness rises. + const anchor = templateOnset(feats, lags, { origin, window: 0.3, hop: ONSET_HOP }); + const shift = anchor?.shift ?? 0; + tiles.forEach((t, i) => out.set(t.id, { + at: t.phrase.start + lags[i] * ONSET_HOP + shift, by: "consensus", r: Number(r[i].toFixed(2)), + })); + out.anchor = Number(shift.toFixed(3)); + return out; + } + tiles.forEach((t, i) => { + const r = ex[i] ? refineOnset(ex[i], rate, ONSET_PRE, { window: 0.4 }) : null; + out.set(t.id, r ? { at: t.phrase.start - ONSET_PRE + r.at, by: "rise" } : { at: t.phrase.start, by: "estimate" }); + }); + return out; } /** @@ -1560,9 +1600,10 @@ async function buildMontageWall({ M, entries, render, outDir, timeline, provenan M.cuts.set(id, src); } } - // Synced: each tile's onset refined against its sound (unless whisper's - // words placed it), and the tile cut to start WALL_LEAD before it. + // Synced: each tile's onset aligned to the others' (wallOnsets), and the + // tile cut to start WALL_LEAD before it. const sources = new Map(); + const onsets = w.sync ? await wallOnsets([...new Set(chosen)].map((id) => ({ id, ...M.cuts.get(id) }))) : null; for (const id of new Set(chosen)) { const c = M.cuts.get(id); if (!w.sync) { @@ -1573,13 +1614,13 @@ async function buildMontageWall({ M, entries, render, outDir, timeline, provenan continue; } const est = c.phrase.start; - const r = c.via === "words" ? null : await refinedOnset(c.raw, est).catch(() => null); - const onset = r ? r.at : est; + const o = onsets.get(id); + const onset = Math.min(c.cutB - 0.4, Math.max(c.cutA, o.at)); const from = Math.max(c.cutA, onset - WALL_LEAD); const to = Math.min(c.cutB, Math.max(onset + 0.4, c.phrase.end + (onset - est) + WALL_TAIL)); sources.set(id, { from, to, lead: onset - from, - sync: { estimate: Number(est.toFixed(3)), onset: Number(onset.toFixed(3)), via: c.via ?? null, refined: !!r, rise: r ? Number(r.rise.toFixed(1)) : null }, + sync: { estimate: Number(est.toFixed(3)), onset: Number(onset.toFixed(3)), via: c.via ?? null, by: o.by, r: o.r ?? null }, }); } const tiles = chosen.map((id) => { @@ -1619,6 +1660,7 @@ async function buildMontageWall({ M, entries, render, outDir, timeline, provenan Object.assign(record, { groups: plan.groups, groupBeats: plan.groupBeats, restart: plan.restart, leads: plan.leads }); } if (w.sync) { + if (onsets?.anchor != null) record.syncAnchor = onsets.anchor; record.sync = tiles.map((t) => ({ id: t.id, raw: t.raw, from: Number(t.from.toFixed(3)), ...sources.get(t.id).sync })); } await writeCutRecord(seg, { version: 1, id: WALL_ENTRY.id, montageWall: record }); diff --git a/umtool/report-to-video/montage.mjs b/umtool/report-to-video/montage.mjs @@ -1177,7 +1177,10 @@ function groupedWallComposeArgs({ tiles, plan, render, settings, first, last, en })); parts.push( `${as.join("")}amix=inputs=${as.length}:normalize=0:duration=longest,alimiter=limit=0.9,` + - `apad=whole_dur=${total},atrim=end=${total},` + + // Re-stamped by sample count before the fades: amix's output clock can + // run ahead of its samples when its inputs start late (an asplit feeding + // a long adelay), and a fade timed on that clock silences the wall. + `apad=whole_dur=${total},atrim=end=${total},asetpts=N/SR/TB,` + `afade=t=in:d=${DECLICK},afade=t=out:st=${exprNum(plan.seconds - DECLICK)}:d=${DECLICK}[a]`, ); return [ @@ -1278,5 +1281,190 @@ export function envelopeLag(a, b, maxLag) { return best; } +// ---- the crowd in unison: aligning every tile's phrase to the others' -------------------- + +/** In-place radix-2 FFT of `re`/`im` (length a power of two). */ +function fft(re, im) { + const n = re.length; + for (let i = 1, j = 0; i < n; i += 1) { + let bit = n >> 1; + for (; j & bit; bit >>= 1) j ^= bit; + j ^= bit; + if (i < j) { + [re[i], re[j]] = [re[j], re[i]]; + [im[i], im[j]] = [im[j], im[i]]; + } + } + for (let len = 2; len <= n; len <<= 1) { + const ang = (-2 * Math.PI) / len; + for (let i = 0; i < n; i += len) { + for (let k = 0; k < len / 2; k += 1) { + const wr = Math.cos(ang * k); + const wi = Math.sin(ang * k); + const ar = re[i + k + len / 2]; + const ai = im[i + k + len / 2]; + const xr = ar * wr - ai * wi; + const xi = ar * wi + ai * wr; + re[i + k + len / 2] = re[i + k] - xr; + im[i + k + len / 2] = im[i + k] - xi; + re[i + k] += xr; + im[i + k] += xi; + } + } + } +} + +/** The bands a phrase's sound is compared in, Hz: low voice to sibilants. */ +export const SPEECH_BANDS = Object.freeze([200, 400, 700, 1100, 1700, 2600, 4000, 6000, 8000]); + +/** + * The sound as log energy per speech band, every `hop` seconds over a + * 512-sample Hann window (32 ms at 16 kHz): frames × bands, each band less + * its own mean over the excerpt (so a louder or duller source compares the + * same). Frame k is centred at k·hop + 256/rate. + */ +export function bandFeatures(samples, rate, { hop = 0.005, size = 512, bands = SPEECH_BANDS } = {}) { + const H = Math.max(1, Math.round(hop * rate)); + const n = Math.max(0, Math.floor((samples.length - size) / H) + 1); + const hann = Float64Array.from({ length: size }, (_, i) => 0.5 - 0.5 * Math.cos((2 * Math.PI * i) / (size - 1))); + const edges = bands.map((f) => Math.min(size / 2, Math.round((f * size) / rate))); + const out = []; + const re = new Float64Array(size); + const im = new Float64Array(size); + for (let k = 0; k < n; k += 1) { + for (let i = 0; i < size; i += 1) { + re[i] = (samples[k * H + i] / 32768) * hann[i]; + im[i] = 0; + } + fft(re, im); + const row = new Float64Array(edges.length - 1); + for (let b = 0; b + 1 < edges.length; b += 1) { + let e = 0; + for (let j = edges[b]; j < Math.max(edges[b] + 1, edges[b + 1]); j += 1) e += re[j] * re[j] + im[j] * im[j]; + row[b] = Math.log10(e + 1e-10); + } + out.push(row); + } + const B = edges.length - 1; + for (let b = 0; b < B; b += 1) { + const m = out.reduce((acc, r) => acc + r[b], 0) / Math.max(1, out.length); + for (const r of out) r[b] -= m; + } + return out; +} + +/** Pearson correlation of two blocks of frames (rows of equal width). */ +function blockCorr(A, a0, B, b0, len) { + let sa = 0, sb = 0, saa = 0, sbb = 0, sab = 0, n = 0; + for (let f = 0; f < len; f += 1) { + const ra = A[a0 + f]; + const rb = B[b0 + f]; + if (!ra || !rb) continue; + for (let b = 0; b < ra.length; b += 1) { + const x = ra[b]; + const y = rb[b]; + sa += x; sb += y; saa += x * x; sbb += y * y; sab += x * y; n += 1; + } + } + if (!n) return -Infinity; + const cov = sab - (sa * sb) / n; + const va = saa - (sa * sa) / n; + const vb = sbb - (sb * sb) / n; + return va > 0 && vb > 0 ? cov / Math.sqrt(va * vb) : -Infinity; +} + +/** + * Every tile's phrase aligned to all the others' (a consensus, no reference + * needed): `feats[i]` are tile i's band frames with its estimated onset at + * frame `origin`; the template is the mean of the others as currently + * aligned, compared over `span` frames from `origin − pre`, and each tile's + * shift is searched within ±`search` frames; repeated `iterations` times. + * The common shift is then taken out (the median is 0), so on the whole the + * estimates' clock is kept and only the tiles' disagreement is removed. + * + * @returns {{ lags: number[], r: number[] }} frames, and each tile's correlation with the rest at its lag + */ +export function consensusLags(feats, { origin, pre = 10, span = 160, search = 60, iterations = 4 } = {}) { + const N = feats.length; + let lags = Array(N).fill(0); + let r = Array(N).fill(0); + if (N < 3) return { lags, r }; + const width = feats[0][0]?.length ?? 0; + const start = origin - pre; + const template = (skip) => { + const T = Array.from({ length: span }, () => new Float64Array(width)); + let n = 0; + feats.forEach((F, j) => { + if (j === skip) return; + n += 1; + for (let f = 0; f < span; f += 1) { + const row = F[start + lags[j] + f]; + if (row) for (let b = 0; b < width; b += 1) T[f][b] += row[b]; + } + }); + for (const row of T) for (let b = 0; b < width; b += 1) row[b] /= Math.max(1, n); + return T; + }; + for (let it = 0; it < iterations; it += 1) { + const next = []; + const rs = []; + for (let i = 0; i < N; i += 1) { + const T = template(i); + let best = { lag: lags[i], r: -Infinity }; + for (let L = -search; L <= search; L += 1) { + if (start + L < 0 || start + L + span > feats[i].length) continue; + const c = blockCorr(T, 0, feats[i], start + L, span); + if (c > best.r) best = { lag: L, r: c }; + } + next.push(best.lag); + rs.push(best.r); + } + const sorted = [...next].sort((a, b) => a - b); + const med = sorted[Math.floor(N / 2)]; + lags = next.map((l) => l - med); + r = rs; + } + return { lags, r }; +} + +/** + * Where the aligned tiles' phrase starts, in seconds from `origin`: the + * sharpest rise of their MEAN loudness (all bands, all tiles at their + * consensus lags) within ±`window` -- the mean of many takes of one phrase is + * a cleaner onset than any one of them. + */ +export function templateOnset(feats, lags, { origin, window = 0.3, hop = 0.005, before = 12, after = 10 } = {}) { + const N = feats.length; + const reach = Math.round(window / hop); + const loud = (f) => { + let acc = 0; + let n = 0; + feats.forEach((F, i) => { + const row = F[f + lags[i]]; + if (row) { + for (const v of row) acc += v; + n += 1; + } + }); + return n ? acc / n : 0; + }; + const env = new Map(); + const at = (f) => (env.has(f) ? env.get(f) : env.set(f, loud(f)).get(f)); + let best = null; + for (let f = origin - reach; f <= origin + reach; f += 1) { + let a = 0; + let b = 0; + for (let k = 1; k <= before; k += 1) a += at(f - k); + for (let k = 0; k < after; k += 1) b += at(f + k); + const rise = b / after - a / before; + if (!best || rise > best.rise) best = { f, rise }; + } + void N; + // `origin` is the frame CENTRED on the estimate; the rise peaks two hops + // before the frame centred on the onset (measured on synthetic takes, to + // the 5 ms hop). + return best ? { shift: (best.f - origin) * hop + 2 * hop, rise: best.rise } : null; +} + /** The wall's place in the cut, as an entry: what the chapters call it. */ export const WALL_ENTRY = Object.freeze({ type: "montage-wall", id: "montage-wall", title: "All together" }); diff --git a/umtool/report-to-video/montage.test.mjs b/umtool/report-to-video/montage.test.mjs @@ -19,7 +19,7 @@ import { montagePieces, montagePiecesGraph, montageWindow, normalisePhrase, parseClipDate, piecesFrames, planMontage, platformLabel, rampCap, rampCaps, resolveMontage, safeText, stutters, tallyMarks, timedText, validateMontage, wallComposeArgs, wallPlan, wallTileClips, whisperWords, wallGroups, wallBeats, wallFirstGap, montageSplit, - refineOnset, speechEnvelope, envelopeLag, WALL_SLIDE_FRAMES, + refineOnset, speechEnvelope, envelopeLag, WALL_SLIDE_FRAMES, bandFeatures, consensusLags, templateOnset, } from "./montage.mjs"; import { applyMontageStyle, MONTAGE_STYLE_NAMES, mergePatch } from "./montage-styles.mjs"; import { buildVideo, snap } from "./build-video.mjs"; @@ -925,6 +925,29 @@ test("refineOnset: the sharpest rise near the estimate, to the frame; null witho assert.ok(env[10] < -30 && env.at(-1) > -10); }); +test("consensusLags + templateOnset: takes of one phrase at different times line up, and land on its onset", () => { + const rate = 16000; + // A floor of noise, then two "syllables" (500 Hz, 900 Hz) from `on`; every estimate says 0.8 s. + const take = (on) => Int16Array.from({ length: 2.4 * rate }, (_, i) => { + const t = i / rate; + const noise = 300 * ((Math.sin(i * 12.9898) * 43758.5453) % 1); + const syl = (t >= on && t < on + 0.25) || (t >= on + 0.35 && t < on + 0.6); + return Math.round(noise + (syl ? 9000 * Math.sin(2 * Math.PI * (t < on + 0.3 ? 500 : 900) * t) : 0)); + }); + const origin = Math.round((0.8 - 256 / rate) / 0.005); + for (const ons of [[1.05, 1.0, 1.12, 0.98, 1.07], [0.6, 0.65, 0.7, 0.62, 0.66], [0.9, 0.93, 0.95, 0.87, 1.1, 0.91]]) { + const feats = ons.map((o) => bandFeatures(take(o), rate)); + assert.equal(feats[0][0].length, 8); + const { lags, r } = consensusLags(feats, { origin, pre: 10, span: 160, search: 80 }); + assert.equal([...lags].sort((a, b) => a - b)[Math.floor(lags.length / 2)], 0, "the median shift is zero"); + for (const x of r) assert.ok(x > 0.9, `r ${x}`); + const a = templateOnset(feats, lags, { origin }); + ons.forEach((o, i) => assert.ok(Math.abs(0.8 + lags[i] * 0.005 + a.shift - o) <= 0.0051, `${ons}: take ${i}`)); + } + // Two takes: no consensus, no shift. + assert.deepEqual(consensusLags([[], []], { origin: 0 }).lags, [0, 0]); +}); + test("envelopeLag: a shifted copy is found at its shift", () => { const a = Array.from({ length: 200 }, (_, i) => Math.sin(i / 7) + (i > 80 && i < 120 ? 3 : 0)); const b = [...Array(9).fill(a[0]), ...a.slice(0, 191)]; @@ -980,7 +1003,10 @@ test("render: today's wall with its new keys spelled out at their defaults is by await buildVideo({ manifestPath: a.manifestPath, opts: { noNetwork: true } }); await buildVideo({ manifestPath: b.manifestPath, opts: { noNetwork: true } }); const md5 = (f) => spawnSync("md5sum", [f]).stdout.toString().split(" ")[0]; - assert.equal(md5(path.join(a.root, "out", "demo.mp4")), md5(path.join(b.root, "out", "demo.mp4"))); + // On a mismatch, say which segment differs. + const segs = ["s1", "s2", "s3", "s12", "montage-wall"].map((id) => `sourced/segments/${id}.mp4`); + const which = segs.filter((f) => md5(path.join(a.root, "out", f)) !== md5(path.join(b.root, "out", f))); + assert.equal(md5(path.join(a.root, "out", "demo.mp4")), md5(path.join(b.root, "out", "demo.mp4")), `differs: ${which.join(", ") || "only the final"}`); } finally { await rm(a.root, { recursive: true, force: true }); await rm(b.root, { recursive: true, force: true }); @@ -1003,12 +1029,14 @@ test("render: build-to-wall over twelve clips -- three run, nine are tiles in gr const wall = JSON.parse(await readFile(path.join(seg, "montage-wall.cut.json"), "utf8")).montageWall; assert.deepEqual(wall.tiles, ["s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12"]); assert.deepEqual(wall.groups, [1, 1, 2, 5]); - // Every onset refined from the cues' 2.0 to the sound's 2.25, to within 10 ms. + // Every onset moved from the cues' 2.0 to the sound's 2.25 (the tiles agree, and their + // mean loudness rises there), to within 15 ms. for (const t of wall.sync) { assert.equal(t.estimate, 2); - assert.equal(t.refined, true, t.id); - assert.ok(Math.abs(t.onset - 2.25) <= 0.01, `${t.id} ${t.onset}`); + assert.equal(t.by, "consensus", t.id); + assert.ok(Math.abs(t.onset - 2.25) <= 0.015, `${t.id} ${t.onset}`); } + assert.ok(Math.abs(wall.syncAnchor - 0.25) <= 0.015, `anchor ${wall.syncAnchor}`); // In each tile's own file the phrase starts its lead in (measured on the tile's sound). for (const id of ["s4", "s8"]) { const pcm = spawnSync("ffmpeg", ["-v", "error", "-i", path.join(seg, "montage-wall", `${id}.mp4`), "-ac", "1", "-ar", "16000", "-f", "s16le", "-"], { maxBuffer: 1 << 24 }).stdout; @@ -1023,6 +1051,9 @@ test("render: build-to-wall over twelve clips -- three run, nine are tiles in gr const tile = `${l.w - 8}:${l.h - 24}:${l.x + 4}:${l.y + 4}`; assert.ok(luma(r.out, start + plan.appearFrames[8] - 2, tile) < 40, "empty before its group"); assert.ok(luma(r.out, start + plan.appearFrames[8] + 6, tile) > 100, "filled on its beat"); + // Heard all through: on each group's beat and at the final one. + const level = (from) => Number(String(spawnSync("ffmpeg", ["-nostdin", "-ss", from.toFixed(3), "-t", "0.3", "-i", path.join(seg, "montage-wall.mp4"), "-vn", "-af", "volumedetect", "-f", "null", "-"]).stderr).match(/mean_volume: (-?[\d.]+)/)[1]); + for (const b of [...wall.groupBeats, wall.beat]) assert.ok(level(b) > -40, `silent at ${b}`); // Chapters: three clips and the wall; verify-build agrees. const ch = spawnSync("ffprobe", ["-v", "error", "-show_chapters", "-of", "json", r.out]); assert.equal(JSON.parse(String(ch.stdout)).chapters.length, 4);