audiostreamingcore-audioopenal

openal: Get the current playing position of a source


How do you get the current position of a playing source in openal? I guess I mean, what position in the audio is currently playing on the hardware after its gone through your buffers, openal's buffers, the hardware buffers, etc.

I've had a brief look at the api but I'm not quite sure what AL_SAMPLE_OFFSET/AL_BYTE_OFFSET/AL_SEC_OFFSET are meant to represent. If I am playing a streaming source, I don't seem to get a constantly increasing number, it seems maybe I'm getting a position in the current playing buffer? (or of all buffers?)

for example, while playing, I loop and run this code:

alGetSourcef( sources[0], AL_SAMPLE_OFFSET, &secoffset );
printf(" - %f samples\n", secoffset);

and get

 - 0.000000 samples
 - 8192.000000 samples
 - 9216.000000 samples
 - 5632.000000 samples

which doesn't seem to be increasing.

This is on macos 10.7 with latest xcode 4.3 but I'm assuming it should be similar on other platforms.

update:

I've tried increasing the buffer size and it does actually look like its only the current position in the currently playing buffer:

 - 0.000000 bytes
 - 18432.000000 bytes
 - 20480.000000 bytes
 - 36864.000000 bytes
 - 36864.000000 bytes
 - 55296.000000 bytes
 - 55296.000000 bytes
 - 73728.000000 bytes
refilling buffer 2408
re-queued buffer 2408
 - 16384.000000 bytes
 - 34816.000000 bytes
 - 34816.000000 bytes
 - 51200.000000 bytes
 - 51200.000000 bytes
 - 69632.000000 bytes
refilling buffer 2409
re-queued buffer 2409

So given that, is there a decent way of keeping track as openal plays through multiple different buffers?


Solution

  • Those offsets are from beginning of queued buffers. You need to manually count size of already unqueued buffers and add to this number.

    Here, if you read the documentation, it says on page 40:

    The position is relative to the beginning of all the queued buffers for the source, and any queued buffers traversed by a set call will be marked as processed.