Playing sounds seems to be very slow on the iPhone - anyone else confirm this?
What I’m seeing is a 220ms average time to kick off a sound using code such as:
audioSource.clip = clip;
audioSource.Play();
or even:
audioSource.PlayOneShot( clip, volume );
The 220ms is just time taken to start the clip, i.e. complete the Play call. This is true on the first and subsequent calls for that clip (its not just a one-time thing). The clip is sampled at 44.1kHz for 1.7s duration, about 70kB on disk.
So, its very disruptive to frame rate, especially in the worst case when I have 3-4 sounds playing per second. That’s CPU time spent almost entirely playing sounds!
Is there a way around the slow playback, or a way to improve the slowness? Halp!
I assume thats a WAV right, because mp3 / aac can’t be used or better shouldn’t be used for that due to the 1 track at a time restriction and the time required to startup them on the dedicated decompressor chip
HamulTech had a good suggestion on another thread - sometime before the game starts, play each of the sounds for a very short time and then stop them. They should now be cached, and subsequent plays will be faster.
As far as I can tell this is untested, and also relies on something you have no control over (i.e. memory cache, GC). But it might work
Hmm… it would be nice to have audio clips compressed, even if only to save disk footprint.
I couldn’t find the thread but here’s what I tried so far (and no luck):
Add a GO to the scene, attach the AudioSource component, then get it to reference the clip, and make sure PlayOnAwake is checked. On startup, the clip is played.
But when I use it, I’m still seeing 220ms for play time. Am I doing it right?
Its odd though, if I import the file as a compressed file, it has its DecompressOnLoad checked, which I would think would decompress it and keep it around. That doesn’t seem to be the case, even when I have another reference sitting around in my GO.
Except for music, yes. That’s really the only option. You don’t think anything of playing compressed sounds on a modern computer, because they are really fast, but iPhones are not.
I have a few short loops playing (1-2 seconds) of uncompressed Wavs at 22khz… I find the audio glitches quite often, clicking noticably. I am just about to update version to Unity 1.5 - is the audio handling better?