Better protect against sample overflow when converting float to short
This commit is contained in:
parent
6e32812bc1
commit
76be7eb1e7
17
Alc/mixer.c
17
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user