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