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?

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.

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?