summaryrefslogtreecommitdiff
path: root/audio_codec/libfaad/structs.h (plain)
blob: 73f81cc6e6408b9b7e11cf81aa13389d2dcfbb70
1/*
2** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
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** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24**
25** Commercial non-GPL licensing of this software is possible.
26** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27**
28** $Id: structs.h,v 1.49 2009/01/26 23:51:15 menno Exp $
29**/
30
31#ifndef __STRUCTS_H__
32#define __STRUCTS_H__
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include "cfft.h"
39#ifdef SBR_DEC
40#include "sbr_dec.h"
41#endif
42
43#define MAX_CHANNELS 64
44#define MAX_SYNTAX_ELEMENTS 48
45#define MAX_WINDOW_GROUPS 8
46#define MAX_SFB 51
47#define MAX_LTP_SFB 40
48#define MAX_LTP_SFB_S 8
49
50 /* used to save the prediction state */
51 typedef struct {
52 int16_t r[2];
53 int16_t COR[2];
54 int16_t VAR[2];
55 } pred_state;
56
57 typedef struct {
58 uint16_t N;
59 cfft_info *cfft;
60 complex_t *sincos;
61#ifdef PROFILE
62 int64_t cycles;
63 int64_t fft_cycles;
64#endif
65 } mdct_info;
66
67 typedef struct {
68 const real_t *long_window[2];
69 const real_t *short_window[2];
70#ifdef LD_DEC
71 const real_t *ld_window[2];
72#endif
73
74 mdct_info *mdct256;
75#ifdef LD_DEC
76 mdct_info *mdct1024;
77#endif
78 mdct_info *mdct2048;
79#ifdef PROFILE
80 int64_t cycles;
81#endif
82 } fb_info;
83
84 typedef struct {
85 uint8_t present;
86
87 uint8_t num_bands;
88 uint8_t pce_instance_tag;
89 uint8_t excluded_chns_present;
90 uint8_t band_top[17];
91 uint8_t prog_ref_level;
92 uint8_t dyn_rng_sgn[17];
93 uint8_t dyn_rng_ctl[17];
94 uint8_t exclude_mask[MAX_CHANNELS];
95 uint8_t additional_excluded_chns[MAX_CHANNELS];
96
97 real_t ctrl1;
98 real_t ctrl2;
99 } drc_info;
100
101 typedef struct {
102 uint8_t element_instance_tag;
103 uint8_t object_type;
104 uint8_t sf_index;
105 uint8_t num_front_channel_elements;
106 uint8_t num_side_channel_elements;
107 uint8_t num_back_channel_elements;
108 uint8_t num_lfe_channel_elements;
109 uint8_t num_assoc_data_elements;
110 uint8_t num_valid_cc_elements;
111 uint8_t mono_mixdown_present;
112 uint8_t mono_mixdown_element_number;
113 uint8_t stereo_mixdown_present;
114 uint8_t stereo_mixdown_element_number;
115 uint8_t matrix_mixdown_idx_present;
116 uint8_t pseudo_surround_enable;
117 uint8_t matrix_mixdown_idx;
118 uint8_t front_element_is_cpe[16];
119 uint8_t front_element_tag_select[16];
120 uint8_t side_element_is_cpe[16];
121 uint8_t side_element_tag_select[16];
122 uint8_t back_element_is_cpe[16];
123 uint8_t back_element_tag_select[16];
124 uint8_t lfe_element_tag_select[16];
125 uint8_t assoc_data_element_tag_select[16];
126 uint8_t cc_element_is_ind_sw[16];
127 uint8_t valid_cc_element_tag_select[16];
128
129 uint8_t channels;
130
131 uint8_t comment_field_bytes;
132 uint8_t comment_field_data[257];
133
134 /* extra added values */
135 uint8_t num_front_channels;
136 uint8_t num_side_channels;
137 uint8_t num_back_channels;
138 uint8_t num_lfe_channels;
139 uint8_t sce_channel[16];
140 uint8_t cpe_channel[16];
141 } program_config;
142
143 typedef struct {
144 uint16_t syncword;
145 uint8_t id;
146 uint8_t layer;
147 uint8_t protection_absent;
148 uint8_t profile;
149 uint8_t sf_index;
150 uint8_t private_bit;
151 uint8_t channel_configuration;
152 uint8_t original;
153 uint8_t home;
154 uint8_t emphasis;
155 uint8_t copyright_identification_bit;
156 uint8_t copyright_identification_start;
157 uint16_t aac_frame_length;
158 uint16_t adts_buffer_fullness;
159 uint8_t no_raw_data_blocks_in_frame;
160 uint16_t crc_check;
161
162 /* control param */
163 uint8_t old_format;
164 } adts_header;
165
166 typedef struct {
167 uint8_t copyright_id_present;
168 int8_t copyright_id[10];
169 uint8_t original_copy;
170 uint8_t home;
171 uint8_t bitstream_type;
172 uint32_t bitrate;
173 uint8_t num_program_config_elements;
174 uint32_t adif_buffer_fullness;
175
176 /* maximum of 16 PCEs */
177 program_config pce[16];
178 } adif_header;
179
180#ifdef LTP_DEC
181 typedef struct {
182 uint8_t last_band;
183 uint8_t data_present;
184 uint16_t lag;
185 uint8_t lag_update;
186 uint8_t coef;
187 uint8_t long_used[MAX_SFB];
188 uint8_t short_used[8];
189 uint8_t short_lag_present[8];
190 uint8_t short_lag[8];
191 } ltp_info;
192#endif
193
194#ifdef MAIN_DEC
195 typedef struct {
196 uint8_t limit;
197 uint8_t predictor_reset;
198 uint8_t predictor_reset_group_number;
199 uint8_t prediction_used[MAX_SFB];
200 } pred_info;
201#endif
202
203 typedef struct {
204 uint8_t number_pulse;
205 uint8_t pulse_start_sfb;
206 uint8_t pulse_offset[4];
207 uint8_t pulse_amp[4];
208 } pulse_info;
209
210 typedef struct {
211 uint8_t n_filt[8];
212 uint8_t coef_res[8];
213 uint8_t length[8][4];
214 uint8_t order[8][4];
215 uint8_t direction[8][4];
216 uint8_t coef_compress[8][4];
217 uint8_t coef[8][4][32];
218 } tns_info;
219
220#ifdef SSR_DEC
221 typedef struct {
222 uint8_t max_band;
223
224 uint8_t adjust_num[4][8];
225 uint8_t alevcode[4][8][8];
226 uint8_t aloccode[4][8][8];
227 } ssr_info;
228#endif
229
230 typedef struct {
231 uint8_t max_sfb;
232
233 uint8_t num_swb;
234 uint8_t num_window_groups;
235 uint8_t num_windows;
236 uint8_t window_sequence;
237 uint8_t window_group_length[8];
238 uint8_t window_shape;
239 uint8_t scale_factor_grouping;
240 uint16_t sect_sfb_offset[8][15 * 8];
241 uint16_t swb_offset[52];
242 uint16_t swb_offset_max;
243
244 uint8_t sect_cb[8][15 * 8];
245 uint16_t sect_start[8][15 * 8];
246 uint16_t sect_end[8][15 * 8];
247 uint8_t sfb_cb[8][8 * 15];
248 uint8_t num_sec[8]; /* number of sections in a group */
249
250 uint8_t global_gain;
251 int16_t scale_factors[8][51]; /* [0..255] */
252
253 uint8_t ms_mask_present;
254 uint8_t ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
255
256 uint8_t noise_used;
257 uint8_t is_used;
258
259 uint8_t pulse_data_present;
260 uint8_t tns_data_present;
261 uint8_t gain_control_data_present;
262 uint8_t predictor_data_present;
263
264 pulse_info pul;
265 tns_info tns;
266#ifdef MAIN_DEC
267 pred_info pred;
268#endif
269#ifdef LTP_DEC
270 ltp_info ltp;
271 ltp_info ltp2;
272#endif
273#ifdef SSR_DEC
274 ssr_info ssr;
275#endif
276
277#ifdef ERROR_RESILIENCE
278 /* ER HCR data */
279 uint16_t length_of_reordered_spectral_data;
280 uint8_t length_of_longest_codeword;
281 /* ER RLVC data */
282 uint8_t sf_concealment;
283 uint8_t rev_global_gain;
284 uint16_t length_of_rvlc_sf;
285 uint16_t dpcm_noise_nrg;
286 uint8_t sf_escapes_present;
287 uint8_t length_of_rvlc_escapes;
288 uint16_t dpcm_noise_last_position;
289#endif
290 } ic_stream; /* individual channel stream */
291
292 typedef struct {
293 uint8_t channel;
294 int16_t paired_channel;
295
296 uint8_t element_instance_tag;
297 uint8_t common_window;
298
299 ic_stream ics1;
300 ic_stream ics2;
301 } element; /* syntax element (SCE, CPE, LFE) */
302
303#define MAX_ASC_BYTES 64
304 typedef struct {
305 int inited;
306 int version, versionA;
307 int framelen_type;
308 int useSameStreamMux;
309 int allStreamsSameTimeFraming;
310 int numSubFrames;
311 int numPrograms;
312 int numLayers;
313 int otherDataPresent;
314 uint32_t otherDataLenBits;
315 uint32_t frameLength;
316 uint8_t ASC[MAX_ASC_BYTES];
317 uint32_t ASCbits;
318 } latm_header;
319
320#define NEW_CODE_CHECK_LATM
321#ifdef NEW_CODE_CHECK_LATM
322#define LOAS_HEADER_SIZE 3
323 /****************************************************************************
324 * LOAS helpers
325 ****************************************************************************/
326#define LATM_MAX_EXTRA_SIZE 64
327 typedef struct {
328 int i_object_type;
329 int i_samplerate;
330 int i_channel;
331 int i_sbr; // 0: no sbr, 1: sbr, -1: unknown
332 int i_ps; // 0: no ps, 1: ps, -1: unknown
333
334 struct {
335 int i_object_type;
336 int i_samplerate;
337 } extension;
338
339 /* GASpecific */
340 int i_frame_length; // 1024 or 960
341
342 } mpeg4_cfg_t;
343 typedef struct {
344 int i_program;
345 int i_layer;
346
347 int i_frame_length_type;
348 int i_frame_length; // type 1
349 int i_frame_length_index; // type 3 4 5 6 7
350
351 mpeg4_cfg_t cfg;
352
353 /* Raw configuration */
354 int i_extra;
355 uint8_t extra[LATM_MAX_EXTRA_SIZE];
356
357 } latm_stream_t;
358
359#define LATM_MAX_LAYER (8)
360#define LATM_MAX_PROGRAM (16)
361 typedef struct {
362 int b_same_time_framing;
363 int i_sub_frames;
364 int i_programs;
365
366 int pi_layers[LATM_MAX_PROGRAM];
367
368 int pi_stream[LATM_MAX_PROGRAM][LATM_MAX_LAYER];
369
370 int i_streams;
371 latm_stream_t stream[LATM_MAX_PROGRAM*LATM_MAX_LAYER];
372
373 int i_other_data;
374 int i_crc; /* -1 if not set */
375 } latm_mux_t;
376
377 typedef struct {
378 /*
379 * Input properties
380 */
381 int i_state;
382 int i_type;
383 int i_frame_size;
384 unsigned int i_channels;
385 unsigned int i_rate, i_frame_length, i_header_size;
386 int i_input_rate;
387 /* LOAS */
388 unsigned char b_latm_cfg;
389 latm_mux_t latm;
390 } decoder_sys_t;
391
392#endif
393 typedef struct {
394 uint8_t adts_header_present;
395 uint8_t adif_header_present;
396 uint8_t latm_header_present;
397 uint8_t sf_index;
398 uint8_t object_type;
399 uint8_t channelConfiguration;
400#ifdef ERROR_RESILIENCE
401 uint8_t aacSectionDataResilienceFlag;
402 uint8_t aacScalefactorDataResilienceFlag;
403 uint8_t aacSpectralDataResilienceFlag;
404#endif
405 uint16_t frameLength;
406 uint8_t postSeekResetFlag;
407
408 uint32_t frame;
409
410 uint8_t downMatrix;
411 uint8_t upMatrix;
412 uint8_t first_syn_ele;
413 uint8_t has_lfe;
414 /* number of channels in current frame */
415 uint8_t fr_channels;
416 /* number of elements in current frame */
417 uint8_t fr_ch_ele;
418
419 /* element_output_channels:
420 determines the number of channels the element will output
421 */
422 uint8_t element_output_channels[MAX_SYNTAX_ELEMENTS];
423 /* element_alloced:
424 determines whether the data needed for the element is allocated or not
425 */
426 uint8_t element_alloced[MAX_SYNTAX_ELEMENTS];
427 /* alloced_channels:
428 determines the number of channels where output data is allocated for
429 */
430 uint8_t alloced_channels;
431
432 /* output data buffer */
433 void *sample_buffer;
434
435 /*add for loas sub frame large than one*/
436 void *sample_buffer_all;
437
438 uint8_t window_shape_prev[MAX_CHANNELS];
439#ifdef LTP_DEC
440 uint16_t ltp_lag[MAX_CHANNELS];
441#endif
442 fb_info *fb;
443 drc_info *drc;
444
445 real_t *time_out[MAX_CHANNELS];
446 real_t *fb_intermed[MAX_CHANNELS];
447
448#ifdef SBR_DEC
449 int8_t sbr_present_flag;
450 int8_t forceUpSampling;
451 int8_t downSampledSBR;
452 /* determines whether SBR data is allocated for the gives element */
453 uint8_t sbr_alloced[MAX_SYNTAX_ELEMENTS];
454
455 sbr_info *sbr[MAX_SYNTAX_ELEMENTS];
456#endif
457#if (defined(PS_DEC) || defined(DRM_PS))
458 uint8_t ps_used[MAX_SYNTAX_ELEMENTS];
459 uint8_t ps_used_global;
460#endif
461
462#ifdef SSR_DEC
463 real_t *ssr_overlap[MAX_CHANNELS];
464 real_t *prev_fmd[MAX_CHANNELS];
465 real_t ipqf_buffer[MAX_CHANNELS][4][96 / 4];
466#endif
467
468#ifdef MAIN_DEC
469 pred_state *pred_stat[MAX_CHANNELS];
470#endif
471#ifdef LTP_DEC
472 int16_t *lt_pred_stat[MAX_CHANNELS];
473#endif
474
475#ifdef DRM
476 uint8_t error_state;
477#endif
478
479 /* RNG states */
480 uint32_t __r1;
481 uint32_t __r2;
482
483 /* Program Config Element */
484 uint8_t pce_set;
485 program_config pce;
486 uint8_t element_id[MAX_CHANNELS];
487 uint8_t internal_channel[MAX_CHANNELS];
488
489 /* Configuration data */
490 NeAACDecConfiguration config;
491
492#ifdef PROFILE
493 int64_t cycles;
494 int64_t spectral_cycles;
495 int64_t output_cycles;
496 int64_t scalefac_cycles;
497 int64_t requant_cycles;
498#endif
499 latm_header latm_config;
500 const unsigned char *cmes;
501#ifdef NEW_CODE_CHECK_LATM
502 decoder_sys_t dec_sys;
503#endif
504 int last_sf_index;
505 int last_ch_configure;
506 } NeAACDecStruct;
507
508
509
510#ifdef __cplusplus
511}
512#endif
513#endif
514