- Home /
Audio start time uncertainty
Hi,
I'm trying to write a game for my project, I'm doing it on Unity Android. My problem is that I want to play an audio in every second, but when I recorded the sound and analyzed it I found that there is some uncertainty in every audio's start time (stdev: 0.035 sec). My main purpose is to give a pulse sound at the exact start of the game, this repeated sound is just a control for me that I can do it.
I used Fixedupdate function to play the sound in every 20th update
I used a very short .wav file (should I use mp3 instead?)
I recorded the framerate too, but have no found any statistical connection between the uncertanty and the framerate
If I adjust the fixed time step form 0.05 to 0.01 the deviation remains
I set the audio priority to max
I'm not sure that whether the time handling or the play causes this uncertainty. Any clue or advise?
Do not use FixedUpdate for that purpose. FixedUpdate is meant to be used for Physics interactions. Even fixed update are not 'fixed'.
Answer by luizgpa · Jan 19, 2012 at 06:49 PM
This happens because the way Unity uses FixedUpdate (see more here)
You could make the clip length exactly 1 second and play it looped. This way you won't have play it again.
Answer by Agoston Torok · Jan 20, 2012 at 09:43 PM
I tried several ways:
Using the method you suggested (to play a 1sec long file in loop) - better results, because time doesn't change for 5-6 cycles, but then it does
Used Update instead of FixedUpdate and saved deltatimes between commands (audio.Play()) to a text file, I can't find out why but the values based on time.time did not match with the recorded sound
Any ideas?
Windows, $$anonymous$$ac, even linux are not realtime OS. There is no way to guarantee the kind of synchro you're looking for.
It's true:( The thing that I don't understand is that how could it be possible, that even if I log the update times the time interval between the sounds has fairly any relation with them. Here is my code:
var ins : float = 1;
function Update () {if (Time.time > ins ) {audio.Play(); print(Time.time); ins = ins +1; }}
But on the recorded soundfile the interval is 0.98 or 1.02 sec