Add the option to retrieve the source offset and latency in seconds

This commit is contained in:
Chris Robinson
2012-08-20 15:57:27 -07:00
parent 965608356f
commit e5ebe345ad
2 changed files with 52 additions and 0 deletions
+1
View File
@@ -45,6 +45,7 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
#ifndef AL_SOFT_source_latency
#define AL_SOFT_source_latency 1
#define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
#define AL_SEC_OFFSET_LATENCY_SOFT 0x1201
typedef int64_t ALint64SOFT;
typedef uint64_t ALuint64SOFT;
typedef void (AL_APIENTRY*LPALGETSOURCEDSOFT)(ALuint,ALenum,ALdouble*);
+51
View File
@@ -49,6 +49,7 @@ const ALsizei ResamplerPrePadding[ResamplerMax] = {
static ALvoid InitSourceParams(ALsource *Source);
static ALint64 GetSourceOffset(ALsource *Source);
static ALdouble GetSourceSecOffset(ALsource *Source);
static ALvoid GetSourceOffsets(ALsource *Source, ALenum name, ALdouble *offsets, ALdouble updateLen);
static ALint GetSampleOffset(ALsource *Source);
@@ -109,6 +110,14 @@ static ALenum GetSourcedv(ALsource *Source, ALCcontext *Context, ALenum name, AL
UnlockContext(Context);
break;
case AL_SEC_OFFSET_LATENCY_SOFT:
LockContext(Context);
values[0] = GetSourceSecOffset(Source);
values[1] = (ALdouble)ALCdevice_GetLatency(Context->Device) /
1000000000.0;
UnlockContext(Context);
break;
case AL_POSITION:
LockContext(Context);
values[0] = Source->Position[0];
@@ -1329,6 +1338,7 @@ AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble
case AL_SAMPLE_RW_OFFSETS_SOFT:
case AL_BYTE_RW_OFFSETS_SOFT:
case AL_SEC_OFFSET_LATENCY_SOFT:
case AL_POSITION:
case AL_VELOCITY:
@@ -2183,6 +2193,47 @@ static ALint64 GetSourceOffset(ALsource *Source)
return (ALint64)minu64(readPos, MAKEU64(0x7fffffff,0xffffffff));
}
/* GetSourceSecOffset
*
* Gets the current read offset for the given Source, in seconds. The offset is
* relative to the start of the queue (not the start of the current buffer).
*/
static ALdouble GetSourceSecOffset(ALsource *Source)
{
const ALbufferlistitem *BufferList;
const ALbuffer *Buffer = NULL;
ALuint64 readPos;
ALuint i;
BufferList = Source->queue;
while(BufferList)
{
if(BufferList->buffer)
{
Buffer = BufferList->buffer;
break;
}
BufferList = BufferList->next;
}
if((Source->state != AL_PLAYING && Source->state != AL_PAUSED) || !Buffer)
return 0.0;
/* NOTE: This is the offset into the *current* buffer, so add the length of
* any played buffers */
readPos = (ALuint64)Source->position << FRACTIONBITS;
readPos |= (ALuint64)Source->position_fraction;
BufferList = Source->queue;
for(i = 0;i < Source->BuffersPlayed && BufferList;i++)
{
if(BufferList->buffer)
readPos += (ALuint64)BufferList->buffer->SampleLen << FRACTIONBITS;
BufferList = BufferList->next;
}
return (ALdouble)readPos / (ALdouble)FRACTIONONE / (ALdouble)Buffer->Frequency;
}
/* GetSourceOffsets
*
* Gets the current read and write offsets for the given Source, in the