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.
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.