Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been using a profiler to optimize my game for the Xbox, my aim is as with any optimization to reduce excess CPU and memory usage. I have managed to cut down a lot of the processor time and memory used by my game. However i have a lot of bullets in my game that the player fires and every-time a bullet impacts with something the method is called to play the explosion. I would like to know if there is a more efficient way of playing the explosion soundeffect?

share|improve this question
Are you sure there is an actual performance problem with .play() for your project? Have you confirmed this, or are you asking into the blue? – Hackworth Feb 24 '13 at 12:38
I am asking if anyone thinks there is a more efficient way of playing soundeffects, particularly when i have a large amount of bullets calling the built in method. i.e. has anyone managed to create a more efficient way of doing this? – Ree Feb 24 '13 at 13:24
up vote 2 down vote accepted

You could possibly look into SoundEffectInstance. You can get one with SoundEffect.CreateInstance (and must Dispose of it when you are finished with it).

SoundEffect.Play internally creates SoundEffectInstance objects and plays them. It then adds them to an internal list so that, once that sound effect has finished playing, it is stopped and added back to a pool. The next time you call SoundEffect.Play, it will try and get a spare instance from the pool, before allocating another one.

By using SoundEffectInstance yourself, you can pre-allocate your desired number of instances of a sound, so you don't have the cost of allocation if the pool is empty. And you save the (small) overhead involved in tracking those internal "fire and forget" sound instances.

This can also allow you to limit the number of sounds playing at once (saving CPU). For example, if you create three instances of a sound (in a circular buffer), and your game has a situation where it wants to trigger that sound four times in a row - on the fourth trigger you could either cut off the oldest sound and restart it, or skip playing the new sound.

share|improve this answer
Thank You Andrew I will try this out, sounds pretty promising. – Ree Feb 24 '13 at 13:50
@Ree let us know how this plays out for performance. – ashes999 Feb 24 '13 at 14:32
No problem, i have some other things i need to sort out at the moment, but will try this out and report back as soon as i am finished, Thanks. – Ree Feb 24 '13 at 15:32
Hey Andrew I have tried out your suggestions, i would like to say that i have got some "good" results, however performance wise as you pointed out they are marginal. I have more control over the sound effects and how many can be played max at once. However the extra code needed may not be worth it for some people. It may be my implementation but if i manage to see any significant improvements i will be sure to leave a message here. Thank you for your answer. :) – Ree Feb 25 '13 at 22:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.