Search Unity

[Unity 5] Some audio clips get randomly cut

Discussion in 'Editor & General Support' started by Elkis, Mar 7, 2015.

  1. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Hey guys! After upgrading to Unity 5, I noticed some audio clips get randomly cut before ending if I call them from code like this one:
    Code (CSharp):
    1. AudioSource audio = GetComponent<AudioSource>();
    2. audio.PlayOneShot(sound);
    It is more noticeable when I call them frequently each frame (when the game gives coins to the player and each add action makes a coin sound for example).
    I'm tempted to substitute all of the code with "AudioSource.PlayClipAtPoint();" but I'm not sure because it will create a lot of objects with the AudioSource component. Do you think it is a good workaround? or did I miss something important to avoid the issue I'm having?

    Thank you in advance!
     
  2. Deleted User

    Deleted User

    Guest

    Are they popping, like they would with an audio buffer underrun?
    Try increasing the audio buffer size in the audio settings. (trading some latency for stability)
     
  3. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Hey Brobot, thanks for answering.
    I tried increasing the audio buffer size as you suggested but nothing changed :(

    Here are some other things I have noticed:
    -Sometimes the audio gets cut before ending, other times it starts halfway through, but most of the time it just plays quieter than normally.
    -The issue is non-existent when playing within the editor, it only happens when playing on a device.
    -It also depends on the platform. It happens more often on BlackBerry devices, then Windows Phone and very seldom on Android.
    -The issue is more likely to happen when all of the sounds come from the same AudioSource.
    -When replacing "audio.PlayOneShot(sound);" with "AudioSource.PlayClipAtPoint();", the occurrence flips (It is more apparent on the editor and almost non existent on the devices).

    Any idea of what could I be missing?
     
  4. Deleted User

    Deleted User

    Guest

    Beats me. All I've noticed is that audio has been broken in many ways since the RC. I'm using PlayClipAtPoint() and while increasing the buffer size helps, it doesn't entirely eliminate the cutoffs, popping and other glitches.

    Is there any difference between streamed and loaded audio? Compressed and uncompressed? Compression settings?
     
  5. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Just tried all the possible Import settings combinations, the only noticeable change was with Load Type set to Streaming, that made random bursts of the clip looping for some seconds but, despite of that, the issue was still very noticeable :(
     
  6. Deleted User

    Deleted User

    Guest

    Sucks. I managed to soften some of the errors by messing with the compression but globally it still glitches out from time to time, usually by skipping samples when it's not supposed to. When previewing audio clips in the editor, there's always some popping now at the beginning and the end.

    Something changed within the audio system, obviously for the worse. In 4.6 or earlier 5.0 builds the audio played perfectly at any point in the world space as well as in 2D, with any speaker setup, at the lowest latency setting and without any mess-ups in the mixing.
     
  7. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Care to share your compression settings? Would like to minimize the errors too.

    Do you know if there is a bug case for this issue? or should I make one?
     
  8. Deleted User

    Deleted User

    Guest

    I don't know of any bug case and I consider the issue tracker unusable due to the lack of a proper search function.

    As for the compression, I changed some of my old uncompressed waves to ADPCMs and lowered the sample rate on those that didn't need 44k.

    Also, some experimentation has revealed that the issues with playing 3D sounds might be related to doppler effects or something else based on a delta value between frames. I'll get a heavily distorted sound effect with clicking and other garbage if I have it playing right after I enter playmode where the camera is in motion. But if I enter playmode with pause on and unpause on the next frame, the sound will be more or less normal. (aside from doppler pitch-shifting of course)

    Perhaps there's some timing/clock issue within the sound system causing all of this.