[Openal] Max number of sources (and legit id values) for each OpenAL implementation

Chris Robinson chris.kcat at gmail.com
Wed Jul 22 14:44:36 PDT 2009


On Tuesday 21 July 2009 5:49:33 pm E. Wing wrote:
> Now I recall that there is a possibility of sounds being dynamically
> diverted to meet other demands which means a source could refuse to
> play even if you've already generated it. Can this still happen with
> the current implementations?

Yes. Another process playing a sound can (temporarily) take a hardware voice a 
source would need, so even though you have an unused source ID, it may fail to 
play. Multi-channel sources also tend to need multiple hardware voices, taking 
away from what other sources would need.

The three points of failure due to lack of hardware voices can usually be: 
alGenSources, alSourceQueueBuffers (if no sources are queued yet), alSourcei 
(with AL_BUFFER), and alSourcePlay. Technically, it can be at any time, but 
these are the most likely points for a hardware implementation to allocate the 
physical voice. Creative's hardware drivers I think do it at 
alSourceQueueBuffers and alSourcei.

> > We used to ship an OpenAL implementation that would return 0 for a valid
> > Source ID.  However we
> > found some problems in the field with games that were doing things like
> > ...
> >
> > if (sourceID)
> >       // found valid source do something with it
> >
> > instead of ...
> >
> > if (alIsSource(sourceID))
> >       // found valid source do something with it
> >
> > So we changed our implementations to stop returning an id of 0.  However,
> > as you say, the spec. does
> > not disallow Source IDs of 0 - so code should always use alIsSource() to
> > validate a Source ID.
>
> Thanks, that's good to know. If a 1.2 spec is ever made, I would like
> to see 0 be reserved for just this reason.

Ditto. Without a reserved source ID that's never used, it would be impossible 
to tell if a given ID should be valid. Using alIsSource can return false 
positives if the "default" source ID value happens to be used by another 
sound. Eg:

ALuint sID = 0;
alGenSources(1, &sID); // fails
...
if(alIsSource(sID))
    // found valid source do something with it

The alIsSource can still succeed if 0 was previously allocated as a source ID. 
Another flag would be needed to say if a given object has successfully 
allocated a source or not.


More information about the Openal mailing list