annotate libac3/parse.c @ 137:21532c56ed8b libavcodec

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