android gdx sound performance issue -


i'm building scrolling shooter libgdx. in windows, runs fine, on android noticeable jitter , framerate drops 61 fps avg without sound 48-56 fps avg sound. plays lot of small sound effects concurrently there lot of bullets fire , enemies hit @ once. sound routine:

import com.badlogic.gdx.gdx; import com.badlogic.gdx.audio.sound;  public class soundfx {      static final int bgdie = 1, bghit = 2, bglaser = 3, bgspawn = 4, pdie = 5, phit = 6, plaser = 7, pspawn = 8, pause = 9;     sound s_bgdie, s_bghit, s_bglaser, s_bgspawn, s_pdie, s_phit, s_plaser, s_pspawn, s_pause;      public void load()     {         s_bgdie = gdx.audio.newsound(gdx.files.internal("data/sfx/badguydie.mp3"));         s_bghit = gdx.audio.newsound(gdx.files.internal("data/sfx/badguygothit.mp3"));         s_bglaser = gdx.audio.newsound(gdx.files.internal("data/sfx/badguylaser.mp3"));         s_bgspawn = gdx.audio.newsound(gdx.files.internal("data/sfx/badguyspawn.mp3"));         s_pdie = gdx.audio.newsound(gdx.files.internal("data/sfx/playerdie.mp3"));         s_phit = gdx.audio.newsound(gdx.files.internal("data/sfx/playergothit.mp3"));         s_plaser = gdx.audio.newsound(gdx.files.internal("data/sfx/playerlaser.mp3"));         s_pspawn = gdx.audio.newsound(gdx.files.internal("data/sfx/playerspawn.mp3"));         s_pause = gdx.audio.newsound(gdx.files.internal("data/sfx/pause.mp3"));     }      public void unload()     {         s_bgdie.dispose();         s_bghit.dispose();         s_bglaser.dispose();         s_bgspawn.dispose();         s_pdie.dispose();         s_phit.dispose();         s_plaser.dispose();         s_pspawn.dispose();         s_pause.dispose();     }      public void play(int id)     {         switch(id)         {         case bgdie:             s_bgdie.play();             break;         case bghit:             s_bghit.play();             break;         case bglaser:             s_bglaser.play();             break;         case bgspawn:             s_bgspawn.play();             break;         case pdie:             s_pdie.play();             break;         case phit:             s_phit.play();             break;         case plaser:             s_plaser.play();             break;         case pspawn:             s_pspawn.play();             break;         case pause:             s_pause.play();             break;         default:             system.out.println("invalid sfx call");             break;         }     } } 

play gets called 4-10 times second depending on what's happening in game, sound effects less second in duration , on avarage 8kb each.

what's going on here, , how can fix this? makes game unprofessional , on hard levels unplayable.

a little background problem why notice such big drop in performance when playing multiple sounds. because underneath covers libgdx needs mix sounds before playing them user. when number of sounds running concurrently demands on system mixing becomes noticeably high. since trying play sounds on rendering thread increase in demand results in drop in framerate.

in experience sort of sound effects in games, when encounter situation have lot of small sounds playing concurrently there few solutions. write these more general solutions specifics libgdx:

1) play sounds on single thread

this doing, while doesn't work once large number of sounds playing easy implement , situations works. however, once enough sounds playing notice lag , poor quality.

2) play sounds on separate thread rendering thread

this 1 possible approach (and depending on if framework allows), not because doesn't scale well. however, if suffering minor performance loss , aren't expecting play huge number (~20+) of sounds concurrently relatively minor change , fix problem.

3) play sounds upto cap

this solution bit more work, , may not acceptable if have sounds must played. track number of sounds playing , allow additional sounds played until hit point. above cap not played. allows guarantee level of performance. biggest downside method if play sound when character critically injured , doesn't played, may upset user listening sound know if going die soon, instead find dead.

4) selectively play important sounds

this bit more difficult implement works extremely setting cap on performance. want determine priority sound played. close you? loud? important? then, play sounds important enough play upto cap (could 4, 6, 8, etc). need keep track of how many sounds playing determine how many new sounds can play @ given point.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -