Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

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'm developing an RTS game and I would like to add sounds to it. My choice has landed on OpenAL. I have plenty of units which from time to time make sounds: fSound.Play(sfx_shoot, location). Sounds often repeat, e.g. when squad of archers shoots arrows, but they are not synced with each other.

My questions are:

  • What is the common design pattern to play multiple sounds in OpenAL, when some of them are duplicate?
  • What are the hardware limitations on sounds count and tricks to overcome them?
share|improve this question
up vote 2 down vote accepted

For every sound you'll have a buffer. Multiple sources can reference the same buffer.

So for example you'd have a buffer that was loaded from 'archerShot.wav' and all the archers can reference this.

In terms of design patterns there's a variety of solutions. One is the Publisher/subscriber pattern (wikipedia). The individual game objects can contain a sound enumeration variable (that can represent a variety of sounds) which would be picked up by the sound system and played after every frame. The advantage of doing it this way is that the sound system is not coupled to the entities - just like how you can separate the rendering of an entity from its logic.

This link may be of use (a thread on forums).

Hardware Limitations: This is very dependant on your target hardware and I don't think there is a general answer. The iPad and iPhone can only play one compressed buffer at a time. If you allow the users to play their music on the device this means you can't rely on being able to play any compressed sound buffers.

share|improve this answer

I use a Pool pattern.

On iOS there is a maximum of 32 sound sources playing at one time. So at program start, I create 32 ALSources (the ALSourcePool), and when a new sound needs to play, it asks the Pool for a SoundSource to use.

If there are no free sources, one of the playing sources is stopped and that source is given to the caller.

Another level of management is to classify the pool into groups. Voice-over should never be cut off by an archer's bow being let, so I am going to designate, say sources 1-8 for "unit sfx", 8-12 for explosions ... and reserve sources 30-31 for voice comments (so in game voice notices are never overridden by any other sound).

share|improve this answer

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.