OpenAL - determine maximum sources
Asked Answered
G

3

21

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

Guatemala answered 20/5, 2010 at 7:56 Comment(1)
Isn't OpenAL provide as much sources as it is needed, event if it will be rendered by soft? The OpenAL contex have only a hint(given at creation time) about how many sources your application may have. I think you should left this configurable by performance need.Oscine
H
15

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.

Hakan answered 8/7, 2010 at 13:9 Comment(3)
my X-FI can play 1024 source at the same time.Indite
Good answer, but kind sad :( As of 2012, is this still the best it gets?Bookstall
This OpenAL feature seems to be basically undocumented. You can read about it in their mailing list here: openal.996291.n3.nabble.com/… It is likely that querying the max sources like in your or uray's answer (simpler) should however work anyway. In another mailing list (here: openal.996291.n3.nabble.com/…) you can read that OpenAL Soft is the way to go nowadays (even according to Creative employees).Xiomaraxiong
L
8

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.

Louisalouisburg answered 16/10, 2013 at 18:8 Comment(2)
Note if you have 32 sounds playing, and you alSourceStop(), then alSourcePlay() immediately afterward, you still get the -1 error. So the actual maximum number of sounds you should have playing simultaneously on iOS is 31.Louisalouisburg
test the hardware platform and code-in the max simultaneous SFX yourself. Unless you're developing for iOS only, I don't think that's realistic. And even then, that's quite a lot of devices already.Xiomaraxiong
I
4

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.

Indite answered 29/7, 2010 at 0:23 Comment(4)
ALC_STEREO_SOURCES and ALC_MONO_SOURCES are params for requesting capabilities by context creation - not for querying them. More on this topic in this bookRedmund
@KrzysztofPrzygoda: Actually what was proposed in this answer works fine (on my machine at least).Xiomaraxiong
Maybe, but this is rather strike of a luck.Redmund
@KrzysztofPrzygoda According to the OpenAL devs at creative themselves, the situation seems a bit murky. From what I understood, they added those constants as hints, but should also be queriable. Eg. you pass the hint to the context creation and later query what you actually got. The spec seems unclear about it, but what I described seemed to have been their intention. You can read about it in their mailing list here: openal.996291.n3.nabble.com/…Xiomaraxiong

© 2022 - 2024 — McMap. All rights reserved.