comparison mpegaudiodec.c @ 1064:b32afefe7d33 libavcodec

* UINTX -> uintx_t INTX -> intx_t
author kabi
date Tue, 11 Feb 2003 16:35:48 +0000
parents bb5de8a59da8
children 1e39f273ecd6
comparison
equal deleted inserted replaced
1063:fdeac9642346 1064:b32afefe7d33
40 #define WFRAC_BITS 14 /* fractional bits for window */ 40 #define WFRAC_BITS 14 /* fractional bits for window */
41 #endif 41 #endif
42 42
43 #define FRAC_ONE (1 << FRAC_BITS) 43 #define FRAC_ONE (1 << FRAC_BITS)
44 44
45 #define MULL(a,b) (((INT64)(a) * (INT64)(b)) >> FRAC_BITS) 45 #define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
46 #define MUL64(a,b) ((INT64)(a) * (INT64)(b)) 46 #define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
47 #define FIX(a) ((int)((a) * FRAC_ONE)) 47 #define FIX(a) ((int)((a) * FRAC_ONE))
48 /* WARNING: only correct for posititive numbers */ 48 /* WARNING: only correct for posititive numbers */
49 #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5)) 49 #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
50 #define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS) 50 #define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
51 51
52 #if FRAC_BITS <= 15 52 #if FRAC_BITS <= 15
53 typedef INT16 MPA_INT; 53 typedef int16_t MPA_INT;
54 #else 54 #else
55 typedef INT32 MPA_INT; 55 typedef int32_t MPA_INT;
56 #endif 56 #endif
57 57
58 /****************/ 58 /****************/
59 59
60 #define HEADER_SIZE 4 60 #define HEADER_SIZE 4
61 #define BACKSTEP_SIZE 512 61 #define BACKSTEP_SIZE 512
62 62
63 typedef struct MPADecodeContext { 63 typedef struct MPADecodeContext {
64 UINT8 inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */ 64 uint8_t inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */
65 int inbuf_index; 65 int inbuf_index;
66 UINT8 *inbuf_ptr, *inbuf; 66 uint8_t *inbuf_ptr, *inbuf;
67 int frame_size; 67 int frame_size;
68 int free_format_frame_size; /* frame size in case of free format 68 int free_format_frame_size; /* frame size in case of free format
69 (zero if currently unknown) */ 69 (zero if currently unknown) */
70 /* next header (used in free format parsing) */ 70 /* next header (used in free format parsing) */
71 UINT32 free_format_next_header; 71 uint32_t free_format_next_header;
72 int error_protection; 72 int error_protection;
73 int layer; 73 int layer;
74 int sample_rate; 74 int sample_rate;
75 int sample_rate_index; /* between 0 and 8 */ 75 int sample_rate_index; /* between 0 and 8 */
76 int bit_rate; 76 int bit_rate;
80 int mode; 80 int mode;
81 int mode_ext; 81 int mode_ext;
82 int lsf; 82 int lsf;
83 MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2]; 83 MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2];
84 int synth_buf_offset[MPA_MAX_CHANNELS]; 84 int synth_buf_offset[MPA_MAX_CHANNELS];
85 INT32 sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]; 85 int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT];
86 INT32 mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ 86 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
87 #ifdef DEBUG 87 #ifdef DEBUG
88 int frame_count; 88 int frame_count;
89 #endif 89 #endif
90 } MPADecodeContext; 90 } MPADecodeContext;
91 91
92 /* layer 3 "granule" */ 92 /* layer 3 "granule" */
93 typedef struct GranuleDef { 93 typedef struct GranuleDef {
94 UINT8 scfsi; 94 uint8_t scfsi;
95 int part2_3_length; 95 int part2_3_length;
96 int big_values; 96 int big_values;
97 int global_gain; 97 int global_gain;
98 int scalefac_compress; 98 int scalefac_compress;
99 UINT8 block_type; 99 uint8_t block_type;
100 UINT8 switch_point; 100 uint8_t switch_point;
101 int table_select[3]; 101 int table_select[3];
102 int subblock_gain[3]; 102 int subblock_gain[3];
103 UINT8 scalefac_scale; 103 uint8_t scalefac_scale;
104 UINT8 count1table_select; 104 uint8_t count1table_select;
105 int region_size[3]; /* number of huffman codes in each region */ 105 int region_size[3]; /* number of huffman codes in each region */
106 int preflag; 106 int preflag;
107 int short_start, long_end; /* long/short band indexes */ 107 int short_start, long_end; /* long/short band indexes */
108 UINT8 scale_factors[40]; 108 uint8_t scale_factors[40];
109 INT32 sb_hybrid[SBLIMIT * 18]; /* 576 samples */ 109 int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */
110 } GranuleDef; 110 } GranuleDef;
111 111
112 #define MODE_EXT_MS_STEREO 2 112 #define MODE_EXT_MS_STEREO 2
113 #define MODE_EXT_I_STEREO 1 113 #define MODE_EXT_I_STEREO 1
114 114
115 /* layer 3 huffman tables */ 115 /* layer 3 huffman tables */
116 typedef struct HuffTable { 116 typedef struct HuffTable {
117 int xsize; 117 int xsize;
118 const UINT8 *bits; 118 const uint8_t *bits;
119 const UINT16 *codes; 119 const uint16_t *codes;
120 } HuffTable; 120 } HuffTable;
121 121
122 #include "mpegaudiodectab.h" 122 #include "mpegaudiodectab.h"
123 123
124 /* vlc structure for decoding layer 3 huffman tables */ 124 /* vlc structure for decoding layer 3 huffman tables */
125 static VLC huff_vlc[16]; 125 static VLC huff_vlc[16];
126 static UINT8 *huff_code_table[16]; 126 static uint8_t *huff_code_table[16];
127 static VLC huff_quad_vlc[2]; 127 static VLC huff_quad_vlc[2];
128 /* computed from band_size_long */ 128 /* computed from band_size_long */
129 static UINT16 band_index_long[9][23]; 129 static uint16_t band_index_long[9][23];
130 /* XXX: free when all decoders are closed */ 130 /* XXX: free when all decoders are closed */
131 #define TABLE_4_3_SIZE (8191 + 16) 131 #define TABLE_4_3_SIZE (8191 + 16)
132 static INT8 *table_4_3_exp; 132 static int8_t *table_4_3_exp;
133 #if FRAC_BITS <= 15 133 #if FRAC_BITS <= 15
134 static UINT16 *table_4_3_value; 134 static uint16_t *table_4_3_value;
135 #else 135 #else
136 static UINT32 *table_4_3_value; 136 static uint32_t *table_4_3_value;
137 #endif 137 #endif
138 /* intensity stereo coef table */ 138 /* intensity stereo coef table */
139 static INT32 is_table[2][16]; 139 static int32_t is_table[2][16];
140 static INT32 is_table_lsf[2][2][16]; 140 static int32_t is_table_lsf[2][2][16];
141 static INT32 csa_table[8][2]; 141 static int32_t csa_table[8][2];
142 static INT32 mdct_win[8][36]; 142 static int32_t mdct_win[8][36];
143 143
144 /* lower 2 bits: modulo 3, higher bits: shift */ 144 /* lower 2 bits: modulo 3, higher bits: shift */
145 static UINT16 scale_factor_modshift[64]; 145 static uint16_t scale_factor_modshift[64];
146 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */ 146 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
147 static INT32 scale_factor_mult[15][3]; 147 static int32_t scale_factor_mult[15][3];
148 /* mult table for layer 2 group quantization */ 148 /* mult table for layer 2 group quantization */
149 149
150 #define SCALE_GEN(v) \ 150 #define SCALE_GEN(v) \
151 { FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) } 151 { FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) }
152 152
153 static INT32 scale_factor_mult2[3][3] = { 153 static int32_t scale_factor_mult2[3][3] = {
154 SCALE_GEN(4.0 / 3.0), /* 3 steps */ 154 SCALE_GEN(4.0 / 3.0), /* 3 steps */
155 SCALE_GEN(4.0 / 5.0), /* 5 steps */ 155 SCALE_GEN(4.0 / 5.0), /* 5 steps */
156 SCALE_GEN(4.0 / 9.0), /* 9 steps */ 156 SCALE_GEN(4.0 / 9.0), /* 9 steps */
157 }; 157 };
158 158
159 /* 2^(n/4) */ 159 /* 2^(n/4) */
160 static UINT32 scale_factor_mult3[4] = { 160 static uint32_t scale_factor_mult3[4] = {
161 FIXR(1.0), 161 FIXR(1.0),
162 FIXR(1.18920711500272106671), 162 FIXR(1.18920711500272106671),
163 FIXR(1.41421356237309504880), 163 FIXR(1.41421356237309504880),
164 FIXR(1.68179283050742908605), 164 FIXR(1.68179283050742908605),
165 }; 165 };
169 /* layer 1 unscaling */ 169 /* layer 1 unscaling */
170 /* n = number of bits of the mantissa minus 1 */ 170 /* n = number of bits of the mantissa minus 1 */
171 static inline int l1_unscale(int n, int mant, int scale_factor) 171 static inline int l1_unscale(int n, int mant, int scale_factor)
172 { 172 {
173 int shift, mod; 173 int shift, mod;
174 INT64 val; 174 int64_t val;
175 175
176 shift = scale_factor_modshift[scale_factor]; 176 shift = scale_factor_modshift[scale_factor];
177 mod = shift & 3; 177 mod = shift & 3;
178 shift >>= 2; 178 shift >>= 2;
179 val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]); 179 val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
201 static inline int l3_unscale(int value, int exponent) 201 static inline int l3_unscale(int value, int exponent)
202 { 202 {
203 #if FRAC_BITS <= 15 203 #if FRAC_BITS <= 15
204 unsigned int m; 204 unsigned int m;
205 #else 205 #else
206 UINT64 m; 206 uint64_t m;
207 #endif 207 #endif
208 int e; 208 int e;
209 209
210 e = table_4_3_exp[value]; 210 e = table_4_3_exp[value];
211 e += (exponent >> 2); 211 e += (exponent >> 2);
219 m = (m * scale_factor_mult3[exponent & 3]); 219 m = (m * scale_factor_mult3[exponent & 3]);
220 m = (m + (1 << (e-1))) >> e; 220 m = (m + (1 << (e-1))) >> e;
221 return m; 221 return m;
222 #else 222 #else
223 m = MUL64(m, scale_factor_mult3[exponent & 3]); 223 m = MUL64(m, scale_factor_mult3[exponent & 3]);
224 m = (m + (UINT64_C(1) << (e-1))) >> e; 224 m = (m + (uint64_t_C(1) << (e-1))) >> e;
225 return m; 225 return m;
226 #endif 226 #endif
227 } 227 }
228 228
229 /* all integer n^(4/3) computation code */ 229 /* all integer n^(4/3) computation code */
230 #define DEV_ORDER 13 230 #define DEV_ORDER 13
231 231
232 #define POW_FRAC_BITS 24 232 #define POW_FRAC_BITS 24
233 #define POW_FRAC_ONE (1 << POW_FRAC_BITS) 233 #define POW_FRAC_ONE (1 << POW_FRAC_BITS)
234 #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE)) 234 #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE))
235 #define POW_MULL(a,b) (((INT64)(a) * (INT64)(b)) >> POW_FRAC_BITS) 235 #define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS)
236 236
237 static int dev_4_3_coefs[DEV_ORDER]; 237 static int dev_4_3_coefs[DEV_ORDER];
238 238
239 static int pow_mult3[3] = { 239 static int pow_mult3[3] = {
240 POW_FIX(1.0), 240 POW_FIX(1.0),
316 316
317 /* scale factor multiply for layer 1 */ 317 /* scale factor multiply for layer 1 */
318 for(i=0;i<15;i++) { 318 for(i=0;i<15;i++) {
319 int n, norm; 319 int n, norm;
320 n = i + 2; 320 n = i + 2;
321 norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); 321 norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
322 scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm); 322 scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
323 scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm); 323 scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
324 scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm); 324 scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
325 dprintf("%d: norm=%x s=%x %x %x\n", 325 dprintf("%d: norm=%x s=%x %x %x\n",
326 i, norm, 326 i, norm,
348 huff_code_table[0] = NULL; 348 huff_code_table[0] = NULL;
349 for(i=1;i<16;i++) { 349 for(i=1;i<16;i++) {
350 const HuffTable *h = &mpa_huff_tables[i]; 350 const HuffTable *h = &mpa_huff_tables[i];
351 int xsize, x, y; 351 int xsize, x, y;
352 unsigned int n; 352 unsigned int n;
353 UINT8 *code_table; 353 uint8_t *code_table;
354 354
355 xsize = h->xsize; 355 xsize = h->xsize;
356 n = xsize * xsize; 356 n = xsize * xsize;
357 /* XXX: fail test */ 357 /* XXX: fail test */
358 init_vlc(&huff_vlc[i], 8, n, 358 init_vlc(&huff_vlc[i], 8, n,
575 } 575 }
576 576
577 #define ADD(a, b) tab[a] += tab[b] 577 #define ADD(a, b) tab[a] += tab[b]
578 578
579 /* DCT32 without 1/sqrt(2) coef zero scaling. */ 579 /* DCT32 without 1/sqrt(2) coef zero scaling. */
580 static void dct32(INT32 *out, INT32 *tab) 580 static void dct32(int32_t *out, int32_t *tab)
581 { 581 {
582 int tmp0, tmp1; 582 int tmp0, tmp1;
583 583
584 /* pass 1 */ 584 /* pass 1 */
585 BF(0, 31, COS0_0); 585 BF(0, 31, COS0_0);
758 #else 758 #else
759 759
760 #define OUT_SAMPLE(sum)\ 760 #define OUT_SAMPLE(sum)\
761 {\ 761 {\
762 int sum1;\ 762 int sum1;\
763 sum1 = (int)((sum + (INT64_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);\ 763 sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);\
764 if (sum1 < -32768)\ 764 if (sum1 < -32768)\
765 sum1 = -32768;\ 765 sum1 = -32768;\
766 else if (sum1 > 32767)\ 766 else if (sum1 > 32767)\
767 sum1 = 32767;\ 767 sum1 = 32767;\
768 *samples = sum1;\ 768 *samples = sum1;\
785 785
786 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output: 786 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
787 32 samples. */ 787 32 samples. */
788 /* XXX: optimize by avoiding ring buffer usage */ 788 /* XXX: optimize by avoiding ring buffer usage */
789 static void synth_filter(MPADecodeContext *s1, 789 static void synth_filter(MPADecodeContext *s1,
790 int ch, INT16 *samples, int incr, 790 int ch, int16_t *samples, int incr,
791 INT32 sb_samples[SBLIMIT]) 791 int32_t sb_samples[SBLIMIT])
792 { 792 {
793 INT32 tmp[32]; 793 int32_t tmp[32];
794 register MPA_INT *synth_buf, *p; 794 register MPA_INT *synth_buf, *p;
795 register MPA_INT *w; 795 register MPA_INT *w;
796 int j, offset, v; 796 int j, offset, v;
797 #if FRAC_BITS <= 15 797 #if FRAC_BITS <= 15
798 int sum; 798 int sum;
799 #else 799 #else
800 INT64 sum; 800 int64_t sum;
801 #endif 801 #endif
802 802
803 dct32(tmp, sb_samples); 803 dct32(tmp, sb_samples);
804 804
805 offset = s1->synth_buf_offset[ch]; 805 offset = s1->synth_buf_offset[ch];
861 /* 12 points IMDCT. We compute it "by hand" by factorizing obvious 861 /* 12 points IMDCT. We compute it "by hand" by factorizing obvious
862 cases. */ 862 cases. */
863 static void imdct12(int *out, int *in) 863 static void imdct12(int *out, int *in)
864 { 864 {
865 int tmp; 865 int tmp;
866 INT64 in1_3, in1_9, in4_3, in4_9; 866 int64_t in1_3, in1_9, in4_3, in4_9;
867 867
868 in1_3 = MUL64(in[1], C3); 868 in1_3 = MUL64(in[1], C3);
869 in1_9 = MUL64(in[1], C9); 869 in1_9 = MUL64(in[1], C9);
870 in4_3 = MUL64(in[4], C3); 870 in4_3 = MUL64(in[4], C3);
871 in4_9 = MUL64(in[4], C9); 871 in4_9 = MUL64(in[4], C9);
953 /* using Lee like decomposition followed by hand coded 9 points DCT */ 953 /* using Lee like decomposition followed by hand coded 9 points DCT */
954 static void imdct36(int *out, int *in) 954 static void imdct36(int *out, int *in)
955 { 955 {
956 int i, j, t0, t1, t2, t3, s0, s1, s2, s3; 956 int i, j, t0, t1, t2, t3, s0, s1, s2, s3;
957 int tmp[18], *tmp1, *in1; 957 int tmp[18], *tmp1, *in1;
958 INT64 in3_3, in6_6; 958 int64_t in3_3, in6_6;
959 959
960 for(i=17;i>=1;i--) 960 for(i=17;i>=1;i--)
961 in[i] += in[i-1]; 961 in[i] += in[i-1];
962 for(i=17;i>=3;i-=2) 962 for(i=17;i>=3;i-=2)
963 in[i] += in[i-2]; 963 in[i] += in[i-2];
1028 out[9 + 4] = -t1; 1028 out[9 + 4] = -t1;
1029 out[8 - 4] = t1; 1029 out[8 - 4] = t1;
1030 } 1030 }
1031 1031
1032 /* fast header check for resync */ 1032 /* fast header check for resync */
1033 static int check_header(UINT32 header) 1033 static int check_header(uint32_t header)
1034 { 1034 {
1035 /* header */ 1035 /* header */
1036 if ((header & 0xffe00000) != 0xffe00000) 1036 if ((header & 0xffe00000) != 0xffe00000)
1037 return -1; 1037 return -1;
1038 /* layer check */ 1038 /* layer check */
1052 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19)) 1052 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
1053 1053
1054 /* header decoding. MUST check the header before because no 1054 /* header decoding. MUST check the header before because no
1055 consistency check is done there. Return 1 if free format found and 1055 consistency check is done there. Return 1 if free format found and
1056 that the frame size must be computed externally */ 1056 that the frame size must be computed externally */
1057 static int decode_header(MPADecodeContext *s, UINT32 header) 1057 static int decode_header(MPADecodeContext *s, uint32_t header)
1058 { 1058 {
1059 int sample_rate, frame_size, mpeg25, padding; 1059 int sample_rate, frame_size, mpeg25, padding;
1060 int sample_rate_index, bitrate_index; 1060 int sample_rate_index, bitrate_index;
1061 if (header & (1<<20)) { 1061 if (header & (1<<20)) {
1062 s->lsf = (header & (1<<19)) ? 0 : 1; 1062 s->lsf = (header & (1<<19)) ? 0 : 1;
1153 1153
1154 /* return the number of decoded frames */ 1154 /* return the number of decoded frames */
1155 static int mp_decode_layer1(MPADecodeContext *s) 1155 static int mp_decode_layer1(MPADecodeContext *s)
1156 { 1156 {
1157 int bound, i, v, n, ch, j, mant; 1157 int bound, i, v, n, ch, j, mant;
1158 UINT8 allocation[MPA_MAX_CHANNELS][SBLIMIT]; 1158 uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
1159 UINT8 scale_factors[MPA_MAX_CHANNELS][SBLIMIT]; 1159 uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
1160 1160
1161 if (s->mode == MPA_JSTEREO) 1161 if (s->mode == MPA_JSTEREO)
1162 bound = (s->mode_ext + 1) * 4; 1162 bound = (s->mode_ext + 1) * 4;
1163 else 1163 else
1164 bound = SBLIMIT; 1164 bound = SBLIMIT;
1449 /* 1449 /*
1450 * Seek back in the stream for backstep bytes (at most 511 bytes) 1450 * Seek back in the stream for backstep bytes (at most 511 bytes)
1451 */ 1451 */
1452 static void seek_to_maindata(MPADecodeContext *s, unsigned int backstep) 1452 static void seek_to_maindata(MPADecodeContext *s, unsigned int backstep)
1453 { 1453 {
1454 UINT8 *ptr; 1454 uint8_t *ptr;
1455 1455
1456 /* compute current position in stream */ 1456 /* compute current position in stream */
1457 ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); 1457 ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
1458 1458
1459 /* copy old data before current one */ 1459 /* copy old data before current one */
1489 slen[0] = sf; 1489 slen[0] = sf;
1490 } 1490 }
1491 1491
1492 static void exponents_from_scale_factors(MPADecodeContext *s, 1492 static void exponents_from_scale_factors(MPADecodeContext *s,
1493 GranuleDef *g, 1493 GranuleDef *g,
1494 INT16 *exponents) 1494 int16_t *exponents)
1495 { 1495 {
1496 const UINT8 *bstab, *pretab; 1496 const uint8_t *bstab, *pretab;
1497 int len, i, j, k, l, v0, shift, gain, gains[3]; 1497 int len, i, j, k, l, v0, shift, gain, gains[3];
1498 INT16 *exp_ptr; 1498 int16_t *exp_ptr;
1499 1499
1500 exp_ptr = exponents; 1500 exp_ptr = exponents;
1501 gain = g->global_gain - 210; 1501 gain = g->global_gain - 210;
1502 shift = g->scalefac_scale + 1; 1502 shift = g->scalefac_scale + 1;
1503 1503
1535 else 1535 else
1536 return get_bits(s, n); 1536 return get_bits(s, n);
1537 } 1537 }
1538 1538
1539 static int huffman_decode(MPADecodeContext *s, GranuleDef *g, 1539 static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
1540 INT16 *exponents, int end_pos) 1540 int16_t *exponents, int end_pos)
1541 { 1541 {
1542 int s_index; 1542 int s_index;
1543 int linbits, code, x, y, l, v, i, j, k, pos; 1543 int linbits, code, x, y, l, v, i, j, k, pos;
1544 GetBitContext last_gb; 1544 GetBitContext last_gb;
1545 VLC *vlc; 1545 VLC *vlc;
1546 UINT8 *code_table; 1546 uint8_t *code_table;
1547 1547
1548 /* low frequencies (called big values) */ 1548 /* low frequencies (called big values) */
1549 s_index = 0; 1549 s_index = 0;
1550 for(i=0;i<3;i++) { 1550 for(i=0;i<3;i++) {
1551 j = g->region_size[i]; 1551 j = g->region_size[i];
1640 would be faster to do it in parsing, but the code would be far more 1640 would be faster to do it in parsing, but the code would be far more
1641 complicated */ 1641 complicated */
1642 static void reorder_block(MPADecodeContext *s, GranuleDef *g) 1642 static void reorder_block(MPADecodeContext *s, GranuleDef *g)
1643 { 1643 {
1644 int i, j, k, len; 1644 int i, j, k, len;
1645 INT32 *ptr, *dst, *ptr1; 1645 int32_t *ptr, *dst, *ptr1;
1646 INT32 tmp[576]; 1646 int32_t tmp[576];
1647 1647
1648 if (g->block_type != 2) 1648 if (g->block_type != 2)
1649 return; 1649 return;
1650 1650
1651 if (g->switch_point) { 1651 if (g->switch_point) {
1666 for(j=len;j>0;j--) { 1666 for(j=len;j>0;j--) {
1667 *dst = *ptr++; 1667 *dst = *ptr++;
1668 dst += 3; 1668 dst += 3;
1669 } 1669 }
1670 } 1670 }
1671 memcpy(ptr1, tmp, len * 3 * sizeof(INT32)); 1671 memcpy(ptr1, tmp, len * 3 * sizeof(int32_t));
1672 } 1672 }
1673 } 1673 }
1674 1674
1675 #define ISQRT2 FIXR(0.70710678118654752440) 1675 #define ISQRT2 FIXR(0.70710678118654752440)
1676 1676
1677 static void compute_stereo(MPADecodeContext *s, 1677 static void compute_stereo(MPADecodeContext *s,
1678 GranuleDef *g0, GranuleDef *g1) 1678 GranuleDef *g0, GranuleDef *g1)
1679 { 1679 {
1680 int i, j, k, l; 1680 int i, j, k, l;
1681 INT32 v1, v2; 1681 int32_t v1, v2;
1682 int sf_max, tmp0, tmp1, sf, len, non_zero_found; 1682 int sf_max, tmp0, tmp1, sf, len, non_zero_found;
1683 INT32 (*is_tab)[16]; 1683 int32_t (*is_tab)[16];
1684 INT32 *tab0, *tab1; 1684 int32_t *tab0, *tab1;
1685 int non_zero_found_short[3]; 1685 int non_zero_found_short[3];
1686 1686
1687 /* intensity stereo */ 1687 /* intensity stereo */
1688 if (s->mode_ext & MODE_EXT_I_STEREO) { 1688 if (s->mode_ext & MODE_EXT_I_STEREO) {
1689 if (!s->lsf) { 1689 if (!s->lsf) {
1802 } 1802 }
1803 1803
1804 static void compute_antialias(MPADecodeContext *s, 1804 static void compute_antialias(MPADecodeContext *s,
1805 GranuleDef *g) 1805 GranuleDef *g)
1806 { 1806 {
1807 INT32 *ptr, *p0, *p1, *csa; 1807 int32_t *ptr, *p0, *p1, *csa;
1808 int n, tmp0, tmp1, i, j; 1808 int n, tmp0, tmp1, i, j;
1809 1809
1810 /* we antialias only "long" bands */ 1810 /* we antialias only "long" bands */
1811 if (g->block_type == 2) { 1811 if (g->block_type == 2) {
1812 if (!g->switch_point) 1812 if (!g->switch_point)
1835 } 1835 }
1836 } 1836 }
1837 1837
1838 static void compute_imdct(MPADecodeContext *s, 1838 static void compute_imdct(MPADecodeContext *s,
1839 GranuleDef *g, 1839 GranuleDef *g,
1840 INT32 *sb_samples, 1840 int32_t *sb_samples,
1841 INT32 *mdct_buf) 1841 int32_t *mdct_buf)
1842 { 1842 {
1843 INT32 *ptr, *win, *win1, *buf, *buf2, *out_ptr, *ptr1; 1843 int32_t *ptr, *win, *win1, *buf, *buf2, *out_ptr, *ptr1;
1844 INT32 in[6]; 1844 int32_t in[6];
1845 INT32 out[36]; 1845 int32_t out[36];
1846 INT32 out2[12]; 1846 int32_t out2[12];
1847 int i, j, k, mdct_long_end, v, sblimit; 1847 int i, j, k, mdct_long_end, v, sblimit;
1848 1848
1849 /* find last non zero block */ 1849 /* find last non zero block */
1850 ptr = g->sb_hybrid + 576; 1850 ptr = g->sb_hybrid + 576;
1851 ptr1 = g->sb_hybrid + 2 * 18; 1851 ptr1 = g->sb_hybrid + 2 * 18;
1934 buf += 18; 1934 buf += 18;
1935 } 1935 }
1936 } 1936 }
1937 1937
1938 #if defined(DEBUG) 1938 #if defined(DEBUG)
1939 void sample_dump(int fnum, INT32 *tab, int n) 1939 void sample_dump(int fnum, int32_t *tab, int n)
1940 { 1940 {
1941 static FILE *files[16], *f; 1941 static FILE *files[16], *f;
1942 char buf[512]; 1942 char buf[512];
1943 int i; 1943 int i;
1944 INT32 v; 1944 int32_t v;
1945 1945
1946 f = files[fnum]; 1946 f = files[fnum];
1947 if (!f) { 1947 if (!f) {
1948 sprintf(buf, "/tmp/out%d.%s.pcm", 1948 sprintf(buf, "/tmp/out%d.%s.pcm",
1949 fnum, 1949 fnum,
1970 pos += n; 1970 pos += n;
1971 } 1971 }
1972 for(i=0;i<n;i++) { 1972 for(i=0;i<n;i++) {
1973 /* normalize to 23 frac bits */ 1973 /* normalize to 23 frac bits */
1974 v = tab[i] << (23 - FRAC_BITS); 1974 v = tab[i] << (23 - FRAC_BITS);
1975 fwrite(&v, 1, sizeof(INT32), f); 1975 fwrite(&v, 1, sizeof(int32_t), f);
1976 } 1976 }
1977 } 1977 }
1978 #endif 1978 #endif
1979 1979
1980 1980
1982 static int mp_decode_layer3(MPADecodeContext *s) 1982 static int mp_decode_layer3(MPADecodeContext *s)
1983 { 1983 {
1984 int nb_granules, main_data_begin, private_bits; 1984 int nb_granules, main_data_begin, private_bits;
1985 int gr, ch, blocksplit_flag, i, j, k, n, bits_pos, bits_left; 1985 int gr, ch, blocksplit_flag, i, j, k, n, bits_pos, bits_left;
1986 GranuleDef granules[2][2], *g; 1986 GranuleDef granules[2][2], *g;
1987 INT16 exponents[576]; 1987 int16_t exponents[576];
1988 1988
1989 /* read side info */ 1989 /* read side info */
1990 if (s->lsf) { 1990 if (s->lsf) {
1991 main_data_begin = get_bits(&s->gb, 8); 1991 main_data_begin = get_bits(&s->gb, 8);
1992 if (s->nb_channels == 2) 1992 if (s->nb_channels == 2)
2122 g = &granules[ch][gr]; 2122 g = &granules[ch][gr];
2123 2123
2124 bits_pos = get_bits_count(&s->gb); 2124 bits_pos = get_bits_count(&s->gb);
2125 2125
2126 if (!s->lsf) { 2126 if (!s->lsf) {
2127 UINT8 *sc; 2127 uint8_t *sc;
2128 int slen, slen1, slen2; 2128 int slen, slen1, slen2;
2129 2129
2130 /* MPEG1 scale factors */ 2130 /* MPEG1 scale factors */
2131 slen1 = slen_table[0][g->scalefac_compress]; 2131 slen1 = slen_table[0][g->scalefac_compress];
2132 slen2 = slen_table[1][g->scalefac_compress]; 2132 slen2 = slen_table[1][g->scalefac_compress];
2326 return nb_frames * 32 * sizeof(short) * s->nb_channels; 2326 return nb_frames * 32 * sizeof(short) * s->nb_channels;
2327 } 2327 }
2328 2328
2329 static int decode_frame(AVCodecContext * avctx, 2329 static int decode_frame(AVCodecContext * avctx,
2330 void *data, int *data_size, 2330 void *data, int *data_size,
2331 UINT8 * buf, int buf_size) 2331 uint8_t * buf, int buf_size)
2332 { 2332 {
2333 MPADecodeContext *s = avctx->priv_data; 2333 MPADecodeContext *s = avctx->priv_data;
2334 UINT32 header; 2334 uint32_t header;
2335 UINT8 *buf_ptr; 2335 uint8_t *buf_ptr;
2336 int len, out_size; 2336 int len, out_size;
2337 short *out_samples = data; 2337 short *out_samples = data;
2338 2338
2339 *data_size = 0; 2339 *data_size = 0;
2340 buf_ptr = buf; 2340 buf_ptr = buf;
2397 /* frame too long: resync */ 2397 /* frame too long: resync */
2398 s->frame_size = 0; 2398 s->frame_size = 0;
2399 memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); 2399 memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
2400 s->inbuf_ptr--; 2400 s->inbuf_ptr--;
2401 } else { 2401 } else {
2402 UINT8 *p, *pend; 2402 uint8_t *p, *pend;
2403 UINT32 header1; 2403 uint32_t header1;
2404 int padding; 2404 int padding;
2405 2405
2406 memcpy(s->inbuf_ptr, buf_ptr, len); 2406 memcpy(s->inbuf_ptr, buf_ptr, len);
2407 /* check for header */ 2407 /* check for header */
2408 p = s->inbuf_ptr - 3; 2408 p = s->inbuf_ptr - 3;