diff options
author | Chris Robinson <[email protected]> | 2017-03-31 09:11:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-03-31 09:11:28 -0700 |
commit | 90c005bbec6cc9c8226bc57028c896c54801b580 (patch) | |
tree | 537591485592705c5aa8c8530c9ae0cb011df88e /OpenAL32 | |
parent | 355a8898cf4886e4193d43ffa0b7204c1eef7d93 (diff) |
Convert float samples to integer using a power-of-2 multiple
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/sample_cvt.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/OpenAL32/sample_cvt.c b/OpenAL32/sample_cvt.c index 22f2e898..89c2a408 100644 --- a/OpenAL32/sample_cvt.c +++ b/OpenAL32/sample_cvt.c @@ -574,9 +574,10 @@ static inline ALfloat Conv_ALfloat_ALuint(ALuint val) #define DECL_TEMPLATE(FT, T, smin, smax) \ static inline AL##T Conv_AL##T##_##FT(FT val) \ { \ - if(val > 1.0f) return smax; \ - if(val < -1.0f) return smin; \ - return (AL##T)(val * (FT)smax); \ + val *= (FT)smax + 1; \ + if(val >= (FT)smax) return smax; \ + if(val <= (FT)smin) return smin; \ + return (AL##T)val; \ } \ static inline ALu##T Conv_ALu##T##_##FT(FT val) \ { return Conv_ALu##T##_AL##T(Conv_AL##T##_##FT(val)); } @@ -590,9 +591,10 @@ DECL_TEMPLATE(ALdouble, int, -2147483647-1, 2147483647) /* Special handling for float32 to int32, since it would overflow. */ static inline ALint Conv_ALint_ALfloat(ALfloat val) { - if(val > 1.0f) return 2147483647; - if(val < -1.0f) return -2147483647-1; - return (ALint)(val * 16777215.0f) << 7; + val *= 16777216.0f; + if(val >= 16777215.0f) return 0x7fffff80/*16777215 << 7*/; + if(val <= -16777216.0f) return 0x80000000/*-16777216 << 7*/; + return (ALint)val << 7; } static inline ALuint Conv_ALuint_ALfloat(ALfloat val) { return Conv_ALuint_ALint(Conv_ALint_ALfloat(val)); } |