Lesson #10 (queing buffers)

By queing buffers it is possible to assign multiple buffers to the same source that will be played in order.

Instead of using albufferdata use:

alSourceQueueBuffers(source, numbuffers, @buffer);

This will assign multiple buffers to the source. Just use alsourceplay to start playing the sounds.

Be aware that sources using qued buffers may not be looped!

Why is this usefull you may think. Well for streaming a large wave file for example.

For making that possible you need to use a time that checks from time to time what buffer has been played. That goes like this:

  alGetSourcei(source, AL_BUFFERS_PROCESSED, @processed);
  if processed = 2 then

Here we start playing the source from buffer one again when the last buffer (buffer two) has been played. Thus giving a faked looping effect.

In the attached example we play two wave files qued. In real life you would read out parts of one wave file and thus create a streaming effect. But that would require another tutorial.