#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "FLAC/assert.h"
#include "share/compat.h"
#include "private/float.h"
#ifdef FLAC__INTEGER_ONLY_LIBRARY
const FLAC__fixedpoint FLAC__FP_ZERO = 0;
const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
const FLAC__fixedpoint FLAC__FP_E = 178145;
#define LOG2_LOOKUP_PRECISION 16
static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
{
0x00000000,
0x00000001,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000
},
{
0x00000000,
0x00000010,
0x00000007,
0x00000003,
0x00000001,
0x00000001,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000
},
{
0x00000000,
0x00000100,
0x0000006a,
0x00000031,
0x00000018,
0x0000000c,
0x00000006,
0x00000003,
0x00000001,
0x00000001,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000
},
{
0x00000000,
0x00001000,
0x000006a4,
0x00000315,
0x0000017d,
0x000000bc,
0x0000005d,
0x0000002e,
0x00000017,
0x0000000c,
0x00000006,
0x00000003,
0x00000001,
0x00000001,
0x00000000,
0x00000000
},
{
0x00000000,
0x00010000,
0x00006a40,
0x00003151,
0x000017d6,
0x00000bba,
0x000005d1,
0x000002e6,
0x00000172,
0x000000b9,
0x0000005c,
0x0000002e,
0x00000017,
0x0000000c,
0x00000006,
0x00000003
},
{
0x00000000,
0x00100000,
0x0006a3fe,
0x00031513,
0x00017d60,
0x0000bb9d,
0x00005d10,
0x00002e59,
0x00001721,
0x00000b8e,
0x000005c6,
0x000002e3,
0x00000171,
0x000000b9,
0x0000005c,
0x0000002e
},
{
0x00000000,
0x01000000,
0x006a3fe6,
0x00315130,
0x0017d605,
0x000bb9ca,
0x0005d0fc,
0x0002e58f,
0x0001720e,
0x0000b8d8,
0x00005c61,
0x00002e2d,
0x00001716,
0x00000b8b,
0x000005c5,
0x000002e3
},
{
0x00000000,
0x10000000,
0x06a3fe5c,
0x03151301,
0x017d6049,
0x00bb9ca6,
0x005d0fba,
0x002e58f7,
0x001720da,
0x000b8d87,
0x0005c60b,
0x0002e2d7,
0x00017160,
0x0000b8ad,
0x00005c56,
0x00002e2b
}
};
#if 0#endif
FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, uint32_t fracbits, uint32_t precision)
{
const FLAC__uint32 ONE = (1u << fracbits);
const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
FLAC__ASSERT(fracbits < 32);
FLAC__ASSERT((fracbits & 0x3) == 0);
if(x < ONE)
return 0;
if(precision > LOG2_LOOKUP_PRECISION)
precision = LOG2_LOOKUP_PRECISION;
{
FLAC__uint32 y = 0;
FLAC__uint32 z = x >> 1, k = 1;
while (x > ONE && k < precision) {
if (x - z >= ONE) {
x -= z;
z = x >> k;
y += table[k];
}
else {
z >>= 1;
k++;
}
}
return y;
}
}
#endif