How many sources could openal gen?

Started by
6 comments, last by Drew_Benton 18 years, 7 months ago
Hi every one! In our game i use openal to play sound, i totally need 64 source to play 3d sound, but when i called alGenSource, it can only gen 16 of them. Does anyone konw the max number of the source could be gen. and in openal's doc, it doesn't limit the max source number, does anyone know about it.
Advertisement
The number of sources should be unlimited, but the number of them you can have playing at once is limited by your hardware. Also, why do you need 64 of them? You'll find it easier to have a list to manage your sources, removing the ones that are no longer playing, and you'll find the number of sources will rarely reach 64.
I think the number of sources depends on how many your sound card/hardware can handle. For example, in a recent review of the X-Fi (don't remember where, comparison to Audigy 4), they tested with 128 voices, and the X-Fi could easily handle 128 voices with little increase in CPU usage, while the Audigy 4 couldn't even run 128 voices. So it depends on your hardware I guess. Like other people have said, you'll probably never need 64 voices at a time. Try to rethink your audio strategy.

Cheers!
- fyhuang [ site ]
Ok this is how it works:

Sources represent the interfaces to audio ports on the sound card. You can only allocate as many as the sound card supports. 16 is a safe number that most cards should support. 32 is common, but really, anything over 16 is just not needed (unless you are making an audio editing program). You should only allocate 16 sources to use to play. At any given time, that means 16 different buffers can be playing. You do not allocate a source for each sound you want nor deallocate the sources until you are done with the program!

Buffers represent the sounds that you want to play. You will allocate/deallocate buffers freely as you need to to keep track of your sound objects. Techniqcally, you can allocate an unlimited amount of buffers, but remeber the computer resource limitations.

Now to get everything all tied together this is what you will need to do:
1. Create a sound managing class.
2. Have your array of 16 sources.
3. Have your vector of buffers.
4. When you want to play a buffer, you will scan the source array to find one that is not currently in use. You send that buffer to that source.
5. When a buffer is done playing, that source will become free for the next buffer to use.

So to explain some more, you should keep an array of the source states that you update every so often in your update function. In your play function, you scan that array to find a free source. When you do, you set that source's state to being "in use", so the next time Play is called, that source will not be used. Finally, you are left with a self managing system, since the update function automatically updates the states of the source buffer state array.

If you meed any other explanaions feel free to ask.
thanks every one, i think i can use the strategy you mentioned above. But one more question. How do i managed the the 3d sound in those strategy. Each 3d sound has it's own position. If i just gen 16 buffer, this means i could just have 16 3d sound played in same time (of course each with it's own different positon).How do i managed when i had 17 or more 3d sound to play in same time. Because the position attribute is binding to the Source object in openal. According to the source numbers limitation, i could just have 16 postion, how do i handle the 17th. BTW, ths Dsound bind the source and buffers as one whole object, IDirectSound3DBuffer8. Does it has the same number limitation when i create IDirectSound3DBuffer8 in Dsound. Hope anyone can help me.
Quote:Original post by crazyjsbach
How do i managed the the 3d sound in those strategy. Each 3d sound has it's own position. If i just gen 16 buffer, this means i could just have 16 3d sound played in same time (of course each with it's own different positon).


That's just a matter of you keeping track of the postions with the buffers yourself. For example, make a sound class that stores all the required sound information. Then tie that in with the sound manager, and ta-da! You are done.

Quote:How do i managed when i had 17 or more 3d sound to play in same time. Because the position attribute is binding to the Source object in openal. According to the source numbers limitation, i could just have 16 postion, how do i handle the 17th.


Well if you really need more sounds playing *at one time* than you can handle, you can go ahead and generate more sources and use it, or you can just limit yourself to 16 simutaneous sounds playing at once. Just keep in mind that realistically, 16+ sounds playing at the same time is not very practical. I mean I am by no means an expert, but from what I have seen working with sounds and some games, I couldn't get that many sounds playing at once even if i wanted to (and still have it sound fine).

Quote:BTW, ths Dsound bind the source and buffers as one whole object, IDirectSound3DBuffer8. Does it has the same number limitation when i create IDirectSound3DBuffer8 in Dsound.


DSound setup is very different from OpenAL [wink] I do not have that answer, but any sound library will have limitations based on the hardware present.

To give you a better overall idea here's some pseduo/code:
class cSound{   ALint X,Y,Z;   Aluint buffer;   int myID;   ...   void SetX();   ...   void GetX();   ...   void LoadSound( char* fileName );};class cSoundManager{   ALuint Sources[16];   bool States[16];   ...   std::vector< cSound* > soundList;   ...   void AddSound( cSound* );   void PlaySound( int index )   {      int UseSorce = FindNextAvaliableSource();      if( UseSource != -1 )          // Send buffer to source          // Start playing source   }   ...   void Initialize()   {       alGenSources( Sources, 16 );       States[0] - [15] = {0};   }};


That's just a quick little example. I personally would use a std::map with reference names rather than a vector and ID's. Anyways just that to get you thinking some. Let us know if you have any other questions. Good luck!
use your strategy, i complete my sound engine, and it works.
thank you! Drew_Benton
But i have two more problems.
1. Under some extreme condition, i do need a lot of SE 3D sound played in same time. eg: a group of units hit by a massive destruction weapon :), and be explosive simultaneously. So i need a lot of "explosion" SE played in the same time. Any solution to fulfil this on openal?
2. How to control the total volume to a limited range. Now when some SE played in same time. The total volume become extremely loud. Is there any methods to limit the total volume under a given range.
Quote:Original post by crazyjsbach
1. Under some extreme condition, i do need a lot of SE 3D sound played in same time. eg: a group of units hit by a massive destruction weapon :), and be explosive simultaneously. So i need a lot of "explosion" SE played in the same time. Any solution to fulfil this on openal?


Well the thing you have to remember is that when something such as that happens, you do not really *have* to play *all* the sounds. ALl you do need to play is enough to where it seems as if all are playing, so you "fake it". The user wouldn't even be able to tell that sounds weren't even played because of all the action going on [wink]. So all you really need to do is play one sound for each type of sound - i.e. if you have 20 marines and they die at once, you don't need to play 20 sound of the death, one should cut it realistically if it's simoultaneous. As for adding in the logics for this to work, that is something you will have to ponder about [smile]. I don't have any immediate suggestions for that other than that of a group setup. Each time you form a group of units, there is one 'group' of each unique sound that will play, and you just play all those sounds.

Quote:2. How to control the total volume to a limited range. Now when some SE played in same time. The total volume become extremely loud. Is there any methods to limit the total volume under a given range.


For that you need to call: alSourcef ( Source , AL_GAIN, newValue ); where Source is the source you want to change the volume of and newValue is a new value in the range of [0,1] with 1 being full volume. (float 0.0-1.0)

This topic is closed to new replies.

Advertisement