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