Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gapless looping in unity3d

Tags:

unity3d

audio

I've been struggling with this for some days already now ... :(

I've read these threads: Gapless-MP3-playback, Gapless looping on iOS, Gapless looping on iOS Producing seamless looping mp3s. Also a bit of theory here: mp3Loops

I am doing as instructed: Import WAV files, select MPEG encoding, check the "gapless looping" box

  • just a note for future googlers. In very old versions of Unity, there was a "gapless looping" button (removed since about 2014). In fact, that button was completely broken and did nothing.

and make it loop:

    var gameObject2 = new GameObject("MyObject");
    audioSource2 = gameObject2.AddComponent<AudioSource>();

    var filename = "test01_1152x";
    audioClip2 = Resources.Load (filename) as AudioClip;
    audioSource2.clip = audioClip2;
    audioSource2.loop = true;
    audioSource2.Play();

However the "pop" sound is terribly obvious.

I wonder what am I missing?

Checking "gapless looping" is just a bit better but it does not avoid the "pop" sound 100%. If the file given is wrong or not best for this situation, what conditions should the file fullfill in order to have a nice gapless looping bgm?

These are the pictures of various settings I've tried, including the original wave file

Original Wave: Loops nicely, because it is WAV. enter image description here

Compressed as MPEG (Non gapless looping selected), "pop" sound is super obvious while listeninig it. enter image description here

Compressed as MPEG (Gapless looping selected), "pop" sound is still obvious, just a bit better than setting. enter image description here

like image 684
nacho4d Avatar asked Feb 13 '23 20:02

nacho4d


1 Answers

You can't loop an mp3 in Unity.

It is clearly stated in the manual.

Indeed when you drop an mp3 in to Unity it literally shows an alert that you cannot loop mp3s in Unity.

Simply convert to Ogg or Wav.

That's all there is to it.

Same sound as mp3 versus wav:

enter image description here

Obviously it is trivial to convert audio files between formats; use any software on your Mac or PC to do so. (Example, TwistedWave.)

(Note: The discussions in the other answers about how to loop smoothly in an artistic sense, are completely unrelated to the question of Unity3D / mp3 looping - which is trivial, you can't loop an mp3 in Unity.)

like image 139
Fattie Avatar answered Feb 15 '23 10:02

Fattie