[Openal]How to calculate the true 'current-playing-time' for a
streaming source?
Keshav B Channa
kbc at dhruva.com
Mon Mar 3 22:45:25 PST 2008
Well I don't know if it's so straight forward.
I stumbled across this situation:
Let's say 3 buffers have completed processing. Let's assume each buffer is
of 1 second.
Hence they add up to 3.0 seconds.
Let's say there are 2 buffers currently queued up.
If I call AL_SEC_OFFSET after 'n' ms then this is what I get.
Current buffer: AL_SEC_OFFSET = 500 ms (actual playing time = 3.0 + 0.5 =
3.5)
Current buffer: AL_SEC_OFFSET = 950 ms (actual playing time = 3.0 + 0.95 =
3.95)
Current buffer: AL_SEC_OFFSET = 1250 ms (actual playing time = 3.0 + 1.25 =
4.25)
Right now the buffer has been completed, but it hasn't gone into the
'processed' list yet.
Current buffer: AL_SEC_OFFSET = 1650 ms (actual playing time = 3.0 + 1.65 =
4.65)
Right now if the first buffer is marked as processed, then the actual
playing time would be:
3.0 + 1.0 = 4.0
But if we consider the "current playing buffer" time, also then the time
becomes 4.0 + 1.65 = 5.65, which is actually wrong.
If OpenAL returns the "bytes" processed for only the current-playing buffer,
then it would work fine.
But OpenAL seems to consider all buffers queued when determining the
AL_SEC_OFFSET value.
Am I right, or am I doing something wrong here.
Thanks,
------------------------------------
-----Original Message-----
From: Ed [mailto:icelus2k5 at gmail.com]
Sent: Monday, March 03, 2008 5:33 PM
To: kbc at dhruva.com; openal at opensource.creative.com
Subject: Re: [Openal]How to calculate the true 'current-playing-time' for a
streaming source?
On 03/03/2008, Keshav B Channa <kbc at dhruva.com> wrote:
> Hi,
>
> Which is the best method to calculate the 'current-playing-time' for a
streaming source, in real-time?
>
> Right now, I'm doing this: (this is not real time determination)
> After every buffer is finished processing, I calculate the 'duration' of
that buffer, and add it to a variable.
> There is a lag of the current buffer that is already being processed.
>
> Is there a function to determine the "total bytes processed" for a
source, so that I can determine the current-time accurately and precisely?
>
> Or if you know of any other method, then please let me know.
>
> I need high accuracy for determining the current playing position.
>
>
>
> Also, the time returned by AL_SEC_OFFSET seems to be different from the
timer that I'm using.
> Has anybody else had this problem?
AL_BYTE_OFFSET tells you the amount of bytes from the start of the
queue that have been processed. AL_SEC_OFFSET tells you the seconds
from the start of the queue that have been played. If you're
streaming, you're pulling buffers off the start of the queue and
pushing them to the end regularly. The easiest method I know is every
time you pull a buffer off the queue, add its play time to your stored
"time played before queue start" variable. (which obviously starts at
zero when you start the stream). Then add AL_SEC_OFFSET to get:
total time played before queue start + total time played in queue = total
time
I haven't actually tried this (I'm still working on my stream api!);
let me know if this helps and/or works (!)
Ed
More information about the Openal
mailing list