Why do I have a noticable gap in my audio when it loops?

So I managed to sort this out, using C++. I had the same problem with looping - there was always a small gap between the loops, even though I was 100% sure that my loop mp3 file was fine.

In the end, I ended up using a recursive function, with a timer that’s set to the duration of the sound.


void USLSound::ExecuteLoop(UWorld* World) {
  UGameplayStatics::PlaySound2D(World, CurrentSound, CurrentVolume);
  float NextLoopTime = CurrentSound->GetDuration();
  World->GetTimerManager().SetTimer(
         LoopTimerHandle,
         [World]()
         {
             ExecuteLoop(World);
         },
         NextLoopTime,
         false // Don't repeat - we handle repetition manually
     );
}

This worked perfectly, confirming that my loop file was fine.

If you have a small gap at the end of your sound file, you could even set NextLoopTime to a slightly smaller number (say CurrentSound->GetDuration() - 0.05 for 50ms)