Live data from Hacker News

Show HN: Beatsync – perfect audio sync across multiple devices

github.com

21–30 of 135 posts

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#21
post #4

How does it deal with the audio ring buffers on the various devices? Does it just try to start them all at the same time, or does it take into account the sample position within the buffer?

Great question! There's two steps:

First, I do clock synchronization with a central server so that all clients can agree on a time reference.

Then, instead of directly manipulating the hardware audio ring buffers (which browsers don't allow), I use the Web Audio API's scheduling system to play audio in the future at a specific start time, on all devices.

So a central server relays messages from clients, telling them when to start and which sample position in the buffer to start from.

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#22

I primarily built this for group in-person listening, and that's what the spatial audio controls are for. But what is interesting is that since it only requires the browser, it works across the internet as well. You can guarantee that you and someone else are listening to the same thing even across an ocean. Someone brought up the idea of an internet radio, which I thought was cool. If you could see a list of all the…

> You can guarantee that you and someone else are listening to the same thing even across an ocean. How can you guarantee that? NTP fails to guarantee that all clocks are synced inside a datacenter, let alone across an ocean (Did not read the code yet) EDIT: The wording got me. "Guarantee" & "Perfect" in the post title, and "Millisecond-accurate synchronization" in the README. Cool project!

More, the speed of light puts a hard cap on how simultaneous you can be. Wolfram Alpha reckons New York to London is 19ms in a vacuum, more using fibre.

Going off on a tangent: Back in the days of Live Aid, they tried doing a transatlantic duet. Turns out it’s literally physically impossible because if A songs when they hear B, then B hears A at least 38ms too late, which is too much for the human body to handle and still make music.

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#23
post #4

How does it deal with the audio ring buffers on the various devices? Does it just try to start them all at the same time, or does it take into account the sample position within the buffer?

Great question! There's two steps: First, I do clock synchronization with a central server so that all clients can agree on a time reference. Then, instead of directly manipulating the hardware audio ring buffers (which browsers don't allow), I use the Web Audio API's scheduling system to play audio in the future at a specific start time, on all devices. So a central server relays messages from clients, telling them…

Interesting. Feels like this might still have some noticeable tens-of-millisends latency on Windows, where the default audio drivers still have high latency. The browser may intend to play the sound at time t, but when it calls Windows's API to play the sound I'm guessing it doesn't apply a negative time offset?

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#24
Very cool! As someone who doesn't know much about the topic, I'm surprised that "millisecond-level accuracy" is enough. I would have imagined that you need to be accurate down to some fairly small multiple of the sample rate to avoid phasing effects.

Do you have any interesting insight into that question?

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#25
post #4

How does it deal with the audio ring buffers on the various devices? Does it just try to start them all at the same time, or does it take into account the sample position within the buffer?

Great question! There's two steps: First, I do clock synchronization with a central server so that all clients can agree on a time reference. Then, instead of directly manipulating the hardware audio ring buffers (which browsers don't allow), I use the Web Audio API's scheduling system to play audio in the future at a specific start time, on all devices. So a central server relays messages from clients, telling them…

So it doesn't need to use the microphone? I guess from the "works across the ocean" comment and based on this description. I would have thought you would listen to the mic and sync based on surrounding audio somehow but it's good to know that it's not needed.

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#26

Very cool! As someone who doesn't know much about the topic, I'm surprised that "millisecond-level accuracy" is enough. I would have imagined that you need to be accurate down to some fairly small multiple of the sample rate to avoid phasing effects. Do you have any interesting insight into that question?

Sound travels at a speed of ~1 foot/millisecond

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#27

Very cool! As someone who doesn't know much about the topic, I'm surprised that "millisecond-level accuracy" is enough. I would have imagined that you need to be accurate down to some fairly small multiple of the sample rate to avoid phasing effects. Do you have any interesting insight into that question?

Yeah the threshold is pretty brutal, but it is enough. Experimentally, I'd say you need under 2-3ms but even at 1ms you can start to hear some phase differences.

Most of the time, I think my synchronization algorithm is actually sub-1ms, but it can be worse depending on unstable network conditions.

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#28

Earlier quoted context omitted.

Great question! There's two steps: First, I do clock synchronization with a central server so that all clients can agree on a time reference. Then, instead of directly manipulating the hardware audio ring buffers (which browsers don't allow), I use the Web Audio API's scheduling system to play audio in the future at a specific start time, on all devices. So a central server relays messages from clients, telling them…

So it doesn't need to use the microphone? I guess from the "works across the ocean" comment and based on this description. I would have thought you would listen to the mic and sync based on surrounding audio somehow but it's good to know that it's not needed.

Yup no microphone. It's all clock sync

Re: Show HN: Beatsync – perfect audio sync across multiple devices

#29

Very cool! As someone who doesn't know much about the topic, I'm surprised that "millisecond-level accuracy" is enough. I would have imagined that you need to be accurate down to some fairly small multiple of the sample rate to avoid phasing effects. Do you have any interesting insight into that question?

[deleted]
Post reply on HN