Reputation: 607
I tried to implement GameKit
to play songs synchronously on several devices over bluetooth/wifi. Still I always have 0.1-0.5 sec latency. Think that such synchronisation is trivial. I found BM receiver metronome that implements what I want, sound is played really synchronously.
I'm using GKSendDataReliable
and sending 1 small packet with rhythm. Done all things using this tutorial here.
I've googled a lot but can't find the answer and/or my bottleneck. Would appreciate any suggestions/approaches. Maybe some tutorials?
Upvotes: 0
Views: 448
Reputation: 543
how many devices do you use? I assume it's server-client scheme. Here's what I would do (it may not work but you are asking for suggestions/approaches), very rough algorithm:
-server sets up a timer and sends its value to clients using PING packet, remembering it per client
-client receives PING packet, and sends response packet
-server gets the response packet, checks the time and stores the resulting delta somewhere (in a vector)
-server sends more PING packets and gets more time deltas
-when server has enough data, it calculates average ping times (CLIENTX_TIME) and chooses the biggest one (BIGGEST_TIME)
-server sends START packet to all the clients, packet has some additional info saying START PLAYING in XX_TIME
-server starts playing music after BIGGEST_TIME
-clients get the START packets and start playing music after XX time, where XX is calculated per player (so for slowest client it will be 0, for other it will be BIGGEST_TIME-CLIENTX_TIME)
-this process continues over and over, everytime you want to play something, you do it in advance
thing is that you will NEVER be able to get everything synced all the time - this is the nature of the network unfortunately ;)
Upvotes: 1