Search Unity

Sound optimization on IOS

Discussion in 'iOS and tvOS' started by unisip, Dec 3, 2012.

  1. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    340
    I'm experiencing severe slowdowns on iPhone4 when playing too many fx sounds at once. In my code, I basically have some 3D sounds triggered through PlayOneShot() on game events. It may happen that quite a few of those are played at the same time (maybe 8?).

    Aside from setting up some code to prevent that from happening, I was wondering if anyone had experience on optimizing sound play.
    Right now my sounds are decompressed in RAM, stereo 44.1khz/16bits.

    I guess my question is, in terms of performance (memory is not an issue here):
    - does it make a difference if sounds are 8bit instead of 16bits?
    - does it make a difference if sounds are mono instead of stereo?
    - does it make a difference if sounds are 22khz instead of 44.1khz?

    Tks for any advice on this
     
  2. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    Stereo sounds will not be played in a 3D scene, they need to be mono to be enviroment sounds.

    Your slowdown is most likely caused by using PlayOneShot(), which makes a new AudioSource component on demand, then cleans up. We've had this problem a lot with weapon firing sounds..

    The way to fix this is to build a pool of Audiosources, and iterate through them..


    Then just make a function that will iterate through them one after the other..

    Something like that is quite effecient in comparison, as there's no cleanup taking place after each shot :)

    In answer to your other questions, always use the lowest possible sample rate you can get away with. For some sounds, 11khz is fine, some might need to be 16, and 22khz will cover pretty much anything you'll need. It saves a lot of ram, it's well worth doing.
     
  3. CH

    CH

    Joined:
    Jul 4, 2012
    Posts:
    109
    Sound performance on iOS 4/5 was better with Unity before 3.5. We created a tech demo which ran fine on iPhone4 but now it doesn't anymore. I personally have the feeling that audiosources that are created in the inspector are heavy, heavier than audiosources generated from script. I do not have proof, however. :D
    Maybe you could try to generate audio objects from script and see if it runs better.
     
  4. BarbaricCo

    BarbaricCo

    Joined:
    Sep 29, 2011
    Posts:
    77
    Great!
    I used this technique for graphics elements but will try for weapons audio also, if its has large impact on performance.

    But I have question too. My explosion sounds are sometimes muted in heavy battle scenes even they have higher priority, and is 8-bit 22 kHz mono good enough for gun shooting sounds?

    Thanks
     
  5. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    When it comes to sound quality, you just have to make that call by listening to it. I often drop a sound as low as I can go before I can start to hear artefacts (lower sampling will kill your higher frequencies).

    As to explosion sounds being muted, we don't get the luxury of running track compressors and dynamics modification on the fly on mobile devices, so you sort of need to balance all your samples with 'worst case scenario' in mind. MP3's being decoded on hardware just blast, so I normally drop those by 6db or more.

    As for sound fx, I start with everything peaking at -6db, tweak audio falloffs/ranges in game, and when things just aren't 'popping' the way I want, I will manually increase their volume in my audio editing tools, or if I suspect it'll be played along side several other sound fx (so I need to keep the volumes lower so everything doesn't end up a big distorted clipping mess), I'll compress them to fake the volume, and still leave -4db.

    It's a fine art, sound balancing is often done very last, and it's often a process of jumping between my Unity machine and my audio machine just to get it right :)
     
    mubashar437 likes this.
  6. BarbaricCo

    BarbaricCo

    Joined:
    Sep 29, 2011
    Posts:
    77
    Thanks
    So if I can summarize audio editing and optimizing is kind of art. I hear it many ours when I was trying mastering of audio tracks and never was on db level without distortion or near CD quality. Without proper equipment or expirience if one can afford it's better to find professional for that kind of work.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I found a performance increase with using decompress on load as well but your mileage may vary.
     
  8. BarbaricCo

    BarbaricCo

    Joined:
    Sep 29, 2011
    Posts:
    77
    Btw all my sound fx are in wav format except level songs. I shorten fx as much as posible in Audacity. Also mixing several effects into one when possible in Garageband. Will try lowering sample rates, playing with dB levels and definitely implement audio pool for often used audio. And listen listen listen... Honestly professional mixing and mastering of all in game audio is only right choice :)