aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2015-10-14 03:23:19 -0700
committerChris Robinson <[email protected]>2015-10-14 03:23:19 -0700
commit98eda6b35be5042534dd2b0cd0608a87cb524f86 (patch)
treecfec51a72fe232a7dd51fd63e18ef6beba7db80c /OpenAL32
parentd386675efe60b43cd302702c9a893562ad937dc8 (diff)
Properly limit the calculated source offset components
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/alSource.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 38b287b4..f5b7111f 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -21,6 +21,7 @@
#include "config.h"
#include <stdlib.h>
+#include <limits.h>
#include <math.h>
#include <float.h>
@@ -2949,6 +2950,7 @@ static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac)
{
const ALbuffer *Buffer = NULL;
const ALbufferlistitem *BufferList;
+ ALdouble dbloff, dblfrac;
/* Find the first valid Buffer in the Queue */
BufferList = ATOMIC_LOAD(&Source->queue);
@@ -2990,13 +2992,15 @@ static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac)
break;
case AL_SAMPLE_OFFSET:
- *offset = (ALuint)Source->Offset;
- *frac = (ALuint)((Source->Offset - *offset) * FRACTIONONE);
+ dbloff = modf(Source->Offset, &dblfrac);
+ *offset = (ALuint)mind(dbloff, UINT_MAX);
+ *frac = (ALuint)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
break;
case AL_SEC_OFFSET:
- *offset = (ALuint)(Source->Offset*Buffer->Frequency);
- *frac = (ALuint)(((Source->Offset*Buffer->Frequency) - *offset) * FRACTIONONE);
+ dbloff = modf(Source->Offset*Buffer->Frequency, &dblfrac);
+ *offset = (ALuint)mind(dbloff, UINT_MAX);
+ *frac = (ALuint)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
break;
}
Source->Offset = -1.0;