I’m working on a game where there are lots of collisions, and I’m playing one shot audio clips upon each collision. The clips are less than a second long, and because it’s a mobile game, they are compressed. Unfortunately, once the files are compressed, there is a brief silence added to the beginning of the file, causing a very obvious disconnect between the collision and the sound.
I’ve read every piece of documentation available from Unity, but the only suggestion offered is to use uncompressed files for soundFX. Unfortunately, that’s not an option for mobile games. Any help/suggestions are much appreciated at this point.
Something to note: this is not an issue on iOS, just Android.
Thanks for the reply, I think I remember hearing that too. There are plenty of games out on Android though, I have to assume there’s a reasonable solution.
We have that issue with our game Stellar Escape. On iPhone it works fine, but on Android there is a small delay when playing audio. Really annoying. Seems to be an Android issue though, just as you are saying.
Did you tried to change the Sound File settings to “Load type: Decompressed on load”, instead of “Compressed in memory”?
This way the files would be compressed in the APK, but would be uncompressed when the scene is loaded, so they will only have to be decoded once on the load of the scene instead of every time it has to be played
The problem is partly os related but just as much driver related. Comparing two android phones is like comparing two pc’s with different sound cards. Glenn and Raph was giving a pretty good talk about low latency audio at Google I/O earlier this year.
Yep latency is still brutal but it is Extremely device dependent. My Quad Core Sony Xperia Z has up to 0.5 s delay on Android 4.2.2 but a mate’s 2.3 HTC and another 2.3 Samsung show no lag at all!
Basically, I have set my output buffer to (256, 2) which is ultra small and this is the only way I can make the delay significantly small. All other things I’ve tried actually produce no difference AT ALL.
I read somewhere that Android likes 48k sampling but a Debug.Log of outputsamples shows clearly that it is in fact 24000 and I am beginning to think that this is what is causing my problem.
The latency will always be there. If your sound is not a result of player’s interaction you could potentially play the sound early on purpose. (You know there will be a collision, so you can play the sound early) Each device has different latency, but a safe number is 0.1ms.
Or you could go native to make instantaneous play faster. I just made Native Audio asset store plugins which can make a native call to both iOS and Android’s fastest native way from one central interface. Unity Asset Store - The Best Assets for Game Making
There are various ways of playing audio at native side, here’s my choice :
On iOS it uses OpenAL. It is faster than AVAudioPlayer, AudioToolbox, and SystemSound.
On Android it uses AudioTrack, I confirmed it to be faster than SoundPool and no meaningful difference from C++ side OpneSL ES of NDK.