2

In DirectSound, there was a very distinct concept of circular buffers

In particular there was a current read position, a current write position, and clear methods to GetPosition and lock the buffer and start writing.

enter image description here

I'm looking for a similar concept in OpenAL, but all I can find is looping an AL_STREAMING buffer, and using AL_SAMPLE_OFFSET to determine the current read position (and write say, 15 samples after that?)

OpenAL docs are down right now, but accessible here.

What is a safe way to declare a sound buffer that gets written to by the application as it is playing? Am I right about using a looping streaming buffer?

bobobobo
  • 64,917
  • 62
  • 258
  • 363

1 Answers1

3

Actually circular buffers in OpenAL are much different than for DirectSound.

In OpenAL, you must queue sound buffers, one after the other. You really only need 2 sound buffers then, and you just continuously call alSourceQueueBuffers and alSourceUnqueueBuffers.

Queuing Buffers on a Source To continuously stream audio from a source without interruption, buffer queuing is required. To use buffer queuing, the buffers and sources are generated in the normal way, but alSourcei is not used to attach the buffers to the source. Instead, the functions alSourceQueueBuffers and alSourceUnqueueBuffers are used. The program can attach a buffer or a set of buffers to a source using alSourceQueueBuffers, and then call alSourcePlay on that source. While the source is playing, alSourceUnqueueBuffers can be called to remove buffers which have already played. Those buffers can then be filled with new data or discarded. New or refilled buffers can then be attached to the playing source using alSourceQueueBuffers. As long as there is always a new buffer to play in the queue, the source will continue to play.

bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • 1
    A while ago, I posted code demonstrating some simple code for microphone-to-speakers with optional filtering: http://stackoverflow.com/questions/4087727/openal-how-to-create-simple-microphone-echo-programm This demonstrates the realtime editing that you're looking for. – JCooper Dec 17 '12 at 18:54