1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #ifndef IXHEAACD_CHANNELINFO_H
21 #define IXHEAACD_CHANNELINFO_H
22 
23 #include "ixheaacd_lt_predict.h"
24 
25 #define MAX_SFB_SHORT 16
26 #define MAX_QUANTIZED_VALUE 8191
27 
28 #define OVERLAP_BUFFER_SIZE 512
29 
30 #define JOINT_STEREO_MAX_GROUPS 8
31 #define JOINT_STEREO_MAX_BANDS 64
32 
33 typedef struct {
34   WORD16 window_shape;
35   WORD16 window_sequence;
36   WORD16 max_sfb;
37   WORD16 num_swb_window;
38   WORD16 sampling_rate_index;
39   WORD16 num_window_groups;
40   WORD8 window_group_length[8];
41   WORD16 frame_length;
42   WORD32 frame_size;
43   WORD16 predictor_data_present;
44   ltp_info ltp;
45   ltp_info ltp2;
46 } ia_ics_info_struct;
47 
48 typedef struct {
49   WORD32 aac_sect_data_resil_flag;
50   WORD32 aac_sf_data_resil_flag;
51   WORD32 aac_spect_data_resil_flag;
52   WORD32 ep_config;
53 } ia_aac_err_config_struct;
54 
55 typedef struct {
56   WORD32 ld_sbr_flag_present;
57   WORD32 ld_sbr_samp_rate;
58   WORD32 ld_sbr_crc_flag;
59   WORD32 ldSbrHeaderPresent;
60 
61   WORD32 aac_sect_data_resil_flag;
62   WORD32 aac_sf_data_resil_flag;
63   WORD32 aac_spect_data_resil_flag;
64   WORD32 ep_config;
65 
66 } ia_eld_specific_config_struct;
67 
68 typedef struct {
69   UWORD8 ms_used[JOINT_STEREO_MAX_GROUPS][JOINT_STEREO_MAX_BANDS];
70 } ia_stereo_info_struct;
71 
72 typedef struct {
73   WORD16 start_band;
74   WORD16 stop_band;
75   WORD8 direction;
76   WORD8 resolution;
77   WORD8 order;
78   WORD8 coef[MAX_ORDER];
79 } ia_filter_info_struct;
80 
81 typedef struct {
82   FLAG tns_data_present;
83   WORD8 n_filt[MAX_WINDOWS];
84   ia_filter_info_struct str_filter[MAX_WINDOWS][MAX_FILTERS];
85 } ia_tns_info_aac_struct;
86 
87 typedef struct {
88   const WORD16 *ptr_long_window[2];
89   const WORD16 *ptr_short_window[2];
90   WORD16 window_shape;
91   WORD16 window_sequence;
92   WORD32 *ptr_overlap_buf;
93 
94   WORD16 rvlc_prev_sf[128];
95   WORD16 rvlc_prev_cb[128];
96   WORD8 rvlc_prev_blk_type;
97   WORD8 rvlc_prev_sf_ok;
98 
99 } ia_aac_dec_overlap_info;
100 
101 typedef struct {
102   WORD32 sf_concealment;
103   WORD32 rev_global_gain;
104   WORD16 rvlc_sf_len;
105   WORD32 dpcm_noise_nrg;
106   WORD32 sf_esc_present;
107   WORD16 rvlc_esc_len;
108   WORD32 dpcm_noise_last_pos;
109 
110   WORD32 dpcm_is_last_pos;
111 
112   WORD16 rvlc_sf_fwd_len;
113   WORD16 rvlc_sf_bwd_len;
114 
115   WORD16 *ptr_rvl_bit_cnt;
116   UWORD16 *ptr_rvl_bit_str_idx;
117 
118   WORD16 num_wind_grps;
119   WORD16 max_sfb_transmitted;
120   UWORD8 first_noise_group;
121   UWORD8 first_noise_band;
122   UWORD8 direction;
123 
124   UWORD16 rvl_fwd_bit_str_idx;
125   UWORD16 rvl_bwd_bit_str_idx;
126   UWORD16 esc_bit_str_idx;
127 
128   const UWORD32 *ptr_huff_tree_rvl_cw;
129   const UWORD32 *ptr_huff_tree_rvl_esc;
130 
131   UWORD8 num_fwd_esc_words_decoded;
132   UWORD8 num_bwd_esc_words_decoded;
133   UWORD8 num_esc_words_decoded;
134 
135   WORD8 noise_used;
136   WORD8 intensity_used;
137   WORD8 sf_used;
138 
139   WORD16 firt_scale_fac;
140   WORD16 last_scale_fac;
141   WORD16 first_nrg;
142   WORD16 last_nrg;
143   WORD16 is_first;
144   WORD16 is_last;
145 
146   UWORD32 rvlc_err_log;
147   WORD16 conceal_min;
148   WORD16 conceal_max;
149   WORD16 conceal_min_esc;
150   WORD16 conceal_max_esc;
151 } ia_rvlc_info_struct;
152 
153 #define LINES_PER_UNIT 4
154 
155 #define MAX_SFB_HCR (((1024 / 8) / LINES_PER_UNIT) * 8)
156 #define NUMBER_OF_UNIT_GROUPS (LINES_PER_UNIT * 8)
157 #define LINES_PER_UNIT_GROUP (1024 / NUMBER_OF_UNIT_GROUPS)
158 
159 #define FROM_LEFT_TO_RIGHT 0
160 #define FROM_RIGHT_TO_LEFT 1
161 
162 #define MAX_CB_PAIRS 23
163 #define MAX_HCR_SETS 14
164 
165 #define ESCAPE_VALUE 16
166 #define POSITION_OF_FLAG_A 21
167 #define POSITION_OF_FLAG_B 20
168 
169 #define MAX_CB 32
170 
171 #define MAX_CB_CHECK 32
172 #define WORD_BITS 32
173 
174 #define THIRTYTWO_LOG_DIV_TWO_LOG 5
175 #define EIGHT_LOG_DIV_TWO_LOG 3
176 #define FOUR_LOG_DIV_TWO_LOG 2
177 
178 #define CPE_TOP_LENGTH 12288
179 #define SCE_TOP_LENGTH 6144
180 #define LEN_OF_LONGEST_CW_TOP_LENGTH 49
181 #define Q_VALUE_INVALID 8192
182 #define NODE_MASK 0x400
183 
184 #define ERROR_POS 0x00000001
185 #define HCR_FATAL_PCW_ERROR_MASK 0x100E01FC
186 
187 typedef enum { PCW, PCW_SIGN, PCW_ESC_SIGN } ia_pcw_type_struct;
188 
189 typedef struct {
190   UWORD32 err_log;
191   WORD32 *ptr_quant_spec_coeff_base;
192   WORD32 quant_spec_coeff_idx;
193   WORD16 reordered_spec_data_len;
194   WORD16 num_sect;
195   WORD16 *ptr_num_line_in_sect;
196   UWORD16 bit_str_idx;
197   WORD8 longest_cw_len;
198   UWORD8 *ptr_cb;
199 } ia_huff_code_reorder_io_struct;
200 
201 typedef struct {
202   const UWORD8 *ptr_min_cb_pair_tbl;
203   const UWORD8 *ptr_max_cb_pair_tbl;
204 } ia_huff_code_reorder_cb_pairs_struct;
205 
206 typedef struct {
207   const UWORD16 *ptr_lav_tbl;
208   const UWORD8 *ptr_max_cw_len_tbl;
209   const UWORD8 *ptr_cb_dimension_tbl;
210   const UWORD8 *ptr_cb_dim_shift_tbl;
211   const UWORD8 *ptr_cb_sign_tbl;
212   const UWORD8 *ptr_cb_priority;
213 } ia_huff_code_reorder_tbl_struct;
214 
215 typedef struct {
216   WORD32 num_segment;
217   UWORD32 segment_offset;
218   WORD32 arr_temp_values[1024];
219   UWORD16 arr_seg_start_l[1024 >> 1];
220   UWORD16 arr_seg_start_r[1024 >> 1];
221   WORD8 p_remaining_bits_in_seg[1024 >> 1];
222   WORD32 code[512];
223   WORD32 code_extra[512];
224   WORD8 p_num_bits[512];
225   UWORD8 read_direction;
226   WORD32 is_decoded[512];
227 } ia_huff_code_reord_seg_info_struct;
228 
229 typedef struct {
230   UWORD32 num_code_word;
231   UWORD32 current_codeword;
232   UWORD32 num_sorted_section;
233   UWORD16 ptr_num_cw_in_sect[MAX_SFB_HCR];
234   UWORD16 ptr_num_sorted_cw_in_sect[MAX_SFB_HCR];
235   UWORD16 ptr_num_ext_sorted_cw_in_sect[MAX_SFB_HCR + MAX_HCR_SETS];
236   WORD32 num_ext_sorted_cw_in_sect_idx;
237   UWORD16 ptr_num_ext_sorted_sect_in_sets[MAX_HCR_SETS];
238   WORD32 num_ext_sorted_sect_in_sets_idx;
239   UWORD16 ptr_reorder_offset[MAX_SFB_HCR];
240   UWORD8 ptr_sorted_cb[MAX_SFB_HCR];
241 
242   UWORD8 ptr_ext_sorted_cw[MAX_SFB_HCR + MAX_HCR_SETS];
243   WORD32 ext_sorted_cw_idx;
244   UWORD8 ptr_ext_sorted_sect_max_cb_len[MAX_SFB_HCR + MAX_HCR_SETS];
245   WORD32 ext_sorted_sect_max_cb_len_idx;
246   UWORD8 ptr_cb_switch[MAX_SFB_HCR];
247 } ia_huff_code_reord_sect_info_struct;
248 
249 typedef UWORD32 (*ixheaacd_ptr_state_func)(ia_bit_buf_struct *, pVOID);
250 
251 typedef struct {
252   WORD32 *ptr_result_base;
253   UWORD16 res_ptr_idx[1024 >> 2];
254   UWORD32 cw_offset;
255   UWORD8 ptr_cb[1024 >> 2];
256 } ia_hcr_non_pcw_sideinfo_struct;
257 
258 typedef struct {
259   ia_huff_code_reorder_io_struct str_dec_io;
260   ia_huff_code_reorder_cb_pairs_struct codebook_pairs;
261   ia_huff_code_reorder_tbl_struct table_info;
262   ia_huff_code_reord_seg_info_struct str_segment_info;
263   ia_huff_code_reord_sect_info_struct sect_info;
264   ia_hcr_non_pcw_sideinfo_struct str_non_pcw_side_info;
265 
266   WORD32 global_hcr_type;
267 } ia_hcr_info_struct;
268 
269 typedef struct {
270   WORD16 scale_factor[MAX_WINDOWS * MAX_SFB_SHORT];
271   WORD8 code_book[MAX_WINDOWS * MAX_SFB_SHORT];
272 } ia_aac_sfb_code_book_struct;
273 
274 typedef struct {
275   ia_stereo_info_struct str_stereo_info;
276   ia_pns_correlation_info_struct str_pns_corr_info;
277 } ia_pns_stereo_data_struct;
278 
279 typedef struct {
280   WORD16 win_shape;
281   WORD16 win_seq;
282 
283   WORD32 *ptr_overlap_buf;
284 
285 } ia_aac_dec_ola_data;
286 
287 typedef struct {
288   const WORD16 *ptr_long_window[2];
289   const WORD16 *ptr_short_window[2];
290 
291   ia_aac_dec_ola_data overlap_add_data;
292 
293   WORD16 *ltp_buf;
294   UWORD16 ltp_lag;
295 
296 } ia_aac_dec_channel_info;
297 
298 typedef struct {
299   WORD16 *ptr_scale_factor;
300   WORD8 *ptr_code_book;
301   WORD32 *ptr_spec_coeff;
302   ia_stereo_info_struct *pstr_stereo_info;
303   ia_pns_correlation_info_struct *pstr_pns_corr_info;
304   ia_pns_rand_vec_struct *pstr_pns_rand_vec_data;
305   ia_ics_info_struct str_ics_info;
306   ia_tns_info_aac_struct str_tns_info;
307   ia_pulse_info_struct str_pulse_info;
308   ia_pns_info_struct str_pns_info;
309   WORD16 common_window;
310   WORD16 element_instance_tag;
311   WORD16 global_gain;
312   WORD32 *scratch_buf_ptr;
313   WORD32 *pulse_scratch;
314   ia_rvlc_info_struct ptr_rvlc_info;
315   ia_hcr_info_struct str_hcr_info;
316   WORD16 reorder_spect_data_len;
317   WORD8 longest_cw_len;
318   WORD16 rvlc_scf_esc_arr[128];
319   WORD16 rvlc_scf_fwd_arr[128];
320   WORD16 rvlc_scf_bwd_arr[128];
321   WORD8 rvlc_intensity_used;
322   WORD16 num_line_in_sec4_hcr_arr[32 * 8];
323   UWORD8 cb4_hcr_arr[32 * 8];
324   WORD32 number_sect;
325   WORD32 granule_len;
326   WORD16 rvlc_curr_sf_flag;
327   WORD16 *ltp_buf;
328   UWORD16 ltp_lag;
329 } ia_aac_dec_channel_info_struct;
330 WORD16 ixheaacd_ics_read(ia_bit_buf_struct *it_bit_buff,
331                          ia_ics_info_struct *ptr_ics_info,
332                          WORD8 num_swb_window[2], WORD32 object_type,
333                          WORD32 common_window, WORD32 frame_size);
334 
335 IA_ERRORCODE ixheaacd_ltp_decode(ia_bit_buf_struct *it_bit_buff,
336                                  ia_ics_info_struct *ptr_ics_info,
337                                  WORD32 object_type, WORD32 frame_size,
338                                  WORD32 ch);
339 
340 #endif /* #ifndef IXHEAACD_CHANNELINFO_H */
341