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