Clean up libfaad's fixed point implementation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28069 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
aa0f895572
commit
ddb936a0c5
6 changed files with 75 additions and 116 deletions
|
@ -167,9 +167,11 @@ extern struct codec_api* ci;
|
|||
#ifdef FIXED_POINT
|
||||
#define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
|
||||
#define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
|
||||
#define DIV_Q(A, B) (((int64_t)A << Q2_BITS )/B)
|
||||
#else
|
||||
#define DIV_R(A, B) ((A)/(B))
|
||||
#define DIV_C(A, B) ((A)/(B))
|
||||
#define DIV_Q(A, B) ((A)/(B))
|
||||
#endif
|
||||
|
||||
#ifndef SBR_LOW_POWER
|
||||
|
|
|
@ -35,7 +35,9 @@
|
|||
#include "mp4.h"
|
||||
#include "syntax.h"
|
||||
#include "error.h"
|
||||
/* rockbox: not used
|
||||
#include "output.h"
|
||||
*/
|
||||
#include "filtbank.h"
|
||||
#include "drc.h"
|
||||
#ifdef SBR_DEC
|
||||
|
|
|
@ -57,7 +57,7 @@ typedef int32_t real_t;
|
|||
|
||||
#define Q2_BITS 22
|
||||
#define Q2_PRECISION (1 << Q2_BITS)
|
||||
#define Q2_CONST(A) (((A) >= 0) ? ((real_t)((A)*(Q2_PRECISION)+0.5)) : ((real_t)((A)*(Q2_PRECISION)-0.5)))
|
||||
#define Q2_CONST(A) FIX_CONST((A),(Q2_PRECISION))
|
||||
|
||||
#if defined(CPU_COLDFIRE)
|
||||
|
||||
|
@ -126,8 +126,6 @@ static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|||
|
||||
/* the following see little or no use, so just ignore them for now */
|
||||
#define MUL_Q2(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (Q2_BITS-1))) >> Q2_BITS)
|
||||
#define MUL_SHIFT6(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (6-1))) >> 6)
|
||||
#define MUL_SHIFT23(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (23-1))) >> 23)
|
||||
|
||||
#elif defined(__GNUC__) && defined (__arm__)
|
||||
|
||||
|
@ -162,16 +160,6 @@ static INLINE real_t MUL_Q2(real_t A, real_t B)
|
|||
return arm_mul(A, B, Q2_BITS);
|
||||
}
|
||||
|
||||
static INLINE real_t MUL_SHIFT6(real_t A, real_t B)
|
||||
{
|
||||
return arm_mul(A, B, 6);
|
||||
}
|
||||
|
||||
static INLINE real_t MUL_SHIFT23(real_t A, real_t B)
|
||||
{
|
||||
return arm_mul(A, B, 23);
|
||||
}
|
||||
|
||||
static INLINE real_t _MulHigh(real_t x, real_t y)
|
||||
{
|
||||
uint32_t __lo;
|
||||
|
@ -223,8 +211,6 @@ static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|||
#define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS)
|
||||
#endif
|
||||
#define MUL_Q2(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (Q2_BITS-1))) >> Q2_BITS)
|
||||
#define MUL_SHIFT6(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (6-1))) >> 6)
|
||||
#define MUL_SHIFT23(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (23-1))) >> 23)
|
||||
|
||||
/* Complex multiplication */
|
||||
static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
||||
|
|
|
@ -38,8 +38,6 @@ static void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size,
|
|||
|
||||
#ifdef FIXED_POINT
|
||||
|
||||
#define DIV(A, B) (((int64_t)A << REAL_BITS)/B)
|
||||
|
||||
#define step(shift) \
|
||||
if ((0x40000000l >> shift) + root <= value) \
|
||||
{ \
|
||||
|
@ -126,7 +124,7 @@ static INLINE void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t
|
|||
energy = fp_sqrt(energy);
|
||||
if (energy > 0)
|
||||
{
|
||||
scale = DIV(REAL_CONST(1),energy);
|
||||
scale = DIV_R(REAL_CONST(1), energy);
|
||||
|
||||
exp = scale_factor >> 2;
|
||||
frac = scale_factor & 3;
|
||||
|
|
|
@ -107,9 +107,9 @@ static uint8_t get_S_mapped(sbr_info *sbr, uint8_t ch, uint8_t l, uint8_t curren
|
|||
*/
|
||||
|
||||
/* find first HI_RES band in current LO_RES band */
|
||||
lb = 2*current_band - ((sbr->N_high & 1) ? 1 : 0);
|
||||
lb = 2 * (current_band ) - ((sbr->N_high & 1) ? 1 : 0);
|
||||
/* find first HI_RES band in next LO_RES band */
|
||||
ub = 2*(current_band+1) - ((sbr->N_high & 1) ? 1 : 0);
|
||||
ub = 2 * (current_band+1) - ((sbr->N_high & 1) ? 1 : 0);
|
||||
|
||||
/* check all HI_RES bands in current LO_RES band for sinusoid */
|
||||
for (b = lb; b < ub; b++)
|
||||
|
@ -130,8 +130,8 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
|
||||
{
|
||||
uint8_t m, l, j, k, k_l, k_h, p;
|
||||
real_t nrg, div;
|
||||
|
||||
real_t nrg, div, tmp;
|
||||
|
||||
(void)adj;
|
||||
if (sbr->bs_interpol_freq == 1)
|
||||
{
|
||||
|
@ -150,29 +150,17 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
|
||||
for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
|
||||
{
|
||||
#ifdef FIXED_POINT
|
||||
#ifdef SBR_LOW_POWER
|
||||
nrg += ((QMF_RE(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS);
|
||||
#else
|
||||
nrg += ((QMF_RE(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS) +
|
||||
((QMF_IM(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_IM(Xsbr[i][m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS);
|
||||
#endif
|
||||
#else
|
||||
nrg += MUL_R(QMF_RE(Xsbr[i][m + sbr->kx]), QMF_RE(Xsbr[i][m + sbr->kx]))
|
||||
tmp = QMF_RE(Xsbr[i][m + sbr->kx]);
|
||||
nrg += MUL_R(tmp, tmp);
|
||||
#ifndef SBR_LOW_POWER
|
||||
+ MUL_R(QMF_IM(Xsbr[i][m + sbr->kx]), QMF_IM(Xsbr[i][m + sbr->kx]))
|
||||
#endif
|
||||
;
|
||||
tmp = QMF_IM(Xsbr[i][m + sbr->kx]);
|
||||
nrg += MUL_R(tmp, tmp);
|
||||
#endif
|
||||
}
|
||||
|
||||
sbr->E_curr[ch][m][l] = nrg / div;
|
||||
#ifdef SBR_LOW_POWER
|
||||
#ifdef FIXED_POINT
|
||||
sbr->E_curr[ch][m][l] <<= 1;
|
||||
#else
|
||||
sbr->E_curr[ch][m][l] *= 2;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -198,30 +186,18 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
{
|
||||
for (j = k_l; j < k_h; j++)
|
||||
{
|
||||
#ifdef FIXED_POINT
|
||||
#ifdef SBR_LOW_POWER
|
||||
nrg += ((QMF_RE(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS);
|
||||
#else
|
||||
nrg += ((QMF_RE(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS) +
|
||||
((QMF_IM(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_IM(Xsbr[i][j])+(1<<(REAL_BITS-1)))>>REAL_BITS);
|
||||
#endif
|
||||
#else
|
||||
nrg += MUL_R(QMF_RE(Xsbr[i][j]), QMF_RE(Xsbr[i][j]))
|
||||
tmp = QMF_RE(Xsbr[i][j]);
|
||||
nrg += MUL_R(tmp, tmp);
|
||||
#ifndef SBR_LOW_POWER
|
||||
+ MUL_R(QMF_IM(Xsbr[i][j]), QMF_IM(Xsbr[i][j]))
|
||||
#endif
|
||||
;
|
||||
tmp = QMF_IM(Xsbr[i][j]);
|
||||
nrg += MUL_R(tmp, tmp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
|
||||
#ifdef SBR_LOW_POWER
|
||||
#ifdef FIXED_POINT
|
||||
sbr->E_curr[ch][k - sbr->kx][l] <<= 1;
|
||||
#else
|
||||
sbr->E_curr[ch][k - sbr->kx][l] *= 2;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +217,7 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
|
||||
/* log2 values of [0..63] */
|
||||
static const real_t log2_int_tab[] = {
|
||||
LOG2_MIN_INF, REAL_CONST(0.000000000000000), REAL_CONST(1.000000000000000), REAL_CONST(1.584962500721156),
|
||||
LOG2_MIN_INF , REAL_CONST(0.000000000000000), REAL_CONST(1.000000000000000), REAL_CONST(1.584962500721156),
|
||||
REAL_CONST(2.000000000000000), REAL_CONST(2.321928094887362), REAL_CONST(2.584962500721156), REAL_CONST(2.807354922057604),
|
||||
REAL_CONST(3.000000000000000), REAL_CONST(3.169925001442313), REAL_CONST(3.321928094887363), REAL_CONST(3.459431618637297),
|
||||
REAL_CONST(3.584962500721156), REAL_CONST(3.700439718141092), REAL_CONST(3.807354922057604), REAL_CONST(3.906890595608519),
|
||||
|
@ -438,7 +414,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
|
|||
ALIGN real_t G_boost;
|
||||
ALIGN real_t S_M[MAX_M];
|
||||
|
||||
|
||||
for (l = 0; l < sbr->L_E[ch]; l++)
|
||||
{
|
||||
uint8_t current_f_noise_band = 0;
|
||||
|
@ -902,7 +877,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
|
|||
ALIGN real_t G_boost;
|
||||
ALIGN real_t S_M[MAX_M];
|
||||
|
||||
|
||||
for (l = 0; l < sbr->L_E[ch]; l++)
|
||||
{
|
||||
uint8_t current_f_noise_band = 0;
|
||||
|
@ -1415,11 +1389,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
|
|||
{
|
||||
G_target = 0;
|
||||
} else {
|
||||
#ifdef FIXED_POINT
|
||||
G_target = (((int64_t)(E_total))<<Q2_BITS)/(E_total_est + EPS);
|
||||
#else
|
||||
G_target = E_total / (E_total_est + EPS);
|
||||
#endif
|
||||
G_target = DIV_Q(E_total, (E_total_est + EPS));
|
||||
}
|
||||
acc = 0;
|
||||
|
||||
|
@ -1451,11 +1421,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
|
|||
{
|
||||
acc = 0;
|
||||
} else {
|
||||
#ifdef FIXED_POINT
|
||||
acc = (((int64_t)(E_total))<<Q2_BITS)/(acc + EPS);
|
||||
#else
|
||||
acc = E_total / (acc + EPS);
|
||||
#endif
|
||||
acc = DIV_Q(E_total, (acc + EPS));
|
||||
}
|
||||
for(m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
|
||||
{
|
||||
|
@ -1506,7 +1472,6 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
|
||||
uint8_t h_SL;
|
||||
|
||||
|
||||
if (sbr->Reset == 1)
|
||||
{
|
||||
assembly_reset = 1;
|
||||
|
@ -1665,39 +1630,46 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
|
|||
}
|
||||
}
|
||||
#else
|
||||
real_t tmp1 = 0;
|
||||
real_t tmp2 = 0;
|
||||
real_t tmp3 = 0;
|
||||
if ((m == 0) && (phi_re[i_plus1] != 0))
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx - 1]) +=
|
||||
(rev*phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][0]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp1 += (phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][0]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
if (sbr->M != 0)
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
|
||||
(rev*phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp2 -= (phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
}
|
||||
}
|
||||
if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0))
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
|
||||
(rev*phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp2 -= (phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
}
|
||||
if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_plus1] != 0))
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
|
||||
(rev*phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][m + 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp2 -= (phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][m + 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
}
|
||||
if ((m == sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0))
|
||||
{
|
||||
if (m > 0)
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
|
||||
(rev*phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp2 -= (phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
}
|
||||
if (m + sbr->kx < 64)
|
||||
{
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx + 1]) +=
|
||||
(rev*phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
tmp3 += (phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m]<<REAL_BITS), FRAC_CONST(0.00815)));
|
||||
}
|
||||
}
|
||||
|
||||
if (rev<0)
|
||||
{
|
||||
tmp1 = -tmp1;
|
||||
tmp2 = -tmp2;
|
||||
tmp3 = -tmp3;
|
||||
}
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx - 1]) += tmp1;
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx ]) += tmp2;
|
||||
QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx + 1]) += tmp3;
|
||||
#endif
|
||||
|
||||
if (adj->S_M_boost[l][m] != 0)
|
||||
|
|
|
@ -224,34 +224,34 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac,
|
|||
|
||||
for (j = offset; j < len + offset; j++)
|
||||
{
|
||||
real_t buf_j = ((QMF_RE(buffer[j][bd])+(1<<(exp-1)))>>exp);
|
||||
real_t buf_j_1 = ((QMF_RE(buffer[j-1][bd])+(1<<(exp-1)))>>exp);
|
||||
real_t buf_j_2 = ((QMF_RE(buffer[j-2][bd])+(1<<(exp-1)))>>exp);
|
||||
real_t buf_j = (QMF_RE(buffer[j ][bd]))>>exp);
|
||||
real_t buf_j_1 = (QMF_RE(buffer[j-1][bd]))>>exp);
|
||||
real_t buf_j_2 = (QMF_RE(buffer[j-2][bd]))>>exp);
|
||||
|
||||
/* normalisation with rounding */
|
||||
r01 += MUL_R(buf_j, buf_j_1);
|
||||
r02 += MUL_R(buf_j, buf_j_2);
|
||||
r01 += MUL_R(buf_j , buf_j_1);
|
||||
r02 += MUL_R(buf_j , buf_j_2);
|
||||
r11 += MUL_R(buf_j_1, buf_j_1);
|
||||
}
|
||||
RE(ac->r12) = r01 -
|
||||
MUL_R(((QMF_RE(buffer[len+offset-1][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp)) +
|
||||
MUL_R(((QMF_RE(buffer[offset-1][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp));
|
||||
MUL_R(((QMF_RE(buffer[len+offset-1][bd]))>>exp), ((QMF_RE(buffer[len+offset-2][bd]))>>exp)) +
|
||||
MUL_R(((QMF_RE(buffer[ offset-1][bd]))>>exp), ((QMF_RE(buffer[ offset-2][bd]))>>exp));
|
||||
RE(ac->r22) = r11 -
|
||||
MUL_R(((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp)) +
|
||||
MUL_R(((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp));
|
||||
MUL_R(((QMF_RE(buffer[len+offset-2][bd]))>>exp), ((QMF_RE(buffer[len+offset-2][bd]))>>exp)) +
|
||||
MUL_R(((QMF_RE(buffer[ offset-2][bd]))>>exp), ((QMF_RE(buffer[ offset-2][bd]))>>exp));
|
||||
#else
|
||||
for (j = offset; j < len + offset; j++)
|
||||
{
|
||||
r01 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]);
|
||||
r02 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]);
|
||||
r01 += QMF_RE(buffer[j ][bd]) * QMF_RE(buffer[j-1][bd]);
|
||||
r02 += QMF_RE(buffer[j ][bd]) * QMF_RE(buffer[j-2][bd]);
|
||||
r11 += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]);
|
||||
}
|
||||
RE(ac->r12) = r01 -
|
||||
QMF_RE(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
|
||||
QMF_RE(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]);
|
||||
QMF_RE(buffer[ offset-1][bd]) * QMF_RE(buffer[ offset-2][bd]);
|
||||
RE(ac->r22) = r11 -
|
||||
QMF_RE(buffer[len+offset-2][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
|
||||
QMF_RE(buffer[offset-2][bd]) * QMF_RE(buffer[offset-2][bd]);
|
||||
QMF_RE(buffer[ offset-2][bd]) * QMF_RE(buffer[ offset-2][bd]);
|
||||
#endif
|
||||
RE(ac->r01) = r01;
|
||||
RE(ac->r02) = r02;
|
||||
|
@ -268,7 +268,6 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS
|
|||
#ifdef FIXED_POINT
|
||||
const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f);
|
||||
uint32_t mask, exp;
|
||||
real_t pow2_to_exp;
|
||||
#else
|
||||
const real_t rel = 1 / (1 + 1e-6f);
|
||||
#endif
|
||||
|
@ -288,13 +287,11 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS
|
|||
}
|
||||
|
||||
exp = wl_min_lzc(mask);
|
||||
|
||||
pow2_to_exp = 1<<(exp-1);
|
||||
|
||||
temp2_r = (QMF_RE(buffer[offset-2][bd]) + pow2_to_exp) >> exp;
|
||||
temp2_i = (QMF_IM(buffer[offset-2][bd]) + pow2_to_exp) >> exp;
|
||||
temp3_r = (QMF_RE(buffer[offset-1][bd]) + pow2_to_exp) >> exp;
|
||||
temp3_i = (QMF_IM(buffer[offset-1][bd]) + pow2_to_exp) >> exp;
|
||||
temp2_r = (QMF_RE(buffer[offset-2][bd])) >> exp;
|
||||
temp2_i = (QMF_IM(buffer[offset-2][bd])) >> exp;
|
||||
temp3_r = (QMF_RE(buffer[offset-1][bd])) >> exp;
|
||||
temp3_i = (QMF_IM(buffer[offset-1][bd])) >> exp;
|
||||
// Save these because they are needed after loop
|
||||
temp4_r = temp2_r;
|
||||
temp4_i = temp2_i;
|
||||
|
@ -307,8 +304,8 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS
|
|||
temp1_i = temp2_i; // temp1_i = (QMF_IM(buffer[offset-2][bd] + (1<<(exp-1))) >> exp;
|
||||
temp2_r = temp3_r; // temp2_r = (QMF_RE(buffer[offset-1][bd] + (1<<(exp-1))) >> exp;
|
||||
temp2_i = temp3_i; // temp2_i = (QMF_IM(buffer[offset-1][bd] + (1<<(exp-1))) >> exp;
|
||||
temp3_r = (QMF_RE(buffer[j][bd]) + pow2_to_exp) >> exp;
|
||||
temp3_i = (QMF_IM(buffer[j][bd]) + pow2_to_exp) >> exp;
|
||||
temp3_r = (QMF_RE(buffer[j][bd])) >> exp;
|
||||
temp3_i = (QMF_IM(buffer[j][bd])) >> exp;
|
||||
r01r += MUL_R(temp3_r, temp2_r) + MUL_R(temp3_i, temp2_i);
|
||||
r01i += MUL_R(temp3_i, temp2_r) - MUL_R(temp3_r, temp2_i);
|
||||
r02r += MUL_R(temp3_r, temp1_r) + MUL_R(temp3_i, temp1_i);
|
||||
|
@ -404,7 +401,7 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS
|
|||
static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
||||
complex_t *alpha_0, complex_t *alpha_1, uint8_t k)
|
||||
{
|
||||
real_t tmp;
|
||||
real_t tmp, mul;
|
||||
acorr_coef ac;
|
||||
|
||||
auto_correlation(sbr, &ac, Xlow, k, sbr->numTimeSlotsRate + 6);
|
||||
|
@ -415,14 +412,15 @@ static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
|||
IM(alpha_1[k]) = 0;
|
||||
} else {
|
||||
#ifdef FIXED_POINT
|
||||
mul = DIV_R(REAL_CONST(1.0), ac.det);
|
||||
tmp = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11)));
|
||||
RE(alpha_1[k]) = DIV_R(tmp, ac.det);
|
||||
RE(alpha_1[k]) = MUL_R(tmp, mul);
|
||||
tmp = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11)));
|
||||
IM(alpha_1[k]) = DIV_R(tmp, ac.det);
|
||||
IM(alpha_1[k]) = MUL_R(tmp, mul);
|
||||
#else
|
||||
tmp = REAL_CONST(1.0) / ac.det;
|
||||
RE(alpha_1[k]) = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11))) * tmp;
|
||||
IM(alpha_1[k]) = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11))) * tmp;
|
||||
mul = REAL_CONST(1.0) / ac.det;
|
||||
RE(alpha_1[k]) = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11))) * mul;
|
||||
IM(alpha_1[k]) = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11))) * mul;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -432,10 +430,11 @@ static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
|||
IM(alpha_0[k]) = 0;
|
||||
} else {
|
||||
#ifdef FIXED_POINT
|
||||
mul = DIV_R(REAL_CONST(1.0), RE(ac.r11));
|
||||
tmp = -(RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12)) + MUL_R(IM(alpha_1[k]), IM(ac.r12)));
|
||||
RE(alpha_0[k]) = DIV_R(tmp, RE(ac.r11));
|
||||
RE(alpha_0[k]) = MUL_R(tmp, mul);
|
||||
tmp = -(IM(ac.r01) + MUL_R(IM(alpha_1[k]), RE(ac.r12)) - MUL_R(RE(alpha_1[k]), IM(ac.r12)));
|
||||
IM(alpha_0[k]) = DIV_R(tmp, RE(ac.r11));
|
||||
IM(alpha_0[k]) = MUL_R(tmp, mul);
|
||||
#else
|
||||
tmp = 1.0f / RE(ac.r11);
|
||||
RE(alpha_0[k]) = -(RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12)) + MUL_R(IM(alpha_1[k]), IM(ac.r12))) * tmp;
|
||||
|
@ -457,7 +456,7 @@ static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
|||
complex_t *alpha_0, complex_t *alpha_1, real_t *rxx)
|
||||
{
|
||||
uint8_t k;
|
||||
real_t tmp;
|
||||
real_t tmp, mul;
|
||||
acorr_coef ac;
|
||||
|
||||
for (k = 1; k < sbr->f_master[0]; k++)
|
||||
|
@ -469,11 +468,11 @@ static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
|||
RE(alpha_0[k]) = 0;
|
||||
RE(alpha_1[k]) = 0;
|
||||
} else {
|
||||
mul = DIV_R(REAL_CONST(1.0), ac.det);
|
||||
tmp = MUL_R(RE(ac.r01), RE(ac.r22)) - MUL_R(RE(ac.r12), RE(ac.r02));
|
||||
RE(alpha_0[k]) = DIV_R(tmp, (-ac.det));
|
||||
|
||||
RE(alpha_0[k]) = -MUL_R(tmp, mul);
|
||||
tmp = MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11));
|
||||
RE(alpha_1[k]) = DIV_R(tmp, ac.det);
|
||||
RE(alpha_1[k]) = MUL_R(tmp, mul);
|
||||
}
|
||||
|
||||
if ((RE(alpha_0[k]) >= REAL_CONST(4)) || (RE(alpha_1[k]) >= REAL_CONST(4)))
|
||||
|
@ -489,7 +488,7 @@ static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
|
|||
} else {
|
||||
rxx[k] = DIV_C(RE(ac.r01), RE(ac.r11));
|
||||
rxx[k] = -rxx[k];
|
||||
if (rxx[k] > COEF_CONST(1.0)) rxx[k] = COEF_CONST(1.0);
|
||||
if (rxx[k] > COEF_CONST( 1.0)) rxx[k] = COEF_CONST(1.0);
|
||||
if (rxx[k] < COEF_CONST(-1.0)) rxx[k] = COEF_CONST(-1.0);
|
||||
}
|
||||
}
|
||||
|
@ -581,7 +580,7 @@ static void calc_chirp_factors(sbr_info *sbr, uint8_t ch)
|
|||
if (sbr->bwArray[ch][i] < COEF_CONST(0.015625))
|
||||
sbr->bwArray[ch][i] = COEF_CONST(0.0);
|
||||
|
||||
if (sbr->bwArray[ch][i] >= COEF_CONST(0.99609375))
|
||||
if (sbr->bwArray[ch][i] > COEF_CONST(0.99609375))
|
||||
sbr->bwArray[ch][i] = COEF_CONST(0.99609375);
|
||||
|
||||
sbr->bwArray_prev[ch][i] = sbr->bwArray[ch][i];
|
||||
|
|
Loading…
Reference in a new issue