tags:

views:

248

answers:

2

Is there an API that allows you to define the maximum number of OpenAL "sources" allowed by the underlying sound hardware?

Searching the internet, I found 2 recommendations :

  • keep generating OpenAL sources till you get an error. However, there is a note in FreeSL (OpenAL wrapper) stating that this is "very bad and may even crash the library"
  • assume you only have 16; why would anyone ever require more? (!)

The second recommendation is even adopted by FreeSL.

So, is there a common API to define the number of simultaneous "voices" supported?

Thank you for your time,

Bill

+3  A: 

update:

I can't find a way to determine what the maximum number of sources a device supports, but I think I've found how to determine the maximum a context supports(ALC_MONO_SOURCES). It would follow that a context supports the same number as its parent device.

//error checking omitted for brevity
ALCdevice* device = alcOpenDevice(NULL);
ALCcontext* context = alcCreateContext(device,NULL);
ALCint size;
alcGetIntegerv( dev, ALC_ATTRIBUTES_SIZE, 1, &size);
std::vector<ALCint> attrs(size);
alcGetIntegerv( dev, ALC_ALL_ATTRIBUTES, size, &attrs[0] );
for(int i=0; i<attrs.size(); ++i)
{
   if( attrs[i] == ALC_MONO_SOURCES )
   {
      std::cout << "max mono sources: " << attrs.at(i+1) << std::endl;
   }
}

This returns 255 on Ubuntu 10.4 using the stock OpenAL driver.


The long answer is well kinda...

Software based OpenAL drivers generally allow an infinite number of sources. Well, not really infinite, eventually you'll max out either the CPU or the RAM eventually.

Most hardware based OpenAL drivers only support as many sources as the hardware has channels. Modernly that is at least 16, probably 32 or more but can be as much as 256. There are probably sound cards that support more but 256 is the largest I've ever looked at.

On Windows DirectSound based drivers are arbitrarily limited to 31 (why not 32?) sources. DirectSound has been deprecated so I don't know if this still applies to Vista and Windows 7.

The iPhone supports 32 sources.

I have seen one hardware based driver that was software backed. Meaning it would give each source a hardware channel until they ran out. Then it would mix some of the sounds in software before shipping it off the the hardware. This gives the best of both worlds, near infinite sources, while still using as much hardware acceleration as possible.

In practice if you're using a hardware based driver, just keep creating them until alGenSources fails. I have heard this doesn't work on the iPhone. There a some software based OpenAL drivers that will crash before alGenSources fails.

There really ought to be an API to check the max number of sources and number of sources that are hardware accelerated. Maybe there is in the extensions.

caspin
my X-FI can play 1024 source at the same time.
uray
+3  A: 

you can query the maximum source by :

ALCint nummono, numstereo;
alcGetIntegerv(device, ALC_MONO_SOURCES, &nummono);
alcGetIntegerv(device, ALC_STEREO_SOURCES, &numstereo);

but this is not standard or in the spec of openAL 1.1 (probably will be added on 1.2), some driver (openAL implementation) can answer this query and some not, so if you're lucky you will get the answer, but if not, there no other solution than to call alGenSources() until it return error.

and you should notice that, some implementation behave differently, AFAIK for example on Apple iPhone they could create 256 source max, but you can't play 256 source simultaneously (limited to 64), so max source is not always the same thing as max concurrent play.

uray