Search Unity

Android sound problem

Discussion in 'Android' started by Dr. Argento, Oct 5, 2015.

  1. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Folks - can you please check the sound with Unity 5.3.3p2?
    It should work on "broken" devices.
    Big thanks for helping us with this issue goes to @iivo_k and @yuliyF !

    Bluetooth and Chromecast sound issues are next to be fixed.
     
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @Aram Azhari : thanks for the video. What would really be helpful is the build fingerprint of the device and logcat.
     
  3. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    141


    This is the device info for the same video. It appears to be a European variant of Tab 2. Our external qa team tested in a U.S version of tab 2 and couldn't reproduce the problem.

    Unfortunately we can't get the logcat from the user.

    Let me know if there is anything else we can help you with. We'll most probably test the new patch you have put in once it's online in the cloud.

    Thanks.
     
  4. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @Aram Azhari : my tab2 is gt-p5100 with 4.1.2, never got 4.2 as an OTA update. Your ROM looks original, but it could be rooted and files changed.
    Unfortunately it's hard to say anything more without logcat. Could you try the latest 5.3 and see how it works.

    Thanks!
     
  5. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    141
    The device in the photo is p5110 and is officially upgradable to 4.2.2. http://m.gsmarena.com/samsung_galaxy_tab_2_10_1_p5110-4669.php

    Even if the device was rooted it shouldn't have to affect the audio in Unity, unless it is a custom core kernel. I believe that the particular customer is incapable of doing rooting let alone a custom os installation. Besides, rooting is completely legal and there is no need for someone to lie about it.

    I'm not arguing whether rooted device should be supported by Unity or not. I'm simply looking for possibilities for a resolution.

    I'll keep you posted about the 5.3.3p2 results.

    Thanks again.
     
  6. dhiru1602

    dhiru1602

    Joined:
    Jun 28, 2015
    Posts:
    4
    On I9300 custom roms, just remove the file system/etc/permissions/android.hardware.audio.low_latency.xml and reboot. The audio issues will be fixed.

    This device doesn't support low latency audio because it has only one PCM Port for playback and it's not possible to use Deep buffer and Low Latency at the same time. Custom roms were falsely advertising low latency audio feature.
     
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Folks, I would love to hear whether latest 5.3 fixes the issue for you.
     
  8. Crendel-Studios

    Crendel-Studios

    Joined:
    May 17, 2015
    Posts:
    1
    YES! THANK YOU SO MUCH!
    BOTH PUBLISHER AND ME ARE HAPPY)
    P.S. Mark me as the guy, who did it and tested, and your BFF :)
     
  9. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Thank you @Crendel Studios !
    Although I think some more changes are about to come up.
     
  10. Dr. Argento

    Dr. Argento

    Joined:
    Jan 29, 2015
    Posts:
    23
    I upgrated to cyanogenmod 13 (Android 6.0.1) and sounds its fine now (Galaxy S3 i9300)

    I upgraded to Android 6.0.1 (cyanogenmod 13) and the sound plays well, if any problem occurs, will be posting in this thread.
     
  11. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    Sounds work properly now on the Galaxy S3 with SlimKat. Thanks a bunch, Yury!
     
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Could you folks please confirm it works on 5.3.4p2?
     
  13. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    That's what I used yesterday, so at least in my case it worked.
     
    Yury-Habets likes this.
  14. BartNT

    BartNT

    Joined:
    Sep 12, 2013
    Posts:
    12
    Hi Yury, thanks for you work on android audio for Unity!

    My tests with Unity 5.3.4p2 & Galaxy S3 i9300:

    On Cyanogenmod 11 (Android 4.4.4) (with this android.hardware.audio.low_latency.xml file in system) I have the same problem like before: choppy, slowdowns, pauses etc. :/

    On Cyanogenmod 13 (Android 6.0.1) (with no hardware.audio.low_latency.xml file - they fixed this bug in OS) everything is OK.

    Another big issue I've noticed is a huge lag on Android using PlayOneShot method:

    On Galaxy S3 it is even quite acceptable (about 200-300ms), but yesterday I've bought a new phone (Xiaomi Redmi Note 3 Pro - based on great hardware and Snapdragon 650) and audio lag there (with PlayOneShot) is about 700-900ms :( (tested on three (2 official and 1 dev) roms - based on Android 5.1.1).

    I've tried with different audio formats, import options and audio settings in project - and there is always the same lag :/

    It is something very very strange because when I use SoundPool from Android Java API I have no lags on both devices.
    So, to have realtime and responsible sound effects, instead Unity Audio, I have to use C# wrapper on Java's SoundPool.

    Something like that :
    https://www.assetstore.unity3d.com/en/#!/content/35295

    In this asset you have a sample scene with two buttons. First plays the sound using AudioSource.PlayOneShot and the second using SoundPool.play. Please, test it at the office on a few devices and you will see (hear) the difference.

    You can also read about this problem in this thread:
    http://forum.unity3d.com/threads/android-sound-latency-fix.319943/
    https://github.com/fadden/android-audio-bypass

    Let me know if there's anything I can help or test on my side.
     
    Last edited: Apr 11, 2016
  15. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Hi @BartNT!

    Thank you for your feedback, appreciate it.

    Could you do the same thing on the device that has "choppy" sound: http://forum.unity3d.com/threads/android-sound-problem.359341/page-2#post-2507427 - install the AudioBufferSize app from Google Play and share the results?
    Could you also search logcat of a Unity app for the line "AudioManager: Selecting".

    Same for Redmi Note 3 would also be helpful.


    On the "bypasses". I've taken a look at these apps some time ago - they have nothing to do with native audio, fast path or anything. They just play an audio clip using Android Java APIs. For the true fast path and minimum latency, you could try this: https://github.com/Over17/AndroidAudioFastPathSample :) I can share the APK if needed.

    The thing is - in Unity audio is not as simple as playing the clip. You have mixing, effects, 3D sound, spatializing and a million of other things that need realtime calculations. Due to all that "pure" fast path as in the sample on github is not really applicable to Unity. To be honest, Android is not well-suited for pro audio applications, so don't expect one-frame-latency.
     
  16. BartNT

    BartNT

    Joined:
    Sep 12, 2013
    Posts:
    12
    Sure Yury! Here are the results :)

    Galaxy S3 - On Cyanogenmod 11 (Android 4.4.4) - with this unwanted android.hardware.audio.low_latency.xml file in system
    04-12 14:54:55.338: D/Unity(12605): AudioManager: Selecting OpenSL output...

    abs_galaxy_s3.png

    Xiaomi Redmi Note 3 Pro
    04-12 14:56:01.900: D/Unity(8114): AudioManager: Selecting AudioTrack output...

    abs_redmi_note3.png

    This phone is a brand new pro model based od Snapdragon 650 with 3GB RAM.
    http://xiaomi-mi.com/redmi-note-3-pro/xiaomi-redmi-note-3-pro-3gb32gb-dual-sim-gray/
    I think that it should have OpenSL and low latency feature, but Unity selects AudioTrack output :/

    I couldn't check for android.hardware.audio.low_latency.xml file there because my Redmi Note is not rooted, so I've found app called "Device Caps Dump" in google play.

    Here are the results:

    Build Info

    Board: msm8952
    BootLoader: unknown
    Brand: Xiaomi
    CPU ABI: arm64-v8a
    CPU ABI2:
    Device: kenzo
    Display: LMY47V
    Fingerprint: Xiaomi/kenzo/kenzo:5.1.1/LMY47V/6.3.31:user/release-keys
    Hardware: qcom
    Host: qh-miui-ota-bd81.bj
    Id: LMY47V
    Manufacturer: Xiaomi
    Model: Redmi Note 3
    Product: kenzo
    Radio: unknown
    Serial: ad3ab4df
    Tags: release-keys
    Type: user
    User: builder
    Time: 1459357175000
    Ver. codename: REL
    Ver. incremental: 6.3.31
    Ver. release: 5.1.1
    Ver. SDK: 22

    Display

    Height: 1920
    Width: 1080
    X DPI: 391.885
    Y DPI: 381.0
    Density: 3.0
    Scaled density: 3.0
    Density DPI: 480
    Screen size: normal

    Features

    android.hardware.audio.output
    android.hardware.bluetooth
    android.hardware.bluetooth_le
    android.hardware.camera
    android.hardware.camera.any
    android.hardware.camera.autofocus
    android.hardware.camera.flash
    android.hardware.camera.front
    android.hardware.consumerir
    android.hardware.ethernet
    android.hardware.faketouch
    android.hardware.location
    android.hardware.location.gps
    android.hardware.location.network
    android.hardware.microphone
    android.hardware.screen.landscape
    android.hardware.screen.portrait
    android.hardware.sensor.accelerometer
    android.hardware.sensor.compass
    android.hardware.sensor.gyroscope
    android.hardware.sensor.light
    android.hardware.sensor.proximity
    android.hardware.sensor.stepcounter
    android.hardware.sensor.stepdetector
    android.hardware.telephony
    android.hardware.telephony.cdma
    android.hardware.telephony.gsm
    android.hardware.touchscreen
    android.hardware.touchscreen.multitouch
    android.hardware.touchscreen.multitouch.distinct
    android.hardware.touchscreen.multitouch.jazzhand
    android.hardware.usb.accessory
    android.hardware.usb.host
    android.hardware.wifi
    android.hardware.wifi.direct
    android.software.app_widgets
    android.software.backup
    android.software.connectionservice
    android.software.device_admin
    android.software.home_screen
    android.software.input_methods
    android.software.live_wallpaper
    android.software.managed_users
    android.software.print
    android.software.sip
    android.software.sip.voip
    android.software.voice_recognizers
    android.software.webview

    So, it looks like there is is no android.hardware.audio.low_latency. Very very strange :/

    I've grabbed also these caps for Galaxy S3:

    Build Info

    Board: smdk4x12
    BootLoader: I9300XXUGNA5
    Brand: samsung
    CPU ABI: armeabi-v7a
    CPU ABI2: armeabi
    Device: m0
    Display: cm_i9300-userdebug 4.4.4 KTU84Q 93cb64d509 test-keys
    Fingerprint: samsung/m0xx/m0:4.3/JSS15J/I9300XXUGMJ9:user/release-keys
    Hardware: smdk4x12
    Host: cyanogenmod
    Id: KTU84Q
    Manufacturer: samsung
    Model: GT-I9300
    Product: m0xx
    Radio: unknown
    Serial: 4df14e4568d75f55
    Tags: test-keys
    Type: userdebug
    User: jenkins
    Time: 1452816078000
    Ver. codename: REL
    Ver. incremental: 93cb64d509
    Ver. release: 4.4.4
    Ver. SDK: 19

    Display

    Height: 1280
    Width: 720
    X DPI: 304.8
    Y DPI: 306.71698
    Density: 2.0
    Scaled density: 2.0
    Density DPI: 320 (xhdpi)
    Screen size: normal

    Features

    android.hardware.audio.low_latency
    android.hardware.bluetooth
    android.hardware.bluetooth_le
    android.hardware.camera
    android.hardware.camera.any
    android.hardware.camera.autofocus
    android.hardware.camera.flash
    android.hardware.camera.front
    android.hardware.faketouch
    android.hardware.location
    android.hardware.location.gps
    android.hardware.location.network
    android.hardware.microphone
    android.hardware.nfc
    android.hardware.screen.landscape
    android.hardware.screen.portrait
    android.hardware.sensor.accelerometer
    android.hardware.sensor.compass
    android.hardware.sensor.gyroscope
    android.hardware.sensor.light
    android.hardware.sensor.proximity
    android.hardware.telephony
    android.hardware.telephony.gsm
    android.hardware.touchscreen
    android.hardware.touchscreen.multitouch
    android.hardware.touchscreen.multitouch.distinct
    android.hardware.touchscreen.multitouch.jazzhand
    android.hardware.usb.accessory
    android.hardware.usb.host
    android.hardware.wifi
    android.hardware.wifi.direct
    android.software.app_widgets
    android.software.device_admin
    android.software.home_screen
    android.software.input_methods
    android.software.live_wallpaper
    android.software.sip
    android.software.sip.voip
    com.cyanogenmod.android
    com.cyanogenmod.nfc.enhanced
    com.nxp.mifare
    com.tmobile.software.themes
    org.cyanogenmod.theme
    org.cyanogenmod.theme.v1

    And we can see unwanted android.hardware.audio.low_latency feature here.

    So it looks like both phones messed up with their audio features in system :/ But why, AudioTrack is so slow on Redmi Note 3?

    I know, I know, but like 90% 2D games I only need to tap on the screen and hear instant sound instead of waiting one second for "click" or "shoot" :)
     
    Last edited: Apr 12, 2016
  17. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @BartNT - thank you for the hard work, and sorry for the delay in answering!

    With latest Unity versions (audio fixes for Bluetooth and casting are in 5.3.4p6), on your Galaxy S3 with Cyanogenmod 11, AudioTrack should be selected, unless you selected "Best performance" in the project audio settings or set custom buffer size in your project.
    Some details. Buffer size "from platform" is 1056 samples. Default Unity buffer size is 512 samples; "Best performance" is 1024. When the device buffer size ("from platform") is >= 2 * Unity buffer size, we don't activate OpenSL. If you are sure you are using the default 512 samples in Unity - something might be wrong on our side then.

    On the huge delay on Redmi Note 3 - I really don't know what could be going there. Could you check with Unity profiler whether there are CPU spikes or anything suspicious?

    On 2D games and simple audio... I understand your position and concerns. Will see if we can do something about that.
     
    BartNT likes this.
  18. Dr. Argento

    Dr. Argento

    Joined:
    Jan 29, 2015
    Posts:
    23
    @Yury Habets Thanks for your time and work, keeping this thread alive and most important, the fixes / solutions.
     
    BartNT likes this.
  19. BartNT

    BartNT

    Joined:
    Sep 12, 2013
    Posts:
    12
    Thanks @Yury Habets! I've just installed Unity 5.3.4p6 and with default buffer size audio is smooth on my Galaxy S3. All good! :)

    It would be great to have some simple and fast path without all pre & post processing for 2D. Something fast like SoundPool on Android ;)
     
  20. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    53
    I have a huge audio delay (around 600ms) on Oneplus 2 device. I'm running default Oxygen 3.1.0
    I already tried all possible settings but the latency always stays the same. I also tried native android apps and there's no audio latency at all. Is there anything I can do about that?
     
  21. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @IcyHammer that's the device issue. Oxygen 3.1.0 - is that an official Android OS with Google Play?
     
  22. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    53
    Yes, this is the official android 6 os, it is the default os for all oneplus two mobile phones.
     
  23. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    Is Google Play available on the device? Not a proprietary market application.
     
  24. Zhixuan

    Zhixuan

    Joined:
    Nov 23, 2016
    Posts:
    1
    We have a problem that the sound will choppy. It only appears in the use of Bluetooth headset. This seems to be the same problem. But the problem seems to have not been fixed. Is there any way to solve it temporarily?
    Unity:5.4.2-GVR11
    FMOD:1.08.12
    OS:Android 7.1
    Thanks!

    @Yury-Habets
     
  25. _mdbnet_

    _mdbnet_

    Joined:
    Jul 7, 2014
    Posts:
    1
    I am also hearing this issue from time-to-time when making builds with 5.4.2-GVR11; I am not using Bluetooth headphones.

    I find that rebooting the device sometimes fixes it, so that the audio is no longer choppy even though the app has not been updated.
     
    Last edited: Nov 23, 2016
  26. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @_mdbnet_ is it using the Unity internal sound system or an external FMOD-based? I'm not really an expert in the custom GVR builds.

    If the former - then you are probably using too much CPU. Try setting Buffer size to "Best Performance" in the Audio settings.
     
  27. theonenr

    theonenr

    Joined:
    Aug 4, 2014
    Posts:
    18
    Has anyone found a way to fix the problem on the Redmi Note 3 Pro with huge sound delay?
    I have newest Unity 2017 version and last official MIUI 8.2 on Android 6.0.1, but the problem remains.
     
  28. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
  29. theonenr

    theonenr

    Joined:
    Aug 4, 2014
    Posts:
    18
    Ok, i have uploaded.
    Yes, on other phones sound works fine. But i have also no problems with non unity greated games on this phone :(
     

    Attached Files:

  30. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    That's interesting - the values make sense to me. I would assume our audio manager selects OpenSL for the audio backend which is not working very well on this device. Try looking into a development build logcat for a line like "AudioManager: Selecting xxxxx output..."
     
  31. oyy

    oyy

    Joined:
    Sep 2, 2015
    Posts:
    6
    I'm working on a music game which can't tolerate huge sound delay. According Yury-Habets's reply. I found that no matter how I change my AudioSettings, the engine always show
    "AudioManager: Selecting AudioTrack output..."
    before OnAudioConfigurationChanged or after Initialize engine version: 5.6.1p4 (99afd32ca6da)
    Audio.jpg
    Is that a problem? Would OpenSL fix the sound lag? Is there other reason that engine choose to use AudioTrack? Thanks
     
  32. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    The answer is - it may. :)
    So far, OpenSL should make the output latency lower than AudioTrack. However, the device must have the necessary support for OpenSL fast path audio. For instance, custom ROMs for old Galaxy S phones claim this support, when in reality they don't - this results in bad performance and glitches.

    Your device seems to be a quite rare one - I can't find much detail, and I have no idea whether it supports OpenSL fast path. Based on what Unity selects - it probably doesn't. There should be a command line to check it somewhere here on the forums.

    If this is true (your device does not claim OpenSL fast path support) - then there's probably nothing you could really do.
     
  33. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
  34. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,261
    Sorry for necro-ing the thread, but I have made a solution Native Audio that uses OpenSL ES to play an audio on Android. The audio is guaranteed to go to a fast mixer track since I have put a built-in resampler in it. But you have to put your audio in
    StreamingAssets
    to send them to the native side.

    http://exceed7.com/native-audio/

    Details of approach taken : https://gametorrahod.com/androids-native-audio-primer-for-unity-developers-65acf66dd124

    This is not true, my Xiaomi Mi A2 (2018 / Stock Oreo 8.1.0 / Android One program device) does not have both FEATURE_AUDIO_LOW_LATENCY and PRO AUDIO flag and sure enough Unity does not get the fast mixer track. However the track I requested manually can be fast just by matching the track's sample rate to the phone. The details of what I did is again all in the article above. Here's the
    adb shell dumpsys media.audio_flinger
    dump. Unity ones (the popup window) does not get the "F" but mine receive the "F". Look for the one with PID 28714, it is the PID of the test Unity app running.

    1_BAc7jYiSNbLVO8PnjuPhpg.png
     
    Last edited: Sep 4, 2018
    Yury-Habets likes this.
  35. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,052
    @5argon thank you, I'll read your blog post, looks interesting at a glance.
    Also thank you for looking into high-performance audio on Android!

    Most latency in Unity Android Audio goes from FMOD; despite using the OpenSL fast path or AAudio output, the end-to-end latency stays around 150 ms. FMOD and Unity Audio system provide a widest range of features for audio playback and processing which are used by thousands of people. Of course the latency could be lower if you want to just fire an audio clip at native sampling rate. I'm sure this one has ~10ms latency: https://github.com/Over17/AndroidAudioFastPathSample

    Good news: we are looking into making things better soon! Our best people are on it.



    No it is true. This is pure logic.

    Please read it once again, guarantee being the most important word:
    And if you go to CDD which you linked in your article:
    https://source.android.com/compatibility/android-cdd#5_6_audio_latency

    If device implementations meet the above requirements, after any initial calibration, when using both the OpenSL ES PCM buffer queue and AAudio native audio APIs, for continuous output latency and cold output latency over at least one supported audio output device, they are:

    • [C-SR] STRONGLY RECOMMENDED to report low-latency audio by declaring android.hardware.audio.low_latency feature flag.

    If device implementations do not meet the requirements for low-latency audio via both the OpenSL ES PCM buffer queue and AAudio native audio APIs, they:

    • [C-1-1] MUST NOT report support for low-latency audio.

    Which means that a device might have Fast path support even if it doesn't report the low-latency flag (like your Xiaomi or a Samsung S7) - this device doesn't follow the "strongly recommended" policy. However most of devices which don't report the flag don't support fast path. So we do a safe assumption by not using fast path on devices which don't report the flag. Moreover, I can tell you from my experience that using OpenSL on devices which don't support fast path may lead to huge latency, up to 1 second. We use Java AudioTrack for them, it's the safest and most compatible option.

    That's only partly true. If your phone supports fast track, you will 99% fit into the requirements from CDD, so you are STRONGLY RECOMMENDED to report the flag. If your phone doesn't support fast track, 99% you won't fit into the threshold from CDD.


    Thank you for bringing this up once again!
     
    JuliusM, 5argon and Vectrex like this.
  36. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,261
    This is exciting. Thank you!


    I stand corrected.

    I am happy that this is like the first thread ever that talks about latency issue down to Android native level and I just found this after deducing blindly on my own. So I didn't have anyone to talk to before. I understand the reason of using FMOD because Unity provides extensive mixing and effects features from 5.0.0, plus the flexibility of importer settings.
     
    Yury-Habets likes this.