diff options
Diffstat (limited to 'apps/codecs/libfaad/sbr_hfgen.c')
-rw-r--r-- | apps/codecs/libfaad/sbr_hfgen.c | 64 |
1 files changed, 29 insertions, 35 deletions
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 |