commit fc2c16ee4dd93a26a42c86edcacedc84ce4ca858
parent 2655e4650ffc1a6b882edcb543f1fc4acb305ccd
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 21:44:20 -0500
common: the clock's fit follows a drifting stream -- one segment, not a step every anchor
Measured on v6w89mk (a scratch copy; the real audio.mp3 and saved video
read): the saved video runs 0.0613 % slow against the audio download -- 0 s
at 2:30, +4.69 s at 2:10:27, a straight line. The first fit took every 300 s
anchor for a step (a one-anchor run cannot say it drifts), refined 175 more
anchors and took 505 s to find one segment. A second anchor now joins a
one-anchor run within tolerance + maxRate (1e-3 s/s) x the time between them,
and a run of two over a minute has a slope: 30 anchors, 112 s, one segment
(rate 6.13e-4, residual 19.7 ms). A 13.1 s step still splits.
A map that is not ok also says its fallback (the quote check per clip;
re-transcribing from the saved video).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/common/lib/recordingClock-server.ts b/common/lib/recordingClock-server.ts
@@ -345,6 +345,14 @@ export async function measureRecordingClock(opts: {
};
if (opts.write !== false) await recordingClockSidecar.write(opts.videoDir, clock);
log(` ⏱ clock ${opts.write !== false ? `→ ${CLOCK_FILE}` : "(not written)"}: ${describeClock(clock)}`);
+ if (!clock.ok) {
+ // The fallback (lane one-clock, part 4) is a transcript made from the saved
+ // video itself -- one file, one clock -- and is not started from here.
+ log(
+ " ⏱ the map cannot be trusted: windows are cut on its best guess and said NOT certain — " +
+ "check their quotes (umtool quote-check); re-transcribing from the saved video is the fallback.",
+ );
+ }
return clock;
}
diff --git a/common/lib/recordingClock.mjs b/common/lib/recordingClock.mjs
@@ -36,7 +36,7 @@ export const CLOCK_VERSION = 1;
/**
* @typedef {{ sampleRate: number, probeSeconds: number, searchSeconds: number, everySeconds: number,
* minScore: number, minPeakRatio: number, tolerance: number, minGapSeconds: number, refinePerGap: number,
- * maxRefinePasses: number, maxRms: number, minAnchors: number, minUsableShare: number }} ClockParams
+ * maxRefinePasses: number, maxRate: number, maxRms: number, minAnchors: number, minUsableShare: number }} ClockParams
*/
/**
@@ -67,6 +67,11 @@ export const CLOCK_DEFAULTS = Object.freeze({
refinePerGap: 7,
// Passes of refinement.
maxRefinePasses: 4,
+ // The steepest drift (seconds per second) one segment may have: two sound
+ // cards' clocks, or a stream resampled a hair off. Measured 6.13e-4 on
+ // v6w89mk (0 s at 2:30, +4.69 s at 2:10:27). A second anchor joins a
+ // one-anchor run within tolerance + this × the time between them.
+ maxRate: 1e-3,
// The fitted map is `ok` only under this RMS residual.
maxRms: 0.05,
// ...with at least this many usable anchors, this share of those measured.
@@ -276,12 +281,12 @@ export function anchorTimes(duration, { extra = [], ...rest } = {}) {
// ---- the fit -----------------------------------------------------------------
-/** Least squares offset = a + b·(t − t0) over the points; rate 0 for a short run. */
+/** Least squares offset = a + b·(t − t0) over the points; rate 0 for a run too short to say. */
function fitLine(points) {
const n = points.length;
const t0 = points[0].at;
const span = points[n - 1].at - t0;
- if (n < 3 || span < 120) {
+ if (n < 2 || span < 60) {
const sorted = points.map((p) => p.offset).sort((a, b) => a - b);
const med = sorted[Math.floor((n - 1) / 2)];
return { t0, offset: med, rate: 0 };
@@ -331,7 +336,10 @@ export function fitClock(anchors, opts = {}) {
continue;
}
const line = fitLine(run);
- if (Math.abs(p.offset - lineAt(line, p.at)) <= o.tolerance) {
+ // One anchor so far says nothing of drift: the next joins it within the
+ // drift a segment may have; after that, the run's own line decides.
+ const allowed = run.length === 1 ? o.tolerance + o.maxRate * Math.abs(p.at - run[0].at) : o.tolerance;
+ if (Math.abs(p.offset - lineAt(line, p.at)) <= allowed) {
run.push(p);
continue;
}
diff --git a/common/lib/recordingClock.test.ts b/common/lib/recordingClock.test.ts
@@ -131,6 +131,26 @@ test("a drift is one segment with a rate, and the map follows it", () => {
assert.ok(Math.abs(clockOffsetAt(clock, 1000).offset - (1.6 + rate * 1000)) < 1e-4);
});
+test("a stream that drifts 0.06 % (v6w89mk, 6 Nov) is ONE segment from its sparse first anchors", () => {
+ // Measured: 0 s at 150 s, +4.69 s at 7827 s; the first pass anchors every 300 s.
+ const rate = 6.128e-4;
+ const anchors = [150, 450, 750, 1050, 1350, 1650, 1950, 4350, 7827].map((at) => ({
+ at,
+ offset: Math.round((rate * (at - 150) + (at % 2 ? 0.02 : -0.02)) * 1e4) / 1e4,
+ ok: true,
+ }));
+ const fit = fitClock(anchors);
+ assert.equal(fit.segments.length, 1, JSON.stringify(fit.segments));
+ assert.equal(fit.ok, true, fit.why);
+ assert.ok(Math.abs(fit.segments[0].rate - rate) < 2e-5, String(fit.segments[0].rate));
+ const clock = clockOf(fit);
+ // c22's span (cue 4324.6): +2.56 s on the saved video.
+ assert.ok(Math.abs(clockOffsetAt(clock, 4324.6).offset - 2.56) < 0.05, String(clockOffsetAt(clock, 4324.6).offset));
+ // A real step still splits: 13.1 s is no drift.
+ const stepped = fitClock([...anchors.slice(0, 4), ...[2250, 2550, 2850].map((at) => ({ at, offset: 13.1 + rate * at, ok: true }))]);
+ assert.equal(stepped.segments.length, 2);
+});
+
test("one anchor that disagrees between two that agree is an outlier, not a step", () => {
const anchors = [
{ at: 100, offset: 2, ok: true },