[Openal] openal output timing

Chris Robinson chris.kcat at gmail.com
Sat Feb 28 11:03:32 PST 2009


On Saturday 28 February 2009 8:57:06 am Daniel wrote:
> Hi,
>
> Can I use AL_SAMPLE_OFFSET to estimate the exact time the next sample I
> put in the openal queue will  by heard in the loudspeakers ?
>
> If not, how can it be done to achieve the minimum error ?  How many
> miliseconds is this error supposed to be ?

Hi Daniel.

I think the simplest way to determine when the next sample you put into a 
queue will be heard is by taking the total length (in samples) of the queue, 
then subtracting the value gotten from AL_SAMPLE_OFFSET. You'll have to keep 
track of the size of the queue yourself, but it shouldn't be too hard if each 
buffer is a fixed size (decrease the size when you unqueue, increase when you 
queue).

This should be close enough for most purposes. There may be an additional 
delay introduced by the sound card itself, but this likely won't exceed 20ms 
or so. There isn't any way to measure this, unfortunately.

> I'm asking about AL_SAMPLE_OFFSET because AL_SEC_OFFSET  always returns
> zero, and i think i can simply convert between samples to seconds.

Just to note though, make sure you're retrieving the value as a float. If you 
get it as an int, or convert it to an int, it will be truncated to the lowest 
integer. For example, if the buffer is at 0.2 seconds (8,820 samples for 
44.1khz), or 0.5 seconds (22,050 samples for 44.1khz), or anything below 1 
second, the value will get truncated to 0.


More information about the Openal mailing list