Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 drHogan · Apr 14, 2016 at 08:01 PM · audiounity5soundaudiosourcesync

Sample-precise sync on multiple audio sources ?

Hi guys, I am making a sort of augmented reality dj machine with unity+vuforia.

I basically have 4 instruments, one audio source per each, and swapping in different loops according to the markers shown in front of the camera. To work nicely they need to be synced as precisely as possible (all the loops are the same lenght, and only one loop per instrument can be played at the same time). I keep a silenced audiosource with one of the loops (so that it has the right lenght) looping endlessly as a reference, so that whenever a new loop is added it starts from the exact same point, therefore giving an illusion of "skill" for the user (i basically just sync each new loop for him).

I am going crazy because of the syncing exactly. I tried the most basic approaches based on time (newLoop.time = refTrack.time) then i moved to the timeSamples to make it more precise. Still something is wrong. (Latency is set to best latency and the files are uncompressed Wavs).

I use a function with ayield return new WaitForFixedUpdate(); called from a StartCoroutine when a new loop has to be played and synced, and I set the audioSourcesvelocityUpdateMode = AudioVelocityUpdateMode.Fixed; In my mind it looks like the most logical way to make sure it happens all at the "same time".

Right after the syncing I print the timeSample value of the ref track and the loop to sync and it looks all fine, they show the same timeSample stamp

 switch (track) { 
     case 0 : drum.Play();
     drum.timeSamples = referenceSync.timeSamples; 
     drum.volume = 1f; 
     Debug.Log("Ref "+referenceSync.timeSamples); 
     Debug.Log("Drum "+drum.timeSamples);
     break;
  }

then, checking on a debug on screen, or even just on the inspector in a public variable, several times they are not. They tend to have an error offset of almost fixed values, that make me feel like it's frame based (470 or 940 usually, but sometimes i ahve some variantions too).

The same identical problem i have in the editor, but also in the Android build. Does anybody have any idea on what is the cause for such a weird behavior and what am I doing wrong?

Thanks in advance, cheers, H

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jerichaosymphony · Aug 05, 2016 at 03:35 AM

AudioSettings.dspTime this is the autio time in seconds based on actual samples heard.

previously i thought:

Im doing the same and AFAIK there is no Time.time samples equivalent, i was thinking of using time.time converted to 44100 to run audio, or system time from the cpu because that is pretty accurate... also it's possible to count the buffers perhaps on the sound card because unity has access to that. perhaps to loop a 44100 long audio file and count num time plays and its position could work, i dont know whic solution is best. did you find what your technical issue was?

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

[Unity5] AudioSource PlayOneShot gives "Ran out of virtual channels" 0 Answers

How to get decibel's value of game's sound? 0 Answers

AudioSource won't play 2 Answers

Can you play a sound at a certain point (time) in the file? 1 Answer

How can I make Audio Reverb Zones effect only certain sounds? 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