diff options
author | Chris Robinson <[email protected]> | 2012-08-20 15:57:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-08-20 15:57:27 -0700 |
commit | e5ebe345ad0e736f24635e96bd9ed3566126dd88 (patch) | |
tree | 02d4ee1a2595379026ab823d59b6256827035d13 /OpenAL32/alSource.c | |
parent | 965608356f41e555e0cb9789e3e54e8f67656ebf (diff) |
Add the option to retrieve the source offset and latency in seconds
Diffstat (limited to 'OpenAL32/alSource.c')
-rw-r--r-- | OpenAL32/alSource.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 52688827..dc9cb283 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -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 |