Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronizing Tone.js audio across multiple devices #1221

Open
MattTheRed opened this issue Dec 15, 2023 · 3 comments
Open

Synchronizing Tone.js audio across multiple devices #1221

MattTheRed opened this issue Dec 15, 2023 · 3 comments

Comments

@MattTheRed
Copy link

The feature you'd like

This isn't so much a feature request, but a request for advice on how to go about approaching an app using Tone.js.

I'm attempting to build an interactive UI where multiple participants can each play an instrument on their own device and play "in time" with each other. I'm going for a similar effect to: https://plink.in/

To accomplish this using Tone.js I believe I would have to:

  • Use websockets for low latency communication between clients
  • Somehow schedule each browser's Tone class to start at the same time (Here's a naive attempt at doing this: https://codepen.io/mattthered/pen/VwpLdvp)
  • Schedule notes to be played slightly in the future and publish them as events to all clients
  • Solve the "clock skew" problem (every device has a slightly different local time) and figure out the offset between a given client's local time VS the server's time and apply that offset to Tone.js (I think I may be able to use the new timing-object, timing-provider and timingsrc libraries which are polyfills for their respective WC3 proposals; Or a library like clockskew)
  • Periodically re-sync each client as their tempos drift

Any advice for how you might go about solving this problem with Tone.js? I know you guys have an approach to re-sync timing periodically to achieve a fixed tempo.

https://codepen.io/mattthered/pen/VwpLdvp

Any alternatives you've considered
N/A

Additional context
N/A

Feature Requests will eventually be closed if inactive
Feel free to close this as an issue since this is not an actual feature request.

@chrisguttandin
Copy link
Contributor

Hi @MattTheRed, I'm the author of the timing* libraries you mentioned above. This question actually comes up quite often which is why I made an attempt to create a demo for it.

https://chrisguttandin.github.io/tonejs-synchronization-demo/

The source code is available here. The JavaScript code is probably the most interesting bit.

I'm not entirely sure though if this is most efficient way to synchronize Tone.js to an external clock. I would be happy to hear your thoughts.

@MattTheRed
Copy link
Author

Woah, thanks @chrisguttandin! This is great!

Going to play with this and see what I can whip up.

@n-1-k-0-l-a-y
Copy link

Hi @MattTheRed, I'm the author of the timing* libraries you mentioned above. This question actually comes up quite often which is why I made an attempt to create a demo for it.

https://chrisguttandin.github.io/tonejs-synchronization-demo/

The source code is available here. The JavaScript code is probably the most interesting bit.

I'm not entirely sure though if this is most efficient way to synchronize Tone.js to an external clock. I would be happy to hear your thoughts.

thx! 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants