summaryrefslogtreecommitdiff
path: root/apps/codecs/libfaad/sbr_hfadj.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libfaad/sbr_hfadj.c')
-rw-r--r--apps/codecs/libfaad/sbr_hfadj.c54
1 files changed, 17 insertions, 37 deletions
diff --git a/apps/codecs/libfaad/sbr_hfadj.c b/apps/codecs/libfaad/sbr_hfadj.c
index 4984eaf1c4..806604519b 100644
--- a/apps/codecs/libfaad/sbr_hfadj.c
+++ b/apps/codecs/libfaad/sbr_hfadj.c
@@ -38,9 +38,11 @@
38#include "sbr_noise.h" 38#include "sbr_noise.h"
39 39
40#ifdef FIXED_POINT 40#ifdef FIXED_POINT
41#define REAL_SCALE(A) ((A)<<REAL_BITS) 41#define REAL_UPSCALE(A) ((A)<<REAL_BITS)
42#define REAL_DOWNSCALE(A) ((A)>>REAL_BITS)
42#else 43#else
43#define REAL_SCALE(A) (A) 44#define REAL_UPSCALE(A) (A)
45#define REAL_DOWNSCALE(A) (A)
44#endif 46#endif
45 47
46/* static function declarations */ 48/* static function declarations */
@@ -156,10 +158,10 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
156 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++) 158 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
157 { 159 {
158 tmp = QMF_RE(Xsbr[i][m + sbr->kx]); 160 tmp = QMF_RE(Xsbr[i][m + sbr->kx]);
159 nrg += MUL_R(tmp, (tmp>>REAL_BITS)); 161 nrg += MUL_R(tmp, REAL_DOWNSCALE(tmp));
160#ifndef SBR_LOW_POWER 162#ifndef SBR_LOW_POWER
161 tmp = QMF_IM(Xsbr[i][m + sbr->kx]); 163 tmp = QMF_IM(Xsbr[i][m + sbr->kx]);
162 nrg += MUL_R(tmp, (tmp>>REAL_BITS)); 164 nrg += MUL_R(tmp, REAL_DOWNSCALE(tmp));
163#endif 165#endif
164 } 166 }
165 167
@@ -192,10 +194,10 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
192 for (j = k_l; j < k_h; j++) 194 for (j = k_l; j < k_h; j++)
193 { 195 {
194 tmp = QMF_RE(Xsbr[i][j]); 196 tmp = QMF_RE(Xsbr[i][j]);
195 nrg += MUL_R(tmp, (tmp>>REAL_BITS)); 197 nrg += MUL_R(tmp, REAL_DOWNSCALE(tmp));
196#ifndef SBR_LOW_POWER 198#ifndef SBR_LOW_POWER
197 tmp = QMF_IM(Xsbr[i][j]); 199 tmp = QMF_IM(Xsbr[i][j]);
198 nrg += MUL_R(tmp, (tmp>>REAL_BITS)); 200 nrg += MUL_R(tmp, REAL_DOWNSCALE(tmp));
199#endif 201#endif
200 } 202 }
201 } 203 }
@@ -1151,7 +1153,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
1151 real_t den = 0; 1153 real_t den = 0;
1152 real_t acc1 = 0; 1154 real_t acc1 = 0;
1153 real_t acc2 = 0; 1155 real_t acc2 = 0;
1154 uint8_t current_res_band_size = 0;
1155 1156
1156 uint8_t ml1, ml2; 1157 uint8_t ml1, ml2;
1157 1158
@@ -1382,11 +1383,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
1382 /* E_total_est: integer */ 1383 /* E_total_est: integer */
1383 /* E_total: integer */ 1384 /* E_total: integer */
1384 E_total_est += sbr->E_curr[ch][m-sbr->kx][l]; 1385 E_total_est += sbr->E_curr[ch][m-sbr->kx][l];
1385#ifdef FIXED_POINT
1386 E_total += MUL_Q2(sbr->E_curr[ch][m-sbr->kx][l], adj->G_lim_boost[l][m-sbr->kx]); 1386 E_total += MUL_Q2(sbr->E_curr[ch][m-sbr->kx][l], adj->G_lim_boost[l][m-sbr->kx]);
1387#else
1388 E_total += sbr->E_curr[ch][m-sbr->kx][l] * adj->G_lim_boost[l][m-sbr->kx];
1389#endif
1390 } 1387 }
1391 1388
1392 /* G_target: fixed point */ 1389 /* G_target: fixed point */
@@ -1414,11 +1411,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
1414 MUL_C((COEF_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]); 1411 MUL_C((COEF_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]);
1415 1412
1416 /* acc: integer */ 1413 /* acc: integer */
1417#ifdef FIXED_POINT
1418 acc += MUL_Q2(adj->G_lim_boost[l][m-sbr->kx], sbr->E_curr[ch][m-sbr->kx][l]); 1414 acc += MUL_Q2(adj->G_lim_boost[l][m-sbr->kx], sbr->E_curr[ch][m-sbr->kx][l]);
1419#else
1420 acc += adj->G_lim_boost[l][m-sbr->kx] * sbr->E_curr[ch][m-sbr->kx][l];
1421#endif
1422 } 1415 }
1423 1416
1424 /* acc: fixed point */ 1417 /* acc: fixed point */
@@ -1430,11 +1423,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
1430 } 1423 }
1431 for(m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++) 1424 for(m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
1432 { 1425 {
1433#ifdef FIXED_POINT
1434 adj->G_lim_boost[l][m-sbr->kx] = MUL_Q2(acc, adj->G_lim_boost[l][m-sbr->kx]); 1426 adj->G_lim_boost[l][m-sbr->kx] = MUL_Q2(acc, adj->G_lim_boost[l][m-sbr->kx]);
1435#else
1436 adj->G_lim_boost[l][m-sbr->kx] = acc * adj->G_lim_boost[l][m-sbr->kx];
1437#endif
1438 } 1427 }
1439 } 1428 }
1440 } 1429 }
@@ -1556,33 +1545,24 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
1556 1545
1557 /* the smoothed gain values are applied to Xsbr */ 1546 /* the smoothed gain values are applied to Xsbr */
1558 /* V is defined, not calculated */ 1547 /* V is defined, not calculated */
1559#ifndef FIXED_POINT
1560 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = G_filt * QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx])
1561 + MUL_F(Q_filt, RE(V[fIndexNoise]));
1562#else
1563 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx])) 1548 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
1564 + MUL_F(Q_filt, RE(V[fIndexNoise])); 1549 + MUL_F(Q_filt, RE(V[fIndexNoise]));
1565#endif 1550
1566 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42) 1551 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42)
1567 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = 16428320; 1552 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = 16428320;
1568#ifndef SBR_LOW_POWER 1553#ifndef SBR_LOW_POWER
1569#ifndef FIXED_POINT
1570 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = G_filt * QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx])
1571 + MUL_F(Q_filt, IM(V[fIndexNoise]));
1572#else
1573 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx])) 1554 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
1574 + MUL_F(Q_filt, IM(V[fIndexNoise])); 1555 + MUL_F(Q_filt, IM(V[fIndexNoise]));
1575#endif 1556#endif
1576#endif
1577 1557
1578 { 1558 {
1579 int8_t rev = (((m + sbr->kx) & 1) ? -1 : 1); 1559 int8_t rev = (((m + sbr->kx) & 1) ? -1 : 1);
1580 QMF_RE(psi) = adj->S_M_boost[l][m] * phi_re[fIndexSine]; 1560 QMF_RE(psi) = adj->S_M_boost[l][m] * phi_re[fIndexSine];
1581 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += REAL_SCALE(QMF_RE(psi)); 1561 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += REAL_UPSCALE(QMF_RE(psi));
1582 1562
1583#ifndef SBR_LOW_POWER 1563#ifndef SBR_LOW_POWER
1584 QMF_IM(psi) = rev * adj->S_M_boost[l][m] * phi_im[fIndexSine]; 1564 QMF_IM(psi) = rev * adj->S_M_boost[l][m] * phi_im[fIndexSine];
1585 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += REAL_SCALE(QMF_IM(psi)); 1565 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += REAL_UPSCALE(QMF_IM(psi));
1586#else 1566#else
1587 1567
1588 i_min1 = (fIndexSine - 1) & 3; 1568 i_min1 = (fIndexSine - 1) & 3;
@@ -1593,29 +1573,29 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
1593 real_t tmp3 = 0; 1573 real_t tmp3 = 0;
1594 if ((m == 0) && (phi_re[i_plus1] != 0)) 1574 if ((m == 0) && (phi_re[i_plus1] != 0))
1595 { 1575 {
1596 tmp1 += (phi_re[i_plus1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][0]), FRAC_CONST(0.00815))); 1576 tmp1 += (phi_re[i_plus1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][0]), FRAC_CONST(0.00815)));
1597 if (sbr->M != 0) 1577 if (sbr->M != 0)
1598 { 1578 {
1599 tmp2 -= (phi_re[i_plus1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][1]), FRAC_CONST(0.00815))); 1579 tmp2 -= (phi_re[i_plus1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][1]), FRAC_CONST(0.00815)));
1600 } 1580 }
1601 } 1581 }
1602 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) 1582 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0))
1603 { 1583 {
1604 tmp2 -= (phi_re[i_min1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][m - 1]), FRAC_CONST(0.00815))); 1584 tmp2 -= (phi_re[i_min1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][m - 1]), FRAC_CONST(0.00815)));
1605 } 1585 }
1606 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_plus1] != 0)) 1586 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_plus1] != 0))
1607 { 1587 {
1608 tmp2 -= (phi_re[i_plus1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][m + 1]), FRAC_CONST(0.00815))); 1588 tmp2 -= (phi_re[i_plus1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][m + 1]), FRAC_CONST(0.00815)));
1609 } 1589 }
1610 if ((m == sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) 1590 if ((m == sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0))
1611 { 1591 {
1612 if (m > 0) 1592 if (m > 0)
1613 { 1593 {
1614 tmp2 -= (phi_re[i_min1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][m - 1]), FRAC_CONST(0.00815))); 1594 tmp2 -= (phi_re[i_min1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][m - 1]), FRAC_CONST(0.00815)));
1615 } 1595 }
1616 if (m + sbr->kx < 64) 1596 if (m + sbr->kx < 64)
1617 { 1597 {
1618 tmp3 += (phi_re[i_min1] * MUL_F(REAL_SCALE(adj->S_M_boost[l][m]), FRAC_CONST(0.00815))); 1598 tmp3 += (phi_re[i_min1] * MUL_F(REAL_UPSCALE(adj->S_M_boost[l][m]), FRAC_CONST(0.00815)));
1619 } 1599 }
1620 } 1600 }
1621 1601