From 29618bee10215d1de2111ad35000c4bf5d779113 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 20 Jan 2008 00:43:02 -0800 Subject: [PATCH] Prevent float samples from overflowing when converting to 16-bit --- OpenAL32/alBuffer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; -- 2.11.4.GIT