yeti labs

field note 014 · 2026-10-29 · infra, timing

a muted tv and a speaker can stay 30ms apart, if you never trust one clock read

we put a 24/7 channel of fan-taped broadcasts from the 80s and 90s on our homelab box, picture on a chromecast and sound on a sonos, with the tv muted. syncing them is subtraction. the work was knowing where each device actually is, to better than the error we were fixing.

held within
~30ms
one tv clock read
±~100ms
reads per position
5
checks before a fix
2

the setup

the channel comes out as http live streaming (hls): a playlist of short video segments. each segment carries a program date-time (pdt), a wall-clock timestamp for its first frame. if we know which pdt each device is playing right now, the gap between them is one subtraction. so a small service sits between the channel and both devices and serves each its own copy of the same segments.

the tv side: the chromecast gets a byte-for-byte mirror of the playlist. its default receiver reports a currentTime that starts at 0 on the first segment of the first playlist it loads. we serve that playlist, so we read that segment's pdt on the way out and keep it as the anchor. tv position = anchor + currentTime. we checked: it started at 58.27s on a segment that began at 58.225s.

the sonos side: it gets an mp3 we decode from the same segments, and we record the pdt of every sample we hand the encoder. a sonos playing a radio stream only reports whole seconds played, which is useless at this scale. so we poll it every 15ms and note the moment the second ticks over, which pins its position to about 20ms. we do that for five ticks and take the median.

first, we were wrong

our first mirror tidied up the playlist on the way through, and the receiver errored on it. now nothing changes except the host.

then the tv stalled or errored at every tape boundary. the channel server was passing each tape's own format straight through, and segments were missing the headers a decoder needs to start. everything now goes out normalized to 640x480 h.264 with 48k aac audio, which suits standard-definition 4:3 tapes anyway. fwiw, the server's api quietly resets that normalize setting to off on any profile update, so we only touch it in the ui.

one tv clock read is as noisy as the drift we correct

size of each timing error in the loop, in milliseconds (approximate)

corrections only past 100ms050100msone chromecast read±~100msnoise in a sync check±~80msone timed sonos tick~20mswhere the two sit~30msafter median-of-five and two-check agreement
source: yeti labs sync service, comments and notes from tuning ityeti labs · field note 014

the loop

a single chromecast status read jitters by ~100ms. that's the same size as our correction threshold, so one read on its own could trigger a fix for drift that isn't there. we take five reads 0.3s apart, turn each into "when was currentTime zero," and use the median.

the loop sleeps 8s, then spends a few seconds sampling both devices, so they get compared about every 15s. anything under 100ms is treated as noise (we've seen about ±80ms of it). past that, it still waits for the next check to agree: same direction, also past 100ms. then it corrects by the average of the two, either skipping the audio ahead or holding it with silence.

rulevalue
chromecast reads per position5, 0.3s apart, median
sonos second-ticks per position5, polled every 15ms, median
ignore drift under100ms
fix drift when2 checks in a row agree
restart the audio whensonos is >5s ahead or >60s behind
sonos play-to-sound2.1s (measured)
reload a stuck tv after20s

two smaller rules matter more than they look. a correction replaces any pending one and never stacks, because a fresh measurement already includes whatever has played. and the loop won't measure again until the speaker has played past the last correction, or it would correct the same drift twice.

the sonos takes 2.1s from "play" to sound, so its stream starts 2.1s ahead of the tv's position. anything way off restarts the audio, because a long hold is just as quiet as a restart and the restart lands closer. what's left (tv display lag, speaker output lag, encoder delay) is one constant we set by ear. a tv stuck buffering or errored for 20s gets reloaded.

one honesty note: the ~30ms comes from our notes after tuning. we haven't logged a full day of drift yet, and the loop deliberately leaves anything under 100ms alone.

what we'd do instead

  1. measure how noisy each clock is before building the controller. without the median of five, the loop chases noise.
  2. serve the stream yourself when you can. owning the playlist is what gave us the tv's anchor, and owning the encoder gave us a pdt for every audio sample.
  3. log the error for a day before quoting a number. that's next on our list.
got two systems that need to agree on what time it is?

we'll measure both clocks before we trust either.

talk to the agent →