/src/libxaac/decoder/ixheaacd_mps_bitdec.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2023 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 | | #include <string.h> |
21 | | #include "ixheaac_type_def.h" |
22 | | #include "ixheaacd_mps_struct_def.h" |
23 | | #include "ixheaacd_error_codes.h" |
24 | | #include "ixheaacd_bitbuffer.h" |
25 | | #include "ixheaacd_mps_res_rom.h" |
26 | | #include "ixheaacd_mps_aac_struct.h" |
27 | | #include "ixheaacd_mps_res_channel.h" |
28 | | #include "ixheaac_constants.h" |
29 | | #include "ixheaacd_cnst.h" |
30 | | #include "ixheaacd_common_rom.h" |
31 | | #include "ixheaacd_sbrdecsettings.h" |
32 | | #include "ixheaacd_sbr_scale.h" |
33 | | #include "ixheaacd_env_extr_part.h" |
34 | | #include "ixheaacd_sbr_rom.h" |
35 | | #include "ixheaacd_hybrid.h" |
36 | | #include "ixheaacd_ps_dec.h" |
37 | | #include "ixheaacd_mps_polyphase.h" |
38 | | #include "ixheaac_error_standards.h" |
39 | | #include "ixheaacd_config.h" |
40 | | #include "ixheaacd_qmf_dec.h" |
41 | | #include "ixheaacd_mps_dec.h" |
42 | | #include "ixheaacd_mps_interface.h" |
43 | | #include "ixheaacd_mps_macro_def.h" |
44 | | #include "ixheaacd_mps_nlc_dec.h" |
45 | | #include "ixheaacd_mps_bitdec.h" |
46 | | #include "ixheaacd_mps_res_tns.h" |
47 | | #include "ixheaacd_mps_mdct_2_qmf.h" |
48 | | #include "ixheaac_sbr_const.h" |
49 | | |
50 | | static const WORD32 ixheaacd_freq_res_table[] = {0, 28, 20, 14, 10, 7, 5, 4}; |
51 | | |
52 | 2.15M | static WORD32 ixheaacd_bound_check(WORD32 var, WORD32 lower_bound, WORD32 upper_bound) { |
53 | 2.15M | var = min(var, upper_bound); |
54 | 2.15M | var = max(var, lower_bound); |
55 | 2.15M | return var; |
56 | 2.15M | } |
57 | | |
58 | | static VOID ixheaacd_mps_check_index_bounds( |
59 | | WORD32 output_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], |
60 | | WORD32 num_parameter_sets, WORD32 start_band, WORD32 stop_band, |
61 | 79.8k | WORD32 param_type, WORD32 xtt_idx) { |
62 | 79.8k | WORD32 i, band; |
63 | 228k | for (i = 0; i < num_parameter_sets; i++) { |
64 | 2.38M | for (band = start_band; band < stop_band; band++) { |
65 | 2.23M | if (param_type == CLD) { |
66 | 1.20M | output_idx_data[xtt_idx][i][band] = |
67 | 1.20M | ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], -15, 15); |
68 | 1.20M | } else if (param_type == ICC) { |
69 | 948k | output_idx_data[xtt_idx][i][band] = |
70 | 948k | ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], 0, 7); |
71 | 948k | } |
72 | 2.23M | } |
73 | 148k | } |
74 | 79.8k | } |
75 | | |
76 | | static IA_ERRORCODE ixheaacd_parse_extension_config( |
77 | | ia_mps_spatial_bs_config_struct *config, WORD32 num_ott_boxes, WORD32 num_ttt_boxes, |
78 | | WORD32 num_out_chan, WORD32 bits_available, ia_bit_buf_struct *it_bit_buff, |
79 | 4.09k | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
80 | 4.09k | WORD32 i, ch, idx, tmp, tmp_open, sac_ext_len, bits_read, n_fill_bits, temp; |
81 | 4.09k | WORD32 ba = bits_available; |
82 | | |
83 | 4.09k | config->sac_ext_cnt = 0; |
84 | | |
85 | 5.04k | while (ba >= 8) { |
86 | 999 | ba -= 8; |
87 | 999 | temp = ixheaacd_read_bits_buf(it_bit_buff, 8); |
88 | 999 | config->bs_sac_ext_type[config->sac_ext_cnt] = (temp >> 4) & FOUR_BIT_MASK; |
89 | 999 | sac_ext_len = temp & FOUR_BIT_MASK; |
90 | 999 | if (sac_ext_len == 15) { |
91 | 7 | sac_ext_len += ixheaacd_read_bits_buf(it_bit_buff, 8); |
92 | 7 | ba -= 8; |
93 | 7 | if (sac_ext_len == 15 + 255) { |
94 | 3 | sac_ext_len += ixheaacd_read_bits_buf(it_bit_buff, 16); |
95 | 3 | ba -= 16; |
96 | 3 | } |
97 | 7 | } |
98 | | |
99 | 999 | tmp = (WORD32)(((it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base + 1) << 3) - |
100 | 999 | (it_bit_buff->bit_pos + 1)); |
101 | | |
102 | 999 | switch (config->bs_sac_ext_type[config->sac_ext_cnt]) { |
103 | 672 | case EXT_TYPE_0: |
104 | 672 | config->bs_residual_coding = 1; |
105 | 672 | temp = ixheaacd_read_bits_buf(it_bit_buff, 6); |
106 | 672 | config->bs_residual_sampling_freq_index = (temp >> 2) & FOUR_BIT_MASK; |
107 | 672 | if (config->bs_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) { |
108 | 2 | return IA_FATAL_ERROR; |
109 | 2 | } |
110 | 670 | config->bs_residual_frames_per_spatial_frame = temp & TWO_BIT_MASK; |
111 | | |
112 | 3.54k | for (i = 0; i < num_ott_boxes + num_ttt_boxes; i++) { |
113 | 2.87k | config->bs_residual_present[i] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
114 | 2.87k | if (config->bs_residual_present[i]) { |
115 | 869 | config->bs_residual_bands[i] = ixheaacd_read_bits_buf(it_bit_buff, 5); |
116 | 869 | if (config->bs_residual_bands[i] > MAX_PARAMETER_BANDS) |
117 | 5 | { |
118 | 5 | return IA_FATAL_ERROR; |
119 | 5 | } |
120 | 869 | } |
121 | 2.87k | } |
122 | 665 | break; |
123 | | |
124 | 665 | case EXT_TYPE_1: |
125 | 234 | config->bs_arbitrary_downmix = 2; |
126 | | |
127 | 234 | temp = ixheaacd_read_bits_buf(it_bit_buff, 11); |
128 | 234 | config->bs_arbitrary_downmix_residual_sampling_freq_index = (temp >> 7) & FOUR_BIT_MASK; |
129 | 234 | if (config->bs_arbitrary_downmix_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) { |
130 | 3 | return IA_FATAL_ERROR; |
131 | 3 | } |
132 | 231 | config->bs_arbitrary_downmix_residual_frames_per_spatial_frame = |
133 | 231 | (temp >> 5) & TWO_BIT_MASK; |
134 | 231 | config->bs_arbitrary_downmix_residual_bands = temp & FIVE_BIT_MASK; |
135 | 231 | if (config->bs_arbitrary_downmix_residual_bands >= |
136 | 231 | ixheaacd_freq_res_table[config->bs_freq_res]) { |
137 | 3 | return IA_FATAL_ERROR; |
138 | 3 | } |
139 | | |
140 | 228 | break; |
141 | | |
142 | 228 | case EXT_TYPE_2: |
143 | 84 | config->arbitrary_tree = 1; |
144 | 84 | config->num_out_chan_at = 0; |
145 | 84 | config->num_ott_boxes_at = 0; |
146 | 577 | for (ch = 0; ch < num_out_chan; ch++) { |
147 | 511 | tmp_open = 1; |
148 | 511 | idx = 0; |
149 | 1.22k | while (tmp_open > 0) { |
150 | 733 | config->bs_ott_box_present_at[ch][idx] = ixheaacd_read_bits_buf(it_bit_buff, 1); |
151 | 733 | if (config->bs_ott_box_present_at[ch][idx]) { |
152 | 139 | config->num_ott_boxes_at++; |
153 | 139 | tmp_open++; |
154 | 594 | } else { |
155 | 594 | config->num_out_chan_at++; |
156 | 594 | tmp_open--; |
157 | 594 | } |
158 | 733 | if (config->num_ott_boxes_at >= 56) return IA_FATAL_ERROR; |
159 | 733 | if (config->num_out_chan_at > MAX_OUTPUT_CHANNELS_AT_MPS) return IA_FATAL_ERROR; |
160 | 724 | idx++; |
161 | 724 | if (idx >= MAX_ARBITRARY_TREE_INDEX) return IA_FATAL_ERROR; |
162 | 724 | } |
163 | 511 | } |
164 | | |
165 | 114 | for (i = 0; i < config->num_ott_boxes_at; i++) { |
166 | 49 | temp = ixheaacd_read_bits_buf(it_bit_buff, 2); |
167 | 49 | config->bs_ott_default_cld_at[i] = (temp >> 1) & ONE_BIT_MASK; |
168 | 49 | config->bs_ott_mode_lfe_at[i] = temp & ONE_BIT_MASK; |
169 | 49 | if (config->bs_ott_mode_lfe_at[i]) { |
170 | 12 | config->bs_ott_bands_at[i] = ixheaacd_read_bits_buf(it_bit_buff, 5); |
171 | 12 | if (config->bs_ott_bands_at[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR; |
172 | 37 | } else { |
173 | 37 | config->bs_ott_bands_at[i] = |
174 | 37 | ixheaacd_mps_dec_bitdec_tables->freq_res_table[config->bs_freq_res]; |
175 | 37 | } |
176 | 49 | } |
177 | | |
178 | 505 | for (i = 0; i < config->num_out_chan_at; i++) { |
179 | 440 | config->bs_output_channel_pos_at[i] = ixheaacd_read_bits_buf(it_bit_buff, 5); |
180 | 440 | } |
181 | | |
182 | 65 | break; |
183 | | |
184 | 5 | default: |
185 | 5 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_EXTENSION_TYPE; |
186 | 999 | } |
187 | | |
188 | 952 | bits_read = (WORD32)(((it_bit_buff->ptr_read_next - it_bit_buff->ptr_bit_buf_base + 1) << 3) - |
189 | 952 | (it_bit_buff->bit_pos + 1) - tmp); |
190 | 952 | n_fill_bits = 8 * sac_ext_len - bits_read; |
191 | | |
192 | 3.17k | while (n_fill_bits > 7) { |
193 | 2.22k | ixheaacd_read_bits_buf(it_bit_buff, 8); |
194 | 2.22k | n_fill_bits -= 8; |
195 | 2.22k | } |
196 | 952 | if (n_fill_bits > 0) { |
197 | 434 | ixheaacd_read_bits_buf(it_bit_buff, n_fill_bits); |
198 | 434 | } |
199 | | |
200 | 952 | ba -= 8 * sac_ext_len; |
201 | 952 | config->sac_ext_cnt++; |
202 | 952 | if (config->sac_ext_cnt >= MAX_NUM_EXT_TYPES) { |
203 | 1 | return IA_FATAL_ERROR; |
204 | 1 | } |
205 | 952 | } |
206 | | |
207 | 4.04k | return IA_NO_ERROR; |
208 | 4.09k | } |
209 | | |
210 | | IA_ERRORCODE ixheaacd_parse_specific_config(ia_heaac_mps_state_struct *pstr_mps_state, |
211 | 4.13k | WORD32 sac_header_len) { |
212 | 4.13k | IA_ERRORCODE err_code = IA_NO_ERROR; |
213 | 4.13k | ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config); |
214 | 4.13k | ia_heaac_mps_state_struct *curr_state = pstr_mps_state; |
215 | 4.13k | const ia_mps_dec_tree_properties_struct *p_tree_property_table = |
216 | 4.13k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->tree_property_table; |
217 | 4.13k | ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff; |
218 | | |
219 | 4.13k | WORD32 i, hc, hb, num_header_bits, ott_mode_lfe[MAX_NUM_OTT]; |
220 | | |
221 | 4.13k | WORD32 tmp = (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) - |
222 | 4.13k | (mps_bit_buf->bit_pos + 1)); |
223 | 4.13k | WORD32 bits_available = (sac_header_len << 3); |
224 | 4.13k | WORD32 temp, alignment_bits = 0; |
225 | | |
226 | 4.13k | config->bs_sampling_freq_index = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
227 | 4.13k | if (config->bs_sampling_freq_index == 15) { |
228 | 22 | config->bs_sampling_frequency = ixheaacd_read_bits_buf(mps_bit_buf, 24); |
229 | 22 | } |
230 | 4.13k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 14); |
231 | 4.13k | config->bs_frame_length = (temp >> 7) & SEVEN_BIT_MASK; |
232 | 4.13k | if (config->bs_frame_length >= (MAX_QMF_BUF_LEN - 1)) { |
233 | 1 | return IA_FATAL_ERROR; |
234 | 1 | } |
235 | 4.13k | config->bs_freq_res = (temp >> 4) & THREE_BIT_MASK; |
236 | 4.13k | if (config->bs_freq_res == 0) { |
237 | 2 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_BANDS; |
238 | 2 | } |
239 | 4.13k | config->bs_tree_config = (temp)&FOUR_BIT_MASK; |
240 | | |
241 | 4.13k | if (config->bs_tree_config >= 7) { |
242 | 3 | return IA_FATAL_ERROR; |
243 | 3 | } |
244 | | |
245 | 4.12k | if (config->bs_tree_config != 15) { |
246 | 4.12k | curr_state->num_ott_boxes = p_tree_property_table[config->bs_tree_config].num_ott_boxes; |
247 | 4.12k | curr_state->num_ttt_boxes = p_tree_property_table[config->bs_tree_config].num_ttt_boxes; |
248 | 4.12k | curr_state->num_input_channels = |
249 | 4.12k | p_tree_property_table[config->bs_tree_config].num_input_channels; |
250 | 4.12k | curr_state->num_output_channels = |
251 | 4.12k | p_tree_property_table[config->bs_tree_config].num_output_channels; |
252 | 24.7k | for (i = 0; i < MAX_NUM_OTT; i++) { |
253 | 20.6k | ott_mode_lfe[i] = p_tree_property_table[config->bs_tree_config].ott_mode_lfe[i]; |
254 | 20.6k | } |
255 | 4.12k | } |
256 | 4.12k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 19); |
257 | 4.12k | config->bs_quant_mode = (temp >> 17) & TWO_BIT_MASK; |
258 | 4.12k | config->bs_one_icc = (temp >> 16) & ONE_BIT_MASK; |
259 | 4.12k | config->bs_arbitrary_downmix = (temp >> 15) & ONE_BIT_MASK; |
260 | 4.12k | config->bs_fixed_gain_sur = (temp >> 12) & THREE_BIT_MASK; |
261 | 4.12k | if (config->bs_fixed_gain_sur >= 5) { |
262 | 1 | return IA_FATAL_ERROR; |
263 | 1 | } |
264 | 4.12k | config->bs_fixed_gain_lfe = (temp >> 9) & THREE_BIT_MASK; |
265 | | |
266 | 4.12k | if (config->bs_fixed_gain_lfe >= 5) return IA_FATAL_ERROR; |
267 | 4.12k | config->bs_fixed_gain_dmx = (temp >> 6) & THREE_BIT_MASK; |
268 | 4.12k | config->bs_matrix_mode = (temp >> 5) & ONE_BIT_MASK; |
269 | 4.12k | config->bs_temp_shape_config = (temp >> 3) & TWO_BIT_MASK; |
270 | 4.12k | if (config->bs_temp_shape_config == 3) |
271 | 1 | return IA_FATAL_ERROR; |
272 | | |
273 | 4.12k | config->bs_decorr_config = (temp >> 1) & TWO_BIT_MASK; |
274 | 4.12k | config->bs_3d_audio_mode = (temp)&ONE_BIT_MASK; |
275 | | |
276 | 18.3k | for (i = 0; i < curr_state->num_ott_boxes; i++) { |
277 | 14.1k | if (ott_mode_lfe[i]) { |
278 | 2.79k | config->bs_ott_bands[i] = ixheaacd_read_bits_buf(mps_bit_buf, 5); |
279 | 2.79k | if (config->bs_ott_bands[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR; |
280 | 2.79k | } |
281 | 14.1k | } |
282 | | |
283 | 5.98k | for (i = 0; i < curr_state->num_ttt_boxes; i++) { |
284 | 1.85k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
285 | 1.85k | config->bs_ttt_dual_mode[i] = (temp >> 3) & ONE_BIT_MASK; |
286 | 1.85k | config->bs_ttt_mode_low[i] = (temp)&THREE_BIT_MASK; |
287 | 1.85k | if (config->bs_ttt_dual_mode[i]) { |
288 | 1.27k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 8); |
289 | 1.27k | config->bs_ttt_mode_high[i] = (temp >> 5) & THREE_BIT_MASK; |
290 | 1.27k | config->bs_ttt_bands_low[i] = (temp)&FIVE_BIT_MASK; |
291 | 1.27k | if (config->bs_ttt_bands_low[i] > MAX_PARAMETER_BANDS) return IA_FATAL_ERROR; |
292 | 1.27k | } |
293 | 1.85k | } |
294 | | |
295 | 4.12k | if (config->bs_temp_shape_config == 2) { |
296 | 1.29k | config->bs_env_quant_mode = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
297 | 1.29k | } |
298 | | |
299 | 4.12k | if (config->bs_3d_audio_mode) { |
300 | 43 | config->bs_3d_audio_hrtf_set = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
301 | 43 | if (config->bs_3d_audio_hrtf_set == 0) { |
302 | 32 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
303 | 32 | config->bs_hrtf_freq_res = (temp >> 1) & THREE_BIT_MASK; |
304 | 32 | config->bs_hrtf_num_chan = 5; |
305 | 32 | config->bs_hrtf_asymmetric = (temp)&ONE_BIT_MASK; |
306 | | |
307 | 32 | config->hrtf_num_band = pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr |
308 | 32 | ->freq_res_table[config->bs_hrtf_freq_res]; |
309 | | |
310 | 115 | for (hc = 0; hc < config->bs_hrtf_num_chan; hc++) { |
311 | 712 | for (hb = 0; hb < config->hrtf_num_band; hb++) { |
312 | 629 | config->bs_hrtf_level_left[hc][hb] = ixheaacd_read_bits_buf(mps_bit_buf, 6); |
313 | 629 | } |
314 | 604 | for (hb = 0; hb < config->hrtf_num_band; hb++) { |
315 | 521 | config->bs_hrtf_level_right[hc][hb] = config->bs_hrtf_asymmetric |
316 | 521 | ? ixheaacd_read_bits_buf(mps_bit_buf, 6) |
317 | 521 | : config->bs_hrtf_level_left[hc][hb]; |
318 | 521 | } |
319 | 83 | config->bs_hrtf_phase[hc] = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
320 | 500 | for (hb = 0; hb < config->hrtf_num_band; hb++) { |
321 | 417 | config->bs_hrtf_phase_lr[hc][hb] = |
322 | 417 | config->bs_hrtf_phase[hc] ? ixheaacd_read_bits_buf(mps_bit_buf, 6) : 0; |
323 | 417 | } |
324 | 83 | } |
325 | 32 | } |
326 | 43 | } |
327 | | |
328 | 4.12k | ixheaacd_byte_align(mps_bit_buf, &alignment_bits); |
329 | | |
330 | 4.12k | num_header_bits = |
331 | 4.12k | (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) - |
332 | 4.12k | (mps_bit_buf->bit_pos + 1) - tmp); |
333 | 4.12k | bits_available -= num_header_bits; |
334 | | |
335 | 4.12k | err_code = ixheaacd_parse_extension_config( |
336 | 4.12k | config, curr_state->num_ott_boxes, curr_state->num_ttt_boxes, |
337 | 4.12k | curr_state->num_output_channels, bits_available, mps_bit_buf, |
338 | 4.12k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr); |
339 | 4.12k | if (err_code != IA_NO_ERROR) return err_code; |
340 | | |
341 | 4.08k | return IA_NO_ERROR; |
342 | 4.12k | } |
343 | | |
344 | | IA_ERRORCODE ixheaacd_default_specific_config(ia_heaac_mps_state_struct *pstr_mps_state, |
345 | 0 | WORD32 sampling_freq) { |
346 | 0 | ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config); |
347 | 0 | ia_heaac_mps_state_struct *curr_state = pstr_mps_state; |
348 | 0 | const ia_mps_dec_tree_properties_struct *p_tree_property_table = |
349 | 0 | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->tree_property_table; |
350 | 0 | WORD32 i, ott_mode_lfe[MAX_NUM_OTT]; |
351 | |
|
352 | 0 | config->bs_sampling_freq_index = 15; |
353 | 0 | for (i = 0; i < 15; i++) { |
354 | 0 | if (sampling_freq == |
355 | 0 | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->sampling_freq_table[i]) { |
356 | 0 | config->bs_sampling_freq_index = i; |
357 | 0 | } |
358 | 0 | } |
359 | 0 | if (config->bs_sampling_freq_index == 15) { |
360 | 0 | config->bs_sampling_frequency = sampling_freq; |
361 | 0 | } |
362 | 0 | config->bs_frame_length = 31; |
363 | 0 | config->bs_freq_res = 1; |
364 | 0 | config->bs_tree_config = 2; |
365 | 0 | if (config->bs_tree_config > 5) return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG; |
366 | 0 | if (config->bs_tree_config != 15) { |
367 | 0 | curr_state->num_ott_boxes = p_tree_property_table[config->bs_tree_config].num_ott_boxes; |
368 | 0 | curr_state->num_ttt_boxes = p_tree_property_table[config->bs_tree_config].num_ttt_boxes; |
369 | 0 | curr_state->num_input_channels = |
370 | 0 | p_tree_property_table[config->bs_tree_config].num_input_channels; |
371 | 0 | curr_state->num_output_channels = |
372 | 0 | p_tree_property_table[config->bs_tree_config].num_output_channels; |
373 | 0 | memcpy(ott_mode_lfe, p_tree_property_table[config->bs_tree_config].ott_mode_lfe, |
374 | 0 | MAX_NUM_OTT * sizeof(ott_mode_lfe[0])); |
375 | 0 | } |
376 | 0 | config->bs_quant_mode = 0; |
377 | 0 | config->bs_one_icc = 0; |
378 | 0 | config->bs_arbitrary_downmix = 0; |
379 | 0 | config->bs_residual_coding = 0; |
380 | 0 | config->bs_smooth_config = 0; |
381 | 0 | config->bs_fixed_gain_sur = 2; |
382 | 0 | config->bs_fixed_gain_lfe = 1; |
383 | 0 | config->bs_fixed_gain_dmx = 0; |
384 | 0 | config->bs_matrix_mode = 1; |
385 | 0 | config->bs_temp_shape_config = 0; |
386 | 0 | config->bs_decorr_config = 0; |
387 | 0 | if (config->bs_tree_config == 15) { |
388 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG; |
389 | 0 | } |
390 | 0 | for (i = 0; i < curr_state->num_ott_boxes; i++) { |
391 | 0 | if (ott_mode_lfe[i]) { |
392 | 0 | config->bs_ott_bands[i] = 28; |
393 | 0 | } |
394 | 0 | } |
395 | 0 | for (i = 0; i < curr_state->num_ttt_boxes; i++) { |
396 | 0 | config->bs_ttt_dual_mode[i] = 0; |
397 | 0 | config->bs_ttt_mode_low[i] = 1; |
398 | 0 | if (config->bs_ttt_dual_mode[i]) { |
399 | 0 | config->bs_ttt_mode_high[i] = 1; |
400 | 0 | config->bs_ttt_bands_low[i] = 28; |
401 | 0 | } |
402 | 0 | } |
403 | 0 | return IA_NO_ERROR; |
404 | 0 | } |
405 | | |
406 | | static VOID ixheaacd_coarse_2_fine(WORD32 *data, WORD32 data_type, WORD32 start_band, |
407 | 9.89k | WORD32 num_bands) { |
408 | 9.89k | WORD32 i; |
409 | | |
410 | 108k | for (i = start_band; i < start_band + num_bands; i++) { |
411 | 98.2k | data[i] <<= 1; |
412 | 98.2k | } |
413 | | |
414 | 9.89k | if (data_type == CLD) { |
415 | 62.6k | for (i = start_band; i < start_band + num_bands; i++) { |
416 | 56.2k | if (data[i] == -14) |
417 | 10.6k | data[i] = -15; |
418 | 45.6k | else if (data[i] == 14) |
419 | 7.57k | data[i] = 15; |
420 | 56.2k | } |
421 | 6.41k | } |
422 | 9.89k | } |
423 | | |
424 | 7.35k | static VOID ixheaacd_fine_2_coarse(WORD32 *data, WORD32 start_band, WORD32 num_bands) { |
425 | 7.35k | WORD32 i; |
426 | | |
427 | 101k | for (i = start_band; i < start_band + num_bands; i++) { |
428 | 94.1k | data[i] >>= 1; |
429 | 94.1k | } |
430 | 7.35k | } |
431 | | |
432 | | static WORD32 ixheaacd_get_stride_map( |
433 | | WORD32 freq_res_stride, WORD32 start_band, WORD32 stop_band, WORD32 *a_strides, |
434 | 23.3k | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
435 | 23.3k | WORD32 i, pb, pb_stride, data_bands, str_offset; |
436 | | |
437 | 23.3k | pb_stride = ixheaacd_mps_dec_bitdec_tables->pb_stride_table[freq_res_stride]; |
438 | 23.3k | data_bands = (stop_band - start_band - 1) / pb_stride + 1; |
439 | | |
440 | 23.3k | a_strides[0] = start_band; |
441 | 152k | for (pb = 1; pb <= data_bands; pb++) { |
442 | 129k | a_strides[pb] = a_strides[pb - 1] + pb_stride; |
443 | 129k | } |
444 | 23.3k | str_offset = 0; |
445 | 150k | while (a_strides[data_bands] > stop_band) { |
446 | 127k | if (str_offset < data_bands) str_offset++; |
447 | 262k | for (i = str_offset; i <= data_bands; i++) { |
448 | 134k | a_strides[i]--; |
449 | 134k | } |
450 | 127k | } |
451 | | |
452 | 23.3k | return data_bands; |
453 | 23.3k | } |
454 | | |
455 | | static IA_ERRORCODE ixheaacd_ec_data_dec(ia_heaac_mps_state_struct *pstr_mps_state, |
456 | | ia_mps_dec_lossless_data_struct *ll_data, |
457 | | WORD32 data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], |
458 | | WORD32 lastdata[][MAX_PARAMETER_BANDS], WORD32 datatype, |
459 | | WORD32 box_idx, WORD32 param_idx, WORD32 start_band, |
460 | 80.8k | WORD32 stop_band) { |
461 | 80.8k | IA_ERRORCODE error_code = IA_NO_ERROR; |
462 | 80.8k | WORD32 i, pb, data_sets, set_idx, bs_data_pair, data_bands, old_quant_coarse_xxx, temp; |
463 | 80.8k | WORD32 a_strides[MAX_PARAMETER_BANDS + 1] = {0}; |
464 | | |
465 | 80.8k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
466 | 80.8k | ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff; |
467 | | |
468 | 80.8k | data_sets = 0; |
469 | 232k | for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) { |
470 | 151k | ll_data->bs_xxx_data_mode[param_idx][i] = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
471 | 151k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) { |
472 | 29.2k | data_sets++; |
473 | 29.2k | } |
474 | 151k | } |
475 | 80.8k | set_idx = 0; |
476 | 80.8k | old_quant_coarse_xxx = ll_data->bs_quant_coarse_xxx_prev[param_idx]; |
477 | | |
478 | 104k | while (set_idx < data_sets) { |
479 | 23.3k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
480 | 23.3k | bs_data_pair = (temp >> 3) & ONE_BIT_MASK; |
481 | 23.3k | ll_data->bs_quant_coarse_xxx[param_idx][set_idx] = (temp >> 2) & ONE_BIT_MASK; |
482 | 23.3k | ll_data->bs_freq_res_stride_xxx[param_idx][set_idx] = temp & TWO_BIT_MASK; |
483 | | |
484 | 23.3k | if (set_idx == 7 && bs_data_pair == 1) { |
485 | 5 | if (pstr_mps_state->ec_flag) { |
486 | 0 | bs_data_pair = 0; |
487 | 5 | } else { |
488 | 5 | return IA_FATAL_ERROR; |
489 | 5 | } |
490 | 5 | } |
491 | | |
492 | 23.3k | if (ll_data->bs_quant_coarse_xxx[param_idx][set_idx] != old_quant_coarse_xxx) { |
493 | 8.70k | if (old_quant_coarse_xxx) { |
494 | 1.34k | ixheaacd_coarse_2_fine(lastdata[box_idx], datatype, start_band, stop_band - start_band); |
495 | 7.35k | } else { |
496 | 7.35k | ixheaacd_fine_2_coarse(lastdata[box_idx], start_band, stop_band - start_band); |
497 | 7.35k | } |
498 | 8.70k | } |
499 | | |
500 | 23.3k | data_bands = ixheaacd_get_stride_map(ll_data->bs_freq_res_stride_xxx[param_idx][set_idx], |
501 | 23.3k | start_band, stop_band, a_strides, |
502 | 23.3k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr); |
503 | | |
504 | 152k | for (pb = 0; pb < data_bands; pb++) { |
505 | 129k | lastdata[box_idx][start_band + pb] = lastdata[box_idx][a_strides[pb]]; |
506 | 129k | } |
507 | | |
508 | 23.3k | error_code = ixheaacd_mps_ecdatapairdec( |
509 | 23.3k | mps_bit_buf, data[box_idx], lastdata[box_idx], datatype, set_idx, start_band, data_bands, |
510 | 23.3k | bs_data_pair, ll_data->bs_quant_coarse_xxx[param_idx][set_idx], |
511 | 23.3k | (!frame->bs_independency_flag || (set_idx > 0)), 0, 1, pstr_mps_state->ec_flag); |
512 | 23.3k | if (error_code != IA_NO_ERROR) return error_code; |
513 | | |
514 | 23.3k | if (datatype == CLD) { |
515 | 17.2k | WORD32 band; |
516 | 82.9k | for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) { |
517 | 940k | for (band = start_band; band < stop_band; band++) { |
518 | 874k | if (data[box_idx][i][band] > 15 || data[box_idx][i][band] < -15) { |
519 | 73 | return IA_FATAL_ERROR; |
520 | 73 | } |
521 | 874k | } |
522 | 65.7k | } |
523 | 17.2k | } else if (datatype == ICC) { |
524 | 4.37k | WORD32 band; |
525 | 24.4k | for (i = 0; i < pstr_mps_state->num_parameter_sets; i++) { |
526 | 284k | for (band = start_band; band < stop_band; band++) { |
527 | 264k | if (data[box_idx][i][band] > 7 || data[box_idx][i][band] < 0) { |
528 | 57 | return IA_FATAL_ERROR; |
529 | 57 | } |
530 | 264k | } |
531 | 20.1k | } |
532 | 4.37k | } |
533 | | |
534 | 150k | for (pb = 0; pb < data_bands; pb++) { |
535 | 473k | for (i = a_strides[pb]; i < a_strides[pb + 1]; i++) { |
536 | 346k | lastdata[box_idx][i] = data[box_idx][set_idx + bs_data_pair][start_band + pb]; |
537 | 346k | } |
538 | 126k | } |
539 | | |
540 | 23.2k | old_quant_coarse_xxx = ll_data->bs_quant_coarse_xxx[param_idx][set_idx]; |
541 | | |
542 | 23.2k | if (bs_data_pair) { |
543 | 14.2k | ll_data->bs_quant_coarse_xxx[param_idx][set_idx + 1] = |
544 | 14.2k | ll_data->bs_quant_coarse_xxx[param_idx][set_idx]; |
545 | 14.2k | ll_data->bs_freq_res_stride_xxx[param_idx][set_idx + 1] = |
546 | 14.2k | ll_data->bs_freq_res_stride_xxx[param_idx][set_idx]; |
547 | 14.2k | } |
548 | 23.2k | set_idx += bs_data_pair + 1; |
549 | 23.2k | } |
550 | 80.7k | return error_code; |
551 | 80.8k | } |
552 | | |
553 | | static IA_ERRORCODE ixheaacd_parse_arbitrary_downmix_data( |
554 | 1.54k | ia_heaac_mps_state_struct *pstr_mps_state) { |
555 | 1.54k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
556 | 1.54k | IA_ERRORCODE error_code = IA_NO_ERROR; |
557 | 1.54k | WORD32 offset = pstr_mps_state->num_ott_boxes + 4 * pstr_mps_state->num_ttt_boxes; |
558 | 1.54k | WORD32 num_input_channels = pstr_mps_state->num_input_channels; |
559 | 1.54k | WORD32 bitstream_parameter_bands = pstr_mps_state->bitstream_parameter_bands; |
560 | 1.54k | WORD32 ch; |
561 | | |
562 | 3.73k | for (ch = 0; ch < num_input_channels; ch++) { |
563 | 2.23k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
564 | 2.23k | frame->cmp_arbdmx_gain_idx, frame->cmp_arbdmx_gain_idx_prev, |
565 | 2.23k | CLD, ch, offset + ch, 0, bitstream_parameter_bands); |
566 | 2.23k | if (error_code != IA_NO_ERROR) return error_code; |
567 | 2.23k | } |
568 | 1.50k | return error_code; |
569 | 1.54k | } |
570 | | |
571 | 5.71k | static WORD32 ixheaacd_decode_icc_diff_code(ia_bit_buf_struct *it_bit_buff) { |
572 | 5.71k | WORD32 value = 0; |
573 | 5.71k | WORD32 count = 0; |
574 | 13.7k | while ((ixheaacd_read_bits_buf(it_bit_buff, 1) == 0) && (count++ < 7)) { |
575 | 7.98k | value++; |
576 | 7.98k | } |
577 | | |
578 | 5.71k | return value; |
579 | 5.71k | } |
580 | | |
581 | 595 | static IA_ERRORCODE ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_state) { |
582 | 595 | WORD32 ich, ch; |
583 | 595 | WORD32 rfpsf; |
584 | 595 | WORD32 ps; |
585 | 595 | WORD32 pb; |
586 | | |
587 | 595 | ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr = |
588 | 595 | pstr_mps_state->ia_mps_dec_mps_table.aac_tab; |
589 | 595 | WORD32 i; |
590 | | |
591 | 595 | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
592 | 595 | ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config); |
593 | | |
594 | 595 | WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes; |
595 | 595 | WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets; |
596 | 595 | WORD32 residual_frames_per_spatial_frame = pstr_mps_state->residual_frames_per_spatial_frame; |
597 | 595 | WORD32 upd_qmf = pstr_mps_state->upd_qmf; |
598 | | |
599 | 595 | WORD32 loop_counter = num_ott_boxes + pstr_mps_state->num_ttt_boxes; |
600 | 595 | WORD32 *p_mdct_res; |
601 | | |
602 | 595 | WORD32 *p_res_mdct = pstr_mps_state->array_struct->res_mdct; |
603 | 595 | ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff; |
604 | 595 | WORD16 error_code = IA_NO_ERROR; |
605 | | |
606 | 2.82k | for (ich = 0; ich < loop_counter; ich++) { |
607 | 2.29k | ch = ich; |
608 | | |
609 | 2.29k | p_mdct_res = p_res_mdct; |
610 | 2.29k | if (config->bs_residual_bands[ch] > 0) { |
611 | 726 | if (ch < num_ott_boxes) { |
612 | 2.60k | for (ps = 0; ps < num_parameter_sets; ps++) { |
613 | 1.92k | frame->res_data.bs_icc_diff_present[ch][ps] = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
614 | 1.92k | if (frame->res_data.bs_icc_diff_present[ch][ps]) { |
615 | 6.06k | for (pb = 0; pb < config->bs_residual_bands[ch]; pb++) { |
616 | 5.71k | frame->res_data.bs_icc_diff[ch][ps][pb] = |
617 | 5.71k | ixheaacd_decode_icc_diff_code(mps_bit_buf); |
618 | 5.71k | frame->ott_icc_diff_idx[ch][ps][pb] = frame->res_data.bs_icc_diff[ch][ps][pb]; |
619 | 5.71k | } |
620 | 353 | } |
621 | 1.92k | } |
622 | 679 | } |
623 | 726 | p_mdct_res = p_res_mdct; |
624 | 1.36k | for (rfpsf = 0; rfpsf < residual_frames_per_spatial_frame; rfpsf++) { |
625 | 706 | error_code = |
626 | 706 | ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, |
627 | 706 | aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls); |
628 | 706 | if (error_code) { |
629 | 59 | if (pstr_mps_state->ec_flag) { |
630 | 0 | pstr_mps_state->frame_ok = 0; |
631 | 0 | } else |
632 | 59 | return error_code; |
633 | 59 | } |
634 | 647 | if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
635 | 111 | ixheaacd_res_ctns_apply( |
636 | 111 | pstr_mps_state->p_aac_decoder_channel_info[0], |
637 | 111 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
638 | 111 | aac_tables_ptr); |
639 | 647 | pstr_mps_state->res_block_type[ch][rfpsf] = |
640 | 647 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
641 | 645k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
642 | 645k | *p_mdct_res++ = |
643 | 645k | (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]); |
644 | 645k | } |
645 | | |
646 | 647 | if ((pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence == |
647 | 647 | EIGHT_SHORT_SEQUENCE) && |
648 | 222 | ((upd_qmf == UPD_QMF_18) || (upd_qmf == UPD_QMF_24) || (upd_qmf == UPD_QMF_30))) { |
649 | 35 | error_code = |
650 | 35 | ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, |
651 | 35 | aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls); |
652 | 35 | if (error_code) { |
653 | 5 | if (pstr_mps_state->ec_flag) { |
654 | 0 | pstr_mps_state->frame_ok = 0; |
655 | 0 | } else |
656 | 5 | return error_code; |
657 | 5 | } |
658 | 30 | if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
659 | 2 | ixheaacd_res_ctns_apply( |
660 | 2 | pstr_mps_state->p_aac_decoder_channel_info[0], |
661 | 2 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
662 | 2 | aac_tables_ptr); |
663 | 16.4k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
664 | 16.3k | *p_mdct_res++ = |
665 | 16.3k | (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]); |
666 | 16.3k | } |
667 | 30 | } |
668 | 647 | } |
669 | 726 | } |
670 | | |
671 | 2.23k | p_res_mdct += RFX2XMDCTCOEF; |
672 | 2.23k | } |
673 | 531 | return IA_NO_ERROR; |
674 | 595 | } |
675 | | |
676 | 14.8k | static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *pstr_mps_state) { |
677 | 14.8k | WORD32 i, fr, gr, offset, ch; |
678 | 14.8k | WORD32 ext_num, sac_ext_type, sac_ext_len, tmp, bits_read, n_fill_bits, temp; |
679 | 14.8k | WORD32 channel_grouping[MAX_INPUT_CHANNELS_MPS]; |
680 | | |
681 | 14.8k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
682 | 14.8k | ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config; |
683 | | |
684 | 14.8k | ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr = |
685 | 14.8k | pstr_mps_state->ia_mps_dec_mps_table.aac_tab; |
686 | | |
687 | 14.8k | WORD32 arbdmx_upd_qmf = pstr_mps_state->arbdmx_upd_qmf; |
688 | 14.8k | WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes; |
689 | 14.8k | WORD32 num_input_channels = pstr_mps_state->num_input_channels; |
690 | 14.8k | WORD32 num_ttt_boxes = pstr_mps_state->num_ttt_boxes; |
691 | 14.8k | WORD32 arbdmx_frames_per_spatial_frame = pstr_mps_state->arbdmx_frames_per_spatial_frame; |
692 | 14.8k | WORD32 *p_res_mdct, *p_mdct_res; |
693 | | |
694 | 14.8k | WORD32 sfidx; |
695 | 14.8k | VOID *free_scratch = pstr_mps_state->mps_scratch_mem_v; |
696 | 14.8k | ia_mps_dec_residual_sfband_info_struct *p_sfband_info_tab = &pstr_mps_state->sfband_info_tab; |
697 | 14.8k | ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff; |
698 | 14.8k | IA_ERRORCODE error_code = IA_NO_ERROR; |
699 | | |
700 | 44.6k | for (ch = 0; ch < 2; ch++) { |
701 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch] = free_scratch; |
702 | 29.7k | free_scratch = |
703 | 29.7k | (WORD8 *)free_scratch + |
704 | 29.7k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_residual_channel_info_struct), BYTE_ALIGN_8); |
705 | 29.7k | pstr_mps_state->p_aac_decoder_dynamic_data_init[ch] = free_scratch; |
706 | 29.7k | free_scratch = |
707 | 29.7k | (WORD8 *)free_scratch + |
708 | 29.7k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_residual_dynamic_data_struct), BYTE_ALIGN_8); |
709 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->p_scale_factor = |
710 | 29.7k | pstr_mps_state->p_aac_decoder_dynamic_data_init[ch]->a_scale_factor; |
711 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->p_code_book = |
712 | 29.7k | pstr_mps_state->p_aac_decoder_dynamic_data_init[ch]->a_code_book; |
713 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->p_spectral_coefficient = free_scratch; |
714 | 29.7k | free_scratch = (WORD8 *)free_scratch + IXHEAAC_GET_SIZE_ALIGNED(4096, BYTE_ALIGN_8); |
715 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->p_tns_scratch = free_scratch; |
716 | 29.7k | free_scratch = (WORD8 *)free_scratch + IXHEAAC_GET_SIZE_ALIGNED(4096, BYTE_ALIGN_8); |
717 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->ics_info.frame_length = AAC_FRAME_LENGTH; |
718 | 29.7k | pstr_mps_state->p_aac_decoder_channel_info[ch]->common_window = 0; |
719 | 29.7k | } |
720 | 14.8k | if (pstr_mps_state->arbitrary_downmix == 2) |
721 | 213 | sfidx = p_bs_config->bs_arbitrary_downmix_residual_sampling_freq_index; |
722 | 14.6k | else |
723 | 14.6k | sfidx = p_bs_config->bs_residual_sampling_freq_index; |
724 | 14.8k | { |
725 | 14.8k | WORD16 *psfb_idx[2]; |
726 | 14.8k | const WORD8 *psfb_width[2]; |
727 | 14.8k | WORD width_idx; |
728 | 14.8k | WORD32 j; |
729 | | |
730 | 14.8k | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.sampling_rate_index = sfidx; |
731 | 14.8k | psfb_idx[0] = p_sfband_info_tab->sfb_long_idx; |
732 | 14.8k | psfb_idx[1] = p_sfband_info_tab->sfb_short_idx; |
733 | 14.8k | psfb_width[0] = aac_tables_ptr->scale_factor_bands_long[sfidx]; |
734 | 14.8k | psfb_width[1] = aac_tables_ptr->scale_factor_bands_short[sfidx]; |
735 | | |
736 | 44.6k | for (j = 1; j >= 0; j--) { |
737 | 29.7k | const WORD8 *ptr_w = psfb_width[j]; |
738 | 29.7k | WORD16 *ptr_i = psfb_idx[j]; |
739 | 29.7k | width_idx = 0; |
740 | 29.7k | *ptr_i++ = width_idx; |
741 | 792k | do { |
742 | 792k | width_idx += (*ptr_w++); |
743 | 792k | *ptr_i++ = width_idx; |
744 | 792k | } while (*ptr_w != -1); |
745 | | |
746 | 29.7k | pstr_mps_state->tot_sf_bands_ls[j] = (WORD8)(ptr_w - psfb_width[j]); |
747 | 29.7k | } |
748 | | |
749 | 14.8k | { |
750 | 14.8k | aac_tables_ptr->sfb_index_long = p_sfband_info_tab->sfb_long_idx; |
751 | 14.8k | aac_tables_ptr->sfb_index_short = p_sfband_info_tab->sfb_short_idx; |
752 | 14.8k | aac_tables_ptr->sfb_index_long_width = (WORD8 *)psfb_width[0]; |
753 | 14.8k | aac_tables_ptr->sfb_index_short_width = (WORD8 *)psfb_width[1]; |
754 | 14.8k | } |
755 | 14.8k | } |
756 | | |
757 | 15.5k | for (ext_num = 0; ext_num < p_bs_config->sac_ext_cnt; ext_num++) { |
758 | 850 | sac_ext_type = p_bs_config->bs_sac_ext_type[ext_num]; |
759 | | |
760 | 850 | if (sac_ext_type < 12) { |
761 | 850 | sac_ext_len = ixheaacd_read_bits_buf(mps_bit_buf, 8); |
762 | 850 | if (sac_ext_len == 255) { |
763 | 11 | sac_ext_len += ixheaacd_read_bits_buf(mps_bit_buf, 16); |
764 | 11 | } |
765 | | |
766 | 850 | tmp = (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) - |
767 | 850 | (mps_bit_buf->bit_pos + 1)); |
768 | | |
769 | 850 | switch (sac_ext_type) { |
770 | 595 | case EXT_TYPE_0: |
771 | 595 | error_code = ixheaacd_parse_residual_data(pstr_mps_state); |
772 | 595 | if (error_code) { |
773 | 64 | if (pstr_mps_state->ec_flag) { |
774 | 0 | pstr_mps_state->frame_ok = 0; |
775 | 0 | } else |
776 | 64 | return error_code; |
777 | 64 | } |
778 | 531 | break; |
779 | | |
780 | 531 | case EXT_TYPE_1: |
781 | 212 | switch (num_input_channels) { |
782 | 148 | case IN_CH_1: |
783 | 148 | channel_grouping[0] = 1; |
784 | 148 | break; |
785 | 57 | case IN_CH_2: |
786 | 57 | channel_grouping[0] = 2; |
787 | 57 | break; |
788 | 7 | case IN_CH_6: |
789 | 7 | channel_grouping[0] = 2; |
790 | 7 | channel_grouping[1] = 2; |
791 | 7 | channel_grouping[2] = 2; |
792 | 7 | break; |
793 | 0 | default: |
794 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_INPUT_CHANNEL; |
795 | 0 | break; |
796 | 212 | } |
797 | | |
798 | 212 | offset = num_ott_boxes + num_ttt_boxes; |
799 | | |
800 | 212 | p_res_mdct = pstr_mps_state->array_struct->res_mdct + offset * RFX2XMDCTCOEF; |
801 | | |
802 | 394 | for (ch = 0, gr = 0; ch < num_input_channels; ch += channel_grouping[gr++]) { |
803 | 222 | p_mdct_res = p_res_mdct; |
804 | | |
805 | 222 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
806 | 222 | frame->bs_arbitrary_downmix_residual_abs[ch] = (temp >> 1) & ONE_BIT_MASK; |
807 | 222 | frame->bs_arbitrary_downmix_residual_alpha_update_set[ch] = temp & ONE_BIT_MASK; |
808 | | |
809 | 222 | if (channel_grouping[gr] == 1) { |
810 | 286 | for (fr = 0; fr < arbdmx_frames_per_spatial_frame; fr++) { |
811 | 151 | error_code = |
812 | 151 | ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, |
813 | 151 | 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls); |
814 | 151 | if (error_code) { |
815 | 12 | if (pstr_mps_state->ec_flag) { |
816 | 0 | pstr_mps_state->frame_ok = 0; |
817 | 0 | } else |
818 | 12 | return error_code; |
819 | 12 | } |
820 | 139 | if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
821 | 53 | ixheaacd_res_ctns_apply( |
822 | 53 | pstr_mps_state->p_aac_decoder_channel_info[0], |
823 | 53 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
824 | 53 | aac_tables_ptr); |
825 | | |
826 | 139 | pstr_mps_state->res_block_type[offset + ch][fr] = |
827 | 139 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
828 | 141k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
829 | 141k | *p_mdct_res++ = |
830 | 141k | (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]); |
831 | 141k | } |
832 | | |
833 | 139 | if ((pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence == |
834 | 139 | EIGHT_SHORT_SEQUENCE) && |
835 | 29 | ((arbdmx_upd_qmf == UPD_QMF_18) || (arbdmx_upd_qmf == UPD_QMF_24) || |
836 | 24 | (arbdmx_upd_qmf == UPD_QMF_30))) { |
837 | 5 | error_code = ixheaacd_res_read_ics( |
838 | 5 | mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr, |
839 | 5 | pstr_mps_state->tot_sf_bands_ls); |
840 | 5 | if (error_code) { |
841 | 1 | if (pstr_mps_state->ec_flag) { |
842 | 0 | pstr_mps_state->frame_ok = 0; |
843 | 0 | } else |
844 | 1 | return error_code; |
845 | 1 | } |
846 | 4 | if (1 == |
847 | 4 | pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
848 | 1 | ixheaacd_res_ctns_apply( |
849 | 1 | pstr_mps_state->p_aac_decoder_channel_info[0], |
850 | 1 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
851 | 1 | aac_tables_ptr); |
852 | 4.10k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
853 | 4.09k | *p_mdct_res++ = (pstr_mps_state->p_aac_decoder_channel_info[0] |
854 | 4.09k | ->p_spectral_coefficient[i]); |
855 | 4.09k | } |
856 | 4 | } |
857 | 139 | } |
858 | 135 | p_res_mdct += RFX2XMDCTCOEF; |
859 | 135 | } else { |
860 | 74 | frame->bs_arbitrary_downmix_residual_abs[ch + 1] = |
861 | 74 | frame->bs_arbitrary_downmix_residual_abs[ch]; |
862 | 74 | frame->bs_arbitrary_downmix_residual_alpha_update_set[ch + 1] = |
863 | 74 | frame->bs_arbitrary_downmix_residual_alpha_update_set[ch]; |
864 | | |
865 | 122 | for (fr = 0; fr < arbdmx_frames_per_spatial_frame; fr++) { |
866 | 75 | WORD32 *res_mdct_1 = p_mdct_res + RFX2XMDCTCOEF; |
867 | 75 | WORD32 temp, win1, win2; |
868 | 75 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
869 | 75 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
870 | | |
871 | 75 | if (temp != 0) { |
872 | 1 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT; |
873 | 1 | } |
874 | | |
875 | 74 | error_code = |
876 | 74 | ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, |
877 | 74 | 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls); |
878 | 74 | if (error_code) { |
879 | 3 | if (pstr_mps_state->ec_flag) { |
880 | 0 | pstr_mps_state->frame_ok = 0; |
881 | 0 | } else |
882 | 3 | return error_code; |
883 | 3 | } |
884 | | |
885 | 71 | if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
886 | 3 | ixheaacd_res_ctns_apply( |
887 | 3 | pstr_mps_state->p_aac_decoder_channel_info[0], |
888 | 3 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
889 | 3 | aac_tables_ptr); |
890 | 71 | win1 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
891 | 71 | pstr_mps_state->res_block_type[offset + ch][fr] = |
892 | 71 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
893 | | |
894 | 71.7k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
895 | 71.6k | *p_mdct_res++ = |
896 | 71.6k | (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]); |
897 | 71.6k | } |
898 | | |
899 | 71 | error_code = |
900 | 71 | ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, |
901 | 71 | 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls); |
902 | 71 | if (error_code) { |
903 | 10 | if (pstr_mps_state->ec_flag) { |
904 | 0 | pstr_mps_state->frame_ok = 0; |
905 | 0 | } else |
906 | 10 | return error_code; |
907 | 10 | } |
908 | | |
909 | 61 | if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
910 | 10 | ixheaacd_res_ctns_apply( |
911 | 10 | pstr_mps_state->p_aac_decoder_channel_info[0], |
912 | 10 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
913 | 10 | aac_tables_ptr); |
914 | 61 | win2 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
915 | 59.4k | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
916 | 59.3k | *res_mdct_1++ = |
917 | 59.3k | (pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]); |
918 | 59.3k | } |
919 | | |
920 | 61 | if (win1 != win2) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_WINDOW_SEQUENCE; |
921 | | |
922 | 48 | if ((win1 == EIGHT_SHORT_SEQUENCE) && |
923 | 0 | ((arbdmx_upd_qmf == UPD_QMF_18) || (arbdmx_upd_qmf == UPD_QMF_24) || |
924 | 0 | (arbdmx_upd_qmf == UPD_QMF_30))) { |
925 | 0 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
926 | 0 | temp = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
927 | |
|
928 | 0 | if (temp != 0) { |
929 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT; |
930 | 0 | } |
931 | | |
932 | 0 | error_code = ixheaacd_res_read_ics( |
933 | 0 | mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr, |
934 | 0 | pstr_mps_state->tot_sf_bands_ls); |
935 | 0 | if (error_code) { |
936 | 0 | if (pstr_mps_state->ec_flag) { |
937 | 0 | pstr_mps_state->frame_ok = 0; |
938 | 0 | } else |
939 | 0 | return error_code; |
940 | 0 | } |
941 | | |
942 | 0 | if (1 == |
943 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
944 | 0 | ixheaacd_res_ctns_apply( |
945 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0], |
946 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
947 | 0 | aac_tables_ptr); |
948 | 0 | win1 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
949 | |
|
950 | 0 | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
951 | 0 | *p_mdct_res++ = (pstr_mps_state->p_aac_decoder_channel_info[0] |
952 | 0 | ->p_spectral_coefficient[i]); |
953 | 0 | } |
954 | |
|
955 | 0 | error_code = ixheaacd_res_read_ics( |
956 | 0 | mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr, |
957 | 0 | pstr_mps_state->tot_sf_bands_ls); |
958 | 0 | if (error_code) { |
959 | 0 | if (pstr_mps_state->ec_flag) { |
960 | 0 | pstr_mps_state->frame_ok = 0; |
961 | 0 | } else |
962 | 0 | return error_code; |
963 | 0 | } |
964 | | |
965 | 0 | if (1 == |
966 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present) |
967 | 0 | ixheaacd_res_ctns_apply( |
968 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0], |
969 | 0 | pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.max_sf_bands, |
970 | 0 | aac_tables_ptr); |
971 | 0 | win2 = pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence; |
972 | 0 | for (i = 0; i < AAC_FRAME_LENGTH; i++) { |
973 | 0 | *res_mdct_1++ = (pstr_mps_state->p_aac_decoder_channel_info[0] |
974 | 0 | ->p_spectral_coefficient[i]); |
975 | 0 | } |
976 | |
|
977 | 0 | if (win1 != win2) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_WINDOW_SEQUENCE; |
978 | 0 | } |
979 | 48 | } |
980 | 47 | p_res_mdct += RFX2XMDCTCOEF; |
981 | 47 | } |
982 | 222 | } |
983 | | |
984 | 172 | break; |
985 | | |
986 | 172 | case EXT_TYPE_2: |
987 | 53 | for (i = 0; i < p_bs_config->num_ott_boxes_at; i++) { |
988 | 16 | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
989 | 16 | frame->cmp_ott_cld_idx, frame->cmp_ott_cld_idx_prev, |
990 | 16 | CLD, num_ott_boxes + i, num_ott_boxes + i, 0, |
991 | 16 | p_bs_config->bs_ott_bands_at[i]); |
992 | 16 | if (error_code != IA_NO_ERROR) return error_code; |
993 | 16 | } |
994 | | |
995 | 37 | break; |
996 | | |
997 | 37 | default: |
998 | 0 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_EXTENSION_TYPE; |
999 | 850 | } |
1000 | | |
1001 | 685 | bits_read = |
1002 | 685 | (WORD32)(((mps_bit_buf->ptr_read_next - mps_bit_buf->ptr_bit_buf_base + 1) << 3) - |
1003 | 685 | (mps_bit_buf->bit_pos + 1) - tmp); |
1004 | 685 | n_fill_bits = (sac_ext_len << 3) - bits_read; |
1005 | | |
1006 | 1.36k | while (n_fill_bits > 7) { |
1007 | 679 | ixheaacd_read_bits_buf(mps_bit_buf, 8); |
1008 | 679 | n_fill_bits -= 8; |
1009 | 679 | } |
1010 | 685 | if (n_fill_bits > 0) { |
1011 | 8 | ixheaacd_read_bits_buf(mps_bit_buf, n_fill_bits); |
1012 | 8 | } |
1013 | 685 | } |
1014 | 850 | } |
1015 | 14.7k | return IA_NO_ERROR; |
1016 | 14.8k | } |
1017 | | |
1018 | 15.1k | IA_ERRORCODE ixheaacd_parse_frame(ia_heaac_mps_state_struct *pstr_mps_state) { |
1019 | 15.1k | ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config; |
1020 | | |
1021 | 15.1k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
1022 | 15.1k | WORD32 i, bs_framing_type, prev_param_slot, data_bands, bs_temp_shape_enable, |
1023 | 15.1k | num_temp_shape_chan; |
1024 | 15.1k | WORD32 ttt_off, ps, pg, ts, pb, temp; |
1025 | 15.1k | WORD32 *bs_env_shape_data = pstr_mps_state->mps_scratch_mem_v; |
1026 | 15.1k | WORD32 const *reciprocal_tab = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->reciprocal; |
1027 | 15.1k | WORD32 num_parameter_sets; |
1028 | | |
1029 | 15.1k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
1030 | 15.1k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
1031 | 15.1k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
1032 | 15.1k | WORD32 bs_num_output_channels = |
1033 | 15.1k | bitdec_table->tree_property_table[pstr_mps_state->tree_config].num_output_channels; |
1034 | | |
1035 | 15.1k | WORD32 time_slots = pstr_mps_state->time_slots; |
1036 | 15.1k | WORD32 bitstream_parameter_bands = pstr_mps_state->bitstream_parameter_bands; |
1037 | 15.1k | WORD32 *b_ott_bands = pstr_mps_state->bitstream_ott_bands; |
1038 | 15.1k | WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot; |
1039 | | |
1040 | 15.1k | WORD32 num_ott_boxes = pstr_mps_state->num_ott_boxes; |
1041 | | |
1042 | 15.1k | WORD32 reciprocal, alignment_bits = 0; |
1043 | 15.1k | ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff; |
1044 | 15.1k | IA_ERRORCODE error_code = IA_NO_ERROR; |
1045 | | |
1046 | 15.1k | if (pstr_mps_state->parse_next_bitstream_frame == 0) return IA_NO_ERROR; |
1047 | | |
1048 | 15.1k | temp = ixheaacd_read_bits_buf(mps_bit_buf, 4); |
1049 | 15.1k | bs_framing_type = (temp >> 3) & ONE_BIT_MASK; |
1050 | 15.1k | num_parameter_sets = (temp & THREE_BIT_MASK) + 1; |
1051 | 15.1k | pstr_mps_state->num_parameter_sets = num_parameter_sets; |
1052 | | |
1053 | 15.1k | reciprocal = reciprocal_tab[num_parameter_sets - 1]; |
1054 | | |
1055 | 15.1k | prev_param_slot = -1; |
1056 | 41.2k | for (i = 0; i < num_parameter_sets; i++) { |
1057 | 26.0k | if (bs_framing_type) { |
1058 | 7.80k | WORD32 bits_param_slot = 0; |
1059 | 33.4k | while ((1 << bits_param_slot) < (time_slots - num_parameter_sets + i - prev_param_slot)) |
1060 | 25.6k | bits_param_slot++; |
1061 | 7.80k | param_slot[i] = |
1062 | 7.80k | bits_param_slot |
1063 | 7.80k | ? prev_param_slot + 1 + ixheaacd_read_bits_buf(mps_bit_buf, bits_param_slot) |
1064 | 7.80k | : prev_param_slot + 1; |
1065 | 7.80k | prev_param_slot = param_slot[i]; |
1066 | 18.2k | } else { |
1067 | 18.2k | WORD64 temp = (WORD64)( |
1068 | 18.2k | ((WORD64)((time_slots * (i + 1)) + num_parameter_sets - 1) * (WORD64)reciprocal) >> 28); |
1069 | 18.2k | param_slot[i] = (WORD32)(temp - 1); |
1070 | 18.2k | } |
1071 | 26.0k | } |
1072 | 15.1k | frame->bs_independency_flag = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
1073 | | |
1074 | 55.4k | for (i = 0; i < num_ott_boxes; i++) { |
1075 | 40.2k | error_code = |
1076 | 40.2k | ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, frame->cmp_ott_cld_idx, |
1077 | 40.2k | frame->cmp_ott_cld_idx_prev, CLD, i, i, 0, b_ott_bands[i]); |
1078 | 40.2k | if (error_code != IA_NO_ERROR) return error_code; |
1079 | 40.2k | } |
1080 | 15.1k | if (pstr_mps_state->one_icc) { |
1081 | 3.63k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data, |
1082 | 3.63k | frame->cmp_ott_icc_idx, frame->cmp_ott_icc_idx_prev, ICC, 0, |
1083 | 3.63k | 0, 0, bitstream_parameter_bands); |
1084 | 3.63k | if (error_code != IA_NO_ERROR) return error_code; |
1085 | 11.5k | } else { |
1086 | 36.7k | for (i = 0; i < num_ott_boxes; i++) { |
1087 | 25.2k | if (!pstr_mps_state->ott_mode_lfe[i]) { |
1088 | 24.1k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data, |
1089 | 24.1k | frame->cmp_ott_icc_idx, frame->cmp_ott_icc_idx_prev, |
1090 | 24.1k | ICC, i, i, 0, b_ott_bands[i]); |
1091 | 24.1k | if (error_code != IA_NO_ERROR) return error_code; |
1092 | 24.1k | } |
1093 | 25.2k | } |
1094 | 11.5k | } |
1095 | | |
1096 | 15.1k | ttt_off = num_ott_boxes; |
1097 | 18.2k | for (i = 0; i < pstr_mps_state->num_ttt_boxes; i++) { |
1098 | 3.11k | if (p_aux_struct->ttt_config[0][i].mode < 2) { |
1099 | 1.44k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data, |
1100 | 1.44k | frame->cmp_ttt_cpc_1_idx, frame->cmp_ttt_cpc_1_idx_prev, |
1101 | 1.44k | CPC, i, ttt_off + 4 * i, |
1102 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
1103 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_stop_band); |
1104 | 1.44k | if (error_code != IA_NO_ERROR) return error_code; |
1105 | | |
1106 | 1.44k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data, |
1107 | 1.44k | frame->cmp_ttt_cpc_2_idx, frame->cmp_ttt_cpc_2_idx_prev, |
1108 | 1.44k | CPC, i, ttt_off + 4 * i + 1, |
1109 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
1110 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_stop_band); |
1111 | 1.44k | if (error_code != IA_NO_ERROR) return error_code; |
1112 | | |
1113 | 1.44k | error_code = |
1114 | 1.44k | ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data, frame->cmp_ttt_icc_idx, |
1115 | 1.44k | frame->cmp_ttt_icc_idx_prev, ICC, i, ttt_off + 4 * i, |
1116 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
1117 | 1.44k | p_aux_struct->ttt_config[0][i].bitstream_stop_band); |
1118 | 1.44k | if (error_code != IA_NO_ERROR) return error_code; |
1119 | 1.66k | } else { |
1120 | 1.66k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
1121 | 1.66k | frame->cmp_ttt_cld_1_idx, frame->cmp_ttt_cld_1_idx_prev, |
1122 | 1.66k | CLD, i, ttt_off + 4 * i, |
1123 | 1.66k | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
1124 | 1.66k | p_aux_struct->ttt_config[0][i].bitstream_stop_band); |
1125 | 1.66k | if (error_code != IA_NO_ERROR) return error_code; |
1126 | | |
1127 | 1.66k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
1128 | 1.66k | frame->cmp_ttt_cld_2_idx, frame->cmp_ttt_cld_2_idx_prev, |
1129 | 1.66k | CLD, i, ttt_off + 4 * i + 1, |
1130 | 1.66k | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
1131 | 1.66k | p_aux_struct->ttt_config[0][i].bitstream_stop_band); |
1132 | 1.66k | if (error_code != IA_NO_ERROR) return error_code; |
1133 | 1.66k | } |
1134 | | |
1135 | 3.08k | if (p_aux_struct->ttt_config[1][i].bitstream_start_band < |
1136 | 3.08k | p_aux_struct->ttt_config[1][i].bitstream_stop_band) { |
1137 | 1.33k | if (p_aux_struct->ttt_config[1][i].mode < 2) { |
1138 | 321 | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data, |
1139 | 321 | frame->cmp_ttt_cpc_1_idx, frame->cmp_ttt_cpc_1_idx_prev, |
1140 | 321 | CPC, i, ttt_off + 4 * i + 2, |
1141 | 321 | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
1142 | 321 | p_aux_struct->ttt_config[1][i].bitstream_stop_band); |
1143 | 321 | if (error_code != IA_NO_ERROR) return error_code; |
1144 | | |
1145 | 320 | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cpc_lossless_data, |
1146 | 320 | frame->cmp_ttt_cpc_2_idx, frame->cmp_ttt_cpc_2_idx_prev, |
1147 | 320 | CPC, i, ttt_off + 4 * i + 3, |
1148 | 320 | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
1149 | 320 | p_aux_struct->ttt_config[1][i].bitstream_stop_band); |
1150 | 320 | if (error_code != IA_NO_ERROR) return error_code; |
1151 | | |
1152 | 319 | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->icc_lossless_data, |
1153 | 319 | frame->cmp_ttt_icc_idx, frame->cmp_ttt_icc_idx_prev, |
1154 | 319 | ICC, i, ttt_off + 4 * i + 2, |
1155 | 319 | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
1156 | 319 | p_aux_struct->ttt_config[1][i].bitstream_stop_band); |
1157 | 319 | if (error_code != IA_NO_ERROR) return error_code; |
1158 | 1.01k | } else { |
1159 | 1.01k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
1160 | 1.01k | frame->cmp_ttt_cld_1_idx, frame->cmp_ttt_cld_1_idx_prev, |
1161 | 1.01k | CLD, i, ttt_off + 4 * i + 2, |
1162 | 1.01k | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
1163 | 1.01k | p_aux_struct->ttt_config[1][i].bitstream_stop_band); |
1164 | 1.01k | if (error_code != IA_NO_ERROR) return error_code; |
1165 | | |
1166 | 1.01k | error_code = ixheaacd_ec_data_dec(pstr_mps_state, &frame->cld_lossless_data, |
1167 | 1.01k | frame->cmp_ttt_cld_2_idx, frame->cmp_ttt_cld_2_idx_prev, |
1168 | 1.01k | CLD, i, ttt_off + 4 * i + 3, |
1169 | 1.01k | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
1170 | 1.01k | p_aux_struct->ttt_config[1][i].bitstream_stop_band); |
1171 | 1.01k | if (error_code != IA_NO_ERROR) return error_code; |
1172 | 1.01k | } |
1173 | 1.33k | } |
1174 | 3.08k | } |
1175 | | |
1176 | 15.1k | frame->bs_smooth_control = 1; |
1177 | | |
1178 | 15.1k | if (frame->bs_smooth_control) { |
1179 | 39.6k | for (ps = 0; ps < num_parameter_sets; ps++) { |
1180 | 24.7k | frame->bs_smooth_mode[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
1181 | 24.7k | if (frame->bs_smooth_mode[ps] > 3 || frame->bs_smooth_mode[ps] < 0) { |
1182 | 0 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_SMOOTH_MODE; |
1183 | 0 | } |
1184 | 24.7k | if (frame->bs_smooth_mode[ps] >= 2) { |
1185 | 6.71k | frame->bs_smooth_time[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
1186 | 6.71k | } |
1187 | 24.7k | if (frame->bs_smooth_mode[ps] == 3) { |
1188 | 2.79k | frame->bs_freq_res_stride_smg[ps] = ixheaacd_read_bits_buf(mps_bit_buf, 2); |
1189 | 2.79k | data_bands = (bitstream_parameter_bands - 1) / |
1190 | 2.79k | bitdec_table->pb_stride_table[frame->bs_freq_res_stride_smg[ps]] + |
1191 | 2.79k | 1; |
1192 | 14.8k | for (pg = 0; pg < data_bands; pg++) { |
1193 | 12.0k | frame->bs_smg_data[ps][pg] = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
1194 | 12.0k | } |
1195 | 2.79k | } |
1196 | 24.7k | } |
1197 | 14.9k | } |
1198 | | |
1199 | 128k | for (i = 0; i < bs_num_output_channels; i++) { |
1200 | 113k | p_aux_struct->temp_shape_enable_channel_stp[i] = 0; |
1201 | 113k | p_aux_struct->temp_shape_enable_channel_ges[i] = 0; |
1202 | 113k | } |
1203 | | |
1204 | 15.1k | if (p_bs_config->bs_temp_shape_config != 0) { |
1205 | 13.9k | bs_temp_shape_enable = ixheaacd_read_bits_buf(mps_bit_buf, 1); |
1206 | 13.9k | if (bs_temp_shape_enable) { |
1207 | 2.79k | num_temp_shape_chan = |
1208 | 2.79k | bitdec_table->temp_shape_chan_table[p_bs_config->bs_temp_shape_config - 1] |
1209 | 2.79k | [p_bs_config->bs_tree_config]; |
1210 | 2.79k | switch (pstr_mps_state->temp_shape_config) { |
1211 | 717 | case 1: |
1212 | 4.11k | for (i = 0; i < num_temp_shape_chan; i++) { |
1213 | 3.39k | p_aux_struct->temp_shape_enable_channel_stp[i] = |
1214 | 3.39k | ixheaacd_read_bits_buf(mps_bit_buf, 1); |
1215 | 3.39k | } |
1216 | 717 | break; |
1217 | 2.08k | case 2: |
1218 | 10.7k | for (i = 0; i < num_temp_shape_chan; i++) { |
1219 | 8.63k | p_aux_struct->temp_shape_enable_channel_ges[i] = |
1220 | 8.63k | ixheaacd_read_bits_buf(mps_bit_buf, 1); |
1221 | 8.63k | } |
1222 | 10.6k | for (i = 0; i < num_temp_shape_chan; i++) { |
1223 | 8.58k | if (p_aux_struct->temp_shape_enable_channel_ges[i]) { |
1224 | 1.22k | WORD32 const *envshape_data = |
1225 | 1.22k | &bitdec_table->envshape_data[pstr_mps_state->env_quant_mode][0]; |
1226 | 1.22k | ixheaacd_mps_huff_decode(mps_bit_buf, bs_env_shape_data, time_slots); |
1227 | 37.5k | for (ts = 0; ts < time_slots; ts++) { |
1228 | 36.3k | p_aux_struct->env_shape_data[i][ts] = envshape_data[bs_env_shape_data[ts]]; |
1229 | 36.3k | } |
1230 | 1.22k | } |
1231 | 8.58k | } |
1232 | 2.08k | break; |
1233 | 0 | default: |
1234 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TEMPORAL_SHAPING_CONFIG; |
1235 | 2.79k | } |
1236 | 2.79k | } |
1237 | 13.9k | } |
1238 | | |
1239 | 15.0k | if (pstr_mps_state->up_mix_type == 2) { |
1240 | 0 | for (i = 0; i < bs_num_output_channels; i++) { |
1241 | 0 | p_aux_struct->temp_shape_enable_channel_stp[i] = 0; |
1242 | 0 | p_aux_struct->temp_shape_enable_channel_ges[i] = 0; |
1243 | 0 | } |
1244 | 0 | } |
1245 | | |
1246 | 15.0k | if (pstr_mps_state->arbitrary_downmix != 0) { |
1247 | 1.54k | ixheaacd_parse_arbitrary_downmix_data(pstr_mps_state); |
1248 | 1.54k | } |
1249 | | |
1250 | 15.0k | ixheaacd_byte_align(mps_bit_buf, &alignment_bits); |
1251 | 15.0k | error_code = ixheaacd_parse_extension_frame(pstr_mps_state); |
1252 | 15.0k | if (error_code) { |
1253 | 105 | if (pstr_mps_state->ec_flag) { |
1254 | 0 | pstr_mps_state->frame_ok = 0; |
1255 | 0 | } |
1256 | 105 | else |
1257 | 105 | return error_code; |
1258 | 105 | } |
1259 | | |
1260 | 52.9k | for (i = 0; i < num_ott_boxes; i++) { |
1261 | 108k | for (ps = 0; ps < num_parameter_sets; ps++) { |
1262 | 70.9k | if (!frame->res_data.bs_icc_diff_present[i][ps] || (pstr_mps_state->up_mix_type == 2) || |
1263 | 70.7k | (pstr_mps_state->up_mix_type == 3)) { |
1264 | 1.14M | for (pb = 0; pb < bitstream_parameter_bands; pb++) { |
1265 | 1.07M | pstr_mps_state->bs_frame->ott_icc_diff_idx[i][ps][pb] = 0; |
1266 | 1.07M | } |
1267 | 70.7k | } |
1268 | 70.9k | } |
1269 | 38.0k | } |
1270 | | |
1271 | 14.9k | pstr_mps_state->parse_next_bitstream_frame = 1; |
1272 | | |
1273 | 14.9k | return IA_NO_ERROR; |
1274 | 15.0k | } |
1275 | | |
1276 | | static VOID ixheaacd_create_mapping(WORD32 a_map[MAX_PARAMETER_BANDS + 1], WORD32 start_band, |
1277 | 32.2k | WORD32 stop_band, WORD32 stride, VOID *scratch) { |
1278 | 32.2k | WORD32 in_bands, out_bands, bands_achived, bands_diff, incr, k, i; |
1279 | 32.2k | WORD32 *v_dk; |
1280 | 32.2k | in_bands = stop_band - start_band; |
1281 | 32.2k | out_bands = (in_bands - 1) / stride + 1; |
1282 | 32.2k | v_dk = scratch; |
1283 | 32.2k | if (out_bands < 1) { |
1284 | 118 | out_bands = 1; |
1285 | 118 | } |
1286 | | |
1287 | 32.2k | bands_achived = out_bands * stride; |
1288 | 32.2k | bands_diff = in_bands - bands_achived; |
1289 | 178k | for (i = 0; i < out_bands; i++) { |
1290 | 145k | v_dk[i] = stride; |
1291 | 145k | } |
1292 | | |
1293 | 32.2k | if (bands_diff > 0) { |
1294 | 0 | incr = -1; |
1295 | 0 | k = out_bands - 1; |
1296 | 32.2k | } else { |
1297 | 32.2k | incr = 1; |
1298 | 32.2k | k = 0; |
1299 | 32.2k | } |
1300 | | |
1301 | 245k | while (bands_diff != 0) { |
1302 | 212k | v_dk[k] = v_dk[k] - incr; |
1303 | 212k | k = k + incr; |
1304 | 212k | bands_diff = bands_diff + incr; |
1305 | 212k | if (k >= out_bands) { |
1306 | 208k | if (bands_diff > 0) { |
1307 | 0 | k = out_bands - 1; |
1308 | 208k | } else if (bands_diff < 0) { |
1309 | 194k | k = 0; |
1310 | 194k | } |
1311 | 208k | } |
1312 | 212k | } |
1313 | 32.2k | a_map[0] = start_band; |
1314 | 178k | for (i = 0; i < out_bands; i++) { |
1315 | 145k | a_map[i + 1] = a_map[i] + v_dk[i]; |
1316 | 145k | } |
1317 | 32.2k | } |
1318 | | |
1319 | | static VOID ixheaacd_map_frequency(WORD32 *p_input, WORD32 *p_output, WORD32 *p_map, |
1320 | 29.8k | WORD32 data_bands) { |
1321 | 29.8k | WORD32 i, j, start_band, stop_band, value; |
1322 | 29.8k | WORD32 start_band_0 = p_map[0]; |
1323 | | |
1324 | 165k | for (i = 0; i < data_bands; i++) { |
1325 | 135k | value = p_input[i + start_band_0]; |
1326 | | |
1327 | 135k | start_band = p_map[i]; |
1328 | 135k | stop_band = p_map[i + 1]; |
1329 | 561k | for (j = start_band; j < stop_band; j++) { |
1330 | 426k | p_output[j] = value; |
1331 | 426k | } |
1332 | 135k | } |
1333 | 29.8k | } |
1334 | | |
1335 | | static IA_ERRORCODE ixheaacd_deq_coarse( |
1336 | | WORD32 value, WORD32 param_type, WORD32 *dequant, |
1337 | 231k | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1338 | 231k | switch (param_type) { |
1339 | 94.5k | case CLD: |
1340 | 94.5k | if (value >= 8 || value < -7) return IA_FATAL_ERROR; |
1341 | 94.4k | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cld_coarse[value + 7]; |
1342 | 94.4k | break; |
1343 | | |
1344 | 116k | case ICC: |
1345 | 116k | if (value >= 8 || value < 0) return IA_FATAL_ERROR; |
1346 | 116k | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_icc[value]; |
1347 | 116k | break; |
1348 | | |
1349 | 19.6k | case CPC: |
1350 | 19.6k | if (value >= 16 || value < -10) return IA_FATAL_ERROR; |
1351 | 19.6k | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cpc_coarse[value + 10]; |
1352 | 19.6k | break; |
1353 | 0 | default: |
1354 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_DEQUANT_PARAM; |
1355 | 231k | } |
1356 | 231k | return IA_NO_ERROR; |
1357 | 231k | } |
1358 | | |
1359 | | static IA_ERRORCODE ia_mps_dec_deq( |
1360 | | WORD32 value, WORD32 param_type, WORD32 *dequant, |
1361 | 2.09M | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1362 | 2.09M | switch (param_type) { |
1363 | 1.19M | case CLD: |
1364 | 1.19M | if (value >= 16 || value < -15) return IA_FATAL_ERROR; |
1365 | 1.19M | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cld[value + 15]; |
1366 | 1.19M | break; |
1367 | | |
1368 | 832k | case ICC: |
1369 | 832k | if (value >= 8 || value < 0) return IA_FATAL_ERROR; |
1370 | 828k | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_icc[value]; |
1371 | 828k | break; |
1372 | | |
1373 | 58.2k | case CPC: |
1374 | 58.2k | if (value >= 32 || value < -20) return IA_FATAL_ERROR; |
1375 | 58.0k | *dequant = ixheaacd_mps_dec_bitdec_tables->dequant_cpc[value + 20]; |
1376 | 58.0k | break; |
1377 | | |
1378 | 0 | default: |
1379 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_DEQUANT_PARAM; |
1380 | 2.09M | } |
1381 | 2.08M | return IA_NO_ERROR; |
1382 | 2.09M | } |
1383 | | |
1384 | | static IA_ERRORCODE ixheaacd_factor_funct(WORD32 ott_vs_tot_db, WORD32 quant_mode, |
1385 | 79.9k | WORD32 *factor) { |
1386 | 79.9k | WORD32 db_diff; |
1387 | 79.9k | WORD32 x_linear = 0; |
1388 | | |
1389 | 79.9k | WORD32 maxfactor = 0; |
1390 | 79.9k | WORD32 constfact; |
1391 | | |
1392 | 79.9k | if (ott_vs_tot_db > 0) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_MPS_PARAM; |
1393 | 79.6k | db_diff = -ott_vs_tot_db; |
1394 | | |
1395 | 79.6k | switch (quant_mode) { |
1396 | 0 | case QUANT_MODE_0: |
1397 | 0 | return (ONE_IN_Q25); |
1398 | 0 | break; |
1399 | 20.2k | case QUANT_MODE_1: |
1400 | 20.2k | x_linear = 1024; |
1401 | | |
1402 | 20.2k | maxfactor = 167772160; |
1403 | 20.2k | constfact = 6554; |
1404 | 20.2k | break; |
1405 | 29.4k | case QUANT_MODE_2: |
1406 | 29.4k | x_linear = 1024; |
1407 | | |
1408 | 29.4k | maxfactor = ONE_IN_Q28; |
1409 | 29.4k | constfact = 9557; |
1410 | 29.4k | break; |
1411 | 29.9k | default: |
1412 | 29.9k | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_QUANT_MODE; |
1413 | 79.6k | } |
1414 | | |
1415 | 49.6k | if (db_diff > (x_linear << 5)) { |
1416 | 18.3k | WORD32 db_diff_fix = db_diff >> 5; |
1417 | 18.3k | *factor = (db_diff_fix - (WORD32)x_linear) * constfact + ONE_IN_Q25; |
1418 | 31.2k | } else { |
1419 | 31.2k | *factor = ONE_IN_Q25; |
1420 | 31.2k | } |
1421 | | |
1422 | 49.6k | *factor = min(maxfactor, *factor); |
1423 | 49.6k | return IA_NO_ERROR; |
1424 | 79.6k | } |
1425 | | |
1426 | | static VOID ixheaacd_factor_cld(WORD32 *idx, WORD32 ott_vs_tot_db, WORD32 *ott_vs_tot_db_1, |
1427 | | WORD32 *ott_vs_tot_db_2, WORD32 quant_mode, |
1428 | 79.9k | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1429 | 79.9k | WORD32 factor = 0; |
1430 | 79.9k | WORD32 c1; |
1431 | 79.9k | WORD32 c2; |
1432 | 79.9k | WORD32 cld_idx; |
1433 | | |
1434 | 79.9k | ixheaacd_factor_funct(ott_vs_tot_db, quant_mode, &factor); |
1435 | | |
1436 | 79.9k | cld_idx = (((*idx * (WORD64)factor) + THIRTYONE_BY_TWO_IN_Q25) >> 25); |
1437 | 79.9k | cld_idx -= 15; |
1438 | | |
1439 | 79.9k | cld_idx = min(cld_idx, 15); |
1440 | 79.9k | cld_idx = max(cld_idx, -15); |
1441 | | |
1442 | 79.9k | *idx = cld_idx; |
1443 | | |
1444 | 79.9k | c1 = ixheaacd_mps_dec_bitdec_tables->factor_cld_tab_1[*idx + 15]; |
1445 | 79.9k | c2 = ixheaacd_mps_dec_bitdec_tables->factor_cld_tab_1[15 - *idx]; |
1446 | | |
1447 | 79.9k | *ott_vs_tot_db_1 = c1 + ott_vs_tot_db; |
1448 | 79.9k | *ott_vs_tot_db_2 = c2 + ott_vs_tot_db; |
1449 | 79.9k | } |
1450 | | |
1451 | | static IA_ERRORCODE ixheaacd_map_index_data( |
1452 | | ia_mps_dec_lossless_data_struct *ll_data, |
1453 | | WORD32 output_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], |
1454 | | WORD32 output_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], |
1455 | | WORD32 cmp_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], |
1456 | | WORD32 diff_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], WORD32 xtt_idx, |
1457 | | WORD32 idx_prev[MAX_NUM_OTT][MAX_PARAMETER_BANDS], WORD32 param_idx, WORD32 param_type, |
1458 | | WORD32 start_band, WORD32 stop_band, WORD32 default_value, WORD32 num_parameter_sets, |
1459 | | WORD32 *param_slot, WORD32 extend_frame, WORD32 quant_mode, WORD32 *ott_vs_tot_db_in, |
1460 | | WORD32 *ott_vs_tot_db_1, WORD32 *ott_vs_tot_db_2, |
1461 | 80.1k | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables, VOID *scratch) { |
1462 | 80.1k | WORD32 *a_param_slots; |
1463 | 80.1k | WORD32 *a_interpolate; |
1464 | | |
1465 | 80.1k | WORD32 data_sets; |
1466 | 80.1k | WORD32 *a_map; |
1467 | 80.1k | VOID *free_scratch; |
1468 | | |
1469 | 80.1k | WORD32 set_idx, i, band, parm_slot; |
1470 | 80.1k | WORD32 data_bands, stride; |
1471 | 80.1k | WORD32 ps, pb; |
1472 | | |
1473 | 80.1k | WORD32 i1, i2, x1, xi, x2; |
1474 | 80.1k | WORD32 *db_in; |
1475 | 80.1k | WORD32 *db_1, *db_2; |
1476 | 80.1k | IA_ERRORCODE error_code = IA_NO_ERROR; |
1477 | 80.1k | db_in = ott_vs_tot_db_in; |
1478 | 80.1k | db_1 = ott_vs_tot_db_1; |
1479 | 80.1k | db_2 = ott_vs_tot_db_2; |
1480 | 80.1k | a_param_slots = scratch; |
1481 | 80.1k | a_interpolate = a_param_slots + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1482 | 80.1k | MAX_PARAMETER_SETS, sizeof(*a_interpolate), BYTE_ALIGN_8); |
1483 | 80.1k | a_map = a_interpolate + |
1484 | 80.1k | IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_SETS, sizeof(*a_map), BYTE_ALIGN_8); |
1485 | 80.1k | free_scratch = a_map + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS_PLUS_1, sizeof(*a_map), |
1486 | 80.1k | BYTE_ALIGN_8); |
1487 | | |
1488 | 80.1k | data_sets = 0; |
1489 | 230k | for (i = 0; i < num_parameter_sets; i++) { |
1490 | 149k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) { |
1491 | 29.8k | a_param_slots[data_sets] = i; |
1492 | 29.8k | data_sets++; |
1493 | 29.8k | } |
1494 | 149k | } |
1495 | | |
1496 | 80.1k | set_idx = 0; |
1497 | | |
1498 | 230k | for (i = 0; i < num_parameter_sets; i++) { |
1499 | 149k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 0) { |
1500 | 94.0k | ll_data->no_cmp_quant_coarse_xxx[param_idx][i] = 0; |
1501 | 1.56M | for (band = start_band; band < stop_band; band++) { |
1502 | 1.47M | output_idx_data[xtt_idx][i][band] = default_value; |
1503 | 1.47M | } |
1504 | 1.56M | for (band = start_band; band < stop_band; band++) { |
1505 | 1.47M | idx_prev[xtt_idx][band] = output_idx_data[xtt_idx][i][band]; |
1506 | 1.47M | } |
1507 | 94.0k | } |
1508 | | |
1509 | 149k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 1) { |
1510 | 235k | for (band = start_band; band < stop_band; band++) { |
1511 | 219k | output_idx_data[xtt_idx][i][band] = idx_prev[xtt_idx][band]; |
1512 | 219k | } |
1513 | 15.3k | ll_data->no_cmp_quant_coarse_xxx[param_idx][i] = |
1514 | 15.3k | ll_data->bs_quant_coarse_xxx_prev[param_idx]; |
1515 | 15.3k | } |
1516 | | |
1517 | 149k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 2) { |
1518 | 139k | for (band = start_band; band < stop_band; band++) { |
1519 | 129k | output_idx_data[xtt_idx][i][band] = idx_prev[xtt_idx][band]; |
1520 | 129k | } |
1521 | 10.5k | a_interpolate[i] = 1; |
1522 | 139k | } else { |
1523 | 139k | a_interpolate[i] = 0; |
1524 | 139k | } |
1525 | | |
1526 | 149k | if (ll_data->bs_xxx_data_mode[param_idx][i] == 3) { |
1527 | 29.8k | parm_slot = a_param_slots[set_idx]; |
1528 | 29.8k | stride = ixheaacd_mps_dec_bitdec_tables |
1529 | 29.8k | ->pb_stride_table[ll_data->bs_freq_res_stride_xxx[param_idx][set_idx]]; |
1530 | 29.8k | data_bands = (stop_band - start_band - 1) / stride + 1; |
1531 | 29.8k | ixheaacd_create_mapping(a_map, start_band, stop_band, stride, free_scratch); |
1532 | 29.8k | ixheaacd_map_frequency(&cmp_idx_data[xtt_idx][set_idx][0], |
1533 | 29.8k | &output_idx_data[xtt_idx][parm_slot][0], a_map, data_bands); |
1534 | | |
1535 | 456k | for (band = start_band; band < stop_band; band++) { |
1536 | 426k | idx_prev[xtt_idx][band] = output_idx_data[xtt_idx][parm_slot][band]; |
1537 | 426k | } |
1538 | | |
1539 | 29.8k | ll_data->bs_quant_coarse_xxx_prev[param_idx] = |
1540 | 29.8k | ll_data->bs_quant_coarse_xxx[param_idx][set_idx]; |
1541 | 29.8k | ll_data->no_cmp_quant_coarse_xxx[param_idx][i] = |
1542 | 29.8k | ll_data->bs_quant_coarse_xxx[param_idx][set_idx]; |
1543 | | |
1544 | 29.8k | set_idx++; |
1545 | 29.8k | } |
1546 | | |
1547 | 149k | if (diff_idx_data != NULL) { |
1548 | 971k | for (band = start_band; band < stop_band; band++) { |
1549 | 913k | output_idx_data[xtt_idx][i][band] += diff_idx_data[xtt_idx][i][band]; |
1550 | 913k | } |
1551 | 58.2k | } |
1552 | 149k | } |
1553 | | |
1554 | 229k | for (i = 0; i < num_parameter_sets; i++) { |
1555 | 149k | if (a_interpolate[i] != 1) { |
1556 | 139k | if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i] == 1) { |
1557 | 248k | for (band = start_band; band < stop_band; band++) { |
1558 | 231k | error_code = ixheaacd_deq_coarse(output_idx_data[xtt_idx][i][band], param_type, |
1559 | 231k | &(output_data[xtt_idx][i][band]), |
1560 | 231k | ixheaacd_mps_dec_bitdec_tables); |
1561 | 231k | if (error_code) { |
1562 | 163 | return error_code; |
1563 | 163 | } |
1564 | 231k | } |
1565 | 121k | } else { |
1566 | 2.00M | for (band = start_band; band < stop_band; band++) { |
1567 | 1.88M | error_code = |
1568 | 1.88M | ia_mps_dec_deq(output_idx_data[xtt_idx][i][band], param_type, |
1569 | 1.88M | &(output_data[xtt_idx][i][band]), ixheaacd_mps_dec_bitdec_tables); |
1570 | 1.88M | if (error_code) { |
1571 | 24 | return error_code; |
1572 | 24 | } |
1573 | 1.88M | } |
1574 | 121k | } |
1575 | 139k | } |
1576 | 149k | } |
1577 | | |
1578 | 79.9k | if (quant_mode && (param_type == CLD)) { |
1579 | 3.23k | if (db_in == 0 || db_1 == 0 || db_2 == 0) |
1580 | 14 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_MPS_PARAM; |
1581 | | |
1582 | 14.1k | for (ps = 0; ps < num_parameter_sets; ps++) { |
1583 | 10.9k | if (a_interpolate[ps] != 1) { |
1584 | 9.14k | if (ll_data->no_cmp_quant_coarse_xxx[param_idx][ps]) { |
1585 | 1.60k | ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][ps], param_type, start_band, |
1586 | 1.60k | stop_band - start_band); |
1587 | 1.60k | } |
1588 | 89.1k | for (pb = start_band; pb < stop_band; pb++) { |
1589 | 79.9k | ll_data->no_cmp_quant_coarse_xxx[param_idx][ps] = 1; |
1590 | 79.9k | ixheaacd_factor_cld(&(output_idx_data[xtt_idx][ps][pb]), *db_in++, &(*db_1++), |
1591 | 79.9k | &(*db_2++), quant_mode, ixheaacd_mps_dec_bitdec_tables); |
1592 | 79.9k | ia_mps_dec_deq(output_idx_data[xtt_idx][ps][pb], param_type, |
1593 | 79.9k | &(output_data[xtt_idx][ps][pb]), ixheaacd_mps_dec_bitdec_tables); |
1594 | 79.9k | } |
1595 | 9.14k | } |
1596 | 10.9k | } |
1597 | 3.22k | } |
1598 | | |
1599 | 79.9k | i1 = 0; |
1600 | 79.9k | x1 = 0; |
1601 | 79.9k | i2 = 0; |
1602 | 228k | for (i = 0; i < num_parameter_sets; i++) { |
1603 | 148k | if (a_interpolate[i] != 1) { |
1604 | 138k | i1 = i; |
1605 | 138k | } |
1606 | 148k | i2 = i; |
1607 | 161k | while (a_interpolate[i2] == 1) { |
1608 | 12.9k | i2++; |
1609 | 12.9k | } |
1610 | 148k | x1 = param_slot[i1]; |
1611 | 148k | xi = param_slot[i]; |
1612 | 148k | x2 = param_slot[i2]; |
1613 | | |
1614 | 148k | if (a_interpolate[i] == 1) { |
1615 | 10.4k | if (i2 >= num_parameter_sets) return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_SETS; |
1616 | 10.2k | if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i1]) { |
1617 | 3.12k | ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][i1], param_type, start_band, |
1618 | 3.12k | stop_band - start_band); |
1619 | 3.12k | } |
1620 | 10.2k | if (ll_data->no_cmp_quant_coarse_xxx[param_idx][i2]) { |
1621 | 3.82k | ixheaacd_coarse_2_fine(output_idx_data[xtt_idx][i2], param_type, start_band, |
1622 | 3.82k | stop_band - start_band); |
1623 | 3.82k | } |
1624 | 135k | for (band = start_band; band < stop_band; band++) { |
1625 | 125k | WORD32 yi = 0, y1, y2; |
1626 | 125k | y1 = output_idx_data[xtt_idx][i1][band]; |
1627 | 125k | y2 = output_idx_data[xtt_idx][i2][band]; |
1628 | | |
1629 | 125k | if (x2 != x1) { |
1630 | 125k | yi = y1 + (xi - x1) * (y2 - y1) / (x2 - x1); |
1631 | 125k | } |
1632 | 125k | output_idx_data[xtt_idx][i][band] = yi; |
1633 | 125k | ia_mps_dec_deq(output_idx_data[xtt_idx][i][band], param_type, |
1634 | 125k | &(output_data[xtt_idx][i][band]), ixheaacd_mps_dec_bitdec_tables); |
1635 | 125k | } |
1636 | 10.2k | } |
1637 | 148k | } |
1638 | | |
1639 | 79.8k | ixheaacd_mps_check_index_bounds(output_idx_data, num_parameter_sets, start_band, |
1640 | 79.8k | stop_band, param_type, xtt_idx); |
1641 | | |
1642 | 79.8k | if (extend_frame) { |
1643 | 345k | for (band = start_band; band < stop_band; band++) { |
1644 | 327k | output_data[xtt_idx][num_parameter_sets][band] = |
1645 | 327k | output_data[xtt_idx][num_parameter_sets - 1][band]; |
1646 | 327k | output_idx_data[xtt_idx][num_parameter_sets][band] = |
1647 | 327k | output_idx_data[xtt_idx][num_parameter_sets - 1][band]; |
1648 | 327k | } |
1649 | 18.2k | } |
1650 | 79.8k | return IA_NO_ERROR; |
1651 | 79.9k | } |
1652 | | |
1653 | | static VOID ixheaacd_get_parameters_mapping( |
1654 | | WORD32 bs_parameter_bands, WORD32 *mapping, |
1655 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1656 | 0 | switch (bs_parameter_bands) { |
1657 | 0 | case PARAMETER_BANDS_4: |
1658 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_4_to_28; |
1659 | 0 | break; |
1660 | 0 | case PARAMETER_BANDS_5: |
1661 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_5_to_28; |
1662 | 0 | break; |
1663 | 0 | case PARAMETER_BANDS_7: |
1664 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_7_to_28; |
1665 | 0 | break; |
1666 | 0 | case PARAMETER_BANDS_10: |
1667 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_10_to_28; |
1668 | 0 | break; |
1669 | 0 | case PARAMETER_BANDS_14: |
1670 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_14_to_28; |
1671 | 0 | break; |
1672 | 0 | case PARAMETER_BANDS_20: |
1673 | 0 | mapping = ixheaacd_mps_dec_bitdec_tables->map_table.mapping_20_to_28; |
1674 | 0 | break; |
1675 | 0 | case PARAMETER_BANDS_28: |
1676 | 0 | break; |
1677 | 0 | default: |
1678 | 0 | break; |
1679 | 0 | } |
1680 | 0 | return; |
1681 | 0 | } |
1682 | | |
1683 | | static VOID ixheaacd_map_number_of_bands_to_28_bands( |
1684 | | WORD32 bands, WORD32 bs_parameter_bands, WORD32 *bands28, |
1685 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1686 | 0 | WORD32 *mapping = NULL; |
1687 | 0 | WORD32 pb; |
1688 | |
|
1689 | 0 | *bands28 = bands; |
1690 | |
|
1691 | 0 | ixheaacd_get_parameters_mapping(bs_parameter_bands, mapping, ixheaacd_mps_dec_bitdec_tables); |
1692 | |
|
1693 | 0 | if (mapping != NULL) { |
1694 | 0 | for (pb = 0; pb < MAX_PARAMETER_BANDS; pb++) { |
1695 | 0 | if (mapping[pb] == bands) { |
1696 | 0 | break; |
1697 | 0 | } |
1698 | 0 | } |
1699 | 0 | *bands28 = pb; |
1700 | 0 | } |
1701 | 0 | return; |
1702 | 0 | } |
1703 | | |
1704 | | static VOID ixheaacd_map_data_to_28_bands( |
1705 | | WORD32 *data, WORD32 bs_parameter_bands, |
1706 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
1707 | 0 | WORD32 *mapping = NULL; |
1708 | 0 | WORD32 pb; |
1709 | |
|
1710 | 0 | ixheaacd_get_parameters_mapping(bs_parameter_bands, mapping, ixheaacd_mps_dec_bitdec_tables); |
1711 | |
|
1712 | 0 | if (mapping != NULL) { |
1713 | 0 | for (pb = MAX_PARAMETER_BANDS - 1; pb >= 0; pb--) { |
1714 | 0 | data[pb] = data[mapping[pb]]; |
1715 | 0 | } |
1716 | 0 | } |
1717 | 0 | return; |
1718 | 0 | } |
1719 | | |
1720 | | static IA_ERRORCODE ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mps_state) |
1721 | 14.5k | { |
1722 | 14.5k | IA_ERRORCODE error_code = IA_NO_ERROR; |
1723 | 14.5k | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs; |
1724 | 14.5k | ia_heaac_mps_state_struct *curr_state = pstr_mps_state; |
1725 | 14.5k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
1726 | 14.5k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
1727 | 14.5k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
1728 | 14.5k | WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot; |
1729 | | |
1730 | 14.5k | WORD32 i, num_parameter_sets, ott_idx, band; |
1731 | 14.5k | WORD32 num_ott_boxes; |
1732 | 14.5k | VOID *free_scratch; |
1733 | | |
1734 | 14.5k | WORD32 ps, pb; |
1735 | | |
1736 | 14.5k | WORD32 *tot_db; |
1737 | 14.5k | WORD32 *ott_vs_tot_db_fc; |
1738 | 14.5k | WORD32 *ott_vs_tot_db_s; |
1739 | 14.5k | WORD32 *ott_vs_tot_db_f; |
1740 | 14.5k | WORD32 *ott_vs_tot_db_c; |
1741 | 14.5k | WORD32 *ott_vs_tot_db_lr; |
1742 | 14.5k | WORD32 *ott_vs_tot_db_l; |
1743 | 14.5k | WORD32 *ott_vs_tot_db_r; |
1744 | 14.5k | WORD32 *tmp1; |
1745 | 14.5k | WORD32 *tmp2; |
1746 | | |
1747 | 14.5k | WORD32 bitstream_parameter_bands = curr_state->bitstream_parameter_bands; |
1748 | 14.5k | WORD32 *b_ott_bands = curr_state->bitstream_ott_bands; |
1749 | 14.5k | WORD32 *ott_cld_default = curr_state->ott_cld_default; |
1750 | 14.5k | WORD32 parameter_sets = curr_state->num_parameter_sets; |
1751 | 14.5k | WORD32 extend_frame = curr_state->extend_frame; |
1752 | 14.5k | WORD32 quant_mode = curr_state->quant_mode; |
1753 | | |
1754 | 14.5k | tot_db = pstr_mps_state->mps_scratch_mem_v; |
1755 | 14.5k | ott_vs_tot_db_fc = |
1756 | 14.5k | tot_db + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*ott_vs_tot_db_fc), BYTE_ALIGN_8); |
1757 | 14.5k | ott_vs_tot_db_s = ott_vs_tot_db_fc + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1758 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_s), BYTE_ALIGN_8); |
1759 | 14.5k | ott_vs_tot_db_f = ott_vs_tot_db_s + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1760 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_f), BYTE_ALIGN_8); |
1761 | 14.5k | ott_vs_tot_db_c = ott_vs_tot_db_f + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1762 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_c), BYTE_ALIGN_8); |
1763 | 14.5k | ott_vs_tot_db_lr = ott_vs_tot_db_c + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1764 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_lr), BYTE_ALIGN_8); |
1765 | 14.5k | ott_vs_tot_db_l = ott_vs_tot_db_lr + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1766 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_l), BYTE_ALIGN_8); |
1767 | 14.5k | ott_vs_tot_db_r = ott_vs_tot_db_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE( |
1768 | 14.5k | MAX_PSXPB, sizeof(*ott_vs_tot_db_r), BYTE_ALIGN_8); |
1769 | 14.5k | tmp1 = ott_vs_tot_db_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp1), BYTE_ALIGN_8); |
1770 | 14.5k | tmp2 = tmp1 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp2), BYTE_ALIGN_8); |
1771 | 14.5k | free_scratch = tmp2 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PSXPB, sizeof(*tmp2), BYTE_ALIGN_8); |
1772 | | |
1773 | 14.5k | p_cur_bs = pstr_mps_state->bs_frame; |
1774 | 14.5k | num_ott_boxes = curr_state->num_ott_boxes; |
1775 | | |
1776 | 14.5k | pb = MAX_PSXPB; |
1777 | 3.26M | for (i = 0; i < pb; i++) tot_db[i] = 0; |
1778 | | |
1779 | 14.5k | switch (curr_state->tree_config) { |
1780 | 427 | case TREE_5151: |
1781 | 427 | i = 0; |
1782 | 427 | error_code = ixheaacd_map_index_data( |
1783 | 427 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1784 | 427 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1785 | 427 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1786 | 427 | quant_mode, tot_db, ott_vs_tot_db_fc, ott_vs_tot_db_s, bitdec_table, free_scratch); |
1787 | 427 | if (error_code) return error_code; |
1788 | | |
1789 | 419 | i = 1; |
1790 | 419 | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
1791 | 419 | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i, |
1792 | 419 | p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i], |
1793 | 419 | ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1794 | 419 | quant_mode, ott_vs_tot_db_fc, ott_vs_tot_db_f, ott_vs_tot_db_c, |
1795 | 419 | bitdec_table, free_scratch); |
1796 | 419 | if (error_code) return error_code; |
1797 | | |
1798 | 412 | i = 2; |
1799 | 412 | error_code = ixheaacd_map_index_data( |
1800 | 412 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1801 | 412 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1802 | 412 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1803 | 412 | quant_mode, ott_vs_tot_db_s, tmp1, tmp2, bitdec_table, free_scratch); |
1804 | 412 | if (error_code) return error_code; |
1805 | | |
1806 | 388 | i = 3; |
1807 | 388 | error_code = ixheaacd_map_index_data( |
1808 | 388 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1809 | 388 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1810 | 388 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1811 | 388 | quant_mode, ott_vs_tot_db_f, tmp1, tmp2, bitdec_table, free_scratch); |
1812 | 388 | if (error_code) return error_code; |
1813 | | |
1814 | 385 | i = 4; |
1815 | 385 | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
1816 | 385 | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i, |
1817 | 385 | p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i], |
1818 | 385 | ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1819 | 385 | quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch); |
1820 | 385 | if (error_code) return error_code; |
1821 | | |
1822 | 383 | break; |
1823 | | |
1824 | 778 | case TREE_5152: |
1825 | 778 | i = 0; |
1826 | 778 | error_code = ixheaacd_map_index_data( |
1827 | 778 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1828 | 778 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1829 | 778 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1830 | 778 | quant_mode, tot_db, ott_vs_tot_db_lr, ott_vs_tot_db_c, bitdec_table, free_scratch); |
1831 | 778 | if (error_code) return error_code; |
1832 | | |
1833 | 767 | i = 1; |
1834 | 767 | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
1835 | 767 | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i, |
1836 | 767 | p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i], |
1837 | 767 | ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1838 | 767 | quant_mode, ott_vs_tot_db_lr, ott_vs_tot_db_l, ott_vs_tot_db_r, |
1839 | 767 | bitdec_table, free_scratch); |
1840 | 767 | if (error_code) return error_code; |
1841 | | |
1842 | 761 | i = 2; |
1843 | 761 | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
1844 | 761 | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i, |
1845 | 761 | p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i], |
1846 | 761 | ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1847 | 761 | quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch); |
1848 | 761 | if (error_code) return error_code; |
1849 | | |
1850 | 756 | i = 3; |
1851 | 756 | error_code = ixheaacd_map_index_data( |
1852 | 756 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1853 | 756 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1854 | 756 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1855 | 756 | quant_mode, ott_vs_tot_db_l, tmp1, tmp2, bitdec_table, free_scratch); |
1856 | 756 | if (error_code) return error_code; |
1857 | | |
1858 | 747 | i = 4; |
1859 | 747 | error_code = ixheaacd_map_index_data( |
1860 | 747 | &p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx, |
1861 | 747 | p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0, |
1862 | 747 | b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1863 | 747 | quant_mode, ott_vs_tot_db_r, tmp1, tmp2, bitdec_table, free_scratch); |
1864 | 747 | if (error_code) return error_code; |
1865 | 733 | break; |
1866 | | |
1867 | 13.3k | default: |
1868 | 45.0k | for (i = 0; i < num_ott_boxes; i++) { |
1869 | 31.8k | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
1870 | 31.8k | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i, |
1871 | 31.8k | p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i], |
1872 | 31.8k | ott_cld_default[i], parameter_sets, param_slot, extend_frame, |
1873 | 31.8k | (curr_state->tree_config == TREE_525) ? 0 : quant_mode, NULL, |
1874 | 31.8k | NULL, NULL, bitdec_table, free_scratch); |
1875 | 31.8k | if (error_code) return error_code; |
1876 | 31.8k | } |
1877 | 13.2k | break; |
1878 | 14.5k | } |
1879 | | |
1880 | 14.3k | if (curr_state->one_icc == 1) { |
1881 | 3.27k | if (extend_frame == 0) { |
1882 | 2.69k | num_parameter_sets = parameter_sets; |
1883 | 2.69k | } else { |
1884 | 572 | num_parameter_sets = parameter_sets + 1; |
1885 | 572 | } |
1886 | | |
1887 | 13.2k | for (ott_idx = 1; ott_idx < num_ott_boxes; ott_idx++) { |
1888 | 10.0k | if (curr_state->ott_mode_lfe[ott_idx] == 0) { |
1889 | 34.2k | for (i = 0; i < num_parameter_sets; i++) { |
1890 | 334k | for (band = 0; band < bitstream_parameter_bands; band++) { |
1891 | 309k | p_cur_bs->cmp_ott_icc_idx[ott_idx][i][band] = p_cur_bs->cmp_ott_icc_idx[0][i][band]; |
1892 | 309k | } |
1893 | 25.0k | } |
1894 | 9.20k | } |
1895 | 10.0k | } |
1896 | | |
1897 | 16.5k | for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) { |
1898 | 13.2k | if (curr_state->ott_mode_lfe[ott_idx] == 0) { |
1899 | 10.2k | error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc, |
1900 | 10.2k | p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx, |
1901 | 10.2k | p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev, |
1902 | 10.2k | 0, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default, |
1903 | 10.2k | parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL, |
1904 | 10.2k | NULL, bitdec_table, free_scratch); |
1905 | 10.2k | if (error_code) return error_code; |
1906 | 10.2k | } |
1907 | 13.2k | } |
1908 | 11.0k | } else { |
1909 | 34.9k | for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) { |
1910 | 23.8k | if (curr_state->ott_mode_lfe[ott_idx] == 0) { |
1911 | 23.1k | error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc, |
1912 | 23.1k | p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx, |
1913 | 23.1k | p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev, |
1914 | 23.1k | ott_idx, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default, |
1915 | 23.1k | parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL, |
1916 | 23.1k | NULL, bitdec_table, free_scratch); |
1917 | 23.1k | if (error_code) return error_code; |
1918 | 23.1k | } |
1919 | 23.8k | } |
1920 | 11.0k | } |
1921 | | |
1922 | 14.2k | if (curr_state->up_mix_type == 2) { |
1923 | 0 | WORD32 num_parameter_sets = parameter_sets; |
1924 | |
|
1925 | 0 | if (extend_frame) { |
1926 | 0 | num_parameter_sets++; |
1927 | 0 | } |
1928 | |
|
1929 | 0 | for (ott_idx = 0; ott_idx < curr_state->num_ott_boxes; ott_idx++) { |
1930 | 0 | for (ps = 0; ps < num_parameter_sets; ps++) { |
1931 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ott_cld[ott_idx][ps], |
1932 | 0 | bitstream_parameter_bands, bitdec_table); |
1933 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ott_icc[ott_idx][ps], |
1934 | 0 | bitstream_parameter_bands, bitdec_table); |
1935 | 0 | } |
1936 | 0 | } |
1937 | 0 | } |
1938 | 14.2k | return error_code; |
1939 | 14.3k | } |
1940 | | |
1941 | | static IA_ERRORCODE ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mps_state) |
1942 | 14.2k | { |
1943 | 14.2k | IA_ERRORCODE error_code = IA_NO_ERROR; |
1944 | 14.2k | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs; |
1945 | 14.2k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
1946 | 14.2k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
1947 | 14.2k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
1948 | 14.2k | WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot; |
1949 | | |
1950 | 14.2k | WORD32 num_bands; |
1951 | | |
1952 | 14.2k | WORD32 i, j, offset; |
1953 | 14.2k | WORD32 num_ttt_boxes; |
1954 | 14.2k | VOID *free_scratch; |
1955 | | |
1956 | 14.2k | p_cur_bs = pstr_mps_state->bs_frame; |
1957 | 14.2k | num_bands = pstr_mps_state->bitstream_parameter_bands; |
1958 | 14.2k | offset = pstr_mps_state->num_ott_boxes; |
1959 | 14.2k | num_ttt_boxes = pstr_mps_state->num_ttt_boxes; |
1960 | 14.2k | free_scratch = pstr_mps_state->mps_scratch_mem_v; |
1961 | | |
1962 | 16.8k | for (i = 0; i < num_ttt_boxes; i++) { |
1963 | 2.64k | for (j = 0; |
1964 | 5.71k | (j < 2) && |
1965 | 4.95k | p_aux_struct->ttt_config[j][i].start_band < p_aux_struct->ttt_config[j][i].stop_band; |
1966 | 3.13k | j++) { |
1967 | 3.13k | if (p_aux_struct->ttt_config[j][i].mode < 2) { |
1968 | 1.04k | error_code = ixheaacd_map_index_data( |
1969 | 1.04k | &p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_1, p_cur_bs->ttt_cpc_1_idx, |
1970 | 1.04k | p_cur_bs->cmp_ttt_cpc_1_idx, NULL, i, p_cur_bs->ttt_cpc_1_idx_prev, |
1971 | 1.04k | offset + 4 * i + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band, |
1972 | 1.04k | p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default, |
1973 | 1.04k | pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, |
1974 | 1.04k | pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch); |
1975 | 1.04k | if (error_code) return error_code; |
1976 | | |
1977 | 1.03k | error_code = ixheaacd_map_index_data( |
1978 | 1.03k | &p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_2, p_cur_bs->ttt_cpc_2_idx, |
1979 | 1.03k | p_cur_bs->cmp_ttt_cpc_2_idx, NULL, i, p_cur_bs->ttt_cpc_2_idx_prev, |
1980 | 1.03k | offset + 4 * i + 1 + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band, |
1981 | 1.03k | p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default, |
1982 | 1.03k | pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, |
1983 | 1.03k | pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch); |
1984 | 1.03k | if (error_code) return error_code; |
1985 | | |
1986 | 1.01k | error_code = ixheaacd_map_index_data( |
1987 | 1.01k | &p_cur_bs->icc_lossless_data, p_aux_struct->ttt_icc, p_cur_bs->ttt_icc_idx, |
1988 | 1.01k | p_cur_bs->cmp_ttt_icc_idx, NULL, i, p_cur_bs->ttt_icc_idx_prev, |
1989 | 1.01k | offset + 4 * i + 2 * j, ICC, p_aux_struct->ttt_config[j][i].bitstream_start_band, |
1990 | 1.01k | p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->icc_default, |
1991 | 1.01k | pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, |
1992 | 1.01k | pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch); |
1993 | 1.01k | if (error_code) return error_code; |
1994 | 1.01k | } |
1995 | | |
1996 | 2.09k | else { |
1997 | 2.09k | error_code = ixheaacd_map_index_data( |
1998 | 2.09k | &p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_1, p_cur_bs->ttt_cld_1_idx, |
1999 | 2.09k | p_cur_bs->cmp_ttt_cld_1_idx, NULL, i, p_cur_bs->ttt_cld_1_idx_prev, |
2000 | 2.09k | offset + 4 * i + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band, |
2001 | 2.09k | p_aux_struct->ttt_config[j][i].bitstream_stop_band, |
2002 | 2.09k | pstr_mps_state->ttt_cld_1_default[i], pstr_mps_state->num_parameter_sets, param_slot, |
2003 | 2.09k | pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL, |
2004 | 2.09k | bitdec_table, free_scratch); |
2005 | 2.09k | if (error_code) return error_code; |
2006 | | |
2007 | 2.06k | error_code = ixheaacd_map_index_data( |
2008 | 2.06k | &p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_2, p_cur_bs->ttt_cld_2_idx, |
2009 | 2.06k | p_cur_bs->cmp_ttt_cld_2_idx, NULL, i, p_cur_bs->ttt_cld_2_idx_prev, |
2010 | 2.06k | offset + 4 * i + 1 + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band, |
2011 | 2.06k | p_aux_struct->ttt_config[j][i].bitstream_stop_band, |
2012 | 2.06k | pstr_mps_state->ttt_cld_2_default[i], pstr_mps_state->num_parameter_sets, param_slot, |
2013 | 2.06k | pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL, |
2014 | 2.06k | bitdec_table, free_scratch); |
2015 | 2.06k | if (error_code) return error_code; |
2016 | 2.06k | } |
2017 | | |
2018 | 3.07k | if (pstr_mps_state->up_mix_type == 2) { |
2019 | 0 | WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets; |
2020 | 0 | WORD32 ps; |
2021 | |
|
2022 | 0 | if (pstr_mps_state->extend_frame) { |
2023 | 0 | num_parameter_sets++; |
2024 | 0 | } |
2025 | |
|
2026 | 0 | for (ps = 0; ps < num_parameter_sets; ps++) { |
2027 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cpc_1[i][ps], num_bands, bitdec_table); |
2028 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cpc_2[i][ps], num_bands, bitdec_table); |
2029 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cld_1[i][ps], num_bands, bitdec_table); |
2030 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_cld_2[i][ps], num_bands, bitdec_table); |
2031 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->ttt_icc[i][ps], num_bands, bitdec_table); |
2032 | 0 | } |
2033 | 0 | } |
2034 | 3.07k | } |
2035 | 2.64k | } |
2036 | 14.2k | return error_code; |
2037 | 14.2k | } |
2038 | | |
2039 | 14.2k | static VOID ixheaacd_decode_and_map_frame_smg(ia_heaac_mps_state_struct *pstr_mps_state) { |
2040 | 14.2k | ia_mps_dec_smoothing_state_struct *smooth_state = |
2041 | 14.2k | pstr_mps_state->mps_persistent_mem.smooth_state; |
2042 | 14.2k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
2043 | 14.2k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
2044 | 14.2k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
2045 | 14.2k | WORD32 *smg_time = p_aux_struct->smg_time; |
2046 | 14.2k | WORD32 ps, pb, pg, pb_stride, data_bands, pb_start, pb_stop; |
2047 | 14.2k | WORD32 *a_group_to_band; |
2048 | 14.2k | VOID *free_scratch; |
2049 | 14.2k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
2050 | 14.2k | pstr_mps_state->smooth_control = frame->bs_smooth_control; |
2051 | 14.2k | a_group_to_band = pstr_mps_state->mps_scratch_mem_v; |
2052 | 14.2k | free_scratch = |
2053 | 14.2k | a_group_to_band + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS_PLUS_1, |
2054 | 14.2k | sizeof(*a_group_to_band), BYTE_ALIGN_8); |
2055 | | |
2056 | 14.2k | if (pstr_mps_state->smooth_control) { |
2057 | 37.1k | for (ps = 0; ps < pstr_mps_state->num_parameter_sets; ps++) { |
2058 | 22.8k | switch (frame->bs_smooth_mode[ps]) { |
2059 | 11.7k | case SMOOTH_MODE_0: |
2060 | 11.7k | smg_time[ps] = 256; |
2061 | 204k | for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) { |
2062 | 192k | p_aux_struct->smg_data[ps][pb] = 0; |
2063 | 192k | } |
2064 | 11.7k | break; |
2065 | | |
2066 | 5.10k | case SMOOTH_MODE_1: |
2067 | 5.10k | if (ps > 0) |
2068 | 1.01k | smg_time[ps] = smg_time[ps - 1]; |
2069 | 4.08k | else |
2070 | 4.08k | smg_time[ps] = smooth_state->prev_smg_time; |
2071 | | |
2072 | 100k | for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) { |
2073 | 95.0k | if (ps > 0) |
2074 | 15.9k | p_aux_struct->smg_data[ps][pb] = p_aux_struct->smg_data[ps - 1][pb]; |
2075 | 79.1k | else |
2076 | 79.1k | p_aux_struct->smg_data[ps][pb] = smooth_state->prev_smg_data[pb]; |
2077 | 95.0k | } |
2078 | 5.10k | break; |
2079 | | |
2080 | 3.60k | case SMOOTH_MODE_2: |
2081 | 3.60k | smg_time[ps] = bitdec_table->smg_time_table[frame->bs_smooth_time[ps]]; |
2082 | 67.8k | for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) { |
2083 | 64.2k | p_aux_struct->smg_data[ps][pb] = 1; |
2084 | 64.2k | } |
2085 | 3.60k | break; |
2086 | | |
2087 | 2.44k | case SMOOTH_MODE_3: |
2088 | 2.44k | smg_time[ps] = bitdec_table->smg_time_table[frame->bs_smooth_time[ps]]; |
2089 | 2.44k | pb_stride = bitdec_table->pb_stride_table[frame->bs_freq_res_stride_smg[ps]]; |
2090 | 2.44k | data_bands = (pstr_mps_state->bitstream_parameter_bands - 1) / pb_stride + 1; |
2091 | 2.44k | ixheaacd_create_mapping(a_group_to_band, 0, pstr_mps_state->bitstream_parameter_bands, |
2092 | 2.44k | pb_stride, free_scratch); |
2093 | 13.0k | for (pg = 0; pg < data_bands; pg++) { |
2094 | 10.5k | pb_start = a_group_to_band[pg]; |
2095 | 10.5k | pb_stop = a_group_to_band[pg + 1]; |
2096 | 41.6k | for (pb = pb_start; pb < pb_stop; pb++) { |
2097 | 31.0k | p_aux_struct->smg_data[ps][pb] = frame->bs_smg_data[ps][pg]; |
2098 | 31.0k | } |
2099 | 10.5k | } |
2100 | 2.44k | break; |
2101 | | |
2102 | 0 | default: |
2103 | 0 | break; |
2104 | 22.8k | } |
2105 | 22.8k | } |
2106 | | |
2107 | 14.2k | smooth_state->prev_smg_time = smg_time[pstr_mps_state->num_parameter_sets - 1]; |
2108 | 268k | for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) { |
2109 | 254k | smooth_state->prev_smg_data[pb] = |
2110 | 254k | p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets - 1][pb]; |
2111 | 254k | } |
2112 | | |
2113 | 14.2k | if (pstr_mps_state->extend_frame) { |
2114 | 3.64k | smg_time[pstr_mps_state->num_parameter_sets] = |
2115 | 3.64k | smg_time[pstr_mps_state->num_parameter_sets - 1]; |
2116 | 72.2k | for (pb = 0; pb < pstr_mps_state->bitstream_parameter_bands; pb++) { |
2117 | 68.6k | p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets][pb] = |
2118 | 68.6k | p_aux_struct->smg_data[pstr_mps_state->num_parameter_sets - 1][pb]; |
2119 | 68.6k | } |
2120 | 3.64k | } |
2121 | | |
2122 | 14.2k | if (pstr_mps_state->up_mix_type == 2) { |
2123 | 0 | WORD32 *mapping = NULL; |
2124 | 0 | ixheaacd_get_parameters_mapping(pstr_mps_state->bitstream_parameter_bands, mapping, |
2125 | 0 | bitdec_table); |
2126 | |
|
2127 | 0 | if (mapping != NULL) { |
2128 | 0 | WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets; |
2129 | |
|
2130 | 0 | if (pstr_mps_state->extend_frame) { |
2131 | 0 | num_parameter_sets++; |
2132 | 0 | } |
2133 | |
|
2134 | 0 | for (ps = 0; ps < num_parameter_sets; ps++) { |
2135 | 0 | for (pb = MAX_PARAMETER_BANDS - 1; pb >= 0; pb--) { |
2136 | 0 | p_aux_struct->smg_data[ps][pb] = p_aux_struct->smg_data[ps][mapping[pb]]; |
2137 | 0 | } |
2138 | 0 | } |
2139 | 0 | } |
2140 | 0 | } |
2141 | 14.2k | } |
2142 | 14.2k | return; |
2143 | 14.2k | } |
2144 | | |
2145 | | static IA_ERRORCODE ixheaacd_decode_and_map_frame_arbdmx( |
2146 | 1.31k | ia_heaac_mps_state_struct *pstr_mps_state) { |
2147 | 1.31k | IA_ERRORCODE error_code = IA_NO_ERROR; |
2148 | 1.31k | ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame; |
2149 | 1.31k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
2150 | 1.31k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
2151 | 1.31k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
2152 | 1.31k | WORD32 *param_slot = p_aux_struct->param_slot; |
2153 | 1.31k | WORD32 offset = pstr_mps_state->num_ott_boxes + 4 * pstr_mps_state->num_ttt_boxes; |
2154 | 1.31k | WORD32 ch; |
2155 | | |
2156 | 1.31k | VOID *scratch = pstr_mps_state->mps_scratch_mem_v; |
2157 | | |
2158 | 3.16k | for (ch = 0; ch < pstr_mps_state->num_input_channels; ch++) { |
2159 | 1.88k | error_code = ixheaacd_map_index_data( |
2160 | 1.88k | &frame->cld_lossless_data, p_aux_struct->arbdmx_gain, frame->arbdmx_gain_idx, |
2161 | 1.88k | frame->cmp_arbdmx_gain_idx, NULL, ch, frame->arbdmx_gain_idx_prev, offset + ch, CLD, 0, |
2162 | 1.88k | pstr_mps_state->bitstream_parameter_bands, pstr_mps_state->arbdmx_gain_default, |
2163 | 1.88k | pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, 0, NULL, |
2164 | 1.88k | NULL, NULL, bitdec_table, scratch); |
2165 | 1.88k | if (error_code) return error_code; |
2166 | | |
2167 | 1.85k | p_aux_struct->arbdmx_residual_abs[ch] = frame->bs_arbitrary_downmix_residual_abs[ch]; |
2168 | 1.85k | p_aux_struct->arbdmx_alpha_upd_set[ch] = |
2169 | 1.85k | frame->bs_arbitrary_downmix_residual_alpha_update_set[ch]; |
2170 | | |
2171 | 1.85k | if (pstr_mps_state->up_mix_type == 2) { |
2172 | 0 | WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets; |
2173 | 0 | WORD32 ps; |
2174 | |
|
2175 | 0 | if (pstr_mps_state->extend_frame) { |
2176 | 0 | num_parameter_sets++; |
2177 | 0 | } |
2178 | |
|
2179 | 0 | for (ps = 0; ps < num_parameter_sets; ps++) { |
2180 | 0 | ixheaacd_map_data_to_28_bands(p_aux_struct->arbdmx_gain[ch][ps], |
2181 | 0 | pstr_mps_state->bitstream_parameter_bands, bitdec_table); |
2182 | 0 | } |
2183 | 0 | } |
2184 | 1.85k | } |
2185 | 1.28k | return error_code; |
2186 | 1.31k | } |
2187 | | |
2188 | | static IA_ERRORCODE ixheaacd_decode_and_map_frame_arb_tree( |
2189 | 17 | ia_heaac_mps_state_struct *pstr_mps_state) { |
2190 | 17 | IA_ERRORCODE error_code = IA_NO_ERROR; |
2191 | 17 | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame; |
2192 | 17 | ia_mps_spatial_bs_config_struct *p_config = &(pstr_mps_state->bs_config); |
2193 | 17 | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
2194 | 17 | WORD32 *param_slot = p_aux_struct->param_slot; |
2195 | 17 | WORD32 offset = pstr_mps_state->num_ott_boxes; |
2196 | | |
2197 | 17 | VOID *scratch = pstr_mps_state->mps_scratch_mem_v; |
2198 | | |
2199 | 17 | WORD32 i; |
2200 | | |
2201 | 19 | for (i = 0; i < p_config->num_ott_boxes_at; i++) { |
2202 | 3 | error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, |
2203 | 3 | p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, offset + i, |
2204 | 3 | p_cur_bs->ott_cld_idx_prev, offset + i, CLD, 0, |
2205 | 3 | p_config->bs_ott_bands_at[i], p_config->bs_ott_default_cld_at[i], |
2206 | 3 | pstr_mps_state->num_parameter_sets, param_slot, |
2207 | 3 | pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, |
2208 | 3 | NULL, pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr, scratch); |
2209 | 3 | if (error_code) return error_code; |
2210 | 3 | } |
2211 | 16 | return error_code; |
2212 | 17 | } |
2213 | | |
2214 | 14.5k | IA_ERRORCODE ixheaacd_decode_frame(ia_heaac_mps_state_struct *pstr_mps_state) { |
2215 | 14.5k | IA_ERRORCODE error_code = IA_NO_ERROR; |
2216 | 14.5k | ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config; |
2217 | 14.5k | WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot; |
2218 | | |
2219 | 14.5k | pstr_mps_state->extend_frame = 0; |
2220 | 14.5k | if (param_slot[pstr_mps_state->num_parameter_sets - 1] != pstr_mps_state->time_slots - 1) { |
2221 | 3.75k | pstr_mps_state->extend_frame = 1; |
2222 | 3.75k | } |
2223 | 14.5k | if (pstr_mps_state->extend_frame) |
2224 | 3.75k | { |
2225 | 3.75k | if (pstr_mps_state->num_parameter_sets == MAX_PARAMETER_SETS) { |
2226 | 4 | if (pstr_mps_state->ec_flag) |
2227 | 0 | pstr_mps_state->num_parameter_sets = 1; |
2228 | 4 | else |
2229 | 4 | return IA_FATAL_ERROR; |
2230 | 4 | } |
2231 | 3.75k | } |
2232 | | |
2233 | 14.5k | error_code = ixheaacd_decode_and_map_frame_ott(pstr_mps_state); |
2234 | 14.5k | if (error_code) |
2235 | 246 | { |
2236 | 246 | if (pstr_mps_state->ec_flag) |
2237 | 0 | { |
2238 | 0 | pstr_mps_state->frame_ok = 0; |
2239 | 0 | for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++) |
2240 | 0 | { |
2241 | 0 | ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx, |
2242 | 0 | pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx], |
2243 | 0 | CLD, idx); |
2244 | 0 | ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_icc_idx, |
2245 | 0 | pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx], |
2246 | 0 | ICC, idx); |
2247 | 0 | } |
2248 | 0 | } |
2249 | 246 | else |
2250 | 246 | return error_code; |
2251 | 246 | } |
2252 | | |
2253 | 14.2k | error_code = ixheaacd_decode_and_map_frame_ttt(pstr_mps_state); |
2254 | 14.2k | if (error_code) |
2255 | 59 | { |
2256 | 59 | if (pstr_mps_state->ec_flag) |
2257 | 0 | { |
2258 | 0 | pstr_mps_state->frame_ok = 0; |
2259 | 0 | ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ttt_icc_idx, |
2260 | 0 | pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS, |
2261 | 0 | ICC, 0); |
2262 | 0 | } |
2263 | 59 | else |
2264 | 59 | return error_code; |
2265 | 59 | } |
2266 | | |
2267 | 14.2k | ixheaacd_decode_and_map_frame_smg(pstr_mps_state); |
2268 | 14.2k | if (p_bs_config->arbitrary_tree != 0) { |
2269 | 17 | error_code = ixheaacd_decode_and_map_frame_arb_tree(pstr_mps_state); |
2270 | 17 | if (error_code) |
2271 | 1 | { |
2272 | 1 | if (pstr_mps_state->ec_flag) |
2273 | 0 | { |
2274 | 0 | pstr_mps_state->frame_ok = 0; |
2275 | 0 | for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++) |
2276 | 0 | { |
2277 | 0 | ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx, |
2278 | 0 | pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS, |
2279 | 0 | CLD, idx); |
2280 | 0 | } |
2281 | 0 | } |
2282 | 1 | else |
2283 | 1 | return error_code; |
2284 | 1 | } |
2285 | 17 | } |
2286 | | |
2287 | 14.2k | if (pstr_mps_state->arbitrary_downmix != 0) { |
2288 | 1.31k | error_code = ixheaacd_decode_and_map_frame_arbdmx(pstr_mps_state); |
2289 | 1.31k | if (error_code) |
2290 | 33 | { |
2291 | 33 | if (pstr_mps_state->ec_flag) |
2292 | 0 | { |
2293 | 0 | pstr_mps_state->frame_ok = 0; |
2294 | 0 | for (WORD32 idx = 0; idx < MAX_INPUT_CHANNELS_MPS; idx++) |
2295 | 0 | { |
2296 | 0 | ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->arbdmx_gain_idx, |
2297 | 0 | pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS, |
2298 | 0 | CLD, idx); |
2299 | 0 | } |
2300 | 0 | } |
2301 | 33 | else |
2302 | 33 | return error_code; |
2303 | 33 | } |
2304 | 1.31k | } |
2305 | | |
2306 | 14.1k | if (pstr_mps_state->extend_frame) { |
2307 | 3.64k | pstr_mps_state->num_parameter_sets++; |
2308 | 3.64k | param_slot[pstr_mps_state->num_parameter_sets - 1] = pstr_mps_state->time_slots - 1; |
2309 | 3.64k | } |
2310 | 14.1k | return IA_NO_ERROR; |
2311 | 14.2k | } |
2312 | | |
2313 | 4.04k | IA_ERRORCODE ixheaacd_set_current_state_parameters(ia_heaac_mps_state_struct *pstr_mps_state) { |
2314 | 4.04k | WORD32 i; |
2315 | | |
2316 | 4.04k | ia_mps_spatial_bs_config_struct *config = &(pstr_mps_state->bs_config); |
2317 | 4.04k | ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config; |
2318 | 4.04k | ia_heaac_mps_state_struct *curr_state = pstr_mps_state; |
2319 | 4.04k | ia_mps_dec_bitdec_tables_struct *bitdec_table = |
2320 | 4.04k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr; |
2321 | 4.04k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
2322 | 4.04k | WORD32 *b_ott_bands = curr_state->bitstream_ott_bands; |
2323 | | |
2324 | 4.04k | if (config->bs_sampling_freq_index == 15) { |
2325 | 19 | curr_state->sampling_freq = config->bs_sampling_frequency; |
2326 | 4.02k | } else { |
2327 | 4.02k | curr_state->sampling_freq = bitdec_table->sampling_freq_table[config->bs_sampling_freq_index]; |
2328 | 4.02k | } |
2329 | 4.04k | curr_state->time_slots = config->bs_frame_length + 1; |
2330 | 4.04k | curr_state->frame_length = curr_state->time_slots * curr_state->qmf_bands; |
2331 | 4.04k | curr_state->bitstream_parameter_bands = bitdec_table->freq_res_table[config->bs_freq_res]; |
2332 | | |
2333 | 4.04k | curr_state->hybrid_bands = curr_state->qmf_bands - QMF_BANDS_TO_HYBRID + 10; |
2334 | 4.04k | curr_state->tp_hyb_band_border = 12; |
2335 | 4.04k | if (curr_state->hybrid_bands > 71) { |
2336 | 1 | return IA_FATAL_ERROR; |
2337 | 1 | } |
2338 | 4.04k | if (curr_state->up_mix_type == 2) { |
2339 | 0 | curr_state->num_parameter_bands = MAX_PARAMETER_BANDS; |
2340 | 4.04k | } else { |
2341 | 4.04k | curr_state->num_parameter_bands = curr_state->bitstream_parameter_bands; |
2342 | 4.04k | } |
2343 | | |
2344 | 4.04k | switch (curr_state->num_parameter_bands) { |
2345 | 541 | case PARAMETER_BANDS_4: |
2346 | 21.7k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2347 | 21.1k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_4_to_71[i]; |
2348 | 21.1k | } |
2349 | 541 | break; |
2350 | 411 | case PARAMETER_BANDS_5: |
2351 | 24.7k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2352 | 24.3k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_5_to_71[i]; |
2353 | 24.3k | } |
2354 | 411 | break; |
2355 | 31 | case PARAMETER_BANDS_7: |
2356 | 1.33k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2357 | 1.30k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_7_to_71[i]; |
2358 | 1.30k | } |
2359 | 31 | break; |
2360 | 71 | case PARAMETER_BANDS_10: |
2361 | 3.22k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2362 | 3.15k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_10_to_71[i]; |
2363 | 3.15k | } |
2364 | 71 | break; |
2365 | 1.38k | case PARAMETER_BANDS_14: |
2366 | 55.8k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2367 | 54.4k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_14_to_71[i]; |
2368 | 54.4k | } |
2369 | 1.38k | break; |
2370 | 1.33k | case PARAMETER_BANDS_20: |
2371 | 76.4k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2372 | 75.0k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_20_to_71[i]; |
2373 | 75.0k | } |
2374 | 1.33k | break; |
2375 | 264 | case PARAMETER_BANDS_28: |
2376 | 10.6k | for (i = 0; i < curr_state->hybrid_bands; i++) { |
2377 | 10.3k | curr_state->kernels[i] = bitdec_table->kernel_table.kernels_28_to_71[i]; |
2378 | 10.3k | } |
2379 | 264 | break; |
2380 | 0 | default: |
2381 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_PARAMETER_BANDS; |
2382 | 4.04k | }; |
2383 | | |
2384 | 4.04k | curr_state->tree_config = config->bs_tree_config; |
2385 | | |
2386 | 4.04k | switch (curr_state->tree_config) { |
2387 | 383 | case TREE_5151: |
2388 | 910 | case TREE_5152: |
2389 | 2.11k | case TREE_525: |
2390 | 2.11k | config->ui_channel_mask = FIVE_POINT_ONE_CHANNEL_MASK; |
2391 | 2.11k | break; |
2392 | 273 | case TREE_7271: |
2393 | 462 | case TREE_7571: |
2394 | 462 | config->ui_channel_mask = SEVEN_POINT_ONE_CHANNEL_MASK1; |
2395 | 462 | break; |
2396 | 347 | case TREE_7272: |
2397 | 1.46k | case TREE_7572: |
2398 | 1.46k | config->ui_channel_mask = SEVEN_POINT_ONE_CHANNEL_MASK2; |
2399 | 1.46k | break; |
2400 | 0 | default: |
2401 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG; |
2402 | 4.04k | } |
2403 | | |
2404 | 4.04k | curr_state->num_ott_boxes = |
2405 | 4.04k | bitdec_table->tree_property_table[curr_state->tree_config].num_ott_boxes; |
2406 | 4.04k | curr_state->num_ttt_boxes = |
2407 | 4.04k | bitdec_table->tree_property_table[curr_state->tree_config].num_ttt_boxes; |
2408 | 4.04k | curr_state->num_input_channels = |
2409 | 4.04k | bitdec_table->tree_property_table[curr_state->tree_config].num_input_channels; |
2410 | 4.04k | curr_state->num_output_channels = |
2411 | 4.04k | bitdec_table->tree_property_table[curr_state->tree_config].num_output_channels; |
2412 | 4.04k | curr_state->quant_mode = config->bs_quant_mode; |
2413 | 4.04k | curr_state->one_icc = config->bs_one_icc; |
2414 | 4.04k | curr_state->arbitrary_downmix = config->bs_arbitrary_downmix; |
2415 | 4.04k | curr_state->residual_coding = config->bs_residual_coding; |
2416 | 4.04k | curr_state->smooth_config = config->bs_smooth_config; |
2417 | 4.04k | curr_state->mtx_inversion = config->bs_matrix_mode; |
2418 | 4.04k | curr_state->temp_shape_config = config->bs_temp_shape_config; |
2419 | 4.04k | curr_state->decorr_config = config->bs_decorr_config; |
2420 | 4.04k | curr_state->env_quant_mode = config->bs_env_quant_mode; |
2421 | 4.04k | curr_state->lfe_gain = bitdec_table->lfe_gain_table[config->bs_fixed_gain_lfe]; |
2422 | 4.04k | curr_state->surround_gain = bitdec_table->surround_gain_table[config->bs_fixed_gain_sur]; |
2423 | 4.04k | curr_state->clip_protect_gain = bitdec_table->clip_gain_table[config->bs_fixed_gain_dmx]; |
2424 | | |
2425 | 4.04k | if (curr_state->up_mix_type == 2) { |
2426 | 0 | curr_state->num_output_channels = 2; |
2427 | 0 | curr_state->decorr_config = 0; |
2428 | 0 | } |
2429 | | |
2430 | 4.04k | if (curr_state->up_mix_type == 3) { |
2431 | 0 | curr_state->num_output_channels = 2; |
2432 | 0 | } |
2433 | | |
2434 | 4.04k | if (p_bs_config->arbitrary_tree == 1) |
2435 | 30 | curr_state->num_output_channels_at = p_bs_config->num_out_chan_at; |
2436 | 4.01k | else |
2437 | 4.01k | curr_state->num_output_channels_at = curr_state->num_output_channels; |
2438 | | |
2439 | 4.04k | p_bs_config->ui_out_channels = curr_state->num_output_channels_at; |
2440 | | |
2441 | 4.04k | curr_state->_3d_stereo_inversion = config->bs_3d_audio_mode; |
2442 | | |
2443 | 4.04k | if (curr_state->mtx_inversion == 1 || curr_state->_3d_stereo_inversion == 1) |
2444 | 1.83k | curr_state->m1_param_imag_present = 1; |
2445 | | |
2446 | 17.9k | for (i = 0; i < curr_state->num_ott_boxes; i++) { |
2447 | 13.8k | if (bitdec_table->tree_property_table[curr_state->tree_config].ott_mode_lfe[i]) { |
2448 | 2.73k | b_ott_bands[i] = config->bs_ott_bands[i]; |
2449 | 2.73k | curr_state->ott_mode_lfe[i] = 1; |
2450 | 11.1k | } else { |
2451 | 11.1k | b_ott_bands[i] = curr_state->bitstream_parameter_bands; |
2452 | 11.1k | curr_state->ott_mode_lfe[i] = 0; |
2453 | 11.1k | } |
2454 | | |
2455 | 13.8k | if (curr_state->up_mix_type == 2) { |
2456 | 0 | ixheaacd_map_number_of_bands_to_28_bands(b_ott_bands[i], |
2457 | 0 | curr_state->bitstream_parameter_bands, |
2458 | 0 | &p_aux_struct->num_ott_bands[i], bitdec_table); |
2459 | 13.8k | } else { |
2460 | 13.8k | p_aux_struct->num_ott_bands[i] = b_ott_bands[i]; |
2461 | 13.8k | } |
2462 | 13.8k | } |
2463 | 5.86k | for (i = 0; i < curr_state->num_ttt_boxes; i++) { |
2464 | 1.82k | p_aux_struct->ttt_config[0][i].mode = config->bs_ttt_mode_low[i]; |
2465 | 1.82k | p_aux_struct->ttt_config[1][i].mode = config->bs_ttt_mode_high[i]; |
2466 | 1.82k | p_aux_struct->ttt_config[0][i].bitstream_start_band = 0; |
2467 | 1.82k | p_aux_struct->ttt_config[1][i].bitstream_stop_band = curr_state->bitstream_parameter_bands; |
2468 | | |
2469 | 1.82k | if (config->bs_ttt_dual_mode[i]) { |
2470 | 1.25k | p_aux_struct->ttt_config[0][i].bitstream_stop_band = config->bs_ttt_bands_low[i]; |
2471 | 1.25k | p_aux_struct->ttt_config[1][i].bitstream_start_band = config->bs_ttt_bands_low[i]; |
2472 | 1.25k | } else { |
2473 | 573 | p_aux_struct->ttt_config[0][i].bitstream_stop_band = curr_state->bitstream_parameter_bands; |
2474 | 573 | p_aux_struct->ttt_config[1][i].bitstream_start_band = curr_state->bitstream_parameter_bands; |
2475 | 573 | } |
2476 | | |
2477 | 1.82k | if (curr_state->up_mix_type == 2) { |
2478 | 0 | ixheaacd_map_number_of_bands_to_28_bands( |
2479 | 0 | p_aux_struct->ttt_config[0][i].bitstream_start_band, |
2480 | 0 | curr_state->bitstream_parameter_bands, &p_aux_struct->ttt_config[0][i].start_band, |
2481 | 0 | bitdec_table); |
2482 | |
|
2483 | 0 | ixheaacd_map_number_of_bands_to_28_bands(p_aux_struct->ttt_config[0][i].bitstream_stop_band, |
2484 | 0 | curr_state->bitstream_parameter_bands, |
2485 | 0 | &p_aux_struct->ttt_config[0][i].stop_band, |
2486 | 0 | bitdec_table); |
2487 | |
|
2488 | 0 | ixheaacd_map_number_of_bands_to_28_bands( |
2489 | 0 | p_aux_struct->ttt_config[1][i].bitstream_start_band, |
2490 | 0 | curr_state->bitstream_parameter_bands, &p_aux_struct->ttt_config[1][i].start_band, |
2491 | 0 | bitdec_table); |
2492 | |
|
2493 | 0 | ixheaacd_map_number_of_bands_to_28_bands(p_aux_struct->ttt_config[1][i].bitstream_stop_band, |
2494 | 0 | curr_state->bitstream_parameter_bands, |
2495 | 0 | &p_aux_struct->ttt_config[1][i].stop_band, |
2496 | 0 | bitdec_table); |
2497 | 1.82k | } else { |
2498 | 1.82k | p_aux_struct->ttt_config[0][i].start_band = |
2499 | 1.82k | p_aux_struct->ttt_config[0][i].bitstream_start_band; |
2500 | 1.82k | p_aux_struct->ttt_config[0][i].stop_band = |
2501 | 1.82k | p_aux_struct->ttt_config[0][i].bitstream_stop_band; |
2502 | 1.82k | p_aux_struct->ttt_config[1][i].start_band = |
2503 | 1.82k | p_aux_struct->ttt_config[1][i].bitstream_start_band; |
2504 | 1.82k | p_aux_struct->ttt_config[1][i].stop_band = |
2505 | 1.82k | p_aux_struct->ttt_config[1][i].bitstream_stop_band; |
2506 | 1.82k | } |
2507 | 1.82k | } |
2508 | 4.04k | curr_state->residual_coding = config->bs_residual_coding; |
2509 | 4.04k | curr_state->num_residual_signals = 0; |
2510 | 4.04k | if (curr_state->residual_coding) { |
2511 | 2.99k | for (i = 0; i < curr_state->num_ttt_boxes + curr_state->num_ott_boxes; i++) { |
2512 | 2.42k | if (config->bs_residual_present[i]) { |
2513 | 779 | curr_state->res_bands[i] = config->bs_residual_bands[i]; |
2514 | 779 | curr_state->num_residual_signals++; |
2515 | 1.64k | } else { |
2516 | 1.64k | curr_state->res_bands[i] = 0; |
2517 | 1.64k | } |
2518 | | |
2519 | 2.42k | if (curr_state->up_mix_type == 2 || curr_state->up_mix_type == 3) { |
2520 | 0 | curr_state->res_bands[i] = 0; |
2521 | 0 | } |
2522 | 2.42k | } |
2523 | 573 | } |
2524 | | |
2525 | 4.04k | curr_state->residual_frames_per_spatial_frame = |
2526 | 4.04k | p_bs_config->bs_residual_frames_per_spatial_frame + 1; |
2527 | 4.04k | if (curr_state->residual_frames_per_spatial_frame > 0) { |
2528 | 4.04k | WORD32 const *reciprocal_tab = |
2529 | 4.04k | pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->reciprocal; |
2530 | | |
2531 | 4.04k | WORD64 temp = |
2532 | 4.04k | (WORD64)(((WORD64)(p_bs_config->bs_frame_length + 1) * |
2533 | 4.04k | (WORD64)reciprocal_tab[p_bs_config->bs_residual_frames_per_spatial_frame]) >> |
2534 | 4.04k | 28); |
2535 | 4.04k | curr_state->upd_qmf = (WORD32)temp; |
2536 | 4.04k | if (curr_state->upd_qmf != UPD_QMF_15 && curr_state->upd_qmf != UPD_QMF_16 && |
2537 | 2.56k | curr_state->upd_qmf != UPD_QMF_32 && curr_state->upd_qmf != UPD_QMF_18 && |
2538 | 415 | curr_state->upd_qmf != UPD_QMF_30 && curr_state->upd_qmf != UPD_QMF_24) |
2539 | 7 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE; |
2540 | 4.04k | } |
2541 | | |
2542 | 4.03k | curr_state->arbdmx_residual_bands = config->bs_arbitrary_downmix_residual_bands; |
2543 | 4.03k | curr_state->arbdmx_frames_per_spatial_frame = |
2544 | 4.03k | config->bs_arbitrary_downmix_residual_frames_per_spatial_frame + 1; |
2545 | 4.03k | if (curr_state->arbdmx_frames_per_spatial_frame > 0) { |
2546 | 4.03k | curr_state->arbdmx_upd_qmf = |
2547 | 4.03k | curr_state->time_slots / curr_state->arbdmx_frames_per_spatial_frame; |
2548 | 4.03k | if (curr_state->arbdmx_upd_qmf != UPD_QMF_15 && curr_state->arbdmx_upd_qmf != UPD_QMF_16 && |
2549 | 2.55k | curr_state->arbdmx_upd_qmf != UPD_QMF_32 && curr_state->arbdmx_upd_qmf != UPD_QMF_18 && |
2550 | 409 | curr_state->arbdmx_upd_qmf != UPD_QMF_30 && curr_state->arbdmx_upd_qmf != UPD_QMF_24) |
2551 | 1 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE; |
2552 | | |
2553 | 4.03k | if ((curr_state->arbdmx_upd_qmf * 1.5f) > (curr_state->upd_qmf * 2)) |
2554 | 1 | return IA_XHEAAC_MPS_DEC_EXE_NONFATAL_INVALID_QMF_UPDATE; |
2555 | 4.03k | } |
2556 | | |
2557 | 4.03k | curr_state->cpc_default = 10; |
2558 | 4.03k | curr_state->ttt_cld_1_default[0] = 15; |
2559 | 4.03k | curr_state->ttt_cld_2_default[0] = 0; |
2560 | 4.03k | curr_state->icc_default = 0; |
2561 | 4.03k | curr_state->arbdmx_gain_default = 0; |
2562 | | |
2563 | 4.03k | if (curr_state->_3d_stereo_inversion) { |
2564 | 4 | if (config->bs_3d_audio_hrtf_set == 0) { |
2565 | 4 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_HRTF_SET; |
2566 | 4 | } else { |
2567 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_HRTF_SET; |
2568 | 0 | } |
2569 | 4 | } |
2570 | | |
2571 | 4.02k | switch (curr_state->tree_config) { |
2572 | 380 | case TREE_5151: |
2573 | 380 | curr_state->num_direct_signals = 1; |
2574 | 380 | curr_state->num_decor_signals = 4; |
2575 | | |
2576 | 380 | if (curr_state->up_mix_type == 2) { |
2577 | 0 | curr_state->num_decor_signals = 1; |
2578 | 0 | } |
2579 | | |
2580 | 380 | if (curr_state->up_mix_type == 3) { |
2581 | 0 | curr_state->num_decor_signals = 3; |
2582 | 0 | } |
2583 | | |
2584 | 380 | curr_state->num_x_channels = 1; |
2585 | 380 | if (curr_state->arbitrary_downmix == 2) { |
2586 | 137 | curr_state->num_x_channels += 1; |
2587 | 137 | } |
2588 | 380 | curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals; |
2589 | 380 | curr_state->num_w_channels = curr_state->num_v_channels; |
2590 | 380 | curr_state->w_start_residual_idx = 0; |
2591 | 380 | curr_state->ott_cld_default[0] = 15; |
2592 | 380 | curr_state->ott_cld_default[1] = 15; |
2593 | 380 | curr_state->ott_cld_default[2] = 0; |
2594 | 380 | curr_state->ott_cld_default[3] = 0; |
2595 | 380 | curr_state->ott_cld_default[4] = 15; |
2596 | 380 | break; |
2597 | 526 | case TREE_5152: |
2598 | 526 | curr_state->num_direct_signals = 1; |
2599 | 526 | curr_state->num_decor_signals = 4; |
2600 | | |
2601 | 526 | if (curr_state->up_mix_type == 2) { |
2602 | 0 | curr_state->num_decor_signals = 1; |
2603 | 0 | } |
2604 | | |
2605 | 526 | if (curr_state->up_mix_type == 3) { |
2606 | 0 | curr_state->num_decor_signals = 2; |
2607 | 0 | } |
2608 | | |
2609 | 526 | curr_state->num_x_channels = 1; |
2610 | 526 | if (curr_state->arbitrary_downmix == 2) { |
2611 | 10 | curr_state->num_x_channels += 1; |
2612 | 10 | } |
2613 | 526 | curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals; |
2614 | 526 | curr_state->num_w_channels = curr_state->num_v_channels; |
2615 | 526 | curr_state->w_start_residual_idx = 0; |
2616 | 526 | curr_state->ott_cld_default[0] = 15; |
2617 | 526 | curr_state->ott_cld_default[1] = 0; |
2618 | 526 | curr_state->ott_cld_default[2] = 15; |
2619 | 526 | curr_state->ott_cld_default[3] = 15; |
2620 | 526 | curr_state->ott_cld_default[4] = 15; |
2621 | 526 | break; |
2622 | 1.20k | case TREE_525: |
2623 | 1.20k | curr_state->num_direct_signals = 3; |
2624 | | |
2625 | 3.59k | for (i = 0; i < 2; i++) { |
2626 | 2.40k | switch (p_aux_struct->ttt_config[i][0].mode) { |
2627 | 1.08k | case TTT_MODE_0: |
2628 | 1.08k | p_aux_struct->ttt_config[i][0].use_ttt_decorr = 1; |
2629 | 1.08k | curr_state->num_decor_signals = 3; |
2630 | 1.08k | break; |
2631 | 261 | case TTT_MODE_1: |
2632 | 439 | case TTT_MODE_2: |
2633 | 625 | case TTT_MODE_3: |
2634 | 957 | case TTT_MODE_4: |
2635 | 1.16k | case TTT_MODE_5: |
2636 | 1.16k | p_aux_struct->ttt_config[i][0].use_ttt_decorr = 0; |
2637 | 1.16k | curr_state->num_decor_signals = 2; |
2638 | 1.16k | break; |
2639 | 150 | default: |
2640 | 150 | if (p_bs_config->bs_ttt_mode_low[0] <= 1) |
2641 | 1 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TTT_MODE; |
2642 | 149 | break; |
2643 | 2.40k | } |
2644 | 2.40k | } |
2645 | | |
2646 | 1.19k | if (curr_state->residual_coding == 1) { |
2647 | 450 | curr_state->num_x_channels = 3; |
2648 | 749 | } else { |
2649 | 749 | curr_state->num_x_channels = 2; |
2650 | 749 | } |
2651 | | |
2652 | 1.19k | if (curr_state->arbitrary_downmix == 2) { |
2653 | 13 | curr_state->num_x_channels = 5; |
2654 | 13 | } |
2655 | | |
2656 | 1.19k | if (curr_state->up_mix_type == 2) { |
2657 | 0 | curr_state->num_direct_signals = 2; |
2658 | 0 | curr_state->num_decor_signals = 0; |
2659 | 0 | curr_state->num_x_channels = 2; |
2660 | |
|
2661 | 0 | if (curr_state->arbitrary_downmix == 2) { |
2662 | 0 | curr_state->num_direct_signals = 4; |
2663 | 0 | curr_state->num_x_channels = 5; |
2664 | 0 | } |
2665 | 0 | } |
2666 | | |
2667 | 1.19k | curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals; |
2668 | 1.19k | curr_state->num_w_channels = curr_state->num_v_channels; |
2669 | 1.19k | curr_state->w_start_residual_idx = 1; |
2670 | 1.19k | curr_state->ott_cld_default[0] = 15; |
2671 | 1.19k | curr_state->ott_cld_default[1] = 15; |
2672 | 1.19k | curr_state->ott_cld_default[2] = 15; |
2673 | 1.19k | break; |
2674 | 272 | case TREE_7271: |
2675 | 617 | case TREE_7272: |
2676 | 617 | curr_state->num_direct_signals = 3; |
2677 | | |
2678 | 1.85k | for (i = 0; i < 2; i++) { |
2679 | 1.23k | switch (p_aux_struct->ttt_config[i][0].mode) { |
2680 | 484 | case TTT_MODE_0: |
2681 | 484 | p_aux_struct->ttt_config[i][0].use_ttt_decorr = 1; |
2682 | 484 | curr_state->num_decor_signals = 5; |
2683 | 484 | break; |
2684 | 60 | case TTT_MODE_1: |
2685 | 187 | case TTT_MODE_2: |
2686 | 355 | case TTT_MODE_3: |
2687 | 511 | case TTT_MODE_4: |
2688 | 550 | case TTT_MODE_5: |
2689 | 550 | p_aux_struct->ttt_config[i][0].use_ttt_decorr = 0; |
2690 | 550 | curr_state->num_decor_signals = 5; |
2691 | 550 | break; |
2692 | 200 | default: |
2693 | 200 | if (p_bs_config->bs_ttt_mode_low[0] <= 1) |
2694 | 1 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_INVALID_TTT_MODE; |
2695 | 199 | break; |
2696 | 1.23k | } |
2697 | 1.23k | } |
2698 | | |
2699 | 616 | if (curr_state->residual_coding == 1) { |
2700 | 45 | curr_state->num_x_channels = 3; |
2701 | 571 | } else { |
2702 | 571 | curr_state->num_x_channels = 2; |
2703 | 571 | } |
2704 | | |
2705 | 616 | if (curr_state->arbitrary_downmix == 2) { |
2706 | 48 | curr_state->num_x_channels = 5; |
2707 | 48 | } |
2708 | | |
2709 | 616 | if (curr_state->up_mix_type == 2) { |
2710 | 0 | curr_state->num_direct_signals = 2; |
2711 | 0 | curr_state->num_decor_signals = 0; |
2712 | 0 | curr_state->num_x_channels = 2; |
2713 | |
|
2714 | 0 | if (curr_state->arbitrary_downmix == 2) { |
2715 | 0 | curr_state->num_direct_signals = 4; |
2716 | 0 | curr_state->num_x_channels = 5; |
2717 | 0 | } |
2718 | 0 | } |
2719 | | |
2720 | 616 | curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals; |
2721 | 616 | curr_state->num_w_channels = curr_state->num_v_channels; |
2722 | 616 | curr_state->w_start_residual_idx = 1; |
2723 | 616 | curr_state->ott_cld_default[0] = 15; |
2724 | 616 | curr_state->ott_cld_default[1] = 15; |
2725 | 616 | curr_state->ott_cld_default[2] = 15; |
2726 | 616 | curr_state->ott_cld_default[3] = 15; |
2727 | 616 | curr_state->ott_cld_default[4] = 15; |
2728 | 616 | break; |
2729 | 189 | case TREE_7571: |
2730 | 1.30k | case TREE_7572: |
2731 | 1.30k | curr_state->num_direct_signals = 6; |
2732 | 1.30k | curr_state->num_decor_signals = 2; |
2733 | 1.30k | curr_state->num_x_channels = 6; |
2734 | 1.30k | curr_state->num_v_channels = curr_state->num_direct_signals + curr_state->num_decor_signals; |
2735 | 1.30k | curr_state->num_w_channels = curr_state->num_v_channels; |
2736 | 1.30k | curr_state->w_start_residual_idx = 0; |
2737 | 1.30k | curr_state->ott_cld_default[0] = 15; |
2738 | 1.30k | curr_state->ott_cld_default[1] = 15; |
2739 | 1.30k | break; |
2740 | 0 | default: |
2741 | 0 | return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG; |
2742 | 0 | break; |
2743 | 4.02k | } |
2744 | 4.02k | return IA_NO_ERROR; |
2745 | 4.02k | } |
2746 | | |
2747 | | VOID ixheaacd_get_dequant_tables( |
2748 | | WORD32 **cld, WORD32 **icc, WORD32 **cpc, |
2749 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
2750 | 0 | *cld = ixheaacd_mps_dec_bitdec_tables->dequant_cld; |
2751 | 0 | *icc = ixheaacd_mps_dec_bitdec_tables->dequant_icc; |
2752 | 0 | *cpc = ixheaacd_mps_dec_bitdec_tables->dequant_cpc; |
2753 | 0 | } |
2754 | | |
2755 | | WORD32 ixheaacd_quantize_cld(WORD32 v, |
2756 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
2757 | 0 | WORD32 i = 1; |
2758 | 0 | WORD32 temp_1; |
2759 | 0 | WORD32 vmin = ixheaacd_mps_dec_bitdec_tables->dequant_cld[0]; |
2760 | 0 | WORD32 dmin = abs(v - vmin); |
2761 | |
|
2762 | 0 | do { |
2763 | 0 | temp_1 = abs(v - ixheaacd_mps_dec_bitdec_tables->dequant_cld[i]); |
2764 | 0 | if (temp_1 < dmin) { |
2765 | 0 | dmin = temp_1; |
2766 | 0 | vmin = ixheaacd_mps_dec_bitdec_tables->dequant_cld[i]; |
2767 | 0 | } |
2768 | 0 | } while (ixheaacd_mps_dec_bitdec_tables->dequant_cld[i++] < ONE_FORTYNINE_Q15); |
2769 | 0 | return vmin; |
2770 | 0 | } |
2771 | | |
2772 | | WORD32 ixheaacd_quantize_icc(WORD32 v, |
2773 | 0 | ia_mps_dec_bitdec_tables_struct *ixheaacd_mps_dec_bitdec_tables) { |
2774 | 0 | WORD32 i = 1; |
2775 | 0 | WORD32 temp_1; |
2776 | 0 | WORD32 vmin = ixheaacd_mps_dec_bitdec_tables->dequant_icc[0]; |
2777 | 0 | WORD32 dmin = abs(v - vmin); |
2778 | |
|
2779 | 0 | do { |
2780 | 0 | temp_1 = abs(v - ixheaacd_mps_dec_bitdec_tables->dequant_icc[i]); |
2781 | 0 | if (temp_1 < dmin) { |
2782 | 0 | dmin = temp_1; |
2783 | 0 | vmin = ixheaacd_mps_dec_bitdec_tables->dequant_icc[i]; |
2784 | 0 | } |
2785 | 0 | } while (ixheaacd_mps_dec_bitdec_tables->dequant_icc[i++] > MINUS_POINT_NINE_EIGHT_Q15); |
2786 | |
|
2787 | 0 | return vmin; |
2788 | 0 | } |