Introduce a generic clamp function to clean up some similarly duplicated code.

This commit is contained in:
Lioncash committed 2014-02-04 20:43:07 -05:00
1 parent 59e2179172
commit 6b87a0ef20
10 files changed
+43 -61

No files matched your search

+3 -5
View File
@@ -5,6 +5,7 @@
// Adapted from in_cube by hcs & destop
#include "StreamADPCM.h"
#include "MathUtil.h"
// STATE_TO_SAVE (not saved yet!)
static s32 histl1;
@@ -31,8 +32,7 @@ s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
break;
}
hist = (hist + 0x20) >> 6;
if (hist > 0x1fffff) hist = 0x1fffff;
if (hist < -0x200000) hist = -0x200000;
MathUtil::Clamp(hist, -0x200000, 0x1fffff);
s32 cur = (((s16)(bits << 12) >> (q & 0xf)) << 6) + hist;
@@ -40,9 +40,7 @@ s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
hist1 = cur;
cur >>= 6;
if (cur < -0x8000) return -0x8000;
if (cur > 0x7fff) return 0x7fff;
MathUtil::Clamp(cur, -0x8000, 0x7fff);
return (s16)cur;
}