0
|
1 /*
|
|
2 * parse.c
|
|
3 *
|
|
4 * Copyright (C) Aaron Holtzman - May 1999
|
|
5 *
|
|
6 * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
|
|
7 *
|
|
8 * ac3dec is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2, or (at your option)
|
|
11 * any later version.
|
|
12 *
|
|
13 * ac3dec is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with GNU Make; see the file COPYING. If not, write to
|
|
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
21 *
|
|
22 *
|
|
23 */
|
|
24
|
64
|
25 #include "../common.h"
|
0
|
26 #include "ac3.h"
|
|
27 #include "ac3_internal.h"
|
|
28
|
|
29 #include "bitstream.h"
|
|
30 #include "tables.h"
|
|
31
|
|
32 extern stream_samples_t samples; // FIXME
|
|
33 static float delay[6][256];
|
|
34
|
|
35 void ac3_init (void)
|
|
36 {
|
|
37 imdct_init ();
|
|
38 }
|
|
39
|
|
40 static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
|
|
41
|
|
42 int ac3_syncinfo (uint8_t * buf, int * flags,
|
|
43 int * sample_rate, int * bit_rate)
|
|
44 {
|
|
45 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
|
|
46 128, 160, 192, 224, 256, 320, 384, 448,
|
|
47 512, 576, 640};
|
|
48 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
|
|
49 int frmsizecod;
|
|
50 int bitrate;
|
|
51 int half;
|
|
52 int acmod;
|
|
53
|
|
54 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) // syncword
|
|
55 return 0;
|
|
56
|
|
57 if (buf[5] >= 0x60) // bsid >= 12
|
|
58 return 0;
|
|
59 half = halfrate[buf[5] >> 3];
|
|
60
|
|
61 // acmod, dsurmod and lfeon
|
|
62 acmod = buf[6] >> 5;
|
|
63 *flags = (((buf[6] & 0xf8) == 0x50) ? AC3_DOLBY : acmod) |
|
|
64 ((buf[6] & lfeon[acmod]) ? AC3_LFE : 0);
|
|
65
|
|
66 frmsizecod = buf[4] & 63;
|
|
67 if (frmsizecod >= 38)
|
|
68 return 0;
|
|
69 bitrate = rate [frmsizecod >> 1];
|
|
70 *bit_rate = (bitrate * 1000) >> half;
|
|
71
|
|
72 switch (buf[4] & 0xc0) {
|
|
73 case 0: // 48 KHz
|
|
74 *sample_rate = 48000 >> half;
|
|
75 return 4 * bitrate;
|
|
76 case 0x40:
|
|
77 *sample_rate = 44100 >> half;
|
|
78 return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
|
|
79 case 0x80:
|
|
80 *sample_rate = 32000 >> half;
|
|
81 return 6 * bitrate;
|
|
82 default:
|
|
83 return 0;
|
|
84 }
|
|
85 }
|
|
86
|
|
87 int ac3_frame (ac3_state_t * state, uint8_t * buf, int * flags, float * level,
|
|
88 float bias)
|
|
89 {
|
|
90 static float clev[4] = {LEVEL_3DB, LEVEL_45DB, LEVEL_6DB, LEVEL_45DB};
|
|
91 static float slev[4] = {LEVEL_3DB, LEVEL_6DB, 0, LEVEL_6DB};
|
|
92 int chaninfo;
|
|
93 int acmod;
|
|
94
|
|
95 state->fscod = buf[4] >> 6;
|
|
96 state->halfrate = halfrate[buf[5] >> 3];
|
|
97 state->acmod = acmod = buf[6] >> 5;
|
|
98
|
|
99 bitstream_set_ptr (buf + 6);
|
|
100 bitstream_get (3); // skip acmod we already parsed
|
|
101
|
|
102 if ((acmod == 2) && (bitstream_get (2) == 2)) // dsurmod
|
|
103 acmod = AC3_DOLBY;
|
|
104
|
|
105 if ((acmod & 1) && (acmod != 1))
|
|
106 state->clev = clev[bitstream_get (2)]; // cmixlev
|
|
107
|
|
108 if (acmod & 4)
|
|
109 state->slev = slev[bitstream_get (2)]; // surmixlev
|
|
110
|
|
111 state->lfeon = bitstream_get (1);
|
|
112
|
|
113 state->output = downmix_init (acmod, *flags, level,
|
|
114 state->clev, state->slev);
|
|
115 if (state->output < 0)
|
|
116 return 1;
|
|
117 *flags = state->output;
|
|
118 state->level = *level;
|
|
119 state->bias = bias;
|
|
120
|
|
121 chaninfo = !acmod;
|
|
122 do {
|
|
123 bitstream_get (5); // dialnorm
|
|
124 if (bitstream_get (1)) // compre
|
|
125 bitstream_get (8); // compr
|
|
126 if (bitstream_get (1)) // langcode
|
|
127 bitstream_get (8); // langcod
|
|
128 if (bitstream_get (1)) // audprodie
|
|
129 bitstream_get (7); // mixlevel + roomtyp
|
|
130 } while (chaninfo--);
|
|
131
|
|
132 bitstream_get (2); // copyrightb + origbs
|
|
133
|
|
134 if (bitstream_get (1)) // timecod1e
|
|
135 bitstream_get (14); // timecod1
|
|
136 if (bitstream_get (1)) // timecod2e
|
|
137 bitstream_get (14); // timecod2
|
|
138
|
|
139 if (bitstream_get (1)) { // addbsie
|
|
140 int addbsil;
|
|
141
|
|
142 addbsil = bitstream_get (6);
|
|
143 do {
|
|
144 bitstream_get (8); // addbsi
|
|
145 } while (addbsil--);
|
|
146 }
|
|
147
|
|
148 return 0;
|
|
149 }
|
|
150
|
|
151 static int parse_exponents (int expstr, int ngrps, uint8_t exponent,
|
|
152 uint8_t * dest)
|
|
153 {
|
|
154 int exps;
|
|
155
|
|
156 while (ngrps--) {
|
|
157 exps = bitstream_get (7);
|
|
158
|
|
159 exponent += exp_1[exps];
|
|
160 if (exponent > 24)
|
|
161 return 1;
|
|
162
|
|
163 switch (expstr) {
|
|
164 case EXP_D45:
|
|
165 *(dest++) = exponent;
|
|
166 *(dest++) = exponent;
|
|
167 case EXP_D25:
|
|
168 *(dest++) = exponent;
|
|
169 case EXP_D15:
|
|
170 *(dest++) = exponent;
|
|
171 }
|
|
172
|
|
173 exponent += exp_2[exps];
|
|
174 if (exponent > 24)
|
|
175 return 1;
|
|
176
|
|
177 switch (expstr) {
|
|
178 case EXP_D45:
|
|
179 *(dest++) = exponent;
|
|
180 *(dest++) = exponent;
|
|
181 case EXP_D25:
|
|
182 *(dest++) = exponent;
|
|
183 case EXP_D15:
|
|
184 *(dest++) = exponent;
|
|
185 }
|
|
186
|
|
187 exponent += exp_3[exps];
|
|
188 if (exponent > 24)
|
|
189 return 1;
|
|
190
|
|
191 switch (expstr) {
|
|
192 case EXP_D45:
|
|
193 *(dest++) = exponent;
|
|
194 *(dest++) = exponent;
|
|
195 case EXP_D25:
|
|
196 *(dest++) = exponent;
|
|
197 case EXP_D15:
|
|
198 *(dest++) = exponent;
|
|
199 }
|
|
200 }
|
|
201
|
|
202 return 0;
|
|
203 }
|
|
204
|
|
205 static int parse_deltba (int8_t * deltba)
|
|
206 {
|
|
207 int deltnseg, deltlen, delta, j;
|
|
208
|
|
209 memset (deltba, 0, 50);
|
|
210
|
|
211 deltnseg = bitstream_get (3);
|
|
212 j = 0;
|
|
213 do {
|
|
214 j += bitstream_get (5);
|
|
215 deltlen = bitstream_get (4);
|
|
216 delta = bitstream_get (3);
|
|
217 delta -= (delta >= 4) ? 3 : 4;
|
|
218 if (!deltlen)
|
|
219 continue;
|
|
220 if (j + deltlen >= 50)
|
|
221 return 1;
|
|
222 while (deltlen--)
|
|
223 deltba[j++] = delta;
|
|
224 } while (deltnseg--);
|
|
225
|
|
226 return 0;
|
|
227 }
|
|
228
|
|
229 static inline int zero_snr_offsets (int nfchans, ac3_state_t * state)
|
|
230 {
|
|
231 int i;
|
|
232
|
|
233 if ((state->csnroffst) || (state->cplinu && state->cplba.fsnroffst) ||
|
|
234 (state->lfeon && state->lfeba.fsnroffst))
|
|
235 return 0;
|
|
236 for (i = 0; i < nfchans; i++)
|
|
237 if (state->ba[i].fsnroffst)
|
|
238 return 0;
|
|
239 return 1;
|
|
240 }
|
|
241
|
|
242 static float q_1[2];
|
|
243 static float q_2[2];
|
|
244 static float q_4;
|
|
245 static int q_1_pointer;
|
|
246 static int q_2_pointer;
|
|
247 static int q_4_pointer;
|
|
248
|
|
249 #define GET_COEFF(COEFF,DITHER) \
|
|
250 switch (bap[i]) { \
|
|
251 case 0: \
|
|
252 DITHER (scale_factor[exp[i]]); \
|
|
253 \
|
|
254 case -1: \
|
|
255 if (q_1_pointer >= 0) { \
|
|
256 COEFF (q_1[q_1_pointer--] * scale_factor[exp[i]]); \
|
|
257 } else { \
|
|
258 int code; \
|
|
259 \
|
|
260 code = bitstream_get (5); \
|
|
261 \
|
|
262 q_1_pointer = 1; \
|
|
263 q_1[0] = q_1_2[code]; \
|
|
264 q_1[1] = q_1_1[code]; \
|
|
265 COEFF (q_1_0[code] * scale_factor[exp[i]]); \
|
|
266 } \
|
|
267 \
|
|
268 case -2: \
|
|
269 if (q_2_pointer >= 0) { \
|
|
270 COEFF (q_2[q_2_pointer--] * scale_factor[exp[i]]); \
|
|
271 } else { \
|
|
272 int code; \
|
|
273 \
|
|
274 code = bitstream_get (7); \
|
|
275 \
|
|
276 q_2_pointer = 1; \
|
|
277 q_2[0] = q_2_2[code]; \
|
|
278 q_2[1] = q_2_1[code]; \
|
|
279 COEFF (q_2_0[code] * scale_factor[exp[i]]); \
|
|
280 } \
|
|
281 \
|
|
282 case 3: \
|
|
283 COEFF (q_3[bitstream_get (3)] * scale_factor[exp[i]]); \
|
|
284 \
|
|
285 case -3: \
|
|
286 if (q_4_pointer == 0) { \
|
|
287 q_4_pointer = -1; \
|
|
288 COEFF (q_4 * scale_factor[exp[i]]); \
|
|
289 } else { \
|
|
290 int code; \
|
|
291 \
|
|
292 code = bitstream_get (7); \
|
|
293 \
|
|
294 q_4_pointer = 0; \
|
|
295 q_4 = q_4_1[code]; \
|
|
296 COEFF (q_4_0[code] * scale_factor[exp[i]]); \
|
|
297 } \
|
|
298 \
|
|
299 case 4: \
|
|
300 COEFF (q_5[bitstream_get (4)] * scale_factor[exp[i]]); \
|
|
301 \
|
|
302 default: \
|
|
303 COEFF (((int16_t)(bitstream_get(bap[i]) << (16 - bap[i]))) * \
|
|
304 scale_factor[exp[i]]); \
|
|
305 }
|
|
306
|
|
307 #define CHANNEL_COEFF(val) \
|
|
308 coeff[i++] = val; \
|
|
309 continue;
|
|
310
|
|
311 #define CHANNEL_DITHER(val) \
|
|
312 if (dither) { \
|
|
313 coeff[i++] = dither_gen () * val; \
|
|
314 continue; \
|
|
315 } else { \
|
|
316 coeff[i++] = 0; \
|
|
317 continue; \
|
|
318 }
|
|
319
|
|
320 static uint16_t lfsr_state = 1;
|
|
321
|
|
322 static inline int16_t dither_gen(void)
|
|
323 {
|
|
324 int16_t state;
|
|
325
|
|
326 state = dither_lut[lfsr_state >> 8] ^ (lfsr_state << 8);
|
|
327
|
|
328 lfsr_state = (uint16_t) state;
|
|
329
|
|
330 return ((state * (int) (LEVEL_3DB * 256)) >> 8);
|
|
331 }
|
|
332
|
|
333 static void coeff_get (float * coeff, uint8_t * exp, int8_t * bap,
|
|
334 int dither, int end)
|
|
335 {
|
|
336 int i;
|
|
337
|
|
338 i = 0;
|
|
339 while (i < end)
|
|
340 GET_COEFF (CHANNEL_COEFF, CHANNEL_DITHER);
|
|
341 }
|
|
342
|
|
343 #define COUPLING_COEFF(val) \
|
|
344 cplcoeff = val; \
|
|
345 break;
|
|
346
|
|
347 #define COUPLING_DITHER(val) \
|
|
348 cplcoeff = val; \
|
|
349 for (ch = 0; ch < nfchans; ch++) \
|
|
350 if (state->chincpl[ch]) { \
|
|
351 if (dithflag[ch]) \
|
|
352 samples[ch][i] = \
|
|
353 state->cplco[ch][bnd] * dither_gen () * cplcoeff; \
|
|
354 else \
|
|
355 samples[ch][i] = 0; \
|
|
356 } \
|
|
357 i++; \
|
|
358 continue;
|
|
359
|
|
360 int ac3_block (ac3_state_t * state)
|
|
361 {
|
|
362 static const uint8_t nfchans_tbl[8] = {2, 1, 2, 3, 3, 4, 4, 5};
|
|
363 static int rematrix_band[4] = {25, 37, 61, 253};
|
|
364 int i, nfchans, chaninfo;
|
|
365 uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl;
|
|
366 uint8_t blksw[5], dithflag[5];
|
|
367
|
|
368 nfchans = nfchans_tbl[state->acmod];
|
|
369
|
|
370 for (i = 0; i < nfchans; i++)
|
|
371 blksw[i] = bitstream_get (1);
|
|
372
|
|
373 for (i = 0; i < nfchans; i++)
|
|
374 dithflag[i] = bitstream_get (1);
|
|
375
|
|
376 chaninfo = !(state->acmod);
|
|
377 do {
|
|
378 if (bitstream_get (1)) // dynrnge
|
|
379 bitstream_get (8); // dynrng
|
|
380 } while (chaninfo--);
|
|
381
|
|
382 if (bitstream_get (1)) { // cplstre
|
|
383 state->cplinu = bitstream_get (1);
|
|
384 if (state->cplinu) {
|
|
385 static int bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
|
|
386 45, 45, 46, 46, 47, 47, 48, 48};
|
|
387 int cplbegf;
|
|
388 int cplendf;
|
|
389 int ncplsubnd;
|
|
390
|
|
391 for (i = 0; i < nfchans; i++)
|
|
392 state->chincpl[i] = bitstream_get (1);
|
|
393 switch (state->acmod) {
|
|
394 case 0: case 1:
|
|
395 return 1;
|
|
396 case 2:
|
|
397 state->phsflginu = bitstream_get (1);
|
|
398 }
|
|
399 cplbegf = bitstream_get (4);
|
|
400 cplendf = bitstream_get (4);
|
|
401
|
|
402 if (cplendf + 3 - cplbegf < 0)
|
|
403 return 1;
|
|
404 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
|
|
405 state->cplstrtbnd = bndtab[cplbegf];
|
|
406 state->cplstrtmant = cplbegf * 12 + 37;
|
|
407 state->cplendmant = cplendf * 12 + 73;
|
|
408
|
|
409 for (i = 0; i < ncplsubnd - 1; i++) {
|
|
410 state->cplbndstrc[i] = bitstream_get (1);
|
|
411 state->ncplbnd -= state->cplbndstrc[i];
|
|
412 }
|
|
413 state->cplbndstrc[i] = 0; // last value is a sentinel
|
|
414 }
|
|
415 }
|
|
416
|
|
417 if (state->cplinu) {
|
|
418 int j, cplcoe;
|
|
419
|
|
420 cplcoe = 0;
|
|
421 for (i = 0; i < nfchans; i++)
|
|
422 if (state->chincpl[i])
|
|
423 if (bitstream_get (1)) { // cplcoe
|
|
424 int mstrcplco, cplcoexp, cplcomant;
|
|
425
|
|
426 cplcoe = 1;
|
|
427 mstrcplco = 3 * bitstream_get (2);
|
|
428 for (j = 0; j < state->ncplbnd; j++) {
|
|
429 cplcoexp = bitstream_get (4);
|
|
430 cplcomant = bitstream_get (4);
|
|
431 if (cplcoexp == 15)
|
|
432 cplcomant <<= 14;
|
|
433 else
|
|
434 cplcomant = (cplcomant | 0x10) << 13;
|
|
435 state->cplco[i][j] =
|
|
436 cplcomant * scale_factor[cplcoexp + mstrcplco];
|
|
437 }
|
|
438 }
|
|
439 if ((state->acmod == 2) && state->phsflginu && cplcoe)
|
|
440 for (j = 0; j < state->ncplbnd; j++)
|
|
441 if (bitstream_get (1)) // phsflg
|
|
442 state->cplco[1][j] = -state->cplco[1][j];
|
|
443 }
|
|
444
|
|
445 if ((state->acmod == 2) && (bitstream_get (1))) { // rematstr
|
|
446 int end;
|
|
447
|
|
448 end = (state->cplinu) ? state->cplstrtmant : 253;
|
|
449 i = 0;
|
|
450 do
|
|
451 state->rematflg[i] = bitstream_get (1);
|
|
452 while (rematrix_band[i++] < end);
|
|
453 }
|
|
454
|
|
455 cplexpstr = EXP_REUSE;
|
|
456 lfeexpstr = EXP_REUSE;
|
|
457 if (state->cplinu)
|
|
458 cplexpstr = bitstream_get (2);
|
|
459 for (i = 0; i < nfchans; i++)
|
|
460 chexpstr[i] = bitstream_get (2);
|
|
461 if (state->lfeon)
|
|
462 lfeexpstr = bitstream_get (1);
|
|
463
|
|
464 for (i = 0; i < nfchans; i++)
|
|
465 if (chexpstr[i] != EXP_REUSE) {
|
|
466 if (state->cplinu && state->chincpl[i])
|
|
467 state->endmant[i] = state->cplstrtmant;
|
|
468 else {
|
|
469 int chbwcod;
|
|
470
|
|
471 chbwcod = bitstream_get (6);
|
|
472 if (chbwcod > 60)
|
|
473 return 1;
|
|
474 state->endmant[i] = chbwcod * 3 + 73;
|
|
475 }
|
|
476 }
|
|
477
|
|
478 do_bit_alloc = 0;
|
|
479
|
|
480 if (cplexpstr != EXP_REUSE) {
|
|
481 int cplabsexp, ncplgrps;
|
|
482
|
|
483 do_bit_alloc = 1;
|
|
484 ncplgrps = ((state->cplendmant - state->cplstrtmant) /
|
|
485 (3 << (cplexpstr - 1)));
|
|
486 cplabsexp = bitstream_get (4) << 1;
|
|
487 if (parse_exponents (cplexpstr, ncplgrps, cplabsexp,
|
|
488 state->cpl_exp + state->cplstrtmant))
|
|
489 return 1;
|
|
490 }
|
|
491 for (i = 0; i < nfchans; i++)
|
|
492 if (chexpstr[i] != EXP_REUSE) {
|
|
493 int grp_size, nchgrps;
|
|
494
|
|
495 do_bit_alloc = 1;
|
|
496 grp_size = 3 << (chexpstr[i] - 1);
|
|
497 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
|
|
498 state->fbw_exp[i][0] = bitstream_get (4);
|
|
499 if (parse_exponents (chexpstr[i], nchgrps, state->fbw_exp[i][0],
|
|
500 state->fbw_exp[i] + 1))
|
|
501 return 1;
|
|
502 bitstream_get (2); // gainrng
|
|
503 }
|
|
504 if (lfeexpstr != EXP_REUSE) {
|
|
505 do_bit_alloc = 1;
|
|
506 state->lfe_exp[0] = bitstream_get (4);
|
|
507 if (parse_exponents (lfeexpstr, 2, state->lfe_exp[0],
|
|
508 state->lfe_exp + 1))
|
|
509 return 1;
|
|
510 }
|
|
511
|
|
512 if (bitstream_get (1)) { // baie
|
|
513 do_bit_alloc = 1;
|
|
514 state->sdcycod = bitstream_get (2);
|
|
515 state->fdcycod = bitstream_get (2);
|
|
516 state->sgaincod = bitstream_get (2);
|
|
517 state->dbpbcod = bitstream_get (2);
|
|
518 state->floorcod = bitstream_get (3);
|
|
519 }
|
|
520 if (bitstream_get (1)) { //snroffste
|
|
521 do_bit_alloc = 1;
|
|
522 state->csnroffst = bitstream_get (6);
|
|
523 if (state->cplinu) {
|
|
524 state->cplba.fsnroffst = bitstream_get (4);
|
|
525 state->cplba.fgaincod = bitstream_get (3);
|
|
526 }
|
|
527 for (i = 0; i < nfchans; i++) {
|
|
528 state->ba[i].fsnroffst = bitstream_get (4);
|
|
529 state->ba[i].fgaincod = bitstream_get (3);
|
|
530 }
|
|
531 if (state->lfeon) {
|
|
532 state->lfeba.fsnroffst = bitstream_get (4);
|
|
533 state->lfeba.fgaincod = bitstream_get (3);
|
|
534 }
|
|
535 }
|
|
536 if ((state->cplinu) && (bitstream_get (1))) { // cplleake
|
|
537 do_bit_alloc = 1;
|
|
538 state->cplfleak = 2304 - (bitstream_get (3) << 8);
|
|
539 state->cplsleak = 2304 - (bitstream_get (3) << 8);
|
|
540 }
|
|
541
|
|
542 if (bitstream_get (1)) { // deltbaie
|
|
543 do_bit_alloc = 1;
|
|
544 if (state->cplinu)
|
|
545 state->cplba.deltbae = bitstream_get (2);
|
|
546 for (i = 0; i < nfchans; i++)
|
|
547 state->ba[i].deltbae = bitstream_get (2);
|
|
548 if (state->cplinu && (state->cplba.deltbae == DELTA_BIT_NEW) &&
|
|
549 parse_deltba (state->cplba.deltba))
|
|
550 return 1;
|
|
551 for (i = 0; i < nfchans; i++)
|
|
552 if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
|
|
553 parse_deltba (state->ba[i].deltba))
|
|
554 return 1;
|
|
555 }
|
|
556
|
|
557 if (do_bit_alloc) {
|
|
558 if (zero_snr_offsets (nfchans, state)) {
|
|
559 memset (state->cpl_bap, 0, sizeof (state->cpl_bap));
|
|
560 memset (state->fbw_bap, 0, sizeof (state->fbw_bap));
|
|
561 memset (state->lfe_bap, 0, sizeof (state->lfe_bap));
|
|
562 } else {
|
|
563 if (state->cplinu)
|
|
564 bit_allocate (state, &state->cplba, state->cplstrtbnd,
|
|
565 state->cplstrtmant, state->cplendmant,
|
|
566 state->cplfleak, state->cplsleak,
|
|
567 state->cpl_exp, state->cpl_bap);
|
|
568 for (i = 0; i < nfchans; i++)
|
|
569 bit_allocate (state, state->ba + i, 0, 0, state->endmant[i],
|
|
570 0, 0, state->fbw_exp[i], state->fbw_bap[i]);
|
|
571 if (state->lfeon) {
|
|
572 state->lfeba.deltbae = DELTA_BIT_NONE;
|
|
573 bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
|
|
574 state->lfe_exp, state->lfe_bap);
|
|
575 }
|
|
576 }
|
|
577 }
|
|
578
|
|
579 if (bitstream_get (1)) { // skiple
|
|
580 i = bitstream_get (9); // skipl
|
|
581 while (i--)
|
|
582 bitstream_get (8);
|
|
583 }
|
|
584
|
|
585 q_1_pointer = q_2_pointer = q_4_pointer = -1;
|
|
586 done_cpl = 0;
|
|
587
|
|
588 for (i = 0; i < nfchans; i++) {
|
|
589 int j;
|
|
590
|
|
591 coeff_get (samples[i], state->fbw_exp[i], state->fbw_bap[i],
|
|
592 dithflag[i], state->endmant[i]);
|
|
593
|
|
594 if (state->cplinu && state->chincpl[i]) {
|
|
595 if (!done_cpl) {
|
|
596 int i, i_end, bnd, sub_bnd, ch;
|
|
597 float cplcoeff;
|
|
598
|
|
599 done_cpl = 1;
|
|
600
|
|
601 #define bap state->cpl_bap
|
|
602 #define exp state->cpl_exp
|
|
603
|
|
604 sub_bnd = bnd = 0;
|
|
605 i = state->cplstrtmant;
|
|
606 while (i < state->cplendmant) {
|
|
607 i_end = i + 12;
|
|
608 while (state->cplbndstrc[sub_bnd++])
|
|
609 i_end += 12;
|
|
610
|
|
611 while (i < i_end) {
|
|
612 GET_COEFF (COUPLING_COEFF, COUPLING_DITHER);
|
|
613 for (ch = 0; ch < nfchans; ch++)
|
|
614 if (state->chincpl[ch])
|
|
615 samples[ch][i] =
|
|
616 state->cplco[ch][bnd] * cplcoeff;
|
|
617 i++;
|
|
618 }
|
|
619 bnd++;
|
|
620 }
|
|
621
|
|
622 #undef bap
|
|
623 #undef exp
|
|
624 }
|
|
625 j = state->cplendmant;
|
|
626 } else
|
|
627 j = state->endmant[i];
|
|
628 for (; j < 256; j++)
|
|
629 samples[i][j] = 0;
|
|
630 }
|
|
631
|
|
632 if (state->acmod == 2) {
|
|
633 int j, end, band;
|
|
634
|
|
635 end = ((state->endmant[0] < state->endmant[1]) ?
|
|
636 state->endmant[0] : state->endmant[1]);
|
|
637
|
|
638 i = 0;
|
|
639 j = 13;
|
|
640 do {
|
|
641 if (!state->rematflg[i]) {
|
|
642 j = rematrix_band[i++];
|
|
643 continue;
|
|
644 }
|
|
645 band = rematrix_band[i++];
|
|
646 if (band > end)
|
|
647 band = end;
|
|
648 do {
|
|
649 float tmp0, tmp1;
|
|
650
|
|
651 tmp0 = samples[0][j];
|
|
652 tmp1 = samples[1][j];
|
|
653 samples[0][j] = tmp0 + tmp1;
|
|
654 samples[1][j] = tmp0 - tmp1;
|
|
655 } while (++j < band);
|
|
656 } while (j < end);
|
|
657 }
|
|
658
|
|
659 if (state->lfeon) {
|
|
660 coeff_get (samples[5], state->lfe_exp, state->lfe_bap, 0, 7);
|
|
661 #if 0
|
|
662 for (i = 7; i < 256; i++)
|
|
663 samples[5][i] = 0;
|
|
664 #endif
|
|
665 }
|
|
666
|
|
667 for (i = 0; i < nfchans; i++)
|
|
668 if (blksw[i])
|
|
669 imdct_256 (samples[i], delay[i]);
|
|
670 else
|
|
671 imdct_512 (samples[i], delay[i]);
|
|
672
|
|
673 #if 0
|
|
674 if (state->lfeon)
|
|
675 imdct_512 (samples[5], delay[5]);
|
|
676 #endif
|
|
677
|
|
678 downmix (*samples, state->acmod, state->output, state->level, state->bias,
|
|
679 state->clev, state->slev);
|
|
680
|
|
681 return 0;
|
|
682 }
|