From e787a241c0e96b890f2173ec71aa02b5b9411ec6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 12 May 2018 00:52:09 -0700 Subject: Add and use a method for fast float rounding Unlike fastf2i, this keeps the result as a float instead of converting to integer. --- Alc/ALu.c | 2 +- Alc/helpers.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'Alc') diff --git a/Alc/ALu.c b/Alc/ALu.c index 81914850..9d7fcdd5 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1663,7 +1663,7 @@ static void ApplyDither(ALfloat (*restrict Samples)[BUFFERSIZE], ALuint *dither_ ALuint rng0 = dither_rng(&seed); ALuint rng1 = dither_rng(&seed); val += (ALfloat)(rng0*(1.0/UINT_MAX) - rng1*(1.0/UINT_MAX)); - samples[i] = fastf2i(val) * invscale; + samples[i] = fast_roundf(val) * invscale; } } *dither_seed = seed; diff --git a/Alc/helpers.c b/Alc/helpers.c index 7bcb3f4a..e54f3fb2 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -125,6 +125,7 @@ extern inline ALuint NextPowerOf2(ALuint value); extern inline size_t RoundUp(size_t value, size_t r); extern inline ALint fastf2i(ALfloat f); extern inline int float2int(float f); +extern inline float fast_roundf(float f); #ifndef __GNUC__ #if defined(HAVE_BITSCANFORWARD64_INTRINSIC) extern inline int msvc64_ctz64(ALuint64 v); -- cgit v1.2.3