downbeat
Put a room full of phones on a table. Every one of them plays the same song at the same moment, with no echo and no “mine is a bit behind”. It sounds like one big speaker. To join, you scan a QR code and tap once.
I still find this funny: two phones lie next to each other on my table, and to keep them together every bit of audio travels to a Cloudflare data centre and back before it plays. They end up within about two thousandths of a second of each other.




Why not a Spotify Jam?
A Jam is a shared queue. Everyone can add songs, but the music plays from one device. When several phones do play at once, nothing keeps them in sync, and Spotify's forums are full of people hearing each other off the beat. Every listener also needs Premium. “All our phones as one speaker” is what people expect a Jam to be, and it isn't.
With downbeat, the host's Mac plays anything, Spotify included, and every phone in the room becomes a speaker for it. Joining is a QR code and a six-letter room code, and a guest only needs a browser tab.
The idea
Streaming audio to a dozen phones and hoping they stay together doesn't work. One network hiccup and a phone is behind for good. So downbeat sends the audio to every phone before it is due, and then the room only has to agree on one thing: the time. Clocks can be made to agree very precisely. Audio streams can't.
No phone gets a start time until every phone has said it has decoded the audio and is ready. After that, playback is just “play sample N at time T”, and the network can be as bad as it likes, as long as the clock is right.
Mac Core Audio tap, original muted Opus 48 kHz · 20 ms packets · ~110 kbit/sDurable Object relays the audio over WebSockets and is the room's time serverevery phone decodes ahead, then plays sample N at room time T
Through Cloudflare and back
The backend is one Cloudflare Worker and one Durable Object. On the Mac, a small Swift program uses a Core Audio process tap to capture whatever is playing. It mutes the real output at the same time, so the Mac plays the song back through downbeat, in step with the phones. The audio goes out as Opus: 48 kHz, a packet every 20 milliseconds, about 110 kbit/s. The Durable Object sends it on to every phone over WebSockets and is also the room's time server.
A D1 database records who owns a room, so two hosts can't fight over one, and an hourly job removes old sessions. All of it runs on your own Cloudflare account, inside the free tier. No audio touches anyone else's servers.
Getting the clocks to agree
Each phone keeps asking the Durable Object for the time and only keeps the answers that came back fastest. A slow answer hides how uneven the network was, so the fast ones are the trustworthy ones. Cloudflare helps in two ways. It freezes its clock between I/O, so the timestamp taken when a message arrives is exactly fresh. And since every phone reads the same server clock, an error in that clock is the same for everyone and cancels out.
The crystals in two phones still tick at slightly different speeds, a few parts per million, which would pull them a millisecond apart every minute or two. So downbeat keeps adjusting the playback speed by a few cents of pitch, far too little to hear. In the browser, decoded audio goes into a shared-memory ring that the audio thread reads directly, so a stuttering page can't interrupt the sound.
Measured
Against the live deployment, with three clients running the real clock and playback code:
clock agreement between phones ~0.5 ms
playback spread, 4 minutes 2.4 ms, flat
long-run drift 0.0 ms
late packets over a 4-minute song 0 of ~11,980These numbers are for the software. The room is a different story: sound travels about 34 cm per millisecond, so two speakers three metres apart are already about 9 ms apart, whatever the code does.
Status
It works end to end, both playing files and capturing live audio, on my own Cloudflare account. The code is on GitHub.