Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gregzo · Apr 20, 2012 at 11:08 AM · audionetworksynchronizing

Synching audioclips over a network - why is this not working?

Hi to all! Trying to get a clip to play in sync on two networked devices.

Here's my script:

 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);
 }

I'm launching SyncPlay(44100) from a GUI button on a mac (which is the server), the connected device is an iPad. timeInTransit and newOffset Debug show absolutely coherent values (.1 s, newOffset 33000 for example), but the audio is not in sync (the server plays about .1s early).

Any ideas? Thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Apr 20, 2012 at 11:25 AM 0
Share

Try using ulong (UInt64) ins$$anonymous$$d of int (Int32).

avatar image gregzo · Apr 20, 2012 at 11:44 AM 0
Share

ulong cannot be used as a RPC param... tried to type newOffset as ulong anyway, no difference. Sync is nearly ok now that I've set DSPBufferSize to best latency, but it is not perfect. I get variations of about .05 seconds...

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gregzo · Apr 20, 2012 at 12:49 PM

Got it, yippee!!!

1) Project settings > Quality > vSync off 2) Application.targetFrameRate = 30; (in my case, just to make sure the frame rate on the server is as close as possible to the device's) 3) Add a yieldForEndOfFrame befor playing but after the RPC call:

 function SyncPlay(offset:int)
 {
     networkView.RPC ("Play", RPCMode.Others,offset);
     yield WaitForEndOfFrame;
     audio.Play(offset);
 }

4) Might still need a little adjustment in the Play function. In my case,

 var newOffset : int = offset - 44100.0*timeInTransit -256;

gives a perfect result. 256 happens to be the DSP buffer size... need more testing before I confirm the link.

Sync is now stable, happiness!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Apr 20, 2012 at 12:56 PM 0
Share

Good to know. Please confirm the DSP buffer size :)

avatar image gregzo · Apr 20, 2012 at 01:22 PM 0
Share

After further testing, I can't get it to sync without setting the buffer size to best latency (which gives a bufferLength of 256, and numBuffers 4).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UNET: Flicker when a client moves a non-player object using another non-player-object 1 Answer

Animation state Synchronization in Multiplayer 1 Answer

Record and play audio-edits in-game 1 Answer

Networked Audio Listeners 2 Answers

Best way to transfer audio clips? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges