Better protect against sample overflow when converting float to short

This commit is contained in:
Chris Robinson 2010-09-08 16:26:19 -07:00
parent 6e32812bc1
commit 76be7eb1e7

View File

@ -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);
}