Search Unity

Noticable delay when playing an AudioClip, suggestions?

Discussion in 'Android' started by twist, Apr 26, 2011.

  1. twist

    twist

    Joined:
    Aug 6, 2010
    Posts:
    15
    I'm working on a game where there are lots of collisions, and I'm playing one shot audio clips upon each collision. The clips are less than a second long, and because it's a mobile game, they are compressed. Unfortunately, once the files are compressed, there is a brief silence added to the beginning of the file, causing a very obvious disconnect between the collision and the sound.

    I've read every piece of documentation available from Unity, but the only suggestion offered is to use uncompressed files for soundFX. Unfortunately, that's not an option for mobile games. Any help/suggestions are much appreciated at this point.

    Something to note: this is not an issue on iOS, just Android.
     
  2. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    Hi!
    Don´t know if this is the issue, but I have read about a general audio latency issue on the Android platform in general
     
  3. twist

    twist

    Joined:
    Aug 6, 2010
    Posts:
    15
    Thanks for the reply, I think I remember hearing that too. There are plenty of games out on Android though, I have to assume there's a reasonable solution.
     
  4. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    We have that issue with our game Stellar Escape. On iPhone it works fine, but on Android there is a small delay when playing audio. Really annoying. Seems to be an Android issue though, just as you are saying.
     
  5. G2X44

    G2X44

    Joined:
    Jun 15, 2011
    Posts:
    11
    Hi!

    Is there any progress with this issue?
     
  6. twist

    twist

    Joined:
    Aug 6, 2010
    Posts:
    15
    It's an Android issue...we are just dealing with it.
     
  7. rickst13

    rickst13

    Joined:
    Jul 12, 2011
    Posts:
    8
    Bumping old thread. A couple of questions.

    1) Did anyone ever find a workaround to this?

    2) Is the delay consistent on all android devices? It is always right around 0.4 seconds on my Nexus S.

    3) Is this being fixed in 3.4?
     
  8. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    Also curious about this fix.. It is a problem in one of our games but works fine on the IOS build.

    -Dane
     
  9. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    Did you tried to change the Sound File settings to "Load type: Decompressed on load", instead of "Compressed in memory"?

    This way the files would be compressed in the APK, but would be uncompressed when the scene is loaded, so they will only have to be decoded once on the load of the scene instead of every time it has to be played
     
  10. MHD Salka

    MHD Salka

    Joined:
    Mar 19, 2013
    Posts:
    72
    It's the year 2013 and audio latency still sucks!!!! holy crap google wtf are you doing....
     
  11. meat5000

    meat5000

    Joined:
    Mar 5, 2013
    Posts:
    118
    Agreed. They make billions and they can't fix a little lag issue?

    But still, Android is a blatant money making machine and not much else, so it's somewhat to be expected.

    If I'd known about this beforehand I probably would not have begun my project and gone to work at Sainsbury's instead.
     
  12. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    (Bumping old thread)

    On my HTC one SV there is a sound delay
    On my Galaxy note there is no sound delay. That's working fine.

    Why is that? It's both Android.
     
  13. MightyRobot

    MightyRobot

    Joined:
    Sep 25, 2013
    Posts:
    35
    Since unity apparently are not interested in this horrible bug, has anyone found a workaround to make SFX in android without such big delays?
     
  14. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    524
    The problem is partly os related but just as much driver related. Comparing two android phones is like comparing two pc's with different sound cards. Glenn and Raph was giving a pretty good talk about low latency audio at Google I/O earlier this year.

    https://developers.google.com/events/io/sessions/325993827
     
  15. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    506
    I've watched that talk and it's pretty insightful, but for as far I know the latency problem still exists.
     
  16. meat5000

    meat5000

    Joined:
    Mar 5, 2013
    Posts:
    118
    Yep latency is still brutal but it is Extremely device dependent. My Quad Core Sony Xperia Z has up to 0.5 s delay on Android 4.2.2 but a mate's 2.3 HTC and another 2.3 Samsung show no lag at all!

    Basically, I have set my output buffer to (256, 2) which is ultra small and this is the only way I can make the delay significantly small. All other things I've tried actually produce no difference AT ALL.

    I read somewhere that Android likes 48k sampling but a Debug.Log of outputsamples shows clearly that it is in fact 24000 and I am beginning to think that this is what is causing my problem.

    470-471 is the magic number...
     
  17. MHD Salka

    MHD Salka

    Joined:
    Mar 19, 2013
    Posts:
    72
    A alot of apps have extremely low latency on all android devices (Magic piano for example), so its possible....
     
  18. ChristopherCreates

    ChristopherCreates

    Joined:
    Apr 8, 2015
    Posts:
    20
  19. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,019
    The latency will always be there. If your sound is not a result of player's interaction you could potentially play the sound early on purpose. (You know there will be a collision, so you can play the sound early) Each device has different latency, but a safe number is 0.1ms.

    Or you could go native to make instantaneous play faster. I just made Native Audio asset store plugins which can make a native call to both iOS and Android's fastest native way from one central interface. https://www.assetstore.unity3d.com/#!/content/107067

    There are various ways of playing audio at native side, here's my choice :

    - On iOS it uses OpenAL. It is faster than AVAudioPlayer, AudioToolbox, and SystemSound.
    - On Android it uses AudioTrack, I confirmed it to be faster than SoundPool and no meaningful difference from C++ side OpneSL ES of NDK.

    I have compiled all of my findings in here : http://exceed7.com/native-audio