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

Sound issues on Kindle Fire

Discussion in 'Android' started by maeschba, Feb 10, 2012.

  1. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Hello,

    has anyone else experienced sound issues on the Kindle Fire? I hear a constant clicking noise, nearly rhythmic. Sound works fine one Nexus S and Xoom, but I had to implement a fader because stopping an AudioSource always made noise, too.

    I'm importing WAV-files, 16 bit, 44100 Hz, Mono with Audio Importer setting Decompress on load.

    Any help appreciated!
     
  2. 9heart

    9heart

    Joined:
    Nov 24, 2011
    Posts:
    18
    We too are having this issue, tried various settings in the Audio Importer. Unity 3.4.2f3, API level 8
     
  3. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    It seems to be a Unity problem. I tested a new version of the game and the audio files sound well directly on the device, but not in the game. I'm working with Unity 3.5.0f5.
     
  4. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    No sound issues here. Using Kndle Fire and Nexus. Same Unity version too. I have already compressed my audio to mp3 though.
     
  5. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Great to know! I also pre-compressed one of the files for the current release but still hear noise on the Kindle. Could you note the values of your audio settings and tell me where you attached the AudioSource to? Mine is attached as child object to the camera in one scene. Even though it's a 2D sound, perhaps the distance to the camera could be a problem.
     
  6. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
  7. Saagara

    Saagara

    Joined:
    Mar 13, 2012
    Posts:
    1
    Hi (A non techie here)

    We are experiencing the same issue with our apps on the Kindle Fire. The issue is Kindle Fire Specific only in our case, the apps are working fine on all other Android devices we have tested ( including the Nook color, Nook Tablet, Acer iconia, Samsung galaxy Tab, and a host of android phones), as well as working fine on iOS, Mac and PC builds

    Our Apps "Universal Breathing - Pranayama" And "Core Yoga" both have popping sounds on the kindle fire. These sounds occur once at the beginning whenever a new music segment is played, our apps generate their sounds by stitching and looping segments of music. Since in a 2.5 second period we stitch 3 segments of music together it makes for a lot of "popping" sounds on the kindle fire and a poor user experience.
     
  8. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    I'm having a similar issue with audio on Android.

    I play a clip (OnAwake) and when the object is destroyed there is a "POP" sound. I've tried stopping the audio, muting the audio (same as setting *.volume = 0.0; ) to no avail.

    I'm using Unity 3d/Android Pro, latest version 3.5.

    I really need to fix this issue, but everything I'm trying is not helping at all.
     
  9. _Petroz

    _Petroz

    Joined:
    May 13, 2010
    Posts:
    730
    I think the best you could do is to manually do a stair step fade using a coroutine before destroying the object completely. I doubt that this issue is specific to the Kindle.
     
  10. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    Wouldn't that result in the same basic thing as setting it to mute? Fading (in the end) just reduces the volume. Or am I missing another reason why step-fading would be better?

    Thanks for the response!
     
  11. _Petroz

    _Petroz

    Joined:
    May 13, 2010
    Posts:
    730
    A 'pop' is a sharp transition. So for example if the signal was at 1.0f and you stop and it immediately goes to 0.0f. Depending on how the internals are set up, mute should trigger a ramp (fade out) which would be just as good, the important thing is to make sure it has time to process that mute (at least a couple of frames). Step fading is always inferrior but it's all you can do from outside the mixer, I think calling mute would probably be a better way to go it if it works.
     
  12. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    OK, I see your logic now. I am muting just before the destruction, so I'll try to break the audio from the main object and split it from the parent just before the destruct call; then give the AudioSource some time to see if it alleviates the POP sound. I'll let you know when I get to if, if it helps.

    I'm working on some Enemy AI scripts now, when done - I'll post.

    Thanks again!
    JS
     
  13. _Petroz

    _Petroz

    Joined:
    May 13, 2010
    Posts:
    730
    May also be worth trying setVolume(0) if mute doesn't work. Let me know how it goes.
     
  14. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    OK, your help was appreciated and did pinpoint the issue. Here's how I implemented it.

    I moved the AudioSource from the GameObject prefab into a GameObject of its own, parented under the original GameObject.

    When I need to destroy a sound gracefully (without popping), I use the script below - ON the AudioSource GameObject under the original (parent) object.

    The script simply checks the GameObject that it is attached to see if it is still parented. If it is, nothing is done. If you clear the parenting of the AudioSource GameObject from the parent, the script will fade out and destroy the object the audio script are attached to over numerous frames (dependent on current volume / stepFactor setting) to smooth the audio destruction and alleviate the sharp volume transitions to prevent pop.

    Again, thank you, help appreciated - script below to repay the community, if anyone needs it!

    JS

    -- Script Start (javascript) --

    #pragma strict

    var stepFactor : float = 0.05;

    private var aSource : AudioSource;

    function Awake()
    {
    aSource = gameObject.GetComponent(AudioSource);
    }

    function FixedUpdate()
    {
    // Once we detach from our parent, we'll fade and die without audio popping noises
    if (transform.parent != null) return;

    if (aSource != null) // Be sure this object actually has an audio source!
    {
    aSource.audio.volume -= stepFactor;

    if (aSource.audio.volume > 0) return;
    }
    else
    Debug.Log("Object named \"" + gameObject.name + "\" has no AudioSource!");


    Destroy(gameObject);
    }

    -- Script End. Enjoy!

    If you use the script and you till hear audio pop, just adjust the stepFactor in the Unity GUI (Inspector view of the audio object the script is attached to). The smaller the step, the more time (and thus FixedUpdate calls) it will take to kill the audio.
     
    Last edited: Mar 18, 2012
  15. _Petroz

    _Petroz

    Joined:
    May 13, 2010
    Posts:
    730
    Good work, I'm glad to hear that fixed your issue.
     
  16. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    My sound sources aren't attached to the camera. I can see it being an issue if you are destroying objects, but if it is the sound track (always on) it should play perfectly. Have you tried on another Kindle?
     
  17. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    I do not have another Kindle to test but the music file runs fine in the Kindle's music player. I'm testing with a simple Unity project now: no other game objects than the camera and an empty game object with the audio source attached to it, but still no luck :(

    Audio Format: Compressed (MPEG)
    3D Sound: No
    Load type: Stream from disc (but same with Decompress on load)
    Compression (kbps): 128 (same as the source file that runs fine on the device)

    Audio Source Priority: 0 (but same result with 128)
    Play On Awake: Yes
    Loop: Yes
     
  18. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    So is it popping when you destroy the audio source?
     
  19. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    No, it's noise (static, crackles) while the audio is playing. Please see my first post.
     
  20. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    Whats the specifics on the audio format you are using? Bitrate, channels, etc. etc.
     
  21. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Sample rate 44100 Hz
    Channels 2
    Bitrate 128 kbps
    Codec MP3
    Codec profile MP3 CBR
    Tool LAME3.98r

    I had the same problem with an uncompressed WAV file. Both generated with Audacity.

    The audio file plays well on the device (Kindle Fire Music Player) and I think that Unity re-encodes the MP3 file, even if I chose the same bitrate in the engine as the original file has.
     
  22. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Try to use .ogg format for all your sounds, and see what happens.
     
  23. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    I tried but still the same. Why do you think this should help? The .ogg files get converted to mp3 by the importer anyway. The result should not differ from using uncompressed audio files.
     
  24. JSorrentino

    JSorrentino

    Joined:
    Feb 28, 2012
    Posts:
    50
    Can you create a small project containing the issue and minimal code snippets to make it work so we can look at it? Any audio file that gives the same result is fine, as long as whatever you send can reproduce the problem.
     
  25. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    I created a small project with the main track (no code necessary). If you PM me your email address, I will send you the Unity scene file as well as the MP3 file.
     
  26. gwangmarc

    gwangmarc

    Joined:
    Mar 13, 2012
    Posts:
    1
    I was using the code in the following on iPad2, it's working:
    audio.PlayOneShot(voiceP0);

    But after I converted to Kindle Fire today, not working with same code. I have to change my code to:
    AudioSource.PlayClipAtPoint(voiceP0, camera.transform.position);

    But a new issue came out, I don't how to stop the audio with this new code...anyone?
     
  27. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    PlayClipAtPoint will pop out a new game object that will be auto destroyed when finished playing.
    See also this code if you want to implement this manually, and may help you. I'm also interested in Unity Kindle performance.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class example : MonoBehaviour {
    5.     public AudioClip theClip;
    6.     AudioSource PlayAudioClip(AudioClip clip, Vector3 position, float volume) {
    7.         GameObject go = new GameObject("One shot audio");
    8.         go.transform.position = position;
    9.         AudioSource source = go.AddComponent<AudioSource>();
    10.         source.clip = clip;
    11.         source.volume = volume;
    12.         source.Play();
    13.         Destroy(go, clip.length);
    14.         return source;
    15.     }
    16.     void Example() {
    17.         PlayAudioClip(theClip, transform.position, 1);
    18.     }
    19. }
    http://unity3d.com/support/documentation/ScriptReference/AudioSource.PlayClipAtPoint.html
     
  28. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    Just wanted to add my experience with Kindle Fire audio to this thread.

    I have the following issues:

    - All audio is delayed by about half a second.
    - I get intermittent pops/clicks.
    - Sounds often do not play at all. This seems to be most common with very short clips.
     
  29. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    I saw this on the latest Marmalade news and wondered if it was relevant:

    And from the project:

    So maybe there's something UT can do to help on the Fire.
     
  30. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Unity support told me that they could reproduce the clicking and popping sound issue and that they do not have any workaround to offer for now. They will investigate into this matter for another release.
     
  31. ladron

    ladron

    Joined:
    Mar 16, 2012
    Posts:
    47
    I've managed to work around one of my sound issues on the Kindle Fire. It seems that very short sound files play sporadically. If you pad the sound out with some silence, though, it works reliably. Not sure what the exact minimum length is, but 1/2 second works fine.

    I haven't been able to solve the agonizing sound latency issue, though. Sound latency on the Fire seems to be bad in general, but Unity is definitely making it worse.
     
  32. radazen

    radazen

    Joined:
    Feb 29, 2012
    Posts:
    13
    I'm having the same problem on the Kindle Fire. I spent a few hours trying various things with my source audio (changing its sample rate, format, encoding options, etc), but in all cases, the audio pops when played on a Kindle Fire. I assume it's some sort of bad interaction between Unity's MP3 encoding and the Kindle Fire's audio decoding. For a game that I've spent some 7-8 months on, I'm not willing to release it on the Amazon Appstore with such an obvious and unprofessional flaw, so I did the only thing I could think of to get around Unity's audio encoding: play my background music with Android's MediaPlayer class. It's a workaround that I'm not thrilled with, but it does work. Info and code for anyone interested...

    NOTE: With Android's MediaPlayer, there's a very slight (but audible) gap when my audio loops. I'm still trying to figure out how to deal with that. [UPDATE: Using an OGG file instead of an MP3 file allows for gapless looping]

    Put a copy of the mp3 file you want to play in your Assets folder under Assets/StreamingAssets/. It'll be accessible as a raw, unprocessed file on the Android side of things.

    To play the audio on iOS and non-Kindle devices, I use this class (BackgroundAudioPlayer.js):

    Code (csharp):
    1. #pragma strict
    2.  
    3. var m_audioSource : AudioSource;
    4.  
    5. function Initialize (clip:AudioClip) {
    6.     m_audioSource = gameObject.AddComponent (AudioSource);
    7.  
    8.     m_audioSource.playOnAwake = false;
    9.     m_audioSource.loop = true;
    10.     m_audioSource.clip = clip;
    11. }
    12.  
    13. function IsPlaying () : boolean {
    14.     return m_audioSource.isPlaying;
    15. }
    16.  
    17. function Play () {
    18.     m_audioSource.Play ();
    19. }
    20.  
    21. function Pause () {
    22.     m_audioSource.Pause ();
    23. }
    And then on a Kindle Fire, I use a subclass of BackgroundAudioPlayer instead:

    Code (csharp):
    1. #pragma strict
    2.  
    3. class AndroidMediaBackgroundAudioPlayer extends BackgroundAudioPlayer {
    4. #if UNITY_ANDROID
    5.  
    6.     var m_mediaPlayer : AndroidJavaObject;
    7.     var m_isPlaying : boolean;
    8.  
    9.     function Initialize (fileName:String) {
    10.         m_isPlaying = false;
    11.  
    12.         var playerClass : AndroidJavaClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
    13.         var activityObj : AndroidJavaObject = playerClass.GetStatic.<AndroidJavaObject> ("currentActivity");
    14.    
    15.         var assetManager        : AndroidJavaObject = activityObj.Call.<AndroidJavaObject> ("getAssets");
    16.         var assetFileDescriptor : AndroidJavaObject = assetManager.Call.<AndroidJavaObject> ("openFd", fileName);
    17.         var fileDescriptor      : AndroidJavaObject = assetFileDescriptor.Call.<AndroidJavaObject> ("getFileDescriptor");
    18.        
    19.         m_mediaPlayer = new AndroidJavaObject ("android.media.MediaPlayer");
    20.         m_mediaPlayer.Call ("setDataSource", fileDescriptor, assetFileDescriptor.Call.<long> ("getStartOffset"), assetFileDescriptor.Call.<long> ("getLength"));
    21.         m_mediaPlayer.Call ("prepare");
    22.         m_mediaPlayer.Call ("setLooping", true);
    23.     }
    24.  
    25.     function Play () {
    26.         m_mediaPlayer.Call ("start");
    27.         m_isPlaying = true;
    28.     }
    29.  
    30.     function Pause () {
    31.         m_mediaPlayer.Call ("pause");
    32.         m_isPlaying = false;
    33.     }
    34.  
    35.     function IsPlaying () {
    36.         return m_isPlaying;
    37.     }
    38.  
    39.     function OnDestroy () {
    40.         m_mediaPlayer.Call ("stop");
    41.         m_mediaPlayer.Call ("release");
    42.         m_mediaPlayer = null;
    43.     }
    44.  
    45.     // The Android MediaPlayer will keep playing while our app is suspended, so we need to handle that when the app is suspended or resumed.
    46.     function OnApplicationPause (pause:boolean) {
    47.         if (pause) {
    48.             if (m_isPlaying)
    49.                 m_mediaPlayer.Call ("pause");
    50.         }
    51.  
    52.         else {
    53.             if (m_isPlaying)
    54.                 m_mediaPlayer.Call ("start");
    55.         }
    56.     }
    57.  
    58. #endif
    59. }
    It's not a perfect solution...I end up with two copies of the mp3 in my final build, one for the Kindle Fire and one for other devices. But if you really need a way to play background music on a Kindle Fire, it's the best workaround I've found so far.
     
    Last edited: May 8, 2012
  33. radazen

    radazen

    Joined:
    Feb 29, 2012
    Posts:
    13
    Update: I converted my audio file to OGG, which does have native support for gapless looping on Android, and now my audio loops perfectly.
     
  34. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Wow! You did a great job! I hope this helps you sell your game on Amazon. Regarding the Kindle platform, all I got from Amazon since months is "Please note that we may review your app separately for Kindle Fire." with no further comment about a Kindle specific issue (the sound). The small number of units I sold in their appstore run probably on other devices.
     
  35. mhardy

    mhardy

    Joined:
    Apr 3, 2011
    Posts:
    48
    We're having the same issue. Anyone find a solution to the latency problem?
     
  36. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    I've been having the same issue too, but strangely enough it only seems to happen on one of my projects and not the other.
    For anyone curious this is what the popping sounds like https://dl.dropbox.com/u/17977639/Unity/PoppingSound.wav

    One big thing I noticed on my non-popping project is that I reduced the volume of the BG music down to 75% since it seemed to be playing exceptionally louder than normal with the default settings.
     
  37. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Unity support acknowledged the issue some time ago (cf. above post) and the last time I tested my game on a Kindle it was acceptable (apk built with Unity 3.5.3). Unfortunately I do not know whether this issue has been officially addressed with in a recent Unity update.
     
  38. screenracer

    screenracer

    Joined:
    May 9, 2011
    Posts:
    112
  39. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    The issue I had should have been addressed and fixed. Since Solstice is free now, please download a copy from Amazon or install the APK on your Kindle from here.

    As soon as the game starts, the background music starts and in the game are several sound effects (thrusters, laser beams) so you can check if there is a similarity to your problem.

    Solstice never got rejected on the Kindle for sound issues and the downloads on Amazon where so marginal that I always released Solstice as is.
     
  40. maeschba

    maeschba

    Joined:
    Aug 11, 2011
    Posts:
    88
    Listening to your video on Youtube, I think that what I had was more choppy, more hardware related. I preloaded all the audio files (not 100% sure for the music anymore). What you have here is perhaps a streaming issue. Does it sound like that if you preload the files?
     
  41. screenracer

    screenracer

    Joined:
    May 9, 2011
    Posts:
    112
    Thanks for the reply. Turns out that the issue stems from the Ultimate FPS package. We are working on the issue now, but I fixed it by taking out the UFPS Rig and just using the Unity example one. Sound issue fixed!? I still think it is a great package, and the creator has been very helpful. You are more then welcome to follow it here