Circular Buffers with OpenAL

I am fiddling around with OpenAL again, and I found a really nice 8 minute space themed music track on OpenGameArt.org. Now I want to decode it and play it. I believe my decoding works, but I was looking into streaming it because it is so massive.

The sound decodes about 2mb, which causes some Heap memory errors among the bigger goal.

What I would like to do is:

  • Decode all of the file into a ByteBuffer
  • Write it in chunks to a circular OpenAL buffer
  • Play the sequence of OpenAL buffers

I have looked into how LibGDX does it, so I understand that it involves the usage of two core commands:
alSourceQueueBuffers
alSourceUnqueueBuffers

However I need some help understanding exactly how to use these commands to achieve circular buffers and play the 8 minute ogg file. Any help would be appreciated.

What about the OpenAL documentation for these methods is unclear? :-\

I guess I’m just having trouble wrapping my head around it.

Is it essentially using alBufferData and loading the chunks into buffers and then sending an intbuffer of those buffers to openal with alSourceQueueBuffers?

you enqueue buffers with:
alSourceQueueBuffers

once a buffer has been played, you are ‘notified’ through the return value of:
alSourceUnqueueBuffers

So I call alSourceQueueBuffers with each buffer chunk and then how do I play them sequentially or know when to play the next one?

Tell me which part of the docs (that you actually read) is unclear to you.

Even a tiny bit of trial and error gets you quicker answers than forum posts.

First decouple your ‘feature’ from OGG and circular buffers. Just play a tiny chunk of audio samples (say, a sine-wave) and try to use the aforementioned methods to play it indefinitely, without using OpenAL’s looping. You’ll quickly figure out how it works. (and if not, read the docs)

I read the OpenAL guide here: http://web.archive.org/web/20110513043311/http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf (see page 59-60)

I also read the javadoc for LWJGL here: http://javadoc.lwjgl.org/

I also looked through the LibGDX lwjgl backend source and googled for people with similar questions.

I understand what you are saying about trial and error. I have loaded ogg clips before, the only new addition was a sound this large and I need a way to write chunks of the sound to OpenAL at a time to free up some memory, and the places I looked suggested a circular buffer of OpenAL data.

Sorry for double posting, but I think I may be back on the right track after looking at slick2d source (https://github.com/ariejan/slick2d/blob/master/src/org/newdawn/slick/openal/OpenALStreamPlayer.java)

Basically to play the sound I:

  • Upload the sound to buffers with alBufferData
  • Call alSourceQueueBuffers and then alSourcePlay

To stop the sound I:

  • Call alSourceStop
  • Unqueue the buffers with alSourceUnqueueBuffers