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