Double Playing Audio Section Due to Bug in MovieSceneAudioSystem.cpp

I am experiencing double-playing audio sections on certain audio clips. Most clips are fine, but ones that double play, always double play.

I have tracked this down to MovieSceneAudioSystem.cpp:656, that is, this line:
AudioTime = Duration > 0.f ? FMath::Fmod(AudioTime, Duration) : AudioTime;

The problem is that the if above is for AudioTime > Duration but FMod will return 0 if AudioTime == Duration. This causes the sound to be started again.

I think the easiest fix is to just change the if check to be AudioTime >= Duration

It may seem unlikely that this would come up, but I’m using an audio sample rate of 24kHz which is the same as the default tick rate so the math ends up coming out to the exact same floating point value. At least in about 5% of cases.

This USoundWaveAsset repros the problem 100%:

Repro:

  1. Create sequence
  2. Add audio
  3. Set looping = false
  4. Drag the end of the section out so it goes past the end of the audio
    (this last step isn’t always required but it makes repro guaranteed)