summaryrefslogtreecommitdiff
path: root/apps/codecs/liba52/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/liba52/parse.c')
-rw-r--r--apps/codecs/liba52/parse.c1200
1 files changed, 600 insertions, 600 deletions
diff --git a/apps/codecs/liba52/parse.c b/apps/codecs/liba52/parse.c
index f2b0ce4f6d..fd7e13006d 100644
--- a/apps/codecs/liba52/parse.c
+++ b/apps/codecs/liba52/parse.c
@@ -66,19 +66,19 @@ a52_state_t * a52_init (uint32_t mm_accel)
66 simultenously. NOTE, you also need to remove comments in a52_free. 66 simultenously. NOTE, you also need to remove comments in a52_free.
67 state = (a52_state_t *) malloc (sizeof (a52_state_t)); 67 state = (a52_state_t *) malloc (sizeof (a52_state_t));
68 if (state == NULL) 68 if (state == NULL)
69 return NULL; 69 return NULL;
70 70
71 state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t)); 71 state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
72 if (state->samples == NULL) { 72 if (state->samples == NULL) {
73 free (state); 73 free (state);
74 return NULL; 74 return NULL;
75 } 75 }
76 76
77 */ 77 */
78 state = &istate; 78 state = &istate;
79 state->samples = isamples; 79 state->samples = isamples;
80 for (i = 0; i < 256 * 12; i++) 80 for (i = 0; i < 256 * 12; i++)
81 state->samples[i] = 0; 81 state->samples[i] = 0;
82 82
83 state->downmixed = 1; 83 state->downmixed = 1;
84 84
@@ -95,57 +95,57 @@ sample_t * a52_samples (a52_state_t * state)
95} 95}
96 96
97int a52_syncinfo (uint8_t * buf, int * flags, 97int a52_syncinfo (uint8_t * buf, int * flags,
98 int * sample_rate, int * bit_rate) 98 int * sample_rate, int * bit_rate)
99{ 99{
100 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112, 100 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
101 128, 160, 192, 224, 256, 320, 384, 448, 101 128, 160, 192, 224, 256, 320, 384, 448,
102 512, 576, 640}; 102 512, 576, 640};
103 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01}; 103 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
104 int frmsizecod; 104 int frmsizecod;
105 int bitrate; 105 int bitrate;
106 int half; 106 int half;
107 int acmod; 107 int acmod;
108 108
109 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */ 109 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
110 return 0; 110 return 0;
111 111
112 if (buf[5] >= 0x60) /* bsid >= 12 */ 112 if (buf[5] >= 0x60) /* bsid >= 12 */
113 return 0; 113 return 0;
114 half = halfrate[buf[5] >> 3]; 114 half = halfrate[buf[5] >> 3];
115 115
116 /* acmod, dsurmod and lfeon */ 116 /* acmod, dsurmod and lfeon */
117 acmod = buf[6] >> 5; 117 acmod = buf[6] >> 5;
118 *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) | 118 *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) |
119 ((buf[6] & lfeon[acmod]) ? A52_LFE : 0)); 119 ((buf[6] & lfeon[acmod]) ? A52_LFE : 0));
120 120
121 frmsizecod = buf[4] & 63; 121 frmsizecod = buf[4] & 63;
122 if (frmsizecod >= 38) 122 if (frmsizecod >= 38)
123 return 0; 123 return 0;
124 bitrate = rate [frmsizecod >> 1]; 124 bitrate = rate [frmsizecod >> 1];
125 *bit_rate = (bitrate * 1000) >> half; 125 *bit_rate = (bitrate * 1000) >> half;
126 126
127 switch (buf[4] & 0xc0) { 127 switch (buf[4] & 0xc0) {
128 case 0: 128 case 0:
129 *sample_rate = 48000 >> half; 129 *sample_rate = 48000 >> half;
130 return 4 * bitrate; 130 return 4 * bitrate;
131 case 0x40: 131 case 0x40:
132 *sample_rate = 44100 >> half; 132 *sample_rate = 44100 >> half;
133 return 2 * (320 * bitrate / 147 + (frmsizecod & 1)); 133 return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
134 case 0x80: 134 case 0x80:
135 *sample_rate = 32000 >> half; 135 *sample_rate = 32000 >> half;
136 return 6 * bitrate; 136 return 6 * bitrate;
137 default: 137 default:
138 return 0; 138 return 0;
139 } 139 }
140} 140}
141 141
142int a52_frame (a52_state_t * state, uint8_t * buf, int * flags, 142int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
143 level_t * level, sample_t bias) 143 level_t * level, sample_t bias)
144{ 144{
145 static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB), 145 static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB),
146 LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) }; 146 LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) };
147 static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB), 147 static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB),
148 0, LEVEL (LEVEL_6DB) }; 148 0, LEVEL (LEVEL_6DB) };
149 int chaninfo; 149 int chaninfo;
150 int acmod; 150 int acmod;
151 151
@@ -154,27 +154,27 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
154 state->acmod = acmod = buf[6] >> 5; 154 state->acmod = acmod = buf[6] >> 5;
155 155
156 a52_bitstream_set_ptr (state, buf + 6); 156 a52_bitstream_set_ptr (state, buf + 6);
157 bitstream_get (state, 3); /* skip acmod we already parsed */ 157 bitstream_get (state, 3); /* skip acmod we already parsed */
158 158
159 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */ 159 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
160 acmod = A52_DOLBY; 160 acmod = A52_DOLBY;
161 161
162 state->clev = state->slev = 0; 162 state->clev = state->slev = 0;
163 163
164 if ((acmod & 1) && (acmod != 1)) 164 if ((acmod & 1) && (acmod != 1))
165 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */ 165 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
166 166
167 if (acmod & 4) 167 if (acmod & 4)
168 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */ 168 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
169 169
170 state->lfeon = bitstream_get (state, 1); 170 state->lfeon = bitstream_get (state, 1);
171 171
172 state->output = a52_downmix_init (acmod, *flags, level, 172 state->output = a52_downmix_init (acmod, *flags, level,
173 state->clev, state->slev); 173 state->clev, state->slev);
174 if (state->output < 0) 174 if (state->output < 0)
175 return 1; 175 return 1;
176 if (state->lfeon && (*flags & A52_LFE)) 176 if (state->lfeon && (*flags & A52_LFE))
177 state->output |= A52_LFE; 177 state->output |= A52_LFE;
178 *flags = state->output; 178 *flags = state->output;
179 /* the 2* compensates for differences in imdct */ 179 /* the 2* compensates for differences in imdct */
180 state->dynrng = state->level = MUL_C (*level, 2); 180 state->dynrng = state->level = MUL_C (*level, 2);
@@ -183,99 +183,99 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
183 state->dynrngcall = NULL; 183 state->dynrngcall = NULL;
184 state->cplba.deltbae = DELTA_BIT_NONE; 184 state->cplba.deltbae = DELTA_BIT_NONE;
185 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae = 185 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae =
186 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE; 186 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE;
187 187
188 chaninfo = !acmod; 188 chaninfo = !acmod;
189 do { 189 do {
190 bitstream_get (state, 5); /* dialnorm */ 190 bitstream_get (state, 5); /* dialnorm */
191 if (bitstream_get (state, 1)) /* compre */ 191 if (bitstream_get (state, 1)) /* compre */
192 bitstream_get (state, 8); /* compr */ 192 bitstream_get (state, 8); /* compr */
193 if (bitstream_get (state, 1)) /* langcode */ 193 if (bitstream_get (state, 1)) /* langcode */
194 bitstream_get (state, 8); /* langcod */ 194 bitstream_get (state, 8); /* langcod */
195 if (bitstream_get (state, 1)) /* audprodie */ 195 if (bitstream_get (state, 1)) /* audprodie */
196 bitstream_get (state, 7); /* mixlevel + roomtyp */ 196 bitstream_get (state, 7); /* mixlevel + roomtyp */
197 } while (chaninfo--); 197 } while (chaninfo--);
198 198
199 bitstream_get (state, 2); /* copyrightb + origbs */ 199 bitstream_get (state, 2); /* copyrightb + origbs */
200 200
201 if (bitstream_get (state, 1)) /* timecod1e */ 201 if (bitstream_get (state, 1)) /* timecod1e */
202 bitstream_get (state, 14); /* timecod1 */ 202 bitstream_get (state, 14); /* timecod1 */
203 if (bitstream_get (state, 1)) /* timecod2e */ 203 if (bitstream_get (state, 1)) /* timecod2e */
204 bitstream_get (state, 14); /* timecod2 */ 204 bitstream_get (state, 14); /* timecod2 */
205 205
206 if (bitstream_get (state, 1)) { /* addbsie */ 206 if (bitstream_get (state, 1)) { /* addbsie */
207 int addbsil; 207 int addbsil;
208 208
209 addbsil = bitstream_get (state, 6); 209 addbsil = bitstream_get (state, 6);
210 do { 210 do {
211 bitstream_get (state, 8); /* addbsi */ 211 bitstream_get (state, 8); /* addbsi */
212 } while (addbsil--); 212 } while (addbsil--);
213 } 213 }
214 214
215 return 0; 215 return 0;
216} 216}
217 217
218void a52_dynrng (a52_state_t * state, 218void a52_dynrng (a52_state_t * state,
219 level_t (* call) (level_t, void *), void * data) 219 level_t (* call) (level_t, void *), void * data)
220{ 220{
221 state->dynrnge = 0; 221 state->dynrnge = 0;
222 if (call) { 222 if (call) {
223 state->dynrnge = 1; 223 state->dynrnge = 1;
224 state->dynrngcall = call; 224 state->dynrngcall = call;
225 state->dynrngdata = data; 225 state->dynrngdata = data;
226 } 226 }
227} 227}
228 228
229static int parse_exponents (a52_state_t * state, int expstr, int ngrps, 229static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
230 uint8_t exponent, uint8_t * dest) 230 uint8_t exponent, uint8_t * dest)
231{ 231{
232 int exps; 232 int exps;
233 233
234 while (ngrps--) { 234 while (ngrps--) {
235 exps = bitstream_get (state, 7); 235 exps = bitstream_get (state, 7);
236 236
237 exponent += exp_1[exps]; 237 exponent += exp_1[exps];
238 if (exponent > 24) 238 if (exponent > 24)
239 return 1; 239 return 1;
240 240
241 switch (expstr) { 241 switch (expstr) {
242 case EXP_D45: 242 case EXP_D45:
243 *(dest++) = exponent; 243 *(dest++) = exponent;
244 *(dest++) = exponent; 244 *(dest++) = exponent;
245 case EXP_D25: 245 case EXP_D25:
246 *(dest++) = exponent; 246 *(dest++) = exponent;
247 case EXP_D15: 247 case EXP_D15:
248 *(dest++) = exponent; 248 *(dest++) = exponent;
249 } 249 }
250 250
251 exponent += exp_2[exps]; 251 exponent += exp_2[exps];
252 if (exponent > 24) 252 if (exponent > 24)
253 return 1; 253 return 1;
254 254
255 switch (expstr) { 255 switch (expstr) {
256 case EXP_D45: 256 case EXP_D45:
257 *(dest++) = exponent; 257 *(dest++) = exponent;
258 *(dest++) = exponent; 258 *(dest++) = exponent;
259 case EXP_D25: 259 case EXP_D25:
260 *(dest++) = exponent; 260 *(dest++) = exponent;
261 case EXP_D15: 261 case EXP_D15:
262 *(dest++) = exponent; 262 *(dest++) = exponent;
263 } 263 }
264 264
265 exponent += exp_3[exps]; 265 exponent += exp_3[exps];
266 if (exponent > 24) 266 if (exponent > 24)
267 return 1; 267 return 1;
268 268
269 switch (expstr) { 269 switch (expstr) {
270 case EXP_D45: 270 case EXP_D45:
271 *(dest++) = exponent; 271 *(dest++) = exponent;
272 *(dest++) = exponent; 272 *(dest++) = exponent;
273 case EXP_D25: 273 case EXP_D25:
274 *(dest++) = exponent; 274 *(dest++) = exponent;
275 case EXP_D15: 275 case EXP_D15:
276 *(dest++) = exponent; 276 *(dest++) = exponent;
277 } 277 }
278 } 278 }
279 279
280 return 0; 280 return 0;
281} 281}
@@ -289,16 +289,16 @@ static int parse_deltba (a52_state_t * state, int8_t * deltba)
289 deltnseg = bitstream_get (state, 3); 289 deltnseg = bitstream_get (state, 3);
290 j = 0; 290 j = 0;
291 do { 291 do {
292 j += bitstream_get (state, 5); 292 j += bitstream_get (state, 5);
293 deltlen = bitstream_get (state, 4); 293 deltlen = bitstream_get (state, 4);
294 delta = bitstream_get (state, 3); 294 delta = bitstream_get (state, 3);
295 delta -= (delta >= 4) ? 3 : 4; 295 delta -= (delta >= 4) ? 3 : 4;
296 if (!deltlen) 296 if (!deltlen)
297 continue; 297 continue;
298 if (j + deltlen >= 50) 298 if (j + deltlen >= 50)
299 return 1; 299 return 1;
300 while (deltlen--) 300 while (deltlen--)
301 deltba[j++] = delta; 301 deltba[j++] = delta;
302 } while (deltnseg--); 302 } while (deltnseg--);
303 303
304 return 0; 304 return 0;
@@ -309,12 +309,12 @@ static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
309 int i; 309 int i;
310 310
311 if ((state->csnroffst) || 311 if ((state->csnroffst) ||
312 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */ 312 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */
313 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */ 313 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */
314 return 0; 314 return 0;
315 for (i = 0; i < nfchans; i++) 315 for (i = 0; i < nfchans; i++)
316 if (state->ba[i].bai >> 3) /* fsnroffst */ 316 if (state->ba[i].bai >> 3) /* fsnroffst */
317 return 0; 317 return 0;
318 return 1; 318 return 1;
319} 319}
320 320
@@ -323,7 +323,7 @@ static inline int16_t dither_gen (a52_state_t * state)
323 int16_t nstate; 323 int16_t nstate;
324 324
325 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8); 325 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
326 326
327 state->lfsr_state = (uint16_t) nstate; 327 state->lfsr_state = (uint16_t) nstate;
328 328
329 return (3 * nstate) >> 2; 329 return (3 * nstate) >> 2;
@@ -332,21 +332,21 @@ static inline int16_t dither_gen (a52_state_t * state)
332#ifndef LIBA52_FIXED 332#ifndef LIBA52_FIXED
333#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e] 333#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
334#else 334#else
335#define COEFF(c,_t,_l,s,e) do { \ 335#define COEFF(c,_t,_l,s,e) do { \
336 quantizer_t t = (_t); \ 336 quantizer_t t = (_t); \
337 level_t l = (_l); \ 337 level_t l = (_l); \
338 int shift = e - 5; \ 338 int shift = e - 5; \
339 sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \ 339 sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
340 if (shift >= 0) \ 340 if (shift >= 0) \
341 (c) = tmp >> shift; \ 341 (c) = tmp >> shift; \
342 else \ 342 else \
343 (c) = tmp << -shift; \ 343 (c) = tmp << -shift; \
344} while (0) 344} while (0)
345#endif 345#endif
346 346
347static void coeff_get (a52_state_t * state, sample_t * coeff, 347static void coeff_get (a52_state_t * state, sample_t * coeff,
348 expbap_t * expbap, quantizer_set_t * quant, 348 expbap_t * expbap, quantizer_set_t * quant,
349 level_t level, int dither, int end) 349 level_t level, int dither, int end)
350{ 350{
351 int i; 351 int i;
352 uint8_t * exp; 352 uint8_t * exp;
@@ -356,96 +356,96 @@ static void coeff_get (a52_state_t * state, sample_t * coeff,
356 sample_t factor[25]; 356 sample_t factor[25];
357 357
358 for (i = 0; i <= 24; i++) 358 for (i = 0; i <= 24; i++)
359 factor[i] = scale_factor[i] * level; 359 factor[i] = scale_factor[i] * level;
360#endif 360#endif
361 361
362 exp = expbap->exp; 362 exp = expbap->exp;
363 bap = expbap->bap; 363 bap = expbap->bap;
364 364
365 for (i = 0; i < end; i++) { 365 for (i = 0; i < end; i++) {
366 int bapi; 366 int bapi;
367 367
368 bapi = bap[i]; 368 bapi = bap[i];
369 switch (bapi) { 369 switch (bapi) {
370 case 0: 370 case 0:
371 if (dither) { 371 if (dither) {
372 COEFF (coeff[i], dither_gen (state), level, factor, exp[i]); 372 COEFF (coeff[i], dither_gen (state), level, factor, exp[i]);
373 continue; 373 continue;
374 } else { 374 } else {
375 coeff[i] = 0; 375 coeff[i] = 0;
376 continue; 376 continue;
377 } 377 }
378 378
379 case -1: 379 case -1:
380 if (quant->q1_ptr >= 0) { 380 if (quant->q1_ptr >= 0) {
381 COEFF (coeff[i], quant->q1[quant->q1_ptr--], level, 381 COEFF (coeff[i], quant->q1[quant->q1_ptr--], level,
382 factor, exp[i]); 382 factor, exp[i]);
383 continue; 383 continue;
384 } else { 384 } else {
385 int code; 385 int code;
386 386
387 code = bitstream_get (state, 5); 387 code = bitstream_get (state, 5);
388 388
389 quant->q1_ptr = 1; 389 quant->q1_ptr = 1;
390 quant->q1[0] = q_1_2[code]; 390 quant->q1[0] = q_1_2[code];
391 quant->q1[1] = q_1_1[code]; 391 quant->q1[1] = q_1_1[code];
392 COEFF (coeff[i], q_1_0[code], level, factor, exp[i]); 392 COEFF (coeff[i], q_1_0[code], level, factor, exp[i]);
393 continue; 393 continue;
394 } 394 }
395 395
396 case -2: 396 case -2:
397 if (quant->q2_ptr >= 0) { 397 if (quant->q2_ptr >= 0) {
398 COEFF (coeff[i], quant->q2[quant->q2_ptr--], level, 398 COEFF (coeff[i], quant->q2[quant->q2_ptr--], level,
399 factor, exp[i]); 399 factor, exp[i]);
400 continue; 400 continue;
401 } else { 401 } else {
402 int code; 402 int code;
403 403
404 code = bitstream_get (state, 7); 404 code = bitstream_get (state, 7);
405 405
406 quant->q2_ptr = 1; 406 quant->q2_ptr = 1;
407 quant->q2[0] = q_2_2[code]; 407 quant->q2[0] = q_2_2[code];
408 quant->q2[1] = q_2_1[code]; 408 quant->q2[1] = q_2_1[code];
409 COEFF (coeff[i], q_2_0[code], level, factor, exp[i]); 409 COEFF (coeff[i], q_2_0[code], level, factor, exp[i]);
410 continue; 410 continue;
411 } 411 }
412 412
413 case 3: 413 case 3:
414 COEFF (coeff[i], q_3[bitstream_get (state, 3)], level, 414 COEFF (coeff[i], q_3[bitstream_get (state, 3)], level,
415 factor, exp[i]); 415 factor, exp[i]);
416 continue; 416 continue;
417 417
418 case -3: 418 case -3:
419 if (quant->q4_ptr == 0) { 419 if (quant->q4_ptr == 0) {
420 quant->q4_ptr = -1; 420 quant->q4_ptr = -1;
421 COEFF (coeff[i], quant->q4, level, factor, exp[i]); 421 COEFF (coeff[i], quant->q4, level, factor, exp[i]);
422 continue; 422 continue;
423 } else { 423 } else {
424 int code; 424 int code;
425 425
426 code = bitstream_get (state, 7); 426 code = bitstream_get (state, 7);
427 427
428 quant->q4_ptr = 0; 428 quant->q4_ptr = 0;
429 quant->q4 = q_4_1[code]; 429 quant->q4 = q_4_1[code];
430 COEFF (coeff[i], q_4_0[code], level, factor, exp[i]); 430 COEFF (coeff[i], q_4_0[code], level, factor, exp[i]);
431 continue; 431 continue;
432 } 432 }
433 433
434 case 4: 434 case 4:
435 COEFF (coeff[i], q_5[bitstream_get (state, 4)], level, 435 COEFF (coeff[i], q_5[bitstream_get (state, 4)], level,
436 factor, exp[i]); 436 factor, exp[i]);
437 continue; 437 continue;
438 438
439 default: 439 default:
440 COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi), 440 COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi),
441 level, factor, exp[i]); 441 level, factor, exp[i]);
442 } 442 }
443 } 443 }
444} 444}
445 445
446static void coeff_get_coupling (a52_state_t * state, int nfchans, 446static void coeff_get_coupling (a52_state_t * state, int nfchans,
447 level_t * coeff, sample_t (* samples)[256], 447 level_t * coeff, sample_t (* samples)[256],
448 quantizer_set_t * quant, uint8_t dithflag[5]) 448 quantizer_set_t * quant, uint8_t dithflag[5])
449{ 449{
450 int cplbndstrc, bnd, i, i_end, ch; 450 int cplbndstrc, bnd, i, i_end, ch;
451 uint8_t * exp; 451 uint8_t * exp;
@@ -458,111 +458,111 @@ static void coeff_get_coupling (a52_state_t * state, int nfchans,
458 cplbndstrc = state->cplbndstrc; 458 cplbndstrc = state->cplbndstrc;
459 i = state->cplstrtmant; 459 i = state->cplstrtmant;
460 while (i < state->cplendmant) { 460 while (i < state->cplendmant) {
461 i_end = i + 12; 461 i_end = i + 12;
462 while (cplbndstrc & 1) { 462 while (cplbndstrc & 1) {
463 cplbndstrc >>= 1; 463 cplbndstrc >>= 1;
464 i_end += 12; 464 i_end += 12;
465 } 465 }
466 cplbndstrc >>= 1; 466 cplbndstrc >>= 1;
467 for (ch = 0; ch < nfchans; ch++) 467 for (ch = 0; ch < nfchans; ch++)
468 cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]); 468 cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]);
469 bnd++; 469 bnd++;
470 470
471 while (i < i_end) { 471 while (i < i_end) {
472 quantizer_t cplcoeff; 472 quantizer_t cplcoeff;
473 int bapi; 473 int bapi;
474 474
475 bapi = bap[i]; 475 bapi = bap[i];
476 switch (bapi) { 476 switch (bapi) {
477 case 0: 477 case 0:
478 for (ch = 0; ch < nfchans; ch++) 478 for (ch = 0; ch < nfchans; ch++)
479 if ((state->chincpl >> ch) & 1) { 479 if ((state->chincpl >> ch) & 1) {
480 if (dithflag[ch]) 480 if (dithflag[ch])
481#ifndef LIBA52_FIXED 481#ifndef LIBA52_FIXED
482 samples[ch][i] = (scale_factor[exp[i]] * 482 samples[ch][i] = (scale_factor[exp[i]] *
483 cplco[ch] * dither_gen (state)); 483 cplco[ch] * dither_gen (state));
484#else 484#else
485 COEFF (samples[ch][i], dither_gen (state), 485 COEFF (samples[ch][i], dither_gen (state),
486 cplco[ch], scale_factor, exp[i]); 486 cplco[ch], scale_factor, exp[i]);
487#endif 487#endif
488 else 488 else
489 samples[ch][i] = 0; 489 samples[ch][i] = 0;
490 } 490 }
491 i++; 491 i++;
492 continue; 492 continue;
493 493
494 case -1: 494 case -1:
495 if (quant->q1_ptr >= 0) { 495 if (quant->q1_ptr >= 0) {
496 cplcoeff = quant->q1[quant->q1_ptr--]; 496 cplcoeff = quant->q1[quant->q1_ptr--];
497 break; 497 break;
498 } else { 498 } else {
499 int code; 499 int code;
500 500
501 code = bitstream_get (state, 5); 501 code = bitstream_get (state, 5);
502 502
503 quant->q1_ptr = 1; 503 quant->q1_ptr = 1;
504 quant->q1[0] = q_1_2[code]; 504 quant->q1[0] = q_1_2[code];
505 quant->q1[1] = q_1_1[code]; 505 quant->q1[1] = q_1_1[code];
506 cplcoeff = q_1_0[code]; 506 cplcoeff = q_1_0[code];
507 break; 507 break;
508 } 508 }
509 509
510 case -2: 510 case -2:
511 if (quant->q2_ptr >= 0) { 511 if (quant->q2_ptr >= 0) {
512 cplcoeff = quant->q2[quant->q2_ptr--]; 512 cplcoeff = quant->q2[quant->q2_ptr--];
513 break; 513 break;
514 } else { 514 } else {
515 int code; 515 int code;
516 516
517 code = bitstream_get (state, 7); 517 code = bitstream_get (state, 7);
518 518
519 quant->q2_ptr = 1; 519 quant->q2_ptr = 1;
520 quant->q2[0] = q_2_2[code]; 520 quant->q2[0] = q_2_2[code];
521 quant->q2[1] = q_2_1[code]; 521 quant->q2[1] = q_2_1[code];
522 cplcoeff = q_2_0[code]; 522 cplcoeff = q_2_0[code];
523 break; 523 break;
524 } 524 }
525 525
526 case 3: 526 case 3:
527 cplcoeff = q_3[bitstream_get (state, 3)]; 527 cplcoeff = q_3[bitstream_get (state, 3)];
528 break; 528 break;
529 529
530 case -3: 530 case -3:
531 if (quant->q4_ptr == 0) { 531 if (quant->q4_ptr == 0) {
532 quant->q4_ptr = -1; 532 quant->q4_ptr = -1;
533 cplcoeff = quant->q4; 533 cplcoeff = quant->q4;
534 break; 534 break;
535 } else { 535 } else {
536 int code; 536 int code;
537 537
538 code = bitstream_get (state, 7); 538 code = bitstream_get (state, 7);
539 539
540 quant->q4_ptr = 0; 540 quant->q4_ptr = 0;
541 quant->q4 = q_4_1[code]; 541 quant->q4 = q_4_1[code];
542 cplcoeff = q_4_0[code]; 542 cplcoeff = q_4_0[code];
543 break; 543 break;
544 } 544 }
545 545
546 case 4: 546 case 4:
547 cplcoeff = q_5[bitstream_get (state, 4)]; 547 cplcoeff = q_5[bitstream_get (state, 4)];
548 break; 548 break;
549 549
550 default: 550 default:
551 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi); 551 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
552 } 552 }
553#ifndef LIBA52_FIXED 553#ifndef LIBA52_FIXED
554 cplcoeff *= scale_factor[exp[i]]; 554 cplcoeff *= scale_factor[exp[i]];
555#endif 555#endif
556 for (ch = 0; ch < nfchans; ch++) 556 for (ch = 0; ch < nfchans; ch++)
557 if ((state->chincpl >> ch) & 1) 557 if ((state->chincpl >> ch) & 1)
558#ifndef LIBA52_FIXED 558#ifndef LIBA52_FIXED
559 samples[ch][i] = cplcoeff * cplco[ch]; 559 samples[ch][i] = cplcoeff * cplco[ch];
560#else 560#else
561 COEFF (samples[ch][i], cplcoeff, cplco[ch], 561 COEFF (samples[ch][i], cplcoeff, cplco[ch],
562 scale_factor, exp[i]); 562 scale_factor, exp[i]);
563#endif 563#endif
564 i++; 564 i++;
565 } 565 }
566 } 566 }
567} 567}
568 568
@@ -581,366 +581,366 @@ int a52_block (a52_state_t * state)
581 nfchans = nfchans_tbl[state->acmod]; 581 nfchans = nfchans_tbl[state->acmod];
582 582
583 for (i = 0; i < nfchans; i++) 583 for (i = 0; i < nfchans; i++)
584 blksw[i] = bitstream_get (state, 1); 584 blksw[i] = bitstream_get (state, 1);
585 585
586 for (i = 0; i < nfchans; i++) 586 for (i = 0; i < nfchans; i++)
587 dithflag[i] = bitstream_get (state, 1); 587 dithflag[i] = bitstream_get (state, 1);
588 588
589 chaninfo = !state->acmod; 589 chaninfo = !state->acmod;
590 do { 590 do {
591 if (bitstream_get (state, 1)) { /* dynrnge */ 591 if (bitstream_get (state, 1)) { /* dynrnge */
592 int dynrng; 592 int dynrng;
593 593
594 dynrng = bitstream_get_2 (state, 8); 594 dynrng = bitstream_get_2 (state, 8);
595 if (state->dynrnge) { 595 if (state->dynrnge) {
596 level_t range; 596 level_t range;
597 597
598#if !defined(LIBA52_FIXED) 598#if !defined(LIBA52_FIXED)
599 range = ((((dynrng & 0x1f) | 0x20) << 13) * 599 range = ((((dynrng & 0x1f) | 0x20) << 13) *
600 scale_factor[3 - (dynrng >> 5)]); 600 scale_factor[3 - (dynrng >> 5)]);
601#else 601#else
602 range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5)); 602 range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5));
603#endif 603#endif
604 if (state->dynrngcall) 604 if (state->dynrngcall)
605 range = state->dynrngcall (range, state->dynrngdata); 605 range = state->dynrngcall (range, state->dynrngdata);
606 state->dynrng = MUL_L (state->level, range); 606 state->dynrng = MUL_L (state->level, range);
607 } 607 }
608 } 608 }
609 } while (chaninfo--); 609 } while (chaninfo--);
610 610
611 if (bitstream_get (state, 1)) { /* cplstre */ 611 if (bitstream_get (state, 1)) { /* cplstre */
612 state->chincpl = 0; 612 state->chincpl = 0;
613 if (bitstream_get (state, 1)) { /* cplinu */ 613 if (bitstream_get (state, 1)) { /* cplinu */
614 static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44, 614 static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
615 45, 45, 46, 46, 47, 47, 48, 48}; 615 45, 45, 46, 46, 47, 47, 48, 48};
616 int cplbegf; 616 int cplbegf;
617 int cplendf; 617 int cplendf;
618 int ncplsubnd; 618 int ncplsubnd;
619 619
620 for (i = 0; i < nfchans; i++) 620 for (i = 0; i < nfchans; i++)
621 state->chincpl |= bitstream_get (state, 1) << i; 621 state->chincpl |= bitstream_get (state, 1) << i;
622 switch (state->acmod) { 622 switch (state->acmod) {
623 case 0: case 1: 623 case 0: case 1:
624 return 1; 624 return 1;
625 case 2: 625 case 2:
626 state->phsflginu = bitstream_get (state, 1); 626 state->phsflginu = bitstream_get (state, 1);
627 } 627 }
628 cplbegf = bitstream_get (state, 4); 628 cplbegf = bitstream_get (state, 4);
629 cplendf = bitstream_get (state, 4); 629 cplendf = bitstream_get (state, 4);
630 630
631 if (cplendf + 3 - cplbegf < 0) 631 if (cplendf + 3 - cplbegf < 0)
632 return 1; 632 return 1;
633 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf; 633 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
634 state->cplstrtbnd = bndtab[cplbegf]; 634 state->cplstrtbnd = bndtab[cplbegf];
635 state->cplstrtmant = cplbegf * 12 + 37; 635 state->cplstrtmant = cplbegf * 12 + 37;
636 state->cplendmant = cplendf * 12 + 73; 636 state->cplendmant = cplendf * 12 + 73;
637 637
638 state->cplbndstrc = 0; 638 state->cplbndstrc = 0;
639 for (i = 0; i < ncplsubnd - 1; i++) 639 for (i = 0; i < ncplsubnd - 1; i++)
640 if (bitstream_get (state, 1)) { 640 if (bitstream_get (state, 1)) {
641 state->cplbndstrc |= 1 << i; 641 state->cplbndstrc |= 1 << i;
642 state->ncplbnd--; 642 state->ncplbnd--;
643 } 643 }
644 } 644 }
645 } 645 }
646 646
647 if (state->chincpl) { /* cplinu */ 647 if (state->chincpl) { /* cplinu */
648 int j, cplcoe; 648 int j, cplcoe;
649 649
650 cplcoe = 0; 650 cplcoe = 0;
651 for (i = 0; i < nfchans; i++) 651 for (i = 0; i < nfchans; i++)
652 if ((state->chincpl) >> i & 1) 652 if ((state->chincpl) >> i & 1)
653 if (bitstream_get (state, 1)) { /* cplcoe */ 653 if (bitstream_get (state, 1)) { /* cplcoe */
654 int mstrcplco, cplcoexp, cplcomant; 654 int mstrcplco, cplcoexp, cplcomant;
655 655
656 cplcoe = 1; 656 cplcoe = 1;
657 mstrcplco = 3 * bitstream_get (state, 2); 657 mstrcplco = 3 * bitstream_get (state, 2);
658 for (j = 0; j < state->ncplbnd; j++) { 658 for (j = 0; j < state->ncplbnd; j++) {
659 cplcoexp = bitstream_get (state, 4); 659 cplcoexp = bitstream_get (state, 4);
660 cplcomant = bitstream_get (state, 4); 660 cplcomant = bitstream_get (state, 4);
661 if (cplcoexp == 15) 661 if (cplcoexp == 15)
662 cplcomant <<= 14; 662 cplcomant <<= 14;
663 else 663 else
664 cplcomant = (cplcomant | 0x10) << 13; 664 cplcomant = (cplcomant | 0x10) << 13;
665#ifndef LIBA52_FIXED 665#ifndef LIBA52_FIXED
666 state->cplco[i][j] = 666 state->cplco[i][j] =
667 cplcomant * scale_factor[cplcoexp + mstrcplco]; 667 cplcomant * scale_factor[cplcoexp + mstrcplco];
668#else 668#else
669 state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco); 669 state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco);
670#endif 670#endif
671 671
672 } 672 }
673 } 673 }
674 if ((state->acmod == 2) && state->phsflginu && cplcoe) 674 if ((state->acmod == 2) && state->phsflginu && cplcoe)
675 for (j = 0; j < state->ncplbnd; j++) 675 for (j = 0; j < state->ncplbnd; j++)
676 if (bitstream_get (state, 1)) /* phsflg */ 676 if (bitstream_get (state, 1)) /* phsflg */
677 state->cplco[1][j] = -state->cplco[1][j]; 677 state->cplco[1][j] = -state->cplco[1][j];
678 } 678 }
679 679
680 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */ 680 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
681 int end; 681 int end;
682 682
683 state->rematflg = 0; 683 state->rematflg = 0;
684 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */ 684 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
685 i = 0; 685 i = 0;
686 do 686 do
687 state->rematflg |= bitstream_get (state, 1) << i; 687 state->rematflg |= bitstream_get (state, 1) << i;
688 while (rematrix_band[i++] < end); 688 while (rematrix_band[i++] < end);
689 } 689 }
690 690
691 cplexpstr = EXP_REUSE; 691 cplexpstr = EXP_REUSE;
692 lfeexpstr = EXP_REUSE; 692 lfeexpstr = EXP_REUSE;
693 if (state->chincpl) /* cplinu */ 693 if (state->chincpl) /* cplinu */
694 cplexpstr = bitstream_get (state, 2); 694 cplexpstr = bitstream_get (state, 2);
695 for (i = 0; i < nfchans; i++) 695 for (i = 0; i < nfchans; i++)
696 chexpstr[i] = bitstream_get (state, 2); 696 chexpstr[i] = bitstream_get (state, 2);
697 if (state->lfeon) 697 if (state->lfeon)
698 lfeexpstr = bitstream_get (state, 1); 698 lfeexpstr = bitstream_get (state, 1);
699 699
700 for (i = 0; i < nfchans; i++) 700 for (i = 0; i < nfchans; i++)
701 if (chexpstr[i] != EXP_REUSE) { 701 if (chexpstr[i] != EXP_REUSE) {
702 if ((state->chincpl >> i) & 1) 702 if ((state->chincpl >> i) & 1)
703 state->endmant[i] = state->cplstrtmant; 703 state->endmant[i] = state->cplstrtmant;
704 else { 704 else {
705 int chbwcod; 705 int chbwcod;
706 706
707 chbwcod = bitstream_get (state, 6); 707 chbwcod = bitstream_get (state, 6);
708 if (chbwcod > 60) 708 if (chbwcod > 60)
709 return 1; 709 return 1;
710 state->endmant[i] = chbwcod * 3 + 73; 710 state->endmant[i] = chbwcod * 3 + 73;
711 } 711 }
712 } 712 }
713 713
714 do_bit_alloc = 0; 714 do_bit_alloc = 0;
715 715
716 if (cplexpstr != EXP_REUSE) { 716 if (cplexpstr != EXP_REUSE) {
717 int cplabsexp, ncplgrps; 717 int cplabsexp, ncplgrps;
718 718
719 do_bit_alloc = 64; 719 do_bit_alloc = 64;
720 ncplgrps = ((state->cplendmant - state->cplstrtmant) / 720 ncplgrps = ((state->cplendmant - state->cplstrtmant) /
721 (3 << (cplexpstr - 1))); 721 (3 << (cplexpstr - 1)));
722 cplabsexp = bitstream_get (state, 4) << 1; 722 cplabsexp = bitstream_get (state, 4) << 1;
723 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp, 723 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
724 state->cpl_expbap.exp + state->cplstrtmant)) 724 state->cpl_expbap.exp + state->cplstrtmant))
725 return 1; 725 return 1;
726 } 726 }
727 for (i = 0; i < nfchans; i++) 727 for (i = 0; i < nfchans; i++)
728 if (chexpstr[i] != EXP_REUSE) { 728 if (chexpstr[i] != EXP_REUSE) {
729 int grp_size, nchgrps; 729 int grp_size, nchgrps;
730 730
731 do_bit_alloc |= 1 << i; 731 do_bit_alloc |= 1 << i;
732 grp_size = 3 << (chexpstr[i] - 1); 732 grp_size = 3 << (chexpstr[i] - 1);
733 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size; 733 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
734 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4); 734 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
735 if (parse_exponents (state, chexpstr[i], nchgrps, 735 if (parse_exponents (state, chexpstr[i], nchgrps,
736 state->fbw_expbap[i].exp[0], 736 state->fbw_expbap[i].exp[0],
737 state->fbw_expbap[i].exp + 1)) 737 state->fbw_expbap[i].exp + 1))
738 return 1; 738 return 1;
739 bitstream_get (state, 2); /* gainrng */ 739 bitstream_get (state, 2); /* gainrng */
740 } 740 }
741 if (lfeexpstr != EXP_REUSE) { 741 if (lfeexpstr != EXP_REUSE) {
742 do_bit_alloc |= 32; 742 do_bit_alloc |= 32;
743 state->lfe_expbap.exp[0] = bitstream_get (state, 4); 743 state->lfe_expbap.exp[0] = bitstream_get (state, 4);
744 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0], 744 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
745 state->lfe_expbap.exp + 1)) 745 state->lfe_expbap.exp + 1))
746 return 1; 746 return 1;
747 } 747 }
748 748
749 if (bitstream_get (state, 1)) { /* baie */ 749 if (bitstream_get (state, 1)) { /* baie */
750 do_bit_alloc = 127; 750 do_bit_alloc = 127;
751 state->bai = bitstream_get (state, 11); 751 state->bai = bitstream_get (state, 11);
752 } 752 }
753 if (bitstream_get (state, 1)) { /* snroffste */ 753 if (bitstream_get (state, 1)) { /* snroffste */
754 do_bit_alloc = 127; 754 do_bit_alloc = 127;
755 state->csnroffst = bitstream_get (state, 6); 755 state->csnroffst = bitstream_get (state, 6);
756 if (state->chincpl) /* cplinu */ 756 if (state->chincpl) /* cplinu */
757 state->cplba.bai = bitstream_get (state, 7); 757 state->cplba.bai = bitstream_get (state, 7);
758 for (i = 0; i < nfchans; i++) 758 for (i = 0; i < nfchans; i++)
759 state->ba[i].bai = bitstream_get (state, 7); 759 state->ba[i].bai = bitstream_get (state, 7);
760 if (state->lfeon) 760 if (state->lfeon)
761 state->lfeba.bai = bitstream_get (state, 7); 761 state->lfeba.bai = bitstream_get (state, 7);
762 } 762 }
763 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */ 763 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
764 do_bit_alloc |= 64; 764 do_bit_alloc |= 64;
765 state->cplfleak = 9 - bitstream_get (state, 3); 765 state->cplfleak = 9 - bitstream_get (state, 3);
766 state->cplsleak = 9 - bitstream_get (state, 3); 766 state->cplsleak = 9 - bitstream_get (state, 3);
767 } 767 }
768 768
769 if (bitstream_get (state, 1)) { /* deltbaie */ 769 if (bitstream_get (state, 1)) { /* deltbaie */
770 do_bit_alloc = 127; 770 do_bit_alloc = 127;
771 if (state->chincpl) /* cplinu */ 771 if (state->chincpl) /* cplinu */
772 state->cplba.deltbae = bitstream_get (state, 2); 772 state->cplba.deltbae = bitstream_get (state, 2);
773 for (i = 0; i < nfchans; i++) 773 for (i = 0; i < nfchans; i++)
774 state->ba[i].deltbae = bitstream_get (state, 2); 774 state->ba[i].deltbae = bitstream_get (state, 2);
775 if (state->chincpl && /* cplinu */ 775 if (state->chincpl && /* cplinu */
776 (state->cplba.deltbae == DELTA_BIT_NEW) && 776 (state->cplba.deltbae == DELTA_BIT_NEW) &&
777 parse_deltba (state, state->cplba.deltba)) 777 parse_deltba (state, state->cplba.deltba))
778 return 1; 778 return 1;
779 for (i = 0; i < nfchans; i++) 779 for (i = 0; i < nfchans; i++)
780 if ((state->ba[i].deltbae == DELTA_BIT_NEW) && 780 if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
781 parse_deltba (state, state->ba[i].deltba)) 781 parse_deltba (state, state->ba[i].deltba))
782 return 1; 782 return 1;
783 } 783 }
784 784
785 if (do_bit_alloc) { 785 if (do_bit_alloc) {
786 if (zero_snr_offsets (nfchans, state)) { 786 if (zero_snr_offsets (nfchans, state)) {
787 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap)); 787 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap));
788 for (i = 0; i < nfchans; i++) 788 for (i = 0; i < nfchans; i++)
789 memset (state->fbw_expbap[i].bap, 0, 789 memset (state->fbw_expbap[i].bap, 0,
790 sizeof (state->fbw_expbap[i].bap)); 790 sizeof (state->fbw_expbap[i].bap));
791 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap)); 791 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap));
792 } else { 792 } else {
793 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */ 793 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */
794 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd, 794 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd,
795 state->cplstrtmant, state->cplendmant, 795 state->cplstrtmant, state->cplendmant,
796 state->cplfleak << 8, state->cplsleak << 8, 796 state->cplfleak << 8, state->cplsleak << 8,
797 &state->cpl_expbap); 797 &state->cpl_expbap);
798 for (i = 0; i < nfchans; i++) 798 for (i = 0; i < nfchans; i++)
799 if (do_bit_alloc & (1 << i)) 799 if (do_bit_alloc & (1 << i))
800 a52_bit_allocate (state, state->ba + i, 0, 0, 800 a52_bit_allocate (state, state->ba + i, 0, 0,
801 state->endmant[i], 0, 0, 801 state->endmant[i], 0, 0,
802 state->fbw_expbap +i); 802 state->fbw_expbap +i);
803 if (state->lfeon && (do_bit_alloc & 32)) { 803 if (state->lfeon && (do_bit_alloc & 32)) {
804 state->lfeba.deltbae = DELTA_BIT_NONE; 804 state->lfeba.deltbae = DELTA_BIT_NONE;
805 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0, 805 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
806 &state->lfe_expbap); 806 &state->lfe_expbap);
807 } 807 }
808 } 808 }
809 } 809 }
810 810
811 if (bitstream_get (state, 1)) { /* skiple */ 811 if (bitstream_get (state, 1)) { /* skiple */
812 i = bitstream_get (state, 9); /* skipl */ 812 i = bitstream_get (state, 9); /* skipl */
813 while (i--) 813 while (i--)
814 bitstream_get (state, 8); 814 bitstream_get (state, 8);
815 } 815 }
816 816
817 samples = state->samples; 817 samples = state->samples;
818 if (state->output & A52_LFE) 818 if (state->output & A52_LFE)
819 samples += 256; /* shift for LFE channel */ 819 samples += 256; /* shift for LFE channel */
820 820
821 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output, 821 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
822 state->dynrng, state->clev, state->slev); 822 state->dynrng, state->clev, state->slev);
823 823
824 quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1; 824 quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1;
825 done_cpl = 0; 825 done_cpl = 0;
826 826
827 for (i = 0; i < nfchans; i++) { 827 for (i = 0; i < nfchans; i++) {
828 int j; 828 int j;
829 829
830 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant, 830 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant,
831 coeff[i], dithflag[i], state->endmant[i]); 831 coeff[i], dithflag[i], state->endmant[i]);
832 832
833 if ((state->chincpl >> i) & 1) { 833 if ((state->chincpl >> i) & 1) {
834 if (!done_cpl) { 834 if (!done_cpl) {
835 done_cpl = 1; 835 done_cpl = 1;
836 coeff_get_coupling (state, nfchans, coeff, 836 coeff_get_coupling (state, nfchans, coeff,
837 (sample_t (*)[256])samples, &quant, 837 (sample_t (*)[256])samples, &quant,
838 dithflag); 838 dithflag);
839 } 839 }
840 j = state->cplendmant; 840 j = state->cplendmant;
841 } else 841 } else
842 j = state->endmant[i]; 842 j = state->endmant[i];
843 do 843 do
844 (samples + 256 * i)[j] = 0; 844 (samples + 256 * i)[j] = 0;
845 while (++j < 256); 845 while (++j < 256);
846 } 846 }
847 847
848 if (state->acmod == 2) { 848 if (state->acmod == 2) {
849 int j, end, band, rematflg; 849 int j, end, band, rematflg;
850 850
851 end = ((state->endmant[0] < state->endmant[1]) ? 851 end = ((state->endmant[0] < state->endmant[1]) ?
852 state->endmant[0] : state->endmant[1]); 852 state->endmant[0] : state->endmant[1]);
853 853
854 i = 0; 854 i = 0;
855 j = 13; 855 j = 13;
856 rematflg = state->rematflg; 856 rematflg = state->rematflg;
857 do { 857 do {
858 if (! (rematflg & 1)) { 858 if (! (rematflg & 1)) {
859 rematflg >>= 1; 859 rematflg >>= 1;
860 j = rematrix_band[i++]; 860 j = rematrix_band[i++];
861 continue; 861 continue;
862 } 862 }
863 rematflg >>= 1; 863 rematflg >>= 1;
864 band = rematrix_band[i++]; 864 band = rematrix_band[i++];
865 if (band > end) 865 if (band > end)
866 band = end; 866 band = end;
867 do { 867 do {
868 sample_t tmp0, tmp1; 868 sample_t tmp0, tmp1;
869 869
870 tmp0 = samples[j]; 870 tmp0 = samples[j];
871 tmp1 = (samples+256)[j]; 871 tmp1 = (samples+256)[j];
872 samples[j] = tmp0 + tmp1; 872 samples[j] = tmp0 + tmp1;
873 (samples+256)[j] = tmp0 - tmp1; 873 (samples+256)[j] = tmp0 - tmp1;
874 } while (++j < band); 874 } while (++j < band);
875 } while (j < end); 875 } while (j < end);
876 } 876 }
877 877
878 if (state->lfeon) { 878 if (state->lfeon) {
879 if (state->output & A52_LFE) { 879 if (state->output & A52_LFE) {
880 coeff_get (state, samples - 256, &state->lfe_expbap, &quant, 880 coeff_get (state, samples - 256, &state->lfe_expbap, &quant,
881 state->dynrng, 0, 7); 881 state->dynrng, 0, 7);
882 for (i = 7; i < 256; i++) 882 for (i = 7; i < 256; i++)
883 (samples-256)[i] = 0; 883 (samples-256)[i] = 0;
884 a52_imdct_512 (samples - 256, samples + 1536 - 256); 884 a52_imdct_512 (samples - 256, samples + 1536 - 256);
885 } else { 885 } else {
886 /* just skip the LFE coefficients */ 886 /* just skip the LFE coefficients */
887 coeff_get (state, samples + 1280, &state->lfe_expbap, &quant, 887 coeff_get (state, samples + 1280, &state->lfe_expbap, &quant,
888 0, 0, 7); 888 0, 0, 7);
889 } 889 }
890 } 890 }
891 891
892 i = 0; 892 i = 0;
893 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans) 893 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans)
894 for (i = 1; i < nfchans; i++) 894 for (i = 1; i < nfchans; i++)
895 if (blksw[i] != blksw[0]) 895 if (blksw[i] != blksw[0])
896 break; 896 break;
897 897
898 if (i < nfchans) { 898 if (i < nfchans) {
899 if (state->downmixed) { 899 if (state->downmixed) {
900 state->downmixed = 0; 900 state->downmixed = 0;
901 a52_upmix (samples + 1536, state->acmod, state->output); 901 a52_upmix (samples + 1536, state->acmod, state->output);
902 } 902 }
903 903
904 for (i = 0; i < nfchans; i++) { 904 for (i = 0; i < nfchans; i++) {
905 sample_t bias; 905 sample_t bias;
906 906
907 bias = 0; 907 bias = 0;
908 if (!(chanbias & (1 << i))) 908 if (!(chanbias & (1 << i)))
909 bias = state->bias; 909 bias = state->bias;
910 910
911 if (coeff[i]) { 911 if (coeff[i]) {
912 if (blksw[i]) 912 if (blksw[i])
913 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i); 913 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i);
914 else 914 else
915 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i); 915 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i);
916 } else { 916 } else {
917 int j; 917 int j;
918 918
919 for (j = 0; j < 256; j++) 919 for (j = 0; j < 256; j++)
920 (samples + 256 * i)[j] = bias; 920 (samples + 256 * i)[j] = bias;
921 } 921 }
922 } 922 }
923 923
924 a52_downmix (samples, state->acmod, state->output, 924 a52_downmix (samples, state->acmod, state->output,
925 state->clev, state->slev); 925 state->clev, state->slev);
926 } else { 926 } else {
927 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK]; 927 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK];
928 928
929 a52_downmix (samples, state->acmod, state->output, 929 a52_downmix (samples, state->acmod, state->output,
930 state->clev, state->slev); 930 state->clev, state->slev);
931 931
932 if (!state->downmixed) { 932 if (!state->downmixed) {
933 state->downmixed = 1; 933 state->downmixed = 1;
934 a52_downmix (samples + 1536, state->acmod, state->output, 934 a52_downmix (samples + 1536, state->acmod, state->output,
935 state->clev, state->slev); 935 state->clev, state->slev);
936 } 936 }
937 937
938 if (blksw[0]) 938 if (blksw[0])
939 for (i = 0; i < nfchans; i++) 939 for (i = 0; i < nfchans; i++)
940 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i); 940 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i);
941 else 941 else
942 for (i = 0; i < nfchans; i++) 942 for (i = 0; i < nfchans; i++)
943 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i); 943 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i);
944 } 944 }
945 945
946 return 0; 946 return 0;