Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Terrible Latency - not so with other engines

Discussion in 'Android' started by Osirius, Mar 20, 2015.

  1. Osirius

    Osirius

    Joined:
    Oct 10, 2014
    Posts:
    47
    I've recently come close to finishing my first Unity mobile game and I started working on Audio. To my surprise, I noticed that every sound had a very noticeable delay (~0.5 seconds). I played around with the latency settings, buffer size, audio formats, load type, sample rate, etc., and absolutely nothing made a difference. I made sure there was no gap of silence in the audio file, I tried compressing the audio file to tiny sizes and I tried leaving it completely uncompressed. The latency always stayed the same.

    I then decided to make a new Unity project; only one asset (a small audio file), no skybox and just one cs file with the following:

    Code (csharp):
    1.  
    2. public AudioClip AudTest;
    3.  
    4.     // Use this for initialization
    5.     void Start () {
    6.     }
    7.    
    8.     // Update is called once per frame
    9.     void Update () {
    10.         if (Input.touchCount > 0)
    11.         {
    12.             AudioSource.PlayClipAtPoint(AudTest, this.transform.position, 1);
    13.         }
    14.     }
    15.  
    Just a simple .apk file that does nothing except play a small audioclip when you touch the screen. Even this had the exact same latency issue that my full game had.

    I started doing some research and I've noticed many people have complained about this in the past, and none of them have ever seemed to find a solution. It doesn't seem to affect everyone and seems very much to be device-related.

    Now here's my issue. On the same device I have previously made games in Construct2 and GameMaker. Whist I'm not here to compare engines, neither of these 2 had any latency issues whatsoever.
    Why is this? In most of the threads and questions posted about latency problems on Android it's always explained that this is a limitation with certain Android OS versions, that they don't have low latency drivers. This is obviously not the case.

    So, I guess my question is, how on earth do I improve latency? Can I even improve latency? Is this something that Unity devs can fix? If not, this is a massive deal-breaker.

    I am currently using Unity 5 but this problem occurs for me on Unity 4 also.

    Thanks in advance!
     
    MrEsquire likes this.
  2. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Yes, unfortunately this issue still exists for almost 3 years now. My observations is that it's not related with OS version but the hardware. Different chipsets may have different audio drivers etc.. which may cause this issue.
     
    MrEsquire likes this.
  3. Osirius

    Osirius

    Joined:
    Oct 10, 2014
    Posts:
    47
    Strange that the problem has existed for so long and Unity hasn't fixed it yet. I mean, I know it's hardware related, but Unity seems to be the only game engine that is experiencing this problem. Even far, far less advanced engines seem to somehow be able to handle audio on Android better than Unity can.
     
  4. Osirius

    Osirius

    Joined:
    Oct 10, 2014
    Posts:
    47
    Sorry to double post but are there no members of Unity staff with an answer?
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  6. Osirius

    Osirius

    Joined:
    Oct 10, 2014
    Posts:
    47
    Please read my first post.

     
  7. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    I think one option to get rid of some of the latency is to play static samples (already uploaded to the AudioFlinger). You could try interfacing with AudioTrack directly and initialize that in STATIC_MODE. I'm not 100% sure this will give you low latency everywhere and it definitely has it's limitations when it comes to mixing but from a theoretical point of view you should be able to get lower latency using that.

    Also, it should be noted Unity does not yet take advantage of the Android low-latency path. We've had an implementation ready for a while but according to QA there are still way too many devices that break using this path. We are working on it though. But on some devices (like Kindle Fire) you will probably never ever see good audio latency with Unity.