3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config-a52.h"
30 #include "a52_internal.h"
31 #include "bitstream.h"
34 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
35 /* some systems have memalign() but no declaration for it */
36 void * memalign (size_t align
, size_t size
);
38 /* assume malloc alignment is sufficient */
39 #define memalign(align,size) malloc (size)
51 static a52_state_t istate IBSS_ATTR
;
52 static sample_t isamples
[256*12] IBSS_ATTR
;
54 static uint8_t halfrate
[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
56 a52_state_t
* a52_init (uint32_t mm_accel
)
61 #if defined(CPU_COLDFIRE)
62 coldfire_set_macsr(EMAC_FRACTIONAL
| EMAC_ROUND
| EMAC_SATURATE
);
65 this needs to come back if we ever want two decoder instances
66 simultenously. NOTE, you also need to remove comments in a52_free.
67 state = (a52_state_t *) malloc (sizeof (a52_state_t));
71 state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
72 if (state->samples == NULL) {
79 state
->samples
= isamples
;
80 for (i
= 0; i
< 256 * 12; i
++)
81 state
->samples
[i
] = 0;
85 state
->lfsr_state
= 1;
87 a52_imdct_init (mm_accel
);
92 sample_t
* a52_samples (a52_state_t
* state
)
94 return state
->samples
;
97 int a52_syncinfo (uint8_t * buf
, int * flags
,
98 int * sample_rate
, int * bit_rate
)
100 static int rate
[] = { 32, 40, 48, 56, 64, 80, 96, 112,
101 128, 160, 192, 224, 256, 320, 384, 448,
103 static uint8_t lfeon
[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
109 if ((buf
[0] != 0x0b) || (buf
[1] != 0x77)) /* syncword */
112 if (buf
[5] >= 0x60) /* bsid >= 12 */
114 half
= halfrate
[buf
[5] >> 3];
116 /* acmod, dsurmod and lfeon */
118 *flags
= ((((buf
[6] & 0xf8) == 0x50) ? A52_DOLBY
: acmod
) |
119 ((buf
[6] & lfeon
[acmod
]) ? A52_LFE
: 0));
121 frmsizecod
= buf
[4] & 63;
122 if (frmsizecod
>= 38)
124 bitrate
= rate
[frmsizecod
>> 1];
125 *bit_rate
= (bitrate
* 1000) >> half
;
127 switch (buf
[4] & 0xc0) {
129 *sample_rate
= 48000 >> half
;
132 *sample_rate
= 44100 >> half
;
133 return 2 * (320 * bitrate
/ 147 + (frmsizecod
& 1));
135 *sample_rate
= 32000 >> half
;
142 int a52_frame (a52_state_t
* state
, uint8_t * buf
, int * flags
,
143 level_t
* level
, sample_t bias
)
145 static level_t clev
[4] = { LEVEL (LEVEL_3DB
), LEVEL (LEVEL_45DB
),
146 LEVEL (LEVEL_6DB
), LEVEL (LEVEL_45DB
) };
147 static level_t slev
[4] = { LEVEL (LEVEL_3DB
), LEVEL (LEVEL_6DB
),
148 0, LEVEL (LEVEL_6DB
) };
152 state
->fscod
= buf
[4] >> 6;
153 state
->halfrate
= halfrate
[buf
[5] >> 3];
154 state
->acmod
= acmod
= buf
[6] >> 5;
156 a52_bitstream_set_ptr (state
, buf
+ 6);
157 bitstream_get (state
, 3); /* skip acmod we already parsed */
159 if ((acmod
== 2) && (bitstream_get (state
, 2) == 2)) /* dsurmod */
162 state
->clev
= state
->slev
= 0;
164 if ((acmod
& 1) && (acmod
!= 1))
165 state
->clev
= clev
[bitstream_get (state
, 2)]; /* cmixlev */
168 state
->slev
= slev
[bitstream_get (state
, 2)]; /* surmixlev */
170 state
->lfeon
= bitstream_get (state
, 1);
172 state
->output
= a52_downmix_init (acmod
, *flags
, level
,
173 state
->clev
, state
->slev
);
174 if (state
->output
< 0)
176 if (state
->lfeon
&& (*flags
& A52_LFE
))
177 state
->output
|= A52_LFE
;
178 *flags
= state
->output
;
179 /* the 2* compensates for differences in imdct */
180 state
->dynrng
= state
->level
= MUL_C (*level
, 2);
183 state
->dynrngcall
= NULL
;
184 state
->cplba
.deltbae
= DELTA_BIT_NONE
;
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
;
190 bitstream_get (state
, 5); /* dialnorm */
191 if (bitstream_get (state
, 1)) /* compre */
192 bitstream_get (state
, 8); /* compr */
193 if (bitstream_get (state
, 1)) /* langcode */
194 bitstream_get (state
, 8); /* langcod */
195 if (bitstream_get (state
, 1)) /* audprodie */
196 bitstream_get (state
, 7); /* mixlevel + roomtyp */
197 } while (chaninfo
--);
199 bitstream_get (state
, 2); /* copyrightb + origbs */
201 if (bitstream_get (state
, 1)) /* timecod1e */
202 bitstream_get (state
, 14); /* timecod1 */
203 if (bitstream_get (state
, 1)) /* timecod2e */
204 bitstream_get (state
, 14); /* timecod2 */
206 if (bitstream_get (state
, 1)) { /* addbsie */
209 addbsil
= bitstream_get (state
, 6);
211 bitstream_get (state
, 8); /* addbsi */
218 void a52_dynrng (a52_state_t
* state
,
219 level_t (* call
) (level_t
, void *), void * data
)
224 state
->dynrngcall
= call
;
225 state
->dynrngdata
= data
;
229 static int parse_exponents (a52_state_t
* state
, int expstr
, int ngrps
,
230 uint8_t exponent
, uint8_t * dest
)
235 exps
= bitstream_get (state
, 7);
237 exponent
+= exp_1
[exps
];
243 *(dest
++) = exponent
;
244 *(dest
++) = exponent
;
246 *(dest
++) = exponent
;
248 *(dest
++) = exponent
;
251 exponent
+= exp_2
[exps
];
257 *(dest
++) = exponent
;
258 *(dest
++) = exponent
;
260 *(dest
++) = exponent
;
262 *(dest
++) = exponent
;
265 exponent
+= exp_3
[exps
];
271 *(dest
++) = exponent
;
272 *(dest
++) = exponent
;
274 *(dest
++) = exponent
;
276 *(dest
++) = exponent
;
283 static int parse_deltba (a52_state_t
* state
, int8_t * deltba
)
285 int deltnseg
, deltlen
, delta
, j
;
287 memset (deltba
, 0, 50);
289 deltnseg
= bitstream_get (state
, 3);
292 j
+= bitstream_get (state
, 5);
293 deltlen
= bitstream_get (state
, 4);
294 delta
= bitstream_get (state
, 3);
295 delta
-= (delta
>= 4) ? 3 : 4;
298 if (j
+ deltlen
>= 50)
302 } while (deltnseg
--);
307 static inline int zero_snr_offsets (int nfchans
, a52_state_t
* state
)
311 if ((state
->csnroffst
) ||
312 (state
->chincpl
&& state
->cplba
.bai
>> 3) || /* cplinu, fsnroffst */
313 (state
->lfeon
&& state
->lfeba
.bai
>> 3)) /* fsnroffst */
315 for (i
= 0; i
< nfchans
; i
++)
316 if (state
->ba
[i
].bai
>> 3) /* fsnroffst */
321 static inline int16_t dither_gen (a52_state_t
* state
)
325 nstate
= dither_lut
[state
->lfsr_state
>> 8] ^ (state
->lfsr_state
<< 8);
327 state
->lfsr_state
= (uint16_t) nstate
;
329 return (3 * nstate
) >> 2;
333 #define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
335 #define COEFF(c,_t,_l,s,e) do { \
336 quantizer_t t = (_t); \
339 sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
341 (c) = tmp >> shift; \
343 (c) = tmp << -shift; \
347 static void coeff_get (a52_state_t
* state
, sample_t
* coeff
,
348 expbap_t
* expbap
, quantizer_set_t
* quant
,
349 level_t level
, int dither
, int end
)
358 for (i
= 0; i
<= 24; i
++)
359 factor
[i
] = scale_factor
[i
] * level
;
365 for (i
= 0; i
< end
; i
++) {
372 COEFF (coeff
[i
], dither_gen (state
), level
, factor
, exp
[i
]);
380 if (quant
->q1_ptr
>= 0) {
381 COEFF (coeff
[i
], quant
->q1
[quant
->q1_ptr
--], level
,
387 code
= bitstream_get (state
, 5);
390 quant
->q1
[0] = q_1_2
[code
];
391 quant
->q1
[1] = q_1_1
[code
];
392 COEFF (coeff
[i
], q_1_0
[code
], level
, factor
, exp
[i
]);
397 if (quant
->q2_ptr
>= 0) {
398 COEFF (coeff
[i
], quant
->q2
[quant
->q2_ptr
--], level
,
404 code
= bitstream_get (state
, 7);
407 quant
->q2
[0] = q_2_2
[code
];
408 quant
->q2
[1] = q_2_1
[code
];
409 COEFF (coeff
[i
], q_2_0
[code
], level
, factor
, exp
[i
]);
414 COEFF (coeff
[i
], q_3
[bitstream_get (state
, 3)], level
,
419 if (quant
->q4_ptr
== 0) {
421 COEFF (coeff
[i
], quant
->q4
, level
, factor
, exp
[i
]);
426 code
= bitstream_get (state
, 7);
429 quant
->q4
= q_4_1
[code
];
430 COEFF (coeff
[i
], q_4_0
[code
], level
, factor
, exp
[i
]);
435 COEFF (coeff
[i
], q_5
[bitstream_get (state
, 4)], level
,
440 COEFF (coeff
[i
], bitstream_get_2 (state
, bapi
) << (16 - bapi
),
441 level
, factor
, exp
[i
]);
446 static void coeff_get_coupling (a52_state_t
* state
, int nfchans
,
447 level_t
* coeff
, sample_t (* samples
)[256],
448 quantizer_set_t
* quant
, uint8_t dithflag
[5])
450 int cplbndstrc
, bnd
, i
, i_end
, ch
;
455 exp
= state
->cpl_expbap
.exp
;
456 bap
= state
->cpl_expbap
.bap
;
458 cplbndstrc
= state
->cplbndstrc
;
459 i
= state
->cplstrtmant
;
460 while (i
< state
->cplendmant
) {
462 while (cplbndstrc
& 1) {
467 for (ch
= 0; ch
< nfchans
; ch
++)
468 cplco
[ch
] = MUL_L (state
->cplco
[ch
][bnd
], coeff
[ch
]);
472 quantizer_t cplcoeff
;
478 for (ch
= 0; ch
< nfchans
; ch
++)
479 if ((state
->chincpl
>> ch
) & 1) {
482 samples
[ch
][i
] = (scale_factor
[exp
[i
]] *
483 cplco
[ch
] * dither_gen (state
));
485 COEFF (samples
[ch
][i
], dither_gen (state
),
486 cplco
[ch
], scale_factor
, exp
[i
]);
495 if (quant
->q1_ptr
>= 0) {
496 cplcoeff
= quant
->q1
[quant
->q1_ptr
--];
501 code
= bitstream_get (state
, 5);
504 quant
->q1
[0] = q_1_2
[code
];
505 quant
->q1
[1] = q_1_1
[code
];
506 cplcoeff
= q_1_0
[code
];
511 if (quant
->q2_ptr
>= 0) {
512 cplcoeff
= quant
->q2
[quant
->q2_ptr
--];
517 code
= bitstream_get (state
, 7);
520 quant
->q2
[0] = q_2_2
[code
];
521 quant
->q2
[1] = q_2_1
[code
];
522 cplcoeff
= q_2_0
[code
];
527 cplcoeff
= q_3
[bitstream_get (state
, 3)];
531 if (quant
->q4_ptr
== 0) {
533 cplcoeff
= quant
->q4
;
538 code
= bitstream_get (state
, 7);
541 quant
->q4
= q_4_1
[code
];
542 cplcoeff
= q_4_0
[code
];
547 cplcoeff
= q_5
[bitstream_get (state
, 4)];
551 cplcoeff
= bitstream_get_2 (state
, bapi
) << (16 - bapi
);
554 cplcoeff
*= scale_factor
[exp
[i
]];
556 for (ch
= 0; ch
< nfchans
; ch
++)
557 if ((state
->chincpl
>> ch
) & 1)
559 samples
[ch
][i
] = cplcoeff
* cplco
[ch
];
561 COEFF (samples
[ch
][i
], cplcoeff
, cplco
[ch
],
562 scale_factor
, exp
[i
]);
569 int a52_block (a52_state_t
* state
)
571 static const uint8_t nfchans_tbl
[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2};
572 static int rematrix_band
[4] = {25, 37, 61, 253};
573 int i
, nfchans
, chaninfo
;
574 uint8_t cplexpstr
, chexpstr
[5], lfeexpstr
, do_bit_alloc
, done_cpl
;
575 uint8_t blksw
[5], dithflag
[5];
578 quantizer_set_t quant
;
581 nfchans
= nfchans_tbl
[state
->acmod
];
583 for (i
= 0; i
< nfchans
; i
++)
584 blksw
[i
] = bitstream_get (state
, 1);
586 for (i
= 0; i
< nfchans
; i
++)
587 dithflag
[i
] = bitstream_get (state
, 1);
589 chaninfo
= !state
->acmod
;
591 if (bitstream_get (state
, 1)) { /* dynrnge */
594 dynrng
= bitstream_get_2 (state
, 8);
595 if (state
->dynrnge
) {
598 #if !defined(LIBA52_FIXED)
599 range
= ((((dynrng
& 0x1f) | 0x20) << 13) *
600 scale_factor
[3 - (dynrng
>> 5)]);
602 range
= ((dynrng
& 0x1f) | 0x20) << (21 + (dynrng
>> 5));
604 if (state
->dynrngcall
)
605 range
= state
->dynrngcall (range
, state
->dynrngdata
);
606 state
->dynrng
= MUL_L (state
->level
, range
);
609 } while (chaninfo
--);
611 if (bitstream_get (state
, 1)) { /* cplstre */
613 if (bitstream_get (state
, 1)) { /* cplinu */
614 static uint8_t bndtab
[16] = {31, 35, 37, 39, 41, 42, 43, 44,
615 45, 45, 46, 46, 47, 47, 48, 48};
620 for (i
= 0; i
< nfchans
; i
++)
621 state
->chincpl
|= bitstream_get (state
, 1) << i
;
622 switch (state
->acmod
) {
626 state
->phsflginu
= bitstream_get (state
, 1);
628 cplbegf
= bitstream_get (state
, 4);
629 cplendf
= bitstream_get (state
, 4);
631 if (cplendf
+ 3 - cplbegf
< 0)
633 state
->ncplbnd
= ncplsubnd
= cplendf
+ 3 - cplbegf
;
634 state
->cplstrtbnd
= bndtab
[cplbegf
];
635 state
->cplstrtmant
= cplbegf
* 12 + 37;
636 state
->cplendmant
= cplendf
* 12 + 73;
638 state
->cplbndstrc
= 0;
639 for (i
= 0; i
< ncplsubnd
- 1; i
++)
640 if (bitstream_get (state
, 1)) {
641 state
->cplbndstrc
|= 1 << i
;
647 if (state
->chincpl
) { /* cplinu */
651 for (i
= 0; i
< nfchans
; i
++)
652 if ((state
->chincpl
) >> i
& 1)
653 if (bitstream_get (state
, 1)) { /* cplcoe */
654 int mstrcplco
, cplcoexp
, cplcomant
;
657 mstrcplco
= 3 * bitstream_get (state
, 2);
658 for (j
= 0; j
< state
->ncplbnd
; j
++) {
659 cplcoexp
= bitstream_get (state
, 4);
660 cplcomant
= bitstream_get (state
, 4);
664 cplcomant
= (cplcomant
| 0x10) << 13;
667 cplcomant
* scale_factor
[cplcoexp
+ mstrcplco
];
669 state
->cplco
[i
][j
] = (cplcomant
<< 11) >> (cplcoexp
+ mstrcplco
);
674 if ((state
->acmod
== 2) && state
->phsflginu
&& cplcoe
)
675 for (j
= 0; j
< state
->ncplbnd
; j
++)
676 if (bitstream_get (state
, 1)) /* phsflg */
677 state
->cplco
[1][j
] = -state
->cplco
[1][j
];
680 if ((state
->acmod
== 2) && (bitstream_get (state
, 1))) { /* rematstr */
684 end
= (state
->chincpl
) ? state
->cplstrtmant
: 253; /* cplinu */
687 state
->rematflg
|= bitstream_get (state
, 1) << i
;
688 while (rematrix_band
[i
++] < end
);
691 cplexpstr
= EXP_REUSE
;
692 lfeexpstr
= EXP_REUSE
;
693 if (state
->chincpl
) /* cplinu */
694 cplexpstr
= bitstream_get (state
, 2);
695 for (i
= 0; i
< nfchans
; i
++)
696 chexpstr
[i
] = bitstream_get (state
, 2);
698 lfeexpstr
= bitstream_get (state
, 1);
700 for (i
= 0; i
< nfchans
; i
++)
701 if (chexpstr
[i
] != EXP_REUSE
) {
702 if ((state
->chincpl
>> i
) & 1)
703 state
->endmant
[i
] = state
->cplstrtmant
;
707 chbwcod
= bitstream_get (state
, 6);
710 state
->endmant
[i
] = chbwcod
* 3 + 73;
716 if (cplexpstr
!= EXP_REUSE
) {
717 int cplabsexp
, ncplgrps
;
720 ncplgrps
= ((state
->cplendmant
- state
->cplstrtmant
) /
721 (3 << (cplexpstr
- 1)));
722 cplabsexp
= bitstream_get (state
, 4) << 1;
723 if (parse_exponents (state
, cplexpstr
, ncplgrps
, cplabsexp
,
724 state
->cpl_expbap
.exp
+ state
->cplstrtmant
))
727 for (i
= 0; i
< nfchans
; i
++)
728 if (chexpstr
[i
] != EXP_REUSE
) {
729 int grp_size
, nchgrps
;
731 do_bit_alloc
|= 1 << i
;
732 grp_size
= 3 << (chexpstr
[i
] - 1);
733 nchgrps
= (state
->endmant
[i
] + grp_size
- 4) / grp_size
;
734 state
->fbw_expbap
[i
].exp
[0] = bitstream_get (state
, 4);
735 if (parse_exponents (state
, chexpstr
[i
], nchgrps
,
736 state
->fbw_expbap
[i
].exp
[0],
737 state
->fbw_expbap
[i
].exp
+ 1))
739 bitstream_get (state
, 2); /* gainrng */
741 if (lfeexpstr
!= EXP_REUSE
) {
743 state
->lfe_expbap
.exp
[0] = bitstream_get (state
, 4);
744 if (parse_exponents (state
, lfeexpstr
, 2, state
->lfe_expbap
.exp
[0],
745 state
->lfe_expbap
.exp
+ 1))
749 if (bitstream_get (state
, 1)) { /* baie */
751 state
->bai
= bitstream_get (state
, 11);
753 if (bitstream_get (state
, 1)) { /* snroffste */
755 state
->csnroffst
= bitstream_get (state
, 6);
756 if (state
->chincpl
) /* cplinu */
757 state
->cplba
.bai
= bitstream_get (state
, 7);
758 for (i
= 0; i
< nfchans
; i
++)
759 state
->ba
[i
].bai
= bitstream_get (state
, 7);
761 state
->lfeba
.bai
= bitstream_get (state
, 7);
763 if ((state
->chincpl
) && (bitstream_get (state
, 1))) { /* cplleake */
765 state
->cplfleak
= 9 - bitstream_get (state
, 3);
766 state
->cplsleak
= 9 - bitstream_get (state
, 3);
769 if (bitstream_get (state
, 1)) { /* deltbaie */
771 if (state
->chincpl
) /* cplinu */
772 state
->cplba
.deltbae
= bitstream_get (state
, 2);
773 for (i
= 0; i
< nfchans
; i
++)
774 state
->ba
[i
].deltbae
= bitstream_get (state
, 2);
775 if (state
->chincpl
&& /* cplinu */
776 (state
->cplba
.deltbae
== DELTA_BIT_NEW
) &&
777 parse_deltba (state
, state
->cplba
.deltba
))
779 for (i
= 0; i
< nfchans
; i
++)
780 if ((state
->ba
[i
].deltbae
== DELTA_BIT_NEW
) &&
781 parse_deltba (state
, state
->ba
[i
].deltba
))
786 if (zero_snr_offsets (nfchans
, state
)) {
787 memset (state
->cpl_expbap
.bap
, 0, sizeof (state
->cpl_expbap
.bap
));
788 for (i
= 0; i
< nfchans
; i
++)
789 memset (state
->fbw_expbap
[i
].bap
, 0,
790 sizeof (state
->fbw_expbap
[i
].bap
));
791 memset (state
->lfe_expbap
.bap
, 0, sizeof (state
->lfe_expbap
.bap
));
793 if (state
->chincpl
&& (do_bit_alloc
& 64)) /* cplinu */
794 a52_bit_allocate (state
, &state
->cplba
, state
->cplstrtbnd
,
795 state
->cplstrtmant
, state
->cplendmant
,
796 state
->cplfleak
<< 8, state
->cplsleak
<< 8,
798 for (i
= 0; i
< nfchans
; i
++)
799 if (do_bit_alloc
& (1 << i
))
800 a52_bit_allocate (state
, state
->ba
+ i
, 0, 0,
801 state
->endmant
[i
], 0, 0,
802 state
->fbw_expbap
+i
);
803 if (state
->lfeon
&& (do_bit_alloc
& 32)) {
804 state
->lfeba
.deltbae
= DELTA_BIT_NONE
;
805 a52_bit_allocate (state
, &state
->lfeba
, 0, 0, 7, 0, 0,
811 if (bitstream_get (state
, 1)) { /* skiple */
812 i
= bitstream_get (state
, 9); /* skipl */
814 bitstream_get (state
, 8);
817 samples
= state
->samples
;
818 if (state
->output
& A52_LFE
)
819 samples
+= 256; /* shift for LFE channel */
821 chanbias
= a52_downmix_coeff (coeff
, state
->acmod
, state
->output
,
822 state
->dynrng
, state
->clev
, state
->slev
);
824 quant
.q1_ptr
= quant
.q2_ptr
= quant
.q4_ptr
= -1;
827 for (i
= 0; i
< nfchans
; i
++) {
830 coeff_get (state
, samples
+ 256 * i
, state
->fbw_expbap
+i
, &quant
,
831 coeff
[i
], dithflag
[i
], state
->endmant
[i
]);
833 if ((state
->chincpl
>> i
) & 1) {
836 coeff_get_coupling (state
, nfchans
, coeff
,
837 (sample_t (*)[256])samples
, &quant
,
840 j
= state
->cplendmant
;
842 j
= state
->endmant
[i
];
844 (samples
+ 256 * i
)[j
] = 0;
848 if (state
->acmod
== 2) {
849 int j
, end
, band
, rematflg
;
851 end
= ((state
->endmant
[0] < state
->endmant
[1]) ?
852 state
->endmant
[0] : state
->endmant
[1]);
856 rematflg
= state
->rematflg
;
858 if (! (rematflg
& 1)) {
860 j
= rematrix_band
[i
++];
864 band
= rematrix_band
[i
++];
871 tmp1
= (samples
+256)[j
];
872 samples
[j
] = tmp0
+ tmp1
;
873 (samples
+256)[j
] = tmp0
- tmp1
;
874 } while (++j
< band
);
879 if (state
->output
& A52_LFE
) {
880 coeff_get (state
, samples
- 256, &state
->lfe_expbap
, &quant
,
881 state
->dynrng
, 0, 7);
882 for (i
= 7; i
< 256; i
++)
883 (samples
-256)[i
] = 0;
884 a52_imdct_512 (samples
- 256, samples
+ 1536 - 256);
886 /* just skip the LFE coefficients */
887 coeff_get (state
, samples
+ 1280, &state
->lfe_expbap
, &quant
,
893 if (nfchans_tbl
[state
->output
& A52_CHANNEL_MASK
] < nfchans
)
894 for (i
= 1; i
< nfchans
; i
++)
895 if (blksw
[i
] != blksw
[0])
899 if (state
->downmixed
) {
900 state
->downmixed
= 0;
901 a52_upmix (samples
+ 1536, state
->acmod
, state
->output
);
904 for (i
= 0; i
< nfchans
; i
++) {
908 if (!(chanbias
& (1 << i
)))
913 a52_imdct_256 (samples
+ 256 * i
, samples
+ 1536 + 256 * i
);
915 a52_imdct_512 (samples
+ 256 * i
, samples
+ 1536 + 256 * i
);
919 for (j
= 0; j
< 256; j
++)
920 (samples
+ 256 * i
)[j
] = bias
;
924 a52_downmix (samples
, state
->acmod
, state
->output
,
925 state
->clev
, state
->slev
);
927 nfchans
= nfchans_tbl
[state
->output
& A52_CHANNEL_MASK
];
929 a52_downmix (samples
, state
->acmod
, state
->output
,
930 state
->clev
, state
->slev
);
932 if (!state
->downmixed
) {
933 state
->downmixed
= 1;
934 a52_downmix (samples
+ 1536, state
->acmod
, state
->output
,
935 state
->clev
, state
->slev
);
939 for (i
= 0; i
< nfchans
; i
++)
940 a52_imdct_256 (samples
+ 256 * i
, samples
+ 1536 + 256 * i
);
942 for (i
= 0; i
< nfchans
; i
++)
943 a52_imdct_512 (samples
+ 256 * i
, samples
+ 1536 + 256 * i
);
949 void a52_free (a52_state_t
* state
)
953 free (state->samples);