jur9103 at October 6th, 2004 04:41 — #1
in Open Al doc. is writen this:
The AL has three fundamental primitives or objects Buffers, Sources, and a single
Listener. Each object can be changed independently, the setting of one object does not affect the setting of others. The application can also set modes that affect processing. Modes are set, objects specified, and other AL operations performed by sending commands in the form of function or procedure calls. Sources store locations, directions, and other attributes of an object in 3D space and have a buffer associated with them for playback. There are normally far more sources defined than buffers. When the program wants to play a sound, it controls execution through a source object. Sources are processed independently from each other.
well, i can have 32 sources max., but i have more than 100 sound sources in my level, but they are not played at once.
Question is: what is good way to manage sources ?
i want to create 100 sources and select 32 of them to play at once, but i dont know how to do it.
spreetree at October 6th, 2004 09:46 — #2
How I normally manage this is as follows
I create all the sound buffers that i will be playing in the level/room whatever
I already have a list of sources (up to the max available)
I request a sound to be played from a given buffer
I look through the array of sources, checking their state as i go (playing, paused stopped etc.)
I find a source that is not playing, i play the requested sound on that source
And so on and so on.
If I have no sources availabe the sound doesnt get played (you could have a priority system running in that case, where certain sounds have a higher priority that others)
I then return the source that the sample has been played on to allow the system to control the source
100's of samples (buffers) is a lot. How many of these would you exxpect to be played at the same time? Repeating sounds can all be played from the same buffer, so dont load in mutiple instances of te same buffer (just in case you are)
Hope that helps a little
jsoftware at October 6th, 2004 09:51 — #3
What i'm doing in my soundengine:
i have an array of all the sources each source containing info off it's id and position.
then i have an array of all currently playing sounds it's length is 32!
at last i have an integer variable which contains the number of playing sources.
(i'm trying to implement a function that sorts the sources by distance from listener but that'll come later..)
when i want to play a source i set playingarray[playingsources] = sources[the one i want to play];
and increment playingsources;
test to see if playingsources is higher than 32; if it is then set it to 1!
guess it can be made a little smarter but that works until now
jur9103 at October 6th, 2004 10:55 — #4
I like idea to have priority on sounds. it looks promising. i have sounds from crowd (a lot of), sounds from players, music, ambient (wind ..)
sometimes there is more than 32 sounds at once.
priority on sounds can work good. only not important sounds are not played, there is a little problem with setting distancies on sounds, because it can be set wrong and not playing some sounds can sounds strange.
i'm going to implement this, and i will write here results.
nomadrock at October 6th, 2004 13:07 — #5
You could make it easy and make a min heap based on the priority and then also on the time it has been playing so that you tend to pick sounds that have at least had a chance to get heard rather than ones that only started a few milliseconds ago.
jur9103 at October 21st, 2004 03:05 — #6
It is functional, but i think there is some place to improvements.
Who is interested to share knovledge to develop sound engine in 3d game, and is interested in source code let me know.