diff options
author | Chris Robinson <[email protected]> | 2017-06-26 06:54:45 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-06-26 06:54:45 -0700 |
commit | 55c329b462ce3df1d5417331f835f6474d0c7e13 (patch) | |
tree | d7cb9ec33421c70f3b657796034e45efefad4f93 /OpenAL32 | |
parent | 5d5eff7502a41fbb8b2dbe27239ec860770fe1bb (diff) |
Clean up some messy rounding code
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMain.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 8cedee94..9460a3f1 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -409,6 +409,24 @@ inline size_t RoundUp(size_t value, size_t r) return value - (value%r); } +/* Scales the given value using 64-bit integer math, rounding the result. */ +inline ALuint64 ScaleRound(ALuint64 val, ALuint64 new_scale, ALuint64 old_scale) +{ + return (val*new_scale + old_scale/2) / old_scale; +} + +/* Scales the given value using 64-bit integer math, flooring the result. */ +inline ALuint64 ScaleFloor(ALuint64 val, ALuint64 new_scale, ALuint64 old_scale) +{ + return val * new_scale / old_scale; +} + +/* Scales the given value using 64-bit integer math, ceiling the result. */ +inline ALuint64 ScaleCeil(ALuint64 val, ALuint64 new_scale, ALuint64 old_scale) +{ + return (val*new_scale + old_scale-1) / old_scale; +} + /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero * mode. */ inline ALint fastf2i(ALfloat f) |