diff options
author | Chris Robinson <[email protected]> | 2008-01-20 00:43:02 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-01-20 00:43:02 -0800 |
commit | 29618bee10215d1de2111ad35000c4bf5d779113 (patch) | |
tree | ea359d5d61ec5b2dd6496cda9c232cebcebce975 | |
parent | db80f682c9427ca20738bcd851239c5e6f2405d6 (diff) |
Prevent float samples from overflowing when converting to 16-bit
-rw-r--r-- | OpenAL32/alBuffer.c | 8 |
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; |