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

Unity 5 Audio Sample Rate Woes

Discussion in 'Audio & Video' started by InsomniaLab, May 18, 2015.

  1. InsomniaLab

    InsomniaLab

    Joined:
    May 14, 2014
    Posts:
    3
    Decided to post here to shed some light on one of Unity 5s vague audio handling issues, and to see if anyone else has dealt with this (or figured out what the best approach might be for working around this issue).

    To preface this, all of my audio in Unity 4 works perfectly, but switching over to Unity 5 introduces some nasty artifacts (some pops and clicks). After some testing I found that the issue seems to be caused due to sample rate mismatch.

    Here is some background on what seems to be causing the issue:
    1. In Unity 5, the Sample Rate setting under Project Settings -> Audio seems to be set as 0 by default. I recall reading in the past that this makes Unity 5 grab the sample rate of whatever device you're running on, but I can't seem to find this reference anymore. Anyway, when I check audio sample rate used in game when run on PC, it comes up as 48000 Hz in both Unity 4 and Unity 5.
    2. All of my audio recordings (all in wav format) have a sample rate of 44100 Hz, which is also the sample rate that I have my audio card set to.
    3. The Sample Rate settings for any audio clip/file in Unity 5 is by default set to "Preserve Sample Rate", meaning the audio clips are imported at 44100 Hz. Changing the sample rate settings to "Optimize Sample Rate" also imports the clips at 44100 Hz.

    So what seems to be happening is that the audio in game is running at 48000 Hz, and my audio clips are running at 44100 Hz, causing the audio artifacts.

    Now the way to solve this problem on PC seems to be to do one of the following:
    1. Set the Sample Rate setting under Project Settings -> Audio to 44100 Hz. Not ideal if porting to mobile devices, since those usually default to at a different sample rate (24000 Hz on my android), and I don't know what repercussions there could be to forcing this to a higher sample rate (possibly slower performance?).
    2. Set the Sample Rate Settings for all Audio Clips to Override Sample Rate, and manually set all audio clips to be imported at 48,000 Hz. Now since you are forcing all audio clips to this sample rate, I'm not sure if you will have issues when running on a mobile device which is running at 24000 Hz. I couldn't hear any distinct audio issues or artifacts during my quick test, but I also don't have any good equipment to listen to audio from mobile (unlike PC).
    Anyone have any input on this? It feels like a real nuisance to have the default audio settings in Unity 5 not work properly, especially when they were working perfectly fine in Unity 4 without all this fiddling.
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Sounds annoying. I'd like to hear about the resolution.
     
  3. etoiles

    etoiles

    Joined:
    May 13, 2008
    Posts:
    216
    I am also curious about this... also, since mobile devices seem to use 24KHz, it seems strange that Unity doesn't offer it as an option in the 'Override Sample Rate' settings for sound assets.