Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAL - determine maximum sources

Tags:

c++

audio

openal

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

like image 431
Bill Kotsias Avatar asked May 20 '10 07:05

Bill Kotsias


3 Answers

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( device, ALC_ATTRIBUTES_SIZE, 1, &size);
std::vector<ALCint> attrs(size);
alcGetIntegerv( device, ALC_ALL_ATTRIBUTES, size, &attrs[0] );
for(size_t i=0; i<attrs.size(); ++i)
{
   if( attrs[i] == ALC_MONO_SOURCES )
   {
      std::cout << "max mono sources: " << attrs[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.

like image 116
deft_code Avatar answered Oct 22 '22 18:10

deft_code


The number of sources you can create via alGenSources() has nothing to do with the number of sources allowed to simultaneously play.

On the iPad 4 (the only device I have tested), the maximum number of voices you can have playing simultaneously is 32. If you try to play a 33rd sound, you get an error at alSourcePlay()

AL ERROR: -1 - AL_INVALID (general error)

And the sound doesn't play. But the source can exist, it can move, and have the various settings set for it. it just won't play until one of the other 32 playing sounds finishes playing.

I've successfully created up to 2048 sources on an iPad 4, just using a loop. That doesn't mean I can play 2048 sounds simultaneously.

So my answer is: test the hardware platform and code-in the max simultaneous SFX yourself.

like image 29
bobobobo Avatar answered Oct 22 '22 17:10

bobobobo


you can query the maximum source by :

ALCint nummono, numstereo;
alcGetIntegerv(device, ALC_MONO_SOURCES, 1, &nummono);
alcGetIntegerv(device, ALC_STEREO_SOURCES, 1, &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.

like image 4
uray Avatar answered Oct 22 '22 19:10

uray