# Alternative to soundeffect.play()?

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 soundeffect.play() method is called to play the explosion. I would like to know if there is a more efficient way of playing the explosion soundeffect?

• 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

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.