About 16 sounds limitation, buffers vs sources

Hi!
Hello everybody, this is my very first post here in JOAL.

I happened to have my thinkings about that limitation problem. Before I read a post before about the 16 sounds limitation, I was thinking of a dynamic or simulated dynamic way of loading sounds.

After I read that nice post, my first question is:

  • Is the limitation on the number of sources or in the number of buffers?

As in that post, I have to deal with many more than 16 sounds - but i would like to have the game compatible with any sound card, and I dont think I’ll need more than 16 sounds at the same time. My idea is to implement some kind of replacing algorithm, taking into consideration the PRIORITIES of the sounds (i.e. I should not replace the Background sound, for example). But then, I found myself unable to fully understand the next question…

  • how should I manage a buffer, that is currently connected to a source (either playing or stopped) to load another sound on it, then link the source to the buffer and play the sound after? What happens with the data that was in the buffer and in the source before?

  • I see in the other post that it is recommended to load ALL SOUNDS on the buffers, but… if there are kind of 100 sounds, may it work?

Even if i have went through the tutorials and played with JOAL a fair bit, it may happen that I am confused about the entities in JOAL… please, could somebody help me?
Thank you very much!

Here is the other post about the 16 sounds limitation, sorry. It may be handy to have the link:

http://192.18.37.44/forums/index.php?topic=9968.0

… thanks tom for the “recommendation” for how to use buffers and sources in a real game… but, does that mean ALL the sounds have to be loaded at startup in the buffers? ALL are a lot of sounds… :slight_smile:
Thanks again


         try
         {
            AL.create();
         }
         catch (LWJGLException exc)
         {
            exc.printStackTrace();
         }

         IntBuffer address = BufferUtils.createIntBuffer(1);

         int i;

         for (i = 0; i < 1024; i++)
         {
            try
            {
               AL10.alGenSources(address);
            }
            catch (OpenALException exc)
            {
               break;
            }
         }

         System.out.println("Max Sources: " + i);

         for (i = 0; i < 1024; i++)
         {
            try
            {
               AL10.alGenBuffers(address);
            }
            catch (OpenALException exc)
            {
               break;
            }
         }

         System.out.println("Max Buffers: " + i);

I get:

Max Sources: 256
Max Buffers: 1024 (this is where the loop terminates)

Nice! Thank you very much for your answer!
But that is dependent from the sound card you are using, isn’t it? Which one is it, btw?

As you may imagine I am coding a game to use in the net. Since there are battles and stuff, it is likely that will be maybe 100 sounds (actually i dont know, it will depend on another people rather than me :slight_smile: and well, if I have more sound files than buffers then I have to implement a circulating algorithm for the buffers… which is the thing I have done now (circulating through an array of 16 buffers, and saving like from 0-2 for the background sounds, from 3-6 to other looped sounds, etc.). And it works, but with some limitations. i have to admit it’s not nice at all to have to deal with that algorithm…
Anyway it seems to be needed to circulate through the sounds… isn’t it?

do you think of another (better) way to do that?
Thank you very much

As you can read in the other thread Buffers are not really limited. So you only have to manage your Sources.

My card is a stone-age one: Montego A3D by Turtle Beach (8 years old!)

It kinds sucks as there are only drivers for Win98 and running I’m WinXP, so all my 3D sound is just plain stereo ATM. Maybe that’s why it supports so much sources :wink:

There should be no limit on the number of buffers OpenAL can handle. I don’t know what rinschwinders problem was in the other thread. May have been a bug in his hardware or driver. So load as many buffers as you like. The limit is the amount of ram you are willing to spend on having the sounds in memory. Large sounds and/or rarly used sounds can be streamed from ogg files. This is commonly used on background music.

There is a limit on the number of sources available. This depends on the sound card, and 16 is the minimum (wich is what I have on my computer).

When implementing a priority based engine, you can just stop the sound with the lowest priority and start a new sound on the same source. The only problem is that this may cause a “clicking” sound wich is quite anoying. Have found no way around this far from implementing a software mixer.

Many thanks to both.

Apparently, my implementation is doing a stupid kind of thing:

  • Array of buffers [16]

  • Array of sources [16]

  • An undefined number of source files (this implementation is independent from that, because there are only 16 at a time).

  • Make correspond source[i] with buffer[i]. this way, when we want to load a sound, we load the buffer and then load the source. If there was an existing buffer/source; then stop the sound, delete previous buffer/source, and gen a new buffer with the new sound file, gen a new source, bind them and play.
    Well, it does work… but reading what you said, it seems to be kind of nonsensical thing with the buffers… isn’t it?
    Should it be just terms of performance or do you think this can issue another kind of errors?
    (Bear in mind that, if a sound is requested twice(or n times), there will be two (or n) buffers loaded with the same sound… what seems to be possible anyway, since this is working - on the small, so far)

Thank you very much for your answers, you are saving my day :slight_smile: please continue doing it :stuck_out_tongue:

Actually - and surprisingly though - , my approach is working fine, so I can hear at the same time a lot of guns (the infamous sound from the tutorials :wink: )
Each time a sound is loaded both in the buffer and in the source… circulating in a buffer of 17, and beginning again dispatching the first one that was used, and creating the new one there.

OK, it looks bad… but it works. At least in my computer :slight_smile:
Any suggestions, improvements or nagging welcome…

Thanks to all!

Incredible… look at this:

Max Sources: 102400
Max Buffers: 102400

// –
al = ALFactory.getAL();
ALut.alutInit();
al.alGetError();

			int[] address = new int[1];
			int i;
			for (i = 0; i < 102400; i++)
			{
				al.alGenSources(1,address);
			}
			System.out.println("Max Sources: " + i);
			for (i = 0; i < 102400; i++)
			{
				al.alGenBuffers(1,address);
			}
			System.out.println("Max Buffers: " + i);

Yeah yeah… guess what…

AL is making a zillion errors, and you just ignore them.

check al.alGetError() after every alGen{XYZ} and you’ll see the true numbers.

Why the 1:1 mapping between source and buffer. A buffer is a sound loaded into memory that OpenAL can play. A source can play one buffer at a time. So load all your sounds into buffers at startup and forget about the source files. Then grab as many sources as you need or can get. Then manage what buffer to play with what source. To play a new buffer on a already playing source, stop the source, bind the new buffer and press play.

Sure it makes more sense.

But I have already implemented the other version, and it is working fine…