Mercurial > mplayer.hg
annotate libfaad2/syntax.c @ 13468:d9591400424b
Hint at examples, better wording, some cosmetics.
author | diego |
---|---|
date | Sat, 25 Sep 2004 22:58:59 +0000 |
parents | 6d50ef45a058 |
children | 2ae5ab4331ca |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
10725 | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | |
6 ** it under the terms of the GNU General Public License as published by | |
7 ** the Free Software Foundation; either version 2 of the License, or | |
8 ** (at your option) any later version. | |
9 ** | |
10 ** This program is distributed in the hope that it will be useful, | |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ** GNU General Public License for more details. | |
14 ** | |
15 ** You should have received a copy of the GNU General Public License | |
16 ** along with this program; if not, write to the Free Software | |
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
26 ** $Id: syntax.c,v 1.4 2004/06/23 13:50:53 diego Exp $ |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
30 /* | |
31 Reads the AAC bitstream as defined in 14496-3 (MPEG-4 Audio) | |
32 */ | |
33 | |
34 #include "common.h" | |
35 #include "structs.h" | |
36 | |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 | |
40 #include "decoder.h" | |
41 #include "syntax.h" | |
42 #include "specrec.h" | |
43 #include "huffman.h" | |
44 #include "bits.h" | |
45 #include "pulse.h" | |
46 #include "analysis.h" | |
47 #include "drc.h" | |
48 #ifdef ERROR_RESILIENCE | |
49 #include "rvlc.h" | |
50 #endif | |
51 #ifdef SBR_DEC | |
52 #include "sbr_syntax.h" | |
53 #endif | |
54 | |
55 | |
12527 | 56 /* static function declarations */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
57 static void decode_sce_lfe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld, |
12527 | 58 uint8_t id_syn_ele); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
59 static void decode_cpe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld, |
12527 | 60 uint8_t id_syn_ele); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
61 static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld, |
12527 | 62 uint8_t channel, uint8_t *tag); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
63 static uint8_t channel_pair_element(NeAACDecHandle hDecoder, bitfile *ld, |
12527 | 64 uint8_t channel, uint8_t *tag); |
65 #ifdef COUPLING_DEC | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
66 static uint8_t coupling_channel_element(NeAACDecHandle hDecoder, bitfile *ld); |
12527 | 67 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
68 static uint16_t data_stream_element(NeAACDecHandle hDecoder, bitfile *ld); |
12527 | 69 static uint8_t program_config_element(program_config *pce, bitfile *ld); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
70 static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc |
12527 | 71 #ifdef SBR_DEC |
72 ,uint8_t sbr_ele | |
73 #endif | |
74 ); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
75 static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele, |
12527 | 76 bitfile *ld, ic_stream *ics, uint8_t scal_flag, |
77 int16_t *spec_data); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
78 static uint8_t ics_info(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld, |
12527 | 79 uint8_t common_window); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
80 static uint8_t section_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
81 static uint8_t scale_factor_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld); |
12527 | 82 #ifdef SSR_DEC |
83 static void gain_control_data(bitfile *ld, ic_stream *ics); | |
84 #endif | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
85 static uint8_t spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld, |
12527 | 86 int16_t *spectral_data); |
87 static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count); | |
88 static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld); | |
89 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
90 #ifdef LTP_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
91 static uint8_t ltp_data(NeAACDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
92 #endif |
12527 | 93 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld); |
94 static void adts_variable_header(adts_header *adts, bitfile *ld); | |
95 static void adts_error_check(adts_header *adts, bitfile *ld); | |
96 static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc); | |
97 static uint8_t excluded_channels(bitfile *ld, drc_info *drc); | |
98 #ifdef SCALABLE_DEC | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
99 static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, |
12527 | 100 bitfile *ld, uint8_t this_layer_stereo); |
101 #endif | |
102 | |
103 | |
10725 | 104 /* Table 4.4.1 */ |
105 int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC, | |
106 program_config *pce_out) | |
107 { | |
108 program_config pce; | |
109 | |
110 /* 1024 or 960 */ | |
111 mp4ASC->frameLengthFlag = faad_get1bit(ld | |
112 DEBUGVAR(1,138,"GASpecificConfig(): FrameLengthFlag")); | |
12527 | 113 #ifndef ALLOW_SMALL_FRAMELENGTH |
114 if (mp4ASC->frameLengthFlag == 1) | |
115 return -3; | |
116 #endif | |
10725 | 117 |
118 mp4ASC->dependsOnCoreCoder = faad_get1bit(ld | |
119 DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder")); | |
120 if (mp4ASC->dependsOnCoreCoder == 1) | |
121 { | |
122 mp4ASC->coreCoderDelay = (uint16_t)faad_getbits(ld, 14 | |
123 DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay")); | |
124 } | |
125 | |
126 mp4ASC->extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag")); | |
127 if (mp4ASC->channelsConfiguration == 0) | |
128 { | |
12527 | 129 if (program_config_element(&pce, ld)) |
130 return -3; | |
10725 | 131 //mp4ASC->channelsConfiguration = pce.channels; |
132 | |
133 if (pce_out != NULL) | |
134 memcpy(pce_out, &pce, sizeof(program_config)); | |
135 | |
136 /* | |
137 if (pce.num_valid_cc_elements) | |
138 return -3; | |
139 */ | |
140 } | |
141 | |
142 #ifdef ERROR_RESILIENCE | |
143 if (mp4ASC->extensionFlag == 1) | |
144 { | |
145 /* Error resilience not supported yet */ | |
146 if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) | |
147 { | |
148 mp4ASC->aacSectionDataResilienceFlag = faad_get1bit(ld | |
149 DEBUGVAR(1,144,"GASpecificConfig(): aacSectionDataResilienceFlag")); | |
150 mp4ASC->aacScalefactorDataResilienceFlag = faad_get1bit(ld | |
151 DEBUGVAR(1,145,"GASpecificConfig(): aacScalefactorDataResilienceFlag")); | |
152 mp4ASC->aacSpectralDataResilienceFlag = faad_get1bit(ld | |
153 DEBUGVAR(1,146,"GASpecificConfig(): aacSpectralDataResilienceFlag")); | |
154 | |
155 /* 1 bit: extensionFlag3 */ | |
156 } | |
157 } | |
158 #endif | |
159 | |
160 return 0; | |
161 } | |
162 | |
163 /* Table 4.4.2 */ | |
164 /* An MPEG-4 Audio decoder is only required to follow the Program | |
165 Configuration Element in GASpecificConfig(). The decoder shall ignore | |
166 any Program Configuration Elements that may occur in raw data blocks. | |
167 PCEs transmitted in raw data blocks cannot be used to convey decoder | |
168 configuration information. | |
169 */ | |
12527 | 170 static uint8_t program_config_element(program_config *pce, bitfile *ld) |
10725 | 171 { |
172 uint8_t i; | |
173 | |
174 memset(pce, 0, sizeof(program_config)); | |
175 | |
176 pce->channels = 0; | |
177 | |
178 pce->element_instance_tag = (uint8_t)faad_getbits(ld, 4 | |
179 DEBUGVAR(1,10,"program_config_element(): element_instance_tag")); | |
180 | |
181 pce->object_type = (uint8_t)faad_getbits(ld, 2 | |
182 DEBUGVAR(1,11,"program_config_element(): object_type")); | |
183 pce->sf_index = (uint8_t)faad_getbits(ld, 4 | |
184 DEBUGVAR(1,12,"program_config_element(): sf_index")); | |
185 pce->num_front_channel_elements = (uint8_t)faad_getbits(ld, 4 | |
186 DEBUGVAR(1,13,"program_config_element(): num_front_channel_elements")); | |
187 pce->num_side_channel_elements = (uint8_t)faad_getbits(ld, 4 | |
188 DEBUGVAR(1,14,"program_config_element(): num_side_channel_elements")); | |
189 pce->num_back_channel_elements = (uint8_t)faad_getbits(ld, 4 | |
190 DEBUGVAR(1,15,"program_config_element(): num_back_channel_elements")); | |
191 pce->num_lfe_channel_elements = (uint8_t)faad_getbits(ld, 2 | |
192 DEBUGVAR(1,16,"program_config_element(): num_lfe_channel_elements")); | |
193 pce->num_assoc_data_elements = (uint8_t)faad_getbits(ld, 3 | |
194 DEBUGVAR(1,17,"program_config_element(): num_assoc_data_elements")); | |
195 pce->num_valid_cc_elements = (uint8_t)faad_getbits(ld, 4 | |
196 DEBUGVAR(1,18,"program_config_element(): num_valid_cc_elements")); | |
197 | |
198 pce->mono_mixdown_present = faad_get1bit(ld | |
199 DEBUGVAR(1,19,"program_config_element(): mono_mixdown_present")); | |
200 if (pce->mono_mixdown_present == 1) | |
201 { | |
202 pce->mono_mixdown_element_number = (uint8_t)faad_getbits(ld, 4 | |
203 DEBUGVAR(1,20,"program_config_element(): mono_mixdown_element_number")); | |
204 } | |
205 | |
206 pce->stereo_mixdown_present = faad_get1bit(ld | |
207 DEBUGVAR(1,21,"program_config_element(): stereo_mixdown_present")); | |
208 if (pce->stereo_mixdown_present == 1) | |
209 { | |
210 pce->stereo_mixdown_element_number = (uint8_t)faad_getbits(ld, 4 | |
211 DEBUGVAR(1,22,"program_config_element(): stereo_mixdown_element_number")); | |
212 } | |
213 | |
214 pce->matrix_mixdown_idx_present = faad_get1bit(ld | |
215 DEBUGVAR(1,23,"program_config_element(): matrix_mixdown_idx_present")); | |
216 if (pce->matrix_mixdown_idx_present == 1) | |
217 { | |
218 pce->matrix_mixdown_idx = (uint8_t)faad_getbits(ld, 2 | |
219 DEBUGVAR(1,24,"program_config_element(): matrix_mixdown_idx")); | |
220 pce->pseudo_surround_enable = faad_get1bit(ld | |
221 DEBUGVAR(1,25,"program_config_element(): pseudo_surround_enable")); | |
222 } | |
223 | |
224 for (i = 0; i < pce->num_front_channel_elements; i++) | |
225 { | |
226 pce->front_element_is_cpe[i] = faad_get1bit(ld | |
227 DEBUGVAR(1,26,"program_config_element(): front_element_is_cpe")); | |
228 pce->front_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
229 DEBUGVAR(1,27,"program_config_element(): front_element_tag_select")); | |
230 | |
231 if (pce->front_element_is_cpe[i] & 1) | |
232 { | |
233 pce->cpe_channel[pce->front_element_tag_select[i]] = pce->channels; | |
234 pce->num_front_channels += 2; | |
235 pce->channels += 2; | |
236 } else { | |
237 pce->sce_channel[pce->front_element_tag_select[i]] = pce->channels; | |
238 pce->num_front_channels++; | |
239 pce->channels++; | |
240 } | |
241 } | |
242 | |
243 for (i = 0; i < pce->num_side_channel_elements; i++) | |
244 { | |
245 pce->side_element_is_cpe[i] = faad_get1bit(ld | |
246 DEBUGVAR(1,28,"program_config_element(): side_element_is_cpe")); | |
247 pce->side_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
248 DEBUGVAR(1,29,"program_config_element(): side_element_tag_select")); | |
249 | |
250 if (pce->side_element_is_cpe[i] & 1) | |
251 { | |
252 pce->cpe_channel[pce->side_element_tag_select[i]] = pce->channels; | |
253 pce->num_side_channels += 2; | |
254 pce->channels += 2; | |
255 } else { | |
256 pce->sce_channel[pce->side_element_tag_select[i]] = pce->channels; | |
257 pce->num_side_channels++; | |
258 pce->channels++; | |
259 } | |
260 } | |
261 | |
262 for (i = 0; i < pce->num_back_channel_elements; i++) | |
263 { | |
264 pce->back_element_is_cpe[i] = faad_get1bit(ld | |
265 DEBUGVAR(1,30,"program_config_element(): back_element_is_cpe")); | |
266 pce->back_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
267 DEBUGVAR(1,31,"program_config_element(): back_element_tag_select")); | |
268 | |
269 if (pce->back_element_is_cpe[i] & 1) | |
270 { | |
271 pce->cpe_channel[pce->back_element_tag_select[i]] = pce->channels; | |
272 pce->channels += 2; | |
273 pce->num_back_channels += 2; | |
274 } else { | |
275 pce->sce_channel[pce->back_element_tag_select[i]] = pce->channels; | |
276 pce->num_back_channels++; | |
277 pce->channels++; | |
278 } | |
279 } | |
280 | |
281 for (i = 0; i < pce->num_lfe_channel_elements; i++) | |
282 { | |
283 pce->lfe_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
284 DEBUGVAR(1,32,"program_config_element(): lfe_element_tag_select")); | |
285 | |
286 pce->sce_channel[pce->lfe_element_tag_select[i]] = pce->channels; | |
287 pce->num_lfe_channels++; | |
288 pce->channels++; | |
289 } | |
290 | |
291 for (i = 0; i < pce->num_assoc_data_elements; i++) | |
292 pce->assoc_data_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
293 DEBUGVAR(1,33,"program_config_element(): assoc_data_element_tag_select")); | |
294 | |
295 for (i = 0; i < pce->num_valid_cc_elements; i++) | |
296 { | |
297 pce->cc_element_is_ind_sw[i] = faad_get1bit(ld | |
298 DEBUGVAR(1,34,"program_config_element(): cc_element_is_ind_sw")); | |
299 pce->valid_cc_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4 | |
300 DEBUGVAR(1,35,"program_config_element(): valid_cc_element_tag_select")); | |
301 } | |
302 | |
303 faad_byte_align(ld); | |
304 | |
305 pce->comment_field_bytes = (uint8_t)faad_getbits(ld, 8 | |
306 DEBUGVAR(1,36,"program_config_element(): comment_field_bytes")); | |
307 | |
308 for (i = 0; i < pce->comment_field_bytes; i++) | |
309 { | |
310 pce->comment_field_data[i] = (uint8_t)faad_getbits(ld, 8 | |
311 DEBUGVAR(1,37,"program_config_element(): comment_field_data")); | |
312 } | |
313 pce->comment_field_data[i] = 0; | |
314 | |
12527 | 315 if (pce->channels > MAX_CHANNELS) |
316 return 22; | |
317 | |
10725 | 318 return 0; |
319 } | |
320 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
321 static void decode_sce_lfe(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
322 NeAACDecFrameInfo *hInfo, bitfile *ld, |
12527 | 323 uint8_t id_syn_ele) |
10725 | 324 { |
325 uint8_t channels = hDecoder->fr_channels; | |
12527 | 326 uint8_t tag = 0; |
10725 | 327 |
328 if (channels+1 > MAX_CHANNELS) | |
329 { | |
330 hInfo->error = 12; | |
12527 | 331 return; |
10725 | 332 } |
333 if (hDecoder->fr_ch_ele+1 > MAX_SYNTAX_ELEMENTS) | |
334 { | |
335 hInfo->error = 13; | |
12527 | 336 return; |
10725 | 337 } |
338 | |
12527 | 339 /* for SCE hDecoder->element_output_channels[] is not set here because this |
340 can become 2 when some form of Parametric Stereo coding is used | |
341 */ | |
10725 | 342 |
12527 | 343 /* save the syntax element id */ |
344 hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele; | |
10725 | 345 |
12527 | 346 /* decode the element */ |
347 hInfo->error = single_lfe_channel_element(hDecoder, ld, channels, &tag); | |
10725 | 348 |
12527 | 349 /* map output channels position to internal data channels */ |
350 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2) | |
351 { | |
352 /* this might be faulty when pce_set is true */ | |
10725 | 353 hDecoder->internal_channel[channels] = channels; |
12527 | 354 hDecoder->internal_channel[channels+1] = channels+1; |
355 } else { | |
356 if (hDecoder->pce_set) | |
357 hDecoder->internal_channel[hDecoder->pce.sce_channel[tag]] = channels; | |
358 else | |
359 hDecoder->internal_channel[channels] = channels; | |
360 } | |
10725 | 361 |
12527 | 362 hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele]; |
10725 | 363 hDecoder->fr_ch_ele++; |
364 } | |
365 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
366 static void decode_cpe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld, |
12527 | 367 uint8_t id_syn_ele) |
10725 | 368 { |
369 uint8_t channels = hDecoder->fr_channels; | |
12527 | 370 uint8_t tag = 0; |
10725 | 371 |
372 if (channels+2 > MAX_CHANNELS) | |
373 { | |
374 hInfo->error = 12; | |
12527 | 375 return; |
10725 | 376 } |
377 if (hDecoder->fr_ch_ele+1 > MAX_SYNTAX_ELEMENTS) | |
378 { | |
379 hInfo->error = 13; | |
12527 | 380 return; |
10725 | 381 } |
382 | |
12527 | 383 /* for CPE the number of output channels is always 2 */ |
384 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) | |
385 { | |
386 /* element_output_channels not set yet */ | |
387 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2; | |
388 } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != 2) { | |
389 /* element inconsistency */ | |
390 hInfo->error = 21; | |
391 return; | |
392 } | |
10725 | 393 |
12527 | 394 /* save the syntax element id */ |
395 hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele; | |
10725 | 396 |
12527 | 397 /* decode the element */ |
398 hInfo->error = channel_pair_element(hDecoder, ld, channels, &tag); | |
10725 | 399 |
12527 | 400 /* map output channel position to internal data channels */ |
10725 | 401 if (hDecoder->pce_set) |
402 { | |
12527 | 403 hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]] = channels; |
404 hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]+1] = channels+1; | |
10725 | 405 } else { |
406 hDecoder->internal_channel[channels] = channels; | |
407 hDecoder->internal_channel[channels+1] = channels+1; | |
408 } | |
409 | |
410 hDecoder->fr_channels += 2; | |
411 hDecoder->fr_ch_ele++; | |
412 } | |
413 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
414 void raw_data_block(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
12527 | 415 bitfile *ld, program_config *pce, drc_info *drc) |
10725 | 416 { |
417 uint8_t id_syn_ele; | |
418 | |
419 hDecoder->fr_channels = 0; | |
420 hDecoder->fr_ch_ele = 0; | |
421 hDecoder->first_syn_ele = 25; | |
422 hDecoder->has_lfe = 0; | |
423 | |
424 #ifdef ERROR_RESILIENCE | |
425 if (hDecoder->object_type < ER_OBJECT_START) | |
426 { | |
427 #endif | |
428 /* Table 4.4.3: raw_data_block() */ | |
429 while ((id_syn_ele = (uint8_t)faad_getbits(ld, LEN_SE_ID | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
430 DEBUGVAR(1,4,"NeAACDecDecode(): id_syn_ele"))) != ID_END) |
10725 | 431 { |
432 switch (id_syn_ele) { | |
433 case ID_SCE: | |
434 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele; | |
12527 | 435 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele); |
10725 | 436 if (hInfo->error > 0) |
12527 | 437 return; |
10725 | 438 break; |
439 case ID_CPE: | |
440 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele; | |
12527 | 441 decode_cpe(hDecoder, hInfo, ld, id_syn_ele); |
10725 | 442 if (hInfo->error > 0) |
12527 | 443 return; |
10725 | 444 break; |
445 case ID_LFE: | |
446 hDecoder->has_lfe++; | |
12527 | 447 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele); |
10725 | 448 if (hInfo->error > 0) |
12527 | 449 return; |
10725 | 450 break; |
451 case ID_CCE: /* not implemented yet, but skip the bits */ | |
12527 | 452 #ifdef COUPLING_DEC |
10725 | 453 hInfo->error = coupling_channel_element(hDecoder, ld); |
12527 | 454 #else |
455 hInfo->error = 6; | |
456 #endif | |
10725 | 457 if (hInfo->error > 0) |
12527 | 458 return; |
10725 | 459 break; |
460 case ID_DSE: | |
461 data_stream_element(hDecoder, ld); | |
462 break; | |
463 case ID_PCE: | |
12527 | 464 /* 14496-4: 5.6.4.1.2.1.3: */ |
465 /* program_configuration_element()'s in access units shall be ignored */ | |
466 program_config_element(pce, ld); | |
467 //if ((hInfo->error = program_config_element(pce, ld)) > 0) | |
468 // return; | |
469 //hDecoder->pce_set = 1; | |
10725 | 470 break; |
471 case ID_FIL: | |
472 /* one sbr_info describes a channel_element not a channel! */ | |
12527 | 473 /* if we encounter SBR data here: error */ |
474 /* SBR data will be read directly in the SCE/LFE/CPE element */ | |
10725 | 475 if ((hInfo->error = fill_element(hDecoder, ld, drc |
476 #ifdef SBR_DEC | |
12527 | 477 , INVALID_SBR_ELEMENT |
10725 | 478 #endif |
479 )) > 0) | |
12527 | 480 return; |
10725 | 481 break; |
482 } | |
483 } | |
484 #ifdef ERROR_RESILIENCE | |
485 } else { | |
486 /* Table 262: er_raw_data_block() */ | |
487 switch (hDecoder->channelConfiguration) | |
488 { | |
489 case 1: | |
12527 | 490 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); |
10725 | 491 if (hInfo->error > 0) |
12527 | 492 return; |
10725 | 493 break; |
494 case 2: | |
12527 | 495 decode_cpe(hDecoder, hInfo, ld, ID_CPE); |
10725 | 496 if (hInfo->error > 0) |
12527 | 497 return; |
10725 | 498 break; |
499 case 3: | |
12527 | 500 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); |
501 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
10725 | 502 if (hInfo->error > 0) |
12527 | 503 return; |
10725 | 504 break; |
505 case 4: | |
12527 | 506 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); |
507 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
508 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); | |
10725 | 509 if (hInfo->error > 0) |
12527 | 510 return; |
10725 | 511 break; |
512 case 5: | |
12527 | 513 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); |
514 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
515 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
10725 | 516 if (hInfo->error > 0) |
12527 | 517 return; |
10725 | 518 break; |
519 case 6: | |
12527 | 520 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); |
521 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
522 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
523 decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE); | |
10725 | 524 if (hInfo->error > 0) |
12527 | 525 return; |
10725 | 526 break; |
12527 | 527 case 7: /* 8 channels */ |
528 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE); | |
529 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
530 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
531 decode_cpe(hDecoder, hInfo, ld, ID_CPE); | |
532 decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE); | |
10725 | 533 if (hInfo->error > 0) |
12527 | 534 return; |
10725 | 535 break; |
536 default: | |
537 hInfo->error = 7; | |
12527 | 538 return; |
10725 | 539 } |
540 #if 0 | |
541 cnt = bits_to_decode() / 8; | |
542 while (cnt >= 1) | |
543 { | |
544 cnt -= extension_payload(cnt); | |
545 } | |
546 #endif | |
547 } | |
548 #endif | |
549 | |
550 /* new in corrigendum 14496-3:2002 */ | |
10989 | 551 #ifdef DRM |
552 if (hDecoder->object_type != DRM_ER_LC) | |
553 #endif | |
554 { | |
555 faad_byte_align(ld); | |
556 } | |
10725 | 557 |
12527 | 558 return; |
10725 | 559 } |
560 | |
561 /* Table 4.4.4 and */ | |
562 /* Table 4.4.9 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
563 static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld, |
12527 | 564 uint8_t channel, uint8_t *tag) |
10725 | 565 { |
10989 | 566 uint8_t retval = 0; |
12527 | 567 element sce = {0}; |
568 ic_stream *ics = &(sce.ics1); | |
569 ALIGN int16_t spec_data[1024] = {0}; | |
10725 | 570 |
12527 | 571 sce.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG |
10725 | 572 DEBUGVAR(1,38,"single_lfe_channel_element(): element_instance_tag")); |
573 | |
12527 | 574 *tag = sce.element_instance_tag; |
575 sce.channel = channel; | |
576 sce.paired_channel = -1; | |
10725 | 577 |
12527 | 578 retval = individual_channel_stream(hDecoder, &sce, ld, ics, 0, spec_data); |
579 if (retval > 0) | |
580 return retval; | |
10725 | 581 |
12527 | 582 #ifdef SBR_DEC |
583 /* check if next bitstream element is a fill element */ | |
584 /* if so, read it now so SBR decoding can be done in case of a file with SBR */ | |
585 if (faad_showbits(ld, LEN_SE_ID) == ID_FIL) | |
586 { | |
587 faad_flushbits(ld, LEN_SE_ID); | |
588 | |
589 /* one sbr_info describes a channel_element not a channel! */ | |
590 if ((retval = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0) | |
10725 | 591 { |
12527 | 592 return retval; |
10725 | 593 } |
12527 | 594 } |
10725 | 595 #endif |
10989 | 596 |
597 /* noiseless coding is done, spectral reconstruction is done now */ | |
12527 | 598 retval = reconstruct_single_channel(hDecoder, ics, &sce, spec_data); |
599 if (retval > 0) | |
600 return retval; | |
10989 | 601 |
602 return 0; | |
10725 | 603 } |
604 | |
605 /* Table 4.4.5 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
606 static uint8_t channel_pair_element(NeAACDecHandle hDecoder, bitfile *ld, |
12527 | 607 uint8_t channels, uint8_t *tag) |
10725 | 608 { |
12527 | 609 ALIGN int16_t spec_data1[1024] = {0}; |
610 ALIGN int16_t spec_data2[1024] = {0}; | |
611 element cpe = {0}; | |
612 ic_stream *ics1 = &(cpe.ics1); | |
613 ic_stream *ics2 = &(cpe.ics2); | |
10725 | 614 uint8_t result; |
12527 | 615 |
616 cpe.channel = channels; | |
617 cpe.paired_channel = channels+1; | |
10725 | 618 |
12527 | 619 cpe.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG |
10725 | 620 DEBUGVAR(1,39,"channel_pair_element(): element_instance_tag")); |
12527 | 621 *tag = cpe.element_instance_tag; |
10725 | 622 |
12527 | 623 if ((cpe.common_window = faad_get1bit(ld |
10725 | 624 DEBUGVAR(1,40,"channel_pair_element(): common_window"))) & 1) |
625 { | |
626 /* both channels have common ics information */ | |
12527 | 627 if ((result = ics_info(hDecoder, ics1, ld, cpe.common_window)) > 0) |
10725 | 628 return result; |
629 | |
630 ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2 | |
631 DEBUGVAR(1,41,"channel_pair_element(): ms_mask_present")); | |
632 if (ics1->ms_mask_present == 1) | |
633 { | |
634 uint8_t g, sfb; | |
635 for (g = 0; g < ics1->num_window_groups; g++) | |
636 { | |
637 for (sfb = 0; sfb < ics1->max_sfb; sfb++) | |
638 { | |
639 ics1->ms_used[g][sfb] = faad_get1bit(ld | |
640 DEBUGVAR(1,42,"channel_pair_element(): faad_get1bit")); | |
641 } | |
642 } | |
643 } | |
644 | |
645 #ifdef ERROR_RESILIENCE | |
646 if ((hDecoder->object_type >= ER_OBJECT_START) && (ics1->predictor_data_present)) | |
647 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
648 if (( |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
649 #ifdef LTP_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
650 ics1->ltp.data_present = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
651 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
652 faad_get1bit(ld DEBUGVAR(1,50,"channel_pair_element(): ltp.data_present"))) & 1) |
10725 | 653 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
654 #ifdef LTP_DEC |
12527 | 655 if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp), ld)) > 0) |
656 { | |
657 return result; | |
658 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
659 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
660 return 26; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
661 #endif |
10725 | 662 } |
663 } | |
664 #endif | |
665 | |
666 memcpy(ics2, ics1, sizeof(ic_stream)); | |
667 } else { | |
668 ics1->ms_mask_present = 0; | |
669 } | |
670 | |
12527 | 671 if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics1, |
10725 | 672 0, spec_data1)) > 0) |
673 { | |
674 return result; | |
675 } | |
676 | |
677 #ifdef ERROR_RESILIENCE | |
12527 | 678 if (cpe.common_window && (hDecoder->object_type >= ER_OBJECT_START) && |
10725 | 679 (ics1->predictor_data_present)) |
680 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
681 if (( |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
682 #ifdef LTP_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
683 ics1->ltp2.data_present = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
684 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
685 faad_get1bit(ld DEBUGVAR(1,50,"channel_pair_element(): ltp.data_present"))) & 1) |
10725 | 686 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
687 #ifdef LTP_DEC |
12527 | 688 if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp2), ld)) > 0) |
689 { | |
690 return result; | |
691 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
692 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
693 return 26; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
694 #endif |
10725 | 695 } |
696 } | |
697 #endif | |
698 | |
12527 | 699 if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics2, |
10725 | 700 0, spec_data2)) > 0) |
701 { | |
702 return result; | |
703 } | |
704 | |
12527 | 705 #ifdef SBR_DEC |
706 /* check if next bitstream element is a fill element */ | |
707 /* if so, read it now so SBR decoding can be done in case of a file with SBR */ | |
708 if (faad_showbits(ld, LEN_SE_ID) == ID_FIL) | |
10725 | 709 { |
12527 | 710 faad_flushbits(ld, LEN_SE_ID); |
10725 | 711 |
12527 | 712 /* one sbr_info describes a channel_element not a channel! */ |
713 if ((result = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0) | |
714 { | |
10725 | 715 return result; |
716 } | |
10989 | 717 } |
10725 | 718 #endif |
719 | |
10989 | 720 /* noiseless coding is done, spectral reconstruction is done now */ |
12527 | 721 if ((result = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe, |
722 spec_data1, spec_data2)) > 0) | |
723 { | |
724 return result; | |
725 } | |
10989 | 726 |
10725 | 727 return 0; |
728 } | |
729 | |
730 /* Table 4.4.6 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
731 static uint8_t ics_info(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld, |
10725 | 732 uint8_t common_window) |
733 { | |
734 uint8_t retval = 0; | |
735 | |
736 /* ics->ics_reserved_bit = */ faad_get1bit(ld | |
737 DEBUGVAR(1,43,"ics_info(): ics_reserved_bit")); | |
738 ics->window_sequence = (uint8_t)faad_getbits(ld, 2 | |
739 DEBUGVAR(1,44,"ics_info(): window_sequence")); | |
740 ics->window_shape = faad_get1bit(ld | |
741 DEBUGVAR(1,45,"ics_info(): window_shape")); | |
742 | |
743 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
744 { | |
745 ics->max_sfb = (uint8_t)faad_getbits(ld, 4 | |
746 DEBUGVAR(1,46,"ics_info(): max_sfb (short)")); | |
747 ics->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7 | |
748 DEBUGVAR(1,47,"ics_info(): scale_factor_grouping")); | |
749 } else { | |
750 ics->max_sfb = (uint8_t)faad_getbits(ld, 6 | |
751 DEBUGVAR(1,48,"ics_info(): max_sfb (long)")); | |
752 } | |
753 | |
754 /* get the grouping information */ | |
755 if ((retval = window_grouping_info(hDecoder, ics)) > 0) | |
756 return retval; | |
757 | |
758 /* should be an error */ | |
759 /* check the range of max_sfb */ | |
760 if (ics->max_sfb > ics->num_swb) | |
761 return 16; | |
762 | |
763 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | |
764 { | |
765 if ((ics->predictor_data_present = faad_get1bit(ld | |
766 DEBUGVAR(1,49,"ics_info(): predictor_data_present"))) & 1) | |
767 { | |
768 if (hDecoder->object_type == MAIN) /* MPEG2 style AAC predictor */ | |
769 { | |
770 uint8_t sfb; | |
771 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
772 uint8_t limit = min(ics->max_sfb, max_pred_sfb(hDecoder->sf_index)); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
773 #ifdef MAIN_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
774 ics->pred.limit = limit; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
775 #endif |
10725 | 776 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
777 if (( |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
778 #ifdef MAIN_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
779 ics->pred.predictor_reset = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
780 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
781 faad_get1bit(ld DEBUGVAR(1,53,"ics_info(): pred.predictor_reset"))) & 1) |
10725 | 782 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
783 #ifdef MAIN_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
784 ics->pred.predictor_reset_group_number = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
785 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
786 (uint8_t)faad_getbits(ld, 5 DEBUGVAR(1,54,"ics_info(): pred.predictor_reset_group_number")); |
10725 | 787 } |
788 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
789 for (sfb = 0; sfb < limit; sfb++) |
10725 | 790 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
791 #ifdef MAIN_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
792 ics->pred.prediction_used[sfb] = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
793 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
794 faad_get1bit(ld DEBUGVAR(1,55,"ics_info(): pred.prediction_used")); |
10725 | 795 } |
796 } | |
797 #ifdef LTP_DEC | |
798 else { /* Long Term Prediction */ | |
799 if (hDecoder->object_type < ER_OBJECT_START) | |
800 { | |
801 if ((ics->ltp.data_present = faad_get1bit(ld | |
802 DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1) | |
803 { | |
12527 | 804 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0) |
805 { | |
806 return retval; | |
807 } | |
10725 | 808 } |
809 if (common_window) | |
810 { | |
811 if ((ics->ltp2.data_present = faad_get1bit(ld | |
812 DEBUGVAR(1,51,"ics_info(): ltp2.data_present"))) & 1) | |
813 { | |
12527 | 814 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp2), ld)) > 0) |
815 { | |
816 return retval; | |
817 } | |
10725 | 818 } |
819 } | |
820 } | |
821 #ifdef ERROR_RESILIENCE | |
822 if (!common_window && (hDecoder->object_type >= ER_OBJECT_START)) | |
823 { | |
824 if ((ics->ltp.data_present = faad_get1bit(ld | |
825 DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1) | |
826 { | |
827 ltp_data(hDecoder, ics, &(ics->ltp), ld); | |
828 } | |
829 } | |
830 #endif | |
831 } | |
832 #endif | |
833 } | |
834 } | |
835 | |
836 return retval; | |
837 } | |
838 | |
839 /* Table 4.4.7 */ | |
840 static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld) | |
841 { | |
842 uint8_t i; | |
843 | |
844 pul->number_pulse = (uint8_t)faad_getbits(ld, 2 | |
845 DEBUGVAR(1,56,"pulse_data(): number_pulse")); | |
846 pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6 | |
847 DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb")); | |
848 | |
849 /* check the range of pulse_start_sfb */ | |
850 if (pul->pulse_start_sfb > ics->num_swb) | |
851 return 16; | |
852 | |
853 for (i = 0; i < pul->number_pulse+1; i++) | |
854 { | |
855 pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5 | |
856 DEBUGVAR(1,58,"pulse_data(): pulse_offset")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
857 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
858 printf("%d\n", pul->pulse_offset[i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
859 #endif |
10725 | 860 pul->pulse_amp[i] = (uint8_t)faad_getbits(ld, 4 |
861 DEBUGVAR(1,59,"pulse_data(): pulse_amp")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
862 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
863 printf("%d\n", pul->pulse_amp[i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
864 #endif |
10725 | 865 } |
866 | |
867 return 0; | |
868 } | |
869 | |
12527 | 870 #ifdef COUPLING_DEC |
10725 | 871 /* Table 4.4.8: Currently just for skipping the bits... */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
872 static uint8_t coupling_channel_element(NeAACDecHandle hDecoder, bitfile *ld) |
10725 | 873 { |
874 uint8_t c, result = 0; | |
875 uint8_t ind_sw_cce_flag = 0; | |
876 uint8_t num_gain_element_lists = 0; | |
877 uint8_t num_coupled_elements = 0; | |
878 | |
12527 | 879 element el_empty = {0}; |
880 ic_stream ics_empty = {0}; | |
10725 | 881 int16_t sh_data[1024]; |
882 | |
883 c = faad_getbits(ld, LEN_TAG | |
884 DEBUGVAR(1,900,"coupling_channel_element(): element_instance_tag")); | |
885 | |
886 ind_sw_cce_flag = faad_get1bit(ld | |
887 DEBUGVAR(1,901,"coupling_channel_element(): ind_sw_cce_flag")); | |
888 num_coupled_elements = faad_getbits(ld, 3 | |
889 DEBUGVAR(1,902,"coupling_channel_element(): num_coupled_elements")); | |
890 | |
891 for (c = 0; c < num_coupled_elements + 1; c++) | |
892 { | |
893 uint8_t cc_target_is_cpe, cc_target_tag_select; | |
894 | |
895 num_gain_element_lists++; | |
896 | |
897 cc_target_is_cpe = faad_get1bit(ld | |
898 DEBUGVAR(1,903,"coupling_channel_element(): cc_target_is_cpe")); | |
899 cc_target_tag_select = faad_getbits(ld, 4 | |
900 DEBUGVAR(1,904,"coupling_channel_element(): cc_target_tag_select")); | |
901 | |
902 if (cc_target_is_cpe) | |
903 { | |
904 uint8_t cc_l = faad_get1bit(ld | |
905 DEBUGVAR(1,905,"coupling_channel_element(): cc_l")); | |
906 uint8_t cc_r = faad_get1bit(ld | |
907 DEBUGVAR(1,906,"coupling_channel_element(): cc_r")); | |
908 | |
909 if (cc_l && cc_r) | |
910 num_gain_element_lists++; | |
911 } | |
912 } | |
913 | |
914 faad_get1bit(ld | |
915 DEBUGVAR(1,907,"coupling_channel_element(): cc_domain")); | |
916 faad_get1bit(ld | |
917 DEBUGVAR(1,908,"coupling_channel_element(): gain_element_sign")); | |
918 faad_getbits(ld, 2 | |
919 DEBUGVAR(1,909,"coupling_channel_element(): gain_element_scale")); | |
920 | |
921 if ((result = individual_channel_stream(hDecoder, &el_empty, ld, &ics_empty, | |
922 0, sh_data)) > 0) | |
923 { | |
924 return result; | |
925 } | |
926 | |
927 for (c = 1; c < num_gain_element_lists; c++) | |
928 { | |
929 uint8_t cge; | |
930 | |
931 if (ind_sw_cce_flag) | |
932 { | |
933 cge = 1; | |
934 } else { | |
935 cge = faad_get1bit(ld | |
936 DEBUGVAR(1,910,"coupling_channel_element(): common_gain_element_present")); | |
937 } | |
938 | |
939 if (cge) | |
940 { | |
941 huffman_scale_factor(ld); | |
942 } else { | |
943 uint8_t g, sfb; | |
944 | |
945 for (g = 0; g < ics_empty.num_window_groups; g++) | |
946 { | |
947 for (sfb = 0; sfb < ics_empty.max_sfb; sfb++) | |
948 { | |
949 if (ics_empty.sfb_cb[g][sfb] != ZERO_HCB) | |
950 huffman_scale_factor(ld); | |
951 } | |
952 } | |
953 } | |
954 } | |
955 | |
956 return 0; | |
957 } | |
12527 | 958 #endif |
10725 | 959 |
960 /* Table 4.4.10 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
961 static uint16_t data_stream_element(NeAACDecHandle hDecoder, bitfile *ld) |
10725 | 962 { |
963 uint8_t byte_aligned; | |
964 uint16_t i, count; | |
965 | |
966 /* element_instance_tag = */ faad_getbits(ld, LEN_TAG | |
967 DEBUGVAR(1,60,"data_stream_element(): element_instance_tag")); | |
968 byte_aligned = faad_get1bit(ld | |
969 DEBUGVAR(1,61,"data_stream_element(): byte_aligned")); | |
970 count = (uint16_t)faad_getbits(ld, 8 | |
971 DEBUGVAR(1,62,"data_stream_element(): count")); | |
972 if (count == 255) | |
973 { | |
974 count += (uint16_t)faad_getbits(ld, 8 | |
975 DEBUGVAR(1,63,"data_stream_element(): extra count")); | |
976 } | |
977 if (byte_aligned) | |
978 faad_byte_align(ld); | |
979 | |
980 for (i = 0; i < count; i++) | |
981 { | |
12527 | 982 faad_getbits(ld, LEN_BYTE |
10725 | 983 DEBUGVAR(1,64,"data_stream_element(): data_stream_byte")); |
984 } | |
985 | |
986 return count; | |
987 } | |
988 | |
989 /* Table 4.4.11 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
990 static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc |
10725 | 991 #ifdef SBR_DEC |
992 ,uint8_t sbr_ele | |
993 #endif | |
994 ) | |
995 { | |
996 uint16_t count; | |
997 #ifdef SBR_DEC | |
998 uint8_t bs_extension_type; | |
999 #endif | |
1000 | |
1001 count = (uint16_t)faad_getbits(ld, 4 | |
1002 DEBUGVAR(1,65,"fill_element(): count")); | |
1003 if (count == 15) | |
1004 { | |
1005 count += (uint16_t)faad_getbits(ld, 8 | |
1006 DEBUGVAR(1,66,"fill_element(): extra count")) - 1; | |
1007 } | |
1008 | |
1009 if (count > 0) | |
1010 { | |
1011 #ifdef SBR_DEC | |
1012 bs_extension_type = (uint8_t)faad_showbits(ld, 4); | |
1013 | |
1014 if ((bs_extension_type == EXT_SBR_DATA) || | |
1015 (bs_extension_type == EXT_SBR_DATA_CRC)) | |
1016 { | |
12527 | 1017 if (sbr_ele == INVALID_SBR_ELEMENT) |
1018 return 24; | |
10725 | 1019 |
1020 if (!hDecoder->sbr[sbr_ele]) | |
10989 | 1021 { |
12527 | 1022 hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength, |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1023 hDecoder->element_id[sbr_ele], 2*get_sample_rate(hDecoder->sf_index), |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1024 hDecoder->downSampledSBR |
10989 | 1025 #ifdef DRM |
1026 , 0 | |
1027 #endif | |
1028 ); | |
1029 } | |
10725 | 1030 |
12527 | 1031 hDecoder->sbr_present_flag = 1; |
1032 | |
1033 /* parse the SBR data */ | |
1034 hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1035 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1036 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1037 if (hDecoder->sbr[sbr_ele]->ret > 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1038 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1039 printf("%s\n", NeAACDecGetErrorMessage(hDecoder->sbr[sbr_ele]->ret)); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1040 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1041 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1042 |
12527 | 1043 #if (defined(PS_DEC) || defined(DRM_PS)) |
1044 if (hDecoder->sbr[sbr_ele]->ps_used) | |
1045 { | |
1046 hDecoder->ps_used[sbr_ele] = 1; | |
1047 } | |
1048 #endif | |
10725 | 1049 } else { |
1050 #endif | |
1051 while (count > 0) | |
1052 { | |
1053 count -= extension_payload(ld, drc, count); | |
1054 } | |
1055 #ifdef SBR_DEC | |
1056 } | |
1057 #endif | |
1058 } | |
1059 | |
1060 return 0; | |
1061 } | |
1062 | |
1063 /* Table 4.4.12 */ | |
1064 #ifdef SSR_DEC | |
1065 static void gain_control_data(bitfile *ld, ic_stream *ics) | |
1066 { | |
1067 uint8_t bd, wd, ad; | |
1068 ssr_info *ssr = &(ics->ssr); | |
1069 | |
1070 ssr->max_band = (uint8_t)faad_getbits(ld, 2 | |
1071 DEBUGVAR(1,1000,"gain_control_data(): max_band")); | |
1072 | |
1073 if (ics->window_sequence == ONLY_LONG_SEQUENCE) | |
1074 { | |
1075 for (bd = 1; bd <= ssr->max_band; bd++) | |
1076 { | |
1077 for (wd = 0; wd < 1; wd++) | |
1078 { | |
1079 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3 | |
1080 DEBUGVAR(1,1001,"gain_control_data(): adjust_num")); | |
1081 | |
1082 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) | |
1083 { | |
1084 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1085 DEBUGVAR(1,1002,"gain_control_data(): alevcode")); | |
1086 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5 | |
1087 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1088 } | |
1089 } | |
1090 } | |
1091 } else if (ics->window_sequence == LONG_START_SEQUENCE) { | |
1092 for (bd = 1; bd <= ssr->max_band; bd++) | |
1093 { | |
1094 for (wd = 0; wd < 2; wd++) | |
1095 { | |
1096 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3 | |
1097 DEBUGVAR(1,1001,"gain_control_data(): adjust_num")); | |
1098 | |
1099 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) | |
1100 { | |
1101 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1102 DEBUGVAR(1,1002,"gain_control_data(): alevcode")); | |
1103 if (wd == 0) | |
1104 { | |
1105 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1106 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1107 } else { | |
1108 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2 | |
1109 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1110 } | |
1111 } | |
1112 } | |
1113 } | |
1114 } else if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { | |
1115 for (bd = 1; bd <= ssr->max_band; bd++) | |
1116 { | |
1117 for (wd = 0; wd < 8; wd++) | |
1118 { | |
1119 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3 | |
1120 DEBUGVAR(1,1001,"gain_control_data(): adjust_num")); | |
1121 | |
1122 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) | |
1123 { | |
1124 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1125 DEBUGVAR(1,1002,"gain_control_data(): alevcode")); | |
1126 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2 | |
1127 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1128 } | |
1129 } | |
1130 } | |
1131 } else if (ics->window_sequence == LONG_STOP_SEQUENCE) { | |
1132 for (bd = 1; bd <= ssr->max_band; bd++) | |
1133 { | |
1134 for (wd = 0; wd < 2; wd++) | |
1135 { | |
1136 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3 | |
1137 DEBUGVAR(1,1001,"gain_control_data(): adjust_num")); | |
1138 | |
1139 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) | |
1140 { | |
1141 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1142 DEBUGVAR(1,1002,"gain_control_data(): alevcode")); | |
1143 | |
1144 if (wd == 0) | |
1145 { | |
1146 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4 | |
1147 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1148 } else { | |
1149 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5 | |
1150 DEBUGVAR(1,1003,"gain_control_data(): aloccode")); | |
1151 } | |
1152 } | |
1153 } | |
1154 } | |
1155 } | |
1156 } | |
1157 #endif | |
1158 | |
12527 | 1159 #ifdef SCALABLE_DEC |
1160 /* Table 4.4.13 ASME */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1161 void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
12527 | 1162 bitfile *ld, program_config *pce, drc_info *drc) |
1163 { | |
1164 uint8_t retval = 0; | |
1165 uint8_t channels = hDecoder->fr_channels = 0; | |
1166 uint8_t ch; | |
1167 uint8_t this_layer_stereo = (hDecoder->channelConfiguration > 1) ? 1 : 0; | |
1168 element cpe = {0}; | |
1169 ic_stream *ics1 = &(cpe.ics1); | |
1170 ic_stream *ics2 = &(cpe.ics2); | |
1171 int16_t *spec_data; | |
1172 ALIGN int16_t spec_data1[1024] = {0}; | |
1173 ALIGN int16_t spec_data2[1024] = {0}; | |
1174 | |
1175 hDecoder->fr_ch_ele = 0; | |
1176 | |
1177 hInfo->error = aac_scalable_main_header(hDecoder, ics1, ics2, ld, this_layer_stereo); | |
1178 if (hInfo->error > 0) | |
1179 return; | |
1180 | |
1181 cpe.common_window = 1; | |
1182 if (this_layer_stereo) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1183 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1184 hDecoder->element_id[0] = ID_CPE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1185 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1186 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1187 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1188 hDecoder->element_id[0] = ID_SCE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1189 } |
12527 | 1190 |
1191 for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++) | |
1192 { | |
1193 ic_stream *ics; | |
1194 if (ch == 0) | |
1195 { | |
1196 ics = ics1; | |
1197 spec_data = spec_data1; | |
1198 } else { | |
1199 ics = ics2; | |
1200 spec_data = spec_data2; | |
1201 } | |
1202 | |
1203 hInfo->error = individual_channel_stream(hDecoder, &cpe, ld, ics, 1, spec_data); | |
1204 if (hInfo->error > 0) | |
1205 return; | |
1206 } | |
1207 | |
1208 #ifdef DRM | |
1209 #ifdef SBR_DEC | |
1210 /* In case of DRM we need to read the SBR info before channel reconstruction */ | |
1211 if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC)) | |
1212 { | |
1213 bitfile ld_sbr = {0}; | |
1214 uint32_t i; | |
1215 uint16_t count = 0; | |
1216 uint8_t *revbuffer; | |
1217 uint8_t *prevbufstart; | |
1218 uint8_t *pbufend; | |
1219 | |
1220 /* all forward bitreading should be finished at this point */ | |
1221 uint32_t bitsconsumed = faad_get_processed_bits(ld); | |
1222 uint32_t buffer_size = faad_origbitbuffer_size(ld); | |
1223 uint8_t *buffer = (uint8_t*)faad_origbitbuffer(ld); | |
1224 | |
1225 if (bitsconsumed + 8 > buffer_size*8) | |
1226 { | |
1227 hInfo->error = 14; | |
1228 return; | |
1229 } | |
1230 | |
1231 if (!hDecoder->sbr[0]) | |
1232 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1233 hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0], |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1234 2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1); |
12527 | 1235 } |
1236 | |
1237 /* Reverse bit reading of SBR data in DRM audio frame */ | |
1238 revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t)); | |
1239 prevbufstart = revbuffer; | |
1240 pbufend = &buffer[buffer_size - 1]; | |
1241 for (i = 0; i < buffer_size; i++) | |
1242 *prevbufstart++ = tabFlipbits[*pbufend--]; | |
1243 | |
1244 /* Set SBR data */ | |
1245 /* consider 8 bits from AAC-CRC */ | |
1246 count = (uint16_t)bit2byte(buffer_size*8 - bitsconsumed); | |
1247 faad_initbits(&ld_sbr, revbuffer, count); | |
1248 | |
1249 hDecoder->sbr[0]->sample_rate = get_sample_rate(hDecoder->sf_index); | |
1250 hDecoder->sbr[0]->sample_rate *= 2; | |
1251 | |
1252 faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */ | |
1253 | |
1254 hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count); | |
1255 #if (defined(PS_DEC) || defined(DRM_PS)) | |
1256 if (hDecoder->sbr[0]->ps_used) | |
1257 { | |
1258 hDecoder->ps_used[0] = 1; | |
1259 } | |
1260 #endif | |
1261 | |
1262 /* check CRC */ | |
1263 /* no need to check it if there was already an error */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1264 // if (hDecoder->sbr[0]->ret == 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1265 // hDecoder->sbr[0]->ret = (uint8_t)faad_check_CRC(&ld_sbr, (uint16_t)faad_get_processed_bits(&ld_sbr) - 8); |
12527 | 1266 |
1267 faad_endbits(&ld_sbr); | |
1268 | |
1269 if (revbuffer) | |
1270 faad_free(revbuffer); | |
1271 } | |
1272 #endif | |
1273 #endif | |
1274 | |
1275 if (this_layer_stereo) | |
1276 { | |
1277 hInfo->error = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe, spec_data1, spec_data2); | |
1278 if (hInfo->error > 0) | |
1279 return; | |
1280 } else { | |
1281 hInfo->error = reconstruct_single_channel(hDecoder, ics1, &cpe, spec_data1); | |
1282 if (hInfo->error > 0) | |
1283 return; | |
1284 } | |
1285 | |
1286 /* map output channels position to internal data channels */ | |
1287 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2) | |
1288 { | |
1289 /* this might be faulty when pce_set is true */ | |
1290 hDecoder->internal_channel[channels] = channels; | |
1291 hDecoder->internal_channel[channels+1] = channels+1; | |
1292 } else { | |
1293 hDecoder->internal_channel[channels] = channels; | |
1294 } | |
1295 | |
1296 hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele]; | |
1297 hDecoder->fr_ch_ele++; | |
1298 | |
1299 return; | |
1300 } | |
1301 | |
1302 /* Table 4.4.15 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1303 static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, |
12527 | 1304 bitfile *ld, uint8_t this_layer_stereo) |
1305 { | |
1306 uint8_t retval = 0; | |
1307 uint8_t ch; | |
1308 ic_stream *ics; | |
1309 | |
1310 /* ics1->ics_reserved_bit = */ faad_get1bit(ld | |
1311 DEBUGVAR(1,300,"aac_scalable_main_header(): ics_reserved_bits")); | |
1312 ics1->window_sequence = (uint8_t)faad_getbits(ld, 2 | |
1313 DEBUGVAR(1,301,"aac_scalable_main_header(): window_sequence")); | |
1314 ics1->window_shape = faad_get1bit(ld | |
1315 DEBUGVAR(1,302,"aac_scalable_main_header(): window_shape")); | |
1316 | |
1317 if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE) | |
1318 { | |
1319 ics1->max_sfb = (uint8_t)faad_getbits(ld, 4 | |
1320 DEBUGVAR(1,303,"aac_scalable_main_header(): max_sfb (short)")); | |
1321 ics1->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7 | |
1322 DEBUGVAR(1,304,"aac_scalable_main_header(): scale_factor_grouping")); | |
1323 } else { | |
1324 ics1->max_sfb = (uint8_t)faad_getbits(ld, 6 | |
1325 DEBUGVAR(1,305,"aac_scalable_main_header(): max_sfb (long)")); | |
1326 } | |
1327 | |
1328 /* get the grouping information */ | |
1329 if ((retval = window_grouping_info(hDecoder, ics1)) > 0) | |
1330 return retval; | |
1331 | |
1332 /* should be an error */ | |
1333 /* check the range of max_sfb */ | |
1334 if (ics1->max_sfb > ics1->num_swb) | |
1335 return 16; | |
1336 | |
1337 if (this_layer_stereo) | |
1338 { | |
1339 ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2 | |
1340 DEBUGVAR(1,306,"aac_scalable_main_header(): ms_mask_present")); | |
1341 if (ics1->ms_mask_present == 1) | |
1342 { | |
1343 uint8_t g, sfb; | |
1344 for (g = 0; g < ics1->num_window_groups; g++) | |
1345 { | |
1346 for (sfb = 0; sfb < ics1->max_sfb; sfb++) | |
1347 { | |
1348 ics1->ms_used[g][sfb] = faad_get1bit(ld | |
1349 DEBUGVAR(1,307,"aac_scalable_main_header(): faad_get1bit")); | |
1350 } | |
1351 } | |
1352 } | |
1353 | |
1354 memcpy(ics2, ics1, sizeof(ic_stream)); | |
1355 } else { | |
1356 ics1->ms_mask_present = 0; | |
1357 } | |
1358 | |
1359 if (0) | |
1360 { | |
1361 faad_get1bit(ld | |
1362 DEBUGVAR(1,308,"aac_scalable_main_header(): tns_channel_mono_layer")); | |
1363 } | |
1364 | |
1365 for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++) | |
1366 { | |
1367 if (ch == 0) | |
1368 ics = ics1; | |
1369 else | |
1370 ics = ics2; | |
1371 | |
1372 if ( 1 /*!tvq_layer_pesent || (tns_aac_tvq_en[ch] == 1)*/) | |
1373 { | |
1374 if ((ics->tns_data_present = faad_get1bit(ld | |
1375 DEBUGVAR(1,309,"aac_scalable_main_header(): tns_data_present"))) & 1) | |
1376 { | |
1377 #ifdef DRM | |
1378 /* different order of data units in DRM */ | |
1379 if (hDecoder->object_type != DRM_ER_LC) | |
1380 #endif | |
1381 { | |
1382 tns_data(ics, &(ics->tns), ld); | |
1383 } | |
1384 } | |
1385 } | |
1386 #if 0 | |
1387 if (0 /*core_flag || tvq_layer_pesent*/) | |
1388 { | |
1389 if ((ch==0) || ((ch==1) && (core_stereo || tvq_stereo)) | |
1390 diff_control_data(); | |
1391 if (mono_stereo_flag) | |
1392 diff_control_data_lr(); | |
1393 } else { | |
1394 #endif | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1395 if (( |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1396 #ifdef LTP_DEC |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1397 ics->ltp.data_present = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1398 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1399 faad_get1bit(ld DEBUGVAR(1,310,"aac_scalable_main_header(): ltp.data_present"))) & 1) |
12527 | 1400 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1401 #ifdef LTP_DEC |
12527 | 1402 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0) |
1403 { | |
1404 return retval; | |
1405 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1406 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1407 return 26; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1408 #endif |
12527 | 1409 } |
1410 #if 0 | |
1411 } | |
1412 #endif | |
1413 } | |
1414 | |
1415 return 0; | |
1416 } | |
1417 #endif | |
1418 | |
10725 | 1419 /* Table 4.4.24 */ |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1420 static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele, |
10725 | 1421 bitfile *ld, ic_stream *ics, uint8_t scal_flag, |
1422 int16_t *spec_data) | |
1423 { | |
1424 uint8_t result; | |
1425 | |
1426 ics->global_gain = (uint8_t)faad_getbits(ld, 8 | |
1427 DEBUGVAR(1,67,"individual_channel_stream(): global_gain")); | |
1428 | |
1429 if (!ele->common_window && !scal_flag) | |
1430 { | |
1431 if ((result = ics_info(hDecoder, ics, ld, ele->common_window)) > 0) | |
1432 return result; | |
1433 } | |
1434 | |
1435 if ((result = section_data(hDecoder, ics, ld)) > 0) | |
1436 return result; | |
1437 | |
1438 if ((result = scale_factor_data(hDecoder, ics, ld)) > 0) | |
1439 return result; | |
1440 | |
1441 if (!scal_flag) | |
1442 { | |
1443 /** | |
1444 ** NOTE: It could be that pulse data is available in scalable AAC too, | |
1445 ** as said in Amendment 1, this could be only the case for ER AAC, | |
1446 ** though. (have to check this out later) | |
1447 **/ | |
1448 /* get pulse data */ | |
1449 if ((ics->pulse_data_present = faad_get1bit(ld | |
1450 DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1) | |
1451 { | |
1452 if ((result = pulse_data(ics, &(ics->pul), ld)) > 0) | |
1453 return result; | |
1454 } | |
1455 | |
1456 /* get tns data */ | |
1457 if ((ics->tns_data_present = faad_get1bit(ld | |
1458 DEBUGVAR(1,69,"individual_channel_stream(): tns_data_present"))) & 1) | |
1459 { | |
1460 #ifdef ERROR_RESILIENCE | |
1461 if (hDecoder->object_type < ER_OBJECT_START) | |
1462 #endif | |
1463 tns_data(ics, &(ics->tns), ld); | |
1464 } | |
1465 | |
1466 /* get gain control data */ | |
1467 if ((ics->gain_control_data_present = faad_get1bit(ld | |
1468 DEBUGVAR(1,70,"individual_channel_stream(): gain_control_data_present"))) & 1) | |
1469 { | |
1470 #ifdef SSR_DEC | |
1471 if (hDecoder->object_type != SSR) | |
1472 return 1; | |
1473 else | |
1474 gain_control_data(ld, ics); | |
1475 #else | |
1476 return 1; | |
1477 #endif | |
1478 } | |
1479 } | |
1480 | |
1481 #ifdef ERROR_RESILIENCE | |
1482 if (hDecoder->aacSpectralDataResilienceFlag) | |
1483 { | |
1484 ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14 | |
1485 DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data")); | |
1486 | |
1487 if (hDecoder->channelConfiguration == 2) | |
1488 { | |
1489 if (ics->length_of_reordered_spectral_data > 6144) | |
1490 ics->length_of_reordered_spectral_data = 6144; | |
1491 } else { | |
1492 if (ics->length_of_reordered_spectral_data > 12288) | |
1493 ics->length_of_reordered_spectral_data = 12288; | |
1494 } | |
1495 | |
1496 ics->length_of_longest_codeword = (uint8_t)faad_getbits(ld, 6 | |
1497 DEBUGVAR(1,148,"individual_channel_stream(): length_of_longest_codeword")); | |
1498 if (ics->length_of_longest_codeword >= 49) | |
1499 ics->length_of_longest_codeword = 49; | |
1500 } | |
1501 | |
1502 /* RVLC spectral data is put here */ | |
1503 if (hDecoder->aacScalefactorDataResilienceFlag) | |
1504 { | |
1505 if ((result = rvlc_decode_scale_factors(ics, ld)) > 0) | |
1506 return result; | |
1507 } | |
1508 | |
1509 if (hDecoder->object_type >= ER_OBJECT_START) | |
1510 { | |
1511 if (ics->tns_data_present) | |
1512 tns_data(ics, &(ics->tns), ld); | |
1513 } | |
1514 | |
12527 | 1515 #ifdef DRM |
1516 /* CRC check */ | |
1517 if (hDecoder->object_type == DRM_ER_LC) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1518 if ((result = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0) |
12527 | 1519 return result; |
1520 #endif | |
1521 | |
10725 | 1522 if (hDecoder->aacSpectralDataResilienceFlag) |
1523 { | |
1524 /* error resilient spectral data decoding */ | |
1525 if ((result = reordered_spectral_data(hDecoder, ics, ld, spec_data)) > 0) | |
1526 { | |
1527 return result; | |
1528 } | |
1529 } else { | |
1530 #endif | |
1531 /* decode the spectral data */ | |
1532 if ((result = spectral_data(hDecoder, ics, ld, spec_data)) > 0) | |
1533 { | |
1534 return result; | |
1535 } | |
1536 #ifdef ERROR_RESILIENCE | |
1537 } | |
1538 #endif | |
1539 | |
1540 /* pulse coding reconstruction */ | |
1541 if (ics->pulse_data_present) | |
1542 { | |
1543 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | |
1544 { | |
1545 if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0) | |
1546 return result; | |
1547 } else { | |
1548 return 2; /* pulse coding not allowed for short blocks */ | |
1549 } | |
1550 } | |
1551 | |
1552 return 0; | |
1553 } | |
1554 | |
1555 /* Table 4.4.25 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1556 static uint8_t section_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld) |
10725 | 1557 { |
1558 uint8_t g; | |
1559 uint8_t sect_esc_val, sect_bits; | |
1560 | |
1561 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
1562 sect_bits = 3; | |
1563 else | |
1564 sect_bits = 5; | |
1565 sect_esc_val = (1<<sect_bits) - 1; | |
1566 | |
1567 #if 0 | |
1568 printf("\ntotal sfb %d\n", ics->max_sfb); | |
1569 printf(" sect top cb\n"); | |
1570 #endif | |
1571 | |
1572 for (g = 0; g < ics->num_window_groups; g++) | |
1573 { | |
1574 uint8_t k = 0; | |
1575 uint8_t i = 0; | |
1576 | |
1577 while (k < ics->max_sfb) | |
1578 { | |
1579 #ifdef ERROR_RESILIENCE | |
1580 uint8_t vcb11 = 0; | |
1581 #endif | |
1582 uint8_t sfb; | |
1583 uint8_t sect_len_incr; | |
1584 uint16_t sect_len = 0; | |
1585 uint8_t sect_cb_bits = 4; | |
1586 | |
1587 /* if "faad_getbits" detects error and returns "0", "k" is never | |
1588 incremented and we cannot leave the while loop */ | |
1589 if ((ld->error != 0) || (ld->no_more_reading)) | |
1590 return 14; | |
1591 | |
1592 #ifdef ERROR_RESILIENCE | |
1593 if (hDecoder->aacSectionDataResilienceFlag) | |
1594 sect_cb_bits = 5; | |
1595 #endif | |
1596 | |
1597 ics->sect_cb[g][i] = (uint8_t)faad_getbits(ld, sect_cb_bits | |
1598 DEBUGVAR(1,71,"section_data(): sect_cb")); | |
1599 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1600 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1601 printf("%d\n", ics->sect_cb[g][i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1602 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1603 |
10725 | 1604 if (ics->sect_cb[g][i] == NOISE_HCB) |
1605 ics->noise_used = 1; | |
1606 | |
1607 #ifdef ERROR_RESILIENCE | |
1608 if (hDecoder->aacSectionDataResilienceFlag) | |
1609 { | |
1610 if ((ics->sect_cb[g][i] == 11) || | |
1611 ((ics->sect_cb[g][i] >= 16) && (ics->sect_cb[g][i] <= 32))) | |
1612 { | |
1613 vcb11 = 1; | |
1614 } | |
1615 } | |
1616 if (vcb11) | |
1617 { | |
1618 sect_len_incr = 1; | |
1619 } else { | |
1620 #endif | |
1621 sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits | |
1622 DEBUGVAR(1,72,"section_data(): sect_len_incr")); | |
1623 #ifdef ERROR_RESILIENCE | |
1624 } | |
1625 #endif | |
1626 while ((sect_len_incr == sect_esc_val) /* && | |
1627 (k+sect_len < ics->max_sfb)*/) | |
1628 { | |
1629 sect_len += sect_len_incr; | |
1630 sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits | |
1631 DEBUGVAR(1,72,"section_data(): sect_len_incr")); | |
1632 } | |
1633 | |
1634 sect_len += sect_len_incr; | |
1635 | |
1636 ics->sect_start[g][i] = k; | |
1637 ics->sect_end[g][i] = k + sect_len; | |
1638 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1639 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1640 printf("%d\n", ics->sect_start[g][i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1641 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1642 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1643 printf("%d\n", ics->sect_end[g][i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1644 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1645 |
10725 | 1646 if (k + sect_len >= 8*15) |
1647 return 15; | |
1648 if (i >= 8*15) | |
1649 return 15; | |
1650 | |
1651 for (sfb = k; sfb < k + sect_len; sfb++) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1652 { |
10725 | 1653 ics->sfb_cb[g][sfb] = ics->sect_cb[g][i]; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1654 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1655 printf("%d\n", ics->sfb_cb[g][sfb]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1656 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1657 } |
10725 | 1658 |
1659 #if 0 | |
1660 printf(" %6d %6d %6d\n", | |
1661 i, | |
1662 ics->sect_end[g][i], | |
1663 ics->sect_cb[g][i]); | |
1664 #endif | |
1665 | |
1666 k += sect_len; | |
1667 i++; | |
1668 } | |
1669 ics->num_sec[g] = i; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1670 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1671 printf("%d\n", ics->num_sec[g]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1672 #endif |
10725 | 1673 } |
1674 | |
1675 #if 0 | |
1676 printf("\n"); | |
1677 #endif | |
1678 | |
1679 return 0; | |
1680 } | |
1681 | |
1682 /* | |
1683 * decode_scale_factors() | |
1684 * decodes the scalefactors from the bitstream | |
1685 */ | |
1686 /* | |
1687 * All scalefactors (and also the stereo positions and pns energies) are | |
1688 * transmitted using Huffman coded DPCM relative to the previous active | |
1689 * scalefactor (respectively previous stereo position or previous pns energy, | |
1690 * see subclause 4.6.2 and 4.6.3). The first active scalefactor is | |
1691 * differentially coded relative to the global gain. | |
1692 */ | |
1693 static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld) | |
1694 { | |
1695 uint8_t g, sfb; | |
1696 int16_t t; | |
1697 int8_t noise_pcm_flag = 1; | |
1698 | |
1699 int16_t scale_factor = ics->global_gain; | |
1700 int16_t is_position = 0; | |
1701 int16_t noise_energy = ics->global_gain - 90; | |
1702 | |
1703 for (g = 0; g < ics->num_window_groups; g++) | |
1704 { | |
1705 for (sfb = 0; sfb < ics->max_sfb; sfb++) | |
1706 { | |
1707 switch (ics->sfb_cb[g][sfb]) | |
1708 { | |
1709 case ZERO_HCB: /* zero book */ | |
1710 ics->scale_factors[g][sfb] = 0; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1711 //#define SF_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1712 #ifdef SF_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1713 printf("%d\n", ics->scale_factors[g][sfb]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1714 #endif |
10725 | 1715 break; |
1716 case INTENSITY_HCB: /* intensity books */ | |
1717 case INTENSITY_HCB2: | |
1718 | |
1719 /* decode intensity position */ | |
1720 t = huffman_scale_factor(ld); | |
1721 is_position += (t - 60); | |
1722 ics->scale_factors[g][sfb] = is_position; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1723 #ifdef SF_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1724 printf("%d\n", ics->scale_factors[g][sfb]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1725 #endif |
10725 | 1726 |
1727 break; | |
1728 case NOISE_HCB: /* noise books */ | |
1729 | |
1730 /* decode noise energy */ | |
1731 if (noise_pcm_flag) | |
1732 { | |
1733 noise_pcm_flag = 0; | |
1734 t = (int16_t)faad_getbits(ld, 9 | |
1735 DEBUGVAR(1,73,"scale_factor_data(): first noise")) - 256; | |
1736 } else { | |
1737 t = huffman_scale_factor(ld); | |
1738 t -= 60; | |
1739 } | |
1740 noise_energy += t; | |
1741 ics->scale_factors[g][sfb] = noise_energy; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1742 #ifdef SF_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1743 printf("%d\n", ics->scale_factors[g][sfb]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1744 #endif |
10725 | 1745 |
1746 break; | |
1747 default: /* spectral books */ | |
1748 | |
12527 | 1749 /* ics->scale_factors[g][sfb] must be between 0 and 255 */ |
1750 | |
1751 ics->scale_factors[g][sfb] = 0; | |
1752 | |
10725 | 1753 /* decode scale factor */ |
1754 t = huffman_scale_factor(ld); | |
1755 scale_factor += (t - 60); | |
12527 | 1756 if (scale_factor < 0 || scale_factor > 255) |
10725 | 1757 return 4; |
1758 ics->scale_factors[g][sfb] = scale_factor; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1759 #ifdef SF_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1760 printf("%d\n", ics->scale_factors[g][sfb]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1761 #endif |
10725 | 1762 |
1763 break; | |
1764 } | |
1765 } | |
1766 } | |
1767 | |
1768 return 0; | |
1769 } | |
1770 | |
1771 /* Table 4.4.26 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1772 static uint8_t scale_factor_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld) |
10725 | 1773 { |
12527 | 1774 uint8_t ret = 0; |
1775 #ifdef PROFILE | |
1776 int64_t count = faad_get_ts(); | |
1777 #endif | |
1778 | |
10725 | 1779 #ifdef ERROR_RESILIENCE |
1780 if (!hDecoder->aacScalefactorDataResilienceFlag) | |
1781 { | |
1782 #endif | |
12527 | 1783 ret = decode_scale_factors(ics, ld); |
10725 | 1784 #ifdef ERROR_RESILIENCE |
1785 } else { | |
1786 /* In ER AAC the parameters for RVLC are seperated from the actual | |
1787 data that holds the scale_factors. | |
1788 Strangely enough, 2 parameters for HCR are put inbetween them. | |
1789 */ | |
12527 | 1790 ret = rvlc_scale_factor_data(ics, ld); |
10725 | 1791 } |
1792 #endif | |
12527 | 1793 |
1794 #ifdef PROFILE | |
1795 count = faad_get_ts() - count; | |
1796 hDecoder->scalefac_cycles += count; | |
1797 #endif | |
1798 | |
1799 return ret; | |
10725 | 1800 } |
1801 | |
1802 /* Table 4.4.27 */ | |
1803 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld) | |
1804 { | |
1805 uint8_t w, filt, i, start_coef_bits, coef_bits; | |
1806 uint8_t n_filt_bits = 2; | |
1807 uint8_t length_bits = 6; | |
1808 uint8_t order_bits = 5; | |
1809 | |
1810 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
1811 { | |
1812 n_filt_bits = 1; | |
1813 length_bits = 4; | |
1814 order_bits = 3; | |
1815 } | |
1816 | |
1817 for (w = 0; w < ics->num_windows; w++) | |
1818 { | |
1819 tns->n_filt[w] = (uint8_t)faad_getbits(ld, n_filt_bits | |
1820 DEBUGVAR(1,74,"tns_data(): n_filt")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1821 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1822 printf("%d\n", tns->n_filt[w]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1823 #endif |
10725 | 1824 |
1825 if (tns->n_filt[w]) | |
1826 { | |
1827 if ((tns->coef_res[w] = faad_get1bit(ld | |
1828 DEBUGVAR(1,75,"tns_data(): coef_res"))) & 1) | |
1829 { | |
1830 start_coef_bits = 4; | |
1831 } else { | |
1832 start_coef_bits = 3; | |
1833 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1834 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1835 printf("%d\n", tns->coef_res[w]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1836 #endif |
10725 | 1837 } |
1838 | |
1839 for (filt = 0; filt < tns->n_filt[w]; filt++) | |
1840 { | |
1841 tns->length[w][filt] = (uint8_t)faad_getbits(ld, length_bits | |
1842 DEBUGVAR(1,76,"tns_data(): length")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1843 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1844 printf("%d\n", tns->length[w][filt]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1845 #endif |
10725 | 1846 tns->order[w][filt] = (uint8_t)faad_getbits(ld, order_bits |
1847 DEBUGVAR(1,77,"tns_data(): order")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1848 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1849 printf("%d\n", tns->order[w][filt]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1850 #endif |
10725 | 1851 if (tns->order[w][filt]) |
1852 { | |
1853 tns->direction[w][filt] = faad_get1bit(ld | |
1854 DEBUGVAR(1,78,"tns_data(): direction")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1855 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1856 printf("%d\n", tns->direction[w][filt]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1857 #endif |
10725 | 1858 tns->coef_compress[w][filt] = faad_get1bit(ld |
1859 DEBUGVAR(1,79,"tns_data(): coef_compress")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1860 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1861 printf("%d\n", tns->coef_compress[w][filt]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1862 #endif |
10725 | 1863 |
1864 coef_bits = start_coef_bits - tns->coef_compress[w][filt]; | |
1865 for (i = 0; i < tns->order[w][filt]; i++) | |
1866 { | |
1867 tns->coef[w][filt][i] = (uint8_t)faad_getbits(ld, coef_bits | |
1868 DEBUGVAR(1,80,"tns_data(): coef")); | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1869 #if 0 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1870 printf("%d\n", tns->coef[w][filt][i]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1871 #endif |
10725 | 1872 } |
1873 } | |
1874 } | |
1875 } | |
1876 } | |
1877 | |
1878 #ifdef LTP_DEC | |
1879 /* Table 4.4.28 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1880 static uint8_t ltp_data(NeAACDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld) |
10725 | 1881 { |
1882 uint8_t sfb, w; | |
1883 | |
12527 | 1884 ltp->lag = 0; |
1885 | |
10725 | 1886 #ifdef LD_DEC |
1887 if (hDecoder->object_type == LD) | |
1888 { | |
1889 ltp->lag_update = (uint8_t)faad_getbits(ld, 1 | |
1890 DEBUGVAR(1,142,"ltp_data(): lag_update")); | |
1891 | |
1892 if (ltp->lag_update) | |
1893 { | |
1894 ltp->lag = (uint16_t)faad_getbits(ld, 10 | |
1895 DEBUGVAR(1,81,"ltp_data(): lag")); | |
1896 } | |
1897 } else { | |
1898 #endif | |
1899 ltp->lag = (uint16_t)faad_getbits(ld, 11 | |
1900 DEBUGVAR(1,81,"ltp_data(): lag")); | |
1901 #ifdef LD_DEC | |
1902 } | |
1903 #endif | |
12527 | 1904 |
1905 /* Check length of lag */ | |
1906 if (ltp->lag > (hDecoder->frameLength << 1)) | |
1907 return 18; | |
1908 | |
10725 | 1909 ltp->coef = (uint8_t)faad_getbits(ld, 3 |
1910 DEBUGVAR(1,82,"ltp_data(): coef")); | |
1911 | |
1912 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
1913 { | |
1914 for (w = 0; w < ics->num_windows; w++) | |
1915 { | |
1916 if ((ltp->short_used[w] = faad_get1bit(ld | |
1917 DEBUGVAR(1,83,"ltp_data(): short_used"))) & 1) | |
1918 { | |
1919 ltp->short_lag_present[w] = faad_get1bit(ld | |
1920 DEBUGVAR(1,84,"ltp_data(): short_lag_present")); | |
1921 if (ltp->short_lag_present[w]) | |
1922 { | |
1923 ltp->short_lag[w] = (uint8_t)faad_getbits(ld, 4 | |
1924 DEBUGVAR(1,85,"ltp_data(): short_lag")); | |
1925 } | |
1926 } | |
1927 } | |
1928 } else { | |
1929 ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB); | |
1930 | |
1931 for (sfb = 0; sfb < ltp->last_band; sfb++) | |
1932 { | |
1933 ltp->long_used[sfb] = faad_get1bit(ld | |
1934 DEBUGVAR(1,86,"ltp_data(): long_used")); | |
1935 } | |
1936 } | |
12527 | 1937 |
1938 return 0; | |
10725 | 1939 } |
1940 #endif | |
1941 | |
1942 /* Table 4.4.29 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1943 static uint8_t spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld, |
10725 | 1944 int16_t *spectral_data) |
1945 { | |
1946 int8_t i; | |
1947 uint8_t g; | |
12527 | 1948 uint16_t inc, k, p = 0; |
10725 | 1949 uint8_t groups = 0; |
1950 uint8_t sect_cb; | |
1951 uint8_t result; | |
1952 uint16_t nshort = hDecoder->frameLength/8; | |
1953 | |
12527 | 1954 #ifdef PROFILE |
1955 int64_t count = faad_get_ts(); | |
1956 #endif | |
10725 | 1957 |
1958 for(g = 0; g < ics->num_window_groups; g++) | |
1959 { | |
1960 p = groups*nshort; | |
1961 | |
1962 for (i = 0; i < ics->num_sec[g]; i++) | |
1963 { | |
1964 sect_cb = ics->sect_cb[g][i]; | |
1965 | |
12527 | 1966 inc = (sect_cb >= FIRST_PAIR_HCB) ? 2 : 4; |
1967 | |
10725 | 1968 switch (sect_cb) |
1969 { | |
1970 case ZERO_HCB: | |
1971 case NOISE_HCB: | |
1972 case INTENSITY_HCB: | |
1973 case INTENSITY_HCB2: | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1974 //#define SD_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1975 #ifdef SD_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1976 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1977 int j; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1978 for (j = ics->sect_sfb_offset[g][ics->sect_start[g][i]]; j < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; j++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1979 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1980 printf("%d\n", 0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1981 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1982 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1983 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1984 //#define SFBO_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1985 #ifdef SFBO_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1986 printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1987 #endif |
10725 | 1988 p += (ics->sect_sfb_offset[g][ics->sect_end[g][i]] - |
1989 ics->sect_sfb_offset[g][ics->sect_start[g][i]]); | |
1990 break; | |
1991 default: | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1992 #ifdef SFBO_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1993 printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1994 #endif |
10725 | 1995 for (k = ics->sect_sfb_offset[g][ics->sect_start[g][i]]; |
12527 | 1996 k < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; k += inc) |
10725 | 1997 { |
12527 | 1998 if ((result = huffman_spectral_data(sect_cb, ld, &spectral_data[p])) > 0) |
1999 return result; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2000 #ifdef SD_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2001 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2002 int j; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2003 for (j = p; j < p+inc; j++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2004 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2005 printf("%d\n", spectral_data[j]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2006 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2007 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
2008 #endif |
12527 | 2009 p += inc; |
10725 | 2010 } |
2011 break; | |
2012 } | |
2013 } | |
2014 groups += ics->window_group_length[g]; | |
2015 } | |
2016 | |
12527 | 2017 #ifdef PROFILE |
2018 count = faad_get_ts() - count; | |
2019 hDecoder->spectral_cycles += count; | |
2020 #endif | |
2021 | |
10725 | 2022 return 0; |
2023 } | |
2024 | |
2025 /* Table 4.4.30 */ | |
2026 static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count) | |
2027 { | |
2028 uint16_t i, n, dataElementLength; | |
2029 uint8_t dataElementLengthPart; | |
2030 uint8_t align = 4, data_element_version, loopCounter; | |
2031 | |
2032 uint8_t extension_type = (uint8_t)faad_getbits(ld, 4 | |
2033 DEBUGVAR(1,87,"extension_payload(): extension_type")); | |
2034 | |
2035 switch (extension_type) | |
2036 { | |
2037 case EXT_DYNAMIC_RANGE: | |
2038 drc->present = 1; | |
2039 n = dynamic_range_info(ld, drc); | |
2040 return n; | |
2041 case EXT_FILL_DATA: | |
2042 /* fill_nibble = */ faad_getbits(ld, 4 | |
2043 DEBUGVAR(1,136,"extension_payload(): fill_nibble")); /* must be ‘0000’ */ | |
2044 for (i = 0; i < count-1; i++) | |
2045 { | |
2046 /* fill_byte[i] = */ faad_getbits(ld, 8 | |
2047 DEBUGVAR(1,88,"extension_payload(): fill_byte")); /* must be ‘10100101’ */ | |
2048 } | |
2049 return count; | |
2050 case EXT_DATA_ELEMENT: | |
12527 | 2051 data_element_version = (uint8_t)faad_getbits(ld, 4 |
10725 | 2052 DEBUGVAR(1,400,"extension_payload(): data_element_version")); |
2053 switch (data_element_version) | |
2054 { | |
2055 case ANC_DATA: | |
2056 loopCounter = 0; | |
2057 dataElementLength = 0; | |
2058 do { | |
12527 | 2059 dataElementLengthPart = (uint8_t)faad_getbits(ld, 8 |
10725 | 2060 DEBUGVAR(1,401,"extension_payload(): dataElementLengthPart")); |
2061 dataElementLength += dataElementLengthPart; | |
2062 loopCounter++; | |
2063 } while (dataElementLengthPart == 255); | |
2064 | |
2065 for (i = 0; i < dataElementLength; i++) | |
2066 { | |
2067 /* data_element_byte[i] = */ faad_getbits(ld, 8 | |
2068 DEBUGVAR(1,402,"extension_payload(): data_element_byte")); | |
2069 return (dataElementLength+loopCounter+1); | |
2070 } | |
2071 default: | |
2072 align = 0; | |
2073 } | |
2074 case EXT_FIL: | |
2075 default: | |
2076 faad_getbits(ld, align | |
2077 DEBUGVAR(1,88,"extension_payload(): fill_nibble")); | |
2078 for (i = 0; i < count-1; i++) | |
2079 { | |
2080 /* other_bits[i] = */ faad_getbits(ld, 8 | |
2081 DEBUGVAR(1,89,"extension_payload(): fill_bit")); | |
2082 } | |
2083 return count; | |
2084 } | |
2085 } | |
2086 | |
2087 /* Table 4.4.31 */ | |
2088 static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc) | |
2089 { | |
2090 uint8_t i, n = 1; | |
2091 uint8_t band_incr; | |
2092 | |
2093 drc->num_bands = 1; | |
2094 | |
2095 if (faad_get1bit(ld | |
2096 DEBUGVAR(1,90,"dynamic_range_info(): has instance_tag")) & 1) | |
2097 { | |
2098 drc->pce_instance_tag = (uint8_t)faad_getbits(ld, 4 | |
2099 DEBUGVAR(1,91,"dynamic_range_info(): pce_instance_tag")); | |
2100 /* drc->drc_tag_reserved_bits = */ faad_getbits(ld, 4 | |
2101 DEBUGVAR(1,92,"dynamic_range_info(): drc_tag_reserved_bits")); | |
2102 n++; | |
2103 } | |
2104 | |
2105 drc->excluded_chns_present = faad_get1bit(ld | |
2106 DEBUGVAR(1,93,"dynamic_range_info(): excluded_chns_present")); | |
2107 if (drc->excluded_chns_present == 1) | |
2108 { | |
2109 n += excluded_channels(ld, drc); | |
2110 } | |
2111 | |
2112 if (faad_get1bit(ld | |
2113 DEBUGVAR(1,94,"dynamic_range_info(): has bands data")) & 1) | |
2114 { | |
2115 band_incr = (uint8_t)faad_getbits(ld, 4 | |
2116 DEBUGVAR(1,95,"dynamic_range_info(): band_incr")); | |
2117 /* drc->drc_bands_reserved_bits = */ faad_getbits(ld, 4 | |
2118 DEBUGVAR(1,96,"dynamic_range_info(): drc_bands_reserved_bits")); | |
2119 n++; | |
2120 drc->num_bands += band_incr; | |
2121 | |
2122 for (i = 0; i < drc->num_bands; i++); | |
2123 { | |
2124 drc->band_top[i] = (uint8_t)faad_getbits(ld, 8 | |
2125 DEBUGVAR(1,97,"dynamic_range_info(): band_top")); | |
2126 n++; | |
2127 } | |
2128 } | |
2129 | |
2130 if (faad_get1bit(ld | |
2131 DEBUGVAR(1,98,"dynamic_range_info(): has prog_ref_level")) & 1) | |
2132 { | |
2133 drc->prog_ref_level = (uint8_t)faad_getbits(ld, 7 | |
2134 DEBUGVAR(1,99,"dynamic_range_info(): prog_ref_level")); | |
2135 /* drc->prog_ref_level_reserved_bits = */ faad_get1bit(ld | |
2136 DEBUGVAR(1,100,"dynamic_range_info(): prog_ref_level_reserved_bits")); | |
2137 n++; | |
2138 } | |
2139 | |
2140 for (i = 0; i < drc->num_bands; i++) | |
2141 { | |
2142 drc->dyn_rng_sgn[i] = faad_get1bit(ld | |
2143 DEBUGVAR(1,101,"dynamic_range_info(): dyn_rng_sgn")); | |
2144 drc->dyn_rng_ctl[i] = (uint8_t)faad_getbits(ld, 7 | |
2145 DEBUGVAR(1,102,"dynamic_range_info(): dyn_rng_ctl")); | |
2146 n++; | |
2147 } | |
2148 | |
2149 return n; | |
2150 } | |
2151 | |
2152 /* Table 4.4.32 */ | |
2153 static uint8_t excluded_channels(bitfile *ld, drc_info *drc) | |
2154 { | |
2155 uint8_t i, n = 0; | |
2156 uint8_t num_excl_chan = 7; | |
2157 | |
2158 for (i = 0; i < 7; i++) | |
2159 { | |
2160 drc->exclude_mask[i] = faad_get1bit(ld | |
2161 DEBUGVAR(1,103,"excluded_channels(): exclude_mask")); | |
2162 } | |
2163 n++; | |
2164 | |
2165 while ((drc->additional_excluded_chns[n-1] = faad_get1bit(ld | |
2166 DEBUGVAR(1,104,"excluded_channels(): additional_excluded_chns"))) == 1) | |
2167 { | |
2168 for (i = num_excl_chan; i < num_excl_chan+7; i++) | |
2169 { | |
2170 drc->exclude_mask[i] = faad_get1bit(ld | |
2171 DEBUGVAR(1,105,"excluded_channels(): exclude_mask")); | |
2172 } | |
2173 n++; | |
2174 num_excl_chan += 7; | |
2175 } | |
2176 | |
2177 return n; | |
2178 } | |
2179 | |
2180 /* Annex A: Audio Interchange Formats */ | |
2181 | |
2182 /* Table 1.A.2 */ | |
2183 void get_adif_header(adif_header *adif, bitfile *ld) | |
2184 { | |
2185 uint8_t i; | |
2186 | |
2187 /* adif_id[0] = */ faad_getbits(ld, 8 | |
2188 DEBUGVAR(1,106,"get_adif_header(): adif_id[0]")); | |
2189 /* adif_id[1] = */ faad_getbits(ld, 8 | |
2190 DEBUGVAR(1,107,"get_adif_header(): adif_id[1]")); | |
2191 /* adif_id[2] = */ faad_getbits(ld, 8 | |
2192 DEBUGVAR(1,108,"get_adif_header(): adif_id[2]")); | |
2193 /* adif_id[3] = */ faad_getbits(ld, 8 | |
2194 DEBUGVAR(1,109,"get_adif_header(): adif_id[3]")); | |
2195 adif->copyright_id_present = faad_get1bit(ld | |
2196 DEBUGVAR(1,110,"get_adif_header(): copyright_id_present")); | |
2197 if(adif->copyright_id_present) | |
2198 { | |
2199 for (i = 0; i < 72/8; i++) | |
2200 { | |
2201 adif->copyright_id[i] = (int8_t)faad_getbits(ld, 8 | |
2202 DEBUGVAR(1,111,"get_adif_header(): copyright_id")); | |
2203 } | |
2204 adif->copyright_id[i] = 0; | |
2205 } | |
2206 adif->original_copy = faad_get1bit(ld | |
2207 DEBUGVAR(1,112,"get_adif_header(): original_copy")); | |
2208 adif->home = faad_get1bit(ld | |
2209 DEBUGVAR(1,113,"get_adif_header(): home")); | |
2210 adif->bitstream_type = faad_get1bit(ld | |
2211 DEBUGVAR(1,114,"get_adif_header(): bitstream_type")); | |
2212 adif->bitrate = faad_getbits(ld, 23 | |
2213 DEBUGVAR(1,115,"get_adif_header(): bitrate")); | |
2214 adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4 | |
2215 DEBUGVAR(1,116,"get_adif_header(): num_program_config_elements")); | |
2216 | |
2217 for (i = 0; i < adif->num_program_config_elements + 1; i++) | |
2218 { | |
2219 if(adif->bitstream_type == 0) | |
2220 { | |
2221 adif->adif_buffer_fullness = faad_getbits(ld, 20 | |
2222 DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness")); | |
2223 } else { | |
2224 adif->adif_buffer_fullness = 0; | |
2225 } | |
2226 | |
2227 program_config_element(&adif->pce[i], ld); | |
2228 } | |
2229 } | |
2230 | |
2231 /* Table 1.A.5 */ | |
2232 uint8_t adts_frame(adts_header *adts, bitfile *ld) | |
2233 { | |
2234 /* faad_byte_align(ld); */ | |
2235 if (adts_fixed_header(adts, ld)) | |
2236 return 5; | |
2237 adts_variable_header(adts, ld); | |
2238 adts_error_check(adts, ld); | |
2239 | |
2240 return 0; | |
2241 } | |
2242 | |
2243 /* Table 1.A.6 */ | |
2244 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld) | |
2245 { | |
2246 uint16_t i; | |
2247 uint8_t sync_err = 1; | |
2248 | |
2249 /* try to recover from sync errors */ | |
2250 for (i = 0; i < 768; i++) | |
2251 { | |
2252 adts->syncword = (uint16_t)faad_showbits(ld, 12); | |
2253 if (adts->syncword != 0xFFF) | |
2254 { | |
2255 faad_getbits(ld, 8 | |
2256 DEBUGVAR(0,0,"")); | |
2257 } else { | |
2258 sync_err = 0; | |
2259 faad_getbits(ld, 12 | |
2260 DEBUGVAR(1,118,"adts_fixed_header(): syncword")); | |
2261 break; | |
2262 } | |
2263 } | |
2264 if (sync_err) | |
2265 return 5; | |
2266 | |
2267 adts->id = faad_get1bit(ld | |
2268 DEBUGVAR(1,119,"adts_fixed_header(): id")); | |
2269 adts->layer = (uint8_t)faad_getbits(ld, 2 | |
2270 DEBUGVAR(1,120,"adts_fixed_header(): layer")); | |
2271 adts->protection_absent = faad_get1bit(ld | |
2272 DEBUGVAR(1,121,"adts_fixed_header(): protection_absent")); | |
2273 adts->profile = (uint8_t)faad_getbits(ld, 2 | |
2274 DEBUGVAR(1,122,"adts_fixed_header(): profile")); | |
2275 adts->sf_index = (uint8_t)faad_getbits(ld, 4 | |
2276 DEBUGVAR(1,123,"adts_fixed_header(): sf_index")); | |
2277 adts->private_bit = faad_get1bit(ld | |
2278 DEBUGVAR(1,124,"adts_fixed_header(): private_bit")); | |
2279 adts->channel_configuration = (uint8_t)faad_getbits(ld, 3 | |
2280 DEBUGVAR(1,125,"adts_fixed_header(): channel_configuration")); | |
2281 adts->original = faad_get1bit(ld | |
2282 DEBUGVAR(1,126,"adts_fixed_header(): original")); | |
2283 adts->home = faad_get1bit(ld | |
2284 DEBUGVAR(1,127,"adts_fixed_header(): home")); | |
10989 | 2285 |
2286 if (adts->old_format == 1) | |
2287 { | |
2288 /* Removed in corrigendum 14496-3:2002 */ | |
12527 | 2289 if (adts->id == 0) |
2290 { | |
2291 adts->emphasis = (uint8_t)faad_getbits(ld, 2 | |
2292 DEBUGVAR(1,128,"adts_fixed_header(): emphasis")); | |
2293 } | |
10989 | 2294 } |
10725 | 2295 |
2296 return 0; | |
2297 } | |
2298 | |
2299 /* Table 1.A.7 */ | |
2300 static void adts_variable_header(adts_header *adts, bitfile *ld) | |
2301 { | |
2302 adts->copyright_identification_bit = faad_get1bit(ld | |
2303 DEBUGVAR(1,129,"adts_variable_header(): copyright_identification_bit")); | |
2304 adts->copyright_identification_start = faad_get1bit(ld | |
2305 DEBUGVAR(1,130,"adts_variable_header(): copyright_identification_start")); | |
2306 adts->aac_frame_length = (uint16_t)faad_getbits(ld, 13 | |
2307 DEBUGVAR(1,131,"adts_variable_header(): aac_frame_length")); | |
2308 adts->adts_buffer_fullness = (uint16_t)faad_getbits(ld, 11 | |
2309 DEBUGVAR(1,132,"adts_variable_header(): adts_buffer_fullness")); | |
2310 adts->no_raw_data_blocks_in_frame = (uint8_t)faad_getbits(ld, 2 | |
2311 DEBUGVAR(1,133,"adts_variable_header(): no_raw_data_blocks_in_frame")); | |
2312 } | |
2313 | |
2314 /* Table 1.A.8 */ | |
2315 static void adts_error_check(adts_header *adts, bitfile *ld) | |
2316 { | |
2317 if (adts->protection_absent == 0) | |
2318 { | |
2319 adts->crc_check = (uint16_t)faad_getbits(ld, 16 | |
2320 DEBUGVAR(1,134,"adts_error_check(): crc_check")); | |
2321 } | |
2322 } |