emir
New Member
Posts: 3
Posts: 3
|
Post by emir on Oct 29, 2014 15:02:04 GMT
We're on the phase of optimizing our game and I'm noticing some frame spikes caused by SoundGroupVariationUpdater.Update(). I've attached a picture of the profiler. At one instance, the function takes over 70ms to complete. I imagine the functions complexity depends on how sound is used, but I can't really say that I'm doing anything strange. I'm using playlists for background music and sound groups for sound effects. I'm playing the sound effects using MasterAudio.PlaySoundAndForget. Why is the function taking so long to complete? Tested on Samsung Galaxy S3 using Unity 4.5.5 and MasterAudio 3.5.5.5. Attachments:
|
|
|
Post by DarkTonic Dev on Oct 29, 2014 16:40:05 GMT
I'll need more information. That script has nothing to do with Playlists, it's just for SFX. I normally do all my testing inside Unity. I'm not sure how you actually get profiler readings from an Android device, maybe you can point me to a tutorial?
1) Are you using any Resource files? 2) Are you "following caller" for the sounds? 3) Have you turned on Auto-Prioritization? 4) Are you using Custom Fading for the Variations? 5) Was the screen shot taken at a time when you were otherwise fading the Variations (fade to volume / fade bus etc). 6) Were you playing any Chained Loop groups?
These are the 6 things that take up CPU and time. Are you able to do a Deep Profile? I can't imagine what would be taking that long to execute off hand.
|
|
|
Post by DarkTonic Dev on Oct 30, 2014 3:05:11 GMT
So far I've tried #2, #3 and #4 from above and I'm still seeing on my computer (not phone) no higher than 0.07ms on the profiler from the Updater script with 5 calls. So I would guess those aren't the problem. Still trying the others.
Looks like actually playing the audio source is taking 2-3ms apiece, which is the normal Unity part that I can't fix. I'm going to try some things.
|
|
|
Post by DarkTonic Dev on Oct 30, 2014 4:31:22 GMT
Ok, I did some reading and experimenting. I am willing to bet that one or more of your sound effect "Variations" is an mp3. I see that a single AudioSource.Play() with an mp3 file will take about 2.4ms. Whereas AudioSource.Play with a wav file takes 0.02 seconds. So I think most of your problem is from this (which is Unity functionality) and a tiny other percentage of processer time is being taken by Master Audio code.
Anyway, this is new knowledge to me, and I'm going to add this information to the readme under the Best Practices section.
If you find other information, please let me know.
|
|
emir
New Member
Posts: 3
Posts: 3
|
Post by emir on Oct 30, 2014 10:02:04 GMT
Sorry for the late reply. To use the profiler with an android device, switch platform to android and follow the android section of this guide: docs.unity3d.com/Manual/Profiler.html1) Are you using any Resource files? No. 2) Are you "following caller" for the sounds? No. 3) Have you turned on Auto-Prioritization? Not that I know of. 4) Are you using Custom Fading for the Variations? Yes, but the problem persist even after disabling the Custom Fading. 5) Was the screen shot taken at a time when you were otherwise fading the Variations (fade to volume / fade bus etc). No. 6) Were you playing any Chained Loop groups? No. " I am willing to bet that one or more of your sound effect "Variations" is an mp3" This is not the case. I've attached screenshots of my sounds folder and the import settings on the clip manager. All SFX are imported as Native and Stream from disk. I'll do some more testing and get back to you if I find anything else. Attachments:
|
|
emir
New Member
Posts: 3
Posts: 3
|
Post by emir on Oct 30, 2014 10:10:09 GMT
The problem seems to go away if I change the import settings to "Compressed in memory" instead of "Stream from disk"! What is the recommended setting here? Uncompressed + Compressed in memory is maybe the same thing as decompress on load?
|
|
|
Post by DarkTonic Dev on Oct 31, 2014 0:39:38 GMT
If you're seeing the options of "compressed in memory" or "decompress on load" then it's an mp3. So it will be very very slow to play that as a SFX. I'd covert those all to wav files. Wav files only show "stream from disk" and "load into memory". Load into memory is the fast one. Stream from disk should never be used for SFX either because you should never stream more than one file at a time for performance reasons. So that should be reserved for music only, and only when you're not using Resource files for music (which is usually the better option).
I just added this info to the readme under the Performance Tips section at the end.
|
|