Hey guys, I’m working on a synchronization game in Unity that requires precise knowledge of the time of the song that is playing, for event triggering and beat related things etc.
I’m using getDSPClock to get the dspClock time of the song event and it works relatively fine, but there’s this weird thing that when the event is first instantiated, the initial dsp time is delayed by around 2 seconds.
A simple example of what I mean - I have code similar to this in Update()
musicChannelGroup.getDSPClock(out dspClockTime, out parentClockTime);
var value = ((double)dspClockTime) / sampleRate;
Debug.Log("time: " + value);
and 0 is printed initially.
Then when I call (not starting the event, only instantiating it!)
eventInstance = RuntimeManager.CreateInstance(musicEventRef);
the block of code mentioned above starts logging “time: 2.1” or so. The values are somewhere around 2 seconds, and they are relatively random. Re-instantiating the event keeps adding time to the dsp clock.
I’d like to understand what’s happening, and how to deal with this issue and get precise time of the song.
One simple idea is that I guess I could just save this “delay” amount that the dspClock returns after event instantiating, and always decrease the time I get by this amount, to get the “real” timeline of the playing song.
But I’m not sure whether maybe there won’t be any extra delay in the dspClock once I actually start the event - maybe after I call start() on the event instance, the dspClock will again keep increasing or something for a while, without anything actually happening - so perhaps I should save the “delay”/dspClock time once the playback state returned by the event instance is “Playing”?
So basically, how should I get rid of the delay? When/how can I figure out what the final “delay” is that I should subtract from the resulting value, to get the real, precise time of the song playing?