diff options
author | Chris Robinson <[email protected]> | 2010-09-08 16:26:19 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-09-08 16:26:19 -0700 |
commit | 76be7eb1e7e240032d734ed41eb2e506552b61e1 (patch) | |
tree | 935324f9e026d3eea6b6886d2c15da547768af69 /Alc | |
parent | 6e32812bc1a194ec55154f99868311110c0cfee6 (diff) |
Better protect against sample overflow when converting float to short
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/mixer.c | 17 |
1 files 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); } |