]> git.sesse.net Git - nageru/commitdiff
Correct a tiny miscalculation in convert_fixed24_to_fp32().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 25 Mar 2019 20:33:49 +0000 (21:33 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 25 Mar 2019 20:33:49 +0000 (21:33 +0100)
nageru/audio_mixer.cpp

index d62f1e180ff7f8a2f14fef69c44b9145763bfa44..891fb227c779f4917201345718b242bc3f71fd39 100644 (file)
@@ -65,8 +65,8 @@ void convert_fixed24_to_fp32(float *dst, size_t out_channel, size_t out_num_chan
                uint32_t s1 = src[0];
                uint32_t s2 = src[1];
                uint32_t s3 = src[2];
-               uint32_t s = s1 | (s1 << 8) | (s2 << 16) | (s3 << 24);
-               *dst = int(s) * (1.0f / 2147483648.0f);
+               uint32_t s = (s1 << 8) | (s2 << 16) | (s3 << 24);  // Note: The bottom eight bits are zero; s3 includes the sign bit.
+               *dst = int(s) * (1.0f / (256.0f * 8388608.0f));  // 256 for signed down-shift by 8, then 2^23 for the actual conversion.
 
                src += 3 * in_num_channels;
                dst += out_num_channels;