aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/alBuffer.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2008-01-20 00:43:02 -0800
committerChris Robinson <[email protected]>2008-01-20 00:43:02 -0800
commit29618bee10215d1de2111ad35000c4bf5d779113 (patch)
treeea359d5d61ec5b2dd6496cda9c232cebcebce975 /OpenAL32/alBuffer.c
parentdb80f682c9427ca20738bcd851239c5e6f2405d6 (diff)
Prevent float samples from overflowing when converting to 16-bit
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r--OpenAL32/alBuffer.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 2b94caf6..a6eda9d3 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -1050,8 +1050,14 @@ static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
if (ALBuf->data)
{
+ ALint smp;
for (i = 0;i < size;i++)
- ALBuf->data[i] = (ALshort)(((ALfloat*)data)[i] * 32767.5f - 0.5);
+ {
+ smp = (((ALfloat*)data)[i] * 32767.5f - 0.5f);
+ smp = min(smp, 32767);
+ smp = max(smp, -32768);
+ ALBuf->data[i] = (ALshort)smp;
+ }
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
ALBuf->format = NewFormat;