- Home /
AudioClip sync across a network: help needed!
Hi!
I'm networking iPhones, iPads and laptops (7 machines) through wifi for musical purposes. To achieve sync, I'm manualy synching a click AudioClip on each device so that it matches the server's. This is tedious... I have tried automating the sync with the following code :
function SyncPlay(offset:int)
{
networkView.RPC ("Play", RPCMode.Others,offset);
audio.Play(offset);
}
@RPC
function Play(offset:int, info : NetworkMessageInfo)
{
var timeInTransit : float = Network.time-info.timestamp;
Debug.Log("timeInTransit : "+timeInTransit);
var newOffset : int = offset - 44100.0*timeInTransit;
Debug.Log("newOffset : "+newOffset);
audio.Play(newOffset);
}
Which kind of works, except it needs an adjustment of over 1000 samples to be accurate enough for my purposes.
Which would be fine, but: this offset adjustment varies from machine to machine. If the iPad is the server, and sends the RPC to a mac, one value. If the mac is the server, and sends the RPC to the iPad, another. iPad to iPhone is yet another value. Plus, sync is never perfect : +-5 miliseconds, tested by repeatedly synching in the same conditions.
Any ideas? The solution I can see now is to first manualy calibrate each device, and to store the adjustment value in case one needs resync (sync cannot be perfectly kept for more than 20 minutes. Minute phasing occurs between the clips...)
I'd be grateful if anyone could suggest a better solution!
Cheers,
Gregzo