www.pudn.com > iMagic_2006_0428_v098r23.rar > aac_struct.h


/* 
**************************************************************** 
*                      Magic Pixel Inc. 
*    Copyright 2004, Magic Pixel Inc., HsinChu, Taiwan 
*                    All rights reserved. 
* 
* 
* 
* Filename:    aac_struct.H 
* 
* Programmer:    Honda  
*                MPX E340 division 
* 
* Created: 11/24/2005 
* 
* Description: Common header file 
* 
*         
* Change History (most recent first): 
*     <1>     11/24/2005    Honda    first file 
**************************************************************** 
*/ 
 
#ifndef aac_struct_h 
#define aac_struct_h 
 
#ifdef __cplusplus 
extern "C" { 
#endif 
 
#define SHORT_WIN_SIZE     128 
#define LONG_WIN_SIZE      1024 
 
 
 
typedef struct 
{ 
    uint8_t number_pulse; 
    uint8_t pulse_start_sfb; 
    uint8_t pulse_offset[4]; 
    uint8_t pulse_amp[4]; 
} pulse_info; 
 
typedef struct 
{ 
    uint8_t n_filt[8]; 
    uint8_t coef_res[8]; 
    uint8_t length[8][4]; 
    uint8_t order[8][4]; 
    uint8_t direction[8][4]; 
    uint8_t coef_compress[8][4]; 
    uint8_t coef[8][4][32]; 
} tns_info; 
 
typedef struct 
{ 
    uint8_t n_filt[8]; 
    uint8_t coef_res[8]; 
    uint8_t length[8]; 
    uint8_t order[8]; 
    uint8_t direction[8]; 
    uint8_t coef_compress[8]; 
    uint8_t coef[56]; 
} tns_info_I; 
 
 
 
typedef struct 
{ 
    uint8_t limit; 
    uint8_t predictor_reset; 
    uint8_t predictor_reset_group_number; 
    uint8_t prediction_used[MAX_SFB]; 
} pred_info; 
 
typedef struct 
{ 
    uint8_t max_sfb; 
    
    uint8_t num_swb; 
    uint8_t num_window_groups; 
    uint8_t num_windows; 
    uint8_t window_sequence; 
    uint8_t window_group_length[8]; 
    uint8_t window_shape; 
    uint8_t scale_factor_grouping; 
   //---------------------------------- 
    uint16_t *swb_offset; 
    uint16_t sect_sfb_offset[128]; 
    uint8_t sect_cb[128]; 
    uint8_t sect_start[128]; 
    uint8_t sfb_cb[128]; 
    int16_t scale_factors[128];    //must  
    uint8_t ms_used[128]; 
    //--------------------------------- 
    uint8_t sect_num_group[8]; // number of sections in a group  
    int16_t zero_size_group[8]; 
 
    uint8_t global_gain; 
 
    uint8_t ms_mask_present; 
    uint8_t noise_used; 
    uint8_t is_used; 
    uint8_t pulse_data_present; 
    uint8_t tns_data_present; 
    uint8_t gain_control_data_present; 
    uint8_t predictor_data_present; 
 
    pulse_info pul; 
    tns_info_I tns; 
    //pred_info pred; 
} ic_stream; // individual channel stream  
 
typedef struct 
{ 
	uint8_t window_sequence; 
	uint8_t window_shape; 
} ic_stream_part; 
 
 
typedef struct 
{ 
    //uint8_t ele_id; 
    //int32_t channel; 
    //int32_t paired_channel; 
    //uint8_t element_instance_tag; 
    uint8_t common_window; 
    ic_stream ics1; 
    ic_stream ics2; 
} element; // syntax element (SCE, CPE, LFE)  
 
 
 
 
/* 
 *  Optimal huffman decoding for AAC taken from: 
 *  "SELECTING AN OPTIMAL HUFFMAN DECODER FOR AAC" by 
 *  VLADIMIR Z. MESAROVIC , RAGHUNATH RAO, MIROSLAV V. DOKIC, and SACHIN DEO 
 *  AES paper 5436 
 * 
 *   2 methods are used for huffman decoding: 
 *   - binary search 
 *   - 2-step table lookup 
 * 
 *   The choice of the "optimal" method is based on the fact that if the 
 *   memory size for the Two-step is exorbitantly high then the decision 
 *   is Binary search for that codebook. However, for marginally more memory 
 *   size, if Twostep outperforms even the best case of Binary then the 
 *   decision is Two-step for that codebook. 
 * 
 *   The following methods are used for the different tables. 
 *   codebook   "optimal" method 
 *    HCB_1      2-Step 
 *    HCB_2      2-Step 
 *    HCB_3      Binary 
 *    HCB_4      2-Step 
 *    HCB_5      Binary 
 *    HCB_6      2-Step 
 *    HCB_7      Binary 
 *    HCB_8      2-Step 
 *    HCB_9      Binary 
 *    HCB_10     2-Step 
 *    HCB_11     2-Step 
 *    HCB_SF     Binary 
 * 
 */ 
 
 
#define ZERO_HCB       0 
#define FIRST_PAIR_HCB 5 
#define ESC_HCB        11 
#define QUAD_LEN       4 
#define PAIR_LEN       2 
#define NOISE_HCB      13 
#define INTENSITY_HCB2 14 
#define INTENSITY_HCB  15 
 
 
//#define SINGLE_BS_BUFFER 
 
#ifdef SINGLE_BS_BUFFER 
#define AAC_BITSTREAM_SIZE 2048 
#else 
#define AAC_BITSTREAM_SIZE 512 
#endif 
 
 
#define GRANULE_NUM 8 
#define GRANULE_SIZE 128 
 
 
 
//------drc.cpp 
#define DRC_REF_LEVEL 20*4 /* -20 dB */ 
 
typedef struct 
{ 
    uint8_t present; 
 
    uint8_t num_bands; 
    uint8_t pce_instance_tag; 
    uint8_t excluded_chns_present; 
    uint8_t band_top[17]; 
    uint8_t prog_ref_level; 
    uint8_t dyn_rng_sgn[17]; 
    uint8_t dyn_rng_ctl[17]; 
    uint8_t exclude_mask[MAX_CHANNELS]; 
    uint8_t additional_excluded_chns[MAX_CHANNELS]; 
 
    real_t ctrl1; 
    real_t ctrl2; 
} drc_info; 
 
 
typedef struct 
{ 
    uint16_t syncword; 
    uint8_t id; 
    uint8_t layer; 
    uint8_t protection_absent; 
    uint8_t profile; 
    uint8_t sf_index; 
    uint8_t private_bit; 
    uint8_t channel_configuration; 
    uint8_t original; 
    uint8_t home; 
    uint8_t emphasis; 
    uint8_t copyright_identification_bit; 
    uint8_t copyright_identification_start; 
    uint16_t aac_frame_length; 
    uint16_t adts_buffer_fullness; 
    uint8_t no_raw_data_blocks_in_frame; 
    uint16_t crc_check; 
 
    /* control param */ 
    uint8_t old_format; 
} adts_header; 
 
 
typedef struct 
{ 
    uint8_t element_instance_tag; 
    uint8_t object_type; 
    uint8_t sf_index; 
    uint8_t num_front_channel_elements; 
    uint8_t num_side_channel_elements; 
    uint8_t num_back_channel_elements; 
    uint8_t num_lfe_channel_elements; 
    uint8_t num_assoc_data_elements; 
    uint8_t num_valid_cc_elements; 
    uint8_t mono_mixdown_present; 
    uint8_t mono_mixdown_element_number; 
    uint8_t stereo_mixdown_present; 
    uint8_t stereo_mixdown_element_number; 
    uint8_t matrix_mixdown_idx_present; 
    uint8_t pseudo_surround_enable; 
    uint8_t matrix_mixdown_idx; 
    uint8_t front_element_is_cpe[16]; 
    uint8_t front_element_tag_select[16]; 
    uint8_t side_element_is_cpe[16]; 
    uint8_t side_element_tag_select[16]; 
    uint8_t back_element_is_cpe[16]; 
    uint8_t back_element_tag_select[16]; 
    uint8_t lfe_element_tag_select[16]; 
    uint8_t assoc_data_element_tag_select[16]; 
    uint8_t cc_element_is_ind_sw[16]; 
    uint8_t valid_cc_element_tag_select[16]; 
    uint8_t channels; 
    uint8_t comment_field_bytes; 
    uint8_t comment_field_data[257]; 
    uint8_t num_front_channels; 
    uint8_t num_side_channels; 
    uint8_t num_back_channels; 
    uint8_t num_lfe_channels; 
    uint8_t sce_channel[16]; 
    uint8_t cpe_channel[16]; 
} program_config; 
 
 
typedef struct 
{ 
    uint8_t copyright_id_present; 
    int8_t copyright_id[10]; 
    uint8_t original_copy; 
    uint8_t home; 
    uint8_t bitstream_type; 
    uint32_t bitrate; 
    uint8_t num_program_config_elements; 
    uint32_t adif_buffer_fullness; 
    // maximum of 16 PCEs  
    //program_config pce[16]; 
} adif_header; 
 
#define MAX_SYNTAX_ELEMENTS 48 
 
 
 
 
typedef struct 
{ 
	uint8_t fr_channels;  // number of elements in current frame  
   uint8_t fr_ch_ele; 
   uint8_t element_output_channels[MAX_SYNTAX_ELEMENTS]; 
 
   uint8_t window_shape_prev[MAX_CHANNELS]; 
   int32_t *pcm_out[MAX_CHANNELS];  //time-domain output 
   int32_t *overlap[MAX_CHANNELS]; 
 
   const short *long_window_I[2]; 
   const short *short_window_I[2]; 
 
   int *freebuf; 
   //aac bit-stream 
   unsigned char *bsbuf;	 
   int buf_left; 
   unsigned char *ado_cache_ptr; 
   unsigned int  ado_cache;   //the cache can be used for 8 bits or 16 bits or 32 bits 
   int ado_cache_left;  //the cache left bit numbers 
   //FILE *hfile; 
//   int bnum; 
//   uint8_t sf_index; 
//   int object_type; 
//   int channelConfiguration; 
//   int samplerate; 
//   unsigned int frameLength; 
 
	unsigned char *host_bs_addr; 
   int *host_pcm_addr; 
   int frame_size; 
   int frame; 
   int channel_num; 
   int error; 
   int sample_rate_index; 
   int header_type; 
   int EQ_enable; 
   unsigned char EQ_band[16]; 
   int frame_left; 
}aac_dec; 
 
//DEQUAN Table 
extern const int c_sqrt_root32[4][7]; 
extern const int c_mantissa[258]; 
extern const unsigned char c_exponent[258]; 
extern const unsigned char c_sqrtExp[7]; 
extern const int c_mad_sqrt[7]; 
extern const int c_root_table[4]; 
extern const int c_root_table_2[4]; 
extern const int c_root_table_3[4]; 
extern const int c_root_table_4[4]; 
extern const int c_pow05_table[4]; 
 
extern int *sqrt_root32;	//[4][7]; 
extern int *mantissa;	//[]; 
extern unsigned char *exponent;	//[]; 
extern unsigned char *sqrtExp;	//[]; 
extern int *mad_sqrt;	//[]; 
extern int *root_table;	//[]; 
extern int *root_table_2;	//[]; 
extern int *root_table_3;	//[]; 
extern int *root_table_4;	//[]; 
extern int *pow05_table;	//[4]; 
 
//Dehumm Table 
 
extern const unsigned short c_cb0[170]; 
extern const unsigned short c_hcb1_1[32]; 
extern const unsigned short c_hcb1_2[113]; 
extern const unsigned short c_hcb2_1[32]; 
extern const unsigned short c_hcb2_2[85]; 
extern const unsigned short c_cb3[124]; 
extern const unsigned short c_hcb4_1[32]; 
extern const unsigned short c_hcb4_2[184]; 
extern const short c_cb5[120]; 
extern const unsigned short c_hcb6_1[32]; 
extern const short c_hcb6_2[125]; 
extern const unsigned short c_cb7[98]; 
extern const unsigned short c_cb9[236]; 
extern const unsigned short c_hcb8_1[32]; 
extern const unsigned short c_hcb8_2[83]; 
extern const unsigned short c_hcb10_1[64]; 
extern const unsigned short c_hcb10_2[209]; 
extern const unsigned short c_hcb11_1[32]; 
extern const unsigned short c_hcb11_2[374]; 
 
extern unsigned short *cb0;		//[170]; 
extern unsigned short *hcb1_1;    //[32]; 
extern unsigned short *hcb1_2;    //[113]; 
extern unsigned short *hcb2_1;    //[32]; 
extern unsigned short *hcb2_2;    //[85]; 
extern unsigned short *cb3;    //[124]; 
extern unsigned short *hcb4_1;    //[32]; 
extern unsigned short *hcb4_2;    //[184]; 
extern short *cb5;    //[120]; 
extern unsigned short *hcb6_1;    //[32]; 
extern short *hcb6_2;    //[125]; 
extern unsigned short *cb7;    //[98]; 
extern unsigned short *cb9;    //[236]; 
extern unsigned short *hcb8_1;    //[32]; 
extern unsigned short *hcb8_2;    //[83]; 
extern unsigned short *hcb10_1;    //[64]; 
extern unsigned short *hcb10_2;    //[209]; 
extern unsigned short *hcb11_1;    //[32]; 
extern unsigned short *hcb11_2;    //[374]; 
 
 
//FFT table 
extern const short c_cfft_tab_64[128]; 
extern const short c_mdct256_I[128]; 
extern const short c_cfft_tab_512[1024]; 
extern const short c_mdct2048_I[1024]; 
extern short *cfft_tab_64;    //[128]; 
extern short *mdct256_I;    //[128]; 
extern short *cfft_tab_512;    //[1024]; 
extern short *mdct2048_I;    //[1024]; 
 
 
 
extern const short sine_long_1024_I[1024]; 
extern const short sine_short_128_I[128]; 
extern const short kbd_long_1024_I[1024]; 
extern const short kbd_short_128_I[128]; 
extern short *short_window;	//[128];		 
extern short *long_window;		//[1024];    
 
 
 
#define NUM_ERROR_MESSAGES 26 
extern int8_t *err_msg[]; 
 
extern uint16_t *swb_offset_1024_window[]; 
extern uint16_t *swb_offset_128_window[]; 
extern int32_t const_tab[][5]; 
//extern const uint8_t num_swb_960_window[]; 
extern uint8_t num_swb_1024_window[]; 
extern uint8_t num_swb_128_window[]; 
extern uint16_t swb_offset_1024_96[]; 
extern uint16_t swb_offset_1024_64[]; 
extern uint16_t swb_offset_1024_48[]; 
extern uint16_t swb_offset_1024_32[]; 
extern uint16_t swb_offset_1024_24[]; 
extern uint16_t swb_offset_1024_16[]; 
extern uint16_t swb_offset_1024_8[]; 
 
extern uint16_t swb_offset_128_96[]; 
extern uint16_t swb_offset_128_64[]; 
extern uint16_t swb_offset_128_48[]; 
extern uint16_t swb_offset_128_24[]; 
extern uint16_t swb_offset_128_16[]; 
extern uint16_t swb_offset_128_8[]; 
 
 
 
 
extern long *tmpr; 
extern int *g_buf0; 
extern int *g_buf1; 
extern int *g_buf2; 
extern int g_overlay_ch0[1024]; 
extern int g_overlay_ch1[1024]; 
extern int	*overlay_ch0; 
extern int	*overlay_ch1; 
extern unsigned char *g_bsbuf; 
extern drc_info *g_drc; 
extern program_config *g_pce; 
extern aac_dec *pad; 
//extern aac_dec ad; 
extern ic_stream *g_ics_ch0; 
extern ic_stream *g_ics_ch1; 
 
//extern adif_header g_adif; 
//extern adts_header g_adts; 
extern adif_header *adif; 
extern adts_header *adts; 
extern short aac_outbuf[2048]; 
 
//EQ 
extern int *aac_EQ_num; 
extern int *aac_EQ_start; 
extern int *aac_EQ_exp; 
extern int *aac_EQ_limit; 
extern int *aac_EQ_base; 
extern int *aac_EQ_shift; 
 
extern int c_aac_EQ_num[16]; 
extern int c_aac_EQ_start[16]; 
extern int c_aac_EQ_exp[16]; 
extern int c_aac_EQ_limit[10]; 
extern int c_aac_EQ_base[10]; 
extern int c_aac_EQ_shift[10]; 
 
#ifdef __cplusplus 
} 
#endif 
#endif