/src/libxaac/encoder/ixheaace_api.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
21 | | #include <stdlib.h> |
22 | | #include <string.h> |
23 | | #include <stdlib.h> |
24 | | #include "ixheaac_type_def.h" |
25 | | #include "ixheaac_constants.h" |
26 | | #include "ixheaace_aac_constants.h" |
27 | | #include "ixheaac_basic_ops32.h" |
28 | | #include "ixheaac_basic_ops16.h" |
29 | | #include "ixheaac_basic_ops40.h" |
30 | | #include "ixheaac_basic_ops.h" |
31 | | /* standard */ |
32 | | #include "ixheaac_error_standards.h" |
33 | | |
34 | | #include "ixheaace_config_params.h" |
35 | | |
36 | | /* library */ |
37 | | #include "ixheaace_definitions.h" |
38 | | #include "ixheaace_error_codes.h" |
39 | | |
40 | | #include "iusace_bitbuffer.h" |
41 | | |
42 | | /* DRC */ |
43 | | #include "impd_drc_common_enc.h" |
44 | | #include "impd_drc_uni_drc.h" |
45 | | #include "impd_drc_tables.h" |
46 | | #include "impd_drc_api.h" |
47 | | #include "impd_drc_uni_drc_eq.h" |
48 | | #include "impd_drc_uni_drc_filter_bank.h" |
49 | | #include "impd_drc_gain_enc.h" |
50 | | #include "impd_drc_struct_def.h" |
51 | | #include "impd_drc_enc.h" |
52 | | |
53 | | #include "ixheaace_sbr_header.h" |
54 | | #include "ixheaace_sbr_def.h" |
55 | | #include "ixheaace_resampler.h" |
56 | | |
57 | | #include "ixheaace_psy_const.h" |
58 | | #include "ixheaace_tns.h" |
59 | | #include "ixheaace_tns_params.h" |
60 | | #include "ixheaace_rom.h" |
61 | | #include "ixheaace_common_rom.h" |
62 | | #include "ixheaace_bitbuffer.h" |
63 | | |
64 | | #include "ixheaace_sbr_rom.h" |
65 | | #include "ixheaace_common_rom.h" |
66 | | #include "ixheaace_sbr_main.h" |
67 | | #include "ixheaace_definitions.h" |
68 | | #include "ixheaace_api.h" |
69 | | #include "ixheaace_memory_standards.h" |
70 | | #include "iusace_block_switch_const.h" |
71 | | #include "iusace_block_switch_struct_def.h" |
72 | | #include "iusace_cnst.h" |
73 | | #include "iusace_tns_usac.h" |
74 | | #include "iusace_psy_mod.h" |
75 | | #include "iusace_config.h" |
76 | | #include "iusace_arith_enc.h" |
77 | | #include "ixheaace_version_number.h" |
78 | | |
79 | | #include "ixheaace_adjust_threshold_data.h" |
80 | | #include "ixheaace_dynamic_bits.h" |
81 | | #include "ixheaace_qc_data.h" |
82 | | #include "ixheaace_channel_map.h" |
83 | | #include "ixheaace_block_switch.h" |
84 | | #include "ixheaace_psy_data.h" |
85 | | #include "ixheaace_interface.h" |
86 | | #include "ixheaace_write_bitstream.h" |
87 | | #include "ixheaace_psy_configuration.h" |
88 | | #include "ixheaace_common_rom.h" |
89 | | |
90 | | #include "ixheaace_psy_mod.h" |
91 | | #include "iusace_fd_qc_util.h" |
92 | | #include "iusace_fd_quant.h" |
93 | | #include "iusace_ms.h" |
94 | | #include "iusace_signal_classifier.h" |
95 | | #include "ixheaace_sbr_header.h" |
96 | | |
97 | | #include "ixheaace_config.h" |
98 | | #include "ixheaace_asc_write.h" |
99 | | #include "iusace_main.h" |
100 | | #include "ixheaace_stereo_preproc.h" |
101 | | #include "ixheaace_enc_main.h" |
102 | | #include "ixheaace_qc_util.h" |
103 | | |
104 | | // MPS header |
105 | | #include "ixheaace_mps_common_fix.h" |
106 | | #include "ixheaace_mps_defines.h" |
107 | | #include "ixheaace_mps_common_define.h" |
108 | | |
109 | | #include "ixheaace_mps_struct_def.h" |
110 | | #include "ixheaace_mps_sac_polyphase.h" |
111 | | #include "ixheaace_mps_sac_hybfilter.h" |
112 | | #include "ixheaace_mps_bitstream.h" |
113 | | #include "ixheaace_mps_spatial_bitstream.h" |
114 | | |
115 | | #include "ixheaace_mps_buf.h" |
116 | | #include "ixheaace_mps_lib.h" |
117 | | #include "ixheaace_mps_main_structure.h" |
118 | | #include "ixheaace_mps_onset_detect.h" |
119 | | |
120 | | #include "ixheaace_mps_param_extract.h" |
121 | | |
122 | | #include "ixheaace_mps_static_gain.h" |
123 | | #include "ixheaace_mps_filter.h" |
124 | | #include "ixheaace_mps_delay.h" |
125 | | #include "ixheaace_mps_dmx_tdom_enh.h" |
126 | | #include "ixheaace_mps_main_structure.h" |
127 | | #include "ixheaace_mps_tools_rom.h" |
128 | | #include "ixheaace_mps_qmf.h" |
129 | | #include "ixheaace_mps_tree.h" |
130 | | #include "ixheaace_mps_frame_windowing.h" |
131 | | |
132 | | #include "ixheaace_mps_structure.h" |
133 | | #include "ixheaace_mps_memory.h" |
134 | | #include "ixheaace_mps_enc.h" |
135 | | #include "ixheaace_struct_def.h" |
136 | | #include "ixheaace_api_defs.h" |
137 | | |
138 | | #include "ixheaace_write_adts_adif.h" |
139 | | #include "ixheaace_loudness_measurement.h" |
140 | | #include "iusace_psy_utils.h" |
141 | | |
142 | 6.25k | static WORD32 iusace_scratch_size(VOID) { |
143 | 6.25k | WORD32 scr_size; |
144 | 6.25k | scr_size = IXHEAAC_GET_SIZE_ALIGNED(USACE_MAX_SCR_SIZE, BYTE_ALIGN_8); |
145 | 6.25k | return scr_size; |
146 | 6.25k | } |
147 | | |
148 | 6.25k | static WORD32 iusace_calc_pers_buf_sizes(ixheaace_api_struct *pstr_api_struct) { |
149 | 6.25k | WORD32 pers_size = 0; |
150 | 6.25k | ia_usac_encoder_config_struct *pstr_config = &pstr_api_struct->config[0].usac_config; |
151 | | |
152 | 6.25k | pers_size += IXHEAAC_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8); |
153 | 6.25k | pers_size += IXHEAAC_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8); |
154 | 6.25k | pers_size += IXHEAAC_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8); |
155 | 6.25k | pers_size += IXHEAAC_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8); |
156 | | |
157 | 6.25k | pers_size += |
158 | 6.25k | (IXHEAAC_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT32)), BYTE_ALIGN_8) * |
159 | 6.25k | pstr_config->channels); |
160 | 6.25k | pers_size += (IXHEAAC_GET_SIZE_ALIGNED((2 * pstr_config->drc_frame_size * sizeof(FLOAT32)), |
161 | 6.25k | BYTE_ALIGN_8) * |
162 | 6.25k | pstr_config->channels); |
163 | 6.25k | if (pstr_config->use_delay_adjustment == 1) { |
164 | 6.09k | pers_size += |
165 | 6.09k | (IXHEAAC_GET_SIZE_ALIGNED( |
166 | 6.09k | ((CC_DELAY_ADJUSTMENT * pstr_config->ccfl) / FRAME_LEN_1024) * sizeof(FLOAT32), |
167 | 6.09k | BYTE_ALIGN_8) * |
168 | 6.09k | pstr_config->channels); |
169 | 6.09k | pers_size += (IXHEAAC_GET_SIZE_ALIGNED( |
170 | 6.09k | ((CC_DELAY_ADJUSTMENT * pstr_config->drc_frame_size) / FRAME_LEN_1024) * |
171 | 6.09k | sizeof(FLOAT32), |
172 | 6.09k | BYTE_ALIGN_8) * |
173 | 6.09k | pstr_config->channels); |
174 | 6.09k | } |
175 | | |
176 | 6.25k | pers_size += |
177 | 6.25k | (IXHEAAC_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) * |
178 | 6.25k | pstr_config->channels); |
179 | | |
180 | 6.25k | pers_size += (IXHEAAC_GET_SIZE_ALIGNED((pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) * |
181 | 6.25k | pstr_config->channels); |
182 | | |
183 | 6.25k | pers_size += |
184 | 6.25k | (IXHEAAC_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) * |
185 | 6.25k | pstr_config->channels); |
186 | | |
187 | 6.25k | pers_size += |
188 | 6.25k | (IXHEAAC_GET_SIZE_ALIGNED((3 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) * |
189 | 6.25k | pstr_config->channels); |
190 | | |
191 | 6.25k | if (pstr_config->tns_select != 0) { |
192 | 2.55k | pers_size += |
193 | 2.55k | (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_tns_info), BYTE_ALIGN_8) * pstr_config->channels); |
194 | 2.55k | } |
195 | | |
196 | 6.25k | pers_size += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_usac_td_encoder_struct), BYTE_ALIGN_8) * |
197 | 6.25k | pstr_config->channels); |
198 | 6.25k | return pers_size; |
199 | 6.25k | } |
200 | | |
201 | | static WORD32 ia_enhaacplus_enc_sizeof_delay_buffer(FLAG flag_framelength_small, WORD32 aot, |
202 | | WORD32 resamp_idx, WORD32 delay_buf_size, |
203 | 19.5k | FLAG mps_enable) { |
204 | 19.5k | WORD32 downsample_fac; |
205 | 19.5k | if (resamp_idx > 1) { |
206 | 14.8k | downsample_fac = resamp_idx / 2; |
207 | 14.8k | } else { |
208 | 4.68k | downsample_fac = 1; |
209 | 4.68k | } |
210 | | // Set the downsampler delay |
211 | 19.5k | WORD32 max_downsamp_delay, max_upsamp_delay; |
212 | 19.5k | if (resamp_idx == 2) // 8:3 |
213 | 1.15k | { |
214 | 1.15k | max_downsamp_delay = MAXIMUM_DS_8_1_FILTER_DELAY; |
215 | 1.15k | max_upsamp_delay = MAXIMUM_DS_1_3_FILTER_DELAY; |
216 | 18.3k | } else if (resamp_idx == 3) // 2:1 |
217 | 11.9k | { |
218 | 11.9k | max_downsamp_delay = MAXIMUM_DS_2_1_FILTER_DELAY; |
219 | 11.9k | max_upsamp_delay = 0; |
220 | 11.9k | } else if (resamp_idx == 4) // 4:1 |
221 | 1.72k | { |
222 | 1.72k | max_downsamp_delay = MAXIMUM_DS_4_1_FILTER_DELAY; |
223 | 1.72k | max_upsamp_delay = 0; |
224 | 4.68k | } else { |
225 | 4.68k | max_downsamp_delay = MAXIMUM_DS_2_1_FILTER_DELAY; |
226 | 4.68k | max_upsamp_delay = 0; |
227 | 4.68k | } |
228 | | |
229 | 19.5k | if (aot == AOT_SBR || aot == AOT_PS) { |
230 | 2.88k | if (flag_framelength_small) |
231 | 862 | return (FRAME_LEN_960 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
232 | 862 | INPUT_DELAY_LC) * |
233 | 862 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
234 | 2.02k | else |
235 | 2.02k | return (FRAME_LEN_1024 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
236 | 2.02k | INPUT_DELAY_LC) * |
237 | 2.02k | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
238 | 16.6k | } else if (aot == AOT_AAC_LC) { |
239 | 1.09k | if (flag_framelength_small) |
240 | 442 | return (FRAME_LEN_960 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LC) * |
241 | 442 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
242 | 653 | else |
243 | 653 | return (FRAME_LEN_1024 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LC) * |
244 | 653 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
245 | 15.5k | } else if (aot == AOT_USAC) { |
246 | 12.5k | return (FRAME_LEN_1024 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
247 | 12.5k | INPUT_DELAY_LC) * |
248 | 12.5k | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
249 | 12.5k | } else if (aot == AOT_AAC_LD) { |
250 | 492 | if (flag_framelength_small) |
251 | 189 | return (FRAME_LEN_480 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LD_480) * |
252 | 189 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
253 | 303 | else |
254 | 303 | return (FRAME_LEN_512 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LD_512) * |
255 | 303 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
256 | 2.56k | } else if (aot == AOT_AAC_ELD) { |
257 | 2.56k | if (flag_framelength_small) { |
258 | 1.25k | if (mps_enable) { |
259 | 854 | return (FRAME_LEN_480 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
260 | 854 | INPUT_DELAY_ELDV2_480) * |
261 | 854 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
262 | 854 | } else { |
263 | 401 | return (FRAME_LEN_480 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
264 | 401 | INPUT_DELAY_ELD_480) * |
265 | 401 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
266 | 401 | } |
267 | 1.30k | } else { |
268 | 1.30k | if (mps_enable) { |
269 | 757 | return (FRAME_LEN_512 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
270 | 757 | INPUT_DELAY_ELDV2_512) * |
271 | 757 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
272 | 757 | } else { |
273 | 548 | return (FRAME_LEN_512 * (1 << downsample_fac) + max_upsamp_delay + max_downsamp_delay + |
274 | 548 | INPUT_DELAY_ELD_512) * |
275 | 548 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
276 | 548 | } |
277 | 1.30k | } |
278 | 2.56k | } else { |
279 | | // return LC Delay buffer size by default |
280 | 0 | return (FRAME_LEN_1024 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LC) * |
281 | 0 | IXHEAACE_MAX_CH_IN_BS_ELE * delay_buf_size; |
282 | 0 | } |
283 | 19.5k | } |
284 | | |
285 | | static VOID ia_enhaacplus_enc_find_slots_for_elements(WORD32 i_channel_mask, |
286 | | WORD32 *slots_for_elements, |
287 | 2.72k | WORD32 i_num_coupling_chan) { |
288 | 2.72k | WORD32 slot = 0, i; |
289 | | |
290 | 2.72k | if ((i_channel_mask & 0x3)) { |
291 | 2.20k | slots_for_elements[FRONT_LEFT_RIGHT] = slot; |
292 | 2.20k | slot += 2; |
293 | 2.20k | } |
294 | | |
295 | 2.72k | if ((i_channel_mask & 0x4)) { |
296 | 2.18k | slots_for_elements[FRONT_CENTER] = slot; |
297 | 2.18k | slot += 1; |
298 | 2.18k | } |
299 | | |
300 | 2.72k | if ((i_channel_mask & 0x8)) { |
301 | 642 | slots_for_elements[LFE_CHANNEL] = slot; |
302 | 642 | slot += 1; |
303 | 642 | } |
304 | | |
305 | 2.72k | if ((i_channel_mask & 0x30)) { |
306 | 1.20k | slots_for_elements[BACK_LEFT_RIGHT] = slot; |
307 | 1.20k | slot += 2; |
308 | 1.20k | } |
309 | | |
310 | 2.72k | if ((i_channel_mask & 0x100)) { |
311 | 241 | slots_for_elements[REAR_CENTER] = slot; |
312 | 241 | slot += 1; |
313 | 241 | } |
314 | | |
315 | 2.72k | if (i_num_coupling_chan != 0) { |
316 | 0 | for (i = 0; i < i_num_coupling_chan; i++) { |
317 | 0 | slots_for_elements[COUPLING_CH + i] = slot; |
318 | 0 | slot += 1; |
319 | 0 | } |
320 | 0 | } |
321 | | |
322 | 2.72k | return; |
323 | 2.72k | } |
324 | | |
325 | | static VOID ia_enhaacplus_enc_find_channel_config(WORD32 *num_bs_elements, WORD32 *chan_config, |
326 | | WORD32 *element_type, WORD32 *element_slot, |
327 | | WORD32 *element_instance_tag, |
328 | | WORD32 i_num_coupling_chan, |
329 | 2.72k | WORD32 i_channel_mask) { |
330 | 2.72k | WORD32 i; |
331 | 2.72k | WORD32 slots_for_elements[2 * MAXIMUM_BS_ELE]; |
332 | 2.72k | *num_bs_elements = 0; |
333 | | |
334 | 2.72k | ia_enhaacplus_enc_find_slots_for_elements(i_channel_mask, slots_for_elements, |
335 | 2.72k | i_num_coupling_chan); |
336 | | |
337 | 2.72k | if ((i_channel_mask & 0x4)) { |
338 | | /*Front Center Present*/ |
339 | 2.18k | chan_config[*num_bs_elements] = 1; |
340 | 2.18k | element_type[*num_bs_elements] = ID_SCE; |
341 | 2.18k | element_slot[*num_bs_elements] = slots_for_elements[FRONT_CENTER]; |
342 | 2.18k | element_instance_tag[*num_bs_elements] = 0; |
343 | 2.18k | (*num_bs_elements)++; |
344 | 2.18k | } |
345 | | |
346 | 2.72k | if ((i_channel_mask & 0x3)) { |
347 | | /*Front Left and Right Present*/ |
348 | 2.20k | chan_config[*num_bs_elements] = 2; |
349 | 2.20k | element_type[*num_bs_elements] = ID_CPE; |
350 | 2.20k | element_slot[*num_bs_elements] = slots_for_elements[FRONT_LEFT_RIGHT]; |
351 | 2.20k | element_instance_tag[*num_bs_elements] = 0; |
352 | 2.20k | (*num_bs_elements)++; |
353 | 2.20k | } |
354 | | |
355 | 2.72k | if ((i_channel_mask & 0x30)) { |
356 | | /*Back Left and Right Present*/ |
357 | 1.20k | chan_config[*num_bs_elements] = 2; |
358 | 1.20k | element_type[*num_bs_elements] = ID_CPE; |
359 | 1.20k | element_slot[*num_bs_elements] = slots_for_elements[BACK_LEFT_RIGHT]; |
360 | 1.20k | element_instance_tag[*num_bs_elements] = 1; |
361 | 1.20k | (*num_bs_elements)++; |
362 | 1.20k | } |
363 | | |
364 | 2.72k | if ((i_channel_mask & 0x100)) { |
365 | | /* Rear Center Present*/ |
366 | 241 | chan_config[*num_bs_elements] = 1; |
367 | 241 | element_type[*num_bs_elements] = ID_SCE; |
368 | 241 | element_slot[*num_bs_elements] = slots_for_elements[REAR_CENTER]; |
369 | 241 | element_instance_tag[*num_bs_elements] = 1; |
370 | 241 | (*num_bs_elements)++; |
371 | 241 | } |
372 | | |
373 | 2.72k | if ((i_channel_mask & 0x8)) { |
374 | | /*LFE channel Present*/ |
375 | 642 | chan_config[*num_bs_elements] = 1; |
376 | 642 | element_type[*num_bs_elements] = ID_LFE; |
377 | 642 | element_slot[*num_bs_elements] = slots_for_elements[LFE_CHANNEL]; |
378 | 642 | element_instance_tag[*num_bs_elements] = 0; |
379 | 642 | (*num_bs_elements)++; |
380 | 642 | } |
381 | | |
382 | 2.72k | if (i_num_coupling_chan != 0) { |
383 | 0 | for (i = 0; i < i_num_coupling_chan; i++) { |
384 | | /*Coupling Channel Present*/ |
385 | 0 | chan_config[*num_bs_elements] = 1; |
386 | 0 | element_type[*num_bs_elements] = ID_CCE; |
387 | 0 | element_slot[*num_bs_elements] = slots_for_elements[COUPLING_CH + i]; |
388 | 0 | element_instance_tag[*num_bs_elements] = i_num_coupling_chan - i - 1; |
389 | 0 | (*num_bs_elements)++; |
390 | 0 | } |
391 | 0 | } |
392 | 2.72k | } |
393 | | |
394 | | static VOID ia_enhaacplus_enc_allocate_bitrate_between_channels( |
395 | 1.67k | ixheaace_api_struct *pstr_api_struct, WORD32 *bitrate, WORD32 inp_bitrate) { |
396 | 1.67k | WORD32 ele_idx; |
397 | 1.67k | WORD32 num_lfe = 0, num_mono = 0, num_stereo = 0; |
398 | 1.67k | WORD32 bitrate_per_stereo, bitrate_per_mono; |
399 | 7.09k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
400 | 5.42k | switch (pstr_api_struct->config[ele_idx].element_type) { |
401 | 1.91k | case ID_SCE: |
402 | 1.91k | case ID_CCE: |
403 | 1.91k | num_mono++; |
404 | 1.91k | break; |
405 | 2.87k | case ID_CPE: |
406 | 2.87k | num_stereo++; |
407 | 2.87k | break; |
408 | 642 | case ID_LFE: |
409 | 642 | num_lfe++; |
410 | 642 | break; |
411 | 0 | default: |
412 | 0 | return; |
413 | 5.42k | } |
414 | 5.42k | } |
415 | 1.67k | bitrate_per_stereo = (WORD32)((inp_bitrate - (num_lfe)*8000) / (num_mono * 0.625 + num_stereo)); |
416 | 1.67k | bitrate_per_mono = (WORD32)(0.625 * bitrate_per_stereo); |
417 | 7.09k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
418 | 5.42k | switch (pstr_api_struct->config[ele_idx].element_type) { |
419 | 1.91k | case ID_SCE: |
420 | 1.91k | case ID_CCE: |
421 | 1.91k | bitrate[ele_idx] = bitrate_per_mono; |
422 | 1.91k | break; |
423 | 2.87k | case ID_CPE: |
424 | 2.87k | bitrate[ele_idx] = bitrate_per_stereo; |
425 | 2.87k | break; |
426 | 642 | case ID_LFE: |
427 | 642 | bitrate[ele_idx] = 8000; |
428 | 642 | break; |
429 | 0 | default: |
430 | 0 | return; |
431 | 5.42k | } |
432 | 5.42k | } |
433 | 1.67k | } |
434 | | |
435 | 2.76k | static IA_ERRORCODE ixheaace_validate_channel_mask(WORD32 ch_mask, WORD32 num_ch) { |
436 | 2.76k | IA_ERRORCODE err_code = IA_NO_ERROR; |
437 | | // If ch_mask not supported, return error |
438 | 2.76k | WORD32 temp_mask; |
439 | 2.76k | switch (num_ch) { |
440 | 544 | case 1: |
441 | 544 | temp_mask = CH_MASK_CENTER_FRONT; |
442 | 544 | break; |
443 | 540 | case 2: |
444 | 540 | temp_mask = CH_MASK_LEFT_RIGHT_FRONT; |
445 | 540 | break; |
446 | 229 | case 3: |
447 | 229 | temp_mask = CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT; |
448 | 229 | break; |
449 | 242 | case 4: |
450 | 242 | temp_mask = CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_REAR_CENTER; |
451 | 242 | break; |
452 | 562 | case 5: |
453 | 562 | temp_mask = CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK; |
454 | 562 | break; |
455 | 644 | case 6: |
456 | 644 | temp_mask = |
457 | 644 | CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK | CH_MASK_LFE; |
458 | 644 | break; |
459 | 0 | default: |
460 | 0 | temp_mask = 0; |
461 | 0 | break; |
462 | 2.76k | } |
463 | 2.76k | if (ch_mask != temp_mask) { |
464 | 39 | err_code = IA_EXHEAACE_CONFIG_FATAL_CHANNELS_MASK; |
465 | 39 | } |
466 | 2.76k | return err_code; |
467 | 2.76k | } |
468 | | |
469 | 2.60k | static VOID ixheaace_set_default_channel_mask(WORD32 *ch_mask, WORD32 num_ch) { |
470 | 2.60k | switch (num_ch) { |
471 | 430 | case 1: |
472 | 430 | *ch_mask = CH_MASK_CENTER_FRONT; |
473 | 430 | break; |
474 | 563 | case 2: |
475 | 563 | *ch_mask = CH_MASK_LEFT_RIGHT_FRONT; |
476 | 563 | break; |
477 | 223 | case 3: |
478 | 223 | *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT); |
479 | 223 | break; |
480 | 241 | case 4: |
481 | 241 | *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_REAR_CENTER); |
482 | 241 | break; |
483 | 541 | case 5: |
484 | 541 | *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK); |
485 | 541 | break; |
486 | 605 | case 6: |
487 | 605 | *ch_mask = |
488 | 605 | (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK | CH_MASK_LFE); |
489 | 605 | break; |
490 | 2.60k | } |
491 | 2.60k | } |
492 | | |
493 | | static VOID ixheaace_set_default_config(ixheaace_api_struct *pstr_api_struct, |
494 | 10.1k | ixheaace_input_config *pstr_input_config) { |
495 | 10.1k | ia_usac_encoder_config_struct *pstr_usac_config = &pstr_api_struct->config[0].usac_config; |
496 | 10.1k | WORD32 i; |
497 | | |
498 | 91.7k | for (i = 0; i < MAXIMUM_BS_ELE; i++) { |
499 | 81.5k | ia_enhaacplus_enc_aac_init_default_config(&pstr_api_struct->config[i].aac_config, |
500 | 81.5k | pstr_input_config->aot); |
501 | | |
502 | 81.5k | pstr_api_struct->config[i].i_channels = NUM_CHANNELS_CONFIG_PARAM_DEFAULT_VALUE; |
503 | 81.5k | pstr_api_struct->config[i].sample_rate = AAC_SAMP_FREQ_CONFIG_PARAM_DEFAULT_VALUE; |
504 | 81.5k | pstr_api_struct->config[i].native_sample_rate = AAC_SAMP_FREQ_CONFIG_PARAM_DEFAULT_VALUE; |
505 | 81.5k | pstr_api_struct->config[i].i_n_memtabs = NUM_MEMTABS_CONFIG_PARAM_DEFAULT_VALUE; |
506 | 81.5k | pstr_api_struct->config[i].aac_classic = AAC_CLASSIC_CONFIG_PARAM_DEFAULT_VALUE; |
507 | 81.5k | pstr_api_struct->config[i].use_parametric_stereo = USE_PS_CONFIG_PARAM_DEFAULT_VALUE; |
508 | 81.5k | pstr_api_struct->config[i].chmode_nchannels = CHMODE_NUM_CHANNELS_CONFIG_PARAM_DEFAULT_VALUE; |
509 | 81.5k | pstr_api_struct->config[i].chmode = CHMODE_CONFIG_PARAM_DEFAULT_VALUE; /*stereo*/ |
510 | 81.5k | pstr_api_struct->config[i].adts_flag = ADTS_FLAG_CONFIG_PARAM_DEFAULT_VALUE; |
511 | 81.5k | pstr_api_struct->config[i].num_bs_elements = NUM_BS_ELEMENTS_CONFIG_PARAM_DEFAULT_VALUE; |
512 | 81.5k | pstr_api_struct->config[i].i_channels_mask = CHANNEL_MASK_CONFIG_PARAM_DEFAULT_VALUE; |
513 | 81.5k | pstr_api_struct->config[i].i_num_coupling_chan = |
514 | 81.5k | NUM_COUPLING_CHANNEL_CONFIG_PARAM_DEFAULT_VALUE; |
515 | 81.5k | pstr_api_struct->config[i].element_type = ELEMENT_TYPE_CONFIG_PARAM_DEFAULT_VALUE; |
516 | 81.5k | pstr_api_struct->config[i].element_slot = ELEMENT_SLOT_CONFIG_PARAM_DEFAULT_VALUE; |
517 | 81.5k | pstr_api_struct->config[i].num_bs_elements = NUM_BS_ELEMENTS_CONFIG_PARAM_DEFAULT_VALUE; |
518 | 81.5k | pstr_api_struct->config[i].element_instance_tag = |
519 | 81.5k | ELEMENT_INSTANCE_TAG_CONFIG_PARAM_DEFAULT_VALUE; |
520 | 81.5k | pstr_api_struct->config[i].aac_config.calc_crc = AAC_CFG_CALC_CRC_CONFIG_PARAM_DEFAULT_VALUE; |
521 | 81.5k | pstr_api_struct->config[i].aac_config.full_bandwidth = |
522 | 81.5k | AAC_CFG_FULL_BW_CONFIG_PARAM_DEFAULT_VALUE; |
523 | 81.5k | pstr_api_struct->config[i].eldsbr_found = ELDSBR_FOUND_CONFIG_PARAM_DEFAULT_VALUE; |
524 | 81.5k | pstr_api_struct->config[i].use_mps = USE_MPS_PARAM_DEFAULT_VALUE; |
525 | 81.5k | pstr_api_struct->config[i].mps_tree_config = USE_MPS_TREE_CONFIG_PARAM_DEFAULT_VALUE; |
526 | 81.5k | } |
527 | 10.1k | if (pstr_input_config->aot == AOT_USAC) { |
528 | 6.25k | memset(pstr_usac_config, 0, sizeof(*pstr_usac_config)); |
529 | 6.25k | pstr_usac_config->channels = NUM_CHANNELS_CONFIG_PARAM_DEFAULT_VALUE; |
530 | 6.25k | pstr_usac_config->sample_rate = USAC_SAMP_FREQ_CONFIG_PARAM_DEFAULT_VALUE; |
531 | 6.25k | pstr_usac_config->core_sample_rate = USAC_SAMP_FREQ_CONFIG_PARAM_DEFAULT_VALUE; |
532 | 6.25k | pstr_usac_config->native_sample_rate = USAC_SAMP_FREQ_CONFIG_PARAM_DEFAULT_VALUE; |
533 | 6.25k | pstr_usac_config->sbr_pvc_active = USAC_SBR_PVC_DEFAULT_VALUE; |
534 | 6.25k | pstr_usac_config->sbr_inter_tes_active = USAC_SBR_INTER_TES_DEFAULT_VALUE; |
535 | 6.25k | pstr_usac_config->sbr_harmonic = USAC_SBR_HARMONIC_DEFAULT_VALUE; |
536 | 6.25k | pstr_usac_config->bit_rate = USAC_BITRATE_DEFAULT_VALUE; |
537 | 6.25k | pstr_usac_config->use_fill_element = USAC_FILL_ELEMENT_DEFAULT_VALUE; |
538 | 6.25k | pstr_usac_config->use_drc_element = USAC_DRC_DEFAULT_VALUE; |
539 | 6.25k | pstr_usac_config->cmplx_pred_flag = USAC_COMPLEX_PREDECTION_DEFAULT_VALUE; |
540 | 6.25k | pstr_usac_config->tns_select = USAC_TNS_DEFAULT_VALUE; |
541 | 6.25k | pstr_usac_config->flag_noiseFilling = USAC_FLAG_NOISE_FILLING_DEFAULT_VALUE; |
542 | 6.25k | pstr_usac_config->use_acelp_only = USAC_DEFAULT_ACELP_FLAG_VALUE; |
543 | 6.25k | pstr_usac_config->is_first_frame = USAC_FIRST_FRAME_FLAG_DEFAULT_VALUE; |
544 | 6.25k | pstr_usac_config->num_preroll_frames = CC_NUM_PREROLL_FRAMES; |
545 | 6.25k | pstr_usac_config->stream_id = USAC_DEFAULT_STREAM_ID_VALUE; |
546 | 6.25k | pstr_usac_config->use_delay_adjustment = USAC_DEFAULT_DELAY_ADJUSTMENT_VALUE; |
547 | 6.25k | pstr_usac_config->is_loudness_configured = USAC_DEFAULT_MEASURED_LOUDNESS_FLAG_VALUE; |
548 | 6.25k | } |
549 | | /* Initialize table pointers */ |
550 | 10.1k | ia_enhaacplus_enc_init_aac_tabs(&(pstr_api_struct->pstr_aac_tabs)); |
551 | 10.1k | ia_enhaacplus_enc_init_sbr_tabs(&(pstr_api_struct->spectral_band_replication_tabs)); |
552 | 10.1k | pstr_api_struct->common_tabs.pstr_common_tab = |
553 | 10.1k | (ixheaace_common_tables *)&ia_enhaacplus_enc_common_tab; |
554 | 10.1k | } |
555 | | |
556 | 10.1k | static IA_ERRORCODE ixheaace_validate_config_params(ixheaace_input_config *pstr_input_config) { |
557 | 10.1k | IA_ERRORCODE err_code = IA_NO_ERROR; |
558 | 10.1k | if (pstr_input_config->aot != AOT_AAC_ELD && pstr_input_config->aot != AOT_AAC_LC && |
559 | 10.1k | pstr_input_config->aot != AOT_AAC_LD && pstr_input_config->aot != AOT_PS && |
560 | 10.1k | pstr_input_config->aot != AOT_SBR && pstr_input_config->aot != AOT_USAC) { |
561 | 0 | pstr_input_config->aot = AOT_AAC_LC; |
562 | 0 | } |
563 | 10.1k | pstr_input_config->i_native_samp_freq = pstr_input_config->i_samp_freq; |
564 | 10.1k | pstr_input_config->i_samp_freq = iusace_map_sample_rate(pstr_input_config->i_samp_freq); |
565 | | |
566 | 10.1k | if ((pstr_input_config->i_channels < MIN_NUM_CORE_CODER_CHANNELS) || |
567 | 10.1k | (pstr_input_config->i_channels > MAX_NUM_CORE_CODER_CHANNELS)) { |
568 | 898 | pstr_input_config->i_channels = 1; |
569 | 898 | } |
570 | 10.1k | if (pstr_input_config->esbr_flag != 1 && pstr_input_config->esbr_flag != 0) { |
571 | 0 | pstr_input_config->esbr_flag = 0; |
572 | 0 | } |
573 | 10.1k | if ((pstr_input_config->esbr_flag == 1) && |
574 | 10.1k | ((pstr_input_config->aot != AOT_SBR) && (pstr_input_config->aot != AOT_PS) && |
575 | 6.34k | (pstr_input_config->aot != AOT_USAC))) { |
576 | 1.52k | pstr_input_config->esbr_flag = 0; |
577 | 1.52k | } |
578 | 10.1k | if (pstr_input_config->i_use_mps != 1 && pstr_input_config->i_use_mps != 0) { |
579 | 0 | pstr_input_config->i_use_mps = 0; |
580 | 0 | } |
581 | | |
582 | 10.1k | if ((pstr_input_config->i_channels != 2) && (pstr_input_config->i_channels != 6)) { |
583 | 3.68k | pstr_input_config->i_use_mps = 0; |
584 | 3.68k | } |
585 | 10.1k | if (pstr_input_config->aot != AOT_AAC_ELD && pstr_input_config->aot != AOT_USAC) { |
586 | 2.51k | pstr_input_config->i_use_mps = 0; |
587 | 2.51k | } |
588 | 10.1k | if (pstr_input_config->aot == AOT_USAC && pstr_input_config->i_use_mps == 1) { |
589 | 1.82k | if (pstr_input_config->ccfl_idx < SBR_8_3) { |
590 | 974 | pstr_input_config->ccfl_idx = SBR_2_1; |
591 | 974 | } |
592 | 1.82k | } |
593 | 10.1k | if (AOT_USAC == pstr_input_config->aot) { |
594 | 6.25k | if ((pstr_input_config->i_channels != 2) || (pstr_input_config->i_samp_freq > 48000)) { |
595 | | // Num qmf bands is mapped only till 48000. Hence, disable mps if fs > 48000 or if input |
596 | | // channels is not 2 |
597 | 2.95k | pstr_input_config->i_use_mps = 0; |
598 | 2.95k | } |
599 | 6.25k | } |
600 | 10.1k | if (pstr_input_config->i_use_mps == 1) { |
601 | 2.23k | if (pstr_input_config->i_channels == 2) { |
602 | 1.71k | if (pstr_input_config->i_mps_tree_config != TREE_212) { |
603 | 1.68k | pstr_input_config->i_mps_tree_config = TREE_212; |
604 | 1.68k | } |
605 | 1.71k | } else { |
606 | 517 | if (pstr_input_config->i_mps_tree_config != TREE_5151 && |
607 | 517 | pstr_input_config->i_mps_tree_config != TREE_5152 && |
608 | 517 | pstr_input_config->i_mps_tree_config != TREE_525) { |
609 | 194 | pstr_input_config->i_mps_tree_config = TREE_5151; |
610 | 194 | } |
611 | 517 | } |
612 | 7.96k | } else { |
613 | 7.96k | pstr_input_config->i_mps_tree_config = INVALID_TREE_CONFIG; |
614 | 7.96k | } |
615 | 10.1k | if (pstr_input_config->aot == AOT_USAC || pstr_input_config->aot == AOT_AAC_ELD || |
616 | 10.1k | pstr_input_config->aot == AOT_AAC_LD) { |
617 | 7.92k | pstr_input_config->i_use_adts = 0; |
618 | 7.92k | pstr_input_config->i_use_es = 1; |
619 | 7.92k | } |
620 | 10.1k | if (pstr_input_config->aot == AOT_USAC) { |
621 | 6.25k | if (pstr_input_config->codec_mode != USAC_SWITCHED && |
622 | 6.25k | pstr_input_config->codec_mode != USAC_ONLY_FD && |
623 | 6.25k | pstr_input_config->codec_mode != USAC_ONLY_TD) { |
624 | 3.90k | pstr_input_config->codec_mode = USAC_ONLY_FD; |
625 | 3.90k | } |
626 | 6.25k | if (pstr_input_config->ccfl_idx < NO_SBR_CCFL_768 || pstr_input_config->ccfl_idx > SBR_4_1) { |
627 | 2.40k | pstr_input_config->ccfl_idx = NO_SBR_CCFL_1024; // default value |
628 | 2.40k | } |
629 | 6.25k | if ((pstr_input_config->ccfl_idx == SBR_4_1) && (pstr_input_config->i_samp_freq < 32000)) |
630 | 298 | { |
631 | 298 | if (pstr_input_config->i_samp_freq >= 16000) |
632 | 222 | { |
633 | 222 | pstr_input_config->ccfl_idx = SBR_2_1; |
634 | 222 | } |
635 | 76 | else |
636 | 76 | { |
637 | 76 | pstr_input_config->ccfl_idx = NO_SBR_CCFL_1024; |
638 | 76 | } |
639 | 298 | } |
640 | 6.25k | if (pstr_input_config->cplx_pred != 1 && pstr_input_config->cplx_pred != 0) { |
641 | 0 | pstr_input_config->cplx_pred = 0; |
642 | 0 | } |
643 | 6.25k | if (pstr_input_config->use_drc_element != 0 && pstr_input_config->use_drc_element != 1) { |
644 | 0 | pstr_input_config->use_drc_element = 0; |
645 | 0 | } |
646 | | |
647 | 6.25k | if (pstr_input_config->hq_esbr != 0 && pstr_input_config->hq_esbr != 1) { |
648 | 0 | pstr_input_config->hq_esbr = 0; |
649 | 0 | } |
650 | 6.25k | if (pstr_input_config->harmonic_sbr != 0 && pstr_input_config->harmonic_sbr != 1) { |
651 | 0 | pstr_input_config->harmonic_sbr = 0; |
652 | 0 | } |
653 | 6.25k | if (pstr_input_config->pvc_active != 0 && pstr_input_config->pvc_active != 1) { |
654 | 0 | pstr_input_config->pvc_active = 0; |
655 | 0 | } |
656 | 6.25k | if (pstr_input_config->inter_tes_active != 0 && pstr_input_config->inter_tes_active != 1) { |
657 | 0 | pstr_input_config->inter_tes_active = 0; |
658 | 0 | } |
659 | 6.25k | if ((pstr_input_config->ccfl_idx != 3 && pstr_input_config->ccfl_idx != 4)) { |
660 | 3.99k | pstr_input_config->harmonic_sbr = 0; |
661 | 3.99k | } |
662 | 6.25k | if (pstr_input_config->harmonic_sbr != 1) { |
663 | 4.58k | pstr_input_config->hq_esbr = 0; |
664 | 4.58k | } |
665 | 6.25k | if (pstr_input_config->i_bitrate != 64000 && pstr_input_config->i_bitrate != 96000) { |
666 | 5.65k | pstr_input_config->i_bitrate = USAC_BITRATE_DEFAULT_VALUE; |
667 | 5.65k | } |
668 | 6.25k | { |
669 | 6.25k | if (pstr_input_config->i_bitrate < MINIMUM_BITRATE * pstr_input_config->i_channels) { |
670 | 0 | pstr_input_config->i_bitrate = MINIMUM_BITRATE * pstr_input_config->i_channels; |
671 | 0 | } |
672 | 6.25k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_768 || |
673 | 6.25k | pstr_input_config->ccfl_idx == NO_SBR_CCFL_1024) { |
674 | 3.74k | if (pstr_input_config->i_bitrate > |
675 | 3.74k | (WORD32)(6 * pstr_input_config->i_samp_freq * pstr_input_config->i_channels)) { |
676 | 348 | pstr_input_config->i_bitrate = |
677 | 348 | (6 * pstr_input_config->i_samp_freq * pstr_input_config->i_channels); |
678 | 348 | } |
679 | 3.74k | } else if (pstr_input_config->ccfl_idx == SBR_8_3) { |
680 | 251 | if (pstr_input_config->i_bitrate > |
681 | 251 | (WORD32)(6 * ((pstr_input_config->i_samp_freq * 3) / 8) * |
682 | 251 | pstr_input_config->i_channels)) { |
683 | 151 | pstr_input_config->i_bitrate = |
684 | 151 | (6 * ((pstr_input_config->i_samp_freq * 3) / 8) * pstr_input_config->i_channels); |
685 | 151 | } |
686 | 2.26k | } else if (pstr_input_config->ccfl_idx == SBR_2_1) { |
687 | 1.40k | if (pstr_input_config->i_bitrate > |
688 | 1.40k | (WORD32)(6 * (pstr_input_config->i_samp_freq / 2) * pstr_input_config->i_channels)) { |
689 | 83 | pstr_input_config->i_bitrate = |
690 | 83 | (6 * (pstr_input_config->i_samp_freq / 2) * pstr_input_config->i_channels); |
691 | 83 | } |
692 | 1.40k | } else if (pstr_input_config->ccfl_idx == SBR_4_1) { |
693 | 862 | if (pstr_input_config->i_bitrate > |
694 | 862 | (WORD32)(6 * (pstr_input_config->i_samp_freq / 4) * pstr_input_config->i_channels)) { |
695 | 259 | pstr_input_config->i_bitrate = |
696 | 259 | (6 * (pstr_input_config->i_samp_freq / 4) * pstr_input_config->i_channels); |
697 | 259 | } |
698 | 862 | } |
699 | 6.25k | } |
700 | | |
701 | 6.25k | { |
702 | 6.25k | if ((pstr_input_config->codec_mode == USAC_SWITCHED || |
703 | 6.25k | pstr_input_config->codec_mode == USAC_ONLY_TD) && pstr_input_config->esbr_flag && |
704 | 6.25k | pstr_input_config->i_samp_freq > 24000) { |
705 | 1.15k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_768) { |
706 | 297 | pstr_input_config->ccfl_idx = SBR_8_3; // Use 8:3 eSBR |
707 | 297 | } |
708 | 1.15k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_1024) { |
709 | 228 | pstr_input_config->ccfl_idx = SBR_2_1; // Use 2:1 eSBR |
710 | 228 | } |
711 | 1.15k | } |
712 | | |
713 | 6.25k | if (pstr_input_config->codec_mode == USAC_ONLY_FD && |
714 | 6.25k | pstr_input_config->i_samp_freq > 24000 && pstr_input_config->esbr_flag && |
715 | 6.25k | pstr_input_config->i_bitrate <= MAX_USAC_ESBR_BITRATE) { |
716 | 1.58k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_768) { |
717 | 29 | pstr_input_config->ccfl_idx = SBR_8_3; // Use 8:3 eSBR |
718 | 29 | } |
719 | 1.58k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_1024) { |
720 | 844 | pstr_input_config->ccfl_idx = SBR_2_1; // Use 2:1 eSBR |
721 | 844 | } |
722 | 1.58k | } |
723 | | |
724 | 6.25k | if (pstr_input_config->ccfl_idx == NO_SBR_CCFL_768 || |
725 | 6.25k | pstr_input_config->ccfl_idx == SBR_8_3) { |
726 | 1.43k | pstr_input_config->frame_length = LEN_SUPERFRAME_768; |
727 | 4.82k | } else { |
728 | 4.82k | pstr_input_config->frame_length = LEN_SUPERFRAME; |
729 | 4.82k | } |
730 | 6.25k | } |
731 | 6.25k | if (pstr_input_config->random_access_interval < MIN_RAP_INTERVAL_IN_MS) { |
732 | 2.38k | pstr_input_config->random_access_interval = DEFAULT_RAP_INTERVAL_IN_MS; |
733 | 2.38k | } |
734 | 6.25k | if (pstr_input_config->method_def > MAX_METHOD_DEFINITION_TYPE) { |
735 | 3.99k | pstr_input_config->method_def = METHOD_DEFINITION_PROGRAM_LOUDNESS; |
736 | 3.99k | } |
737 | 6.25k | if (pstr_input_config->measurement_system != MEASUREMENT_SYSTEM_BS_1770_3) { |
738 | 6.25k | pstr_input_config->measurement_system = MEASUREMENT_SYSTEM_BS_1770_3; |
739 | 6.25k | } |
740 | 6.25k | if (pstr_input_config->measured_loudness > MAX_METHOD_VALUE || |
741 | 6.25k | pstr_input_config->measured_loudness < MIN_METHOD_VALUE) { |
742 | 117 | pstr_input_config->measured_loudness = DEFAULT_METHOD_VALUE; |
743 | 117 | } |
744 | 6.25k | if (pstr_input_config->sample_peak_level > MAX_SAMPLE_PEAK_LEVEL || |
745 | 6.25k | pstr_input_config->sample_peak_level < MIN_SAMPLE_PEAK_LEVEL) { |
746 | 0 | pstr_input_config->sample_peak_level = DEFAULT_SAMPLE_PEAK_VALUE; |
747 | 0 | } |
748 | 6.25k | if (pstr_input_config->use_delay_adjustment != 0 && |
749 | 6.25k | pstr_input_config->use_delay_adjustment != 1) { |
750 | 6.09k | pstr_input_config->use_delay_adjustment = USAC_DEFAULT_DELAY_ADJUSTMENT_VALUE; |
751 | 6.09k | } |
752 | 6.25k | if (pstr_input_config->use_drc_element) { |
753 | 2.92k | ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)pstr_input_config->pv_drc_cfg; |
754 | 2.92k | err_code = impd_drc_validate_config_params(pstr_drc_cfg); |
755 | 2.92k | if (err_code & IA_FATAL_ERROR) { |
756 | 0 | return err_code; |
757 | 0 | } |
758 | 2.92k | if (err_code) { |
759 | 974 | pstr_input_config->use_drc_element = 0; |
760 | 974 | err_code = IA_NO_ERROR; |
761 | 974 | } |
762 | 2.92k | } |
763 | 6.25k | } else { |
764 | 3.94k | pstr_input_config->cplx_pred = 0; |
765 | 3.94k | pstr_input_config->harmonic_sbr = 0; |
766 | 3.94k | pstr_input_config->pvc_active = 0; |
767 | 3.94k | pstr_input_config->inter_tes_active = 0; |
768 | 3.94k | pstr_input_config->use_drc_element = 0; |
769 | 3.94k | pstr_input_config->hq_esbr = 0; |
770 | 3.94k | pstr_input_config->use_delay_adjustment = 0; |
771 | 3.94k | if (pstr_input_config->i_channels != 2 && pstr_input_config->aot == AOT_PS) { |
772 | 400 | pstr_input_config->aot = AOT_SBR; |
773 | 400 | } |
774 | 3.94k | if (pstr_input_config->aac_config.use_tns != 1 && |
775 | 3.94k | pstr_input_config->aac_config.use_tns != 0) { |
776 | 0 | pstr_input_config->aac_config.use_tns = 0; |
777 | 0 | } |
778 | 3.94k | if (pstr_input_config->aac_config.noise_filling != 1 && |
779 | 3.94k | pstr_input_config->aac_config.noise_filling != 0) { |
780 | 0 | pstr_input_config->aac_config.noise_filling = 0; |
781 | 0 | } |
782 | 3.94k | if (pstr_input_config->i_use_adts != 1 && pstr_input_config->i_use_adts != 0) { |
783 | 0 | pstr_input_config->i_use_adts = 0; |
784 | 0 | pstr_input_config->i_use_es = 1; |
785 | 0 | } |
786 | 3.94k | if (pstr_input_config->aac_config.full_bandwidth != 1 && |
787 | 3.94k | pstr_input_config->aac_config.full_bandwidth != 0) { |
788 | 0 | pstr_input_config->aac_config.full_bandwidth = 0; |
789 | 0 | } |
790 | 3.94k | { |
791 | 3.94k | if (pstr_input_config->i_bitrate < MINIMUM_BITRATE * pstr_input_config->i_channels) { |
792 | 2.04k | pstr_input_config->i_bitrate = MINIMUM_BITRATE * pstr_input_config->i_channels; |
793 | 2.04k | } |
794 | 3.94k | if (pstr_input_config->i_bitrate > |
795 | 3.94k | (WORD32)(6 * pstr_input_config->i_samp_freq * pstr_input_config->i_channels)) { |
796 | 1.25k | pstr_input_config->i_bitrate = |
797 | 1.25k | (6 * pstr_input_config->i_samp_freq * pstr_input_config->i_channels); |
798 | 1.25k | } |
799 | 3.94k | } |
800 | | |
801 | 3.94k | { |
802 | 3.94k | if (pstr_input_config->aot == AOT_AAC_LC || pstr_input_config->aot == AOT_SBR || |
803 | 3.94k | pstr_input_config->aot == AOT_PS) { |
804 | 2.27k | if (pstr_input_config->frame_length != LEN_SUPERFRAME && |
805 | 2.27k | pstr_input_config->frame_length != FRAME_LEN_960) { |
806 | 1.31k | pstr_input_config->frame_length = LEN_SUPERFRAME; |
807 | 1.31k | } |
808 | 2.27k | } else if (pstr_input_config->aot == AOT_AAC_LD || pstr_input_config->aot == AOT_AAC_ELD) { |
809 | 1.66k | if (pstr_input_config->frame_length != FRAME_LEN_512 && |
810 | 1.66k | pstr_input_config->frame_length != FRAME_LEN_480) { |
811 | 781 | pstr_input_config->frame_length = FRAME_LEN_512; |
812 | 781 | } |
813 | 1.66k | } else { |
814 | 0 | pstr_input_config->frame_length = LEN_SUPERFRAME; |
815 | 0 | } |
816 | 3.94k | } |
817 | 3.94k | if ((pstr_input_config->frame_length == FRAME_LEN_960) && |
818 | 3.94k | (pstr_input_config->esbr_flag == 1)) { |
819 | 403 | pstr_input_config->esbr_flag = 0; |
820 | 403 | } |
821 | 3.94k | } |
822 | 10.1k | return err_code; |
823 | 10.1k | } |
824 | | |
825 | | static IA_ERRORCODE ixheaace_set_config_params(ixheaace_api_struct *pstr_api_struct, |
826 | 10.1k | ixheaace_input_config *pstr_input_config) { |
827 | 10.1k | WORD32 ele_idx; |
828 | 10.1k | IA_ERRORCODE err_code = IA_NO_ERROR; |
829 | 10.1k | ia_usac_encoder_config_struct *pstr_usac_config = &pstr_api_struct->config[0].usac_config; |
830 | 10.1k | err_code = ixheaace_validate_config_params(pstr_input_config); |
831 | 10.1k | if (err_code) { |
832 | 0 | return err_code; |
833 | 0 | } |
834 | | |
835 | 10.1k | if (pstr_input_config->ui_pcm_wd_sz != 16) { |
836 | 274 | return (IA_EXHEAACE_CONFIG_FATAL_PCM_WDSZ); |
837 | 274 | } |
838 | 9.92k | if ((pstr_input_config->aac_config.inv_quant != 0) && |
839 | 9.92k | (pstr_input_config->aac_config.inv_quant != 1) && |
840 | 9.92k | (pstr_input_config->aac_config.inv_quant != 2)) { |
841 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_QUALITY_LEVEL); |
842 | 0 | } |
843 | 9.92k | if ((pstr_input_config->write_program_config_element != 0) && |
844 | 9.92k | (pstr_input_config->write_program_config_element != 1)) { |
845 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_WRITE_PCE); |
846 | 0 | } |
847 | 9.92k | if ((pstr_input_config->aac_config.f_no_stereo_preprocessing != 0) && |
848 | 9.92k | (pstr_input_config->aac_config.f_no_stereo_preprocessing != 1)) { |
849 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_USE_STEREO_PRE_PROC); |
850 | 0 | } |
851 | 9.92k | if ((pstr_input_config->aac_config.use_tns != 0) && |
852 | 9.92k | (pstr_input_config->aac_config.use_tns != 1)) { |
853 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_USE_TNS); |
854 | 0 | } |
855 | 9.92k | if ((pstr_input_config->aac_config.full_bandwidth != 0) && |
856 | 9.92k | (pstr_input_config->aac_config.full_bandwidth != 1)) { |
857 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_USE_FULL_BANDWIDTH); |
858 | 0 | } |
859 | | |
860 | 89.3k | for (ele_idx = 0; ele_idx < MAXIMUM_BS_ELE; ele_idx++) { |
861 | 79.4k | pstr_api_struct->config[ele_idx].aac_classic = 1; |
862 | 79.4k | pstr_api_struct->config[ele_idx].firstframe = 1; |
863 | 79.4k | pstr_api_struct->config[ele_idx].aot = pstr_input_config->aot; |
864 | 79.4k | pstr_api_struct->config[ele_idx].adts_flag = pstr_input_config->i_use_adts; |
865 | 79.4k | pstr_api_struct->config[ele_idx].sample_rate = pstr_input_config->i_samp_freq; |
866 | 79.4k | pstr_api_struct->config[ele_idx].native_sample_rate = pstr_input_config->i_native_samp_freq; |
867 | | |
868 | 79.4k | pstr_api_struct->config[ele_idx].i_channels = pstr_input_config->i_channels; |
869 | 79.4k | pstr_api_struct->config[ele_idx].i_native_channels = pstr_input_config->i_channels; |
870 | 79.4k | pstr_api_struct->config[ele_idx].i_channels_mode = pstr_input_config->i_channels; |
871 | 79.4k | pstr_api_struct->config[ele_idx].aac_config.bit_rate = pstr_input_config->i_bitrate; |
872 | 79.4k | pstr_api_struct->config[ele_idx].esbr_flag = pstr_input_config->esbr_flag; |
873 | 79.4k | pstr_api_struct->config[ele_idx].use_mps = pstr_input_config->i_use_mps; |
874 | 79.4k | pstr_api_struct->config[ele_idx].mps_tree_config = pstr_input_config->i_mps_tree_config; |
875 | 79.4k | pstr_api_struct->config[ele_idx].i_num_coupling_chan = pstr_input_config->i_num_coupling_chan; |
876 | 79.4k | pstr_api_struct->config[ele_idx].ui_pcm_wd_sz = pstr_input_config->ui_pcm_wd_sz; |
877 | 79.4k | pstr_api_struct->config[ele_idx].write_program_config_element = |
878 | 79.4k | pstr_input_config->write_program_config_element; |
879 | 79.4k | pstr_api_struct->config[ele_idx].frame_length = pstr_input_config->frame_length; |
880 | 79.4k | pstr_api_struct->config[ele_idx].aac_config.num_stereo_preprocessing = |
881 | 79.4k | pstr_input_config->aac_config.f_no_stereo_preprocessing; |
882 | | |
883 | 79.4k | pstr_api_struct->config[ele_idx].aac_config.use_tns = pstr_input_config->aac_config.use_tns; |
884 | 79.4k | if (pstr_input_config->aot == AOT_AAC_LD || pstr_input_config->aot == AOT_AAC_ELD) { |
885 | 12.5k | pstr_api_struct->config[ele_idx].aac_config.inv_quant = |
886 | 12.5k | pstr_input_config->aac_config.inv_quant; |
887 | 12.5k | if (pstr_input_config->frame_length == FRAME_LEN_512) { |
888 | 6.74k | pstr_api_struct->config[ele_idx].aac_config.flag_framelength_small = 0; |
889 | 6.74k | } else if (pstr_input_config->frame_length == FRAME_LEN_480) { |
890 | 5.82k | pstr_api_struct->config[ele_idx].aac_config.flag_framelength_small = 1; |
891 | 5.82k | } |
892 | 66.8k | } else if (pstr_input_config->aot == AOT_AAC_LC || pstr_input_config->aot == AOT_SBR || |
893 | 66.8k | pstr_input_config->aot == AOT_PS) { |
894 | 16.7k | pstr_api_struct->config[ele_idx].aac_config.inv_quant = 0; |
895 | 16.7k | if (pstr_input_config->frame_length == FRAME_LEN_1024) { |
896 | 11.5k | pstr_api_struct->config[ele_idx].aac_config.flag_framelength_small = 0; |
897 | 11.5k | } else if (pstr_input_config->frame_length == FRAME_LEN_960) { |
898 | 5.25k | pstr_api_struct->config[ele_idx].aac_config.flag_framelength_small = 1; |
899 | 5.25k | } |
900 | 16.7k | } |
901 | 79.4k | if ((AOT_SBR == pstr_input_config->aot) || (AOT_PS == pstr_input_config->aot) || |
902 | 79.4k | (AOT_AAC_ELD == pstr_input_config->aot)) { |
903 | 21.2k | pstr_api_struct->config[ele_idx].aac_classic = 0; |
904 | 21.2k | } |
905 | 79.4k | if (pstr_api_struct->config[ele_idx].sample_rate < 32000) { |
906 | 19.1k | if (pstr_api_struct->config[ele_idx].aac_classic == 0) { |
907 | 391 | pstr_api_struct->config[ele_idx].aac_classic = 1; |
908 | 391 | } |
909 | 19.1k | if (pstr_input_config->aot == AOT_SBR || pstr_input_config->aot == AOT_PS) { |
910 | 264 | pstr_input_config->aot = AOT_AAC_LC; |
911 | 264 | } |
912 | 19.1k | if (pstr_input_config->aot == AOT_AAC_ELD) { |
913 | 127 | pstr_input_config->aot = AOT_AAC_LD; |
914 | 127 | } |
915 | 19.1k | } |
916 | 79.4k | pstr_api_struct->config[ele_idx].eldsbr_found = |
917 | 79.4k | !(pstr_api_struct->config[ele_idx].aac_classic); |
918 | 79.4k | } |
919 | 9.92k | if (pstr_input_config->aot == AOT_USAC) { |
920 | 6.25k | if (pstr_input_config->i_channels > 2) { |
921 | 0 | return IA_EXHEAACE_CONFIG_FATAL_NUM_CHANNELS; |
922 | 0 | } |
923 | 6.25k | if ((pstr_input_config->i_samp_freq < 6000) || (pstr_input_config->i_samp_freq > 96000)) { |
924 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_SAMP_FREQ); |
925 | 0 | } |
926 | 6.25k | pstr_api_struct->usac_en = 1; |
927 | | |
928 | 6.25k | pstr_usac_config->codec_mode = pstr_input_config->codec_mode; |
929 | 6.25k | pstr_usac_config->channels = pstr_input_config->i_channels; |
930 | | |
931 | 6.25k | pstr_usac_config->core_sample_rate = pstr_input_config->i_samp_freq; |
932 | 6.25k | pstr_usac_config->sample_rate = pstr_input_config->i_samp_freq; |
933 | 6.25k | pstr_usac_config->native_sample_rate = pstr_input_config->i_native_samp_freq; |
934 | | |
935 | 6.25k | pstr_usac_config->ui_pcm_wd_sz = pstr_input_config->ui_pcm_wd_sz; |
936 | 6.25k | pstr_usac_config->ccfl_idx = pstr_input_config->ccfl_idx; |
937 | 6.25k | pstr_usac_config->bit_rate = pstr_input_config->i_bitrate; |
938 | 6.25k | pstr_usac_config->basic_bitrate = pstr_input_config->i_bitrate; |
939 | 6.25k | pstr_usac_config->tns_select = pstr_input_config->aac_config.use_tns; |
940 | 6.25k | pstr_usac_config->cmplx_pred_flag = pstr_input_config->cplx_pred; |
941 | 6.25k | pstr_usac_config->flag_noiseFilling = pstr_input_config->aac_config.noise_filling; |
942 | 6.25k | pstr_usac_config->sbr_pvc_active = pstr_input_config->pvc_active; |
943 | 6.25k | pstr_usac_config->sbr_harmonic = pstr_input_config->harmonic_sbr; |
944 | 6.25k | pstr_usac_config->hq_esbr = pstr_input_config->hq_esbr; |
945 | 6.25k | pstr_usac_config->sbr_inter_tes_active = pstr_input_config->inter_tes_active; |
946 | 6.25k | pstr_api_struct->config[0].chmode_nchannels = pstr_api_struct->config[0].i_channels; |
947 | | |
948 | 6.25k | switch (pstr_input_config->ccfl_idx) { |
949 | 860 | case NO_SBR_CCFL_768: |
950 | 860 | pstr_usac_config->ccfl = LEN_SUPERFRAME_768; |
951 | 860 | pstr_usac_config->in_frame_length = LEN_SUPERFRAME_768; |
952 | 860 | pstr_usac_config->sbr_enable = 0; |
953 | 860 | pstr_usac_config->drc_frame_size = LEN_SUPERFRAME_768; |
954 | 860 | break; |
955 | 1.48k | case NO_SBR_CCFL_1024: |
956 | 1.48k | pstr_usac_config->ccfl = LEN_SUPERFRAME; |
957 | 1.48k | pstr_usac_config->in_frame_length = LEN_SUPERFRAME; |
958 | 1.48k | pstr_usac_config->sbr_enable = 0; |
959 | 1.48k | pstr_usac_config->drc_frame_size = LEN_SUPERFRAME; |
960 | 1.48k | break; |
961 | 577 | case SBR_8_3: |
962 | 577 | pstr_usac_config->ccfl = LEN_SUPERFRAME_768; |
963 | 577 | pstr_usac_config->in_frame_length = (LEN_SUPERFRAME_768 * 8) / 3; |
964 | 577 | pstr_usac_config->sbr_enable = 1; |
965 | 577 | pstr_usac_config->drc_frame_size = (LEN_SUPERFRAME_768 * 8) / 3; |
966 | 577 | break; |
967 | 2.47k | case SBR_2_1: |
968 | 2.47k | pstr_usac_config->ccfl = LEN_SUPERFRAME; |
969 | 2.47k | pstr_usac_config->in_frame_length = (LEN_SUPERFRAME * 2); |
970 | 2.47k | pstr_usac_config->sbr_enable = 1; |
971 | 2.47k | pstr_usac_config->drc_frame_size = (LEN_SUPERFRAME * 2); |
972 | 2.47k | break; |
973 | 862 | case SBR_4_1: |
974 | 862 | pstr_usac_config->ccfl = LEN_SUPERFRAME; |
975 | 862 | pstr_usac_config->in_frame_length = (LEN_SUPERFRAME * 4); |
976 | 862 | pstr_usac_config->sbr_enable = 1; |
977 | 862 | pstr_usac_config->drc_frame_size = (LEN_SUPERFRAME * 4); |
978 | 862 | break; |
979 | 0 | default: |
980 | 0 | pstr_usac_config->ccfl = LEN_SUPERFRAME; |
981 | 0 | pstr_usac_config->in_frame_length = LEN_SUPERFRAME; |
982 | 0 | pstr_usac_config->sbr_enable = 0; |
983 | 0 | pstr_usac_config->drc_frame_size = LEN_SUPERFRAME; |
984 | 0 | break; |
985 | 6.25k | } |
986 | 6.25k | pstr_usac_config->random_access_interval = pstr_input_config->random_access_interval; |
987 | 6.25k | if (pstr_usac_config->random_access_interval > 0) { |
988 | 3.87k | pstr_usac_config->random_access_interval = |
989 | 3.87k | (WORD32)((((WORD64)pstr_usac_config->random_access_interval * |
990 | 3.87k | pstr_input_config->i_native_samp_freq) + |
991 | 3.87k | (pstr_usac_config->ccfl * 1000 - 1)) / |
992 | 3.87k | (pstr_usac_config->ccfl * 1000)); |
993 | 3.87k | } |
994 | 6.25k | pstr_usac_config->use_delay_adjustment = pstr_input_config->use_delay_adjustment; |
995 | 6.25k | if (pstr_usac_config->random_access_interval) { |
996 | 5.95k | pstr_usac_config->preroll_flag = 1; |
997 | 5.95k | } |
998 | 6.25k | if (pstr_usac_config->sbr_enable == 1) { |
999 | 3.91k | pstr_usac_config->num_preroll_frames++; |
1000 | 3.91k | if (pstr_usac_config->sbr_harmonic == 1) { |
1001 | 1.67k | pstr_usac_config->num_preroll_frames++; |
1002 | 1.67k | } |
1003 | 3.91k | } else { |
1004 | 2.34k | if (pstr_usac_config->use_delay_adjustment == 1) { |
1005 | 2.28k | pstr_usac_config->num_preroll_frames++; |
1006 | 2.28k | } |
1007 | 2.34k | } |
1008 | 6.25k | pstr_usac_config->stream_id = pstr_input_config->stream_id; |
1009 | 6.25k | if (pstr_input_config->ccfl_idx < NO_SBR_CCFL_768 || pstr_input_config->ccfl_idx > SBR_4_1) { |
1010 | 0 | pstr_api_struct->config[0].ccfl_idx = NO_SBR_CCFL_1024; // default value |
1011 | 6.25k | } else { |
1012 | 6.25k | pstr_api_struct->config[0].ccfl_idx = pstr_input_config->ccfl_idx; |
1013 | 6.25k | } |
1014 | 6.25k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
1015 | 577 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_upsamp_tab = |
1016 | 577 | (ixheaace_resampler_sos_table *)&iixheaace_resamp_1_to_3_filt_params; |
1017 | | |
1018 | 577 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_downsamp_tab = |
1019 | 577 | (ixheaace_resampler_sos_table *)&iixheaace_resamp_8_to_1_filt_params; |
1020 | 5.68k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_2_1) { |
1021 | 2.47k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab = |
1022 | 2.47k | (ixheaace_resampler_table *)&ixheaace_resamp_2_to_1_iir_filt_params; |
1023 | 3.20k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_4_1) { |
1024 | 862 | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab = |
1025 | 862 | (ixheaace_resampler_table *)&ixheaace_resamp_4_to_1_iir_filt_params; |
1026 | 862 | } |
1027 | 6.25k | pstr_usac_config->use_drc_element = pstr_input_config->use_drc_element; |
1028 | 6.25k | { |
1029 | 6.25k | ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)pstr_input_config->pv_drc_cfg; |
1030 | 6.25k | pstr_drc_cfg->str_uni_drc_config.str_channel_layout.base_ch_count = |
1031 | 6.25k | pstr_input_config->i_channels; |
1032 | 6.25k | pstr_drc_cfg->str_enc_params.sample_rate = pstr_input_config->i_samp_freq; |
1033 | 6.25k | pstr_drc_cfg->str_enc_params.domain = TIME_DOMAIN; |
1034 | 6.25k | pstr_drc_cfg->str_uni_drc_config.sample_rate = pstr_drc_cfg->str_enc_params.sample_rate; |
1035 | 6.25k | if (pstr_usac_config->use_drc_element) { |
1036 | 3.02k | for (WORD32 i = 0; i < pstr_drc_cfg->str_uni_drc_config.drc_coefficients_uni_drc_count; |
1037 | 1.95k | i++) { |
1038 | 1.06k | for (WORD32 j = 0; |
1039 | 2.08k | j < |
1040 | 2.08k | pstr_drc_cfg->str_uni_drc_config.str_drc_coefficients_uni_drc[i].gain_set_count; |
1041 | 1.06k | j++) { |
1042 | 1.01k | pstr_drc_cfg->str_uni_drc_config.str_drc_coefficients_uni_drc[i] |
1043 | 1.01k | .str_gain_set_params[j] |
1044 | 1.01k | .delta_tmin = |
1045 | 1.01k | impd_drc_get_delta_t_min(pstr_drc_cfg->str_uni_drc_config.sample_rate); |
1046 | 1.01k | } |
1047 | 1.06k | } |
1048 | 2.86k | for (WORD32 i = 0; i < pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext |
1049 | 2.86k | .drc_coefficients_uni_drc_v1_count; |
1050 | 1.95k | i++) { |
1051 | 2.07k | for (WORD32 j = 0; j < pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext |
1052 | 2.07k | .str_drc_coefficients_uni_drc_v1[i] |
1053 | 2.07k | .gain_set_count; |
1054 | 1.15k | j++) { |
1055 | 1.15k | pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext |
1056 | 1.15k | .str_drc_coefficients_uni_drc_v1[i] |
1057 | 1.15k | .str_gain_set_params[j] |
1058 | 1.15k | .delta_tmin = |
1059 | 1.15k | impd_drc_get_delta_t_min(pstr_drc_cfg->str_uni_drc_config.sample_rate); |
1060 | 1.15k | } |
1061 | 917 | } |
1062 | 1.95k | } |
1063 | 6.25k | pstr_usac_config->str_drc_cfg = *pstr_drc_cfg; |
1064 | 6.25k | pstr_usac_config->str_drc_cfg.str_enc_params.frame_size = pstr_usac_config->drc_frame_size; |
1065 | 6.25k | pstr_usac_config->str_drc_cfg.str_uni_drc_config.str_drc_coefficients_uni_drc |
1066 | 6.25k | ->drc_frame_size = pstr_usac_config->drc_frame_size; |
1067 | 6.25k | pstr_input_config->drc_frame_size = pstr_usac_config->drc_frame_size; |
1068 | | |
1069 | 6.25k | ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set = |
1070 | 6.25k | &pstr_usac_config->str_drc_cfg.str_enc_loudness_info_set; |
1071 | | |
1072 | 6.25k | if ((pstr_usac_config->use_drc_element && |
1073 | 6.25k | ((pstr_enc_loudness_info_set->loudness_info_count != 0) || |
1074 | 1.95k | (pstr_enc_loudness_info_set->loudness_info_album_count != 0) || |
1075 | 1.95k | (pstr_enc_loudness_info_set->str_loudness_info_set_extension |
1076 | 1.64k | .str_loudness_info_set_ext_eq.loudness_info_v1_count != 0) || |
1077 | 1.95k | (pstr_enc_loudness_info_set->str_loudness_info_set_extension |
1078 | 1.40k | .str_loudness_info_set_ext_eq.loudness_info_v1_album_count != 0)))) { |
1079 | 673 | pstr_usac_config->is_loudness_configured = 1; |
1080 | 5.58k | } else { |
1081 | 5.58k | pstr_usac_config->is_loudness_configured = 0; |
1082 | 5.58k | } |
1083 | 6.25k | } |
1084 | 6.25k | } else { |
1085 | 3.66k | if ((pstr_input_config->i_channels > MAX_NUM_CORE_CODER_CHANNELS)) { |
1086 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_NUM_CHANNELS); |
1087 | 0 | } |
1088 | 3.66k | if (!((pstr_input_config->i_native_samp_freq == 7350) || |
1089 | 3.66k | (pstr_input_config->i_native_samp_freq == 8000) || |
1090 | 3.66k | (pstr_input_config->i_native_samp_freq == 11025) || |
1091 | 3.66k | (pstr_input_config->i_native_samp_freq == 12000) || |
1092 | 3.66k | (pstr_input_config->i_native_samp_freq == 16000) || |
1093 | 3.66k | (pstr_input_config->i_native_samp_freq == 22050) || |
1094 | 3.66k | (pstr_input_config->i_native_samp_freq == 24000) || |
1095 | 3.66k | (pstr_input_config->i_native_samp_freq == 32000) || |
1096 | 3.66k | (pstr_input_config->i_native_samp_freq == 44100) || |
1097 | 3.66k | (pstr_input_config->i_native_samp_freq == 48000) || |
1098 | 3.66k | (pstr_input_config->i_native_samp_freq == 64000) || |
1099 | 3.66k | (pstr_input_config->i_native_samp_freq == 88200) || |
1100 | 3.66k | (pstr_input_config->i_native_samp_freq == 96000))) { |
1101 | 114 | return (IA_EXHEAACE_CONFIG_FATAL_SAMP_FREQ); |
1102 | 114 | } |
1103 | | |
1104 | 3.55k | if ((pstr_input_config->aot == AOT_AAC_ELD) && (pstr_input_config->i_use_mps == 1) && |
1105 | 3.55k | (pstr_input_config->i_channels > 2)) { |
1106 | 491 | pstr_api_struct->config[0].num_bs_elements = 1; |
1107 | 491 | pstr_api_struct->config[0].i_channels = pstr_input_config->i_channels; |
1108 | 491 | pstr_api_struct->config[0].i_native_channels = pstr_input_config->i_channels; |
1109 | 491 | pstr_api_struct->config[0].chmode_nchannels = pstr_input_config->i_channels; |
1110 | 491 | pstr_api_struct->config[0].element_type = ID_SCE; |
1111 | 491 | if (pstr_api_struct->config[0].mps_tree_config == TREE_525) { |
1112 | 268 | pstr_api_struct->config[0].element_type = ID_CPE; |
1113 | 268 | } |
1114 | 491 | pstr_api_struct->config[0].element_slot = 0; |
1115 | 491 | pstr_api_struct->config[0].element_instance_tag = 0; |
1116 | 491 | pstr_api_struct->config[0].aac_config.bit_rate = pstr_input_config->i_bitrate; |
1117 | 491 | pstr_api_struct->config[0].use_parametric_stereo = 0; |
1118 | 491 | } |
1119 | 3.55k | if (pstr_input_config->i_channels_mask == 0) { |
1120 | 2.60k | ixheaace_set_default_channel_mask(&pstr_input_config->i_channels_mask, |
1121 | 2.60k | pstr_input_config->i_channels); |
1122 | 2.60k | } |
1123 | 3.55k | if (pstr_api_struct->config[0].aac_config.dual_mono != 1) { |
1124 | 3.55k | if (pstr_input_config->aot != AOT_AAC_ELD || (pstr_input_config->i_use_mps != 1)) { |
1125 | 2.76k | WORD32 num_bs_elements, chan_config[MAXIMUM_BS_ELE], element_type[MAXIMUM_BS_ELE], |
1126 | 2.76k | element_slot[MAXIMUM_BS_ELE], element_instance_tag[MAXIMUM_BS_ELE], |
1127 | 2.76k | bitrate[MAXIMUM_BS_ELE]; |
1128 | 2.76k | if ((pstr_input_config->i_channels_mask > 0x3FFFF)) { |
1129 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_CHANNELS_MASK); |
1130 | 0 | } |
1131 | 2.76k | if (ixheaace_validate_channel_mask(pstr_input_config->i_channels_mask, |
1132 | 2.76k | pstr_input_config->i_channels)) { |
1133 | 39 | return IA_EXHEAACE_CONFIG_FATAL_CHANNELS_MASK; |
1134 | 39 | } |
1135 | 24.4k | for (ele_idx = 0; ele_idx < MAXIMUM_BS_ELE; ele_idx++) { |
1136 | 21.7k | pstr_api_struct->config[ele_idx].i_channels_mask = pstr_input_config->i_channels_mask; |
1137 | 21.7k | } |
1138 | 2.72k | ia_enhaacplus_enc_find_channel_config( |
1139 | 2.72k | &num_bs_elements, chan_config, element_type, element_slot, element_instance_tag, |
1140 | 2.72k | pstr_api_struct->config[0].i_num_coupling_chan, pstr_input_config->i_channels_mask); |
1141 | 9.20k | for (ele_idx = 0; ele_idx < num_bs_elements; ele_idx++) { |
1142 | 6.47k | pstr_api_struct->config[ele_idx].i_channels = chan_config[ele_idx]; |
1143 | 6.47k | pstr_api_struct->config[ele_idx].i_native_channels = chan_config[ele_idx]; |
1144 | 6.47k | pstr_api_struct->config[ele_idx].chmode_nchannels = chan_config[ele_idx]; |
1145 | 6.47k | pstr_api_struct->config[ele_idx].element_type = element_type[ele_idx]; |
1146 | 6.47k | pstr_api_struct->config[ele_idx].element_slot = element_slot[ele_idx]; |
1147 | 6.47k | pstr_api_struct->config[ele_idx].num_bs_elements = num_bs_elements; |
1148 | 6.47k | pstr_api_struct->config[ele_idx].element_instance_tag = element_instance_tag[ele_idx]; |
1149 | 6.47k | } |
1150 | | |
1151 | 2.72k | if (pstr_api_struct->config[0].num_bs_elements > 1) { |
1152 | 1.67k | ia_enhaacplus_enc_allocate_bitrate_between_channels(pstr_api_struct, bitrate, |
1153 | 1.67k | pstr_input_config->i_bitrate); |
1154 | | |
1155 | 7.09k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
1156 | 5.42k | pstr_api_struct->config[ele_idx].aac_config.bit_rate = bitrate[ele_idx]; |
1157 | 5.42k | } |
1158 | | |
1159 | 15.0k | for (ele_idx = 0; ele_idx < MAXIMUM_BS_ELE; ele_idx++) { |
1160 | 13.3k | pstr_api_struct->config[ele_idx].use_parametric_stereo = 0; |
1161 | 13.3k | } |
1162 | 1.67k | } |
1163 | 2.72k | } |
1164 | 3.55k | } else { |
1165 | 0 | WORD32 num_bs_elements; |
1166 | 0 | WORD32 bitrate[MAXIMUM_BS_ELE]; |
1167 | |
|
1168 | 0 | num_bs_elements = 2; |
1169 | |
|
1170 | 0 | pstr_api_struct->config[0].i_channels = 1; |
1171 | 0 | pstr_api_struct->config[0].chmode_nchannels = 1; |
1172 | 0 | pstr_api_struct->config[0].element_type = ID_SCE; |
1173 | 0 | pstr_api_struct->config[0].element_slot = 0; |
1174 | 0 | pstr_api_struct->config[0].num_bs_elements = num_bs_elements; |
1175 | 0 | pstr_api_struct->config[0].element_instance_tag = 0; |
1176 | |
|
1177 | 0 | pstr_api_struct->config[1].i_channels = 1; |
1178 | 0 | pstr_api_struct->config[1].chmode_nchannels = 1; |
1179 | 0 | pstr_api_struct->config[1].element_type = ID_SCE; |
1180 | 0 | pstr_api_struct->config[1].element_slot = 1; |
1181 | 0 | pstr_api_struct->config[1].num_bs_elements = num_bs_elements; |
1182 | 0 | pstr_api_struct->config[1].element_instance_tag = 1; |
1183 | |
|
1184 | 0 | if (pstr_api_struct->config[0].num_bs_elements > 1) { |
1185 | 0 | ia_enhaacplus_enc_allocate_bitrate_between_channels( |
1186 | 0 | pstr_api_struct, bitrate, pstr_api_struct->config[0].aac_config.bit_rate); |
1187 | |
|
1188 | 0 | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
1189 | 0 | pstr_api_struct->config[ele_idx].aac_config.bit_rate = bitrate[ele_idx]; |
1190 | 0 | } |
1191 | |
|
1192 | 0 | for (ele_idx = 0; ele_idx < MAXIMUM_BS_ELE; ele_idx++) { |
1193 | 0 | pstr_api_struct->config[ele_idx].use_parametric_stereo = 0; |
1194 | 0 | } |
1195 | 0 | } |
1196 | 0 | } |
1197 | | |
1198 | 3.51k | if (pstr_input_config->aot == AOT_PS && pstr_input_config->i_channels == 2) { |
1199 | 356 | pstr_api_struct->config[0].use_parametric_stereo = 1; |
1200 | 356 | pstr_api_struct->config[0].chmode_nchannels = 2; |
1201 | 3.15k | } else { |
1202 | 10.0k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
1203 | 6.91k | pstr_api_struct->config[ele_idx].chmode_nchannels = |
1204 | 6.91k | pstr_api_struct->config[ele_idx].i_channels; |
1205 | 6.91k | } |
1206 | 3.15k | } |
1207 | | |
1208 | 3.51k | if (pstr_input_config->aot == AOT_AAC_LD || pstr_input_config->aot == AOT_AAC_ELD) { |
1209 | 1.52k | WORD32 max_channel_bits = (pstr_api_struct->config[0].aac_config.flag_framelength_small |
1210 | 1.52k | ? MAXIMUM_CHANNEL_BITS_480 |
1211 | 1.52k | : MAXIMUM_CHANNEL_BITS_512); |
1212 | 1.52k | if ((pstr_input_config->aac_config.bitreservoir_size > max_channel_bits / 8) || |
1213 | 1.52k | (pstr_input_config->aac_config.bitreservoir_size < -1)) { |
1214 | 1.25k | pstr_input_config->aac_config.bitreservoir_size = |
1215 | 1.25k | BITRESERVOIR_SIZE_CONFIG_PARAM_DEFAULT_VALUE_LD; |
1216 | 1.25k | } |
1217 | 1.52k | pstr_api_struct->config[0].aac_config.bitreservoir_size = |
1218 | 1.52k | pstr_input_config->aac_config.bitreservoir_size; |
1219 | 1.52k | } |
1220 | 3.51k | if (pstr_input_config->aot == AOT_AAC_LC || pstr_input_config->aot == AOT_SBR || |
1221 | 3.51k | pstr_input_config->aot == AOT_PS) { |
1222 | 1.98k | WORD32 max_channel_bits = (pstr_api_struct->config[0].aac_config.flag_framelength_small |
1223 | 1.98k | ? MAXIMUM_CHANNEL_BITS_960 |
1224 | 1.98k | : MAXIMUM_CHANNEL_BITS_1024); |
1225 | | |
1226 | 1.98k | if ((pstr_input_config->aac_config.bitreservoir_size > max_channel_bits / 8) || |
1227 | 1.98k | (pstr_input_config->aac_config.bitreservoir_size < -1)) { |
1228 | 1.58k | pstr_input_config->aac_config.bitreservoir_size = |
1229 | 1.58k | BITRESERVOIR_SIZE_CONFIG_PARAM_DEFAULT_VALUE_LC; |
1230 | 1.58k | } |
1231 | 1.98k | pstr_api_struct->config[0].aac_config.bitreservoir_size = |
1232 | 1.98k | pstr_input_config->aac_config.bitreservoir_size; |
1233 | 1.98k | } |
1234 | 3.51k | pstr_api_struct->config[0].aac_config.full_bandwidth = |
1235 | 3.51k | pstr_input_config->aac_config.full_bandwidth; |
1236 | 3.51k | } |
1237 | | |
1238 | 9.77k | return IA_NO_ERROR; |
1239 | 9.92k | } |
1240 | | |
1241 | 9.77k | static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32 aot) { |
1242 | 9.77k | WORD32 ele_idx; |
1243 | 9.77k | WORD32 num_channel; |
1244 | 9.77k | WORD32 frame_length = LEN_SUPERFRAME; |
1245 | 9.77k | ixheaace_mem_info_struct *pstr_mem_info; |
1246 | 9.77k | frame_length = pstr_api_struct->config[0].frame_length; |
1247 | 9.77k | WORD32 offset_size = 0; |
1248 | 9.77k | if (pstr_api_struct->usac_en) { |
1249 | 6.25k | WORD32 fac_downsample = 1; |
1250 | 6.25k | if (pstr_api_struct->config[0].ccfl_idx > NO_SBR_CCFL_1024) { |
1251 | 3.91k | fac_downsample = pstr_api_struct->config[0].ccfl_idx >> 1; |
1252 | 3.91k | } else { |
1253 | 2.34k | fac_downsample = 1; |
1254 | 2.34k | } |
1255 | | /* persistant */ |
1256 | 6.25k | { |
1257 | 6.25k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_PERSIST_IDX]; |
1258 | 6.25k | { |
1259 | 6.25k | pstr_mem_info->ui_size = |
1260 | 6.25k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_state_struct), BYTE_ALIGN_8) + |
1261 | 6.25k | iusace_calc_pers_buf_sizes(pstr_api_struct); |
1262 | 6.25k | if (pstr_api_struct->config[0].usac_config.sbr_enable) { |
1263 | 3.91k | pstr_mem_info->ui_size += ixheaace_sbr_enc_pers_size( |
1264 | 3.91k | 2, 0, pstr_api_struct->config[0].usac_config.sbr_harmonic); |
1265 | 3.91k | } |
1266 | 6.25k | offset_size = 2 * |
1267 | 6.25k | ia_enhaacplus_enc_sizeof_delay_buffer( |
1268 | 6.25k | 0, AOT_USAC, pstr_api_struct->config[0].ccfl_idx, |
1269 | 6.25k | sizeof(pstr_api_struct->pstr_state->inp_delay[0]), |
1270 | 6.25k | pstr_api_struct->config[0].use_mps) * |
1271 | 6.25k | pstr_api_struct->config[0].num_bs_elements; |
1272 | 6.25k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1273 | | |
1274 | 6.25k | if (pstr_api_struct->config[0].use_mps) { |
1275 | 1.40k | offset_size = |
1276 | 1.40k | (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]); |
1277 | 1.40k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1278 | | |
1279 | 1.40k | offset_size = |
1280 | 1.40k | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]); |
1281 | 1.40k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1282 | | |
1283 | 1.40k | pstr_mem_info->ui_size += |
1284 | 1.40k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8); |
1285 | 1.40k | } |
1286 | 6.25k | if (1 == pstr_api_struct->config[0].usac_config.sbr_enable) { |
1287 | 3.91k | offset_size = |
1288 | 3.91k | (MAX_FRAME_LEN * (1 << fac_downsample) + MAX_DS_8_1_FILTER_DELAY + INPUT_DELAY) * |
1289 | 3.91k | MAX_CHANNELS * sizeof(pstr_mem_info->ui_size); |
1290 | 3.91k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1291 | 3.91k | } |
1292 | 6.25k | if ((2 != pstr_api_struct->config[0].usac_config.channels) && |
1293 | 6.25k | (1 == pstr_api_struct->config[0].usac_config.sbr_enable)) { |
1294 | 990 | offset_size = (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]); |
1295 | 990 | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1296 | 990 | } |
1297 | 6.25k | } |
1298 | | |
1299 | 6.25k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1300 | 6.25k | pstr_mem_info->ui_type = IA_MEMTYPE_PERSIST; |
1301 | 6.25k | pstr_mem_info->ui_placement[0] = 0; |
1302 | 6.25k | pstr_mem_info->ui_placement[1] = 0; |
1303 | 6.25k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1304 | 6.25k | pstr_mem_info->ui_placed[0] = 0; |
1305 | 6.25k | pstr_mem_info->ui_placed[1] = 0; |
1306 | 6.25k | } |
1307 | | |
1308 | | /* scratch */ |
1309 | 6.25k | { |
1310 | 6.25k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_SCRATCH_IDX]; |
1311 | 6.25k | UWORD32 usac_scr_size = iusace_scratch_size(); |
1312 | 6.25k | if (pstr_api_struct->config[0].usac_config.sbr_enable) { |
1313 | 3.91k | UWORD32 sbr_scr_size = ixheaace_sbr_enc_scr_size() + ixheaace_resampler_scr_size(); |
1314 | 3.91k | pstr_mem_info->ui_size = max(usac_scr_size, sbr_scr_size); |
1315 | 3.91k | } else { |
1316 | 2.34k | pstr_mem_info->ui_size = usac_scr_size; |
1317 | 2.34k | } |
1318 | | |
1319 | 6.25k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1320 | 6.25k | pstr_mem_info->ui_type = IA_MEMTYPE_SCRATCH; |
1321 | 6.25k | pstr_mem_info->ui_placement[0] = 0; |
1322 | 6.25k | pstr_mem_info->ui_placement[1] = 0; |
1323 | 6.25k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1324 | 6.25k | pstr_mem_info->ui_placed[0] = 0; |
1325 | 6.25k | pstr_mem_info->ui_placed[1] = 0; |
1326 | 6.25k | } |
1327 | | |
1328 | | /* input */ |
1329 | 6.25k | { |
1330 | 6.25k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_INPUT_IDX]; |
1331 | 6.25k | WORD32 pcm_wd_sz; |
1332 | 6.25k | num_channel = pstr_api_struct->config[0].i_channels; |
1333 | 6.25k | pcm_wd_sz = pstr_api_struct->config[0].usac_config.ui_pcm_wd_sz; |
1334 | 6.25k | pstr_mem_info->ui_size = frame_length * num_channel * (pcm_wd_sz >> 3); |
1335 | 6.25k | if (1 == pstr_api_struct->config[0].usac_config.sbr_enable) { |
1336 | 3.91k | switch (pstr_api_struct->config[0].ccfl_idx) { |
1337 | 577 | case SBR_8_3: // 8:3 |
1338 | 577 | pstr_mem_info->ui_size *= 8; |
1339 | 577 | pstr_mem_info->ui_size /= 3; |
1340 | 577 | break; |
1341 | | |
1342 | 2.47k | case SBR_2_1: // 2:1 |
1343 | 2.47k | pstr_mem_info->ui_size *= 2; |
1344 | 2.47k | break; |
1345 | | |
1346 | 862 | case SBR_4_1: // 4:1 |
1347 | 862 | pstr_mem_info->ui_size *= 4; |
1348 | 862 | break; |
1349 | 3.91k | } |
1350 | 3.91k | } |
1351 | | |
1352 | 6.25k | pstr_mem_info->ui_alignment = |
1353 | 6.25k | BYTE_ALIGN_8; /* As input is used as scratch memory internally */ |
1354 | 6.25k | pstr_mem_info->ui_type = IA_MEMTYPE_INPUT; |
1355 | 6.25k | pstr_mem_info->ui_placement[0] = 0; |
1356 | 6.25k | pstr_mem_info->ui_placement[1] = 0; |
1357 | 6.25k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1358 | 6.25k | pstr_mem_info->ui_placed[0] = 0; |
1359 | 6.25k | pstr_mem_info->ui_placed[1] = 0; |
1360 | 6.25k | } |
1361 | | |
1362 | | /* output */ |
1363 | 0 | { |
1364 | 6.25k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_OUTPUT_IDX]; |
1365 | 6.25k | pstr_mem_info->ui_size = |
1366 | 6.25k | ((MAX_PREROLL_FRAMES + 1) * (MAX_CHANNEL_BITS / BYTE_NUMBIT) * num_channel) + |
1367 | 6.25k | MAX_PREROLL_CONFIG_SIZE; |
1368 | 6.25k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1369 | 6.25k | pstr_mem_info->ui_type = IA_MEMTYPE_OUTPUT; |
1370 | 6.25k | pstr_mem_info->ui_placement[0] = 0; |
1371 | 6.25k | pstr_mem_info->ui_placement[1] = 0; |
1372 | 6.25k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1373 | 6.25k | pstr_mem_info->ui_placed[0] = 0; |
1374 | 6.25k | pstr_mem_info->ui_placed[1] = 0; |
1375 | 6.25k | } |
1376 | 6.25k | } else { |
1377 | | /* persistant */ |
1378 | 3.51k | { |
1379 | 3.51k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_PERSIST_IDX]; |
1380 | 3.51k | { |
1381 | 3.51k | if (pstr_api_struct->config[0].num_bs_elements == 1) { |
1382 | 1.84k | num_channel = pstr_api_struct->config[0].aac_classic |
1383 | 1.84k | ? pstr_api_struct->config[0].chmode_nchannels |
1384 | 1.84k | : (pstr_api_struct->config[0].use_parametric_stereo |
1385 | 1.48k | ? 1 |
1386 | 1.48k | : pstr_api_struct->config[0].chmode_nchannels); |
1387 | 1.84k | pstr_mem_info->ui_size = |
1388 | 1.84k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_state_struct), BYTE_ALIGN_8) + |
1389 | 1.84k | ia_enhaacplus_enc_aac_enc_pers_size(num_channel, aot); |
1390 | 1.84k | if (pstr_api_struct->config[0].aot != AOT_AAC_LC && |
1391 | 1.84k | pstr_api_struct->config[0].aot != AOT_AAC_LD) { |
1392 | 1.64k | pstr_mem_info->ui_size += ixheaace_sbr_enc_pers_size( |
1393 | 1.64k | num_channel, pstr_api_struct->config[0].use_parametric_stereo, 0); |
1394 | 1.64k | } |
1395 | 1.84k | offset_size = ia_enhaacplus_enc_sizeof_delay_buffer( |
1396 | 1.84k | pstr_api_struct->config[0].aac_config.flag_framelength_small, aot, 3, |
1397 | 1.84k | sizeof(pstr_api_struct->pstr_state->inp_delay[0]), |
1398 | 1.84k | pstr_api_struct->config[0].use_mps) * |
1399 | 1.84k | pstr_api_struct->config[0].num_bs_elements; |
1400 | 1.84k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1401 | 1.84k | } |
1402 | 3.51k | if (pstr_api_struct->config[0].num_bs_elements > 1) { |
1403 | 1.67k | offset_size = IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_state_struct), BYTE_ALIGN_8) + |
1404 | 1.67k | ia_enhaacplus_enc_sizeof_delay_buffer( |
1405 | 1.67k | pstr_api_struct->config[0].aac_config.flag_framelength_small, aot, 3, |
1406 | 1.67k | sizeof(pstr_api_struct->pstr_state->inp_delay[0]), |
1407 | 1.67k | pstr_api_struct->config[0].use_mps) * |
1408 | 1.67k | pstr_api_struct->config[0].num_bs_elements; |
1409 | 1.67k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1410 | 7.09k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
1411 | 5.42k | num_channel = pstr_api_struct->config[ele_idx].i_channels; |
1412 | 5.42k | if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) |
1413 | 4.78k | pstr_mem_info->ui_size += ixheaace_sbr_enc_pers_size(num_channel, 0, 0); |
1414 | 5.42k | pstr_mem_info->ui_size += ia_enhaacplus_enc_aac_enc_pers_size(num_channel, aot) + 32; |
1415 | 5.42k | } |
1416 | 1.67k | } |
1417 | | |
1418 | 3.51k | if (pstr_api_struct->config[0].use_mps) { |
1419 | 818 | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) { |
1420 | 432 | offset_size = |
1421 | 432 | (MAX_INPUT_SAMPLES + (INPUT_DELAY_ELDV2_480 * IXHEAACE_MAX_CH_IN_BS_ELE)) * |
1422 | 432 | sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]); |
1423 | 432 | } else { |
1424 | 386 | offset_size = |
1425 | 386 | (MAX_INPUT_SAMPLES + (INPUT_DELAY_ELDV2_512 * IXHEAACE_MAX_CH_IN_BS_ELE)) * |
1426 | 386 | sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]); |
1427 | 386 | } |
1428 | 818 | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1429 | 818 | if (pstr_api_struct->config[0].mps_tree_config == TREE_212) { |
1430 | 306 | pstr_mem_info->ui_size += |
1431 | 306 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8); |
1432 | 512 | } else { |
1433 | 512 | pstr_mem_info->ui_size += |
1434 | 512 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_515_memory_struct), BYTE_ALIGN_8); |
1435 | 512 | } |
1436 | 818 | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED( |
1437 | 818 | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]), |
1438 | 818 | BYTE_ALIGN_8); |
1439 | 818 | } |
1440 | | |
1441 | 3.51k | offset_size = IXHEAACE_MAX_PAYLOAD_SIZE * pstr_api_struct->config[0].num_bs_elements; |
1442 | 3.51k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1443 | 3.51k | offset_size = (MAX_FRAME_LEN * 2 + MAX_DS_2_1_FILTER_DELAY + INPUT_DELAY) * |
1444 | 3.51k | MAX_INPUT_CHAN * sizeof(pstr_mem_info->ui_size); |
1445 | 3.51k | pstr_mem_info->ui_size += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1446 | 3.51k | } |
1447 | | |
1448 | 3.51k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1449 | 3.51k | pstr_mem_info->ui_type = IA_MEMTYPE_PERSIST; |
1450 | 3.51k | pstr_mem_info->ui_placement[0] = 0; |
1451 | 3.51k | pstr_mem_info->ui_placement[1] = 0; |
1452 | 3.51k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1453 | 3.51k | pstr_mem_info->ui_placed[0] = 0; |
1454 | 3.51k | pstr_mem_info->ui_placed[1] = 0; |
1455 | 3.51k | } |
1456 | | |
1457 | | /* scratch */ |
1458 | 3.51k | { |
1459 | 3.51k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_SCRATCH_IDX]; |
1460 | 3.51k | { |
1461 | 3.51k | pstr_mem_info->ui_size = ia_enhaacplus_enc_aac_enc_scr_size(); |
1462 | 3.51k | UWORD32 sbr_scr_size = ixheaace_sbr_enc_scr_size() + ixheaace_resampler_scr_size(); |
1463 | 3.51k | UWORD32 mps_scr_size = 0; |
1464 | 3.51k | if (pstr_api_struct->config[0].use_mps) { |
1465 | 818 | if (pstr_api_struct->config[0].mps_tree_config != TREE_212) { |
1466 | 512 | mps_scr_size = ixheaace_mps_515_scratch_size(); |
1467 | 512 | } |
1468 | 818 | } |
1469 | 3.51k | pstr_mem_info->ui_size += MAX(sbr_scr_size, mps_scr_size); |
1470 | 3.51k | } |
1471 | 3.51k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1472 | 3.51k | pstr_mem_info->ui_type = IA_MEMTYPE_SCRATCH; |
1473 | 3.51k | pstr_mem_info->ui_placement[0] = 0; |
1474 | 3.51k | pstr_mem_info->ui_placement[1] = 0; |
1475 | 3.51k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1476 | 3.51k | pstr_mem_info->ui_placed[0] = 0; |
1477 | 3.51k | pstr_mem_info->ui_placed[1] = 0; |
1478 | 3.51k | } |
1479 | | |
1480 | | /* input */ |
1481 | 3.51k | { |
1482 | 3.51k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_INPUT_IDX]; |
1483 | | |
1484 | 3.51k | WORD32 pcm_wd_sz; |
1485 | 3.51k | pcm_wd_sz = pstr_api_struct->config[0].ui_pcm_wd_sz; |
1486 | 3.51k | num_channel = 0; |
1487 | 10.7k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
1488 | 7.27k | num_channel += pstr_api_struct->config[ele_idx].i_channels; |
1489 | 7.27k | } |
1490 | 3.51k | { |
1491 | 3.51k | if (pstr_api_struct->config[0].aac_classic) { |
1492 | 974 | pstr_mem_info->ui_size = (frame_length * (pcm_wd_sz >> 3)) * num_channel; |
1493 | 2.54k | } else { |
1494 | 2.54k | pstr_mem_info->ui_size = (frame_length * (pcm_wd_sz >> 3)) * 2 * num_channel; |
1495 | 2.54k | } |
1496 | 3.51k | } |
1497 | 3.51k | pstr_mem_info->ui_alignment = |
1498 | 3.51k | BYTE_ALIGN_8; /* As input is used as scratch memory internally */ |
1499 | 3.51k | pstr_mem_info->ui_type = IA_MEMTYPE_INPUT; |
1500 | 3.51k | pstr_mem_info->ui_placement[0] = 0; |
1501 | 3.51k | pstr_mem_info->ui_placement[1] = 0; |
1502 | 3.51k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1503 | 3.51k | pstr_mem_info->ui_placed[0] = 0; |
1504 | 3.51k | pstr_mem_info->ui_placed[1] = 0; |
1505 | 3.51k | } |
1506 | | |
1507 | | /* output */ |
1508 | 3.51k | { |
1509 | 3.51k | pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_OUTPUT_IDX]; |
1510 | 3.51k | if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) { |
1511 | 1.98k | pstr_mem_info->ui_size = (6 * frame_length / 8) * num_channel; |
1512 | 1.98k | pstr_mem_info->ui_size += (7) * IXHEAACE_MAX_CH_IN_BS_ELE * MAXIMUM_BS_ELE; |
1513 | 1.98k | } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) { |
1514 | 1.52k | pstr_mem_info->ui_size = (6 * frame_length / 8) * num_channel; |
1515 | 1.52k | } |
1516 | 3.51k | pstr_mem_info->ui_alignment = BYTE_ALIGN_8; |
1517 | 3.51k | pstr_mem_info->ui_type = IA_MEMTYPE_OUTPUT; |
1518 | 3.51k | pstr_mem_info->ui_placement[0] = 0; |
1519 | 3.51k | pstr_mem_info->ui_placement[1] = 0; |
1520 | 3.51k | pstr_mem_info->ui_priority = IA_MEMPRIORITY_ANYWHERE; |
1521 | 3.51k | pstr_mem_info->ui_placed[0] = 0; |
1522 | 3.51k | pstr_mem_info->ui_placed[1] = 0; |
1523 | 3.51k | } |
1524 | 3.51k | } |
1525 | | |
1526 | 9.77k | return; |
1527 | 9.77k | } |
1528 | | |
1529 | | static WORD32 get_drc_config_size(ixheaace_api_struct *pstr_api_struct, |
1530 | 1.95k | ixheaace_input_config *ptr_in_cfg) { |
1531 | 1.95k | WORD32 bit_count = 0; |
1532 | 1.95k | WORD32 total_byte_cnt = 0; |
1533 | | |
1534 | 1.95k | ia_drc_enc_state *pstr_drc_state = |
1535 | 1.95k | &pstr_api_struct->pstr_state->str_usac_enc_data.str_drc_state; |
1536 | 1.95k | ia_drc_input_config *pstr_in_drc_cfg = (ia_drc_input_config *)ptr_in_cfg->pv_drc_cfg; |
1537 | | |
1538 | 1.95k | memset(pstr_drc_state, 0, sizeof(*pstr_drc_state)); |
1539 | | |
1540 | 1.95k | pstr_drc_state->str_enc_params = pstr_in_drc_cfg->str_enc_params; |
1541 | 1.95k | pstr_drc_state->str_uni_drc_config = pstr_in_drc_cfg->str_uni_drc_config; |
1542 | 1.95k | pstr_drc_state->str_gain_enc.str_loudness_info_set = pstr_in_drc_cfg->str_enc_loudness_info_set; |
1543 | 1.95k | pstr_drc_state->str_enc_gain_extension = pstr_in_drc_cfg->str_enc_gain_extension; |
1544 | 1.95k | pstr_drc_state->str_gain_enc.str_uni_drc_config = pstr_in_drc_cfg->str_uni_drc_config; |
1545 | 1.95k | pstr_drc_state->drc_scratch_mem = |
1546 | 1.95k | pstr_api_struct->pstr_state->str_usac_enc_data.str_scratch.ptr_scratch_buf; |
1547 | 1.95k | pstr_drc_state->str_gain_enc.base_ch_count = ptr_in_cfg->i_channels; |
1548 | | |
1549 | | //uniDrc payload size |
1550 | 1.95k | impd_drc_write_uni_drc_config(pstr_drc_state, &bit_count, 0); |
1551 | 1.95k | total_byte_cnt += ((bit_count + 7) >> 3); |
1552 | 1.95k | bit_count = 0; |
1553 | | |
1554 | | // LoudnessInfo payload size |
1555 | 1.95k | impd_drc_write_loudness_info_set(pstr_drc_state, NULL, &bit_count, 0); |
1556 | 1.95k | total_byte_cnt += ((bit_count + 7) >> 3); |
1557 | | |
1558 | 1.95k | return total_byte_cnt; |
1559 | 1.95k | } |
1560 | | |
1561 | | static IA_ERRORCODE ixheaace_alloc_and_assign_mem(ixheaace_api_struct *pstr_api_struct, |
1562 | | ixheaace_output_config *ptr_out_cfg, |
1563 | 9.77k | ixheaace_input_config *ptr_in_cfg) { |
1564 | 9.77k | IA_ERRORCODE err_code = IA_NO_ERROR; |
1565 | 9.77k | UWORD32 i_idx; |
1566 | 9.77k | pVOID pv_value; |
1567 | 48.8k | for (i_idx = 0; i_idx < 4; i_idx++) { |
1568 | 39.0k | if (i_idx == IA_ENHAACPLUSENC_OUTPUT_IDX && |
1569 | 39.0k | pstr_api_struct->config[0].usac_config.use_drc_element) { |
1570 | 1.95k | WORD32 drc_config_size_expected = |
1571 | 1.95k | get_drc_config_size(pstr_api_struct, ptr_in_cfg); |
1572 | 1.95k | if (drc_config_size_expected > MAX_DRC_CONFIG_SIZE_EXPECTED) { |
1573 | 0 | return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG; |
1574 | 0 | } |
1575 | 1.95k | pstr_api_struct->pstr_mem_info[i_idx].ui_size += drc_config_size_expected; |
1576 | 1.95k | } |
1577 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_size = pstr_api_struct->pstr_mem_info[i_idx].ui_size; |
1578 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_alignment = |
1579 | 39.0k | pstr_api_struct->pstr_mem_info[i_idx].ui_alignment; |
1580 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_type = pstr_api_struct->pstr_mem_info[i_idx].ui_type; |
1581 | | |
1582 | 39.0k | ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count] = |
1583 | 39.0k | ptr_out_cfg->malloc_xheaace(ptr_out_cfg->mem_info_table[i_idx].ui_size + |
1584 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_alignment, |
1585 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_alignment); |
1586 | | |
1587 | 39.0k | if (NULL == ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count]) { |
1588 | 0 | return IA_EXHEAACE_API_FATAL_MEM_ALLOC; |
1589 | 0 | } |
1590 | 39.0k | memset(ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count], 0, |
1591 | 39.0k | ptr_out_cfg->mem_info_table[i_idx].ui_size); |
1592 | 39.0k | if ((i_idx == IA_ENHAACPLUSENC_PERSIST_IDX) || (i_idx == IA_ENHAACPLUSENC_SCRATCH_IDX)) { |
1593 | 19.5k | ptr_out_cfg->ui_rem = |
1594 | 19.5k | (SIZE_T)((SIZE_T)ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count] % |
1595 | 19.5k | ptr_out_cfg->mem_info_table[i_idx].ui_alignment); |
1596 | | |
1597 | 19.5k | pv_value = ptr_out_cfg->mem_info_table[i_idx].mem_ptr = |
1598 | 19.5k | (pVOID)((WORD8 *)ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count] + |
1599 | 19.5k | ptr_out_cfg->mem_info_table[i_idx].ui_alignment - ptr_out_cfg->ui_rem); |
1600 | 19.5k | } else { |
1601 | 19.5k | pv_value = ptr_out_cfg->mem_info_table[i_idx].mem_ptr = |
1602 | 19.5k | ptr_out_cfg->arr_alloc_memory[ptr_out_cfg->malloc_count]; |
1603 | 19.5k | } |
1604 | | |
1605 | 39.0k | pstr_api_struct->pp_mem[i_idx] = ptr_out_cfg->mem_info_table[i_idx].mem_ptr; |
1606 | 39.0k | memset(pstr_api_struct->pp_mem[i_idx], 0, pstr_api_struct->pstr_mem_info[i_idx].ui_size); |
1607 | | |
1608 | 39.0k | pstr_api_struct->pp_mem[i_idx] = pv_value; |
1609 | | |
1610 | 39.0k | if (i_idx == IA_ENHAACPLUSENC_PERSIST_IDX) { |
1611 | 9.77k | WORD32 offset_size = IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_state_struct), BYTE_ALIGN_8); |
1612 | 9.77k | WORD8 *p_offset = NULL; |
1613 | | |
1614 | | /* Set persistent memory pointer in api obj */ |
1615 | 9.77k | pstr_api_struct->pstr_state = (ixheaace_state_struct *)pv_value; |
1616 | 9.77k | WORD32 i, inp_delay_size; |
1617 | 9.77k | WORD8 *p_temp; |
1618 | 9.77k | if (pstr_api_struct->usac_en) { |
1619 | 6.25k | memset(pstr_api_struct->pstr_state, 0, sizeof(*(pstr_api_struct->pstr_state))); |
1620 | 6.25k | ia_usac_encoder_config_struct *pstr_usac_config = &pstr_api_struct->config[0].usac_config; |
1621 | 6.25k | ixheaace_state_struct *pstr_state = pstr_api_struct->pstr_state; |
1622 | 6.25k | ia_usac_data_struct *pstr_usac_enc_data = &(pstr_state->str_usac_enc_data); |
1623 | | |
1624 | 6.25k | pstr_state->ptr_in_buf = (FLOAT32 **)((WORD8 *)pstr_state + offset_size); |
1625 | | |
1626 | 6.25k | offset_size = pstr_usac_config->channels * sizeof(FLOAT32 *); |
1627 | 6.25k | p_offset = (WORD8 *)pstr_state->ptr_in_buf + |
1628 | 6.25k | IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1629 | | |
1630 | | // Input delay |
1631 | 6.25k | pstr_state->inp_delay = (FLOAT32 *)(p_offset); |
1632 | 6.25k | inp_delay_size = |
1633 | 6.25k | 2 * |
1634 | 6.25k | ia_enhaacplus_enc_sizeof_delay_buffer( |
1635 | 6.25k | 0, AOT_USAC, pstr_api_struct->config[0].ccfl_idx, |
1636 | 6.25k | sizeof(pstr_state->inp_delay[0]), pstr_api_struct->config[0].use_mps) * |
1637 | 6.25k | pstr_api_struct->config[0].num_bs_elements; |
1638 | 6.25k | memset(pstr_state->inp_delay, 0, inp_delay_size); |
1639 | 6.25k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(inp_delay_size, BYTE_ALIGN_8); |
1640 | 6.25k | if (1 == pstr_usac_config->sbr_enable) { |
1641 | 3.91k | if (2 != pstr_usac_config->channels) { |
1642 | 990 | pstr_api_struct->pstr_state->time_signal = (FLOAT32 *)(p_offset); |
1643 | | |
1644 | 990 | memset(pstr_api_struct->pstr_state->time_signal, 0, |
1645 | 990 | (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0])); |
1646 | 990 | offset_size = |
1647 | 990 | (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]); |
1648 | 990 | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1649 | 990 | } |
1650 | | |
1651 | 3.91k | pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[0] = |
1652 | 3.91k | (struct ixheaace_str_sbr_enc *)p_offset; |
1653 | 3.91k | p_offset = p_offset + ixheaace_sbr_enc_pers_size(pstr_usac_config->channels, 0, |
1654 | 3.91k | pstr_usac_config->sbr_harmonic); |
1655 | 3.91k | } |
1656 | 6.25k | if (1 == pstr_api_struct->config[0].use_mps) { |
1657 | 1.40k | pstr_api_struct->pstr_state->time_signal_mps = (FLOAT32 *)(p_offset); |
1658 | | |
1659 | 1.40k | memset(pstr_api_struct->pstr_state->time_signal_mps, 0, |
1660 | 1.40k | (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0])); |
1661 | 1.40k | offset_size = |
1662 | 1.40k | (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]); |
1663 | 1.40k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1664 | 1.40k | pstr_api_struct->pstr_state->mps_bs = (UWORD8 *)(p_offset); |
1665 | | |
1666 | 1.40k | memset(pstr_api_struct->pstr_state->mps_bs, 0, |
1667 | 1.40k | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0])); |
1668 | | |
1669 | 1.40k | offset_size = |
1670 | 1.40k | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]); |
1671 | 1.40k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1672 | | |
1673 | 1.40k | pstr_api_struct->pstr_state->mps_pers_mem = (ixheaace_mps_212_memory_struct *)p_offset; |
1674 | 1.40k | p_offset += |
1675 | 1.40k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8); |
1676 | 4.85k | } else { |
1677 | 4.85k | pstr_api_struct->pstr_state->mps_bs = NULL; |
1678 | 4.85k | } |
1679 | 6.25k | if (1 == pstr_usac_config->use_drc_element) { |
1680 | 1.95k | pstr_state->pp_drc_in_buf = (FLOAT32 **)((WORD8 *)p_offset); |
1681 | 1.95k | offset_size = pstr_usac_config->channels * sizeof(pstr_state->pp_drc_in_buf[0]); |
1682 | 1.95k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1683 | 1.95k | p_temp = p_offset; |
1684 | | |
1685 | 5.30k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1686 | 3.35k | pstr_state->pp_drc_in_buf[i] = (FLOAT32 *)(p_offset); |
1687 | 3.35k | p_offset += IXHEAAC_GET_SIZE_ALIGNED( |
1688 | 3.35k | (pstr_usac_config->drc_frame_size * sizeof(pstr_state->pp_drc_in_buf[0][0]) * 2), |
1689 | 3.35k | BYTE_ALIGN_8); |
1690 | 3.35k | if (pstr_usac_config->use_delay_adjustment == 1) { |
1691 | 3.30k | p_offset += IXHEAAC_GET_SIZE_ALIGNED( |
1692 | 3.30k | ((CC_DELAY_ADJUSTMENT * pstr_usac_config->drc_frame_size) / FRAME_LEN_1024) * |
1693 | 3.30k | sizeof(pstr_state->pp_drc_in_buf[0][0]), |
1694 | 3.30k | BYTE_ALIGN_8); |
1695 | 3.30k | } |
1696 | 3.35k | } |
1697 | 1.95k | memset(p_temp, 0, (p_offset - p_temp)); |
1698 | 1.95k | } |
1699 | 6.25k | p_temp = p_offset; |
1700 | | |
1701 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1702 | 10.7k | pstr_state->ptr_in_buf[i] = (FLOAT32 *)(p_offset); |
1703 | 10.7k | p_offset += IXHEAAC_GET_SIZE_ALIGNED((pstr_usac_config->ccfl * sizeof(FLOAT32) * 2), |
1704 | 10.7k | BYTE_ALIGN_8); |
1705 | 10.7k | if (pstr_usac_config->use_delay_adjustment) { |
1706 | 10.5k | p_offset += IXHEAAC_GET_SIZE_ALIGNED( |
1707 | 10.5k | ((CC_DELAY_ADJUSTMENT * pstr_usac_config->ccfl) / FRAME_LEN_1024) * |
1708 | 10.5k | sizeof(FLOAT32), |
1709 | 10.5k | BYTE_ALIGN_8); |
1710 | 10.5k | } |
1711 | 10.7k | } |
1712 | 6.25k | memset(p_temp, 0, (p_offset - p_temp)); |
1713 | | |
1714 | 6.25k | p_temp = p_offset; |
1715 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1716 | 10.7k | pstr_usac_enc_data->ptr_time_data[i] = (FLOAT64 *)(p_offset); |
1717 | 10.7k | p_offset += IXHEAAC_GET_SIZE_ALIGNED((2 * (pstr_usac_config->ccfl) * sizeof(FLOAT64)), |
1718 | 10.7k | BYTE_ALIGN_8); |
1719 | 10.7k | } |
1720 | | |
1721 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1722 | 10.7k | pstr_usac_enc_data->ptr_look_ahead_time_data[i] = (FLOAT64 *)(p_offset); |
1723 | 10.7k | p_offset += |
1724 | 10.7k | IXHEAAC_GET_SIZE_ALIGNED((pstr_usac_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8); |
1725 | 10.7k | } |
1726 | | |
1727 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1728 | 10.7k | pstr_usac_enc_data->spectral_line_vector[i] = (FLOAT64 *)(p_offset); |
1729 | 10.7k | p_offset += IXHEAAC_GET_SIZE_ALIGNED((2 * pstr_usac_config->ccfl * sizeof(FLOAT64)), |
1730 | 10.7k | BYTE_ALIGN_8); |
1731 | 10.7k | } |
1732 | | |
1733 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1734 | 10.7k | pstr_usac_enc_data->ptr_2frame_time_data[i] = (FLOAT64 *)(p_offset); |
1735 | 10.7k | p_offset += IXHEAAC_GET_SIZE_ALIGNED((3 * pstr_usac_config->ccfl * sizeof(FLOAT64)), |
1736 | 10.7k | BYTE_ALIGN_8); |
1737 | 10.7k | } |
1738 | 6.25k | memset(p_temp, 0, p_offset - p_temp); |
1739 | | |
1740 | 6.25k | if (pstr_usac_config->tns_select != 0) { |
1741 | 2.55k | p_temp = p_offset; |
1742 | 6.96k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1743 | 4.41k | pstr_usac_enc_data->pstr_tns_info[i] = (ia_tns_info *)(p_offset); |
1744 | 4.41k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_tns_info), BYTE_ALIGN_8); |
1745 | 4.41k | } |
1746 | 2.55k | memset(p_temp, 0, p_offset - p_temp); |
1747 | 2.55k | } |
1748 | | |
1749 | 6.25k | p_temp = p_offset; |
1750 | 17.0k | for (i = 0; i < pstr_usac_config->channels; i++) { |
1751 | 10.7k | pstr_usac_enc_data->td_encoder[i] = (ia_usac_td_encoder_struct *)(p_offset); |
1752 | 10.7k | p_offset += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_usac_td_encoder_struct), BYTE_ALIGN_8); |
1753 | 10.7k | } |
1754 | 6.25k | memset(p_temp, 0, p_offset - p_temp); |
1755 | 6.25k | } else { |
1756 | 3.51k | WORD32 num_aac_chan; |
1757 | 3.51k | ixheaace_state_struct *pstr_state = pstr_api_struct->pstr_state; |
1758 | 3.51k | memset(pstr_api_struct->pstr_state, 0, sizeof(*(pstr_api_struct->pstr_state))); |
1759 | | |
1760 | 3.51k | pstr_api_struct->pstr_state->inp_delay = (FLOAT32 *)((WORD8 *)pstr_state + offset_size); |
1761 | 3.51k | offset_size = ia_enhaacplus_enc_sizeof_delay_buffer( |
1762 | 3.51k | pstr_api_struct->config[0].aac_config.flag_framelength_small, |
1763 | 3.51k | pstr_api_struct->config[0].aot, 3, |
1764 | 3.51k | sizeof(pstr_api_struct->pstr_state->inp_delay[0]), |
1765 | 3.51k | pstr_api_struct->config[0].use_mps) * |
1766 | 3.51k | pstr_api_struct->config[0].num_bs_elements; |
1767 | 3.51k | p_offset = (WORD8 *)pstr_api_struct->pstr_state->inp_delay + |
1768 | 3.51k | IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1769 | | |
1770 | 3.51k | if (pstr_api_struct->config[0].use_mps) { |
1771 | 818 | pstr_api_struct->pstr_state->time_signal_mps = (FLOAT32 *)(p_offset); |
1772 | | |
1773 | 818 | memset(pstr_api_struct->pstr_state->time_signal_mps, 0, |
1774 | 818 | (MAX_INPUT_SAMPLES + (INPUT_DELAY_ELDV2_512 * IXHEAACE_MAX_CH_IN_BS_ELE)) * |
1775 | 818 | sizeof(pstr_api_struct->pstr_state->time_signal_mps[0])); |
1776 | 818 | offset_size = |
1777 | 818 | (MAX_INPUT_SAMPLES + (INPUT_DELAY_ELDV2_512 * IXHEAACE_MAX_CH_IN_BS_ELE)) * |
1778 | 818 | sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]); |
1779 | 818 | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1780 | | |
1781 | 818 | pstr_api_struct->pstr_state->mps_bs = (UWORD8 *)(p_offset); |
1782 | 818 | memset(pstr_api_struct->pstr_state->mps_bs, 0, |
1783 | 818 | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0])); |
1784 | 818 | offset_size = |
1785 | 818 | (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]); |
1786 | 818 | p_offset += IXHEAAC_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8); |
1787 | | |
1788 | 818 | if (pstr_api_struct->config[0].mps_tree_config == TREE_212) { |
1789 | 306 | pstr_api_struct->pstr_state->mps_pers_mem = |
1790 | 306 | (ixheaace_mps_212_memory_struct *)p_offset; |
1791 | 306 | p_offset += |
1792 | 306 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8); |
1793 | 512 | } else { |
1794 | 512 | pstr_api_struct->pstr_state->mps_515_pers_mem = |
1795 | 512 | (ixheaace_mps_515_memory_struct *)p_offset; |
1796 | 512 | p_offset += |
1797 | 512 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_515_memory_struct), BYTE_ALIGN_8); |
1798 | 512 | } |
1799 | 2.69k | } else { |
1800 | 2.69k | pstr_api_struct->pstr_state->mps_bs = NULL; |
1801 | 2.69k | } |
1802 | | |
1803 | 10.7k | for (WORD32 ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; |
1804 | 7.27k | ele_idx++) { |
1805 | 7.27k | num_aac_chan = pstr_api_struct->config[ele_idx].aac_classic |
1806 | 7.27k | ? pstr_api_struct->config[ele_idx].chmode_nchannels |
1807 | 7.27k | : (pstr_api_struct->config[ele_idx].use_parametric_stereo |
1808 | 4.97k | ? 1 |
1809 | 4.97k | : pstr_api_struct->config[ele_idx].chmode_nchannels); |
1810 | | |
1811 | | /* Set aac enc persistent memory pointer in api obj */ |
1812 | 7.27k | pstr_api_struct->pstr_state->aac_enc_pers_mem[ele_idx] = |
1813 | 7.27k | (iexheaac_encoder_str *)p_offset; |
1814 | 7.27k | p_offset = p_offset + ia_enhaacplus_enc_aac_enc_pers_size( |
1815 | 7.27k | num_aac_chan, pstr_api_struct->config[ele_idx].aot); |
1816 | | |
1817 | 7.27k | if (pstr_api_struct->config[ele_idx].aot != AOT_AAC_LC && |
1818 | 7.27k | pstr_api_struct->config[ele_idx].aot != AOT_AAC_LD) { |
1819 | 5.33k | if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) { |
1820 | | /* Set spectral_band_replication_ enc persistent memory pointer in api obj */ |
1821 | 4.90k | pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[ele_idx] = |
1822 | 4.90k | (struct ixheaace_str_sbr_enc *)p_offset; |
1823 | | |
1824 | 4.90k | p_offset = |
1825 | 4.90k | p_offset + |
1826 | 4.90k | ixheaace_sbr_enc_pers_size( |
1827 | 4.90k | num_aac_chan, pstr_api_struct->config[ele_idx].use_parametric_stereo, 0); |
1828 | 4.90k | } |
1829 | 5.33k | } |
1830 | 7.27k | } |
1831 | 3.51k | } |
1832 | 9.77k | } |
1833 | | |
1834 | 39.0k | if ((i_idx == IA_MEMTYPE_SCRATCH) && pstr_api_struct->usac_en) { |
1835 | 6.25k | pstr_api_struct->pstr_state->str_usac_enc_data.str_scratch.ptr_scratch_buf = |
1836 | 6.25k | (UWORD8 *)pstr_api_struct->pp_mem[IA_MEMTYPE_SCRATCH]; |
1837 | 6.25k | memset(pstr_api_struct->pp_mem[IA_MEMTYPE_SCRATCH], 0, |
1838 | 6.25k | pstr_api_struct->pstr_mem_info[i_idx].ui_size); |
1839 | 6.25k | } |
1840 | 39.0k | if (i_idx == IA_ENHAACPLUSENC_INPUT_IDX) { |
1841 | 9.77k | ptr_out_cfg->ui_inp_buf_size = ptr_out_cfg->mem_info_table[i_idx].ui_size; |
1842 | 9.77k | } |
1843 | 39.0k | ptr_out_cfg->malloc_count++; |
1844 | 39.0k | } |
1845 | 9.77k | return err_code; |
1846 | 9.77k | } |
1847 | | |
1848 | | static VOID ixheaace_write_audio_preroll_data(ixheaace_api_struct *pstr_api_struct, |
1849 | 401k | ia_bit_buf_struct *it_bit_buff) { |
1850 | 401k | ixheaace_config_struct *pstr_config = &pstr_api_struct->config[0]; |
1851 | 401k | ixheaace_state_struct *pstr_enc_state = pstr_api_struct->pstr_state; |
1852 | 401k | ia_usac_data_struct *pstr_usac_data = &pstr_enc_state->str_usac_enc_data; |
1853 | 401k | ia_usac_encoder_config_struct *pstr_usac_config = &pstr_config->usac_config; |
1854 | 401k | WORD32 i, j, padding_bits; |
1855 | | |
1856 | 401k | if (pstr_usac_config->is_ipf) { |
1857 | 15.7k | if (pstr_usac_config->iframes_interval == pstr_usac_config->num_preroll_frames) { |
1858 | 5.32k | WORD32 config_len = 0, num_bits = 0, au_len = 0, config_bits = 0; |
1859 | 5.32k | WORD32 bytes_to_write; |
1860 | 5.32k | UWORD8 *ptr_out = (UWORD8 *)pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT]; |
1861 | 5.32k | WORD32 max_output_size = |
1862 | 5.32k | ((MAX_CHANNEL_BITS / BYTE_NUMBIT) * pstr_usac_config->channels) * MAX_PREROLL_FRAMES + |
1863 | 5.32k | MAX_PREROLL_CONFIG_SIZE; |
1864 | 5.32k | UWORD8 *out_data = ptr_out + max_output_size; |
1865 | 5.32k | UWORD8 residual_bits = 0, residual_data = 0; |
1866 | 5.32k | memmove(ptr_out + max_output_size, ptr_out, pstr_enc_state->i_out_bytes); |
1867 | 5.32k | pstr_usac_config->is_ipf = 0; |
1868 | | |
1869 | 5.32k | config_bits = ixheaace_get_usac_config_bytes(NULL, &pstr_enc_state->audio_specific_config, |
1870 | 5.32k | pstr_config->ccfl_idx); |
1871 | 5.32k | config_len = (config_bits + 7) >> 3; |
1872 | 5.32k | num_bits = iusace_write_escape_value(NULL, config_len, 4, 4, 8); |
1873 | 5.32k | num_bits += (config_len * 8); // config data bits |
1874 | 5.32k | num_bits++; // apply-crossfade |
1875 | 5.32k | num_bits++; // apr-reserved |
1876 | | // bits for number of preroll frames |
1877 | 5.32k | num_bits += iusace_write_escape_value(NULL, pstr_usac_config->num_preroll_frames, 2, 4, 0); |
1878 | | // bits for au_len |
1879 | 17.4k | for (i = 0; i < pstr_usac_config->num_preroll_frames; i++) { |
1880 | 12.1k | num_bits += iusace_write_escape_value(NULL, pstr_usac_data->prev_out_bytes[i], 16, 16, 0); |
1881 | 12.1k | au_len += pstr_usac_data->prev_out_bytes[i]; |
1882 | 12.1k | } |
1883 | 5.32k | iusace_reset_bit_buffer(it_bit_buff); |
1884 | | // total bytes to write |
1885 | 5.32k | bytes_to_write = (num_bits + 7) >> 3; |
1886 | | // usacIndependencyFlag |
1887 | 5.32k | iusace_write_bits_buf(it_bit_buff, pstr_usac_data->usac_independency_flag, 1); |
1888 | 5.32k | iusace_write_bits_buf(it_bit_buff, 1, 1); // usacExtElementPresent |
1889 | 5.32k | iusace_write_bits_buf(it_bit_buff, 0, 1); // usacExtElementUseDefaultLength |
1890 | | |
1891 | 5.32k | if (au_len + bytes_to_write >= MAXIMUM_VALUE_8BIT) { |
1892 | 5.07k | iusace_write_escape_value(it_bit_buff, au_len + bytes_to_write + 2, 8, 16, 0); |
1893 | 5.07k | } else { |
1894 | 248 | iusace_write_bits_buf(it_bit_buff, au_len + bytes_to_write, 8); |
1895 | 248 | } |
1896 | | |
1897 | 5.32k | iusace_write_escape_value(it_bit_buff, config_len, 4, 4, 8); // configLen |
1898 | | // Config |
1899 | 5.32k | ixheaace_get_usac_config_bytes(it_bit_buff, &pstr_enc_state->audio_specific_config, |
1900 | 5.32k | pstr_config->ccfl_idx); |
1901 | | |
1902 | 5.32k | if (config_bits % 8) { |
1903 | 3.47k | iusace_write_bits_buf(it_bit_buff, 0, (UWORD8)((config_len << 3) - config_bits)); |
1904 | 3.47k | } |
1905 | | |
1906 | 5.32k | iusace_write_bits_buf(it_bit_buff, 0, 1); // applyCrossfade |
1907 | 5.32k | iusace_write_bits_buf(it_bit_buff, 0, 1); // apr_reserved |
1908 | | // numPreRollFrames |
1909 | 5.32k | iusace_write_escape_value(it_bit_buff, pstr_usac_config->num_preroll_frames, 2, 4, 0); |
1910 | 17.4k | for (i = 0; i < pstr_usac_config->num_preroll_frames; i++) { |
1911 | 12.1k | au_len = pstr_usac_data->prev_out_bytes[i]; |
1912 | | |
1913 | 12.1k | if (pstr_usac_config->iframes_interval != 0) { |
1914 | 12.1k | out_data = pstr_usac_data->prev_out_data[i]; |
1915 | 12.1k | } |
1916 | | |
1917 | | // auLen |
1918 | 12.1k | iusace_write_escape_value(it_bit_buff, au_len, 16, 16, 0); |
1919 | | |
1920 | | // AccessUnit |
1921 | 9.13M | for (j = 0; j < au_len; j++) { |
1922 | 9.12M | iusace_write_bits_buf(it_bit_buff, *out_data, 8); |
1923 | 9.12M | out_data++; |
1924 | 9.12M | } |
1925 | 12.1k | } |
1926 | | |
1927 | 5.32k | if (num_bits % 8) { |
1928 | 3.74k | iusace_write_bits_buf(it_bit_buff, 0, (UWORD8)((bytes_to_write << 3) - num_bits)); |
1929 | 3.74k | } |
1930 | | // current frame |
1931 | 5.32k | au_len = pstr_enc_state->i_out_bits >> 3; |
1932 | 5.32k | residual_bits = (UWORD8)(pstr_enc_state->i_out_bits - (au_len << 3)); |
1933 | 5.32k | out_data = ptr_out + max_output_size; |
1934 | 3.84M | for (j = 0; j < au_len; j++) { |
1935 | 3.84M | iusace_write_bits_buf(it_bit_buff, *out_data, 8); |
1936 | 3.84M | out_data++; |
1937 | 3.84M | } |
1938 | 5.32k | residual_data = *out_data >> (8 - residual_bits); |
1939 | 5.32k | iusace_write_bits_buf(it_bit_buff, residual_data, residual_bits); |
1940 | | |
1941 | 5.32k | padding_bits = 8 - (it_bit_buff->cnt_bits & 7); |
1942 | 5.32k | if (padding_bits > 0 && padding_bits < 8) { |
1943 | 4.64k | ptr_out[it_bit_buff->cnt_bits >> 3] = |
1944 | 4.64k | (WORD8)((UWORD32)ptr_out[it_bit_buff->cnt_bits >> 3]) & (0xFF << padding_bits); |
1945 | 4.64k | } |
1946 | 5.32k | pstr_enc_state->i_out_bytes = (it_bit_buff->cnt_bits + 7) >> 3; |
1947 | 5.32k | pstr_usac_config->preroll_idx++; |
1948 | | |
1949 | 5.32k | if (!pstr_usac_config->is_first_frame) { |
1950 | 985 | pstr_usac_config->preroll_idx = pstr_usac_config->num_preroll_frames + 1; |
1951 | 985 | } |
1952 | 5.32k | if (pstr_usac_config->is_first_frame) { |
1953 | 4.33k | pstr_usac_config->is_first_frame = 0; |
1954 | 4.33k | } |
1955 | 10.4k | } else { |
1956 | 10.4k | if (pstr_usac_config->preroll_idx < pstr_usac_config->num_preroll_frames) { |
1957 | 10.1k | WORD32 *ptr_prev_out_bytes = pstr_usac_data->prev_out_bytes; |
1958 | 10.1k | WORD32 pr_idx = pstr_usac_config->preroll_idx; |
1959 | 10.1k | UWORD8 *ptr_out = (UWORD8 *)pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT]; |
1960 | 10.1k | ptr_prev_out_bytes[pr_idx] = pstr_enc_state->i_out_bytes; |
1961 | 10.1k | memcpy(pstr_usac_data->prev_out_data[pr_idx++], ptr_out, pstr_enc_state->i_out_bytes); |
1962 | 10.1k | pstr_usac_config->preroll_idx = pr_idx; |
1963 | 10.1k | pstr_enc_state->i_out_bytes = 0; |
1964 | 10.1k | } |
1965 | 10.4k | } |
1966 | 386k | } else { |
1967 | 849k | for (j = 0; j < pstr_usac_config->num_preroll_frames - 1; j++) { |
1968 | 463k | pstr_usac_data->prev_out_bytes[j] = pstr_usac_data->prev_out_bytes[j + 1]; |
1969 | 463k | } |
1970 | 386k | if (pstr_usac_config->num_preroll_frames) { |
1971 | 386k | pstr_usac_data->prev_out_bytes[pstr_usac_config->num_preroll_frames - 1] = |
1972 | 386k | pstr_enc_state->i_out_bytes; |
1973 | 386k | } |
1974 | 386k | pstr_usac_config->preroll_idx = pstr_usac_config->num_preroll_frames + 1; |
1975 | 386k | } |
1976 | 401k | return; |
1977 | 401k | } |
1978 | | |
1979 | 6.25k | static IA_ERRORCODE ia_usac_enc_init(ixheaace_api_struct *pstr_api_struct, WORD32 ccfl_idx) { |
1980 | 6.25k | IA_ERRORCODE error = IA_NO_ERROR; |
1981 | 6.25k | WORD32 i = 0; |
1982 | 6.25k | ixheaace_config_struct *pstr_config = &pstr_api_struct->config[0]; |
1983 | 6.25k | ixheaace_state_struct *pstr_enc_state = pstr_api_struct->pstr_state; |
1984 | 6.25k | ia_usac_data_struct *pstr_enc_data = &pstr_enc_state->str_usac_enc_data; |
1985 | 6.25k | ia_usac_encoder_config_struct *pstr_usac_config = &pstr_config->usac_config; |
1986 | | |
1987 | 6.25k | pstr_usac_config->bit_rate = pstr_api_struct->config[0].aac_config.bit_rate; |
1988 | | |
1989 | 6.25k | if ((pstr_usac_config->codec_mode == USAC_SWITCHED) || |
1990 | 6.25k | (pstr_usac_config->codec_mode == USAC_ONLY_FD)) { |
1991 | 5.96k | pstr_usac_config->aac_allow_scalefacs = 1; |
1992 | 5.96k | if (pstr_usac_config->aac_scale_facs == 0) pstr_usac_config->aac_allow_scalefacs = 0; |
1993 | 5.96k | } |
1994 | | |
1995 | 6.25k | if (pstr_usac_config->codec_mode == USAC_ONLY_TD) { |
1996 | 839 | for (i = 0; i < pstr_config->i_channels; i++) { |
1997 | 548 | pstr_enc_data->core_mode_prev[i] = CORE_MODE_FD; |
1998 | 548 | pstr_enc_data->core_mode[i] = CORE_MODE_TD; |
1999 | 548 | } |
2000 | 5.96k | } else { |
2001 | 16.1k | for (i = 0; i < pstr_config->i_channels; i++) { |
2002 | 10.2k | pstr_enc_data->core_mode_prev[i] = CORE_MODE_FD; |
2003 | 10.2k | pstr_enc_data->core_mode[i] = CORE_MODE_FD; |
2004 | 10.2k | } |
2005 | 5.96k | } |
2006 | | |
2007 | 6.25k | if (1 == pstr_usac_config->use_drc_element) { |
2008 | 1.95k | pstr_enc_data->str_scratch.drc_scratch = pstr_enc_data->str_scratch.ptr_scratch_buf; |
2009 | 1.95k | } |
2010 | 6.25k | if (pstr_usac_config->sbr_enable) { |
2011 | 3.91k | WORD8 *sbr_scr_ptr = (WORD8 *)pstr_enc_data->str_scratch.ptr_scratch_buf; |
2012 | 3.91k | ixheaace_audio_specific_config_struct *pstr_asc = &pstr_enc_state->audio_specific_config; |
2013 | 3.91k | ixheaace_str_sbr_cfg spectral_band_replication_config; |
2014 | | // SBR defaults |
2015 | 3.91k | iaace_config *pstr_sbr_config = &(pstr_api_struct->config[0].aac_config); |
2016 | 3.91k | WORD32 sbr_ratio = 0; |
2017 | 3.91k | WORD32 samples = pstr_usac_config->ccfl; |
2018 | | // Set scratch buffers for SBR and resampler |
2019 | 3.91k | pstr_api_struct->pstr_state->temp_buff_sbr = |
2020 | 3.91k | (WORD8 *)pstr_enc_data->str_scratch.ptr_scratch_buf; |
2021 | 3.91k | pstr_api_struct->pstr_state->ptr_temp_buff_resamp = |
2022 | 3.91k | (WORD8 *)pstr_enc_data->str_scratch.ptr_scratch_buf + ixheaace_sbr_enc_scr_size(); |
2023 | | |
2024 | 3.91k | ixheaace_initialize_sbr_defaults(&spectral_band_replication_config); |
2025 | | // Set SBR codec as USAC |
2026 | 3.91k | spectral_band_replication_config.sbr_codec = USAC_SBR; |
2027 | 3.91k | spectral_band_replication_config.sbr_pvc_active = pstr_usac_config->sbr_pvc_active; |
2028 | 3.91k | spectral_band_replication_config.sbr_harmonic = pstr_usac_config->sbr_harmonic; |
2029 | 3.91k | spectral_band_replication_config.hq_esbr = pstr_usac_config->hq_esbr; |
2030 | 3.91k | pstr_usac_config->core_sample_rate = pstr_usac_config->sample_rate / 2; |
2031 | 3.91k | switch (pstr_usac_config->ccfl_idx) { |
2032 | 862 | case SBR_4_1: |
2033 | 862 | spectral_band_replication_config.sbr_ratio_idx = USAC_SBR_RATIO_INDEX_4_1; |
2034 | 862 | spectral_band_replication_config.sbr_pvc_rate = USAC_SBR_DOWNSAMPLE_RATIO_4_1; |
2035 | 862 | pstr_usac_config->core_sample_rate = pstr_usac_config->sample_rate / 4; |
2036 | 862 | sbr_ratio = 4; |
2037 | 862 | samples *= 4; |
2038 | 862 | break; |
2039 | 577 | case SBR_8_3: |
2040 | 577 | spectral_band_replication_config.sbr_ratio_idx = USAC_SBR_RATIO_INDEX_8_3; |
2041 | 577 | spectral_band_replication_config.sbr_pvc_rate = USAC_SBR_DOWNSAMPLE_RATIO_2_1; |
2042 | 577 | sbr_ratio = 2; |
2043 | 577 | samples *= 8; |
2044 | 577 | samples /= 3; |
2045 | 577 | break; |
2046 | 2.47k | case SBR_2_1: |
2047 | 2.47k | spectral_band_replication_config.sbr_ratio_idx = USAC_SBR_RATIO_INDEX_2_1; |
2048 | 2.47k | spectral_band_replication_config.sbr_pvc_rate = USAC_SBR_DOWNSAMPLE_RATIO_2_1; |
2049 | 2.47k | sbr_ratio = 2; |
2050 | 2.47k | samples *= 2; |
2051 | 2.47k | break; |
2052 | 0 | default: |
2053 | 0 | spectral_band_replication_config.sbr_ratio_idx = USAC_SBR_RATIO_NO_SBR; |
2054 | 0 | spectral_band_replication_config.sbr_pvc_rate = 2; |
2055 | 0 | sbr_ratio = 2; |
2056 | 0 | break; |
2057 | 3.91k | } |
2058 | 3.91k | if (pstr_api_struct->pstr_state->mps_enable) { |
2059 | 1.27k | ixheaace_mps_212_memory_struct *pstr_mps_memory; |
2060 | 1.27k | pstr_mps_memory = pstr_api_struct->pstr_state->mps_pers_mem; |
2061 | 1.27k | ixheaace_mps_212_open(&pstr_api_struct->pstr_mps_212_enc, pstr_mps_memory); |
2062 | 1.27k | pstr_asc->str_aac_config.num_sac_cfg_bits = 0; |
2063 | | |
2064 | 1.27k | error = ixheaace_mps_212_initialise( |
2065 | 1.27k | pstr_api_struct->pstr_mps_212_enc, AOT_USAC, pstr_usac_config->sample_rate, |
2066 | 1.27k | &pstr_sbr_config->bit_rate, sbr_ratio, (WORD32)samples, samples, 515 * sbr_ratio, |
2067 | 1.27k | (WORD8 *)pstr_api_struct->pstr_state->ptr_temp_buff_resamp); |
2068 | 1.27k | if (error) { |
2069 | 41 | return error; |
2070 | 41 | } |
2071 | | |
2072 | 1.23k | pstr_asc->str_aac_config.num_sac_cfg_bits = ixheaace_mps_212_get_spatial_specific_config( |
2073 | 1.23k | pstr_api_struct->pstr_mps_212_enc, (WORD8 *)pstr_asc->str_aac_config.sac_cfg_data, |
2074 | 1.23k | sizeof(pstr_asc->str_aac_config.sac_cfg_data), AOT_USAC); |
2075 | 1.23k | } |
2076 | 3.87k | ixheaace_adjust_sbr_settings( |
2077 | 3.87k | &spectral_band_replication_config, pstr_sbr_config->bit_rate, |
2078 | 3.87k | (pstr_api_struct->pstr_state->mps_enable != 1) ? pstr_config->i_channels : 1, |
2079 | 3.87k | pstr_usac_config->core_sample_rate, AACENC_TRANS_FAC, 24000, |
2080 | 3.87k | pstr_api_struct->spectral_band_replication_tabs.ptr_qmf_tab, |
2081 | 3.87k | pstr_api_struct->pstr_state->aot, (pstr_api_struct->config[0].ccfl_idx == SBR_4_1)); |
2082 | | |
2083 | 3.87k | error = ixheaace_env_open( |
2084 | 3.87k | &pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[0], |
2085 | 3.87k | &spectral_band_replication_config, &pstr_sbr_config->band_width, sbr_scr_ptr, |
2086 | 3.87k | &(pstr_api_struct->spectral_band_replication_tabs), &pstr_asc->str_aac_config.sbr_config); |
2087 | 3.87k | if (error) { |
2088 | 39 | return error; |
2089 | 39 | } |
2090 | | |
2091 | 3.83k | if (pstr_api_struct->config[0].ccfl_idx >= 2) { |
2092 | 3.83k | pstr_api_struct->pstr_state->downsample[0] = 1; |
2093 | 3.83k | } else { |
2094 | 0 | pstr_api_struct->pstr_state->downsample[0] = 0; |
2095 | 0 | } |
2096 | | |
2097 | 3.83k | if (pstr_api_struct->pstr_state->downsample[0]) { |
2098 | 3.83k | IA_ERRORCODE resamp_error = IA_NO_ERROR; |
2099 | 3.83k | WORD32 resamp_ratio = 0, upsamp_fac = 0, downsamp_fac = 0; |
2100 | 3.83k | WORD32 ele_idx = 0, ch_idx = 0; |
2101 | | |
2102 | 3.83k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
2103 | 577 | upsamp_fac = 3; |
2104 | 577 | downsamp_fac = 8; |
2105 | 577 | pstr_usac_config->sample_rate /= 2; |
2106 | 3.25k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_2_1) { |
2107 | 2.40k | resamp_ratio = 2; |
2108 | 2.40k | pstr_usac_config->sample_rate /= 2; |
2109 | 2.40k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_4_1) { |
2110 | 855 | resamp_ratio = 4; |
2111 | 855 | pstr_usac_config->sample_rate /= 4; |
2112 | 855 | } |
2113 | | |
2114 | 3.83k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
2115 | 577 | if (upsamp_fac != 3 || downsamp_fac != 8) { |
2116 | 0 | return IA_EXHEAACE_CONFIG_FATAL_USAC_RESAMPLER_RATIO; |
2117 | 0 | } |
2118 | 3.25k | } else { |
2119 | 3.25k | if (resamp_ratio != 2 && resamp_ratio != 4) { |
2120 | 0 | return IA_EXHEAACE_CONFIG_FATAL_USAC_RESAMPLER_RATIO; |
2121 | 0 | } |
2122 | 3.25k | } |
2123 | 3.83k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { // Upsampler initialization |
2124 | 577 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2125 | 577 | &(pstr_api_struct->pstr_state->up_sampler[ele_idx][ch_idx]), upsamp_fac, |
2126 | 577 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_upsamp_tab); |
2127 | 577 | if (resamp_error) { |
2128 | 0 | return resamp_error; |
2129 | 0 | } |
2130 | 577 | if (pstr_api_struct->config[0].i_channels > 1) { |
2131 | 370 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2132 | 370 | &(pstr_api_struct->pstr_state->up_sampler[ele_idx][ch_idx + 1]), upsamp_fac, |
2133 | 370 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_upsamp_tab); |
2134 | 370 | if (resamp_error) { |
2135 | 0 | return resamp_error; |
2136 | 0 | } |
2137 | 370 | } |
2138 | 577 | if (pstr_usac_config->sbr_harmonic) { |
2139 | 0 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2140 | 0 | &(pstr_api_struct->pstr_state->hbe_up_sampler[ele_idx][ch_idx]), upsamp_fac, |
2141 | 0 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_upsamp_tab); |
2142 | 0 | if (resamp_error) { |
2143 | 0 | return resamp_error; |
2144 | 0 | } |
2145 | 0 | if (pstr_api_struct->config[0].i_channels > 1) { |
2146 | 0 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2147 | 0 | &(pstr_api_struct->pstr_state->hbe_up_sampler[ele_idx][ch_idx + 1]), upsamp_fac, |
2148 | 0 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_upsamp_tab); |
2149 | 0 | if (resamp_error) { |
2150 | 0 | return resamp_error; |
2151 | 0 | } |
2152 | 0 | } |
2153 | 0 | } |
2154 | | // Downsampler initialization |
2155 | 577 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2156 | 577 | &(pstr_api_struct->pstr_state->down_samp_sos[ele_idx][ch_idx]), downsamp_fac, |
2157 | 577 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_downsamp_tab); |
2158 | 577 | if (resamp_error) { |
2159 | 0 | return resamp_error; |
2160 | 0 | } |
2161 | 577 | if (pstr_api_struct->config[0].i_channels > 1) { |
2162 | 370 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2163 | 370 | &(pstr_api_struct->pstr_state->down_samp_sos[ele_idx][ch_idx + 1]), downsamp_fac, |
2164 | 370 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_downsamp_tab); |
2165 | 370 | if (resamp_error) { |
2166 | 0 | return resamp_error; |
2167 | 0 | } |
2168 | 370 | } |
2169 | 577 | if (pstr_usac_config->sbr_harmonic) { |
2170 | 0 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2171 | 0 | &(pstr_api_struct->pstr_state->hbe_down_samp_sos[ele_idx][ch_idx]), downsamp_fac, |
2172 | 0 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_downsamp_tab); |
2173 | 0 | if (resamp_error) { |
2174 | 0 | return resamp_error; |
2175 | 0 | } |
2176 | 0 | if (pstr_api_struct->config[0].i_channels > 1) { |
2177 | 0 | resamp_error = ia_enhaacplus_enc_init_iir_sos_resampler( |
2178 | 0 | &(pstr_api_struct->pstr_state->hbe_down_samp_sos[ele_idx][ch_idx + 1]), |
2179 | 0 | downsamp_fac, |
2180 | 0 | pstr_api_struct->spectral_band_replication_tabs.ptr_sos_downsamp_tab); |
2181 | 0 | if (resamp_error) { |
2182 | 0 | return resamp_error; |
2183 | 0 | } |
2184 | 0 | } |
2185 | 0 | } |
2186 | 3.25k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_2_1 || |
2187 | 3.25k | pstr_api_struct->config[0].ccfl_idx == SBR_4_1) { |
2188 | 3.25k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2189 | 3.25k | &(pstr_api_struct->pstr_state->down_sampler[ele_idx][ch_idx]), resamp_ratio, |
2190 | 3.25k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2191 | 3.25k | if (resamp_error) { |
2192 | 0 | return resamp_error; |
2193 | 0 | } |
2194 | 3.25k | if (pstr_api_struct->config[0].i_channels > 1) { |
2195 | 2.50k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2196 | 2.50k | &(pstr_api_struct->pstr_state->down_sampler[ele_idx][ch_idx + 1]), resamp_ratio, |
2197 | 2.50k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2198 | 2.50k | if (resamp_error) { |
2199 | 0 | return resamp_error; |
2200 | 0 | } |
2201 | 2.50k | } |
2202 | 3.25k | if (pstr_usac_config->sbr_harmonic) { |
2203 | 1.65k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2204 | 1.65k | &(pstr_api_struct->pstr_state->hbe_down_sampler[ele_idx][ch_idx]), resamp_ratio, |
2205 | 1.65k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2206 | 1.65k | if (resamp_error) { |
2207 | 0 | return resamp_error; |
2208 | 0 | } |
2209 | 1.65k | if (pstr_api_struct->config[0].i_channels > 1) { |
2210 | 1.57k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2211 | 1.57k | &(pstr_api_struct->pstr_state->hbe_down_sampler[ele_idx][ch_idx + 1]), |
2212 | 1.57k | resamp_ratio, pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2213 | 1.57k | if (resamp_error) { |
2214 | 0 | return resamp_error; |
2215 | 0 | } |
2216 | 1.57k | } |
2217 | 1.65k | } |
2218 | 3.25k | } |
2219 | 3.83k | } |
2220 | 3.83k | } |
2221 | | |
2222 | 6.17k | error = iusace_enc_init(pstr_usac_config, &pstr_api_struct->pstr_state->audio_specific_config, |
2223 | 6.17k | &pstr_api_struct->pstr_state->str_usac_enc_data); |
2224 | 6.17k | if (error & IA_FATAL_ERROR) { |
2225 | 1.29k | return error; |
2226 | 1.29k | } |
2227 | 4.88k | pstr_api_struct->pstr_state->str_usac_enc_data.frame_count = 0; |
2228 | 4.88k | pstr_usac_config->is_ipf = 1; |
2229 | 4.88k | pstr_enc_data->stereo_config_index = (pstr_enc_state->mps_enable == 1) ? 2 : 0; |
2230 | 4.88k | ia_bit_buf_struct *pstr_ia_asc_bit_buf; |
2231 | 4.88k | pstr_ia_asc_bit_buf = iusace_create_bit_buffer( |
2232 | 4.88k | &(pstr_api_struct->pstr_state->str_bit_buf), pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT], |
2233 | 4.88k | pstr_api_struct->pstr_mem_info[IA_MEMTYPE_OUTPUT].ui_size, 1); |
2234 | 4.88k | if (pstr_usac_config->sbr_enable) { |
2235 | 12.4k | for (UWORD32 idx = 0; idx < pstr_usac_config->num_elements; idx++) { |
2236 | 9.34k | switch (pstr_enc_state->audio_specific_config.str_usac_config.usac_element_type[idx]) { |
2237 | 724 | case ID_USAC_SCE: |
2238 | 3.07k | case ID_USAC_CPE: |
2239 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2240 | 3.07k | .stereo_config_index = pstr_enc_data->stereo_config_index; |
2241 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2242 | 3.07k | .str_usac_sbr_config.bs_inter_tes = pstr_usac_config->sbr_inter_tes_active; |
2243 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2244 | 3.07k | .str_usac_sbr_config.bs_pvc = pstr_usac_config->sbr_pvc_active; |
2245 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2246 | 3.07k | .str_usac_sbr_config.dflt_header_extra1 = 0; |
2247 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2248 | 3.07k | .str_usac_sbr_config.dflt_header_extra2 = 0; |
2249 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2250 | 3.07k | .str_usac_sbr_config.dflt_start_freq = 0; |
2251 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2252 | 3.07k | .str_usac_sbr_config.dflt_stop_freq = 4; |
2253 | 3.07k | pstr_enc_state->audio_specific_config.str_usac_config.str_usac_element_config[idx] |
2254 | 3.07k | .str_usac_sbr_config.harmonic_sbr = pstr_usac_config->sbr_harmonic; |
2255 | 3.07k | break; |
2256 | 6.26k | default: |
2257 | 6.26k | continue; |
2258 | 9.34k | } |
2259 | 9.34k | } |
2260 | 3.07k | } |
2261 | | |
2262 | 4.88k | ixheaace_get_audiospecific_config_bytes(pstr_ia_asc_bit_buf, |
2263 | 4.88k | &pstr_api_struct->pstr_state->audio_specific_config, |
2264 | 4.88k | AOT_USAC, ccfl_idx); |
2265 | 4.88k | pstr_api_struct->pstr_state->i_out_bytes = (pstr_ia_asc_bit_buf->cnt_bits + 7) >> 3; |
2266 | | |
2267 | 4.88k | return IA_NO_ERROR; |
2268 | 4.88k | } |
2269 | | |
2270 | 7.25k | static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, WORD32 ele_idx) { |
2271 | 7.25k | IA_ERRORCODE error = IA_NO_ERROR; |
2272 | 7.25k | WORD32 anc_flag = 0; |
2273 | 7.25k | WORD32 anc_rate = -1; |
2274 | 7.25k | WORD32 anc_mode = 0; |
2275 | 7.25k | WORD32 core_ch; |
2276 | 7.25k | WORD32 asc_channels; |
2277 | 7.25k | WORD8 *ptr_resampler_scratch; |
2278 | 7.25k | iaace_scratch *pstr_aac_scratch; |
2279 | 7.25k | WORD8 *ptr_spectral_band_replication_scratch; |
2280 | 7.25k | UWORD32 core_sample_rate; |
2281 | 7.25k | ixheaace_state_struct *pstr_enc_state = pstr_api_struct->pstr_state; |
2282 | 7.25k | ixheaace_audio_specific_config_struct *pstr_asc = &pstr_enc_state->audio_specific_config; |
2283 | | |
2284 | 7.25k | iaace_config *pstr_aac_config = &(pstr_api_struct->config[ele_idx].aac_config); |
2285 | | |
2286 | 7.25k | ixheaace_config_ancillary *pstr_ancillary = &(pstr_api_struct->config[ele_idx].pstr_ancillary); |
2287 | 7.25k | pstr_aac_scratch = (iaace_scratch *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX]; |
2288 | 7.25k | ptr_spectral_band_replication_scratch = |
2289 | 7.25k | ((pWORD8)pstr_aac_scratch) + ia_enhaacplus_enc_aac_enc_scr_size(); |
2290 | 7.25k | ptr_resampler_scratch = ((pWORD8)pstr_aac_scratch) + ia_enhaacplus_enc_aac_enc_scr_size() + |
2291 | 7.25k | ixheaace_sbr_enc_scr_size(); |
2292 | | |
2293 | | /* fill pstr_ancillary data */ |
2294 | 7.25k | pstr_ancillary->anc_flag = anc_flag; |
2295 | 7.25k | pstr_ancillary->anc_mode = anc_mode; |
2296 | 7.25k | pstr_ancillary->anc_rate = anc_rate; |
2297 | 7.25k | pstr_api_struct->pstr_state->temp_buff_aac = |
2298 | 7.25k | (void *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX]; |
2299 | 7.25k | pstr_api_struct->pstr_state->temp_buff_sbr = |
2300 | 7.25k | (void *)((WORD8 *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX] + |
2301 | 7.25k | ia_enhaacplus_enc_aac_enc_scr_size()); |
2302 | | |
2303 | 7.25k | if (pstr_api_struct->config[ele_idx].use_mps && |
2304 | 7.25k | pstr_api_struct->config[ele_idx].mps_tree_config != TREE_212) { |
2305 | 575 | pstr_api_struct->pstr_state->mps_scratch = |
2306 | 575 | (FLOAT32 *)((WORD8 *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX] + |
2307 | 575 | ia_enhaacplus_enc_aac_enc_scr_size()); |
2308 | | |
2309 | 575 | pstr_api_struct->pstr_state->ptr_temp_buff_resamp = |
2310 | 575 | (void *)((WORD8 *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX] + |
2311 | 575 | ia_enhaacplus_enc_aac_enc_scr_size() + ixheaace_sbr_enc_scr_size()); |
2312 | 6.67k | } else { |
2313 | 6.67k | pstr_api_struct->pstr_state->ptr_temp_buff_resamp = |
2314 | 6.67k | (void *)((WORD8 *)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX] + |
2315 | 6.67k | ia_enhaacplus_enc_aac_enc_scr_size() + ixheaace_sbr_enc_scr_size()); |
2316 | 6.67k | } |
2317 | | |
2318 | 7.25k | if (pstr_api_struct->config[ele_idx].chmode_nchannels == 2) { |
2319 | | /* When the chmode option is not used, |
2320 | | the number of channels depends on the input file */ |
2321 | 3.69k | pstr_api_struct->config[ele_idx].chmode_nchannels = |
2322 | 3.69k | pstr_api_struct->config[ele_idx].i_channels; |
2323 | 3.69k | } |
2324 | | |
2325 | 7.25k | switch (pstr_api_struct->pstr_state->aot) { |
2326 | 1.63k | case AOT_AAC_LC: |
2327 | 4.26k | case AOT_SBR: |
2328 | 4.62k | case AOT_PS: |
2329 | 4.62k | pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_LC; |
2330 | 4.62k | break; |
2331 | | |
2332 | 664 | case AOT_AAC_LD: |
2333 | 664 | if (pstr_aac_config->flag_framelength_small == 1) { |
2334 | 265 | pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_LD_480; |
2335 | 399 | } else { |
2336 | 399 | pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_LD_512; |
2337 | 399 | } |
2338 | 664 | break; |
2339 | | |
2340 | 1.96k | case AOT_AAC_ELD: |
2341 | 1.96k | if (pstr_aac_config->flag_framelength_small == 1) { |
2342 | 992 | pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_ELD_480; |
2343 | 992 | } else { |
2344 | 976 | pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_ELD_512; |
2345 | 976 | } |
2346 | 1.96k | break; |
2347 | 7.25k | } |
2348 | 7.25k | pstr_api_struct->pstr_state->downsample[ele_idx] = 0; |
2349 | 7.25k | pstr_api_struct->config->frame_count = 0; |
2350 | 7.25k | core_ch = pstr_api_struct->config[ele_idx].chmode_nchannels; |
2351 | 7.25k | pstr_aac_config->sample_rate = pstr_api_struct->config[ele_idx].sample_rate; |
2352 | 7.25k | pstr_aac_config->core_sample_rate = pstr_api_struct->config[ele_idx].sample_rate; |
2353 | 7.25k | pstr_aac_config->native_sample_rate = pstr_api_struct->config[ele_idx].native_sample_rate; |
2354 | 7.25k | pstr_aac_config->num_in_channels = pstr_api_struct->config[ele_idx].i_channels; |
2355 | 7.25k | pstr_aac_config->num_out_channels = pstr_api_struct->config[ele_idx].chmode_nchannels; |
2356 | 7.25k | if (pstr_api_struct->config[ele_idx].aac_classic == 0) { |
2357 | 4.95k | pstr_aac_config->core_sample_rate = pstr_aac_config->core_sample_rate / 2; |
2358 | 4.95k | } |
2359 | 7.25k | if (pstr_api_struct->pstr_state->mps_enable) { |
2360 | 793 | switch (pstr_api_struct->pstr_state->mps_tree_config) { |
2361 | 302 | case TREE_212: |
2362 | 484 | case TREE_5151: |
2363 | 525 | case TREE_5152: |
2364 | 525 | pstr_aac_config->num_out_channels = 1; |
2365 | 525 | core_ch = 1; |
2366 | 525 | break; |
2367 | | |
2368 | 268 | case TREE_525: |
2369 | 268 | pstr_aac_config->num_out_channels = 2; |
2370 | 268 | core_ch = 2; |
2371 | 268 | break; |
2372 | 793 | } |
2373 | 793 | } |
2374 | | |
2375 | 7.25k | if (pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2376 | 356 | pstr_api_struct->config[ele_idx].chmode_nchannels = 2; |
2377 | 356 | pstr_aac_config->num_out_channels = 1; |
2378 | 356 | core_ch = 1; |
2379 | 356 | pstr_api_struct->config[ele_idx].element_type = ID_SCE; |
2380 | 356 | } |
2381 | 7.25k | if ((pstr_api_struct->config[ele_idx].i_channels == 2) && |
2382 | 7.25k | (pstr_api_struct->config[ele_idx].chmode == 0)) { |
2383 | 0 | pstr_api_struct->config[ele_idx].chmode_nchannels = 1; |
2384 | 0 | pstr_aac_config->num_out_channels = 1; |
2385 | 0 | } |
2386 | 7.25k | if ((pstr_api_struct->config[ele_idx].use_parametric_stereo) && |
2387 | 7.25k | (pstr_api_struct->config[ele_idx].aac_classic)) { |
2388 | 0 | return (IA_EXHEAACE_CONFIG_FATAL_AAC_CLASSIC_WITH_PS); |
2389 | 0 | } |
2390 | | |
2391 | 7.25k | if (!(pstr_api_struct->config[ele_idx].adts_flag) && |
2392 | 7.25k | (pstr_api_struct->config[0].aac_config.calc_crc)) { |
2393 | | // set here default for crc as 0 |
2394 | 0 | pstr_api_struct->config[0].aac_config.calc_crc = 0; |
2395 | 0 | return (IA_EXHEAACE_CONFIG_NONFATAL_INVALID_CONFIG); |
2396 | 0 | } |
2397 | | |
2398 | 7.25k | if ((pstr_api_struct->config[0].chmode == 3) && |
2399 | 7.25k | (pstr_api_struct->config[0].aac_config.calc_crc == 1)) { |
2400 | | // dual mono case so crc if enabled must be disabled |
2401 | 0 | pstr_api_struct->config[0].aac_config.calc_crc = 0; |
2402 | 0 | return (IA_EXHEAACE_CONFIG_NONFATAL_INVALID_CONFIG); |
2403 | 0 | } |
2404 | | |
2405 | 7.25k | pstr_aac_config->bit_rate = ixheaac_min32(360000 * core_ch, pstr_aac_config->bit_rate); |
2406 | 7.25k | pstr_aac_config->bit_rate = ixheaac_max32(8000 * core_ch, pstr_aac_config->bit_rate); |
2407 | 7.25k | switch (pstr_api_struct->pstr_state->aot) { |
2408 | 1.63k | case AOT_AAC_LC: |
2409 | 4.26k | case AOT_SBR: |
2410 | 4.62k | case AOT_PS: |
2411 | 4.62k | pstr_aac_config->bit_rate = ia_enhaacplus_aac_limitbitrate( |
2412 | 4.62k | pstr_aac_config->core_sample_rate, |
2413 | 4.62k | (pstr_aac_config->flag_framelength_small ? FRAME_LEN_960 : FRAME_LEN_1024), core_ch, |
2414 | 4.62k | pstr_aac_config->bit_rate); |
2415 | 4.62k | break; |
2416 | | |
2417 | 664 | case AOT_AAC_LD: |
2418 | 2.63k | case AOT_AAC_ELD: |
2419 | 2.63k | pstr_aac_config->bit_rate = ia_enhaacplus_aac_limitbitrate( |
2420 | 2.63k | pstr_aac_config->core_sample_rate, |
2421 | 2.63k | (pstr_aac_config->flag_framelength_small ? FRAME_LEN_480 : FRAME_LEN_512), core_ch, |
2422 | 2.63k | pstr_aac_config->bit_rate); |
2423 | 2.63k | break; |
2424 | 7.25k | } |
2425 | 7.25k | if (pstr_api_struct->config[ele_idx].eldsbr_found == 1) { |
2426 | 4.95k | WORD32 num_iter = 0; |
2427 | 4.95k | WORD32 initial_bitrate, adjusted_bitrate; |
2428 | 4.95k | adjusted_bitrate = pstr_aac_config->bit_rate; |
2429 | | |
2430 | | /* Find total bitrate which provides valid configuration for each SBR element. */ |
2431 | 5.70k | do { |
2432 | 5.70k | WORD32 e; |
2433 | 5.70k | WORD32 q_format; |
2434 | 5.70k | initial_bitrate = adjusted_bitrate; |
2435 | | |
2436 | 16.9k | for (e = 0; e < pstr_api_struct->config[ele_idx].num_bs_elements; e++) { |
2437 | 12.7k | WORD32 sbr_element_bitate_in, sbr_bitrate_out; |
2438 | | |
2439 | 12.7k | sbr_element_bitate_in = pstr_aac_config->bit_rate; |
2440 | 12.7k | sbr_bitrate_out = ixheaace_sbr_limit_bitrate( |
2441 | 12.7k | sbr_element_bitate_in, core_ch, pstr_aac_config->core_sample_rate, |
2442 | 12.7k | pstr_api_struct->spectral_band_replication_tabs.ptr_qmf_tab, |
2443 | 12.7k | pstr_api_struct->pstr_state->aot); |
2444 | | |
2445 | 12.7k | if (sbr_bitrate_out == 0) { |
2446 | 0 | pstr_aac_config->bit_rate = 0; |
2447 | 0 | } |
2448 | | |
2449 | | /* If bitrates don't match, distribution and limiting needs to be determined again. |
2450 | | Abort element loop and restart with adapted bitrate. */ |
2451 | 12.7k | if (sbr_element_bitate_in != sbr_bitrate_out) { |
2452 | 1.50k | if (sbr_element_bitate_in < sbr_bitrate_out) { |
2453 | 1.50k | adjusted_bitrate = ixheaac_max32( |
2454 | 1.50k | initial_bitrate, |
2455 | 1.50k | (WORD32)ixheaac_div32((WORD32)(sbr_bitrate_out + 8), MAX_32, &q_format)); |
2456 | 1.50k | adjusted_bitrate = adjusted_bitrate >> (q_format - 31); |
2457 | 1.50k | break; |
2458 | 1.50k | } |
2459 | | |
2460 | 0 | if (sbr_element_bitate_in > sbr_bitrate_out) { |
2461 | 0 | adjusted_bitrate = ixheaac_min32( |
2462 | 0 | initial_bitrate, |
2463 | 0 | (WORD32)ixheaac_div32((WORD32)(sbr_bitrate_out - 8), MAX_32, &q_format)); |
2464 | 0 | break; |
2465 | 0 | } |
2466 | |
|
2467 | 0 | } /* sbr_element_bitate_in != sbr_bitrate_out */ |
2468 | | |
2469 | 12.7k | } /* elements */ |
2470 | | |
2471 | 5.70k | num_iter++; /* restrict iteration to worst case of num elements */ |
2472 | | |
2473 | 5.70k | } while ((initial_bitrate != adjusted_bitrate) && |
2474 | 5.70k | (num_iter <= pstr_api_struct->config[ele_idx].num_bs_elements)); |
2475 | | |
2476 | | /* Unequal bitrates mean that no reasonable bitrate configuration found. */ |
2477 | 4.95k | pstr_aac_config->bit_rate = (initial_bitrate == adjusted_bitrate) ? adjusted_bitrate : 0; |
2478 | 4.95k | } |
2479 | | |
2480 | 7.25k | pstr_asc->str_aac_config.frame_length_flag = pstr_aac_config->flag_framelength_small; |
2481 | 7.25k | pstr_asc->sampling_frequency = pstr_api_struct->config[0].native_sample_rate; |
2482 | 7.25k | asc_channels = pstr_api_struct->config[ele_idx].i_channels_mode; |
2483 | 7.25k | pstr_asc->channel_configuration = |
2484 | 7.25k | (pstr_api_struct->pstr_state->mps_enable ? core_ch : asc_channels); |
2485 | 7.25k | pstr_asc->channel_configuration = |
2486 | 7.25k | pstr_api_struct->config[ele_idx].use_parametric_stereo |
2487 | 7.25k | ? 1 |
2488 | 7.25k | : (pstr_api_struct->pstr_state->mps_enable |
2489 | 6.89k | ? core_ch |
2490 | 6.89k | : pstr_api_struct->config[ele_idx].i_channels_mode); |
2491 | | |
2492 | 7.25k | if (!(pstr_api_struct->config[ele_idx].aac_classic) && |
2493 | 7.25k | ixheaace_is_sbr_setting_available( |
2494 | 4.95k | pstr_aac_config->bit_rate, |
2495 | 4.95k | (pstr_api_struct->pstr_state->mps_enable |
2496 | 4.95k | ? 1 |
2497 | 4.95k | : pstr_api_struct->config[ele_idx].chmode_nchannels), |
2498 | 4.95k | pstr_aac_config->sample_rate, &core_sample_rate, |
2499 | 4.95k | pstr_api_struct->spectral_band_replication_tabs.ptr_qmf_tab, |
2500 | 4.95k | pstr_api_struct->pstr_state->aot)) { |
2501 | 4.91k | ixheaace_str_sbr_cfg spectral_band_replication_config; |
2502 | 4.91k | ixheaace_initialize_sbr_defaults(&spectral_band_replication_config); |
2503 | | |
2504 | 4.91k | spectral_band_replication_config.use_ps = |
2505 | 4.91k | pstr_api_struct->config[ele_idx].use_parametric_stereo; |
2506 | 4.91k | spectral_band_replication_config.crc_sbr = 0; |
2507 | 4.91k | spectral_band_replication_config.parametric_coding = 1; |
2508 | 4.91k | spectral_band_replication_config.is_esbr = pstr_api_struct->config[0].esbr_flag; |
2509 | 4.91k | if (pstr_api_struct->pstr_state->aot == AOT_AAC_ELD) { |
2510 | 1.95k | spectral_band_replication_config.is_ld_sbr = 1; |
2511 | 1.95k | spectral_band_replication_config.sbr_codec = ELD_SBR; |
2512 | 1.95k | spectral_band_replication_config.frame_flag_480 = pstr_aac_config->flag_framelength_small; |
2513 | 2.96k | } else if (pstr_api_struct->pstr_state->aot == AOT_SBR || |
2514 | 2.96k | pstr_api_struct->pstr_state->aot == AOT_PS) { |
2515 | 2.96k | spectral_band_replication_config.frame_flag_960 = pstr_aac_config->flag_framelength_small; |
2516 | 2.96k | spectral_band_replication_config.sbr_codec = HEAAC_SBR; |
2517 | 2.96k | } |
2518 | | |
2519 | 4.91k | if (pstr_api_struct->config[ele_idx].aac_classic == 0) { |
2520 | 4.91k | pstr_api_struct->pstr_state->downsample[ele_idx] = 1; |
2521 | 4.91k | } |
2522 | | |
2523 | 4.91k | if (pstr_api_struct->pstr_state->mps_enable) { |
2524 | 785 | if (pstr_api_struct->pstr_state->mps_tree_config == TREE_212) { |
2525 | 298 | WORD32 delay = |
2526 | 298 | ((pstr_aac_config->flag_framelength_small ? FRAME_LEN_480 / 2 : FRAME_LEN_512 / 2) * |
2527 | 298 | 2 + |
2528 | 298 | 4); |
2529 | 298 | ixheaace_mps_212_memory_struct *pstr_mps_memory; |
2530 | 298 | pstr_mps_memory = pstr_api_struct->pstr_state->mps_pers_mem; |
2531 | 298 | ixheaace_mps_212_open(&pstr_api_struct->pstr_mps_212_enc, pstr_mps_memory); |
2532 | | |
2533 | 298 | pstr_asc->str_aac_config.num_sac_cfg_bits = 0; |
2534 | | |
2535 | 298 | error = ixheaace_mps_212_initialise( |
2536 | 298 | pstr_api_struct->pstr_mps_212_enc, AOT_AAC_ELD, pstr_aac_config->sample_rate, |
2537 | 298 | &pstr_aac_config->bit_rate, |
2538 | 298 | pstr_api_struct->config[ele_idx].eldsbr_found ? 2 /*hAacConfig->sbrRatio*/ : 0, |
2539 | 298 | (pstr_aac_config->flag_framelength_small ? FRAME_LEN_480 * 2 : FRAME_LEN_512 * 2), |
2540 | | /* for dual rate sbr this value is already multiplied by 2 */ |
2541 | 298 | (pstr_aac_config->flag_framelength_small |
2542 | 298 | ? FRAME_LEN_480 * 2 |
2543 | 298 | : FRAME_LEN_512 * 2) /* samples read per ch*/, |
2544 | 298 | delay, (WORD8 *)pstr_api_struct->pstr_state->ptr_temp_buff_resamp); |
2545 | 298 | if (error) { |
2546 | 0 | return error; |
2547 | 0 | } |
2548 | | |
2549 | 298 | pstr_asc->str_aac_config.num_sac_cfg_bits = ixheaace_mps_212_get_spatial_specific_config( |
2550 | 298 | pstr_api_struct->pstr_mps_212_enc, (WORD8 *)pstr_asc->str_aac_config.sac_cfg_data, |
2551 | 298 | sizeof(pstr_asc->str_aac_config.sac_cfg_data), AOT_AAC_ELD); |
2552 | 298 | pstr_asc->str_aac_config.eld_ext_type[0] = IAAC_ELDEXT_LDSAC; |
2553 | 298 | pstr_asc->str_aac_config.eld_ext_len[0] = |
2554 | 298 | (pstr_asc->str_aac_config.num_sac_cfg_bits + 7) >> 3; |
2555 | 487 | } else { |
2556 | 487 | WORD32 tree_config; |
2557 | 487 | WORD32 bits_written; |
2558 | 487 | ixheaace_bit_buf bit_buf; |
2559 | 487 | ixheaace_bit_buf_handle ptr_bit_buf; |
2560 | 487 | ixheaace_mps_515_memory_struct *pstr_mps_memory; |
2561 | 487 | if (pstr_api_struct->pstr_state->mps_tree_config == TREE_525) { |
2562 | 266 | tree_config = 525; |
2563 | 266 | } else if (pstr_api_struct->pstr_state->mps_tree_config == TREE_5152) { |
2564 | 41 | tree_config = 5152; |
2565 | 180 | } else { |
2566 | 180 | tree_config = 5151; |
2567 | 180 | } |
2568 | 487 | pstr_mps_memory = pstr_api_struct->pstr_state->mps_515_pers_mem; |
2569 | 487 | ptr_bit_buf = ia_enhaacplus_enc_create_bitbuffer( |
2570 | 487 | &bit_buf, (UWORD8 *)pstr_asc->str_aac_config.sac_cfg_data, |
2571 | 487 | sizeof(pstr_asc->str_aac_config.sac_cfg_data)); |
2572 | | |
2573 | 487 | error = ixheaace_mps_515_open( |
2574 | 487 | &pstr_api_struct->pstr_mps_515_enc, pstr_aac_config->sample_rate, tree_config, |
2575 | 487 | ptr_bit_buf, &bits_written, pstr_mps_memory, pstr_aac_config->flag_framelength_small); |
2576 | 487 | pstr_asc->str_aac_config.num_sac_cfg_bits = bits_written; |
2577 | 487 | pstr_asc->str_aac_config.eld_ext_type[0] = IAAC_ELDEXT_LDSAC; |
2578 | 487 | pstr_asc->str_aac_config.eld_ext_len[0] = (bits_written + 7) >> 3; |
2579 | 487 | if (error) { |
2580 | 0 | return error; |
2581 | 0 | } |
2582 | 487 | } |
2583 | 785 | } |
2584 | | |
2585 | 4.91k | ixheaace_adjust_sbr_settings( |
2586 | 4.91k | &spectral_band_replication_config, pstr_aac_config->bit_rate, |
2587 | 4.91k | pstr_aac_config->num_out_channels, core_sample_rate, AACENC_TRANS_FAC, 24000, |
2588 | 4.91k | pstr_api_struct->spectral_band_replication_tabs.ptr_qmf_tab, |
2589 | 4.91k | pstr_api_struct->pstr_state->aot, (pstr_api_struct->config[0].ccfl_idx == SBR_4_1)); |
2590 | | |
2591 | 4.91k | if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) { |
2592 | | /* open SBR PART, set core bandwidth */ |
2593 | 4.49k | error = ixheaace_env_open( |
2594 | 4.49k | &pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[ele_idx], |
2595 | 4.49k | &spectral_band_replication_config, &pstr_aac_config->band_width, |
2596 | 4.49k | ptr_spectral_band_replication_scratch, |
2597 | 4.49k | &(pstr_api_struct->spectral_band_replication_tabs), |
2598 | 4.49k | &pstr_asc->str_aac_config.sbr_config); |
2599 | 4.49k | pstr_asc->str_aac_config.ld_sbr_present_flag = |
2600 | 4.49k | pstr_api_struct->config[ele_idx].eldsbr_found; |
2601 | 4.49k | if (error) { |
2602 | 0 | return error; |
2603 | 0 | } |
2604 | 4.49k | pstr_asc->str_aac_config.ld_sbr_sample_rate = |
2605 | 4.49k | (spectral_band_replication_config.codec_settings.sample_freq != |
2606 | 4.49k | pstr_aac_config->sample_rate) |
2607 | 4.49k | ? 1 |
2608 | 4.49k | : 0; |
2609 | 4.49k | pstr_asc->str_aac_config.ld_sbr_crc_flag = spectral_band_replication_config.crc_sbr; |
2610 | 4.49k | } |
2611 | | |
2612 | 4.91k | if (!pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2613 | 4.56k | IA_ERRORCODE resamp_error = IA_NO_ERROR; |
2614 | 4.56k | WORD32 ch_idx = 0; |
2615 | | |
2616 | 4.56k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2617 | 4.56k | &(pstr_api_struct->pstr_state->down_sampler[ele_idx][ch_idx]), 2, |
2618 | 4.56k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2619 | 4.56k | if (resamp_error) { |
2620 | 0 | return resamp_error; |
2621 | 0 | } |
2622 | 4.56k | if (pstr_api_struct->config[ele_idx].i_channels > 1) { |
2623 | 2.71k | resamp_error = ia_enhaacplus_enc_init_iir_resampler( |
2624 | 2.71k | &(pstr_api_struct->pstr_state->down_sampler[ele_idx][ch_idx + 1]), 2, |
2625 | 2.71k | pstr_api_struct->spectral_band_replication_tabs.ptr_resamp_tab); |
2626 | 2.71k | if (resamp_error) { |
2627 | 0 | return resamp_error; |
2628 | 0 | } |
2629 | 2.71k | } |
2630 | 4.56k | } |
2631 | 4.91k | } else { |
2632 | 2.33k | if (!(pstr_api_struct->config[ele_idx].aac_classic && |
2633 | 2.33k | !(pstr_api_struct->config[ele_idx].eldsbr_found))) { |
2634 | 34 | if (pstr_api_struct->config[ele_idx].aac_classic == 0) { |
2635 | 34 | error = IA_EXHEAACE_INIT_FATAL_AACPLUS_NOT_AVAIL; |
2636 | 34 | } else { |
2637 | 0 | error = IA_EXHEAACE_INIT_FATAL_BITRATE_NOT_SUPPORTED; |
2638 | 0 | } |
2639 | 34 | return error; |
2640 | 34 | } |
2641 | 2.30k | pstr_api_struct->pstr_state->buffer_offset = 0; |
2642 | 2.30k | pstr_api_struct->config[ele_idx].aac_classic = 1; |
2643 | 2.30k | } |
2644 | 7.21k | { |
2645 | 7.21k | WORD32 *shared_buf1, *shared_buf2; |
2646 | 7.21k | WORD32 *shared_buf3; |
2647 | 7.21k | WORD8 *shared_buf4; |
2648 | 7.21k | switch (pstr_api_struct->pstr_state->aot) { |
2649 | 1.63k | case AOT_AAC_LC: |
2650 | 4.24k | case AOT_SBR: |
2651 | 4.60k | case AOT_PS: |
2652 | 4.60k | ia_enhaacplus_enc_get_shared_bufs( |
2653 | 4.60k | ptr_spectral_band_replication_scratch, &shared_buf1, &shared_buf2, &shared_buf3, |
2654 | 4.60k | &shared_buf4, |
2655 | 4.60k | (pstr_aac_config->flag_framelength_small == 1) ? FRAME_LEN_960 : FRAME_LEN_1024); |
2656 | 4.60k | break; |
2657 | | |
2658 | 664 | case AOT_AAC_LD: |
2659 | 2.61k | case AOT_AAC_ELD: |
2660 | 2.61k | ia_enhaacplus_enc_get_shared_bufs( |
2661 | 2.61k | ptr_spectral_band_replication_scratch, &shared_buf1, &shared_buf2, &shared_buf3, |
2662 | 2.61k | &shared_buf4, |
2663 | 2.61k | (pstr_aac_config->flag_framelength_small == 1) ? FRAME_LEN_480 : FRAME_LEN_512); |
2664 | 2.61k | break; |
2665 | 7.21k | } |
2666 | | |
2667 | 7.21k | ia_enhaacplus_enc_set_shared_bufs(pstr_aac_scratch, &shared_buf1, &shared_buf2, &shared_buf3, |
2668 | 7.21k | &ptr_resampler_scratch); |
2669 | | |
2670 | 7.21k | error = ia_enhaacplus_enc_aac_enc_open( |
2671 | 7.21k | &(pstr_api_struct->pstr_state->aac_enc_pers_mem[ele_idx]), |
2672 | 7.21k | *pstr_aac_config /*, *pstr_ancillary*/, pstr_aac_scratch, |
2673 | 7.21k | &(pstr_api_struct->pstr_aac_tabs), pstr_api_struct->config[ele_idx].element_type, |
2674 | 7.21k | pstr_api_struct->config[ele_idx].element_instance_tag, pstr_api_struct->pstr_state->aot); |
2675 | 7.21k | if (error != IA_NO_ERROR) { |
2676 | 0 | return error; |
2677 | 0 | } |
2678 | 7.21k | if (error) { |
2679 | 0 | if (pstr_api_struct->pstr_mps_212_enc && pstr_api_struct->pstr_state->mps_enable) { |
2680 | 0 | ixheaace_mps_212_close(&(pstr_api_struct->pstr_mps_212_enc)); |
2681 | 0 | } |
2682 | 0 | if (pstr_api_struct->pstr_mps_515_enc && pstr_api_struct->pstr_state->mps_enable) { |
2683 | 0 | ixheaace_mps_515_close(pstr_api_struct->pstr_mps_212_enc); |
2684 | 0 | } |
2685 | |
|
2686 | 0 | return (IA_EXHEAACE_INIT_FATAL_AAC_INIT_FAILED); |
2687 | 0 | } |
2688 | 7.21k | } |
2689 | | |
2690 | 7.21k | return error; |
2691 | 7.21k | } |
2692 | | |
2693 | | static IA_ERRORCODE ia_enhaacplus_enc_execute(ixheaace_api_struct *pstr_api_struct, |
2694 | 382k | WORD32 ele_idx) { |
2695 | 382k | IA_ERRORCODE error = IA_NO_ERROR; |
2696 | 382k | WORD32 downsample; |
2697 | 382k | WORD32 aot; |
2698 | 382k | WORD32 idx; |
2699 | 382k | WORD32 header_bytes = 0; |
2700 | 382k | WORD32 num_samples_read; |
2701 | 382k | WORD32 env_read_offset = 0; |
2702 | 382k | WORD32 write_off_set = 0; |
2703 | 382k | WORD32 aacenc_blocksize; |
2704 | 382k | WORD32 ch, out_samples; |
2705 | 382k | WORD32 total_channels = 0, ele, slot; |
2706 | 382k | WORD32 time_in_stride; |
2707 | 382k | WORD32 num_bs_elements; |
2708 | 382k | FLAG flag_last_element; |
2709 | 382k | WORD32 i_num_coup_channels; |
2710 | 382k | WORD32 i_channels_mask; |
2711 | 382k | ixheaace_pstr_sbr_enc pstr_sbr_encoder = NULL; |
2712 | 382k | iexheaac_encoder_str **pstr_aac_enc; |
2713 | 382k | iaace_config *pstr_aac_config; |
2714 | 382k | pWORD16 pw_inp_buf = NULL; |
2715 | 382k | pUWORD8 pub_out_buf = NULL; |
2716 | 382k | FLOAT32 *ptr_input_buffer = NULL; |
2717 | 382k | FLOAT32 *ptr_input_buffer_mps = NULL; |
2718 | 382k | FLOAT32 *shared_buf1_ring, *shared_buf2_ring; |
2719 | 382k | WORD32 out_stride = IXHEAACE_MAX_CH_IN_BS_ELE; |
2720 | 382k | WORD32 *pstr_aac_scratch = (pWORD32)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_SCRATCH_IDX]; |
2721 | 382k | WORD8 *ptr_spectral_band_replication_scratch = |
2722 | 382k | ((pWORD8)pstr_aac_scratch) + ia_enhaacplus_enc_aac_enc_scr_size(); |
2723 | 382k | WORD32 *total_fill_bits = &(pstr_api_struct->pstr_state->total_fill_bits); |
2724 | 382k | WORD32 *write_program_config_element = |
2725 | 382k | &(pstr_api_struct->config[0].write_program_config_element); |
2726 | | |
2727 | 382k | aot = pstr_api_struct->pstr_state->aot; |
2728 | 382k | num_bs_elements = pstr_api_struct->config[0].num_bs_elements; |
2729 | 382k | flag_last_element = (ele_idx == (num_bs_elements - 1)); |
2730 | 382k | i_num_coup_channels = pstr_api_struct->config[0].i_num_coupling_chan; |
2731 | 382k | i_channels_mask = pstr_api_struct->config[0].i_channels_mask; |
2732 | 382k | aacenc_blocksize = pstr_api_struct->config[0].frame_length; |
2733 | 382k | downsample = pstr_api_struct->pstr_state->downsample[ele_idx]; |
2734 | 382k | num_samples_read = |
2735 | 382k | aacenc_blocksize * pstr_api_struct->config[ele_idx].i_native_channels * (1 << downsample); |
2736 | 1.35M | for (ele = 0; ele < num_bs_elements; ele++) { |
2737 | 974k | total_channels += pstr_api_struct->config[ele].i_native_channels; |
2738 | 974k | } |
2739 | 382k | pstr_aac_config = &(pstr_api_struct->config[ele_idx].aac_config); |
2740 | 382k | if ((pstr_api_struct->config[ele_idx].aac_classic == 0) && |
2741 | 382k | pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2742 | 29.9k | time_in_stride = 1; |
2743 | 352k | } else if ((pstr_api_struct->config[ele_idx].aac_classic == 1) && |
2744 | 352k | (pstr_api_struct->config[ele_idx].num_bs_elements == 1)) { |
2745 | 15.6k | time_in_stride = pstr_aac_config->num_out_channels; |
2746 | 336k | } else { |
2747 | 336k | time_in_stride = IXHEAACE_MAX_CH_IN_BS_ELE; |
2748 | 336k | } |
2749 | 382k | pstr_aac_enc = pstr_api_struct->pstr_state->aac_enc_pers_mem; |
2750 | | |
2751 | 382k | pw_inp_buf = (pWORD16)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_INPUT_IDX]; |
2752 | 382k | if (ele_idx == 0) { |
2753 | 208k | pstr_api_struct->pstr_state->i_out_bytes = 0; |
2754 | 208k | pub_out_buf = ((pUWORD8)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_OUTPUT_IDX]); |
2755 | 208k | *total_fill_bits = 0; |
2756 | 208k | } |
2757 | | |
2758 | 382k | if (pstr_api_struct->config->adts_flag) { |
2759 | 116k | pub_out_buf = (pUWORD8)(pub_out_buf + 7); |
2760 | 116k | } |
2761 | | |
2762 | 1.14M | for (ch = 0; ch < IXHEAACE_MAX_CH_IN_BS_ELE; ch++) |
2763 | 764k | pstr_api_struct->pstr_state->num_anc_data_bytes[ele_idx][ch] = 0; |
2764 | | |
2765 | 382k | if (aot == AOT_SBR || aot == AOT_PS) { |
2766 | 156k | write_off_set = INPUT_DELAY_LC * IXHEAACE_MAX_CH_IN_BS_ELE; |
2767 | 226k | } else if (aot == AOT_AAC_ELD && pstr_api_struct->pstr_state->mps_enable != 1) { |
2768 | 72.3k | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) |
2769 | 36.0k | write_off_set = INPUT_DELAY_ELD_480 * IXHEAACE_MAX_CH_IN_BS_ELE; |
2770 | 36.2k | else |
2771 | 36.2k | write_off_set = INPUT_DELAY_ELD_512 * IXHEAACE_MAX_CH_IN_BS_ELE; |
2772 | 153k | } else if (aot == AOT_AAC_ELD && pstr_api_struct->pstr_state->mps_enable == 1 && |
2773 | 153k | pstr_api_struct->pstr_state->mps_tree_config == TREE_212) { |
2774 | 34.4k | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) |
2775 | 21.5k | write_off_set = INPUT_DELAY_ELDV2_480 * IXHEAACE_MAX_CH_IN_BS_ELE; |
2776 | 12.9k | else |
2777 | 12.9k | write_off_set = INPUT_DELAY_ELDV2_512 * IXHEAACE_MAX_CH_IN_BS_ELE; |
2778 | 119k | } else if (aot == AOT_AAC_ELD && pstr_api_struct->pstr_state->mps_enable == 1 && |
2779 | 119k | pstr_api_struct->pstr_state->mps_tree_config != TREE_212) { |
2780 | 22.3k | write_off_set = INPUT_DELAY_ELD_512_MPS * IXHEAACE_MAX_CH_IN_BS_ELE; |
2781 | 22.3k | } |
2782 | 382k | if (pstr_api_struct->config[ele_idx].aac_classic == 1) { |
2783 | 96.8k | write_off_set = 0; |
2784 | 96.8k | } |
2785 | 382k | if (aot == AOT_AAC_ELD && pstr_api_struct->pstr_state->mps_enable == 1) { |
2786 | 56.8k | if (pstr_api_struct->pstr_state->mps_tree_config == TREE_212) { |
2787 | 34.4k | env_read_offset = INPUT_DELAY_ELD_512_MPS; |
2788 | 34.4k | } else { |
2789 | 22.3k | env_read_offset = write_off_set; |
2790 | 22.3k | } |
2791 | 56.8k | } |
2792 | 382k | if (pstr_api_struct->pstr_state->downsample[ele_idx]) { |
2793 | 285k | if (!pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2794 | 255k | if (aot == AOT_AAC_ELD && pstr_api_struct->pstr_state->mps_enable != 1) { |
2795 | 72.3k | write_off_set += |
2796 | 72.3k | 4 * IXHEAACE_MAX_CH_IN_BS_ELE; // Downsampler delay = 4 samples per channel @input SR |
2797 | 183k | } else { |
2798 | 183k | write_off_set += (pstr_api_struct->pstr_state->down_sampler[ele_idx][0].delay) * |
2799 | 183k | IXHEAACE_MAX_CH_IN_BS_ELE; |
2800 | 183k | } |
2801 | 255k | } |
2802 | 285k | if (pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2803 | 29.9k | env_read_offset = (MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY) * IXHEAACE_MAX_CH_IN_BS_ELE; |
2804 | 29.9k | write_off_set = env_read_offset; |
2805 | 29.9k | } |
2806 | 285k | } |
2807 | | |
2808 | 382k | if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) { |
2809 | 231k | ptr_input_buffer = pstr_api_struct->pstr_state->inp_delay + |
2810 | 231k | (aacenc_blocksize * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LC) * |
2811 | 231k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2812 | 231k | } else if (aot == AOT_AAC_LD) { |
2813 | 21.6k | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) { |
2814 | 4.46k | ptr_input_buffer = pstr_api_struct->pstr_state->inp_delay + |
2815 | 4.46k | (FRAME_LEN_480 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LD_480) * |
2816 | 4.46k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2817 | 17.1k | } else { |
2818 | 17.1k | ptr_input_buffer = pstr_api_struct->pstr_state->inp_delay + |
2819 | 17.1k | (FRAME_LEN_512 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_LD_512) * |
2820 | 17.1k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2821 | 17.1k | } |
2822 | 129k | } else if (aot == AOT_AAC_ELD) { |
2823 | 129k | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) { |
2824 | 69.6k | if (pstr_api_struct->pstr_state->mps_enable == 1) { |
2825 | 33.5k | ptr_input_buffer = |
2826 | 33.5k | pstr_api_struct->pstr_state->inp_delay + |
2827 | 33.5k | (FRAME_LEN_480 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_ELDV2_480) * |
2828 | 33.5k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2829 | 36.0k | } else { |
2830 | 36.0k | ptr_input_buffer = |
2831 | 36.0k | pstr_api_struct->pstr_state->inp_delay + |
2832 | 36.0k | (FRAME_LEN_480 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_ELD_480) * |
2833 | 36.0k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2834 | 36.0k | } |
2835 | 69.6k | } else { |
2836 | 59.5k | if (pstr_api_struct->pstr_state->mps_enable == 1) { |
2837 | 23.3k | ptr_input_buffer = |
2838 | 23.3k | pstr_api_struct->pstr_state->inp_delay + |
2839 | 23.3k | (FRAME_LEN_512 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_ELDV2_512) * |
2840 | 23.3k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2841 | 36.2k | } else { |
2842 | 36.2k | ptr_input_buffer = |
2843 | 36.2k | pstr_api_struct->pstr_state->inp_delay + |
2844 | 36.2k | (FRAME_LEN_512 * 2 + MAXIMUM_DS_2_1_FILTER_DELAY + INPUT_DELAY_ELD_512) * |
2845 | 36.2k | IXHEAACE_MAX_CH_IN_BS_ELE * ele_idx; |
2846 | 36.2k | } |
2847 | 59.5k | } |
2848 | 129k | } else { |
2849 | 0 | return IA_EXHEAACE_EXE_FATAL_UNSUPPORTED_AOT; |
2850 | 0 | } |
2851 | | |
2852 | 382k | if (aot != AOT_AAC_LD && aot != AOT_AAC_LC) { |
2853 | 285k | pstr_sbr_encoder = |
2854 | 285k | pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[ele_idx]; |
2855 | 285k | if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) { |
2856 | 264k | ixheaace_sbr_set_scratch_ptr(pstr_sbr_encoder, ptr_spectral_band_replication_scratch); |
2857 | 264k | } |
2858 | 285k | } |
2859 | | |
2860 | 382k | { |
2861 | 382k | ixheaace_mps_enc_ext_payload mps_extension_payload; |
2862 | 382k | UWORD8 *mps_bs = pstr_api_struct->pstr_state->mps_bs; |
2863 | 382k | memset(&mps_extension_payload, 0, sizeof(ixheaace_mps_enc_ext_payload)); |
2864 | 382k | mps_extension_payload.p_data = mps_bs; |
2865 | | |
2866 | 382k | if ((pstr_api_struct->config[ele_idx].num_bs_elements == 1) && |
2867 | 382k | (pstr_api_struct->config[ele_idx].i_channels <= 2)) { |
2868 | 103k | if (pstr_api_struct->config[ele_idx].aac_classic != 1) { |
2869 | 87.8k | if ((pstr_api_struct->config[ele_idx].i_channels == 2 && |
2870 | 87.8k | pstr_api_struct->config[ele_idx].chmode_nchannels == 2) && |
2871 | 87.8k | (!((pstr_api_struct->pstr_mps_212_enc != NULL) && |
2872 | 79.1k | pstr_api_struct->pstr_state->mps_enable))) { |
2873 | 152M | for (idx = 0; idx < (num_samples_read); idx++) { |
2874 | 152M | ptr_input_buffer[write_off_set + idx] = (FLOAT32)pw_inp_buf[idx]; |
2875 | 152M | } |
2876 | 44.6k | } else if (pstr_api_struct->config[ele_idx].i_channels == 1) { |
2877 | 16.6M | for (idx = 0; idx < num_samples_read; idx++) { |
2878 | 16.6M | ptr_input_buffer[write_off_set + (IXHEAACE_MAX_CH_IN_BS_ELE * idx)] = |
2879 | 16.6M | (FLOAT32)pw_inp_buf[idx]; |
2880 | 16.6M | } |
2881 | 34.4k | } else if ((pstr_api_struct->pstr_mps_212_enc != NULL) && |
2882 | 34.4k | pstr_api_struct->pstr_state->mps_enable) { |
2883 | 34.4k | ptr_input_buffer_mps = pstr_api_struct->pstr_state->time_signal_mps; |
2884 | 33.9M | for (idx = 0; idx < (num_samples_read / 2); idx++) { |
2885 | 33.9M | ptr_input_buffer_mps[idx] = (FLOAT32)pw_inp_buf[2 * idx]; |
2886 | 33.9M | ptr_input_buffer_mps[(num_samples_read / 2) + idx] = |
2887 | 33.9M | (FLOAT32)pw_inp_buf[(2 * idx) + 1]; |
2888 | 33.9M | } |
2889 | 34.4k | } |
2890 | 87.8k | } else { |
2891 | 17.1M | for (idx = 0; idx < (num_samples_read + write_off_set); idx++) { |
2892 | 17.1M | ptr_input_buffer[idx] = (FLOAT32)pw_inp_buf[idx]; |
2893 | 17.1M | } |
2894 | 15.6k | } |
2895 | 279k | } else { |
2896 | 279k | if (pstr_api_struct->config[ele_idx].i_channels == 2) { |
2897 | 140k | slot = pstr_api_struct->config[ele_idx].element_slot; |
2898 | 201M | for (idx = 0; idx < num_samples_read / 2; idx++) { |
2899 | 201M | ptr_input_buffer[2 * idx + write_off_set] = |
2900 | 201M | (FLOAT32)pw_inp_buf[total_channels * idx + slot]; |
2901 | 201M | ptr_input_buffer[2 * idx + write_off_set + 1] = |
2902 | 201M | (FLOAT32)pw_inp_buf[total_channels * idx + slot + 1]; |
2903 | 201M | } |
2904 | 140k | } |
2905 | | |
2906 | 279k | if (pstr_api_struct->config[ele_idx].i_channels == 1) { |
2907 | 116k | slot = pstr_api_struct->config[ele_idx].element_slot; |
2908 | 162M | for (idx = 0; idx < num_samples_read; idx++) { |
2909 | 162M | ptr_input_buffer[write_off_set + (IXHEAACE_MAX_CH_IN_BS_ELE * idx)] = |
2910 | 162M | (FLOAT32)pw_inp_buf[total_channels * idx + slot]; |
2911 | 162M | } |
2912 | 116k | } |
2913 | | |
2914 | 279k | if (pstr_api_struct->config[ele_idx].i_channels == 6) { |
2915 | 22.3k | ptr_input_buffer_mps = pstr_api_struct->pstr_state->time_signal_mps; |
2916 | 132M | for (idx = 0; idx < num_samples_read; idx++) { |
2917 | 132M | ptr_input_buffer_mps[idx] = (FLOAT32)pw_inp_buf[idx]; |
2918 | 132M | } |
2919 | 22.3k | } |
2920 | 279k | } |
2921 | | |
2922 | 382k | if ((pstr_api_struct->pstr_mps_212_enc != NULL) && pstr_api_struct->pstr_state->mps_enable) { |
2923 | 34.4k | ptr_input_buffer_mps = pstr_api_struct->pstr_state->time_signal_mps; |
2924 | 34.4k | error = ixheaace_mps_212_process(pstr_api_struct->pstr_mps_212_enc, ptr_input_buffer_mps, |
2925 | 34.4k | num_samples_read, &mps_extension_payload); |
2926 | 34.4k | if (error) { |
2927 | 0 | return error; |
2928 | 0 | } |
2929 | 34.4k | num_samples_read /= 2; |
2930 | 33.9M | for (idx = 0; idx < num_samples_read; idx++) { |
2931 | 33.9M | ptr_input_buffer[2 * idx + write_off_set] = (FLOAT32)ptr_input_buffer_mps[idx]; |
2932 | 33.9M | } |
2933 | 34.4k | env_read_offset = write_off_set; |
2934 | 34.4k | } |
2935 | 382k | if ((pstr_api_struct->pstr_mps_515_enc != NULL) && pstr_api_struct->pstr_state->mps_enable) { |
2936 | 22.3k | ixheaace_bit_buf bit_buf; |
2937 | 22.3k | ixheaace_bit_buf_handle ptr_bit_buf = NULL; |
2938 | 22.3k | FLOAT32 *ptr_downmix_buffer_mps = pstr_api_struct->pstr_state->mps_scratch; |
2939 | 22.3k | VOID *ptr_scratch_515_mps = (VOID *)(pstr_api_struct->pstr_state->mps_scratch + |
2940 | 22.3k | (MAX_INPUT_CHANNELS * MAX_BUFFER_SIZE) + |
2941 | 22.3k | (MAX_OUTPUT_CHANNELS * MAX_BUFFER_SIZE)); |
2942 | 22.3k | ptr_bit_buf = ia_enhaacplus_enc_create_bitbuffer(&bit_buf, mps_bs, MAX_MPS_BS_PAYLOAD_SIZE); |
2943 | | |
2944 | 22.3k | error = |
2945 | 22.3k | ixheaace_mps_515_apply(pstr_api_struct->pstr_mps_515_enc, &ptr_input_buffer_mps[0], |
2946 | 22.3k | &ptr_downmix_buffer_mps[0], ptr_bit_buf, ptr_scratch_515_mps); |
2947 | 22.3k | if (error) { |
2948 | 0 | return error; |
2949 | 0 | } |
2950 | 22.3k | mps_extension_payload.data_size = ptr_bit_buf->cnt_bits; |
2951 | 22.3k | mps_extension_payload.data_type = IXHEAACE_MPS_EXT_LDSAC_DATA; |
2952 | 22.3k | mps_extension_payload.associated_ch_element = -1; |
2953 | | |
2954 | 22.3k | if (pstr_api_struct->pstr_state->mps_tree_config == TREE_5151 || |
2955 | 22.3k | pstr_api_struct->pstr_state->mps_tree_config == TREE_5152) { |
2956 | 10.2k | num_samples_read /= 6; |
2957 | 10.0M | for (idx = 0; idx < num_samples_read; idx++) { |
2958 | 10.0M | ptr_input_buffer[2 * idx + write_off_set] = (FLOAT32)ptr_downmix_buffer_mps[idx]; |
2959 | 10.0M | } |
2960 | 12.1k | } else { |
2961 | 12.1k | num_samples_read /= 3; |
2962 | 24.2M | for (idx = 0; idx < num_samples_read; idx++) { |
2963 | 24.1M | ptr_input_buffer[idx + write_off_set] = (FLOAT32)ptr_downmix_buffer_mps[idx]; |
2964 | 24.1M | } |
2965 | 12.1k | } |
2966 | 22.3k | env_read_offset = write_off_set; |
2967 | 22.3k | } |
2968 | | |
2969 | 382k | if (pstr_api_struct->pstr_state->downsample[ele_idx]) { |
2970 | 285k | ixheaace_resampler_scratch *pstr_scratch_resampler = |
2971 | 285k | (ixheaace_resampler_scratch *)pstr_api_struct->pstr_state->ptr_temp_buff_resamp; |
2972 | | |
2973 | 285k | if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) { |
2974 | 264k | error = ixheaace_env_encode_frame( |
2975 | 264k | pstr_sbr_encoder, ptr_input_buffer + env_read_offset, ptr_input_buffer, |
2976 | 264k | IXHEAACE_MAX_CH_IN_BS_ELE, |
2977 | 264k | &(pstr_api_struct->pstr_state->num_anc_data_bytes[ele_idx][0]), |
2978 | 264k | pstr_api_struct->pstr_state->anc_data_bytes[ele_idx], |
2979 | 264k | &(pstr_api_struct->spectral_band_replication_tabs), &(pstr_api_struct->common_tabs), |
2980 | 264k | &(mps_extension_payload.p_data[0]), mps_extension_payload.data_size, |
2981 | 264k | pstr_api_struct->config[0].aac_config.flag_framelength_small, NULL); |
2982 | | |
2983 | 264k | if (error != IA_NO_ERROR) { |
2984 | 2.95k | return error; |
2985 | 2.95k | } |
2986 | 264k | } |
2987 | | |
2988 | 282k | if (!pstr_api_struct->config[ele_idx].use_parametric_stereo) { |
2989 | 624k | for (ch = 0; ch < pstr_aac_config->num_out_channels; ch++) { |
2990 | 371k | ia_enhaacplus_enc_get_scratch_bufs(pstr_api_struct->pstr_state->temp_buff_sbr, |
2991 | 371k | &shared_buf1_ring, &shared_buf2_ring); |
2992 | 371k | { |
2993 | 371k | ia_enhaacplus_enc_iir_downsampler( |
2994 | 371k | &(pstr_api_struct->pstr_state->down_sampler[ele_idx][ch]), |
2995 | 371k | ptr_input_buffer + write_off_set + ch, |
2996 | 371k | num_samples_read / pstr_aac_config->num_out_channels, IXHEAACE_MAX_CH_IN_BS_ELE, |
2997 | 371k | ptr_input_buffer + ch, &out_samples, out_stride, shared_buf1_ring, |
2998 | 371k | shared_buf2_ring, pstr_scratch_resampler); |
2999 | 371k | } |
3000 | 371k | } |
3001 | 252k | } |
3002 | 282k | } |
3003 | | |
3004 | 379k | error = ia_enhaacplus_enc_aac_core_encode( |
3005 | 379k | pstr_aac_enc, ptr_input_buffer, time_in_stride, |
3006 | 379k | pstr_api_struct->pstr_state->anc_data_bytes[ele_idx], |
3007 | 379k | pstr_api_struct->pstr_state->num_anc_data_bytes[ele_idx], pub_out_buf, |
3008 | 379k | &(pstr_api_struct->pstr_state->i_out_bytes), &(pstr_api_struct->pstr_aac_tabs), |
3009 | 379k | pstr_api_struct->pstr_state->pstr_bit_stream_handle, |
3010 | 379k | &(pstr_api_struct->pstr_state->bit_stream), flag_last_element, |
3011 | 379k | write_program_config_element, i_num_coup_channels, i_channels_mask, ele_idx, |
3012 | 379k | total_fill_bits, total_channels, aot, pstr_api_struct->config->adts_flag, |
3013 | 379k | num_bs_elements, &pstr_api_struct->pstr_state->is_quant_spec_zero, |
3014 | 379k | &pstr_api_struct->pstr_state->is_gain_limited); |
3015 | 379k | if (error != IA_NO_ERROR) { |
3016 | 5.23k | return error; |
3017 | 5.23k | } |
3018 | 374k | if (pstr_sbr_encoder && !(pstr_api_struct->config[ele_idx].use_parametric_stereo)) { |
3019 | 227k | if (pstr_sbr_encoder && (ptr_input_buffer != NULL)) { |
3020 | 227k | memmove(ptr_input_buffer, |
3021 | 227k | ptr_input_buffer + aacenc_blocksize * 2 * IXHEAACE_MAX_CH_IN_BS_ELE, |
3022 | 227k | write_off_set * sizeof(ptr_input_buffer[0])); |
3023 | 227k | } |
3024 | 227k | } |
3025 | 374k | } |
3026 | 0 | {} |
3027 | | /*ADTS Header Write*/ |
3028 | 374k | if (pstr_api_struct->config->adts_flag) { |
3029 | 115k | pub_out_buf = ((pUWORD8)pstr_api_struct->pp_mem[IA_ENHAACPLUSENC_OUTPUT_IDX]); |
3030 | 115k | { |
3031 | 115k | WORD32 num_channels = 0; |
3032 | | |
3033 | 479k | for (ele = 0; ele < pstr_api_struct->config[0].num_bs_elements; ele++) { |
3034 | 363k | num_channels += pstr_api_struct->config[ele].i_channels; |
3035 | 363k | } |
3036 | 115k | { |
3037 | 115k | header_bytes = ia_enhaacplus_enc_write_ADTS_header( |
3038 | 115k | pub_out_buf, pstr_api_struct->pstr_state->i_out_bytes, |
3039 | 115k | pstr_api_struct->config->aac_config.core_sample_rate, |
3040 | 115k | (pstr_api_struct->config[0].num_bs_elements > 1) |
3041 | 115k | ? num_channels |
3042 | 115k | : pstr_api_struct->config[0].aac_config.num_out_channels); |
3043 | 115k | } |
3044 | 115k | } |
3045 | | |
3046 | 115k | pstr_api_struct->pstr_state->i_out_bytes += header_bytes; |
3047 | 115k | } |
3048 | | |
3049 | 374k | return IA_NO_ERROR; |
3050 | 379k | } |
3051 | 412k | static IA_ERRORCODE iusace_process(ixheaace_api_struct *pstr_api_struct) { |
3052 | 412k | IA_ERRORCODE error = IA_NO_ERROR; |
3053 | 412k | WORD32 idx; |
3054 | 412k | WORD32 write_off_set = 0; |
3055 | 412k | WORD32 core_coder_frame_length; |
3056 | 412k | WORD32 usac_independency_flg; |
3057 | 412k | UWORD32 padding_bits = 0; |
3058 | 412k | WORD32 core_sample; |
3059 | 412k | WORD32 drc_sample; |
3060 | 412k | WORD32 ptr_inp_buf_offset = 0; |
3061 | 412k | WORD32 num_ch; |
3062 | 412k | WORD16 *ps_inp_buf = NULL; |
3063 | 412k | WORD8 *ps_out_buf = NULL; |
3064 | 412k | FLOAT32 *ptr_input_buffer = NULL; |
3065 | 412k | FLOAT32 *ptr_inp_buf[MAX_TIME_CHANNELS]; |
3066 | 412k | FLOAT32 *ptr_drc_inp_buf[MAX_TIME_CHANNELS]; |
3067 | 412k | WORD32 delay = 0; |
3068 | 412k | ixheaace_state_struct *pstr_state = pstr_api_struct->pstr_state; |
3069 | 412k | ia_bit_buf_struct *pstr_it_bit_buff = &pstr_state->str_bit_buf; |
3070 | 412k | ia_usac_encoder_config_struct *pstr_config = &pstr_api_struct->config[0].usac_config; |
3071 | 412k | ia_usac_data_struct *pstr_usac_data = &pstr_api_struct->pstr_state->str_usac_enc_data; |
3072 | 412k | iusace_scratch_mem *pstr_scratch = &pstr_usac_data->str_scratch; |
3073 | 412k | ia_classification_struct *pstr_sig_class_data = |
3074 | 412k | &pstr_state->str_usac_enc_data.str_sig_class_data; |
3075 | 412k | core_sample = (pstr_config->ccfl * pstr_config->channels); |
3076 | 412k | drc_sample = pstr_config->drc_frame_size * pstr_config->channels; |
3077 | 412k | core_coder_frame_length = pstr_config->ccfl; |
3078 | 412k | num_ch = pstr_config->channels; |
3079 | 412k | usac_independency_flg = pstr_usac_data->usac_independency_flag; |
3080 | 412k | ps_inp_buf = (WORD16 *)pstr_api_struct->pp_mem[IA_MEMTYPE_INPUT]; |
3081 | 412k | ps_out_buf = (WORD8 *)pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT]; |
3082 | | |
3083 | 412k | if (pstr_config->use_drc_element) { |
3084 | 37.6k | if (pstr_config->use_delay_adjustment == 1) { |
3085 | 37.2k | delay = (CC_DELAY_ADJUSTMENT * pstr_config->drc_frame_size / FRAME_LEN_1024) * num_ch; |
3086 | 37.2k | } |
3087 | 103M | for (idx = 0; idx < core_sample + delay; idx++) { |
3088 | 103M | pstr_api_struct->pstr_state->pp_drc_in_buf[idx % num_ch][idx / num_ch] = |
3089 | 103M | pstr_api_struct->pstr_state |
3090 | 103M | ->pp_drc_in_buf[idx % num_ch][idx / num_ch + pstr_config->drc_frame_size]; |
3091 | 103M | } |
3092 | 37.6k | ptr_inp_buf_offset = pstr_config->drc_frame_size; |
3093 | 105k | for (idx = 0; idx < num_ch; idx++) { |
3094 | 67.5k | ptr_drc_inp_buf[idx] = pstr_api_struct->pstr_state->pp_drc_in_buf[idx]; |
3095 | 67.5k | } |
3096 | 37.6k | } |
3097 | | |
3098 | 412k | ixheaace_pstr_sbr_enc pstr_sbr_encoder = |
3099 | 412k | pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[0]; |
3100 | 412k | if (pstr_config->sbr_enable) { |
3101 | 215k | ixheaace_mps_enc_ext_payload mps_extension_payload; |
3102 | 215k | UWORD8 *mps_bs = pstr_api_struct->pstr_state->mps_bs; |
3103 | 215k | FLOAT32 *time_signal_mps = pstr_api_struct->pstr_state->time_signal_mps; |
3104 | 215k | WORD32 sbr_pvc_mode = 0; |
3105 | 215k | WORD32 sbr_patching_mode = 1; |
3106 | 215k | WORD32 ccfl_size; |
3107 | 215k | WORD32 num_samples_read; |
3108 | 215k | WORD32 out_samples, ch; |
3109 | 215k | WORD32 resamp_ratio = |
3110 | 215k | ia_enhaacplus_enc_compute_resampling_ratio(pstr_api_struct->config[0].ccfl_idx); |
3111 | 215k | switch (pstr_config->codec_mode) { |
3112 | 107k | case USAC_SWITCHED: |
3113 | 107k | if (pstr_usac_data->str_sig_class_data.coding_mode == 2) { |
3114 | 16.7k | sbr_pvc_mode = 0; |
3115 | 91.1k | } else { |
3116 | 91.1k | sbr_pvc_mode = 2; |
3117 | 91.1k | } |
3118 | 107k | sbr_patching_mode = 1; |
3119 | 107k | break; |
3120 | 99.3k | case USAC_ONLY_FD: |
3121 | 99.3k | sbr_pvc_mode = 0; |
3122 | 99.3k | sbr_patching_mode = 0; |
3123 | 99.3k | break; |
3124 | 8.34k | case USAC_ONLY_TD: |
3125 | 8.34k | sbr_pvc_mode = 2; |
3126 | 8.34k | sbr_patching_mode = 1; |
3127 | 8.34k | break; |
3128 | 215k | } |
3129 | | |
3130 | 215k | write_off_set = INPUT_DELAY_LC * IXHEAACE_MAX_CH_IN_BS_ELE; |
3131 | | |
3132 | 215k | if (pstr_api_struct->config[0].ccfl_idx == SBR_4_1) { |
3133 | 54.3k | write_off_set = write_off_set * 2; |
3134 | 54.3k | } |
3135 | | |
3136 | 215k | if (pstr_api_struct->pstr_state->downsample[0]) { |
3137 | 215k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3138 | 31.9k | write_off_set += |
3139 | 31.9k | (pstr_api_struct->pstr_state->down_samp_sos[0][0].delay) * IXHEAACE_MAX_CH_IN_BS_ELE; |
3140 | | |
3141 | 31.9k | write_off_set += |
3142 | 31.9k | (pstr_api_struct->pstr_state->up_sampler[0][0].delay) * IXHEAACE_MAX_CH_IN_BS_ELE; |
3143 | 183k | } else if (pstr_api_struct->config[0].ccfl_idx == SBR_2_1 || |
3144 | 183k | pstr_api_struct->config[0].ccfl_idx == SBR_4_1) { |
3145 | 183k | write_off_set += |
3146 | 183k | (pstr_api_struct->pstr_state->down_sampler[0][0].delay) * IXHEAACE_MAX_CH_IN_BS_ELE; |
3147 | 183k | } |
3148 | 215k | } |
3149 | | |
3150 | 215k | ptr_input_buffer = pstr_api_struct->pstr_state->inp_delay; |
3151 | 215k | ccfl_size = pstr_api_struct->config[0].usac_config.ccfl; |
3152 | 215k | num_samples_read = ccfl_size * pstr_api_struct->config[0].i_channels; |
3153 | 215k | switch (pstr_api_struct->config[0].ccfl_idx) { |
3154 | 31.9k | case SBR_8_3: |
3155 | 31.9k | num_samples_read *= 8; |
3156 | 31.9k | num_samples_read /= 3; |
3157 | 31.9k | break; |
3158 | | |
3159 | 129k | case SBR_2_1: |
3160 | 129k | num_samples_read *= 2; |
3161 | 129k | break; |
3162 | | |
3163 | 54.3k | case SBR_4_1: |
3164 | 54.3k | num_samples_read *= 4; |
3165 | 54.3k | break; |
3166 | 215k | } |
3167 | | |
3168 | 215k | mps_extension_payload.p_data = mps_bs; |
3169 | 215k | memset(&mps_extension_payload, 0, sizeof(ixheaace_mps_enc_ext_payload)); |
3170 | | |
3171 | 215k | if ((pstr_api_struct->pstr_mps_212_enc != NULL) && pstr_api_struct->pstr_state->mps_enable) { |
3172 | 175M | for (idx = 0; idx < num_samples_read / 2; idx++) { |
3173 | 175M | time_signal_mps[idx] = (FLOAT32)ps_inp_buf[2 * idx]; |
3174 | 175M | time_signal_mps[num_samples_read / 2 + idx] = (FLOAT32)ps_inp_buf[2 * idx + 1]; |
3175 | 175M | } |
3176 | 69.4k | ixheaace_mps_pstr_struct pstr_mps_enc = |
3177 | 69.4k | (ixheaace_mps_pstr_struct)pstr_api_struct->pstr_mps_212_enc; |
3178 | 69.4k | pstr_mps_enc->ptr_sac_encoder->independency_flag = usac_independency_flg; |
3179 | | |
3180 | 69.4k | error = ixheaace_mps_212_process(pstr_api_struct->pstr_mps_212_enc, time_signal_mps, |
3181 | 69.4k | num_samples_read, &mps_extension_payload); |
3182 | 69.4k | if (error) { |
3183 | 0 | return error; |
3184 | 0 | } |
3185 | 69.4k | if (pstr_api_struct->pstr_state->mps_enable == 1) { |
3186 | 175M | for (idx = 0; idx < num_samples_read / 2; idx++) { |
3187 | 175M | ptr_input_buffer[write_off_set + 2 * idx] = time_signal_mps[idx]; |
3188 | 175M | ptr_input_buffer[write_off_set + 2 * idx + 1] = |
3189 | 175M | time_signal_mps[num_samples_read / 2 + idx]; |
3190 | 175M | } |
3191 | 69.4k | } |
3192 | 146k | } else if (pstr_api_struct->config[0].i_channels == 2 && |
3193 | 146k | pstr_api_struct->config[0].chmode_nchannels == 2) { |
3194 | 424M | for (idx = 0; idx < (num_samples_read); idx++) { |
3195 | 424M | ptr_input_buffer[write_off_set + idx] = (FLOAT32)ps_inp_buf[idx]; |
3196 | 424M | } |
3197 | 87.7k | } else if (pstr_api_struct->config[0].i_channels == 1) { |
3198 | 165M | for (idx = 0; idx < num_samples_read; idx++) { |
3199 | 165M | ptr_input_buffer[write_off_set + (IXHEAACE_MAX_CH_IN_BS_ELE * idx)] = |
3200 | 165M | (FLOAT32)ps_inp_buf[idx]; |
3201 | 165M | } |
3202 | 58.4k | } |
3203 | | |
3204 | 215k | if (num_ch == 2) { |
3205 | 157k | if (1 == pstr_config->use_drc_element) { |
3206 | 6.26M | for (idx = 0; idx < drc_sample; idx++) { |
3207 | 6.26M | ptr_drc_inp_buf[idx % num_ch][(idx >> 1) + ptr_inp_buf_offset] = ptr_input_buffer[idx]; |
3208 | 6.26M | } |
3209 | 1.53k | } |
3210 | | |
3211 | | // update Header and bit-stream parameters |
3212 | 157k | if (0 == pstr_config->sbr_pvc_active) { |
3213 | 101k | sbr_pvc_mode = 0; |
3214 | 101k | } |
3215 | | |
3216 | 157k | ixheaace_set_usac_sbr_params( |
3217 | 157k | pstr_sbr_encoder, usac_independency_flg, 0, pstr_config->sbr_pvc_active, sbr_pvc_mode, |
3218 | 157k | pstr_config->sbr_inter_tes_active, pstr_config->sbr_harmonic, sbr_patching_mode); |
3219 | | |
3220 | | // Downsample SBR input buffer for Harmonic SBR |
3221 | 157k | if (pstr_config->sbr_harmonic) { |
3222 | 91.4k | FLOAT32 *in_buffer_temp; |
3223 | 91.4k | ixheaace_get_input_scratch_buf(pstr_api_struct->pstr_state->ptr_temp_buff_resamp, |
3224 | 91.4k | &in_buffer_temp); |
3225 | 91.4k | FLOAT32 *outbuf = ixheaace_get_hbe_resample_buffer(pstr_sbr_encoder); |
3226 | 91.4k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3227 | 0 | WORD32 input_tot = num_samples_read / pstr_api_struct->config[0].i_channels; |
3228 | 0 | ixheaace_upsampling_inp_buf_generation(ptr_input_buffer, in_buffer_temp, input_tot, |
3229 | 0 | UPSAMPLE_FAC, 0); |
3230 | 0 | } |
3231 | | |
3232 | | // Resampler |
3233 | 274k | for (ch = 0; ch < num_ch; ch++) { |
3234 | 182k | FLOAT32 *shared_buf1_ring, *shared_buf2_ring; |
3235 | 182k | ixheaace_resampler_scratch *pstr_scratch_resampler = |
3236 | 182k | (ixheaace_resampler_scratch *)(ixheaace_resampler_scratch *) |
3237 | 182k | pstr_api_struct->pstr_state->ptr_temp_buff_resamp; |
3238 | | |
3239 | 182k | ia_enhaacplus_enc_get_scratch_bufs(pstr_api_struct->pstr_state->temp_buff_sbr, |
3240 | 182k | &shared_buf1_ring, &shared_buf2_ring); |
3241 | | |
3242 | 182k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3243 | | // Upsampling by factor 3 - SOS implementation |
3244 | 0 | ia_enhaacplus_enc_iir_sos_upsampler( |
3245 | 0 | &(pstr_api_struct->pstr_state->hbe_up_sampler[0][ch]), in_buffer_temp + ch, |
3246 | 0 | num_samples_read / pstr_api_struct->config[0].i_channels, |
3247 | 0 | IXHEAACE_MAX_CH_IN_BS_ELE, in_buffer_temp + ch, &out_samples, shared_buf1_ring, |
3248 | 0 | shared_buf2_ring, pstr_scratch_resampler); |
3249 | | |
3250 | | // Downsampling by factor 8 |
3251 | 0 | ia_enhaacplus_enc_iir_sos_downsampler( |
3252 | 0 | &(pstr_api_struct->pstr_state->hbe_down_samp_sos[0][ch]), in_buffer_temp + ch, |
3253 | 0 | out_samples, IXHEAACE_MAX_CH_IN_BS_ELE, outbuf + ch, &out_samples, |
3254 | 0 | shared_buf1_ring, shared_buf2_ring, pstr_scratch_resampler); |
3255 | 182k | } else { |
3256 | 182k | WORD32 out_stride = IXHEAACE_MAX_CH_IN_BS_ELE * resamp_ratio; |
3257 | | |
3258 | 182k | ia_enhaacplus_enc_iir_downsampler( |
3259 | 182k | &(pstr_api_struct->pstr_state->hbe_down_sampler[0][ch]), ptr_input_buffer + ch, |
3260 | 182k | num_samples_read / pstr_api_struct->config[0].i_channels, |
3261 | 182k | IXHEAACE_MAX_CH_IN_BS_ELE, outbuf + ch, &out_samples, out_stride, |
3262 | 182k | shared_buf1_ring, shared_buf2_ring, pstr_scratch_resampler); |
3263 | 182k | } |
3264 | 182k | } |
3265 | 91.4k | } |
3266 | | |
3267 | | // SBR Encode |
3268 | 157k | error = ixheaace_env_encode_frame( |
3269 | 157k | pstr_sbr_encoder, ptr_input_buffer, ptr_input_buffer, |
3270 | 157k | pstr_api_struct->config[0].i_channels, |
3271 | 157k | &(pstr_api_struct->pstr_state->num_anc_data_bytes[0][0]), |
3272 | 157k | pstr_api_struct->pstr_state->anc_data_bytes[0], |
3273 | 157k | &(pstr_api_struct->spectral_band_replication_tabs), &(pstr_api_struct->common_tabs), |
3274 | 157k | &(mps_extension_payload.p_data[0]), mps_extension_payload.data_size, 0, |
3275 | 157k | &pstr_api_struct->pstr_state->str_usac_enc_data.num_sbr_bits); |
3276 | 157k | if (error != IA_NO_ERROR) { |
3277 | 8.00k | return error; |
3278 | 8.00k | } |
3279 | 157k | } else { |
3280 | 58.4k | if (0 == pstr_config->sbr_pvc_active) { |
3281 | 32.1k | sbr_pvc_mode = 0; |
3282 | 32.1k | } |
3283 | | |
3284 | 58.4k | ixheaace_set_usac_sbr_params( |
3285 | 58.4k | pstr_sbr_encoder, usac_independency_flg, 0, pstr_config->sbr_pvc_active, sbr_pvc_mode, |
3286 | 58.4k | pstr_config->sbr_inter_tes_active, pstr_config->sbr_harmonic, sbr_patching_mode); |
3287 | 58.4k | if (pstr_config->sbr_harmonic) { |
3288 | 3.86k | FLOAT32 *in_buffer_temp; |
3289 | 3.86k | ixheaace_get_input_scratch_buf(pstr_api_struct->pstr_state->ptr_temp_buff_resamp, |
3290 | 3.86k | &in_buffer_temp); |
3291 | 3.86k | FLOAT32 *outbuf = ixheaace_get_hbe_resample_buffer(pstr_sbr_encoder); |
3292 | 3.86k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3293 | 0 | WORD32 input_tot = num_samples_read / pstr_api_struct->config[0].i_channels; |
3294 | 0 | ixheaace_upsampling_inp_buf_generation(ptr_input_buffer, in_buffer_temp, input_tot, |
3295 | 0 | UPSAMPLE_FAC, 0); |
3296 | 0 | } |
3297 | | |
3298 | | // Resampler |
3299 | 7.73k | for (ch = 0; ch < num_ch; ch++) { |
3300 | 3.86k | FLOAT32 *shared_buf1_ring, *shared_buf2_ring; |
3301 | 3.86k | ixheaace_resampler_scratch *pstr_scratch_resampler = |
3302 | 3.86k | (ixheaace_resampler_scratch *)(ixheaace_resampler_scratch *) |
3303 | 3.86k | pstr_api_struct->pstr_state->ptr_temp_buff_resamp; |
3304 | | |
3305 | 3.86k | ia_enhaacplus_enc_get_scratch_bufs(pstr_api_struct->pstr_state->temp_buff_sbr, |
3306 | 3.86k | &shared_buf1_ring, &shared_buf2_ring); |
3307 | | |
3308 | 3.86k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3309 | | // Upsampling by factor 3 - SOS implementation |
3310 | 0 | ia_enhaacplus_enc_iir_sos_upsampler( |
3311 | 0 | &(pstr_api_struct->pstr_state->hbe_up_sampler[0][ch]), in_buffer_temp + ch, |
3312 | 0 | num_samples_read / pstr_api_struct->config[0].i_channels, |
3313 | 0 | IXHEAACE_MAX_CH_IN_BS_ELE, in_buffer_temp + ch, &out_samples, shared_buf1_ring, |
3314 | 0 | shared_buf2_ring, pstr_scratch_resampler); |
3315 | | |
3316 | | // Downsampling by factor 8 |
3317 | 0 | ia_enhaacplus_enc_iir_sos_downsampler( |
3318 | 0 | &(pstr_api_struct->pstr_state->hbe_down_samp_sos[0][ch]), in_buffer_temp + ch, |
3319 | 0 | out_samples, IXHEAACE_MAX_CH_IN_BS_ELE, outbuf + ch, &out_samples, |
3320 | 0 | shared_buf1_ring, shared_buf2_ring, pstr_scratch_resampler); |
3321 | 3.86k | } else { |
3322 | 3.86k | WORD32 out_stride = IXHEAACE_MAX_CH_IN_BS_ELE * resamp_ratio; |
3323 | | |
3324 | 3.86k | ia_enhaacplus_enc_iir_downsampler( |
3325 | 3.86k | &(pstr_api_struct->pstr_state->hbe_down_sampler[0][ch]), |
3326 | 3.86k | ptr_input_buffer /*input_buffer_fix + write_off_set*/ + ch, |
3327 | 3.86k | num_samples_read / pstr_api_struct->config[0].i_channels, |
3328 | 3.86k | IXHEAACE_MAX_CH_IN_BS_ELE, outbuf + ch, &out_samples, out_stride, |
3329 | 3.86k | shared_buf1_ring, shared_buf2_ring, pstr_scratch_resampler); |
3330 | 3.86k | } |
3331 | 3.86k | } |
3332 | 3.86k | } |
3333 | | |
3334 | 58.4k | FLOAT32 *time_signal = pstr_api_struct->pstr_state->time_signal; |
3335 | 165M | for (idx = 0; idx < num_samples_read; idx++) { |
3336 | 165M | time_signal[idx] = (FLOAT32)ptr_input_buffer[idx << 1]; |
3337 | 165M | } |
3338 | | |
3339 | 58.4k | if (1 == pstr_config->use_drc_element) { |
3340 | 15.8M | for (idx = 0; idx < drc_sample; idx++) { |
3341 | 15.8M | ptr_drc_inp_buf[0][idx + ptr_inp_buf_offset] = time_signal[idx]; |
3342 | 15.8M | } |
3343 | 7.71k | } |
3344 | | |
3345 | | // SBR Encode |
3346 | 58.4k | error = ixheaace_env_encode_frame( |
3347 | 58.4k | pstr_sbr_encoder, time_signal, time_signal, pstr_api_struct->config[0].i_channels, |
3348 | 58.4k | &(pstr_api_struct->pstr_state->num_anc_data_bytes[0][0]), |
3349 | 58.4k | pstr_api_struct->pstr_state->anc_data_bytes[0], |
3350 | 58.4k | &(pstr_api_struct->spectral_band_replication_tabs), &(pstr_api_struct->common_tabs), |
3351 | 58.4k | &(mps_extension_payload.p_data[0]), mps_extension_payload.data_size, 0, |
3352 | 58.4k | &pstr_api_struct->pstr_state->str_usac_enc_data.num_sbr_bits); |
3353 | 58.4k | if (error != IA_NO_ERROR) { |
3354 | 3.00k | return error; |
3355 | 3.00k | } |
3356 | 58.4k | } |
3357 | | |
3358 | | /* Resampling for USAC core */ |
3359 | 204k | { |
3360 | 204k | FLOAT32 *in_buffer_temp; |
3361 | 204k | ixheaace_get_input_scratch_buf(pstr_api_struct->pstr_state->ptr_temp_buff_resamp, |
3362 | 204k | &in_buffer_temp); |
3363 | 204k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3364 | 31.9k | WORD32 input_tot = num_samples_read / pstr_api_struct->config[0].i_channels; |
3365 | 31.9k | ixheaace_upsampling_inp_buf_generation(ptr_input_buffer, in_buffer_temp, input_tot, |
3366 | 31.9k | UPSAMPLE_FAC, write_off_set - delay); |
3367 | 31.9k | } |
3368 | | |
3369 | 558k | for (ch = 0; ch < num_ch; ch++) { |
3370 | 353k | FLOAT32 *shared_buf1_ring, *shared_buf2_ring; |
3371 | 353k | ixheaace_resampler_scratch *pstr_scratch_resampler = |
3372 | 353k | (ixheaace_resampler_scratch *)pstr_api_struct->pstr_state->ptr_temp_buff_resamp; |
3373 | | |
3374 | 353k | ia_enhaacplus_enc_get_scratch_bufs(pstr_api_struct->pstr_state->temp_buff_sbr, |
3375 | 353k | &shared_buf1_ring, &shared_buf2_ring); |
3376 | | |
3377 | 353k | if (pstr_api_struct->config[0].ccfl_idx == SBR_8_3) { |
3378 | | // Upsampling by factor 3 - SOS implementation |
3379 | 48.4k | ia_enhaacplus_enc_iir_sos_upsampler( |
3380 | 48.4k | &(pstr_api_struct->pstr_state->up_sampler[0][ch]), in_buffer_temp + ch, |
3381 | 48.4k | num_samples_read / pstr_api_struct->config[0].i_channels, IXHEAACE_MAX_CH_IN_BS_ELE, |
3382 | 48.4k | in_buffer_temp + ch, &out_samples, shared_buf1_ring, shared_buf2_ring, |
3383 | 48.4k | pstr_scratch_resampler); |
3384 | | |
3385 | | // Downsampling by factor 8 |
3386 | 48.4k | ia_enhaacplus_enc_iir_sos_downsampler( |
3387 | 48.4k | &(pstr_api_struct->pstr_state->down_samp_sos[0][ch]), in_buffer_temp + ch, |
3388 | 48.4k | out_samples, IXHEAACE_MAX_CH_IN_BS_ELE, ptr_input_buffer + ch, &out_samples, |
3389 | 48.4k | shared_buf1_ring, shared_buf2_ring, pstr_scratch_resampler); |
3390 | 305k | } else { |
3391 | 305k | WORD32 out_stride = IXHEAACE_MAX_CH_IN_BS_ELE * resamp_ratio; |
3392 | 305k | ia_enhaacplus_enc_iir_downsampler( |
3393 | 305k | &(pstr_api_struct->pstr_state->down_sampler[0][ch]), |
3394 | 305k | ptr_input_buffer + write_off_set - delay + ch, |
3395 | 305k | num_samples_read / pstr_api_struct->config[0].i_channels, IXHEAACE_MAX_CH_IN_BS_ELE, |
3396 | 305k | ptr_input_buffer + ch, &out_samples, out_stride, shared_buf1_ring, shared_buf2_ring, |
3397 | 305k | pstr_scratch_resampler); |
3398 | 305k | } |
3399 | 353k | } |
3400 | 204k | } |
3401 | | |
3402 | 204k | if (num_ch != 0) { |
3403 | 558k | for (idx = 0; idx < num_ch; idx++) { |
3404 | 353k | ptr_inp_buf[idx] = pstr_api_struct->pstr_state->ptr_in_buf[idx]; |
3405 | 353k | } |
3406 | | |
3407 | 204k | if (num_ch == 1) { |
3408 | 52.8M | for (idx = 0; idx < core_sample; idx++) { |
3409 | 52.7M | ptr_inp_buf[0][idx] = ptr_input_buffer[idx << 1]; |
3410 | 52.7M | } |
3411 | 149k | } else { |
3412 | 297M | for (idx = 0; idx < core_sample; idx++) { |
3413 | 296M | ptr_inp_buf[idx % num_ch][idx / num_ch] = ptr_input_buffer[idx]; |
3414 | 296M | } |
3415 | 149k | } |
3416 | 204k | } |
3417 | 204k | } else { |
3418 | 197k | if (pstr_config->use_delay_adjustment == 1) { |
3419 | 195k | delay = ((CC_DELAY_ADJUSTMENT * core_coder_frame_length) / FRAME_LEN_1024) * num_ch; |
3420 | 195k | } |
3421 | 197k | if (num_ch != 0) { |
3422 | 535k | for (idx = 0; idx < num_ch; idx++) { |
3423 | 338k | ptr_inp_buf[idx] = pstr_api_struct->pstr_state->ptr_in_buf[idx]; |
3424 | 338k | } |
3425 | | |
3426 | 290M | for (idx = 0; idx < core_sample; idx++) { |
3427 | 290M | ptr_inp_buf[idx % num_ch][(idx + delay) / num_ch] = ps_inp_buf[idx]; |
3428 | 290M | } |
3429 | | |
3430 | 197k | if (1 == pstr_config->use_drc_element) { |
3431 | 58.1M | for (idx = 0; idx < drc_sample; idx++) { |
3432 | 58.1M | ptr_drc_inp_buf[idx % num_ch][(idx + delay) / num_ch + ptr_inp_buf_offset] = |
3433 | 58.1M | ps_inp_buf[idx]; |
3434 | 58.1M | } |
3435 | 28.3k | } |
3436 | 197k | } |
3437 | 197k | } |
3438 | | |
3439 | 401k | if (pstr_sig_class_data->is_switch_mode) { |
3440 | 141M | for (idx = 0; idx < core_coder_frame_length; idx++) { |
3441 | 141M | pstr_sig_class_data->input_samples[pstr_sig_class_data->n_buffer_samples + idx] = |
3442 | 141M | pstr_api_struct->pstr_state->ptr_in_buf[0][idx]; |
3443 | 141M | } |
3444 | 154k | pstr_sig_class_data->n_buffer_samples += core_coder_frame_length; |
3445 | 154k | iusace_classification(pstr_sig_class_data, pstr_scratch, core_coder_frame_length); |
3446 | 154k | } |
3447 | | |
3448 | 401k | pstr_it_bit_buff = |
3449 | 401k | iusace_create_bit_buffer(pstr_it_bit_buff, pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT], |
3450 | 401k | pstr_api_struct->pstr_mem_info[IA_MEMTYPE_OUTPUT].ui_size, 1); |
3451 | 401k | if (pstr_it_bit_buff == NULL) { |
3452 | 0 | return IA_EXHEAACE_INIT_FATAL_USAC_BITBUFFER_INIT_FAILED; |
3453 | 0 | } |
3454 | 401k | error = |
3455 | 401k | ixheaace_usac_encode(pstr_api_struct->pstr_state->ptr_in_buf, pstr_config, |
3456 | 401k | &pstr_api_struct->pstr_state->str_usac_enc_data, |
3457 | 401k | &pstr_api_struct->pstr_state->audio_specific_config, pstr_it_bit_buff, |
3458 | 401k | pstr_sbr_encoder, pstr_api_struct->pstr_state->pp_drc_in_buf, |
3459 | 401k | &pstr_api_struct->pstr_state->is_quant_spec_zero, |
3460 | 401k | &pstr_api_struct->pstr_state->is_gain_limited); |
3461 | 401k | if (error) return error; |
3462 | | |
3463 | 401k | padding_bits = 8 - (pstr_it_bit_buff->cnt_bits & 7); |
3464 | 401k | if (padding_bits > 0 && padding_bits < 8) { |
3465 | 343k | ps_out_buf[pstr_it_bit_buff->cnt_bits >> 3] = |
3466 | 343k | (WORD8)((UWORD32)ps_out_buf[pstr_it_bit_buff->cnt_bits >> 3]) & (0xFF << padding_bits); |
3467 | 343k | } |
3468 | 401k | pstr_api_struct->pstr_state->i_out_bytes = |
3469 | 401k | (padding_bits > 0 && padding_bits < 8) ? (pstr_it_bit_buff->cnt_bits + padding_bits) >> 3 |
3470 | 401k | : pstr_it_bit_buff->cnt_bits >> 3; |
3471 | 401k | pstr_api_struct->pstr_state->i_out_bits = pstr_it_bit_buff->cnt_bits; |
3472 | 401k | ixheaace_write_audio_preroll_data(pstr_api_struct, pstr_it_bit_buff); |
3473 | 401k | pstr_state->str_usac_enc_data.frame_count++; |
3474 | 401k | pstr_usac_data->usac_independency_flag_count = |
3475 | 401k | (pstr_usac_data->usac_independency_flag_count + 1) % |
3476 | 401k | pstr_usac_data->usac_independency_flag_interval; |
3477 | | |
3478 | 401k | if (pstr_config->sbr_enable) { |
3479 | 204k | WORD32 num_samples = pstr_api_struct->config[0].usac_config.ccfl * IXHEAACE_MAX_CH_IN_BS_ELE; |
3480 | 204k | switch (pstr_api_struct->config[0].ccfl_idx) { |
3481 | 31.9k | case SBR_8_3: |
3482 | 31.9k | num_samples *= 8; |
3483 | 31.9k | num_samples /= 3; |
3484 | 31.9k | break; |
3485 | | |
3486 | 122k | case SBR_2_1: |
3487 | 122k | num_samples *= 2; |
3488 | 122k | break; |
3489 | | |
3490 | 50.3k | case SBR_4_1: |
3491 | 50.3k | num_samples *= 4; |
3492 | 50.3k | break; |
3493 | 204k | } |
3494 | | |
3495 | 204k | if (ptr_input_buffer != NULL) { |
3496 | 204k | memmove(ptr_input_buffer, ptr_input_buffer + num_samples, |
3497 | 204k | write_off_set * sizeof(ptr_input_buffer[0])); |
3498 | 204k | } |
3499 | 204k | } else if (!pstr_config->sbr_enable && pstr_config->use_delay_adjustment) { |
3500 | 529k | for (idx = 0; idx < num_ch; idx++) { |
3501 | 334k | memmove(&ptr_inp_buf[idx][0], &ptr_inp_buf[idx][core_sample / num_ch], |
3502 | 334k | sizeof(ptr_inp_buf[idx][0]) * delay / num_ch); |
3503 | 334k | } |
3504 | 195k | } |
3505 | | |
3506 | 401k | return IA_NO_ERROR; |
3507 | 401k | } |
3508 | 0 | IA_ERRORCODE ixheaace_get_lib_id_strings(pVOID pv_output) { |
3509 | 0 | IA_ERRORCODE err_code = IA_NO_ERROR; |
3510 | 0 | ixheaace_version *pstr_output_config = (ixheaace_version *)pv_output; |
3511 | 0 | pstr_output_config->p_lib_name = (WORD8 *)LIB_NAME; |
3512 | 0 | pstr_output_config->p_version_num = (WORD8 *)ITTIAM_VER; |
3513 | |
|
3514 | 0 | return err_code; |
3515 | 0 | } |
3516 | | |
3517 | | static void ixheaace_get_measured_loudness_info(ixheaace_api_struct *pstr_api_struct, |
3518 | 5.58k | ixheaace_input_config *pstr_input_config) { |
3519 | 5.58k | ia_drc_input_config *pstr_internal_drc_cfg; |
3520 | 5.58k | ia_drc_uni_drc_config_struct *pstr_uni_drc_config; |
3521 | 5.58k | ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set; |
3522 | 5.58k | WORD32 n, m; |
3523 | | |
3524 | 5.58k | pstr_internal_drc_cfg = |
3525 | 5.58k | (ia_drc_input_config *)&pstr_api_struct->config[0].usac_config.str_drc_cfg; |
3526 | 5.58k | if (pstr_input_config->use_drc_element == 0) { |
3527 | 4.30k | memset(pstr_internal_drc_cfg, 0, sizeof(ia_drc_input_config)); |
3528 | 4.30k | } |
3529 | 5.58k | pstr_uni_drc_config = &pstr_internal_drc_cfg->str_uni_drc_config; |
3530 | 5.58k | pstr_enc_loudness_info_set = &pstr_internal_drc_cfg->str_enc_loudness_info_set; |
3531 | | |
3532 | 5.58k | pstr_uni_drc_config->sample_rate_present = 1; |
3533 | 5.58k | pstr_uni_drc_config->loudness_info_set_present = 1; |
3534 | 5.58k | pstr_enc_loudness_info_set->loudness_info_count = 1; |
3535 | | |
3536 | 11.1k | for (n = 0; n < pstr_enc_loudness_info_set->loudness_info_count; n++) { |
3537 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].drc_set_id = 0; |
3538 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].downmix_id = 0; |
3539 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level_present = 1; |
3540 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level = |
3541 | 5.58k | pstr_input_config->sample_peak_level; |
3542 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_present = 0; |
3543 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count = 1; |
3544 | | |
3545 | 11.1k | for (m = 0; m < pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count; m++) { |
3546 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_definition = |
3547 | 5.58k | pstr_input_config->method_def; |
3548 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_value = |
3549 | 5.58k | (FLOAT32)pstr_input_config->measured_loudness; |
3550 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n] |
3551 | 5.58k | .str_loudness_measure[m] |
3552 | 5.58k | .measurement_system = pstr_input_config->measurement_system; |
3553 | 5.58k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].reliability = 3; |
3554 | 5.58k | } |
3555 | 5.58k | } |
3556 | 5.58k | } |
3557 | | |
3558 | 10.5k | IA_ERRORCODE ixheaace_allocate(pVOID pv_input, pVOID pv_output) { |
3559 | 10.5k | IA_ERRORCODE err_code = IA_NO_ERROR; |
3560 | 10.5k | WORD32 ui_api_size; |
3561 | 10.5k | pVOID pv_value; |
3562 | 10.5k | ixheaace_input_config *pstr_input_config = (ixheaace_input_config *)pv_input; |
3563 | 10.5k | ixheaace_output_config *pstr_output_config = (ixheaace_output_config *)pv_output; |
3564 | 10.5k | ixheaace_api_struct *pstr_api_struct; |
3565 | 10.5k | if (1 == pstr_input_config->usac_en) { |
3566 | 6.16k | pstr_input_config->aot = AOT_USAC; |
3567 | 6.16k | } |
3568 | 10.5k | if (pstr_input_config->aot != AOT_AAC_ELD && pstr_input_config->aot != AOT_AAC_LC && |
3569 | 10.5k | pstr_input_config->aot != AOT_AAC_LD && pstr_input_config->aot != AOT_SBR && |
3570 | 10.5k | pstr_input_config->aot != AOT_PS && pstr_input_config->aot != AOT_USAC) { |
3571 | 382 | return IA_EXHEAACE_API_FATAL_UNSUPPORTED_AOT; |
3572 | 382 | } |
3573 | 10.1k | ui_api_size = sizeof(ixheaace_api_struct); |
3574 | 10.1k | pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] = |
3575 | 10.1k | pstr_output_config->malloc_xheaace(ui_api_size + EIGHT_BYTE_SIZE, DEFAULT_MEM_ALIGN_8); |
3576 | 10.1k | if (NULL == pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count]) { |
3577 | 0 | return IA_EXHEAACE_API_FATAL_MEM_ALLOC; |
3578 | 0 | } |
3579 | 10.1k | memset(pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count], 0, ui_api_size); |
3580 | | |
3581 | 10.1k | pstr_output_config->ui_rem = |
3582 | 10.1k | (SIZE_T)((SIZE_T)pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] % |
3583 | 10.1k | BYTE_ALIGN_8); |
3584 | | |
3585 | 10.1k | pstr_output_config->pv_ia_process_api_obj = |
3586 | 10.1k | (pVOID)((WORD8 *)pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] + |
3587 | 10.1k | BYTE_ALIGN_8 - pstr_output_config->ui_rem); |
3588 | 10.1k | pstr_output_config->malloc_count++; |
3589 | | |
3590 | 10.1k | pstr_api_struct = (ixheaace_api_struct *)pstr_output_config->pv_ia_process_api_obj; |
3591 | 10.1k | memset(pstr_api_struct, 0, sizeof(*pstr_api_struct)); |
3592 | | |
3593 | 10.1k | ixheaace_set_default_config(pstr_api_struct, pstr_input_config); |
3594 | | |
3595 | 10.1k | err_code = ixheaace_set_config_params(pstr_api_struct, pstr_input_config); |
3596 | 10.1k | if (err_code) { |
3597 | 427 | return err_code; |
3598 | 427 | } |
3599 | | |
3600 | 9.77k | if (pstr_input_config->aot == AOT_USAC) { |
3601 | 6.25k | if (pstr_api_struct->config[0].usac_config.is_loudness_configured == 0) { |
3602 | 5.58k | ixheaace_get_measured_loudness_info(pstr_api_struct, pstr_input_config); |
3603 | 5.58k | memcpy(pstr_input_config->pv_drc_cfg, &pstr_api_struct->config[0].usac_config.str_drc_cfg, |
3604 | 5.58k | sizeof(ia_drc_input_config)); |
3605 | 5.58k | } |
3606 | 6.25k | } |
3607 | | |
3608 | 9.77k | pstr_output_config->ui_proc_mem_tabs_size = |
3609 | 9.77k | (sizeof(ixheaace_mem_info_struct) + sizeof(pVOID *)) * 4; |
3610 | 9.77k | pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] = |
3611 | 9.77k | pstr_output_config->malloc_xheaace( |
3612 | 9.77k | pstr_output_config->ui_proc_mem_tabs_size + EIGHT_BYTE_SIZE, DEFAULT_MEM_ALIGN_8); |
3613 | 9.77k | if (NULL == pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count]) { |
3614 | 0 | return IA_EXHEAACE_API_FATAL_MEM_ALLOC; |
3615 | 0 | } |
3616 | 9.77k | memset(pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count], 0, |
3617 | 9.77k | pstr_output_config->ui_proc_mem_tabs_size); |
3618 | | |
3619 | 9.77k | pstr_output_config->ui_rem = |
3620 | 9.77k | (SIZE_T)((SIZE_T)pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] % |
3621 | 9.77k | BYTE_ALIGN_8); |
3622 | | |
3623 | 9.77k | pv_value = |
3624 | 9.77k | (pVOID)((WORD8 *)pstr_output_config->arr_alloc_memory[pstr_output_config->malloc_count] + |
3625 | 9.77k | BYTE_ALIGN_8 - pstr_output_config->ui_rem); |
3626 | 9.77k | if (pv_value == NULL) { |
3627 | 0 | return IA_EXHEAACE_API_FATAL_MEM_ALLOC; |
3628 | 0 | } |
3629 | 9.77k | memset(pv_value, 0, (sizeof(ixheaace_mem_info_struct) + sizeof(pVOID *)) * 4); |
3630 | | |
3631 | 9.77k | pstr_api_struct->pstr_mem_info = (ixheaace_mem_info_struct *)pv_value; |
3632 | 9.77k | pstr_api_struct->pp_mem = (pVOID *)((WORD8 *)pv_value + sizeof(ixheaace_mem_info_struct) * 4); |
3633 | | |
3634 | 9.77k | pstr_output_config->malloc_count++; |
3635 | | |
3636 | 9.77k | ixheaace_fill_mem_tabs(pstr_api_struct, pstr_input_config->aot); |
3637 | | |
3638 | 9.77k | err_code = |
3639 | 9.77k | ixheaace_alloc_and_assign_mem(pstr_api_struct, pstr_output_config, pstr_input_config); |
3640 | 9.77k | if (err_code) { |
3641 | 0 | return err_code; |
3642 | 0 | } |
3643 | | |
3644 | 9.77k | pstr_output_config->is_loudness_configured = |
3645 | 9.77k | pstr_api_struct->config[0].usac_config.is_loudness_configured; |
3646 | | |
3647 | 9.77k | return err_code; |
3648 | 9.77k | } |
3649 | | |
3650 | 9.77k | IA_ERRORCODE ixheaace_init(pVOID pstr_obj_ixheaace, pVOID pv_input, pVOID pv_output) { |
3651 | 9.77k | IA_ERRORCODE error = IA_NO_ERROR; |
3652 | 9.77k | WORD32 frame_length; |
3653 | 9.77k | WORD32 channels, ele_idx; |
3654 | 9.77k | ixheaace_api_struct *pstr_api_struct = (ixheaace_api_struct *)pstr_obj_ixheaace; |
3655 | 9.77k | ixheaace_input_config *pstr_input_config = (ixheaace_input_config *)pv_input; |
3656 | 9.77k | ixheaace_output_config *pstr_output_config = (ixheaace_output_config *)pv_output; |
3657 | 9.77k | WORD32 total_bitrate_used = 0; |
3658 | 9.77k | frame_length = pstr_input_config->frame_length; |
3659 | 9.77k | channels = 0; |
3660 | 23.3k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
3661 | 13.5k | channels += pstr_api_struct->config[ele_idx].i_channels; |
3662 | 13.5k | } |
3663 | 9.77k | pstr_api_struct->pstr_state->aot = pstr_input_config->aot; |
3664 | | |
3665 | 9.77k | if ((pstr_api_struct->config[0].use_mps == 1) && |
3666 | 9.77k | (0 == pstr_api_struct->config->aac_classic || |
3667 | 2.22k | pstr_api_struct->pstr_state->aot == AOT_USAC)) { |
3668 | 2.19k | pstr_api_struct->pstr_state->mps_enable = pstr_api_struct->config[0].use_mps; |
3669 | 2.19k | pstr_api_struct->pstr_state->mps_tree_config = pstr_api_struct->config[0].mps_tree_config; |
3670 | 2.19k | } |
3671 | 9.77k | if (pstr_api_struct->config[0].num_bs_elements == 1) { |
3672 | 8.10k | pstr_api_struct->config[ele_idx].write_program_config_element = 0; |
3673 | 8.10k | } |
3674 | | |
3675 | 9.77k | if (pstr_api_struct->pstr_state->aot != AOT_USAC) { |
3676 | 10.7k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
3677 | | /* Set config pointer in api obj */ |
3678 | 7.25k | pstr_api_struct->pstr_state->pstr_config[ele_idx] = &pstr_api_struct->config[ele_idx]; |
3679 | | |
3680 | 7.25k | error = ia_enhaacplus_enc_init(pstr_api_struct, ele_idx); |
3681 | 7.25k | if (error) { |
3682 | 34 | return error; |
3683 | 34 | } |
3684 | | |
3685 | 7.21k | pstr_api_struct->pstr_state->ui_init_done = 1; |
3686 | 7.21k | total_bitrate_used += pstr_api_struct->config[ele_idx].aac_config.bit_rate; |
3687 | 7.21k | } |
3688 | 3.48k | if (pstr_input_config->i_bitrate != total_bitrate_used) { |
3689 | 2.53k | pstr_input_config->i_bitrate = total_bitrate_used; |
3690 | 2.53k | } |
3691 | 3.48k | if (pstr_api_struct->config[0].aac_config.bitreservoir_size != -1) { |
3692 | 3.33k | WORD32 avg_bytes_per_frame_per_ch = pstr_api_struct->config[0].aac_config.bitreservoir_size; |
3693 | 3.33k | if (pstr_api_struct->config[0].aac_config.flag_framelength_small) { |
3694 | 1.28k | if (pstr_api_struct->config[0].aot == AOT_AAC_LC || |
3695 | 1.28k | pstr_api_struct->config[0].aot == AOT_PS || |
3696 | 1.28k | pstr_api_struct->config[0].aot == AOT_SBR) { |
3697 | 612 | avg_bytes_per_frame_per_ch = (pstr_api_struct->config[0].aac_config.bit_rate) * |
3698 | 612 | FRAME_LEN_960 / |
3699 | 612 | (pstr_api_struct->config[0].aac_config.core_sample_rate * |
3700 | 612 | pstr_api_struct->config[0].i_channels * 8); |
3701 | 612 | } |
3702 | 1.28k | if (pstr_input_config->aot == AOT_AAC_LD || pstr_input_config->aot == AOT_AAC_ELD) { |
3703 | 671 | avg_bytes_per_frame_per_ch = (pstr_api_struct->config[0].aac_config.bit_rate) * |
3704 | 671 | FRAME_LEN_480 / |
3705 | 671 | (pstr_api_struct->config[0].aac_config.core_sample_rate * |
3706 | 671 | pstr_api_struct->config[0].i_channels * 8); |
3707 | 671 | } |
3708 | 2.04k | } else { |
3709 | 2.04k | if (pstr_api_struct->config[0].aot == AOT_AAC_LC || |
3710 | 2.04k | pstr_api_struct->config[0].aot == AOT_PS || |
3711 | 2.04k | pstr_api_struct->config[0].aot == AOT_SBR) { |
3712 | 1.27k | avg_bytes_per_frame_per_ch = (pstr_api_struct->config[0].aac_config.bit_rate) * |
3713 | 1.27k | FRAME_LEN_1024 / |
3714 | 1.27k | (pstr_api_struct->config[0].aac_config.core_sample_rate * |
3715 | 1.27k | pstr_api_struct->config[0].i_channels * 8); |
3716 | 1.27k | } |
3717 | 2.04k | if (pstr_input_config->aot == AOT_AAC_LD || pstr_input_config->aot == AOT_AAC_ELD) { |
3718 | 776 | avg_bytes_per_frame_per_ch = (pstr_api_struct->config[0].aac_config.bit_rate) * |
3719 | 776 | FRAME_LEN_512 / |
3720 | 776 | (pstr_api_struct->config[0].aac_config.core_sample_rate * |
3721 | 776 | pstr_api_struct->config[0].i_channels * 8); |
3722 | 776 | } |
3723 | 2.04k | } |
3724 | | |
3725 | 3.33k | if (pstr_api_struct->config[0].aac_config.bitreservoir_size < avg_bytes_per_frame_per_ch) { |
3726 | 307 | return IA_EXHEAACE_CONFIG_NONFATAL_BITRES_SIZE_TOO_SMALL; |
3727 | 307 | } |
3728 | 3.33k | } |
3729 | 3.17k | if (pstr_input_config->i_use_es) { |
3730 | | // Write GA header |
3731 | 2.55k | ia_bit_buf_struct *pstr_ia_asc_bit_buf; |
3732 | 2.55k | pstr_ia_asc_bit_buf = iusace_create_bit_buffer( |
3733 | 2.55k | &(pstr_api_struct->pstr_state->str_bit_buf), pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT], |
3734 | 2.55k | pstr_api_struct->pstr_mem_info[IA_MEMTYPE_OUTPUT].ui_size, 1); |
3735 | | |
3736 | 2.55k | ixheaace_get_audiospecific_config_bytes(pstr_ia_asc_bit_buf, |
3737 | 2.55k | &pstr_api_struct->pstr_state->audio_specific_config, |
3738 | 2.55k | pstr_api_struct->pstr_state->aot, |
3739 | 2.55k | pstr_input_config->ccfl_idx); |
3740 | | |
3741 | 2.55k | pstr_api_struct->pstr_state->i_out_bytes = (pstr_ia_asc_bit_buf->cnt_bits + 7) >> 3; |
3742 | 2.55k | } |
3743 | 3.17k | if (pstr_api_struct->config->aac_classic) { |
3744 | 925 | pstr_output_config->input_size = |
3745 | 925 | frame_length * channels * pstr_api_struct->config[0].ui_pcm_wd_sz / 8; |
3746 | 2.24k | } else { |
3747 | 2.24k | pstr_output_config->input_size = |
3748 | 2.24k | 2 * frame_length * channels * pstr_api_struct->config[0].ui_pcm_wd_sz / 8; |
3749 | 2.24k | } |
3750 | 3.17k | pstr_output_config->samp_freq = pstr_api_struct->config[0].native_sample_rate; |
3751 | 3.17k | pstr_output_config->header_samp_freq = pstr_api_struct->config[0].aac_config.core_sample_rate; |
3752 | 3.17k | pstr_output_config->down_sampling_ratio = |
3753 | 3.17k | pstr_api_struct->config->aac_classic == 0 ? 2.0f : 1.0f; |
3754 | 3.17k | switch (pstr_api_struct->config->aot) { |
3755 | 416 | case AOT_AAC_LC: |
3756 | 416 | pstr_output_config->audio_profile = AUDIO_PROFILE_AAC_LC_L5; |
3757 | 416 | break; |
3758 | 1.10k | case AOT_SBR: |
3759 | 1.10k | pstr_output_config->audio_profile = AUDIO_PROFILE_HEAAC_L5; |
3760 | 1.10k | break; |
3761 | 321 | case AOT_PS: |
3762 | 321 | pstr_output_config->audio_profile = AUDIO_PROFILE_HEAAC_V2_L5; |
3763 | 321 | break; |
3764 | 175 | case AOT_AAC_LD: |
3765 | 175 | pstr_output_config->audio_profile = AUDIO_PROFILE_AAC_LD_L4; |
3766 | 175 | break; |
3767 | 1.15k | case AOT_AAC_ELD: |
3768 | 1.15k | if (pstr_api_struct->config[0].use_mps) { |
3769 | 673 | if (pstr_api_struct->config[0].mps_tree_config == TREE_212) { |
3770 | 253 | pstr_output_config->audio_profile = AUDIO_PROFILE_AAC_ELD_L2; |
3771 | 420 | } else { |
3772 | 420 | pstr_output_config->audio_profile = AUDIO_PROFILE_AAC_ELD_L4; |
3773 | 420 | } |
3774 | 673 | } else { |
3775 | 486 | pstr_output_config->audio_profile = AUDIO_PROFILE_AAC_ELD_L1; |
3776 | 486 | } |
3777 | 1.15k | break; |
3778 | 0 | default: |
3779 | 0 | pstr_output_config->audio_profile = AUDIO_PROFILE_NOT_SPECIFIED; |
3780 | 0 | break; |
3781 | 3.17k | } |
3782 | 3.17k | } |
3783 | | |
3784 | 6.25k | else { |
3785 | 6.25k | pstr_api_struct->pstr_state->pstr_config[0] = &pstr_api_struct->config[0]; |
3786 | 6.25k | error = ia_usac_enc_init(pstr_api_struct, pstr_input_config->ccfl_idx); |
3787 | 6.25k | if (error) { |
3788 | 1.37k | return error; |
3789 | 1.37k | } |
3790 | | |
3791 | 4.88k | pstr_output_config->input_size = |
3792 | 4.88k | frame_length * channels * (pstr_api_struct->config[0].usac_config.ui_pcm_wd_sz >> 3); |
3793 | | |
3794 | 4.88k | if (pstr_api_struct->config[0].usac_config.use_drc_element) { |
3795 | 615 | ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)(pstr_input_config->pv_drc_cfg); |
3796 | 615 | memcpy(pstr_drc_cfg, &pstr_api_struct->config[0].usac_config.str_drc_cfg, |
3797 | 615 | sizeof(ia_drc_input_config)); |
3798 | 615 | } |
3799 | | |
3800 | 4.88k | pstr_output_config->down_sampling_ratio = 1; |
3801 | 4.88k | if (pstr_api_struct->config[0].usac_config.sbr_enable == 1) { |
3802 | 3.07k | switch (pstr_api_struct->config[0].ccfl_idx) { |
3803 | 519 | case SBR_8_3: |
3804 | 519 | pstr_output_config->input_size *= 8; |
3805 | 519 | pstr_output_config->input_size /= 3; |
3806 | 519 | pstr_output_config->down_sampling_ratio = 8.0f / 3.0f; |
3807 | 519 | break; |
3808 | | |
3809 | 1.74k | case SBR_2_1: |
3810 | 1.74k | pstr_output_config->input_size *= 2; |
3811 | 1.74k | pstr_output_config->down_sampling_ratio = 2; |
3812 | 1.74k | break; |
3813 | | |
3814 | 808 | case SBR_4_1: |
3815 | 808 | pstr_output_config->input_size *= 4; |
3816 | 808 | pstr_output_config->down_sampling_ratio = 4; |
3817 | 808 | break; |
3818 | 3.07k | } |
3819 | 3.07k | } |
3820 | 4.88k | pstr_output_config->samp_freq = pstr_api_struct->config[0].usac_config.native_sample_rate; |
3821 | 4.88k | pstr_output_config->header_samp_freq = |
3822 | 4.88k | pstr_api_struct->config[0].usac_config.native_sample_rate; |
3823 | 4.88k | pstr_output_config->audio_profile = AUDIO_PROFILE_USAC_L2; |
3824 | 4.88k | if (pstr_input_config->use_drc_element != |
3825 | 4.88k | pstr_api_struct->config[0].usac_config.use_drc_element) { |
3826 | 0 | error = IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS; |
3827 | 0 | } |
3828 | 4.88k | pstr_input_config->use_drc_element = pstr_api_struct->config[0].usac_config.use_drc_element; |
3829 | 4.88k | } |
3830 | | |
3831 | 8.06k | pstr_api_struct->pstr_state->ui_init_done = 1; |
3832 | 8.06k | pstr_output_config->i_out_bytes = pstr_api_struct->pstr_state->i_out_bytes; |
3833 | 8.06k | if (pstr_output_config->input_size) { |
3834 | 8.06k | pstr_output_config->expected_frame_count = |
3835 | 8.06k | (pstr_input_config->aac_config.length + (pstr_output_config->input_size - 1)) / |
3836 | 8.06k | pstr_output_config->input_size; |
3837 | 8.06k | if (pstr_api_struct->config[0].usac_config.use_delay_adjustment == 1) { |
3838 | 4.73k | pstr_output_config->expected_frame_count -= |
3839 | 4.73k | pstr_api_struct->config[0].usac_config.num_preroll_frames; |
3840 | 4.73k | } |
3841 | 8.06k | } |
3842 | | |
3843 | 8.06k | return error; |
3844 | 9.77k | } |
3845 | | |
3846 | 10.5k | IA_ERRORCODE ixheaace_create(pVOID pv_input, pVOID pv_output) { |
3847 | 10.5k | IA_ERRORCODE err_code = IA_NO_ERROR; |
3848 | 10.5k | ixheaace_output_config *pstr_out_cfg = (ixheaace_output_config *)pv_output; |
3849 | 10.5k | err_code = ixheaace_allocate(pv_input, pv_output); |
3850 | 10.5k | if (!err_code) { |
3851 | 9.77k | err_code = ixheaace_init(pstr_out_cfg->pv_ia_process_api_obj, pv_input, pv_output); |
3852 | 9.77k | } |
3853 | 10.5k | if (err_code & IA_FATAL_ERROR) { |
3854 | 2.21k | IXHEAACE_MEM_FREE(pv_output); |
3855 | 2.21k | } |
3856 | 10.5k | return err_code; |
3857 | 10.5k | } |
3858 | | |
3859 | 621k | IA_ERRORCODE ixheaace_process(pVOID pstr_obj_ixheaace, pVOID pv_input, pVOID pv_output) { |
3860 | 621k | IA_ERRORCODE error = IA_NO_ERROR; |
3861 | 621k | WORD32 ele_idx; |
3862 | 621k | (VOID) pv_input; |
3863 | 621k | ixheaace_api_struct *pstr_api_struct = (ixheaace_api_struct *)pstr_obj_ixheaace; |
3864 | 621k | ixheaace_output_config *pstr_output_config = (ixheaace_output_config *)pv_output; |
3865 | 621k | pstr_api_struct->pstr_state->is_quant_spec_zero = 0; |
3866 | 621k | pstr_api_struct->pstr_state->is_gain_limited = 0; |
3867 | 621k | if (!pstr_api_struct->usac_en) { |
3868 | 583k | for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) { |
3869 | 382k | error = ia_enhaacplus_enc_execute(pstr_api_struct, ele_idx); |
3870 | 382k | if (error != IA_NO_ERROR) { |
3871 | 8.19k | return error; |
3872 | 8.19k | } |
3873 | 382k | } |
3874 | 200k | if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_quant_spec_zero)) { |
3875 | 174 | error = IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_SPECTRUM_ZERO; |
3876 | 174 | } |
3877 | 200k | if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_gain_limited)) { |
3878 | 0 | error = IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_INSUFFICIENT_BITRES; |
3879 | 0 | } |
3880 | 412k | } else { |
3881 | 412k | ia_usac_encoder_config_struct *usac_config = &pstr_api_struct->config[0].usac_config; |
3882 | 412k | if (usac_config->iframes_interval <= usac_config->num_preroll_frames) { |
3883 | 28.6k | pstr_api_struct->pstr_state->str_usac_enc_data.usac_independency_flag = 1; |
3884 | 28.6k | if (usac_config->iframes_interval == usac_config->num_preroll_frames && |
3885 | 28.6k | usac_config->is_first_frame == 0) { |
3886 | 985 | usac_config->is_ipf = 1; |
3887 | 985 | } |
3888 | 384k | } else { |
3889 | 384k | pstr_api_struct->pstr_state->str_usac_enc_data.usac_independency_flag = 0; |
3890 | 384k | } |
3891 | 412k | if (pstr_api_struct->pstr_state->str_usac_enc_data.frame_count > |
3892 | 412k | usac_config->num_preroll_frames) { |
3893 | 387k | if (usac_config->iframes_interval <= usac_config->num_preroll_frames) { |
3894 | 3.64k | pstr_api_struct->pstr_state->str_usac_enc_data.usac_independency_flag = 1; |
3895 | 384k | } else { |
3896 | 384k | pstr_api_struct->pstr_state->str_usac_enc_data.usac_independency_flag = 0; |
3897 | 384k | } |
3898 | 387k | } |
3899 | | |
3900 | 412k | { |
3901 | 412k | error = iusace_process(pstr_api_struct); |
3902 | 412k | if (error & IA_FATAL_ERROR) { |
3903 | 10.5k | pstr_output_config->i_out_bytes = 0; |
3904 | 10.5k | return error; |
3905 | 10.5k | } |
3906 | 402k | if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_quant_spec_zero)) { |
3907 | 12 | error = IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_SPECTRUM_ZERO; |
3908 | 12 | } |
3909 | 402k | if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_gain_limited)) { |
3910 | 0 | error = IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_INSUFFICIENT_BITRES; |
3911 | 0 | } |
3912 | 402k | } |
3913 | | |
3914 | 0 | usac_config->iframes_interval++; |
3915 | 402k | if (usac_config->iframes_interval == |
3916 | 402k | (usac_config->random_access_interval - usac_config->num_preroll_frames)) { |
3917 | 1.25k | usac_config->iframes_interval = 0; |
3918 | 1.25k | } |
3919 | 402k | } |
3920 | 603k | pstr_output_config->i_out_bytes = pstr_api_struct->pstr_state->i_out_bytes; |
3921 | 603k | return error; |
3922 | 621k | } |
3923 | | |
3924 | 11.6k | IA_ERRORCODE ixheaace_delete(pVOID pv_output) { |
3925 | 11.6k | IXHEAACE_MEM_FREE(pv_output); |
3926 | 11.6k | return IA_NO_ERROR; |
3927 | 11.6k | } |