diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2010-09-14 20:26:01 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2010-09-14 20:26:01 +0000 |
commit | 9fb54ae32bb6e0958094f9991caa7a493a091f27 (patch) | |
tree | 24a67de90086f537a4bc15982e4a2297c64aadbc | |
parent | 82c143c4e1fb248ada018663f1d5b675d2174aea (diff) | |
download | rockbox-9fb54ae32bb6e0958094f9991caa7a493a091f27.tar.gz rockbox-9fb54ae32bb6e0958094f9991caa7a493a091f27.zip |
More unification of FIXED_POINT and FLOAT. Small refactoring.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28084 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/libfaad/common.h | 14 | ||||
-rw-r--r-- | apps/codecs/libfaad/sbr_hfadj.c | 54 | ||||
-rw-r--r-- | apps/codecs/libfaad/sbr_hfgen.c | 64 |
3 files changed, 54 insertions, 78 deletions
diff --git a/apps/codecs/libfaad/common.h b/apps/codecs/libfaad/common.h index e6cdcd8646..abef33e645 100644 --- a/apps/codecs/libfaad/common.h +++ b/apps/codecs/libfaad/common.h | |||
@@ -285,9 +285,10 @@ char *strchr(), *strrchr(); | |||
285 | 285 | ||
286 | #include <math.h> | 286 | #include <math.h> |
287 | 287 | ||
288 | #define MUL_R(A,B) ((A)*(B)) | 288 | #define MUL_R(A,B) ((A)*(B)) |
289 | #define MUL_C(A,B) ((A)*(B)) | 289 | #define MUL_C(A,B) ((A)*(B)) |
290 | #define MUL_F(A,B) ((A)*(B)) | 290 | #define MUL_F(A,B) ((A)*(B)) |
291 | #define MUL_Q2(A,B) ((A)*(B)) | ||
291 | 292 | ||
292 | /* Complex multiplication */ | 293 | /* Complex multiplication */ |
293 | static INLINE void ComplexMult(real_t *y1, real_t *y2, | 294 | static INLINE void ComplexMult(real_t *y1, real_t *y2, |
@@ -306,9 +307,10 @@ char *strchr(), *strrchr(); | |||
306 | 307 | ||
307 | typedef float real_t; | 308 | typedef float real_t; |
308 | 309 | ||
309 | #define MUL_R(A,B) ((A)*(B)) | 310 | #define MUL_R(A,B) ((A)*(B)) |
310 | #define MUL_C(A,B) ((A)*(B)) | 311 | #define MUL_C(A,B) ((A)*(B)) |
311 | #define MUL_F(A,B) ((A)*(B)) | 312 | #define MUL_F(A,B) ((A)*(B)) |
313 | #define MUL_Q2(A,B) ((A)*(B)) | ||
312 | 314 | ||
313 | #define REAL_CONST(A) ((real_t)(A)) | 315 | #define REAL_CONST(A) ((real_t)(A)) |
314 | #define COEF_CONST(A) ((real_t)(A)) | 316 | #define COEF_CONST(A) ((real_t)(A)) |
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 | ||
diff --git a/apps/codecs/libfaad/sbr_hfgen.c b/apps/codecs/libfaad/sbr_hfgen.c index 2f9583cd6a..66ef656e55 100644 --- a/apps/codecs/libfaad/sbr_hfgen.c +++ b/apps/codecs/libfaad/sbr_hfgen.c | |||
@@ -185,6 +185,20 @@ typedef struct | |||
185 | real_t det; | 185 | real_t det; |
186 | } acorr_coef; | 186 | } acorr_coef; |
187 | 187 | ||
188 | /* Within auto_correlation(...) a pre-shift of >>2 is needed to avoid overflow | ||
189 | * when multiply-adding the FRACT-variables -- FRACT part is 31 bits. After the | ||
190 | * calculation has been finished the result 'ac->det' needs to be | ||
191 | * post-shifted by <<(4*2). This pre-/post-shifting is needed for FIXED_POINT | ||
192 | * only. */ | ||
193 | #ifdef FIXED_POINT | ||
194 | #define ACDET_EXP 2 | ||
195 | #define ACDET_PRE(A) (A)>>ACDET_EXP | ||
196 | #define ACDET_POST(A) (A)<<(4*ACDET_EXP) | ||
197 | #else | ||
198 | #define ACDET_PRE(A) (A) | ||
199 | #define ACDET_POST(A) (A) | ||
200 | #endif | ||
201 | |||
188 | #ifdef SBR_LOW_POWER | 202 | #ifdef SBR_LOW_POWER |
189 | static void auto_correlation(sbr_info *sbr, acorr_coef *ac, | 203 | static void auto_correlation(sbr_info *sbr, acorr_coef *ac, |
190 | qmf_t buffer[MAX_NTSRHFG][64], | 204 | qmf_t buffer[MAX_NTSRHFG][64], |
@@ -194,41 +208,31 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, | |||
194 | real_t tmp1, tmp2; | 208 | real_t tmp1, tmp2; |
195 | int8_t j; | 209 | int8_t j; |
196 | uint8_t offset = sbr->tHFAdj; | 210 | uint8_t offset = sbr->tHFAdj; |
197 | #ifdef FIXED_POINT | ||
198 | const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); | 211 | const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); |
199 | /* A pre-shift of >>2 is needed to avoid overflow when multiply-adding | ||
200 | * the FRACT-variables buffer -- FRACT part is 31 bits. After the | ||
201 | * calculation has been finished the result 'ac.det' needs to be | ||
202 | * post-shifted by <<(4*exp). */ | ||
203 | const uint32_t exp = 2; | ||
204 | #else | ||
205 | const real_t rel = 1 / (1 + 1e-6f); | ||
206 | const uint32_t exp = 0; | ||
207 | #endif | ||
208 | 212 | ||
209 | for (j = offset; j < len + offset; j++) | 213 | for (j = offset; j < len + offset; j++) |
210 | { | 214 | { |
211 | real_t buf_j = QMF_RE(buffer[j ][bd]) >> exp; | 215 | real_t buf_j = ACDET_PRE(QMF_RE(buffer[j ][bd])); |
212 | real_t buf_j_1 = QMF_RE(buffer[j-1][bd]) >> exp; | 216 | real_t buf_j_1 = ACDET_PRE(QMF_RE(buffer[j-1][bd])); |
213 | real_t buf_j_2 = QMF_RE(buffer[j-2][bd]) >> exp; | 217 | real_t buf_j_2 = ACDET_PRE(QMF_RE(buffer[j-2][bd])); |
214 | 218 | ||
215 | r01 += MUL_F(buf_j , buf_j_1); | 219 | r01 += MUL_F(buf_j , buf_j_1); |
216 | r02 += MUL_F(buf_j , buf_j_2); | 220 | r02 += MUL_F(buf_j , buf_j_2); |
217 | r11 += MUL_F(buf_j_1, buf_j_1); | 221 | r11 += MUL_F(buf_j_1, buf_j_1); |
218 | } | 222 | } |
219 | tmp1 = QMF_RE(buffer[len+offset-1][bd]) >> exp; | 223 | tmp1 = ACDET_PRE(QMF_RE(buffer[len+offset-1][bd])); |
220 | tmp2 = QMF_RE(buffer[ offset-1][bd]) >> exp; | 224 | tmp2 = ACDET_PRE(QMF_RE(buffer[ offset-1][bd])); |
221 | RE(ac->r12) = r01 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); | 225 | RE(ac->r12) = r01 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); |
222 | 226 | ||
223 | tmp1 = QMF_RE(buffer[len+offset-2][bd]) >> exp; | 227 | tmp1 = ACDET_PRE(QMF_RE(buffer[len+offset-2][bd])); |
224 | tmp2 = QMF_RE(buffer[ offset-2][bd]) >> exp; | 228 | tmp2 = ACDET_PRE(QMF_RE(buffer[ offset-2][bd])); |
225 | RE(ac->r22) = r11 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); | 229 | RE(ac->r22) = r11 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); |
226 | RE(ac->r01) = r01; | 230 | RE(ac->r01) = r01; |
227 | RE(ac->r02) = r02; | 231 | RE(ac->r02) = r02; |
228 | RE(ac->r11) = r11; | 232 | RE(ac->r11) = r11; |
229 | 233 | ||
230 | ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_F(RE(ac->r12), RE(ac->r12)), rel); | 234 | ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_F(RE(ac->r12), RE(ac->r12)), rel); |
231 | ac->det <<= (4*exp); /* Post-shift as described above. */ | 235 | ac->det = ACDET_POST(ac->det); |
232 | } | 236 | } |
233 | #else | 237 | #else |
234 | static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64], | 238 | static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64], |
@@ -239,22 +243,12 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS | |||
239 | real_t temp4_r, temp4_i, temp5_r, temp5_i; | 243 | real_t temp4_r, temp4_i, temp5_r, temp5_i; |
240 | int8_t j; | 244 | int8_t j; |
241 | uint8_t offset = sbr->tHFAdj; | 245 | uint8_t offset = sbr->tHFAdj; |
242 | #ifdef FIXED_POINT | ||
243 | const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); | 246 | const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); |
244 | /* A pre-shift of >>2 is needed to avoid overflow when multiply-adding | ||
245 | * the FRACT-variables buffer -- FRACT part is 31 bits. After the | ||
246 | * calculation has been finished the result 'ac.det' needs to be | ||
247 | * post-shifted by <<(4*exp). */ | ||
248 | const uint32_t exp = 2; | ||
249 | #else | ||
250 | const real_t rel = 1 / (1 + 1e-6f); | ||
251 | const uint32_t exp = 0; | ||
252 | #endif | ||
253 | 247 | ||
254 | temp2_r = QMF_RE(buffer[offset-2][bd]) >> exp; | 248 | temp2_r = ACDET_PRE(QMF_RE(buffer[offset-2][bd])); |
255 | temp2_i = QMF_IM(buffer[offset-2][bd]) >> exp; | 249 | temp2_i = ACDET_PRE(QMF_IM(buffer[offset-2][bd])); |
256 | temp3_r = QMF_RE(buffer[offset-1][bd]) >> exp; | 250 | temp3_r = ACDET_PRE(QMF_RE(buffer[offset-1][bd])); |
257 | temp3_i = QMF_IM(buffer[offset-1][bd]) >> exp; | 251 | temp3_i = ACDET_PRE(QMF_IM(buffer[offset-1][bd])); |
258 | // Save these because they are needed after loop | 252 | // Save these because they are needed after loop |
259 | temp4_r = temp2_r; | 253 | temp4_r = temp2_r; |
260 | temp4_i = temp2_i; | 254 | temp4_i = temp2_i; |
@@ -267,8 +261,8 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS | |||
267 | temp1_i = temp2_i; | 261 | temp1_i = temp2_i; |
268 | temp2_r = temp3_r; | 262 | temp2_r = temp3_r; |
269 | temp2_i = temp3_i; | 263 | temp2_i = temp3_i; |
270 | temp3_r = QMF_RE(buffer[j][bd]) >> exp; | 264 | temp3_r = ACDET_PRE(QMF_RE(buffer[j][bd])); |
271 | temp3_i = QMF_IM(buffer[j][bd]) >> exp; | 265 | temp3_i = ACDET_PRE(QMF_IM(buffer[j][bd])); |
272 | r01r += MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i); | 266 | r01r += MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i); |
273 | r01i += MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i); | 267 | r01i += MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i); |
274 | r02r += MUL_F(temp3_r, temp1_r) + MUL_F(temp3_i, temp1_i); | 268 | r02r += MUL_F(temp3_r, temp1_r) + MUL_F(temp3_i, temp1_i); |
@@ -289,7 +283,7 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS | |||
289 | RE(ac->r11) = r11r; | 283 | RE(ac->r11) = r11r; |
290 | 284 | ||
291 | ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F((MUL_F(RE(ac->r12), RE(ac->r12)) + MUL_F(IM(ac->r12), IM(ac->r12))), rel); | 285 | ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F((MUL_F(RE(ac->r12), RE(ac->r12)) + MUL_F(IM(ac->r12), IM(ac->r12))), rel); |
292 | ac->det <<= (4*exp); /* Post-shift as described above. */ | 286 | ac->det = ACDET_POST(ac->det); |
293 | 287 | ||
294 | } | 288 | } |
295 | #endif | 289 | #endif |