[Openal] Playing multiple sounds
Jason Daly
jdaly at ist.ucf.edu
Tue May 1 20:58:12 PDT 2007
Chris Robinson wrote:
> On Tuesday 01 May 2007 06:27:19 pm Ben Martin wrote:
>
>> I am working on a game using OpenAL and OGGVorbis with about 50
>> different sounds. Several of these sounds can be played simultaneously
>> at any given time. In my first implementation, I was creating several
>> OpenAL contexts and I was assigning the sounds to be played to each
>> "player" using round robin. I know this is a very poor implementation so
>> I want to redo it using multiple sources instead of contexts.
>>
>> Most examples I found either have only 1 source or each source is
>> associated with only one sound buffer. I don't want to create 50 sources
>> as I think this can cause problems with some systems (correct me if I'm
>> wrong).
>>
>
> To play a sound, you must have a source object. Whether you have 1 context
> with 50 sources, or 50 contexts with 1 source each. A sound is played from a
> source, and heard by a listener.
>
> Basically think of it as:
>
> Buffer = what's played
> Source = how/where it's played
> Listener/context = how/where it's heard
>
> Moving the listener 5 units to the right would be the same as moving the
> source 5 units to the left (assuming AL_SOURCE_RELATIVE is false).
>
> A single buffer can be attached to multiple sources, so for instance, if you
> have an explosion sound effect, you can have multiple sources playing an
> explosion all at different places and times, but only need the sound loaded
> in one buffer, and heard by one listener (the "camera").
>
> Hope this helps.
>
Just to add to this. Depending on the implementation, you might or
might not be able to create 50 sources at once. A typical maximum
source count would be 32 or so, but some of the native devices (like the
Audigy and X-fi) can go as high as 62 or more (on the other hand, some
implementations might not have any fixed limit at all). What this means
is you can't assume that you'll have a particular number of sources to
use, although I believe you're guaranteed at least 16 (check the spec to
be sure).
Essentially, this means you won't necessarily be able to play 50 sounds
at once. Probably, the best thing to do is to first get your app
working with whatever number of sources you can generate. Then, you can
work on a source management scheme, where you may have lots of sounds
active, but only a given number actually making noise at once.
Practically, most people can't distinguish between 50 sounds all playing
at once, so you can get away with a prioritization scheme where only the
most "important" sounds are actually audible at any given time.
--"J"
More information about the Openal
mailing list