Event timeline lags behind after repeated setPaused calls


I’m currently implementing a rhythm game system in UE4 using FMOD, and I noticed a specific issue when trying to add a pause/unpause feature to the game. After calling setPaused on the event instance multiple times, the getTimelinePosition values I get start falling behind what I’m actually hearing in the song. To examine the issue more clearly, I set up this test case:

  • There was a clear kick sound X seconds into the song, and I wanted to print a string in Unreal exactly at X seconds after the song started playing.
  • I play the audio alongside my rhythm game system (without any pausing) and it prints the message exactly X seconds into the song. I’m using getTimelinePosition as the way to see how far we are in the song playback. My printed message also prints what getTimelinePosition is at that point, and it prints a value very close to X as expected.
  • I play the audio again, but this time I pause and resume playback 10-20 times by calling setPaused on the event instance. I hear the kick sound, and after a noticeable delay (~200-300 ms), I see my message printed. My printed message says that getTimelinePosition is again X.

I saw a couple of other questions related to this subject such as dspClockTime is out of sync after event instantiation? - #2 by cameron-fmod and Off sync on position "getTimelinePosition" when using "setPaused" method. , and so I tested the same system using channelGroup->getDSPClock instead. I saved the getDSPClock value once when the song playback started, and would subtract that from the newer DSPClock value as the song played to find the current song playback position. This method didn’t work either and my song position value still ended up lagging behind the actual audio after repeated pause calls.

One last thing I tried was to create a timeline marker exactly at X seconds in FMOD Studio, and print out my message using the timeline marker callback. Without any pausing, this worked fine and my message was timed perfectly with the kick at X seconds. With repeated pausing and resuming, the same issue happened: I heard the kick first, and after a noticeable delay I saw the timeline marker callback print out my message.

I’m happy to create a small example project and send that to better demonstrate the issue. Any help would be appreciated as at this point I’m not sure if there’s a way for me to reliably track how far I am in the event being played, if I also want to support pausing and resuming playback. Thanks!

1 Like

I would very much like to hear some insight on this as well! Thank you.

I have been trying to reproduce this issue myself but have not been able to as of yet, if you could provide a project that would be very helpful.

Can you also tell me a couple of other things:

  • What OS are you one?
  • What version of FMOD are you using?
  • What version of UE4 are you using?

Hey Cameron, thanks for the reply. I’m on Windows 10, FMOD Studio 2.01.06 and UE 4.23.1. I could give it a try on a newer Unreal version or different FMOD versions later this week if you have any specific versions in mind to test out.

I just created a test project, here’s the link: FMODPauseTestProject.zip - Google Drive

You can run the TestMap scene to hear an audio clip automatically play. I’ve placed a marker at around the 17th second of this clip, when you first hear a kick sound. When you run the scene, once the clip hits 17 seconds and you hear the kick, you’ll see a Print Screen message printing ‘Marker A’, along with the marker position (17150).

If you run the scene again and pop up the console, and then type in ‘ce RunPauseTest’ and press enter, this will run a series of SetPaused true, SetPaused false calls on the FMODAudio component, with some short delays in between (You can check out the TestMap level blueprint to tweak the delay or how many times the pause and resumes should happen). Then if you keep listening to where the first kick happens, you’ll notice that there’ll be a noticeable delay between when the kick happens, and when the timeline marker is triggered, printing 17150.

I hope this helps, let me know if you need anything else from me (like the FMOD Studio project). I also wanted to let you know that I found a somewhat hacky workaround for this issue for now; I get the timeline position of the event when I pause the game, stop the event altogether, and then when the game is unpaused I call Play on the event, and then SetTimelinePosition with the timeline value I had saved. By doing this, I can confirm that the timeline values no longer lag behind the audio and I’m able to get around the issues I was observing with repeated SetPaused calls. However I’d still like to avoid stopping and restarting the event altogether every time if I can, so let me know if there’s anything else I can do to debug this. Thanks!

Thank you very much, we are looking into this now.