Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] Audio loop not gapless anymore - Android - Unity 5.1.3f1

Discussion in 'Audio & Video' started by Kristof_Newfort, Oct 14, 2015.

  1. Kristof_Newfort

    Kristof_Newfort

    Joined:
    Feb 21, 2014
    Posts:
    24
    Hi

    I have an audio file (OGG) that is gapless. When you preview it in unity with loop on, you can hear it being gapless.
    But when I build the audio file into an AssetBundle, load it into my app and play it as a loop, there is a 1 or 2 second pause in it.

    The best settings I got to create the smallest gap is:
    - Decompress On Load
    - PCM (Vorbis gives me the biggest gap.)
    - Preserve Sample Rate

    There is a sentence on the bottom of following page that I don't like though: http://docs.unity3d.com/Manual/class-AudioClip.html
    It says: On mobile platforms compressed audio is encoded as MP3 to automatically take advantage of hardware decompression.

    Mp3 files are hard to make gapless. so if unity builds all the android audio into mp3, then maybe it adds gaps to them. There was a toggle 'gapless looping' in an older version of Unity, but in Unity 5 I don't see that setting anymore.

    Does someone know how to fix this? Is this a bug?
    Does someone know a setting that works and makes my audio gapless?

    Thanks in advance.
     
    Last edited: Oct 15, 2015
  2. Kristof_Newfort

    Kristof_Newfort

    Joined:
    Feb 21, 2014
    Posts:
    24
    Changed the sample rate of my audio to 44.100 Hz instead of 22.050 Hz with an application (not unity).
    It's a bit better, but still not gapless.

    I'll try and make it a gapless mp3 file, maybe that way Unity doesn't have to convert it to mp3 and doesn't add a gap.
    I'll post the results.
     
  3. Kristof_Newfort

    Kristof_Newfort

    Joined:
    Feb 21, 2014
    Posts:
    24
    Ok, I tried to create the gapless mp3 file, but the software keeps failing.
    I used following: http://www.compuphase.com/mp3/mp3loops.htm

    It keeps saying: Error: Bit reservoir non-zero.
    If someone has an idea on how to just fix it in Unity, please do tell me :)

    Thanks.
     
  4. Kristof_Newfort

    Kristof_Newfort

    Joined:
    Feb 21, 2014
    Posts:
    24
    It seems that the audio wasn't using the Unity loop after all. The dev that wrote the code had created his own loop method with a coroutine, but it seems that this doesn't work good on android anymore. (code was first written in Unity 3.x)

    So I removed it and implemented the Unity version and now it loops gapless :)
     
    Endahs likes this.