1diff -ruN a52dec.orig/include/a52.h a52dec/include/a52.h 2--- a52dec.orig/include/a52.h 2012-11-13 17:25:33.438758556 +0100 3+++ a52dec/include/a52.h 2012-11-13 17:27:31.143704187 +0100 4@@ -1,6 +1,6 @@ 5 /* 6 * a52.h 7- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 8+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 9 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 10 * 11 * This file is part of a52dec, a free ATSC A-52 stream decoder. 12@@ -24,10 +24,17 @@ 13 #ifndef A52_H 14 #define A52_H 15 16-#ifndef LIBA52_DOUBLE 17-typedef float sample_t; 18-#else 19+#define LIBA52_FIXED 20+ 21+#if defined(LIBA52_FIXED) 22+typedef int32_t sample_t; 23+typedef int32_t level_t; 24+#elif defined(LIBA52_DOUBLE) 25 typedef double sample_t; 26+typedef double level_t; 27+#else 28+typedef float sample_t; 29+typedef float level_t; 30 #endif 31 32 typedef struct a52_state_s a52_state_t; 33@@ -53,9 +60,9 @@ 34 int a52_syncinfo (uint8_t * buf, int * flags, 35 int * sample_rate, int * bit_rate); 36 int a52_frame (a52_state_t * state, uint8_t * buf, int * flags, 37- sample_t * level, sample_t bias); 38+ level_t * level, sample_t bias); 39 void a52_dynrng (a52_state_t * state, 40- sample_t (* call) (sample_t, void *), void * data); 41+ level_t (* call) (level_t, void *), void * data); 42 int a52_block (a52_state_t * state); 43 void a52_free (a52_state_t * state); 44 45diff -ruN a52dec.orig/include/attributes.h a52dec/include/attributes.h 46--- a52dec.orig/include/attributes.h 2012-11-13 17:25:33.438758556 +0100 47+++ a52dec/include/attributes.h 2012-11-13 17:27:31.147037566 +0100 48@@ -1,6 +1,6 @@ 49 /* 50 * attributes.h 51- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 52+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 53 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 54 * 55 * This file is part of a52dec, a free ATSC A-52 stream decoder. 56@@ -27,3 +27,11 @@ 57 #else 58 #define ATTR_ALIGN(align) 59 #endif 60+ 61+#ifdef HAVE_BUILTIN_EXPECT 62+#define likely(x) __builtin_expect ((x) != 0, 1) 63+#define unlikely(x) __builtin_expect ((x) != 0, 0) 64+#else 65+#define likely(x) (x) 66+#define unlikely(x) (x) 67+#endif 68diff -ruN a52dec.orig/include/mm_accel.h a52dec/include/mm_accel.h 69--- a52dec.orig/include/mm_accel.h 2012-11-13 17:25:33.438758556 +0100 70+++ a52dec/include/mm_accel.h 2012-11-13 17:27:31.147037566 +0100 71@@ -1,6 +1,6 @@ 72 /* 73 * mm_accel.h 74- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 75+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 76 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 77 * 78 * This file is part of a52dec, a free ATSC A-52 stream decoder. 79diff -ruN a52dec.orig/include/tendra.h a52dec/include/tendra.h 80--- a52dec.orig/include/tendra.h 2012-11-13 17:25:33.438758556 +0100 81+++ a52dec/include/tendra.h 2012-11-13 17:27:31.147037566 +0100 82@@ -1,6 +1,6 @@ 83 /* 84 * tendra.h 85- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 86+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 87 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 88 * 89 * This file is part of a52dec, a free ATSC A-52 stream decoder. 90diff -ruN a52dec.orig/liba52/a52_internal.h a52dec/liba52/a52_internal.h 91--- a52dec.orig/liba52/a52_internal.h 2012-11-13 17:25:33.438758556 +0100 92+++ a52dec/liba52/a52_internal.h 2012-11-13 17:27:31.147037566 +0100 93@@ -1,6 +1,6 @@ 94 /* 95 * a52_internal.h 96- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 97+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 98 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 99 * 100 * This file is part of a52dec, a free ATSC A-52 stream decoder. 101@@ -37,24 +37,24 @@ 102 uint8_t halfrate; /* halfrate factor */ 103 uint8_t acmod; /* coded channels */ 104 uint8_t lfeon; /* coded lfe channel */ 105- sample_t clev; /* centre channel mix level */ 106- sample_t slev; /* surround channels mix level */ 107+ level_t clev; /* centre channel mix level */ 108+ level_t slev; /* surround channels mix level */ 109 110 int output; /* type of output */ 111- sample_t level; /* output level */ 112+ level_t level; /* output level */ 113 sample_t bias; /* output bias */ 114 115 int dynrnge; /* apply dynamic range */ 116- sample_t dynrng; /* dynamic range */ 117+ level_t dynrng; /* dynamic range */ 118 void * dynrngdata; /* dynamic range callback funtion and data */ 119- sample_t (* dynrngcall) (sample_t range, void * dynrngdata); 120+ level_t (* dynrngcall) (level_t range, void * dynrngdata); 121 122 uint8_t chincpl; /* channel coupled */ 123 uint8_t phsflginu; /* phase flags in use (stereo only) */ 124 uint8_t cplstrtmant; /* coupling channel start mantissa */ 125 uint8_t cplendmant; /* coupling channel end mantissa */ 126 uint32_t cplbndstrc; /* coupling band structure */ 127- sample_t cplco[5][18]; /* coupling coordinates */ 128+ level_t cplco[5][18]; /* coupling coordinates */ 129 130 /* derived information */ 131 uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */ 132@@ -107,14 +107,79 @@ 133 int start, int end, int fastleak, int slowleak, 134 expbap_t * expbap); 135 136-int a52_downmix_init (int input, int flags, sample_t * level, 137- sample_t clev, sample_t slev); 138-int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level, 139- sample_t clev, sample_t slev); 140+int a52_downmix_init (int input, int flags, level_t * level, 141+ level_t clev, level_t slev); 142+int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level, 143+ level_t clev, level_t slev); 144 void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias, 145- sample_t clev, sample_t slev); 146+ level_t clev, level_t slev); 147 void a52_upmix (sample_t * samples, int acmod, int output); 148 149 void a52_imdct_init (uint32_t mm_accel); 150 void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias); 151 void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias); 152+ 153+#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5))) 154+ 155+#ifndef LIBA52_FIXED 156+ 157+typedef sample_t quantizer_t; 158+#define SAMPLE(x) (x) 159+#define LEVEL(x) (x) 160+#define MUL(a,b) ((a) * (b)) 161+#define MUL_L(a,b) ((a) * (b)) 162+#define MUL_C(a,b) ((a) * (b)) 163+#define DIV(a,b) ((a) / (b)) 164+#define BIAS(x) ((x) + bias) 165+ 166+#else /* LIBA52_FIXED */ 167+ 168+typedef int16_t quantizer_t; 169+#define SAMPLE(x) (sample_t)((x) * (1 << 30)) 170+#define LEVEL(x) (level_t)((x) * (1 << 26)) 171+ 172+#if 0 173+#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30)) 174+#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26)) 175+#elif defined(CPU_COLDFIRE) 176+/* loses 1 bit of accuracy */ 177+#define MUL(a, b) \ 178+({ \ 179+ int32_t t; \ 180+ asm volatile ( \ 181+ "mac.l %[A], %[B], %%acc0\n\t" \ 182+ "movclr.l %%acc0, %[t]\n\t" \ 183+ "asl.l #1, %[t]" \ 184+ : [t] "=d" (t) \ 185+ : [A] "r" ((a)), [B] "r" ((b))); \ 186+ t; \ 187+}) 188+/* loses 5 bits of accuracy */ 189+#define MUL_L(a, b) \ 190+({ \ 191+ int32_t t; \ 192+ asm volatile ( \ 193+ "mac.l %[A], %[B], %%acc0\n\t" \ 194+ "movclr.l %%acc0, %[t]\n\t" \ 195+ "asl.l #5, %[t]" \ 196+ : [t] "=d" (t) \ 197+ : [A] "r" ((a)), [B] "r" ((b))); \ 198+ t; \ 199+}) 200+#elif 1 201+#define MUL(a,b) \ 202+({ int32_t _ta=(a), _tb=(b), _tc; \ 203+ _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); }) 204+#define MUL_L(a,b) \ 205+({ int32_t _ta=(a), _tb=(b), _tc; \ 206+ _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); }) 207+#else 208+#define MUL(a,b) (((a) >> 15) * ((b) >> 15)) 209+#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13)) 210+#endif 211+ 212+#define MUL_C(a,b) MUL_L (a, LEVEL (b)) 213+#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b)) 214+#define BIAS(x) ((x) + (bias*0)) 215+ 216+#endif 217diff -ruN a52dec.orig/liba52/bit_allocate.c a52dec/liba52/bit_allocate.c 218--- a52dec.orig/liba52/bit_allocate.c 2012-11-13 17:25:33.438758556 +0100 219+++ a52dec/liba52/bit_allocate.c 2012-11-13 17:27:31.147037566 +0100 220@@ -1,6 +1,6 @@ 221 /* 222 * bit_allocate.c 223- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 224+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 225 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 226 * 227 * This file is part of a52dec, a free ATSC A-52 stream decoder. 228@@ -21,14 +21,14 @@ 229 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 230 */ 231 232-#include "config.h" 233+#include "config-a52.h" 234 235 #include <inttypes.h> 236 237 #include "a52.h" 238 #include "a52_internal.h" 239 240-static int hthtab[3][50] = { 241+static int hthtab[3][50] IDATA_ATTR = { 242 {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860, 243 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890, 244 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900, 245@@ -46,7 +46,7 @@ 246 0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720} 247 }; 248 249-static int8_t baptab[305] = { 250+static int8_t baptab[305] IDATA_ATTR = { 251 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 252 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 253 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 254@@ -71,11 +71,11 @@ 255 0, 0, 0, 0 /* 148 padding elems */ 256 }; 257 258-static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34, 259+static int bndtab[30] IDATA_ATTR = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34, 260 37, 40, 43, 46, 49, 55, 61, 67, 73, 79, 261 85, 97, 109, 121, 133, 157, 181, 205, 229, 253}; 262 263-static int8_t latab[256] = { 264+static int8_t latab[256] IDATA_ATTR = { 265 -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, 266 -52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44, 267 -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35, 268@@ -231,7 +231,7 @@ 269 int startband, endband; 270 271 startband = j; 272- endband = ((bndtab-20)[i] < end) ? (bndtab-20)[i] : end; 273+ endband = (bndtab[i-20] < end) ? bndtab[i-20] : end; 274 psd = 128 * exp[j++]; 275 while (j < endband) { 276 int next, delta; 277diff -ruN a52dec.orig/liba52/bitstream.c a52dec/liba52/bitstream.c 278--- a52dec.orig/liba52/bitstream.c 2012-11-13 17:25:33.442091935 +0100 279+++ a52dec/liba52/bitstream.c 2012-11-13 17:27:31.147037566 +0100 280@@ -1,6 +1,6 @@ 281 /* 282 * bitstream.c 283- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 284+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 285 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 286 * 287 * This file is part of a52dec, a free ATSC A-52 stream decoder. 288@@ -21,7 +21,7 @@ 289 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 290 */ 291 292-#include "config.h" 293+#include "config-a52.h" 294 295 #include <inttypes.h> 296 297@@ -38,7 +38,9 @@ 298 align = (long)buf & 3; 299 state->buffer_start = (uint32_t *) (buf - align); 300 state->bits_left = 0; 301+ state->current_word = 0; 302 bitstream_get (state, align * 8); 303+ bitstream_get_2 (state, 0); /* pretend function is used - keep gcc happy */ 304 } 305 306 static inline void bitstream_fill_current (a52_state_t * state) 307diff -ruN a52dec.orig/liba52/bitstream.h a52dec/liba52/bitstream.h 308--- a52dec.orig/liba52/bitstream.h 2012-11-13 17:25:33.442091935 +0100 309+++ a52dec/liba52/bitstream.h 2012-11-13 17:27:31.147037566 +0100 310@@ -1,6 +1,6 @@ 311 /* 312 * bitstream.h 313- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 314+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 315 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 316 * 317 * This file is part of a52dec, a free ATSC A-52 stream decoder. 318@@ -21,29 +21,29 @@ 319 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 320 */ 321 322-/* (stolen from the kernel) */ 323+//#define swab32(x) (betoh32(x)) 324 #ifdef WORDS_BIGENDIAN 325 326-# define swab32(x) (x) 327+# define swab32(x) (x) 328 329 #else 330 331-# if 0 && defined (__i386__) 332+# if defined (__i386__) 333 334-# define swab32(x) __i386_swab32(x) 335- static inline const uint32_t __i386_swab32(uint32_t x) 336- { 337- __asm__("bswap %0" : "=r" (x) : "0" (x)); 338- return x; 339- } 340+# define swab32(x) __i386_swab32(x) 341+ static inline const uint32_t __i386_swab32(uint32_t x) 342+ { 343+ __asm__("bswap %0" : "=r" (x) : "0" (x)); 344+ return x; 345+ } 346 347-# else 348+# else 349 350-# define swab32(x)\ 351+# define swab32(x)\ 352 ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \ 353 (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3])) 354 355-# endif 356+# endif 357 #endif 358 359 void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf); 360diff -ruN a52dec.orig/liba52/config-a52.h a52dec/liba52/config-a52.h 361--- a52dec.orig/liba52/config-a52.h 1970-01-01 01:00:00.000000000 +0100 362+++ a52dec/liba52/config-a52.h 2012-11-13 17:27:31.150370945 +0100 363@@ -0,0 +1,26 @@ 364+#define IDATA_ATTR 365+#define IBSS_ATTR 366+/* a52dec profiling */ 367+/* #undef A52DEC_GPROF */ 368+ 369+/* Define to 1 if you have the `memalign' function. */ 370+/* #undef HAVE_MEMALIGN 1 */ 371+ 372+/* liba52 djbfft support */ 373+/* #undef LIBA52_DJBFFT */ 374+ 375+/* a52 sample precision */ 376+/* #undef LIBA52_DOUBLE */ 377+ 378+/* use fixed-point arithmetic */ 379+#define LIBA52_FIXED 380+ 381+/* Define to 1 if your processor stores words with the most significant byte 382+ first (like Motorola and SPARC, unlike Intel and VAX). */ 383+ 384+/* Used in bitstream.h */ 385+ 386+#ifdef ROCKBOX_BIG_ENDIAN 387+#define WORDS_BIGENDIAN 1 388+#endif 389+ 390diff -ruN a52dec.orig/liba52/downmix.c a52dec/liba52/downmix.c 391--- a52dec.orig/liba52/downmix.c 2012-11-13 17:25:33.442091935 +0100 392+++ a52dec/liba52/downmix.c 2012-11-13 17:27:31.150370945 +0100 393@@ -1,6 +1,6 @@ 394 /* 395 * downmix.c 396- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 397+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 398 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 399 * 400 * This file is part of a52dec, a free ATSC A-52 stream decoder. 401@@ -21,7 +21,7 @@ 402 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 403 */ 404 405-#include "config.h" 406+#include "config-a52.h" 407 408 #include <string.h> 409 #include <inttypes.h> 410@@ -31,8 +31,8 @@ 411 412 #define CONVERT(acmod,output) (((output) << 3) + (acmod)) 413 414-int a52_downmix_init (int input, int flags, sample_t * level, 415- sample_t clev, sample_t slev) 416+int a52_downmix_init (int input, int flags, level_t * level, 417+ level_t clev, level_t slev) 418 { 419 static uint8_t table[11][8] = { 420 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO, 421@@ -66,94 +66,106 @@ 422 423 output = table[output][input & 7]; 424 425- if ((output == A52_STEREO) && 426- ((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB)))) 427+ if (output == A52_STEREO && 428+ (input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB)))) 429 output = A52_DOLBY; 430 431- if (flags & A52_ADJUST_LEVEL) 432+ if (flags & A52_ADJUST_LEVEL) { 433+ level_t adjust; 434+ 435 switch (CONVERT (input & 7, output)) { 436 437 case CONVERT (A52_3F, A52_MONO): 438- *level *= LEVEL_3DB / (1 + clev); 439+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev); 440 break; 441 442 case CONVERT (A52_STEREO, A52_MONO): 443 case CONVERT (A52_2F2R, A52_2F1R): 444 case CONVERT (A52_3F2R, A52_3F1R): 445 level_3db: 446- *level *= LEVEL_3DB; 447+ adjust = LEVEL (LEVEL_3DB); 448 break; 449 450 case CONVERT (A52_3F2R, A52_2F1R): 451- if (clev < LEVEL_PLUS3DB - 1) 452+ if (clev < LEVEL (LEVEL_PLUS3DB - 1)) 453 goto level_3db; 454 /* break thru */ 455 case CONVERT (A52_3F, A52_STEREO): 456 case CONVERT (A52_3F1R, A52_2F1R): 457 case CONVERT (A52_3F1R, A52_2F2R): 458 case CONVERT (A52_3F2R, A52_2F2R): 459- *level /= 1 + clev; 460+ adjust = DIV (1, LEVEL (1) + clev); 461 break; 462 463 case CONVERT (A52_2F1R, A52_MONO): 464- *level *= LEVEL_PLUS3DB / (2 + slev); 465+ adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev); 466 break; 467 468 case CONVERT (A52_2F1R, A52_STEREO): 469 case CONVERT (A52_3F1R, A52_3F): 470- *level /= 1 + slev * LEVEL_3DB; 471+ adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB)); 472 break; 473 474 case CONVERT (A52_3F1R, A52_MONO): 475- *level *= LEVEL_3DB / (1 + clev + 0.5 * slev); 476+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5)); 477 break; 478 479 case CONVERT (A52_3F1R, A52_STEREO): 480- *level /= 1 + clev + slev * LEVEL_3DB; 481+ adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB)); 482 break; 483 484 case CONVERT (A52_2F2R, A52_MONO): 485- *level *= LEVEL_3DB / (1 + slev); 486+ adjust = DIV (LEVEL_3DB, LEVEL (1) + slev); 487 break; 488 489 case CONVERT (A52_2F2R, A52_STEREO): 490 case CONVERT (A52_3F2R, A52_3F): 491- *level /= 1 + slev; 492+ adjust = DIV (1, LEVEL (1) + slev); 493 break; 494 495 case CONVERT (A52_3F2R, A52_MONO): 496- *level *= LEVEL_3DB / (1 + clev + slev); 497+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev); 498 break; 499 500 case CONVERT (A52_3F2R, A52_STEREO): 501- *level /= 1 + clev + slev; 502+ adjust = DIV (1, LEVEL (1) + clev + slev); 503 break; 504 505 case CONVERT (A52_MONO, A52_DOLBY): 506- *level *= LEVEL_PLUS3DB; 507+ adjust = LEVEL (LEVEL_PLUS3DB); 508 break; 509 510 case CONVERT (A52_3F, A52_DOLBY): 511 case CONVERT (A52_2F1R, A52_DOLBY): 512- *level *= 1 / (1 + LEVEL_3DB); 513+ adjust = LEVEL (1 / (1 + LEVEL_3DB)); 514 break; 515 516 case CONVERT (A52_3F1R, A52_DOLBY): 517 case CONVERT (A52_2F2R, A52_DOLBY): 518- *level *= 1 / (1 + 2 * LEVEL_3DB); 519+ adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB)); 520 break; 521 522 case CONVERT (A52_3F2R, A52_DOLBY): 523- *level *= 1 / (1 + 3 * LEVEL_3DB); 524+ adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB)); 525 break; 526+ 527+ default: 528+ return output; 529 } 530 531+ *level = MUL_L (*level, adjust); 532+ } 533+ 534 return output; 535 } 536 537-int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level, 538- sample_t clev, sample_t slev) 539+int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level, 540+ level_t clev, level_t slev) 541 { 542+ level_t level_3db; 543+ 544+ level_3db = MUL_C (level, LEVEL_3DB); 545+ 546 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) { 547 548 case CONVERT (A52_CHANNEL, A52_CHANNEL): 549@@ -169,120 +181,138 @@ 550 return 0; 551 552 case CONVERT (A52_CHANNEL, A52_MONO): 553- coeff[0] = coeff[1] = level * LEVEL_6DB; 554+ coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB); 555 return 3; 556 557 case CONVERT (A52_STEREO, A52_MONO): 558- coeff[0] = coeff[1] = level * LEVEL_3DB; 559+ coeff[0] = coeff[1] = level_3db; 560 return 3; 561 562 case CONVERT (A52_3F, A52_MONO): 563- coeff[0] = coeff[2] = level * LEVEL_3DB; 564- coeff[1] = level * clev * LEVEL_PLUS3DB; 565+ coeff[0] = coeff[2] = level_3db; 566+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 567 return 7; 568 569 case CONVERT (A52_2F1R, A52_MONO): 570- coeff[0] = coeff[1] = level * LEVEL_3DB; 571- coeff[2] = level * slev * LEVEL_3DB; 572+ coeff[0] = coeff[1] = level_3db; 573+ coeff[2] = MUL_L (level_3db, slev); 574 return 7; 575 576 case CONVERT (A52_2F2R, A52_MONO): 577- coeff[0] = coeff[1] = level * LEVEL_3DB; 578- coeff[2] = coeff[3] = level * slev * LEVEL_3DB; 579+ coeff[0] = coeff[1] = level_3db; 580+ coeff[2] = coeff[3] = MUL_L (level_3db, slev); 581 return 15; 582 583 case CONVERT (A52_3F1R, A52_MONO): 584- coeff[0] = coeff[2] = level * LEVEL_3DB; 585- coeff[1] = level * clev * LEVEL_PLUS3DB; 586- coeff[3] = level * slev * LEVEL_3DB; 587+ coeff[0] = coeff[2] = level_3db; 588+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 589+ coeff[3] = MUL_L (level_3db, slev); 590 return 15; 591 592 case CONVERT (A52_3F2R, A52_MONO): 593- coeff[0] = coeff[2] = level * LEVEL_3DB; 594- coeff[1] = level * clev * LEVEL_PLUS3DB; 595- coeff[3] = coeff[4] = level * slev * LEVEL_3DB; 596+ coeff[0] = coeff[2] = level_3db; 597+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 598+ coeff[3] = coeff[4] = MUL_L (level_3db, slev); 599 return 31; 600 601 case CONVERT (A52_MONO, A52_DOLBY): 602- coeff[0] = level * LEVEL_3DB; 603+ coeff[0] = level_3db; 604 return 0; 605 606 case CONVERT (A52_3F, A52_DOLBY): 607- clev = LEVEL_3DB; 608+ coeff[0] = coeff[2] = coeff[3] = coeff[4] = level; 609+ coeff[1] = level_3db; 610+ return 7; 611+ 612 case CONVERT (A52_3F, A52_STEREO): 613 case CONVERT (A52_3F1R, A52_2F1R): 614 case CONVERT (A52_3F2R, A52_2F2R): 615 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level; 616- coeff[1] = level * clev; 617+ coeff[1] = MUL_L (level, clev); 618 return 7; 619 620 case CONVERT (A52_2F1R, A52_DOLBY): 621- slev = 1; 622+ coeff[0] = coeff[1] = level; 623+ coeff[2] = level_3db; 624+ return 7; 625+ 626 case CONVERT (A52_2F1R, A52_STEREO): 627 coeff[0] = coeff[1] = level; 628- coeff[2] = level * slev * LEVEL_3DB; 629+ coeff[2] = MUL_L (level_3db, slev); 630 return 7; 631 632 case CONVERT (A52_3F1R, A52_DOLBY): 633- clev = LEVEL_3DB; 634- slev = 1; 635+ coeff[0] = coeff[2] = level; 636+ coeff[1] = coeff[3] = level_3db; 637+ return 15; 638+ 639 case CONVERT (A52_3F1R, A52_STEREO): 640 coeff[0] = coeff[2] = level; 641- coeff[1] = level * clev; 642- coeff[3] = level * slev * LEVEL_3DB; 643+ coeff[1] = MUL_L (level, clev); 644+ coeff[3] = MUL_L (level_3db, slev); 645 return 15; 646 647 case CONVERT (A52_2F2R, A52_DOLBY): 648- slev = LEVEL_3DB; 649+ coeff[0] = coeff[1] = level; 650+ coeff[2] = coeff[3] = level_3db; 651+ return 15; 652+ 653 case CONVERT (A52_2F2R, A52_STEREO): 654 coeff[0] = coeff[1] = level; 655- coeff[2] = coeff[3] = level * slev; 656+ coeff[2] = coeff[3] = MUL_L (level, slev); 657 return 15; 658 659 case CONVERT (A52_3F2R, A52_DOLBY): 660- clev = LEVEL_3DB; 661+ coeff[0] = coeff[2] = level; 662+ coeff[1] = coeff[3] = coeff[4] = level_3db; 663+ return 31; 664+ 665 case CONVERT (A52_3F2R, A52_2F1R): 666- slev = LEVEL_3DB; 667+ coeff[0] = coeff[2] = level; 668+ coeff[1] = MUL_L (level, clev); 669+ coeff[3] = coeff[4] = level_3db; 670+ return 31; 671+ 672 case CONVERT (A52_3F2R, A52_STEREO): 673 coeff[0] = coeff[2] = level; 674- coeff[1] = level * clev; 675- coeff[3] = coeff[4] = level * slev; 676+ coeff[1] = MUL_L (level, clev); 677+ coeff[3] = coeff[4] = MUL_L (level, slev); 678 return 31; 679 680 case CONVERT (A52_3F1R, A52_3F): 681 coeff[0] = coeff[1] = coeff[2] = level; 682- coeff[3] = level * slev * LEVEL_3DB; 683+ coeff[3] = MUL_L (level_3db, slev); 684 return 13; 685 686 case CONVERT (A52_3F2R, A52_3F): 687 coeff[0] = coeff[1] = coeff[2] = level; 688- coeff[3] = coeff[4] = level * slev; 689+ coeff[3] = coeff[4] = MUL_L (level, slev); 690 return 29; 691 692 case CONVERT (A52_2F2R, A52_2F1R): 693 coeff[0] = coeff[1] = level; 694- coeff[2] = coeff[3] = level * LEVEL_3DB; 695+ coeff[2] = coeff[3] = level_3db; 696 return 12; 697 698 case CONVERT (A52_3F2R, A52_3F1R): 699 coeff[0] = coeff[1] = coeff[2] = level; 700- coeff[3] = coeff[4] = level * LEVEL_3DB; 701+ coeff[3] = coeff[4] = level_3db; 702 return 24; 703 704 case CONVERT (A52_2F1R, A52_2F2R): 705 coeff[0] = coeff[1] = level; 706- coeff[2] = level * LEVEL_3DB; 707+ coeff[2] = level_3db; 708 return 0; 709 710 case CONVERT (A52_3F1R, A52_2F2R): 711 coeff[0] = coeff[2] = level; 712- coeff[1] = level * clev; 713- coeff[3] = level * LEVEL_3DB; 714+ coeff[1] = MUL_L (level, clev); 715+ coeff[3] = level_3db; 716 return 7; 717 718 case CONVERT (A52_3F1R, A52_3F2R): 719 coeff[0] = coeff[1] = coeff[2] = level; 720- coeff[3] = level * LEVEL_3DB; 721+ coeff[3] = level_3db; 722 return 0; 723 724 case CONVERT (A52_CHANNEL, A52_CHANNEL1): 725@@ -304,7 +334,7 @@ 726 int i; 727 728 for (i = 0; i < 256; i++) 729- dest[i] += src[i] + bias; 730+ dest[i] += BIAS (src[i]); 731 } 732 733 static void mix3to1 (sample_t * samples, sample_t bias) 734@@ -312,7 +342,7 @@ 735 int i; 736 737 for (i = 0; i < 256; i++) 738- samples[i] += samples[i + 256] + samples[i + 512] + bias; 739+ samples[i] += BIAS (samples[i + 256] + samples[i + 512]); 740 } 741 742 static void mix4to1 (sample_t * samples, sample_t bias) 743@@ -320,8 +350,8 @@ 744 int i; 745 746 for (i = 0; i < 256; i++) 747- samples[i] += (samples[i + 256] + samples[i + 512] + 748- samples[i + 768] + bias); 749+ samples[i] += BIAS (samples[i + 256] + samples[i + 512] + 750+ samples[i + 768]); 751 } 752 753 static void mix5to1 (sample_t * samples, sample_t bias) 754@@ -329,8 +359,8 @@ 755 int i; 756 757 for (i = 0; i < 256; i++) 758- samples[i] += (samples[i + 256] + samples[i + 512] + 759- samples[i + 768] + samples[i + 1024] + bias); 760+ samples[i] += BIAS (samples[i + 256] + samples[i + 512] + 761+ samples[i + 768] + samples[i + 1024]); 762 } 763 764 static void mix3to2 (sample_t * samples, sample_t bias) 765@@ -339,7 +369,7 @@ 766 sample_t common; 767 768 for (i = 0; i < 256; i++) { 769- common = samples[i + 256] + bias; 770+ common = BIAS (samples[i + 256]); 771 samples[i] += common; 772 samples[i + 256] = samples[i + 512] + common; 773 } 774@@ -351,7 +381,7 @@ 775 sample_t common; 776 777 for (i = 0; i < 256; i++) { 778- common = right[i + 256] + bias; 779+ common = BIAS (right[i + 256]); 780 left[i] += common; 781 right[i] += common; 782 } 783@@ -364,8 +394,8 @@ 784 785 for (i = 0; i < 256; i++) { 786 surround = samples[i + 512]; 787- samples[i] += bias - surround; 788- samples[i + 256] += bias + surround; 789+ samples[i] += BIAS (-surround); 790+ samples[i + 256] += BIAS (surround); 791 } 792 } 793 794@@ -375,7 +405,7 @@ 795 sample_t common; 796 797 for (i = 0; i < 256; i++) { 798- common = samples[i + 256] + samples[i + 768] + bias; 799+ common = BIAS (samples[i + 256] + samples[i + 768]); 800 samples[i] += common; 801 samples[i + 256] = samples[i + 512] + common; 802 } 803@@ -387,7 +417,7 @@ 804 sample_t common, surround; 805 806 for (i = 0; i < 256; i++) { 807- common = samples[i + 256] + bias; 808+ common = BIAS (samples[i + 256]); 809 surround = samples[i + 768]; 810 samples[i] += common - surround; 811 samples[i + 256] = samples[i + 512] + common + surround; 812@@ -401,8 +431,8 @@ 813 814 for (i = 0; i < 256; i++) { 815 surround = samples[i + 512] + samples[i + 768]; 816- samples[i] += bias - surround; 817- samples[i + 256] += bias + surround; 818+ samples[i] += BIAS (-surround); 819+ samples[i + 256] += BIAS (surround); 820 } 821 } 822 823@@ -412,7 +442,7 @@ 824 sample_t common; 825 826 for (i = 0; i < 256; i++) { 827- common = samples[i + 256] + bias; 828+ common = BIAS (samples[i + 256]); 829 samples[i] += common + samples[i + 768]; 830 samples[i + 256] = common + samples[i + 512] + samples[i + 1024]; 831 } 832@@ -424,7 +454,7 @@ 833 sample_t common, surround; 834 835 for (i = 0; i < 256; i++) { 836- common = samples[i + 256] + bias; 837+ common = BIAS (samples[i + 256]); 838 surround = samples[i + 768] + samples[i + 1024]; 839 samples[i] += common - surround; 840 samples[i + 256] = samples[i + 512] + common + surround; 841@@ -436,7 +466,7 @@ 842 int i; 843 844 for (i = 0; i < 256; i++) 845- dest[i] = src[i] + src[i + 256] + bias; 846+ dest[i] = BIAS (src[i] + src[i + 256]); 847 } 848 849 static void zero (sample_t * samples) 850@@ -448,8 +478,11 @@ 851 } 852 853 void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias, 854- sample_t clev, sample_t slev) 855+ level_t clev, level_t slev) 856 { 857+ /* avoid compiler warning */ 858+ (void)clev; 859+ 860 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) { 861 862 case CONVERT (A52_CHANNEL, A52_CHANNEL2): 863@@ -583,7 +616,7 @@ 864 break; 865 866 case CONVERT (A52_3F1R, A52_3F2R): 867- memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t)); 868+ memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t)); 869 break; 870 } 871 } 872diff -ruN a52dec.orig/liba52/imdct.c a52dec/liba52/imdct.c 873--- a52dec.orig/liba52/imdct.c 2012-11-13 17:25:33.438758556 +0100 874+++ a52dec/liba52/imdct.c 2012-11-13 17:27:31.150370945 +0100 875@@ -1,6 +1,6 @@ 876 /* 877 * imdct.c 878- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 879+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 880 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 881 * 882 * The ifft algorithms in this file have been largely inspired by Dan 883@@ -24,12 +24,13 @@ 884 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 885 */ 886 887-#include "config.h" 888+#include "config-a52.h" 889 890 #include <math.h> 891 #include <stdio.h> 892 #ifdef LIBA52_DJBFFT 893 #include <fftc4.h> 894+#include <fftc8.h> 895 #endif 896 #ifndef M_PI 897 #define M_PI 3.1415926535897932384626433832795029 898@@ -57,25 +58,26 @@ 899 }; 900 901 /* Root values for IFFT */ 902-static sample_t roots16[3]; 903-static sample_t roots32[7]; 904-static sample_t roots64[15]; 905-static sample_t roots128[31]; 906+//static sample_t roots16[3]; 907+//static sample_t roots32[7]; 908+//static sample_t roots64[15]; 909+//static sample_t roots128[31]; 910 911 /* Twiddle factors for IMDCT */ 912-static complex_t pre1[128]; 913-static complex_t post1[64]; 914-static complex_t pre2[64]; 915-static complex_t post2[32]; 916+//static complex_t pre1[128]; 917+//static complex_t post1[64]; 918+//static complex_t pre2[64]; 919+//static complex_t post2[32]; 920 921-static sample_t a52_imdct_window[256]; 922+//static sample_t a52_imdct_window[256]; 923+#include "imdct_lookups.h" 924 925 static void (* ifft128) (complex_t * buf); 926 static void (* ifft64) (complex_t * buf); 927 928 static inline void ifft2 (complex_t * buf) 929 { 930- double r, i; 931+ sample_t r, i; 932 933 r = buf[0].real; 934 i = buf[0].imag; 935@@ -87,7 +89,7 @@ 936 937 static inline void ifft4 (complex_t * buf) 938 { 939- double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 940+ sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 941 942 tmp1 = buf[0].real + buf[1].real; 943 tmp2 = buf[3].real + buf[2].real; 944@@ -108,25 +110,37 @@ 945 buf[3].imag = tmp6 - tmp8; 946 } 947 948+/* basic radix-2 ifft butterfly */ 949+ 950+#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \ 951+ t0 = MUL (W1, d1) + MUL (W0, d0); \ 952+ t1 = MUL (W0, d1) - MUL (W1, d0); \ 953+} while (0) 954+ 955+/* radix-2 ifft butterfly with bias */ 956+ 957+#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \ 958+ t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \ 959+ t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \ 960+} while (0) 961+ 962 /* the basic split-radix ifft butterfly */ 963 964-#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \ 965- tmp5 = a2.real * wr + a2.imag * wi; \ 966- tmp6 = a2.imag * wr - a2.real * wi; \ 967- tmp7 = a3.real * wr - a3.imag * wi; \ 968- tmp8 = a3.imag * wr + a3.real * wi; \ 969- tmp1 = tmp5 + tmp7; \ 970- tmp2 = tmp6 + tmp8; \ 971- tmp3 = tmp6 - tmp8; \ 972- tmp4 = tmp7 - tmp5; \ 973- a2.real = a0.real - tmp1; \ 974- a2.imag = a0.imag - tmp2; \ 975- a3.real = a1.real - tmp3; \ 976- a3.imag = a1.imag - tmp4; \ 977- a0.real += tmp1; \ 978- a0.imag += tmp2; \ 979- a1.real += tmp3; \ 980- a1.imag += tmp4; \ 981+#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \ 982+ BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \ 983+ BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \ 984+ tmp1 = tmp5 + tmp7; \ 985+ tmp2 = tmp6 + tmp8; \ 986+ tmp3 = tmp6 - tmp8; \ 987+ tmp4 = tmp7 - tmp5; \ 988+ a2.real = a0.real - tmp1; \ 989+ a2.imag = a0.imag - tmp2; \ 990+ a3.real = a1.real - tmp3; \ 991+ a3.imag = a1.imag - tmp4; \ 992+ a0.real += tmp1; \ 993+ a0.imag += tmp2; \ 994+ a1.real += tmp3; \ 995+ a1.imag += tmp4; \ 996 } while (0) 997 998 /* split-radix ifft butterfly, specialized for wr=1 wi=0 */ 999@@ -149,10 +163,10 @@ 1000 /* split-radix ifft butterfly, specialized for wr=wi */ 1001 1002 #define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \ 1003- tmp5 = (a2.real + a2.imag) * w; \ 1004- tmp6 = (a2.imag - a2.real) * w; \ 1005- tmp7 = (a3.real - a3.imag) * w; \ 1006- tmp8 = (a3.imag + a3.real) * w; \ 1007+ tmp5 = MUL (a2.real + a2.imag, w); \ 1008+ tmp6 = MUL (a2.imag - a2.real, w); \ 1009+ tmp7 = MUL (a3.real - a3.imag, w); \ 1010+ tmp8 = MUL (a3.imag + a3.real, w); \ 1011 tmp1 = tmp5 + tmp7; \ 1012 tmp2 = tmp6 + tmp8; \ 1013 tmp3 = tmp6 - tmp8; \ 1014@@ -169,7 +183,7 @@ 1015 1016 static inline void ifft8 (complex_t * buf) 1017 { 1018- double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 1019+ sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 1020 1021 ifft4 (buf); 1022 ifft2 (buf + 4); 1023@@ -183,7 +197,7 @@ 1024 complex_t * buf1; 1025 complex_t * buf2; 1026 complex_t * buf3; 1027- double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 1028+ sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; 1029 int i; 1030 1031 buf++; 1032@@ -196,7 +210,8 @@ 1033 i = n - 1; 1034 1035 do { 1036- BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0], weight[n], weight[2*i]); 1037+ BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0], 1038+ weight[0], weight[2*i-n]); 1039 buf++; 1040 buf1++; 1041 buf2++; 1042@@ -210,7 +225,7 @@ 1043 ifft8 (buf); 1044 ifft4 (buf + 8); 1045 ifft4 (buf + 12); 1046- ifft_pass (buf, roots16 - 4, 4); 1047+ ifft_pass (buf, roots16, 4); 1048 } 1049 1050 static void ifft32 (complex_t * buf) 1051@@ -218,7 +233,7 @@ 1052 ifft16 (buf); 1053 ifft8 (buf + 16); 1054 ifft8 (buf + 24); 1055- ifft_pass (buf, roots32 - 8, 8); 1056+ ifft_pass (buf, roots32, 8); 1057 } 1058 1059 static void ifft64_c (complex_t * buf) 1060@@ -226,7 +241,7 @@ 1061 ifft32 (buf); 1062 ifft16 (buf + 32); 1063 ifft16 (buf + 48); 1064- ifft_pass (buf, roots64 - 16, 16); 1065+ ifft_pass (buf, roots64, 16); 1066 } 1067 1068 static void ifft128_c (complex_t * buf) 1069@@ -234,11 +249,11 @@ 1070 ifft32 (buf); 1071 ifft16 (buf + 32); 1072 ifft16 (buf + 48); 1073- ifft_pass (buf, roots64 - 16, 16); 1074+ ifft_pass (buf, roots64, 16); 1075 1076 ifft32 (buf + 64); 1077 ifft32 (buf + 96); 1078- ifft_pass (buf, roots128 - 32, 32); 1079+ ifft_pass (buf, roots128, 32); 1080 } 1081 1082 void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias) 1083@@ -252,9 +267,7 @@ 1084 k = fftorder[i]; 1085 t_r = pre1[i].real; 1086 t_i = pre1[i].imag; 1087- 1088- buf[i].real = t_i * data[255-k] + t_r * data[k]; 1089- buf[i].imag = t_r * data[255-k] - t_i * data[k]; 1090+ BUTTERFLY_0 (buf[i].real, buf[i].imag, t_r, t_i, data[k], data[255-k]); 1091 } 1092 1093 ifft128 (buf); 1094@@ -265,27 +278,22 @@ 1095 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */ 1096 t_r = post1[i].real; 1097 t_i = post1[i].imag; 1098- 1099- a_r = t_r * buf[i].real + t_i * buf[i].imag; 1100- a_i = t_i * buf[i].real - t_r * buf[i].imag; 1101- b_r = t_i * buf[127-i].real + t_r * buf[127-i].imag; 1102- b_i = t_r * buf[127-i].real - t_i * buf[127-i].imag; 1103+ BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].imag, buf[i].real); 1104+ BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].imag, buf[127-i].real); 1105 1106 w_1 = window[2*i]; 1107 w_2 = window[255-2*i]; 1108- data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias; 1109- data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias; 1110+ BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]); 1111 delay[2*i] = a_i; 1112 1113 w_1 = window[2*i+1]; 1114 w_2 = window[254-2*i]; 1115- data[2*i+1] = delay[2*i+1] * w_2 + b_r * w_1 + bias; 1116- data[254-2*i] = delay[2*i+1] * w_1 - b_r * w_2 + bias; 1117+ BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]); 1118 delay[2*i+1] = b_i; 1119 } 1120 } 1121 1122-void a52_imdct_256(sample_t * data, sample_t * delay, sample_t bias) 1123+void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias) 1124 { 1125 int i, k; 1126 sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2; 1127@@ -297,12 +305,8 @@ 1128 k = fftorder[i]; 1129 t_r = pre2[i].real; 1130 t_i = pre2[i].imag; 1131- 1132- buf1[i].real = t_i * data[254-k] + t_r * data[k]; 1133- buf1[i].imag = t_r * data[254-k] - t_i * data[k]; 1134- 1135- buf2[i].real = t_i * data[255-k] + t_r * data[k+1]; 1136- buf2[i].imag = t_r * data[255-k] - t_i * data[k+1]; 1137+ BUTTERFLY_0 (buf1[i].real, buf1[i].imag, t_r, t_i, data[k], data[254-k]); 1138+ BUTTERFLY_0 (buf2[i].real, buf2[i].imag, t_r, t_i, data[k+1], data[255-k]); 1139 } 1140 1141 ifft64 (buf1); 1142@@ -314,43 +318,34 @@ 1143 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */ 1144 t_r = post2[i].real; 1145 t_i = post2[i].imag; 1146- 1147- a_r = t_r * buf1[i].real + t_i * buf1[i].imag; 1148- a_i = t_i * buf1[i].real - t_r * buf1[i].imag; 1149- b_r = t_i * buf1[63-i].real + t_r * buf1[63-i].imag; 1150- b_i = t_r * buf1[63-i].real - t_i * buf1[63-i].imag; 1151- 1152- c_r = t_r * buf2[i].real + t_i * buf2[i].imag; 1153- c_i = t_i * buf2[i].real - t_r * buf2[i].imag; 1154- d_r = t_i * buf2[63-i].real + t_r * buf2[63-i].imag; 1155- d_i = t_r * buf2[63-i].real - t_i * buf2[63-i].imag; 1156+ BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].imag, buf1[i].real); 1157+ BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].imag, buf1[63-i].real); 1158+ BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].imag, buf2[i].real); 1159+ BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].imag, buf2[63-i].real); 1160 1161 w_1 = window[2*i]; 1162 w_2 = window[255-2*i]; 1163- data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias; 1164- data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias; 1165+ BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]); 1166 delay[2*i] = c_i; 1167 1168 w_1 = window[128+2*i]; 1169 w_2 = window[127-2*i]; 1170- data[128+2*i] = delay[127-2*i] * w_2 + a_i * w_1 + bias; 1171- data[127-2*i] = delay[127-2*i] * w_1 - a_i * w_2 + bias; 1172+ BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]); 1173 delay[127-2*i] = c_r; 1174 1175 w_1 = window[2*i+1]; 1176 w_2 = window[254-2*i]; 1177- data[2*i+1] = delay[2*i+1] * w_2 - b_i * w_1 + bias; 1178- data[254-2*i] = delay[2*i+1] * w_1 + b_i * w_2 + bias; 1179+ BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]); 1180 delay[2*i+1] = d_r; 1181 1182 w_1 = window[129+2*i]; 1183 w_2 = window[126-2*i]; 1184- data[129+2*i] = delay[126-2*i] * w_2 + b_r * w_1 + bias; 1185- data[126-2*i] = delay[126-2*i] * w_1 - b_r * w_2 + bias; 1186+ BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]); 1187 delay[126-2*i] = d_i; 1188 } 1189 } 1190 1191+/* 1192 static double besselI0 (double x) 1193 { 1194 double bessel = 1; 1195@@ -361,66 +356,118 @@ 1196 while (--i); 1197 return bessel; 1198 } 1199+*/ 1200 1201 void a52_imdct_init (uint32_t mm_accel) 1202 { 1203- int i, k; 1204+ (void)mm_accel; 1205+/* int i, k; 1206 double sum; 1207+ double local_imdct_window[256];*/ 1208 1209 /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */ 1210- sum = 0; 1211+ /* sum = 0; 1212 for (i = 0; i < 256; i++) { 1213 sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256)); 1214- a52_imdct_window[i] = sum; 1215+ local_imdct_window[i] = sum; 1216 } 1217 sum++; 1218- for (i = 0; i < 256; i++) 1219- a52_imdct_window[i] = sqrt (a52_imdct_window[i] / sum); 1220+ */ 1221+ /* for (i = 0; i < 256; i++) 1222+ a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum)); 1223+ 1224+ printf("static sample_t a52_imdct_window[256]={"); 1225+ for (i=0;i<256;i++) { 1226+ if ((i % 16)==0) { printf("\n"); } 1227+ printf("%d,",a52_imdct_window[i]); 1228+ } 1229+ printf("\n}\n"); 1230+ */ 1231+ 1232+ /* for (i = 0; i < 3; i++) 1233+ roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1))); 1234 1235- for (i = 0; i < 3; i++) 1236- roots16[i] = cos ((M_PI / 8) * (i + 1)); 1237+ printf("static sample_t roots16[3]={%d,%d,%d};\n\n",roots16[0],roots16[1],roots16[2]); 1238 1239 for (i = 0; i < 7; i++) 1240- roots32[i] = cos ((M_PI / 16) * (i + 1)); 1241+ roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1))); 1242+ 1243+ printf("static sample_t roots32[7]={"); 1244+ for (i=0;i<7;i++) { printf("%d%s",roots32[i],(i < 6 ? "," : "")); } 1245+ printf("};\n"); 1246 1247 for (i = 0; i < 15; i++) 1248- roots64[i] = cos ((M_PI / 32) * (i + 1)); 1249+ roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1))); 1250+ 1251+ printf("static sample_t roots64[15]={"); 1252+ for (i=0;i<15;i++) { printf("%d%s",roots64[i],(i < 14 ? "," : "")); } 1253+ printf("};\n"); 1254 1255 for (i = 0; i < 31; i++) 1256- roots128[i] = cos ((M_PI / 64) * (i + 1)); 1257+ roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1))); 1258 1259+ printf("static sample_t roots128[31]={"); 1260+ for (i=0;i<31;i++) { printf("%d%s",roots128[i],(i < 30 ? "," : "")); } 1261+ printf("};\n"); 1262+ */ 1263+ /* 1264 for (i = 0; i < 64; i++) { 1265 k = fftorder[i] / 2 + 64; 1266- pre1[i].real = cos ((M_PI / 256) * (k - 0.25)); 1267- pre1[i].imag = sin ((M_PI / 256) * (k - 0.25)); 1268+ pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25))); 1269+ pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25))); 1270 } 1271 1272 for (i = 64; i < 128; i++) { 1273 k = fftorder[i] / 2 + 64; 1274- pre1[i].real = -cos ((M_PI / 256) * (k - 0.25)); 1275- pre1[i].imag = -sin ((M_PI / 256) * (k - 0.25)); 1276+ pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25))); 1277+ pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25))); 1278 } 1279 1280+ printf("static complex_t pre1[128]={"); 1281+ for (i=0;i<128;i++) { printf("{%d,%d}%s",pre1[i].real,pre1[i].imag,(i < 127 ? "," : "")); } 1282+ printf("};\n"); 1283+ */ 1284+ /* 1285 for (i = 0; i < 64; i++) { 1286- post1[i].real = cos ((M_PI / 256) * (i + 0.5)); 1287- post1[i].imag = sin ((M_PI / 256) * (i + 0.5)); 1288+ post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5))); 1289+ post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5))); 1290 } 1291 1292+ printf("static complex_t post1[64]={"); 1293+ for (i=0;i<64;i++) { printf("{%d,%d}%s",post1[i].real,post1[i].imag,(i < 63 ? "," : "")); } 1294+ printf("};\n"); 1295+ */ 1296+ 1297+ /* 1298 for (i = 0; i < 64; i++) { 1299 k = fftorder[i] / 4; 1300- pre2[i].real = cos ((M_PI / 128) * (k - 0.25)); 1301- pre2[i].imag = sin ((M_PI / 128) * (k - 0.25)); 1302+ pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25))); 1303+ pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25))); 1304 } 1305 1306+ printf("static complex_t pre2[64]={"); 1307+ for (i=0;i<64;i++) { printf("{%d,%d}%s",pre2[i].real,pre2[i].imag,(i < 63 ? "," : "")); } 1308+ printf("};\n"); 1309+ 1310 for (i = 0; i < 32; i++) { 1311- post2[i].real = cos ((M_PI / 128) * (i + 0.5)); 1312- post2[i].imag = sin ((M_PI / 128) * (i + 0.5)); 1313+ post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5))); 1314+ post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5))); 1315 } 1316 1317+ printf("static complex_t post2[32]={"); 1318+ for (i=0;i<32;i++) { printf("{%d,%d}%s",post2[i].real,post2[i].imag,(i < 31 ? "," : "")); } 1319+ printf("};\n"); 1320+ */ 1321+ 1322 #ifdef LIBA52_DJBFFT 1323 if (mm_accel & MM_ACCEL_DJBFFT) { 1324+#ifndef LIBA52_DOUBLE 1325 ifft128 = (void (*) (complex_t *)) fftc4_un128; 1326 ifft64 = (void (*) (complex_t *)) fftc4_un64; 1327+#else 1328+ ifft128 = (void (*) (complex_t *)) fftc8_un128; 1329+ ifft64 = (void (*) (complex_t *)) fftc8_un64; 1330+#endif 1331 } else 1332 #endif 1333 { 1334diff -ruN a52dec.orig/liba52/imdct_lookups.h a52dec/liba52/imdct_lookups.h 1335--- a52dec.orig/liba52/imdct_lookups.h 1970-01-01 01:00:00.000000000 +0100 1336+++ a52dec/liba52/imdct_lookups.h 2012-11-13 17:27:31.150370945 +0100 1337@@ -0,0 +1,15 @@ 1338+static sample_t a52_imdct_window[256]IDATA_ATTR={ 1339+ 146020,261886,393529,545197,719447,918478,1144416,1399394,1685589,2005234,2360623,2754115,3188134,3665170,4187773,4758556, 5380193,6055411,6786995,7577779,8430645,9348521,10334375,11391212,12522071,13730020,15018150,16389576,17847424,19394833,21034947,22770912, 24605865,26542938,28585242,30735872,32997891,35374332,37868188,40482408,43219889,46083473,49075937,52199993,55458273,58853331,62387636,66063559, 69883377,73849259,77963266,82227341,86643307,91212859,95937560,100818835,105857968,111056092,116414194,121933098,127613474,133455822,139460477,145627601, 151957182,158449029,165102772,171917855,178893540,186028900,193322822,200774000,208380940,216141958,224055176,232118527,240329753,248686407,257185854,265825270, 274601649,283511802,292552357,301719768,311010314,320420105,329945084,339581031,349323572,359168178,369110174,379144743,389266934,399471665,409753732,420107815, 430528483,441010205,451547355,462134219,472765003,483433845,494134818,504861939,515609181,526370480,537139740,547910849,558677680,569434108,580174011,590891284, 601579849,612233658,622846709,633413050,643926788,654382103,664773249,675094567,685340494,695505569,705584441,715571877,725462772,735252152,744935184,754507184, 763963620,773300119,782512477,791596659,800548807,809365245,818042484,826577226,834966364,843206992,851296404,859232096,867011771,874633340,882094922,889394844, 896531647,903504079,910311101,916951881,923425798,929732436,935871584,941843233,947647575,953284997,958756080,964061593,969202490,974179906,978995149,983649698, 988145195,992483442,996666390,1000696136,1004574919,1008305104,1011889185,1015329772,1018629583,1021791439,1024818257,1027713038,1030478862,1033118881,1035636308,1038034411, 1040316504,1042485942,1044546109,1046500412,1048352275,1050105129,1051762405,1053327531,1054803917,1056194958,1057504020,1058734435,1059889501,1060972468,1061986539,1062934861, 1063820523,1064646551,1065415903,1066131467,1066796055,1067412403,1067983168,1068510924,1068998160,1069447282,1069860607,1070240366,1070588702,1070907668,1071199230,1071465266, 1071707567,1071927836,1072127692,1072308670,1072472221,1072619716,1072752449,1072871635,1072978415,1073073858,1073158963,1073234663,1073301826,1073361257,1073413702,1073459852, 1073500344,1073535763,1073566646,1073593486,1073616731,1073636791,1073654036,1073668804,1073681398,1073692090,1073701126,1073708726,1073715084,1073720373,1073724748,1073728344, 1073731279,1073733657,1073735568,1073737090,1073738291,1073739229,1073739951,1073740500,1073740912,1073741214,1073741431,1073741582,1073741685,1073741751,1073741792,1073741814 1340+}; 1341+ 1342+static sample_t roots16[3]IDATA_ATTR={992008094,759250124,410903206}; 1343+static sample_t roots32[7]IDATA_ATTR={1053110175,992008094,892783698,759250124,596538995,410903206,209476638}; 1344+static sample_t roots64[15]IDATA_ATTR={1068571463,1053110175,1027506861,992008094,946955747,892783698,830013654,759250124,681174602,596538995,506158392,410903206,311690798,209476638,105245103}; 1345+static sample_t roots128[31]IDATA_ATTR={1072448454,1068571463,1062120190,1053110175,1041563127,1027506861,1010975241,992008094,970651112,946955747,920979082,892783698,862437519,830013654,795590212,759250124,721080937,681174602,639627257,596538995,552013618,506158392,459083785,410903206,361732725,311690798,260897981,209476638,157550647,105245103,52686014}; 1346+ 1347+static complex_t pre1[128]IDATA_ATTR={{761575898,756917205},{3294193,1073736770},{413944710,990742792},{-407857834,993264059},{599275209,890949340},{-206244755,1053747885},{-593797166,894609652},{212706548,1052462554},{683717842,827919933},{-101966276,1068889322},{314841678,1026545772},{-503250790,948504162},{-678624950,832099562},{108522938,1068243547},{509061229,945398418},{-308536985,1028458279},{723518379,793374223},{-49395540,1072605046},{364832651,1009860703},{-456103709,972054993},{554836544,919281193},{-257701283,1042358649},{-636978326,864395809},{160808444,1061631832},{-718636707,797798713},{55975991,1072281769},{462059540,969238095},{-358629394,1012080264},{642270168,860471112},{-154291366,1062598550},{-549185496,922668301},{264092224,1040757801},{742770847,775379244},{-23057618,1073494224},{389505993,1000603111},{-432110916,982955574},{577229727,905387953},{-232042906,1048369016},{-615573145,879767700},{186813761,1057365652},{663193747,844449855},{-128167423,1066065014},{289554159,1033963197},{-526376678,935868098},{-698841306,815194659},{82274244,1070585098},{485706670,957606670},{-333683689,1020576650},{-737999227,779922204},{29644020,1073332537},{438134083,980285687},{-383359075,1002974238},{620959710,875974053},{-180322371,1058492015},{-571663505,908912724},{238471209,1046925492},{703830091,810891303},{-75703709,1071069770},{339939548,1018509994},{-479821763,960568883},{-657999815,848503239},{134706262,1065258526},{532109148,932620694},{-283204430,1035720404},{-752230014,-766205918},{9882456,-1073696345},{-401755603,-995747929},{420016001,-988184225},{-588296766,-898236282},{219160333,-1051137599},{604730690,-887255485},{-199775197,-1054993542},{-673506508,-836247862},{115075515,-1067557553},{-302220675,-1030332066},{514852501,-942257080},{688784992,-823709134},{-95405775,-1069494853},{-497421404,-951574195},{321134518,-1024594615},{-713727978,-802193167},{62554335,-1071918121},{-352412636,-1014261720},{467997975,-966384705},{-543513771,-926020671},{270473222,-1039117770},{647537829,-856514018},{-147768480,-1063525261},{728372812,-788919863},{-42813229,-1072887940},{-450130706,-974835294},{371022172,-1007603122},{-631662502,-868287963},{167319467,-1060625145},{560466703,-915859475},{-251300639,-1043920252},{747514502,-770807091},{-16470347,-1073615495},{-426071479,-985588453},{395638246,-998194311},{-610163404,-883528225},{193298118,-1056199480},{582774217,-901829094},{-225605866,-1049773069},{-693826210,-819467323},{88841682,-1070060119},{-327415267,-1022604883},{491573291,-954608403},{668362709,-840364678},{-121623758,-1066831367},{-520624390,-939080267},{295892987,-1032167062},{-733199822,-784435800},{36229307,-1073130440},{-377197724,-1005307605},{444140755,-977578893},{-566075760,-912403275},{244890534,-1045442552},{626322896,-872147426},{-173824191,-1059578527},{708792377,-806557418},{-69130323,-1071514117},{-473918791,-963494932},{346182609,-1016404991},{-652781111,-852524677},{141240030,-1064411930},{537821584,-929338177},{-276844037,-1037438616}}; 1348+ 1349+static complex_t post1[64]IDATA_ATTR={{1073721611,6588355},{1073559912,19764075},{1073236539,32936819},{1072751541,46104602},{1072104991,59265442},{1071296985,72417357},{1070327646,85558366},{1069197119,98686490},{1067905576,111799753},{1066453209,124896178},{1064840239,137973795},{1063066908,151030634},{1061133483,164064728},{1059040255,177074114},{1056787539,190056834},{1054375675,203010932},{1051805026,215934457},{1049075979,228825463},{1046188946,241682009},{1043144359,254502159},{1039942680,267283981},{1036584388,280025551},{1033069991,292724951},{1029400017,305380267},{1025575020,317989594},{1021595574,330551034},{1017462280,343062693},{1013175760,355522688},{1008736660,367929143},{1004145647,380280189},{999403414,392573967},{994510674,404808624},{989468165,416982318},{984276645,429093217},{978936897,441139495},{973449725,453119340},{967815955,465030947},{962036435,476872521},{956112036,488642280},{950043650,500338452},{943832191,511959274},{937478594,523502998},{930983817,534967883},{924348836,546352205},{917574653,557654248},{910662286,568872310},{903612776,580004702},{896427186,591049747},{889106597,602005783},{881652112,612871159},{874064853,623644238},{866345963,634323399},{858496605,644907034},{850517961,655393547},{842411231,665781361},{834177638,676068911},{825818420,686254647},{817334837,696337035},{808728167,706314558},{799999705,716185713},{791150766,725949012},{782182683,735602987},{773096806,745146182},{763894503,754577161}}; 1350+ 1351+static complex_t pre2[64]IDATA_ATTR={{1073721611,-6588355},{763894503,754577161},{994510674,404808624},{416982318,989468165},{1054375675,203010932},{602005783,889106597},{215934457,1051805026},{896427186,591049747},{1069197119,98686490},{686254647,825818420},{950043650,500338452},{317989594,1025575020},{111799753,1067905576},{834177638,676068911},{1029400017,305380267},{511959274,943832191},{1072751541,46104602},{725949012,791150766},{973449725,453119340},{367929143,1008736660},{1043144359,254502159},{557654248,917574653},{164064728,1061133483},{866345963,634323399},{59265442,1072104991},{799999705,716185713},{1013175760,355522688},{465030947,967815955},{1063066908,151030634},{644907034,858496605},{267283981,1039942680},{924348836,546352205},{1073559912,19764075},{745146182,773096806},{984276645,429093217},{392573967,999403414},{1049075979,228825463},{580004702,903612776},{190056834,1056787539},{881652112,612871159},{1066453209,124896178},{665781361,842411231},{937478594,523502998},{292724951,1033069991},{85558366,1070327646},{817334837,696337035},{1021595574,330551034},{488642280,956112036},{32936819,1073236539},{782182683,735602987},{1004145647,380280189},{441139495,978936897},{1059040255,177074114},{623644238,874064853},{241682009,1046188946},{910662286,568872310},{1071296985,72417357},{706314558,808728167},{962036435,476872521},{343062693,1017462280},{137973795,1064840239},{850517961,655393547},{1036584388,280025551},{534967883,930983817}}; 1352+static complex_t post2[32]IDATA_ATTR={{1073660973,13176463},{1073014239,39521454},{1071721163,65842639},{1069782521,92124162},{1067199482,118350193},{1063973603,144504935},{1060106825,170572632},{1055601479,196537583},{1050460278,222384146},{1044686318,248096754},{1038283079,273659918},{1031254417,299058239},{1023604566,324276418},{1015338134,349299266},{1006460100,374111709},{996975812,398698801},{986890983,423045731},{976211688,447137835},{964944359,470960600},{953095785,494499675},{940673100,517740882},{927683790,540670222},{914135677,563273882},{900036924,585538247},{885396022,607449906},{870221790,628995659},{854523369,650162530},{838310215,670937766},{821592095,691308855},{804379078,711263525},{786681534,730789756},{768510121,749875787}}; 1353diff -ruN a52dec.orig/liba52/parse.c a52dec/liba52/parse.c 1354--- a52dec.orig/liba52/parse.c 2012-11-13 17:25:33.438758556 +0100 1355+++ a52dec/liba52/parse.c 2012-11-13 17:27:31.150370945 +0100 1356@@ -1,6 +1,6 @@ 1357 /* 1358 * parse.c 1359- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 1360+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 1361 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 1362 * 1363 * This file is part of a52dec, a free ATSC A-52 stream decoder. 1364@@ -21,9 +21,8 @@ 1365 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1366 */ 1367 1368-#include "config.h" 1369+#include "config-a52.h" 1370 1371-#include <stdlib.h> 1372 #include <string.h> 1373 #include <inttypes.h> 1374 1375@@ -32,7 +31,7 @@ 1376 #include "bitstream.h" 1377 #include "tables.h" 1378 1379-#ifdef HAVE_MEMALIGN 1380+#if defined(HAVE_MEMALIGN) && !defined(__cplusplus) 1381 /* some systems have memalign() but no declaration for it */ 1382 void * memalign (size_t align, size_t size); 1383 #else 1384@@ -41,13 +40,16 @@ 1385 #endif 1386 1387 typedef struct { 1388- sample_t q1[2]; 1389- sample_t q2[2]; 1390- sample_t q4; 1391+ quantizer_t q1[2]; 1392+ quantizer_t q2[2]; 1393+ quantizer_t q4; 1394 int q1_ptr; 1395 int q2_ptr; 1396 int q4_ptr; 1397-} quantizer_t; 1398+} quantizer_set_t; 1399+ 1400+static a52_state_t istate IBSS_ATTR; 1401+static sample_t isamples[256*12] IBSS_ATTR; 1402 1403 static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}; 1404 1405@@ -56,16 +58,25 @@ 1406 a52_state_t * state; 1407 int i; 1408 1409- state = malloc (sizeof (a52_state_t)); 1410+ #if defined(CPU_COLDFIRE) 1411+ coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_ROUND | EMAC_SATURATE); 1412+ #endif 1413+ /* 1414+ this needs to come back if we ever want two decoder instances 1415+ simultenously. NOTE, you also need to remove comments in a52_free. 1416+ state = (a52_state_t *) malloc (sizeof (a52_state_t)); 1417 if (state == NULL) 1418 return NULL; 1419 1420- state->samples = memalign (16, 256 * 12 * sizeof (sample_t)); 1421+ state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t)); 1422 if (state->samples == NULL) { 1423 free (state); 1424 return NULL; 1425 } 1426 1427+ */ 1428+ state = &istate; 1429+ state->samples = isamples; 1430 for (i = 0; i < 256 * 12; i++) 1431 state->samples[i] = 0; 1432 1433@@ -129,10 +140,12 @@ 1434 } 1435 1436 int a52_frame (a52_state_t * state, uint8_t * buf, int * flags, 1437- sample_t * level, sample_t bias) 1438+ level_t * level, sample_t bias) 1439 { 1440- static sample_t clev[4] = {LEVEL_3DB, LEVEL_45DB, LEVEL_6DB, LEVEL_45DB}; 1441- static sample_t slev[4] = {LEVEL_3DB, LEVEL_6DB, 0, LEVEL_6DB}; 1442+ static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB), 1443+ LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) }; 1444+ static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB), 1445+ 0, LEVEL (LEVEL_6DB) }; 1446 int chaninfo; 1447 int acmod; 1448 1449@@ -146,6 +159,8 @@ 1450 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */ 1451 acmod = A52_DOLBY; 1452 1453+ state->clev = state->slev = 0; 1454+ 1455 if ((acmod & 1) && (acmod != 1)) 1456 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */ 1457 1458@@ -162,7 +177,7 @@ 1459 state->output |= A52_LFE; 1460 *flags = state->output; 1461 /* the 2* compensates for differences in imdct */ 1462- state->dynrng = state->level = 2 * *level; 1463+ state->dynrng = state->level = MUL_C (*level, 2); 1464 state->bias = bias; 1465 state->dynrnge = 1; 1466 state->dynrngcall = NULL; 1467@@ -201,7 +216,7 @@ 1468 } 1469 1470 void a52_dynrng (a52_state_t * state, 1471- sample_t (* call) (sample_t, void *), void * data) 1472+ level_t (* call) (level_t, void *), void * data) 1473 { 1474 state->dynrnge = 0; 1475 if (call) { 1476@@ -311,20 +326,38 @@ 1477 1478 state->lfsr_state = (uint16_t) nstate; 1479 1480- return nstate; 1481+ return (3 * nstate) >> 2; 1482 } 1483 1484+#ifndef LIBA52_FIXED 1485+#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e] 1486+#else 1487+#define COEFF(c,_t,_l,s,e) do { \ 1488+ quantizer_t t = (_t); \ 1489+ level_t l = (_l); \ 1490+ int shift = e - 5; \ 1491+ sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \ 1492+ if (shift >= 0) \ 1493+ (c) = tmp >> shift; \ 1494+ else \ 1495+ (c) = tmp << -shift; \ 1496+} while (0) 1497+#endif 1498+ 1499 static void coeff_get (a52_state_t * state, sample_t * coeff, 1500- expbap_t * expbap, quantizer_t * quantizer, 1501- sample_t level, int dither, int end) 1502+ expbap_t * expbap, quantizer_set_t * quant, 1503+ level_t level, int dither, int end) 1504 { 1505 int i; 1506 uint8_t * exp; 1507 int8_t * bap; 1508+ 1509+#ifndef LIBA52_FIXED 1510 sample_t factor[25]; 1511 1512 for (i = 0; i <= 24; i++) 1513 factor[i] = scale_factor[i] * level; 1514+#endif 1515 1516 exp = expbap->exp; 1517 bap = expbap->bap; 1518@@ -336,7 +369,7 @@ 1519 switch (bapi) { 1520 case 0: 1521 if (dither) { 1522- coeff[i] = dither_gen (state) * LEVEL_3DB * factor[exp[i]]; 1523+ COEFF (coeff[i], dither_gen (state), level, factor, exp[i]); 1524 continue; 1525 } else { 1526 coeff[i] = 0; 1527@@ -344,76 +377,80 @@ 1528 } 1529 1530 case -1: 1531- if (quantizer->q1_ptr >= 0) { 1532- coeff[i] = quantizer->q1[quantizer->q1_ptr--] * factor[exp[i]]; 1533+ if (quant->q1_ptr >= 0) { 1534+ COEFF (coeff[i], quant->q1[quant->q1_ptr--], level, 1535+ factor, exp[i]); 1536 continue; 1537 } else { 1538 int code; 1539 1540 code = bitstream_get (state, 5); 1541 1542- quantizer->q1_ptr = 1; 1543- quantizer->q1[0] = q_1_2[code]; 1544- quantizer->q1[1] = q_1_1[code]; 1545- coeff[i] = q_1_0[code] * factor[exp[i]]; 1546+ quant->q1_ptr = 1; 1547+ quant->q1[0] = q_1_2[code]; 1548+ quant->q1[1] = q_1_1[code]; 1549+ COEFF (coeff[i], q_1_0[code], level, factor, exp[i]); 1550 continue; 1551 } 1552 1553 case -2: 1554- if (quantizer->q2_ptr >= 0) { 1555- coeff[i] = quantizer->q2[quantizer->q2_ptr--] * factor[exp[i]]; 1556+ if (quant->q2_ptr >= 0) { 1557+ COEFF (coeff[i], quant->q2[quant->q2_ptr--], level, 1558+ factor, exp[i]); 1559 continue; 1560 } else { 1561 int code; 1562 1563 code = bitstream_get (state, 7); 1564 1565- quantizer->q2_ptr = 1; 1566- quantizer->q2[0] = q_2_2[code]; 1567- quantizer->q2[1] = q_2_1[code]; 1568- coeff[i] = q_2_0[code] * factor[exp[i]]; 1569+ quant->q2_ptr = 1; 1570+ quant->q2[0] = q_2_2[code]; 1571+ quant->q2[1] = q_2_1[code]; 1572+ COEFF (coeff[i], q_2_0[code], level, factor, exp[i]); 1573 continue; 1574 } 1575 1576 case 3: 1577- coeff[i] = q_3[bitstream_get (state, 3)] * factor[exp[i]]; 1578+ COEFF (coeff[i], q_3[bitstream_get (state, 3)], level, 1579+ factor, exp[i]); 1580 continue; 1581 1582 case -3: 1583- if (quantizer->q4_ptr == 0) { 1584- quantizer->q4_ptr = -1; 1585- coeff[i] = quantizer->q4 * factor[exp[i]]; 1586+ if (quant->q4_ptr == 0) { 1587+ quant->q4_ptr = -1; 1588+ COEFF (coeff[i], quant->q4, level, factor, exp[i]); 1589 continue; 1590 } else { 1591 int code; 1592 1593 code = bitstream_get (state, 7); 1594 1595- quantizer->q4_ptr = 0; 1596- quantizer->q4 = q_4_1[code]; 1597- coeff[i] = q_4_0[code] * factor[exp[i]]; 1598+ quant->q4_ptr = 0; 1599+ quant->q4 = q_4_1[code]; 1600+ COEFF (coeff[i], q_4_0[code], level, factor, exp[i]); 1601 continue; 1602 } 1603 1604 case 4: 1605- coeff[i] = q_5[bitstream_get (state, 4)] * factor[exp[i]]; 1606+ COEFF (coeff[i], q_5[bitstream_get (state, 4)], level, 1607+ factor, exp[i]); 1608 continue; 1609 1610 default: 1611- coeff[i] = ((bitstream_get_2 (state, bapi) << (16 - bapi)) * 1612- factor[exp[i]]); 1613+ COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi), 1614+ level, factor, exp[i]); 1615 } 1616 } 1617 } 1618 1619 static void coeff_get_coupling (a52_state_t * state, int nfchans, 1620- sample_t * coeff, sample_t (* samples)[256], 1621- quantizer_t * quantizer, uint8_t dithflag[5]) 1622+ level_t * coeff, sample_t (* samples)[256], 1623+ quantizer_set_t * quant, uint8_t dithflag[5]) 1624 { 1625 int cplbndstrc, bnd, i, i_end, ch; 1626 uint8_t * exp; 1627 int8_t * bap; 1628- sample_t cplco[5]; 1629+ level_t cplco[5]; 1630 1631 exp = state->cpl_expbap.exp; 1632 bap = state->cpl_expbap.bap; 1633@@ -428,22 +465,26 @@ 1634 } 1635 cplbndstrc >>= 1; 1636 for (ch = 0; ch < nfchans; ch++) 1637- cplco[ch] = state->cplco[ch][bnd] * coeff[ch]; 1638+ cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]); 1639 bnd++; 1640 1641 while (i < i_end) { 1642- sample_t cplcoeff; 1643+ quantizer_t cplcoeff; 1644 int bapi; 1645 1646 bapi = bap[i]; 1647 switch (bapi) { 1648 case 0: 1649- cplcoeff = LEVEL_3DB * scale_factor[exp[i]]; 1650 for (ch = 0; ch < nfchans; ch++) 1651 if ((state->chincpl >> ch) & 1) { 1652 if (dithflag[ch]) 1653- samples[ch][i] = (cplcoeff * cplco[ch] * 1654- dither_gen (state)); 1655+#ifndef LIBA52_FIXED 1656+ samples[ch][i] = (scale_factor[exp[i]] * 1657+ cplco[ch] * dither_gen (state)); 1658+#else 1659+ COEFF (samples[ch][i], dither_gen (state), 1660+ cplco[ch], scale_factor, exp[i]); 1661+#endif 1662 else 1663 samples[ch][i] = 0; 1664 } 1665@@ -451,33 +492,33 @@ 1666 continue; 1667 1668 case -1: 1669- if (quantizer->q1_ptr >= 0) { 1670- cplcoeff = quantizer->q1[quantizer->q1_ptr--]; 1671+ if (quant->q1_ptr >= 0) { 1672+ cplcoeff = quant->q1[quant->q1_ptr--]; 1673 break; 1674 } else { 1675 int code; 1676 1677 code = bitstream_get (state, 5); 1678 1679- quantizer->q1_ptr = 1; 1680- quantizer->q1[0] = q_1_2[code]; 1681- quantizer->q1[1] = q_1_1[code]; 1682+ quant->q1_ptr = 1; 1683+ quant->q1[0] = q_1_2[code]; 1684+ quant->q1[1] = q_1_1[code]; 1685 cplcoeff = q_1_0[code]; 1686 break; 1687 } 1688 1689 case -2: 1690- if (quantizer->q2_ptr >= 0) { 1691- cplcoeff = quantizer->q2[quantizer->q2_ptr--]; 1692+ if (quant->q2_ptr >= 0) { 1693+ cplcoeff = quant->q2[quant->q2_ptr--]; 1694 break; 1695 } else { 1696 int code; 1697 1698 code = bitstream_get (state, 7); 1699 1700- quantizer->q2_ptr = 1; 1701- quantizer->q2[0] = q_2_2[code]; 1702- quantizer->q2[1] = q_2_1[code]; 1703+ quant->q2_ptr = 1; 1704+ quant->q2[0] = q_2_2[code]; 1705+ quant->q2[1] = q_2_1[code]; 1706 cplcoeff = q_2_0[code]; 1707 break; 1708 } 1709@@ -487,17 +528,17 @@ 1710 break; 1711 1712 case -3: 1713- if (quantizer->q4_ptr == 0) { 1714- quantizer->q4_ptr = -1; 1715- cplcoeff = quantizer->q4; 1716+ if (quant->q4_ptr == 0) { 1717+ quant->q4_ptr = -1; 1718+ cplcoeff = quant->q4; 1719 break; 1720 } else { 1721 int code; 1722 1723 code = bitstream_get (state, 7); 1724 1725- quantizer->q4_ptr = 0; 1726- quantizer->q4 = q_4_1[code]; 1727+ quant->q4_ptr = 0; 1728+ quant->q4 = q_4_1[code]; 1729 cplcoeff = q_4_0[code]; 1730 break; 1731 } 1732@@ -509,11 +550,17 @@ 1733 default: 1734 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi); 1735 } 1736- 1737+#ifndef LIBA52_FIXED 1738 cplcoeff *= scale_factor[exp[i]]; 1739+#endif 1740 for (ch = 0; ch < nfchans; ch++) 1741- if ((state->chincpl >> ch) & 1) 1742+ if ((state->chincpl >> ch) & 1) 1743+#ifndef LIBA52_FIXED 1744 samples[ch][i] = cplcoeff * cplco[ch]; 1745+#else 1746+ COEFF (samples[ch][i], cplcoeff, cplco[ch], 1747+ scale_factor, exp[i]); 1748+#endif 1749 i++; 1750 } 1751 } 1752@@ -526,9 +573,9 @@ 1753 int i, nfchans, chaninfo; 1754 uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl; 1755 uint8_t blksw[5], dithflag[5]; 1756- sample_t coeff[5]; 1757+ level_t coeff[5]; 1758 int chanbias; 1759- quantizer_t quantizer; 1760+ quantizer_set_t quant; 1761 sample_t * samples; 1762 1763 nfchans = nfchans_tbl[state->acmod]; 1764@@ -546,13 +593,17 @@ 1765 1766 dynrng = bitstream_get_2 (state, 8); 1767 if (state->dynrnge) { 1768- sample_t range; 1769+ level_t range; 1770 1771+#if !defined(LIBA52_FIXED) 1772 range = ((((dynrng & 0x1f) | 0x20) << 13) * 1773 scale_factor[3 - (dynrng >> 5)]); 1774+#else 1775+ range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5)); 1776+#endif 1777 if (state->dynrngcall) 1778 range = state->dynrngcall (range, state->dynrngdata); 1779- state->dynrng = state->level * range; 1780+ state->dynrng = MUL_L (state->level, range); 1781 } 1782 } 1783 } while (chaninfo--); 1784@@ -611,8 +662,13 @@ 1785 cplcomant <<= 14; 1786 else 1787 cplcomant = (cplcomant | 0x10) << 13; 1788+#ifndef LIBA52_FIXED 1789 state->cplco[i][j] = 1790 cplcomant * scale_factor[cplcoexp + mstrcplco]; 1791+#else 1792+ state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco); 1793+#endif 1794+ 1795 } 1796 } 1797 if ((state->acmod == 2) && state->phsflginu && cplcoe) 1798@@ -691,11 +747,11 @@ 1799 } 1800 1801 if (bitstream_get (state, 1)) { /* baie */ 1802- do_bit_alloc = -1; 1803+ do_bit_alloc = 127; 1804 state->bai = bitstream_get (state, 11); 1805 } 1806 if (bitstream_get (state, 1)) { /* snroffste */ 1807- do_bit_alloc = -1; 1808+ do_bit_alloc = 127; 1809 state->csnroffst = bitstream_get (state, 6); 1810 if (state->chincpl) /* cplinu */ 1811 state->cplba.bai = bitstream_get (state, 7); 1812@@ -711,7 +767,7 @@ 1813 } 1814 1815 if (bitstream_get (state, 1)) { /* deltbaie */ 1816- do_bit_alloc = -1; 1817+ do_bit_alloc = 127; 1818 if (state->chincpl) /* cplinu */ 1819 state->cplba.deltbae = bitstream_get (state, 2); 1820 for (i = 0; i < nfchans; i++) 1821@@ -765,20 +821,20 @@ 1822 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output, 1823 state->dynrng, state->clev, state->slev); 1824 1825- quantizer.q1_ptr = quantizer.q2_ptr = quantizer.q4_ptr = -1; 1826+ quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1; 1827 done_cpl = 0; 1828 1829 for (i = 0; i < nfchans; i++) { 1830 int j; 1831 1832- coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quantizer, 1833+ coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant, 1834 coeff[i], dithflag[i], state->endmant[i]); 1835 1836 if ((state->chincpl >> i) & 1) { 1837 if (!done_cpl) { 1838 done_cpl = 1; 1839 coeff_get_coupling (state, nfchans, coeff, 1840- (sample_t (*)[256])samples, &quantizer, 1841+ (sample_t (*)[256])samples, &quant, 1842 dithflag); 1843 } 1844 j = state->cplendmant; 1845@@ -821,14 +877,14 @@ 1846 1847 if (state->lfeon) { 1848 if (state->output & A52_LFE) { 1849- coeff_get (state, samples - 256, &state->lfe_expbap, &quantizer, 1850+ coeff_get (state, samples - 256, &state->lfe_expbap, &quant, 1851 state->dynrng, 0, 7); 1852 for (i = 7; i < 256; i++) 1853 (samples-256)[i] = 0; 1854 a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias); 1855 } else { 1856 /* just skip the LFE coefficients */ 1857- coeff_get (state, samples + 1280, &state->lfe_expbap, &quantizer, 1858+ coeff_get (state, samples + 1280, &state->lfe_expbap, &quant, 1859 0, 0, 7); 1860 } 1861 } 1862@@ -896,6 +952,9 @@ 1863 1864 void a52_free (a52_state_t * state) 1865 { 1866+ (void)state; 1867+ /* 1868 free (state->samples); 1869 free (state); 1870+ */ 1871 } 1872diff -ruN a52dec.orig/liba52/tables.h a52dec/liba52/tables.h 1873--- a52dec.orig/liba52/tables.h 2012-11-13 17:25:33.438758556 +0100 1874+++ a52dec/liba52/tables.h 2012-11-13 17:27:31.150370945 +0100 1875@@ -1,6 +1,6 @@ 1876 /* 1877 * tables.h 1878- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 1879+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 1880 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 1881 * 1882 * This file is part of a52dec, a free ATSC A-52 stream decoder. 1883@@ -46,42 +46,44 @@ 1884 25,25,25 1885 }; 1886 1887-#define Q0 ((-2 << 15) / 3.0) 1888-#define Q1 (0) 1889-#define Q2 ((2 << 15) / 3.0) 1890- 1891-static const sample_t q_1_0[32] = { 1892- Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0, 1893- Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1, 1894- Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2, 1895- 0,0,0,0,0 1896-}; 1897- 1898-static const sample_t q_1_1[32] = { 1899- Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2, 1900- Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2, 1901- Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2, 1902- 0,0,0,0,0 1903-}; 1904- 1905-static const sample_t q_1_2[32] = { 1906- Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2, 1907- Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2, 1908- Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2, 1909- 0,0,0,0,0 1910+#define Q(x) ROUND (32768.0 * x) 1911+ 1912+#define Q0 Q (-2/3) 1913+#define Q1 Q (0) 1914+#define Q2 Q (2/3) 1915+ 1916+static const quantizer_t q_1_0[32] = { 1917+ Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, 1918+ Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, 1919+ Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, 1920+ 0, 0, 0, 0, 0 1921+}; 1922+ 1923+static const quantizer_t q_1_1[32] = { 1924+ Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2, 1925+ Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2, 1926+ Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2, 1927+ 0, 0, 0, 0, 0 1928+}; 1929+ 1930+static const quantizer_t q_1_2[32] = { 1931+ Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2, 1932+ Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2, 1933+ Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2, 1934+ 0, 0, 0, 0, 0 1935 }; 1936 1937 #undef Q0 1938 #undef Q1 1939 #undef Q2 1940 1941-#define Q0 ((-4 << 15) / 5.0) 1942-#define Q1 ((-2 << 15) / 5.0) 1943-#define Q2 (0) 1944-#define Q3 ((2 << 15) / 5.0) 1945-#define Q4 ((4 << 15) / 5.0) 1946+#define Q0 Q (-4/5) 1947+#define Q1 Q (-2/5) 1948+#define Q2 Q (0) 1949+#define Q3 Q (2/5) 1950+#define Q4 Q (4/5) 1951 1952-static const sample_t q_2_0[128] = { 1953+static const quantizer_t q_2_0[128] = { 1954 Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0, 1955 Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1, 1956 Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2, 1957@@ -90,7 +92,7 @@ 1958 0,0,0 1959 }; 1960 1961-static const sample_t q_2_1[128] = { 1962+static const quantizer_t q_2_1[128] = { 1963 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4, 1964 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4, 1965 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4, 1966@@ -99,7 +101,7 @@ 1967 0,0,0 1968 }; 1969 1970-static const sample_t q_2_2[128] = { 1971+static const quantizer_t q_2_2[128] = { 1972 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4, 1973 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4, 1974 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4, 1975@@ -114,24 +116,23 @@ 1976 #undef Q3 1977 #undef Q4 1978 1979-static const sample_t q_3[8] = { 1980- (-6 << 15)/7.0, (-4 << 15)/7.0, (-2 << 15)/7.0, 0, 1981- ( 2 << 15)/7.0, ( 4 << 15)/7.0, ( 6 << 15)/7.0, 0 1982-}; 1983- 1984-#define Q0 ((-10 << 15) / 11.0) 1985-#define Q1 ((-8 << 15) / 11.0) 1986-#define Q2 ((-6 << 15) / 11.0) 1987-#define Q3 ((-4 << 15) / 11.0) 1988-#define Q4 ((-2 << 15) / 11.0) 1989-#define Q5 (0) 1990-#define Q6 ((2 << 15) / 11.0) 1991-#define Q7 ((4 << 15) / 11.0) 1992-#define Q8 ((6 << 15) / 11.0) 1993-#define Q9 ((8 << 15) / 11.0) 1994-#define QA ((10 << 15) / 11.0) 1995+static const quantizer_t q_3[8] = { 1996+ Q (-6/7), Q (-4/7), Q (-2/7), Q (0), Q (2/7), Q (4/7), Q (6/7), 0 1997+}; 1998+ 1999+#define Q0 Q (-10/11) 2000+#define Q1 Q (-8/11) 2001+#define Q2 Q (-6/11) 2002+#define Q3 Q (-4/11) 2003+#define Q4 Q (-2/11) 2004+#define Q5 Q (0) 2005+#define Q6 Q (2/11) 2006+#define Q7 Q (4/11) 2007+#define Q8 Q (6/11) 2008+#define Q9 Q (8/11) 2009+#define QA Q (10/11) 2010 2011-static const sample_t q_4_0[128] = { 2012+static const quantizer_t q_4_0[128] = { 2013 Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, 2014 Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, 2015 Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, 2016@@ -146,7 +147,7 @@ 2017 0, 0, 0, 0, 0, 0, 0 2018 }; 2019 2020-static const sample_t q_4_1[128] = { 2021+static const quantizer_t q_4_1[128] = { 2022 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA, 2023 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA, 2024 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA, 2025@@ -173,15 +174,13 @@ 2026 #undef Q9 2027 #undef QA 2028 2029-static const sample_t q_5[16] = { 2030- (-14 << 15)/15.0,(-12 << 15)/15.0,(-10 << 15)/15.0, 2031- ( -8 << 15)/15.0,( -6 << 15)/15.0,( -4 << 15)/15.0, 2032- ( -2 << 15)/15.0, 0 ,( 2 << 15)/15.0, 2033- ( 4 << 15)/15.0,( 6 << 15)/15.0,( 8 << 15)/15.0, 2034- ( 10 << 15)/15.0,( 12 << 15)/15.0,( 14 << 15)/15.0, 2035- 0 2036+static const quantizer_t q_5[16] = { 2037+ Q (-14/15), Q (-12/15), Q (-10/15), Q (-8/15), Q (-6/15), 2038+ Q (-4/15), Q (-2/15), Q (0), Q (2/15), Q (4/15), 2039+ Q (6/15), Q (8/15), Q (10/15), Q (12/15), Q (14/15), 0 2040 }; 2041 2042+#ifndef LIBA52_FIXED 2043 static const sample_t scale_factor[25] = { 2044 0.000030517578125, 2045 0.0000152587890625, 2046@@ -209,6 +208,7 @@ 2047 0.00000000000363797880709171295166015625, 2048 0.000000000001818989403545856475830078125 2049 }; 2050+#endif 2051 2052 static const uint16_t dither_lut[256] = { 2053 0x0000, 0xa011, 0xe033, 0x4022, 0x6077, 0xc066, 0x8044, 0x2055, 2054