diff options
| author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2010-09-14 19:53:13 +0000 |
|---|---|---|
| committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2010-09-14 19:53:13 +0000 |
| commit | 82c143c4e1fb248ada018663f1d5b675d2174aea (patch) | |
| tree | dc7f4f2b1b3819b19db352ffe01e124a5ca3ac3c /apps/codecs | |
| parent | c8da311de4224e48da5099bc9adec046710f75c6 (diff) | |
| download | rockbox-82c143c4e1fb248ada018663f1d5b675d2174aea.zip rockbox-82c143c4e1fb248ada018663f1d5b675d2174aea.tar.gz rockbox-82c143c4e1fb248ada018663f1d5b675d2174aea.tar.bz2 rockbox-82c143c4e1fb248ada018663f1d5b675d2174aea.tar.xz | |
Also correct autocorrelation for yet undefined SBR_LOW_POWER. Unify FIXED_POINT and FLOAT implementation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28083 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
| -rw-r--r-- | apps/codecs/libfaad/sbr_hfgen.c | 138 |
1 files changed, 36 insertions, 102 deletions
diff --git a/apps/codecs/libfaad/sbr_hfgen.c b/apps/codecs/libfaad/sbr_hfgen.c index 5c346f1..2f9583c 100644 --- a/apps/codecs/libfaad/sbr_hfgen.c +++ b/apps/codecs/libfaad/sbr_hfgen.c @@ -196,85 +196,65 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, uint8_t offset = sbr->tHFAdj; #ifdef FIXED_POINT const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); - uint32_t exp = 2; -#else - const real_t rel = 1 / (1 + 1e-6f); -#endif - - -#ifdef FIXED_POINT /* A pre-shift of >>2 is needed to avoid overflow when multiply-adding * the FRACT-variables buffer -- FRACT part is 31 bits. After the * calculation has been finished the result 'ac.det' needs to be * post-shifted by <<(4*exp). */ + const uint32_t exp = 2; +#else + const real_t rel = 1 / (1 + 1e-6f); + const uint32_t exp = 0; +#endif for (j = offset; j < len + offset; j++) { - 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); - r11 += MUL_R(buf_j_1, buf_j_1); - } - tmp1 = (QMF_RE(buffer[len+offset-1][bd]))>>exp; - tmp2 = (QMF_RE(buffer[ offset-1][bd]))>>exp; - RE(ac->r12) = r01 - MUL_R(tmp1, tmp1) + MUL_R(tmp2, tmp2); + 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; - tmp1 = (QMF_RE(buffer[len+offset-2][bd]))>>exp; - tmp2 = (QMF_RE(buffer[ offset-2][bd]))>>exp; - RE(ac->r22) = r11 - MUL_R(tmp1, tmp1) + MUL_R(tmp2, tmp2); -#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]); - r11 += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]); + r01 += MUL_F(buf_j , buf_j_1); + r02 += MUL_F(buf_j , buf_j_2); + r11 += MUL_F(buf_j_1, buf_j_1); } - tmp1 = (QMF_RE(buffer[len+offset-1][bd])); - tmp2 = (QMF_RE(buffer[ offset-1][bd])); - RE(ac->r12) = r01 - tmp1*tmp1 + tmp2*tmp2; + tmp1 = QMF_RE(buffer[len+offset-1][bd]) >> exp; + tmp2 = QMF_RE(buffer[ offset-1][bd]) >> exp; + RE(ac->r12) = r01 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); - tmp1 = (QMF_RE(buffer[len+offset-2][bd])); - tmp2 = (QMF_RE(buffer[ offset-2][bd])); - RE(ac->r22) = r11 - tmp1*tmp1 + tmp2*tmp2; -#endif + tmp1 = QMF_RE(buffer[len+offset-2][bd]) >> exp; + tmp2 = QMF_RE(buffer[ offset-2][bd]) >> exp; + RE(ac->r22) = r11 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); RE(ac->r01) = r01; RE(ac->r02) = r02; RE(ac->r11) = r11; - ac->det = MUL_R(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_R(RE(ac->r12), RE(ac->r12)), rel); -#ifdef FIXED_POINT - ac->det <<= (4*exp); -#endif + ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_F(RE(ac->r12), RE(ac->r12)), rel); + ac->det <<= (4*exp); /* Post-shift as described above. */ } #else static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64], uint8_t bd, uint8_t len) { real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0; - real_t temp1_r, temp1_i, temp2_r, temp2_i, temp3_r, temp3_i, temp4_r, temp4_i, temp5_r, temp5_i; -#ifdef FIXED_POINT - const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); - uint32_t exp = 2; -#else - const real_t rel = 1 / (1 + 1e-6f); -#endif + real_t temp1_r, temp1_i, temp2_r, temp2_i, temp3_r, temp3_i; + real_t temp4_r, temp4_i, temp5_r, temp5_i; int8_t j; uint8_t offset = sbr->tHFAdj; - #ifdef FIXED_POINT + const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); /* A pre-shift of >>2 is needed to avoid overflow when multiply-adding * the FRACT-variables buffer -- FRACT part is 31 bits. After the * calculation has been finished the result 'ac.det' needs to be * post-shifted by <<(4*exp). */ + const uint32_t exp = 2; +#else + const real_t rel = 1 / (1 + 1e-6f); + const uint32_t exp = 0; +#endif - 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; + 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; @@ -287,8 +267,8 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS temp1_i = temp2_i; temp2_r = temp3_r; temp2_i = temp3_i; - temp3_r = (QMF_RE(buffer[j][bd])) >> exp; - temp3_i = (QMF_IM(buffer[j][bd])) >> exp; + temp3_r = QMF_RE(buffer[j][bd]) >> exp; + temp3_i = QMF_IM(buffer[j][bd]) >> exp; r01r += MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i); r01i += MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i); r02r += MUL_F(temp3_r, temp1_r) + MUL_F(temp3_i, temp1_i); @@ -302,49 +282,15 @@ static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTS (MUL_F(temp5_i, temp4_r) - MUL_F(temp5_r, temp4_i)); RE(ac->r22) = r11r - (MUL_F(temp2_r, temp2_r) + MUL_F(temp2_i, temp2_i)) + (MUL_F(temp4_r, temp4_r) + MUL_F(temp4_i, temp4_i)); -#else - temp2_r = QMF_RE(buffer[offset-2][bd]); - temp2_i = QMF_IM(buffer[offset-2][bd]); - temp3_r = QMF_RE(buffer[offset-1][bd]); - temp3_i = QMF_IM(buffer[offset-1][bd]); - // Save these because they are needed after loop - temp4_r = temp2_r; - temp4_i = temp2_i; - temp5_r = temp3_r; - temp5_i = temp3_i; - - for (j = offset; j < len + offset; j++) - { - temp1_r = temp2_r; - temp1_i = temp2_i; - temp2_r = temp3_r; - temp2_i = temp3_i; - temp3_r = QMF_RE(buffer[j][bd]); - temp3_i = QMF_IM(buffer[j][bd]); - r01r += temp3_r * temp2_r + temp3_i * temp2_i; - r01i += temp3_i * temp2_r - temp3_r * temp2_i; - r02r += temp3_r * temp1_r + temp3_i * temp1_i; - r02i += temp3_i * temp1_r - temp3_r * temp1_i; - r11r += temp2_r * temp2_r + temp2_i * temp2_i; - } - - RE(ac->r12) = r01r - (temp3_r * temp2_r + temp3_i * temp2_i) + - (temp5_r * temp4_r + temp5_i * temp4_i); - IM(ac->r12) = r01i - (temp3_i * temp2_r - temp3_r * temp2_i) + - (temp5_i * temp4_r - temp5_r * temp4_i); - RE(ac->r22) = r11r - (temp2_r * temp2_r + temp2_i * temp2_i) + - (temp4_r * temp4_r + temp4_i * temp4_i); -#endif RE(ac->r01) = r01r; IM(ac->r01) = r01i; RE(ac->r02) = r02r; IM(ac->r02) = r02i; RE(ac->r11) = r11r; - ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F(rel, (MUL_F(RE(ac->r12), RE(ac->r12)) + MUL_F(IM(ac->r12), IM(ac->r12)))); -#ifdef FIXED_POINT - ac->det <<= (4*exp); -#endif + 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); + ac->det <<= (4*exp); /* Post-shift as described above. */ + } #endif @@ -363,17 +309,11 @@ static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64], RE(alpha_1[k]) = 0; 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]) = 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]) = MUL_R(tmp, mul); -#else - 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 } if (RE(ac.r11) == 0) @@ -381,17 +321,11 @@ static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64], RE(alpha_0[k]) = 0; 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]) = 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]) = 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; - IM(alpha_0[k]) = -(IM(ac.r01) + MUL_R(IM(alpha_1[k]), RE(ac.r12)) - MUL_R(RE(alpha_1[k]), IM(ac.r12))) * tmp; -#endif } if ((MUL_R(RE(alpha_0[k]),RE(alpha_0[k])) + MUL_R(IM(alpha_0[k]),IM(alpha_0[k])) >= REAL_CONST(16)) || |