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