#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <math.h>
#include <stdlib.h>
#include "FLAC/assert.h"
#include "FLAC/format.h"
#include "share/compat.h"
#include "private/bitmath.h"
#include "private/lpc.h"
#include "private/macros.h"
#if !defined(NDEBUG) || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
#include <stdio.h>
#endif
#define FLAC__LPC_UNROLLED_FILTER_LOOPS
#ifndef FLAC__INTEGER_ONLY_LIBRARY
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#include <float.h>
static inline long int lround(double x) {
return (long)(x + _copysign(0.5, x));
}
#elif !defined(HAVE_LROUND) && defined(__GNUC__)
static inline long int lround(double x) {
return (long)(x + __builtin_copysign(0.5, x));
}
#endif
void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len)
{ … }
void FLAC__lpc_window_data_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len)
{ … }
void FLAC__lpc_window_data_partial(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift)
{ … }
void FLAC__lpc_window_data_partial_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift)
{ … }
void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[])
{ … }
void FLAC__lpc_compute_lp_coefficients(const double autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[])
{ … }
int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], uint32_t order, uint32_t precision, FLAC__int32 qlp_coeff[], int *shift)
{ … }
#if defined(_MSC_VER)
#pragma warning ( disable : 4028 )
#endif
void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{ … }
#else
{
int i;
FLAC__int32 sum;
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= 32);
if(order <= 12) {
if(order > 8) {
if(order > 10) {
if(order == 12) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[11] * data[i-12];
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 10) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
}
else if(order > 4) {
if(order > 6) {
if(order == 8) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 6) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
}
else {
if(order > 2) {
if(order == 4) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 2) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++)
residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
}
}
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
case 32: sum += qlp_coeff[31] * data[i-32];
case 31: sum += qlp_coeff[30] * data[i-31];
case 30: sum += qlp_coeff[29] * data[i-30];
case 29: sum += qlp_coeff[28] * data[i-29];
case 28: sum += qlp_coeff[27] * data[i-28];
case 27: sum += qlp_coeff[26] * data[i-27];
case 26: sum += qlp_coeff[25] * data[i-26];
case 25: sum += qlp_coeff[24] * data[i-25];
case 24: sum += qlp_coeff[23] * data[i-24];
case 23: sum += qlp_coeff[22] * data[i-23];
case 22: sum += qlp_coeff[21] * data[i-22];
case 21: sum += qlp_coeff[20] * data[i-21];
case 20: sum += qlp_coeff[19] * data[i-20];
case 19: sum += qlp_coeff[18] * data[i-19];
case 18: sum += qlp_coeff[17] * data[i-18];
case 17: sum += qlp_coeff[16] * data[i-17];
case 16: sum += qlp_coeff[15] * data[i-16];
case 15: sum += qlp_coeff[14] * data[i-15];
case 14: sum += qlp_coeff[13] * data[i-14];
case 13: sum += qlp_coeff[12] * data[i-13];
sum += qlp_coeff[11] * data[i-12];
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[ 9] * data[i-10];
sum += qlp_coeff[ 8] * data[i- 9];
sum += qlp_coeff[ 7] * data[i- 8];
sum += qlp_coeff[ 6] * data[i- 7];
sum += qlp_coeff[ 5] * data[i- 6];
sum += qlp_coeff[ 4] * data[i- 5];
sum += qlp_coeff[ 3] * data[i- 4];
sum += qlp_coeff[ 2] * data[i- 3];
sum += qlp_coeff[ 1] * data[i- 2];
sum += qlp_coeff[ 0] * data[i- 1];
}
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
#endif
void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{ … }
#else
{
int i;
FLAC__int64 sum;
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= 32);
if(order <= 12) {
if(order > 8) {
if(order > 10) {
if(order == 12) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 10) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
}
else if(order > 4) {
if(order > 6) {
if(order == 8) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 6) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
}
else {
if(order > 2) {
if(order == 4) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
else {
if(order == 2) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
residual[i] = data[i] - (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++)
residual[i] = data[i] - ((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
}
}
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
}
residual[i] = data[i] - (sum >> lp_quantization);
}
}
}
#endif
FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
{ … }
FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual_33bit(const FLAC__int64 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
{ … }
#endif
uint32_t FLAC__lpc_max_prediction_before_shift_bps(uint32_t subframe_bps, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order)
{ … }
uint32_t FLAC__lpc_max_residual_bps(uint32_t subframe_bps, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization)
{ … }
#ifdef FUZZING_BUILD_MODE_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
void FLAC__lpc_restore_signal(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{ … }
#else
{
int i;
FLAC__int32 sum;
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= 32);
if(order <= 12) {
if(order > 8) {
if(order > 10) {
if(order == 12) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[11] * data[i-12];
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
else {
if(order == 10) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[9] * data[i-10];
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[8] * data[i-9];
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
}
else if(order > 4) {
if(order > 6) {
if(order == 8) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[7] * data[i-8];
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[6] * data[i-7];
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
else {
if(order == 6) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[5] * data[i-6];
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[4] * data[i-5];
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
}
else {
if(order > 2) {
if(order == 4) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[3] * data[i-4];
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[2] * data[i-3];
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
else {
if(order == 2) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[1] * data[i-2];
sum += qlp_coeff[0] * data[i-1];
data[i] = residual[i] + (sum >> lp_quantization);
}
}
else {
for(i = 0; i < (int)data_len; i++)
data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
}
}
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
case 32: sum += qlp_coeff[31] * data[i-32];
case 31: sum += qlp_coeff[30] * data[i-31];
case 30: sum += qlp_coeff[29] * data[i-30];
case 29: sum += qlp_coeff[28] * data[i-29];
case 28: sum += qlp_coeff[27] * data[i-28];
case 27: sum += qlp_coeff[26] * data[i-27];
case 26: sum += qlp_coeff[25] * data[i-26];
case 25: sum += qlp_coeff[24] * data[i-25];
case 24: sum += qlp_coeff[23] * data[i-24];
case 23: sum += qlp_coeff[22] * data[i-23];
case 22: sum += qlp_coeff[21] * data[i-22];
case 21: sum += qlp_coeff[20] * data[i-21];
case 20: sum += qlp_coeff[19] * data[i-20];
case 19: sum += qlp_coeff[18] * data[i-19];
case 18: sum += qlp_coeff[17] * data[i-18];
case 17: sum += qlp_coeff[16] * data[i-17];
case 16: sum += qlp_coeff[15] * data[i-16];
case 15: sum += qlp_coeff[14] * data[i-15];
case 14: sum += qlp_coeff[13] * data[i-14];
case 13: sum += qlp_coeff[12] * data[i-13];
sum += qlp_coeff[11] * data[i-12];
sum += qlp_coeff[10] * data[i-11];
sum += qlp_coeff[ 9] * data[i-10];
sum += qlp_coeff[ 8] * data[i- 9];
sum += qlp_coeff[ 7] * data[i- 8];
sum += qlp_coeff[ 6] * data[i- 7];
sum += qlp_coeff[ 5] * data[i- 6];
sum += qlp_coeff[ 4] * data[i- 5];
sum += qlp_coeff[ 3] * data[i- 4];
sum += qlp_coeff[ 2] * data[i- 3];
sum += qlp_coeff[ 1] * data[i- 2];
sum += qlp_coeff[ 0] * data[i- 1];
}
data[i] = residual[i] + (sum >> lp_quantization);
}
}
}
#endif
void FLAC__lpc_restore_signal_wide(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{ … }
#else
{
int i;
FLAC__int64 sum;
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= 32);
if(order <= 12) {
if(order > 8) {
if(order > 10) {
if(order == 12) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
else {
if(order == 10) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
}
else if(order > 4) {
if(order > 6) {
if(order == 8) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
else {
if(order == 6) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
}
else {
if(order > 2) {
if(order == 4) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
else {
if(order == 2) {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
else {
for(i = 0; i < (int)data_len; i++)
data[i] = (FLAC__int32)(residual[i] + ((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization));
}
}
}
}
else {
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
}
data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization));
}
}
}
#endif
#ifdef FUZZING_BUILD_MODE_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
void FLAC__lpc_restore_signal_wide_33bit(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int64 * flac_restrict data)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{ … }
#else
{
int i;
FLAC__int64 sum;
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= 32);
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
case 32: sum += qlp_coeff[31] * data[i-32];
case 31: sum += qlp_coeff[30] * data[i-31];
case 30: sum += qlp_coeff[29] * data[i-30];
case 29: sum += qlp_coeff[28] * data[i-29];
case 28: sum += qlp_coeff[27] * data[i-28];
case 27: sum += qlp_coeff[26] * data[i-27];
case 26: sum += qlp_coeff[25] * data[i-26];
case 25: sum += qlp_coeff[24] * data[i-25];
case 24: sum += qlp_coeff[23] * data[i-24];
case 23: sum += qlp_coeff[22] * data[i-23];
case 22: sum += qlp_coeff[21] * data[i-22];
case 21: sum += qlp_coeff[20] * data[i-21];
case 20: sum += qlp_coeff[19] * data[i-20];
case 19: sum += qlp_coeff[18] * data[i-19];
case 18: sum += qlp_coeff[17] * data[i-18];
case 17: sum += qlp_coeff[16] * data[i-17];
case 16: sum += qlp_coeff[15] * data[i-16];
case 15: sum += qlp_coeff[14] * data[i-15];
case 14: sum += qlp_coeff[13] * data[i-14];
case 13: sum += qlp_coeff[12] * data[i-13];
case 12: sum += qlp_coeff[11] * data[i-12];
case 11: sum += qlp_coeff[10] * data[i-11];
case 10: sum += qlp_coeff[ 9] * data[i-10];
case 9: sum += qlp_coeff[ 8] * data[i- 9];
case 8: sum += qlp_coeff[ 7] * data[i- 8];
case 7: sum += qlp_coeff[ 6] * data[i- 7];
case 6: sum += qlp_coeff[ 5] * data[i- 6];
case 5: sum += qlp_coeff[ 4] * data[i- 5];
case 4: sum += qlp_coeff[ 3] * data[i- 4];
case 3: sum += qlp_coeff[ 2] * data[i- 3];
case 2: sum += qlp_coeff[ 1] * data[i- 2];
case 1: sum += qlp_coeff[ 0] * data[i- 1];
}
data[i] = residual[i] + (sum >> lp_quantization);
}
}
#endif
#if defined(_MSC_VER)
#pragma warning ( default : 4028 )
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
double FLAC__lpc_compute_expected_bits_per_residual_sample(double lpc_error, uint32_t total_samples)
{ … }
double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(double lpc_error, double error_scale)
{ … }
uint32_t FLAC__lpc_compute_best_order(const double lpc_error[], uint32_t max_order, uint32_t total_samples, uint32_t overhead_bits_per_order)
{ … }
#endif