Mercurial > libavcodec.hg
comparison mpegaudiodec.c @ 2490:c2c642ad6ef4 libavcodec
faster, simpler and more accurate l3_unscale()
author | michael |
---|---|
date | Tue, 01 Feb 2005 23:43:07 +0000 |
parents | 2e5ae040e92b |
children | c559ea6e395c |
comparison
equal
deleted
inserted
replaced
2489:2e5ae040e92b | 2490:c2c642ad6ef4 |
---|---|
160 static uint8_t *huff_code_table[16]; | 160 static uint8_t *huff_code_table[16]; |
161 static VLC huff_quad_vlc[2]; | 161 static VLC huff_quad_vlc[2]; |
162 /* computed from band_size_long */ | 162 /* computed from band_size_long */ |
163 static uint16_t band_index_long[9][23]; | 163 static uint16_t band_index_long[9][23]; |
164 /* XXX: free when all decoders are closed */ | 164 /* XXX: free when all decoders are closed */ |
165 #define TABLE_4_3_SIZE (8191 + 16) | 165 #define TABLE_4_3_SIZE (8191 + 16)*4 |
166 static int8_t *table_4_3_exp; | 166 static int8_t *table_4_3_exp; |
167 #if FRAC_BITS <= 15 | |
168 static uint16_t *table_4_3_value; | |
169 #else | |
170 static uint32_t *table_4_3_value; | 167 static uint32_t *table_4_3_value; |
171 #endif | |
172 /* intensity stereo coef table */ | 168 /* intensity stereo coef table */ |
173 static int32_t is_table[2][16]; | 169 static int32_t is_table[2][16]; |
174 static int32_t is_table_lsf[2][2][16]; | 170 static int32_t is_table_lsf[2][2][16]; |
175 static int32_t csa_table[8][4]; | 171 static int32_t csa_table[8][4]; |
176 static float csa_table_float[8][4]; | 172 static float csa_table_float[8][4]; |
187 | 183 |
188 static int32_t scale_factor_mult2[3][3] = { | 184 static int32_t scale_factor_mult2[3][3] = { |
189 SCALE_GEN(4.0 / 3.0), /* 3 steps */ | 185 SCALE_GEN(4.0 / 3.0), /* 3 steps */ |
190 SCALE_GEN(4.0 / 5.0), /* 5 steps */ | 186 SCALE_GEN(4.0 / 5.0), /* 5 steps */ |
191 SCALE_GEN(4.0 / 9.0), /* 9 steps */ | 187 SCALE_GEN(4.0 / 9.0), /* 9 steps */ |
192 }; | |
193 | |
194 /* 2^(n/4) */ | |
195 static uint32_t scale_factor_mult3[4] = { | |
196 FIXR(1.0), | |
197 FIXR(1.18920711500272106671), | |
198 FIXR(1.41421356237309504880), | |
199 FIXR(1.68179283050742908605), | |
200 }; | 188 }; |
201 | 189 |
202 void ff_mpa_synth_init(MPA_INT *window); | 190 void ff_mpa_synth_init(MPA_INT *window); |
203 static MPA_INT window[512] __attribute__((aligned(16))); | 191 static MPA_INT window[512] __attribute__((aligned(16))); |
204 | 192 |
234 } | 222 } |
235 | 223 |
236 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */ | 224 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */ |
237 static inline int l3_unscale(int value, int exponent) | 225 static inline int l3_unscale(int value, int exponent) |
238 { | 226 { |
239 #if FRAC_BITS <= 15 | 227 |
240 unsigned int m; | 228 unsigned int m; |
241 #else | |
242 uint64_t m; | |
243 #endif | |
244 int e; | 229 int e; |
245 | 230 |
246 e = table_4_3_exp[value]; | 231 e = table_4_3_exp [4*value + (exponent&3)]; |
247 e += (exponent >> 2); | 232 m = table_4_3_value[4*value + (exponent&3)]; |
248 e = FRAC_BITS - e; | 233 e -= (exponent >> 2); |
249 #if FRAC_BITS <= 15 | 234 assert(e>=1); |
250 if (e > 31) | 235 if (e > 31) |
251 #else | |
252 if (e > 63) | |
253 #endif | |
254 return 0; | 236 return 0; |
255 m = table_4_3_value[value]; | |
256 #if FRAC_BITS <= 15 | |
257 m = (m * scale_factor_mult3[exponent & 3]); | |
258 m = (m + (1 << (e-1))) >> e; | 237 m = (m + (1 << (e-1))) >> e; |
238 | |
259 return m; | 239 return m; |
260 #else | |
261 m = MUL64(m, scale_factor_mult3[exponent & 3]); | |
262 m = (m + (uint64_t_C(1) << (e-1))) >> e; | |
263 return m; | |
264 #endif | |
265 } | 240 } |
266 | 241 |
267 /* all integer n^(4/3) computation code */ | 242 /* all integer n^(4/3) computation code */ |
268 #define DEV_ORDER 13 | 243 #define DEV_ORDER 13 |
269 | 244 |
424 if(!table_4_3_value) | 399 if(!table_4_3_value) |
425 return -1; | 400 return -1; |
426 | 401 |
427 int_pow_init(); | 402 int_pow_init(); |
428 for(i=1;i<TABLE_4_3_SIZE;i++) { | 403 for(i=1;i<TABLE_4_3_SIZE;i++) { |
404 double f, fm; | |
429 int e, m; | 405 int e, m; |
430 m = int_pow(i, &e); | 406 f = pow((double)(i/4), 4.0 / 3.0) * pow(2, (i&3)*0.25); |
431 #if 0 | 407 fm = frexp(f, &e); |
432 /* test code */ | 408 m = FIXHR(fm*0.5); |
433 { | 409 e+= FRAC_BITS - 31; |
434 double f, fm; | 410 |
435 int e1, m1; | |
436 f = pow((double)i, 4.0 / 3.0); | |
437 fm = frexp(f, &e1); | |
438 m1 = FIXR(2 * fm); | |
439 #if FRAC_BITS <= 15 | |
440 if ((unsigned short)m1 != m1) { | |
441 m1 = m1 >> 1; | |
442 e1++; | |
443 } | |
444 #endif | |
445 e1--; | |
446 if (m != m1 || e != e1) { | |
447 printf("%4d: m=%x m1=%x e=%d e1=%d\n", | |
448 i, m, m1, e, e1); | |
449 } | |
450 } | |
451 #endif | |
452 /* normalized to FRAC_BITS */ | 411 /* normalized to FRAC_BITS */ |
453 table_4_3_value[i] = m; | 412 table_4_3_value[i] = m; |
454 table_4_3_exp[i] = e; | 413 // av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0)); |
414 table_4_3_exp[i] = -e; | |
455 } | 415 } |
456 | 416 |
457 for(i=0;i<7;i++) { | 417 for(i=0;i<7;i++) { |
458 float f; | 418 float f; |
459 int v; | 419 int v; |