Mercurial > libavcodec.hg
comparison mpegaudiodec.c @ 392:4ef26ed29399 libavcodec
put all integer init code to compute n^(4/3) - memory alloc and header fixes
author | glantau |
---|---|
date | Sat, 18 May 2002 22:58:08 +0000 |
parents | ce35fd27bbb0 |
children | 29dc52c127c6 |
comparison
equal
deleted
inserted
replaced
391:ddb1be8aa479 | 392:4ef26ed29399 |
---|---|
16 * along with this program; if not, write to the Free Software | 16 * along with this program; if not, write to the Free Software |
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 */ | 18 */ |
19 //#define DEBUG | 19 //#define DEBUG |
20 #include "avcodec.h" | 20 #include "avcodec.h" |
21 #include <math.h> | |
22 #include "mpegaudio.h" | 21 #include "mpegaudio.h" |
23 | 22 |
24 /* | 23 /* |
25 * TODO: | 24 * TODO: |
26 * - in low precision mode, use more 16 bit multiplies in synth filter | 25 * - in low precision mode, use more 16 bit multiplies in synth filter |
219 m = (m + (UINT64_C(1) << (e-1))) >> e; | 218 m = (m + (UINT64_C(1) << (e-1))) >> e; |
220 return m; | 219 return m; |
221 #endif | 220 #endif |
222 } | 221 } |
223 | 222 |
223 /* all integer n^(4/3) computation code */ | |
224 #define DEV_ORDER 13 | |
225 | |
226 #define POW_FRAC_BITS 24 | |
227 #define POW_FRAC_ONE (1 << POW_FRAC_BITS) | |
228 #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE)) | |
229 #define POW_MULL(a,b) (((INT64)(a) * (INT64)(b)) >> POW_FRAC_BITS) | |
230 | |
231 static int dev_4_3_coefs[DEV_ORDER]; | |
232 | |
233 static int pow_mult3[3] = { | |
234 POW_FIX(1.0), | |
235 POW_FIX(1.25992104989487316476), | |
236 POW_FIX(1.58740105196819947474), | |
237 }; | |
238 | |
239 static void int_pow_init(void) | |
240 { | |
241 int i, a; | |
242 | |
243 a = POW_FIX(1.0); | |
244 for(i=0;i<DEV_ORDER;i++) { | |
245 a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1); | |
246 dev_4_3_coefs[i] = a; | |
247 } | |
248 } | |
249 | |
250 /* return the mantissa and the binary exponent */ | |
251 static int int_pow(int i, int *exp_ptr) | |
252 { | |
253 int e, er, eq, j; | |
254 int a, a1; | |
255 | |
256 /* renormalize */ | |
257 a = i; | |
258 e = POW_FRAC_BITS; | |
259 while (a < (1 << (POW_FRAC_BITS - 1))) { | |
260 a = a << 1; | |
261 e--; | |
262 } | |
263 a -= (1 << POW_FRAC_BITS); | |
264 a1 = 0; | |
265 for(j = DEV_ORDER - 1; j >= 0; j--) | |
266 a1 = POW_MULL(a, dev_4_3_coefs[j] + a1); | |
267 a = (1 << POW_FRAC_BITS) + a1; | |
268 /* exponent compute (exact) */ | |
269 e = e * 4; | |
270 er = e % 3; | |
271 eq = e / 3; | |
272 a = POW_MULL(a, pow_mult3[er]); | |
273 while (a >= 2 * POW_FRAC_ONE) { | |
274 a = a >> 1; | |
275 eq++; | |
276 } | |
277 /* convert to float */ | |
278 while (a < POW_FRAC_ONE) { | |
279 a = a << 1; | |
280 eq--; | |
281 } | |
282 *exp_ptr = eq; | |
283 #if POW_FRAC_BITS == FRAC_BITS | |
284 return a; | |
285 #else | |
286 return (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS); | |
287 #endif | |
288 } | |
224 | 289 |
225 static int decode_init(AVCodecContext * avctx) | 290 static int decode_init(AVCodecContext * avctx) |
226 { | 291 { |
227 MPADecodeContext *s = avctx->priv_data; | 292 MPADecodeContext *s = avctx->priv_data; |
228 static int init; | 293 static int init; |
313 if (!table_4_3_exp) | 378 if (!table_4_3_exp) |
314 return -1; | 379 return -1; |
315 table_4_3_value = av_mallocz(TABLE_4_3_SIZE * | 380 table_4_3_value = av_mallocz(TABLE_4_3_SIZE * |
316 sizeof(table_4_3_value[0])); | 381 sizeof(table_4_3_value[0])); |
317 if (!table_4_3_value) { | 382 if (!table_4_3_value) { |
318 free(table_4_3_exp); | 383 av_free(table_4_3_exp); |
319 return -1; | 384 return -1; |
320 } | 385 } |
321 | 386 |
387 int_pow_init(); | |
322 for(i=1;i<TABLE_4_3_SIZE;i++) { | 388 for(i=1;i<TABLE_4_3_SIZE;i++) { |
323 double f, fm; | |
324 int e, m; | 389 int e, m; |
325 f = pow((double)i, 4.0 / 3.0); | 390 m = int_pow(i, &e); |
326 fm = frexp(f, &e); | |
327 m = FIXR(2 * fm); | |
328 #if FRAC_BITS <= 15 | 391 #if FRAC_BITS <= 15 |
329 if ((unsigned short)m != m) | 392 if ((unsigned short)m != m) |
330 m = 65535; | 393 m = 65535; |
394 #endif | |
395 #if 0 | |
396 /* test code */ | |
397 { | |
398 double f, fm; | |
399 int e1, m1; | |
400 f = pow((double)i, 4.0 / 3.0); | |
401 fm = frexp(f, &e1); | |
402 m1 = FIXR(2 * fm); | |
403 #if FRAC_BITS <= 15 | |
404 if ((unsigned short)m1 != m1) | |
405 m1 = 65535; | |
406 #endif | |
407 e1--; | |
408 if (m != m1 || e != e1) { | |
409 printf("%4d: m=%x m1=%x e=%d e1=%d\n", | |
410 i, m, m1, e, e1); | |
411 } | |
412 } | |
331 #endif | 413 #endif |
332 /* normalized to FRAC_BITS */ | 414 /* normalized to FRAC_BITS */ |
333 table_4_3_value[i] = m; | 415 table_4_3_value[i] = m; |
334 table_4_3_exp[i] = e - 1; | 416 table_4_3_exp[i] = e - 1; |
335 } | 417 } |