annotate liba52/parse.c @ 4344:4aa24216f71a libavcodec

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