From 76be7eb1e7e240032d734ed41eb2e506552b61e1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 8 Sep 2010 16:26:19 -0700 Subject: [PATCH] Better protect against sample overflow when converting float to short --- Alc/mixer.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Alc/mixer.c b/Alc/mixer.c index 2daac85b..356a760f 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -44,18 +44,13 @@ static __inline ALfloat aluF2F(ALfloat Value) static __inline ALshort aluF2S(ALfloat Value) { - ALint i; + ALint i = 0; + + if(Value < -1.0f) i = -32768; + else if(Value < 0.0f) i = (ALint)(Value*32768.0f); + else if(Value > 1.0f) i = 32767; + else if(Value > 0.0f) i = (ALint)(Value*32767.0f); - if(Value < 0.0f) - { - i = (ALint)(Value*32768.0f); - i = max(-32768, i); - } - else - { - i = (ALint)(Value*32767.0f); - i = min( 32767, i); - } return ((ALshort)i); } -- 2.11.4.GIT