How to seamlessly rewind a Timeline that contains audio

Hey all, I’m trying to rewind a Timeline that contains some audio, in a way that the audio loops seamlessly.

The setup:

A 15 seconds timeline with 2 tracks: one is a custom playable track, the other is an audio track.
The audio track has a 12 seconds clip, and I need to loop back at second 6 to second 3, or to 0.


What I do is that the MixerBehaviour of the custom track checks if its time is past the value (6), and if so, sets PlayableDirector.time to the beginning of the loop (3 or 0).

It kinda works, but there’s a tiny hitch in the audio. Being this a musical game, I wanted to ask if there is something else I’m not considering that I need to do to ensure smooth audio playback.

PS: I have tried in a build, I have tried setting the PlayableDirector to DSP clock, but the hitch is still there.

Thanks!

In the end, I found out that rewinding the Timeline to _whereIWantToRewind + Time.deltaTime seems to do the trick. The idea is this:

If I have to rewind at second 6, and rewind to 0, the reality is that the code that checks the rewind will never play at 6, but anytime after that. So 6.002, 6.013, 6.02, etc. depending on the current framerate.

So it will always sample that frame in audio, and play it. When I rewind to exactly 0, I now hear the frame before and the frame at 0, which contain the same sample (because the audio is looping), which makes me hear a stutter.

But if I send it to 0 + something (the Time.deltaTime I mentioned before), the first sample is skipped, so it ends up with no duplication, which produces a smooth audio playthrough.

If anyone has a better trick/technique, let me know!