diff options
-rw-r--r-- | libFDK/include/scale.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libFDK/include/scale.h b/libFDK/include/scale.h index 655ccaf..fcfc116 100644 --- a/libFDK/include/scale.h +++ b/libFDK/include/scale.h @@ -241,20 +241,31 @@ inline void scaleValueInPlace(FIXP_DBL *value, /*!< Value */ #ifndef SATURATE_RIGHT_SHIFT #define SATURATE_RIGHT_SHIFT(src, scale, dBits) \ + (((scale) >= 8*sizeof(LONG)) ? (LONG)0 : \ ((((LONG)(src) >> (scale)) > (LONG)(((1U) << ((dBits)-1)) - 1)) \ ? (LONG)(((1U) << ((dBits)-1)) - 1) \ : (((LONG)(src) >> (scale)) < ~((LONG)(((1U) << ((dBits)-1)) - 1))) \ ? ~((LONG)(((1U) << ((dBits)-1)) - 1)) \ - : ((LONG)(src) >> (scale))) + : ((LONG)(src) >> (scale)))) +#endif + +#ifndef SATURATE_LEFT_MAX +#define SATURATE_LEFT_MAX(src, dBits) \ + (((LONG)(src) > 0) \ + ? (LONG)(((1U) << ((dBits)-1)) - 1) \ + : ((LONG)(src) < 0) \ + ? ~((LONG)(((1U) << ((dBits)-1)) - 1)) \ + : (LONG)0) #endif #ifndef SATURATE_LEFT_SHIFT #define SATURATE_LEFT_SHIFT(src, scale, dBits) \ + (((scale) >= 8*sizeof(LONG)) ? SATURATE_LEFT_MAX(src, dBits) : \ (((LONG)(src) > ((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \ ? (LONG)(((1U) << ((dBits)-1)) - 1) \ : ((LONG)(src) < ~((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \ ? ~((LONG)(((1U) << ((dBits)-1)) - 1)) \ - : ((LONG)(src) << (scale))) + : ((LONG)(src) << (scale)))) #endif #ifndef SATURATE_SHIFT |