ref: 15b9be3a2974daee733feb6f2abf70161cea582f
parent: 0773fec4ad5647bb84e3d8ce401a715342c83456
author: Jean-Marc Valin <[email protected]>
date: Fri Mar 14 13:58:33 EDT 2008
fixed-point: playing it safe. SHL32() now automatically casts input to 32-bit to prevent surprises. Also, a few comments.
--- a/libcelt/fixed_generic.h
+++ b/libcelt/fixed_generic.h
@@ -54,7 +54,7 @@
#define SHR16(a,shift) ((a) >> (shift))
#define SHL16(a,shift) ((a) << (shift))
#define SHR32(a,shift) ((a) >> (shift))
-#define SHL32(a,shift) ((a) << (shift))
+#define SHL32(a,shift) ((celt_word32_t)(a) << (shift))
#define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
--- a/libcelt/mathops.h
+++ b/libcelt/mathops.h
@@ -54,16 +54,13 @@
#include "entcode.h"
+/** Integer log in base2. Undefined for zero and negative numbers */
static inline celt_int16_t celt_ilog2(celt_word32_t x)
{
return EC_ILOG(x)-1;
}
-#define C0 3634
-#define C1 21173
-#define C2 -12627
-#define C3 4204
-
+/** Sqrt approximation (QX input, QX/2 output) */
static inline celt_word32_t celt_sqrt(celt_word32_t x)
{
int k;
@@ -149,7 +146,7 @@
#define D1 11356
#define D2 3726
#define D3 1301
-/* Input in Q11 format, output in Q16 */
+/** Base-2 exponential approximation (2^x). (Q11 input, Q16 output) */
static inline celt_word32_t celt_exp2(celt_word16_t x)
{
int integer;
@@ -164,6 +161,7 @@
return VSHR32(EXTEND32(frac), -integer-2);
}
+/** Reciprocal approximation (Q15 input, Q16 output) */
static inline celt_word32_t celt_rcp(celt_word32_t x)
{
int i, neg=0;