i want to use a timeline to create an audio that has an intro section, a looped section and an out section.
i have a pair of custom markers, LoopInMarker and LoopOutMarker which i use to set the section which will be looped.
by setting playableDirector.time in Update() i can make playback jump back to the loop start point.
but i always get a dropout in the audio, i suspect i will need this to be sample accurate.
so i figure i should use the Dsp Clock and set the jump to happen in OnAudioFilterRead()
i have two problems here:
since i can’t use playableDirector.time in OnAudioFilterRead(); How can i get and set playableDirector.time?
OnAudioFilterRead creates an audio filter, which i do not need and i’m sure it creates needless overhead., i just need a way to run code on each dsp frame. if not OnAudioFilterRead, what else can i use?
That should work - independent of the clock type. Can you be more specific about what you mean by ‘dropout in the audio’?
The DSP clock is used to drive the time of the timeline - in practice, it should be very close to using unscaled game time. Audio is always scheduled against the DSP clock, no matter what clock is driving timeline, and when you set playabledirector.time in Update, that should be causing the audio clips to be rescheduled.
The DSP clock sample is typically less accurate than other clocks, so after it is sampled by the playable director, it is smoothed out using unscaled game time - and there are some pending fixes that might be causing the issues you are seeing. The pending fixes solve cases where the smoothing could cause the estimate to deviate too far from the audio clock, typically caused by lower framerates. (A workaround if you suspect that is a problem is to call the internal method PlayableDirector.ResetFrameTiming() using reflection).
I don’t think OnAudioFilterRead() will help in this situation, since changing the time will cause timeline to reschedule no matter where the sync came from. If the above information isn’t helpful, I’d recommend filing a bug report with a repro case.
there is a small silence in playback lasting a fraction of a second. which changes with cpu load, this happens in all the updatemodes, .(if the loop is really small (2 - 4 frames) i get silence instead of stutterring)
is it possible to specify a PlayableDirector.time in a sample accurate way like AudioSource.timeSamples?
does it take a whole two frames for the audioSource to get updated?
thinking that it was just a problem with the latency between updating PlayableDirector.time and the Audio playing i tried adding an offset of +/- a few frames to the loop points but it still has a bit of silence.
It shouldn’t be. The time jump on timeline should just be causing a re-seek on the clip (rounded to the near. I made a small repro case, and I can hear a small gap as well. It needs further investigation, but I suspect there is a reset of some kind occurring that shouldn’t be in that scenario. I’d recommend filing a bug - one, so you can track it, and two, the repro case is the same.