#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <math.h>
#include <string.h>
#include "share/compat.h"
#include "private/bitmath.h"
#include "private/fixed.h"
#include "private/macros.h"
#include "FLAC/assert.h"
#ifdef local_abs
#undef local_abs
#endif
#define local_abs(x) …
#ifdef local_abs64
#undef local_abs64
#endif
#define local_abs64(x) …
#ifdef FLAC__INTEGER_ONLY_LIBRARY
static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
{
FLAC__uint32 rbps;
uint32_t bits;
int fracbits;
FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
FLAC__ASSERT(err > 0);
FLAC__ASSERT(n > 0);
FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
if(err <= n)
return 0;
fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
err <<= fracbits;
err /= n;
FLAC__ASSERT(err > 0);
bits = FLAC__bitmath_ilog2(err)+1;
if(bits > 16) {
err >>= (bits-16);
fracbits -= (bits-16);
}
rbps = (FLAC__uint32)err;
rbps *= FLAC__FP_LN2;
fracbits += 16;
FLAC__ASSERT(fracbits >= 0);
{
const int f = fracbits & 3;
if(f) {
rbps >>= f;
fracbits -= f;
}
}
rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1));
if(rbps == 0)
return 0;
FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
FLAC__ASSERT(fracbits >= -3);
if(fracbits < 16)
return rbps << (16-fracbits);
else if(fracbits > 16)
return rbps >> (fracbits-16);
else
return rbps;
}
static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
{
FLAC__uint32 rbps;
uint32_t bits;
int fracbits;
FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
FLAC__ASSERT(err > 0);
FLAC__ASSERT(n > 0);
FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
if(err <= n)
return 0;
fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
err <<= fracbits;
err /= n;
FLAC__ASSERT(err > 0);
bits = FLAC__bitmath_ilog2_wide(err)+1;
if(bits > 16) {
err >>= (bits-16);
fracbits -= (bits-16);
}
rbps = (FLAC__uint32)err;
rbps *= FLAC__FP_LN2;
fracbits += 16;
FLAC__ASSERT(fracbits >= 0);
{
const int f = fracbits & 3;
if(f) {
rbps >>= f;
fracbits -= f;
}
}
rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1));
if(rbps == 0)
return 0;
FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
FLAC__ASSERT(fracbits >= -3);
if(fracbits < 16)
return rbps << (16-fracbits);
else if(fracbits > 16)
return rbps >> (fracbits-16);
else
return rbps;
}
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#endif
{ … }
#ifndef FLAC__INTEGER_ONLY_LIBRARY
uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#endif
{ … }
#ifndef FLAC__INTEGER_ONLY_LIBRARY
#define CHECK_ORDER_IS_VALID(macro_order) …
#else
#define CHECK_ORDER_IS_VALID …
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#endif
{ … }
#ifndef FLAC__INTEGER_ONLY_LIBRARY
uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#endif
{ … }
void FLAC__fixed_compute_residual(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[])
{ … }
void FLAC__fixed_compute_residual_wide(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[])
{ … }
void FLAC__fixed_compute_residual_wide_33bit(const FLAC__int64 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[])
{ … }
#ifdef FUZZING_BUILD_MODE_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
void FLAC__fixed_restore_signal(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[])
{ … }
void FLAC__fixed_restore_signal_wide(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[])
{ … }
#ifdef FUZZING_BUILD_MODE_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
void FLAC__fixed_restore_signal_wide_33bit(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int64 data[])
{ … }