aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-05-11 11:59:41 -0700
committerChris Robinson <[email protected]>2010-05-11 11:59:41 -0700
commitf0ce1bff3eddbe9d081585abe1aaa2810371b692 (patch)
tree9020814b293d5711b373c7dd26e06c2de74827fc
parentab3c23478d9d0df04059b9163d77ea68a1562b4c (diff)
Simplify and fix applying a source offset
-rw-r--r--OpenAL32/alSource.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index d7a6d16c..afea8dfb 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -1908,6 +1908,7 @@ static ALboolean ApplyOffset(ALsource *Source)
ALbufferlistitem *BufferList;
ALbuffer *Buffer;
ALint lBufferSize, lTotalBufferSize;
+ ALint BuffersPlayed;
ALint lByteOffset;
// Get true byte offset
@@ -1920,7 +1921,7 @@ static ALboolean ApplyOffset(ALsource *Source)
// Sort out the queue (pending and processed states)
BufferList = Source->queue;
lTotalBufferSize = 0;
- Source->BuffersPlayed = 0;
+ BuffersPlayed = 0;
while(BufferList)
{
@@ -1930,19 +1931,21 @@ static ALboolean ApplyOffset(ALsource *Source)
if(lTotalBufferSize+lBufferSize <= lByteOffset)
{
// Offset is past this buffer so increment BuffersPlayed
- Source->BuffersPlayed++;
+ BuffersPlayed++;
}
else if(lTotalBufferSize <= lByteOffset)
{
+
// Offset is within this buffer
// Set Current Buffer
Source->Buffer = BufferList->buffer;
+ Source->BuffersPlayed = BuffersPlayed;
// SW Mixer Positions are in Samples
Source->position = (lByteOffset - lTotalBufferSize) /
aluBytesFromFormat(Buffer->format) /
aluChannelsFromFormat(Buffer->format);
- break;
+ return AL_TRUE;
}
// Increment the TotalBufferSize
@@ -1951,8 +1954,8 @@ static ALboolean ApplyOffset(ALsource *Source)
// Move on to next buffer in the Queue
BufferList = BufferList->next;
}
-
- return AL_TRUE;
+ // Offset is out of range of the buffer queue
+ return AL_FALSE;
}
@@ -1970,7 +1973,6 @@ static ALint GetByteOffset(ALsource *Source)
ALfloat BufferFreq;
ALint Channels, Bytes;
ALint ByteOffset = -1;
- ALint TotalBufferDataSize;
// Find the first non-NULL Buffer in the Queue
BufferList = Source->queue;
@@ -2017,19 +2019,6 @@ static ALint GetByteOffset(ALsource *Source)
// Clear Offset
Source->lOffset = 0;
- TotalBufferDataSize = 0;
- BufferList = Source->queue;
- while(BufferList)
- {
- if(BufferList->buffer)
- TotalBufferDataSize += BufferList->buffer->size;
- BufferList = BufferList->next;
- }
-
- // Finally, if the ByteOffset is beyond the length of all the buffers in
- // the queue, return -1
- if(ByteOffset >= TotalBufferDataSize)
- return -1;
return ByteOffset;
}