annotate libfaad2/syntax.c @ 10865:308c20281eec

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