Why is AudioSettings.DspTime so inaccurate?
AudioSettings.DspTime doesn't update every frame or anywhere close to it!
The manual says dspTime is ".. much more precise than the time obtained via the Time.time property." but, if I read DspTime every frame I can see that it stays the exact same value for up to 3-4 frames at a time. Even if I put this code in FixedUpdate (50 fps) it still doesn't change every frame.
Example Code...
double lastDspTime = 0;
void Update ()
{
if (AudioSettings.dspTime == lastDspTime)
{
Debug.Log ("Duplicate Time: " + lastDspTime);
}
lastDspTime = AudioSettings.dspTime;
}
My output looks like this...
...
Duplicate Time: 210.474666666667
Duplicate Time: 210.474666666667
Duplicate Time: 210.496
Duplicate Time: 210.517333333333
Duplicate Time: 210.517333333333
Duplicate Time: 210.517333333333
Duplicate Time: 210.538666666667
Duplicate Time: 210.56
Duplicate Time: 210.56
...
I couldn't find anyone else asking about it. Is it just me or do other people just not realize or care? Is there some way to fix this?
Unity 5.3.3 & 4.3.2 both do it.
Comment
Answer by monremobile · Jun 19, 2016 at 09:50 PM
You must read AudioSettings.dspTime in OnAudioFilterRead() not in Update().