Noticeable Mp3 Audio loop gap

Hi

I am trying to loop a short mp3 audio (engine noise) by using the following code but no matter what I do, I get a noticeable gap at the beginning of each repeat. I read other posts but couldn’t figure out what the problem is. The noise sounds flawless when I listen to the loop in Ableton audio interface. Here is the code:

local noise = audio.loadStream( "noise.mp3")  
audio.play( noise, {loops=-1})

Be aware that certain formats — particularly highly-compressed, lossy formats like .mp3 , .aac , and .ogg — can pad/remove samples at the end of an audio sample and potentially break a “perfect-looping” music clip. If you are experiencing gaps in looping playback, try using .wav and make sure that your starting and ending points are clean.

You can find information about this and other audio-related gotchas here:
Audio Usage/Functions

1 Like

@sianature - although I don’t have a tested solution, I would try two different things.

  1. look at the compression settings of your mp3 files, make sure they are not too high; like above 210. I use 160-210 max.
  2. I went here: https://docs.coronalabs.com/api/library/audio/loadStream.html

The Gotchas section of this page states, “Also note that streamed files may have slightly higher latency costs than files loaded with audio.loadSound(). They also may have slightly higher runtime (CPU) cost to play than files loaded with audio.loadSound().”

1 Like

Thank you @Gil44liG

I was able to fix the problem by using a WAV file (16 bit) and reduced the size by reducing the sample rate to 22050 from my DAW (Ableton). I was using a 24 bit wav and it wasn’t compatible based on the guide and all I could hear was a hissing noise.

@troylyndon thank you man.
I would love to use mp3 to save space, but even changing the sample rate didn’t help and I still got a glitch or pause in the beginning. I tried 128, 160, 256, and 320. I am using Solar SDK on Windows 10.

2 Likes