constant.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. Index: a52dec-0.7.4/liba52/bit_allocate.c
  2. ===================================================================
  3. --- a52dec-0.7.4.orig/liba52/bit_allocate.c
  4. +++ a52dec-0.7.4/liba52/bit_allocate.c
  5. @@ -28,7 +28,7 @@
  6. #include "a52.h"
  7. #include "a52_internal.h"
  8. -static int hthtab[3][50] = {
  9. +static const int hthtab[3][50] = {
  10. {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860,
  11. 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890,
  12. 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900,
  13. @@ -46,7 +46,7 @@ static int hthtab[3][50] = {
  14. 0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720}
  15. };
  16. -static int8_t baptab[305] = {
  17. +static const int8_t baptab[305] = {
  18. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  19. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  20. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  21. @@ -71,11 +71,11 @@ static int8_t baptab[305] = {
  22. 0, 0, 0, 0 /* 148 padding elems */
  23. };
  24. -static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
  25. +static const int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
  26. 37, 40, 43, 46, 49, 55, 61, 67, 73, 79,
  27. 85, 97, 109, 121, 133, 157, 181, 205, 229, 253};
  28. -static int8_t latab[256] = {
  29. +static const int8_t latab[256] = {
  30. -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53,
  31. -52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44,
  32. -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35,
  33. @@ -125,9 +125,9 @@ void a52_bit_allocate (a52_state_t * sta
  34. int start, int end, int fastleak, int slowleak,
  35. expbap_t * expbap)
  36. {
  37. - static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
  38. - static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
  39. - static int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
  40. + static const int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
  41. + static const int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
  42. + static const int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
  43. 0xa10, 0xa90, 0xb10, 0x1400};
  44. int i, j;
  45. @@ -135,8 +135,8 @@ void a52_bit_allocate (a52_state_t * sta
  46. int8_t * bap;
  47. int fdecay, fgain, sdecay, sgain, dbknee, floor, snroffset;
  48. int psd, mask;
  49. - int8_t * deltba;
  50. - int * hth;
  51. + const int8_t * deltba;
  52. + const int * hth;
  53. int halfrate;
  54. halfrate = state->halfrate;
  55. Index: a52dec-0.7.4/liba52/imdct.c
  56. ===================================================================
  57. --- a52dec-0.7.4.orig/liba52/imdct.c
  58. +++ a52dec-0.7.4/liba52/imdct.c
  59. @@ -56,6 +56,7 @@ static uint8_t fftorder[] = {
  60. 6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
  61. };
  62. +#ifndef HARDCODED_TABLES
  63. /* Root values for IFFT */
  64. static sample_t roots16[3];
  65. static sample_t roots32[7];
  66. @@ -69,6 +70,13 @@ static complex_t pre2[64];
  67. static complex_t post2[32];
  68. static sample_t a52_imdct_window[256];
  69. +#else
  70. +# ifdef LIBA52_DOUBLE
  71. +# include "imdct_tables_double.h"
  72. +# else
  73. +# include "imdct_tables_float.h"
  74. +# endif
  75. +#endif
  76. static void (* ifft128) (complex_t * buf);
  77. static void (* ifft64) (complex_t * buf);
  78. @@ -178,7 +186,7 @@ static inline void ifft8 (complex_t * bu
  79. BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
  80. }
  81. -static void ifft_pass (complex_t * buf, sample_t * weight, int n)
  82. +static void ifft_pass (complex_t * buf, const sample_t * weight, int n)
  83. {
  84. complex_t * buf1;
  85. complex_t * buf2;
  86. @@ -351,6 +359,7 @@ void a52_imdct_256(sample_t * data, samp
  87. }
  88. }
  89. +#ifndef HARDCODED_TABLES
  90. static double besselI0 (double x)
  91. {
  92. double bessel = 1;
  93. @@ -361,9 +370,11 @@ static double besselI0 (double x)
  94. while (--i);
  95. return bessel;
  96. }
  97. +#endif
  98. void a52_imdct_init (uint32_t mm_accel)
  99. {
  100. +#ifndef HARDCODED_TABLES
  101. int i, k;
  102. double sum;
  103. @@ -416,6 +427,7 @@ void a52_imdct_init (uint32_t mm_accel)
  104. post2[i].real = cos ((M_PI / 128) * (i + 0.5));
  105. post2[i].imag = sin ((M_PI / 128) * (i + 0.5));
  106. }
  107. +#endif
  108. #ifdef LIBA52_DJBFFT
  109. if (mm_accel & MM_ACCEL_DJBFFT) {
  110. Index: a52dec-0.7.4/liba52/imdct-gentables.c
  111. ===================================================================
  112. --- /dev/null
  113. +++ a52dec-0.7.4/liba52/imdct-gentables.c
  114. @@ -0,0 +1,139 @@
  115. +#include <stdint.h>
  116. +#include <stdio.h>
  117. +#include <math.h>
  118. +
  119. +#ifndef LIBA52_DOUBLE
  120. +typedef float sample_t;
  121. +#else
  122. +typedef double sample_t;
  123. +#endif
  124. +
  125. +typedef struct complex_s {
  126. + sample_t real;
  127. + sample_t imag;
  128. +} complex_t;
  129. +
  130. +static uint8_t fftorder[] = {
  131. + 0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
  132. + 8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
  133. + 4,132, 68,196, 36,164,228,100, 20,148, 84,212,244,116, 52,180,
  134. + 252,124, 60,188, 28,156,220, 92, 12,140, 76,204,236,108, 44,172,
  135. + 2,130, 66,194, 34,162,226, 98, 18,146, 82,210,242,114, 50,178,
  136. + 10,138, 74,202, 42,170,234,106,250,122, 58,186, 26,154,218, 90,
  137. + 254,126, 62,190, 30,158,222, 94, 14,142, 78,206,238,110, 46,174,
  138. + 6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
  139. +};
  140. +
  141. +/* Root values for IFFT */
  142. +static sample_t roots16[3];
  143. +static sample_t roots32[7];
  144. +static sample_t roots64[15];
  145. +static sample_t roots128[31];
  146. +
  147. +/* Twiddle factors for IMDCT */
  148. +static complex_t pre1[128];
  149. +static complex_t post1[64];
  150. +static complex_t pre2[64];
  151. +static complex_t post2[32];
  152. +
  153. +static sample_t a52_imdct_window[256];
  154. +
  155. +static double besselI0 (double x)
  156. +{
  157. + double bessel = 1;
  158. + int i = 100;
  159. +
  160. + do
  161. + bessel = bessel * x / (i * i) + 1;
  162. + while (--i);
  163. + return bessel;
  164. +}
  165. +
  166. +int main() {
  167. + int i, k;
  168. + double sum;
  169. +
  170. + /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
  171. + sum = 0;
  172. + for (i = 0; i < 256; i++) {
  173. + sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
  174. + a52_imdct_window[i] = sum;
  175. + }
  176. + sum++;
  177. + for (i = 0; i < 256; i++)
  178. + a52_imdct_window[i] = sqrt (a52_imdct_window[i] / sum);
  179. +
  180. + for (i = 0; i < 3; i++)
  181. + roots16[i] = cos ((M_PI / 8) * (i + 1));
  182. +
  183. + for (i = 0; i < 7; i++)
  184. + roots32[i] = cos ((M_PI / 16) * (i + 1));
  185. +
  186. + for (i = 0; i < 15; i++)
  187. + roots64[i] = cos ((M_PI / 32) * (i + 1));
  188. +
  189. + for (i = 0; i < 31; i++)
  190. + roots128[i] = cos ((M_PI / 64) * (i + 1));
  191. +
  192. + for (i = 0; i < 64; i++) {
  193. + k = fftorder[i] / 2 + 64;
  194. + pre1[i].real = cos ((M_PI / 256) * (k - 0.25));
  195. + pre1[i].imag = sin ((M_PI / 256) * (k - 0.25));
  196. + }
  197. +
  198. + for (i = 64; i < 128; i++) {
  199. + k = fftorder[i] / 2 + 64;
  200. + pre1[i].real = -cos ((M_PI / 256) * (k - 0.25));
  201. + pre1[i].imag = -sin ((M_PI / 256) * (k - 0.25));
  202. + }
  203. +
  204. + for (i = 0; i < 64; i++) {
  205. + post1[i].real = cos ((M_PI / 256) * (i + 0.5));
  206. + post1[i].imag = sin ((M_PI / 256) * (i + 0.5));
  207. + }
  208. +
  209. + for (i = 0; i < 64; i++) {
  210. + k = fftorder[i] / 4;
  211. + pre2[i].real = cos ((M_PI / 128) * (k - 0.25));
  212. + pre2[i].imag = sin ((M_PI / 128) * (k - 0.25));
  213. + }
  214. +
  215. + for (i = 0; i < 32; i++) {
  216. + post2[i].real = cos ((M_PI / 128) * (i + 0.5));
  217. + post2[i].imag = sin ((M_PI / 128) * (i + 0.5));
  218. + }
  219. +
  220. +#define print_table_samples(name, size) \
  221. + do { \
  222. + int i; \
  223. + printf("static const sample_t " #name "[" #size "] = {\n"); \
  224. + for(i = 0; i < size; i++) { \
  225. + printf(" %a%s\n", name[i], i < size-1 ? ", " : ""); \
  226. + } \
  227. + printf("\n};\n\n"); \
  228. + } while(0);
  229. +
  230. +#define print_table_complex(name, size) \
  231. + do { \
  232. + int i; \
  233. + printf("static const complex_t " #name "[" #size "] = {\n"); \
  234. + for(i = 0; i < size; i++) { \
  235. + printf(" { %a, %a }%s\n", name[i].real, name[i].imag, i < size-1 ? ", " : ""); \
  236. + } \
  237. + printf("\n};\n\n"); \
  238. + } while(0);
  239. +
  240. + print_table_samples(roots16, 3);
  241. + print_table_samples(roots32, 7);
  242. + print_table_samples(roots64, 15);
  243. + print_table_samples(roots128, 31);
  244. +
  245. + print_table_complex(pre1, 128);
  246. + print_table_complex(post1, 64);
  247. + print_table_complex(pre2, 64);
  248. + print_table_complex(post2, 32);
  249. +
  250. + print_table_samples(a52_imdct_window, 256);
  251. +
  252. + return 0;
  253. +}
  254. Index: a52dec-0.7.4/liba52/Makefile.am
  255. ===================================================================
  256. --- a52dec-0.7.4.orig/liba52/Makefile.am
  257. +++ a52dec-0.7.4/liba52/Makefile.am
  258. @@ -2,8 +2,26 @@ CFLAGS = @CFLAGS@ @LIBA52_CFLAGS@
  259. lib_LTLIBRARIES = liba52.la
  260. -liba52_la_SOURCES = bitstream.c imdct.c bit_allocate.c parse.c downmix.c
  261. +liba52_la_SOURCES = bitstream.c imdct.c bit_allocate.c parse.c downmix.c imdct_tables_double.h imdct_tables_float.h
  262. liba52_la_LIBADD = @LIBA52_LIBS@ -lm
  263. liba52_la_LDFLAGS = -no-undefined
  264. +noinst_PROGRAMS = imdct-gentables-double imdct-gentables-float
  265. +
  266. +imdct_gentables_double_SOURCES = imdct-gentables.c
  267. +imdct_gentables_double_CFLAGS = $(CFLAGS) -DLIBA52_DOUBLE
  268. +imdct_gentables_double_LDADD = -lm
  269. +
  270. +imdct_gentables_float_SOURCES = imdct-gentables.c
  271. +imdct_gentables_float_CFLAGS = $(CFLAGS) -ULIBA52_DOUBLE
  272. +imdct_gentables_float_LDADD = -lm
  273. +
  274. +imdct_tables_double.h: imdct-gentables-double
  275. + ./$^ > $@
  276. +
  277. +imdct_tables_float.h: imdct-gentables-float
  278. + ./$^ > $@
  279. +
  280. +imdct.c: imdct_tables_double.h imdct_tables_float.h
  281. +
  282. EXTRA_DIST = configure.incl a52_internal.h bitstream.h tables.h