1 /******************************************************************************
2 *
3 * Copyright (C) 2018 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <stdlib.h>
21 #include <math.h>
22 #include <string.h>
23 #include "impd_type_def.h"
24 #include "impd_error_standards.h"
25 #include <string.h>
26 #include "impd_drc_extr_delta_coded_info.h"
27 #include "impd_drc_common.h"
28 #include "impd_drc_struct.h"
29 #include "impd_drc_interface.h"
30 #include "impd_memory_standards.h"
31 #include "impd_drc_peak_limiter.h"
32 #include "impd_drc_bitbuffer.h"
33 #include "impd_drc_bitstream_dec_api.h"
34 #include "impd_drc_gain_dec.h"
35 #include "impd_drc_filter_bank.h"
36 #include "impd_drc_multi_band.h"
37 #include "impd_drc_process_audio.h"
38 #include "impd_parametric_drc_dec.h"
39 #include "impd_drc_eq.h"
40 #include "impd_drc_gain_decoder.h"
41 #include "impd_drc_selection_process.h"
42 #include "impd_drc_api_struct_def.h"
43 #include "impd_drc_peak_limiter.h"
44
45 #define PARAMETRIC_DRC_DELAY_MAX_DEFAULT 4096
46 #define EQ_DELAY_MAX_DEFAULT 256
47
48 IA_ERRORCODE impd_drc_mem_api(ia_drc_api_struct *p_obj_drc, WORD32 iCmd,
49 WORD32 iIdx, pVOID pvValue);
50
51 IA_ERRORCODE impd_drc_fill_mem_tables(ia_drc_api_struct *p_obj_drc);
52
53 WORD32
54 impd_drc_dec_interface_process(ia_bit_buf_struct *it_bit_buff,
55 ia_drc_interface_struct *pstr_drc_interface,
56 UWORD8 *it_bit_buf, WORD32 num_bit_stream_bits,
57 WORD32 *num_bits_read);
58
59 WORD32
60 impd_drc_dec_interface_add_effect_type(
61 ia_drc_interface_struct *pstr_drc_interface, WORD32 drc_effect_type,
62 WORD32 target_loudness, WORD32 loud_norm);
63
64 #define BITSTREAM_FILE_FORMAT_SPLIT 1
65 #define LIM_DEFAULT_THRESHOLD (0.89125094f)
66
impd_match_downmix(WORD32 downmix_id,WORD32 dec_downmix_id)67 static WORD32 impd_match_downmix(WORD32 downmix_id, WORD32 dec_downmix_id) {
68 WORD32 id_match = 0;
69
70 switch (dec_downmix_id) {
71 case 0:
72 id_match = (downmix_id == 0);
73 break;
74 case 1:
75 id_match = ((downmix_id == 0) || (downmix_id == 0x7F));
76 break;
77 case 2:
78 id_match = (downmix_id == 0x7F);
79 break;
80 case 3:
81 id_match = ((downmix_id != 0) && (downmix_id != 0x7F));
82 break;
83 case 4:
84 id_match = (downmix_id != 0);
85 break;
86 }
87 return id_match;
88 }
89
impd_drc_set_default_config(ia_drc_api_struct * p_obj_drc)90 IA_ERRORCODE impd_drc_set_default_config(ia_drc_api_struct *p_obj_drc) {
91 memset(p_obj_drc, 0, sizeof(*p_obj_drc));
92 p_obj_drc->str_config.bitstream_file_format = 1;
93 p_obj_drc->str_config.dec_type = 0;
94 p_obj_drc->str_config.sub_band_domain_mode = 0;
95 p_obj_drc->str_config.sub_band_count = 0;
96 p_obj_drc->str_config.sub_band_down_sampling_factor = 0;
97 p_obj_drc->str_config.sampling_rate = 0;
98 p_obj_drc->str_config.frame_size = 1024;
99 p_obj_drc->str_config.num_ch_in = -1;
100 p_obj_drc->str_config.num_ch_out = -1;
101 p_obj_drc->str_config.control_parameter_index = -1;
102 p_obj_drc->str_config.peak_limiter = 0;
103 p_obj_drc->str_config.delay_mode = 0;
104 p_obj_drc->str_config.interface_bitstream_present = 1;
105 p_obj_drc->str_config.gain_delay_samples = 0;
106 p_obj_drc->str_config.absorb_delay_on = 1;
107 p_obj_drc->str_config.subband_domain_io_flag = 0;
108 p_obj_drc->str_bit_handler.gain_stream_flag = 1;
109 p_obj_drc->str_config.constant_delay_on = 0;
110 p_obj_drc->str_config.audio_delay_samples = 0;
111 p_obj_drc->str_config.effect_type = 0;
112 p_obj_drc->str_config.target_loudness = -24;
113 p_obj_drc->str_config.loud_norm_flag = 0;
114 memset(&p_obj_drc->str_bit_handler, 0, sizeof(p_obj_drc->str_bit_handler));
115
116 return IA_NO_ERROR;
117 }
118
impd_drc_set_default_bitstream_config(ia_drc_config * pstr_drc_config)119 IA_ERRORCODE impd_drc_set_default_bitstream_config(
120 ia_drc_config *pstr_drc_config) {
121 WORD32 i;
122
123 pstr_drc_config->sample_rate_present = 0;
124 pstr_drc_config->sampling_rate = 0;
125 pstr_drc_config->dwnmix_instructions_count = 0;
126 pstr_drc_config->drc_coefficients_drc_count = 1;
127 pstr_drc_config->drc_instructions_uni_drc_count = 4;
128 pstr_drc_config->drc_instructions_count_plus = 5;
129 pstr_drc_config->drc_description_basic_present = 0;
130 pstr_drc_config->drc_coefficients_basic_count = 0;
131 pstr_drc_config->drc_instructions_basic_count = 0;
132 pstr_drc_config->drc_config_ext_present = 1;
133 pstr_drc_config->apply_drc = 0;
134 pstr_drc_config->str_drc_config_ext.drc_config_ext_type[0] = 2;
135 pstr_drc_config->str_drc_config_ext.ext_bit_size[0] = 345;
136 pstr_drc_config->str_drc_config_ext.parametric_drc_present = 0;
137 pstr_drc_config->str_drc_config_ext.drc_extension_v1_present = 1;
138 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].version = 1;
139 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].drc_location = 1;
140 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count = 4;
141 for (i = 0;
142 i <
143 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count;
144 i++) {
145 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
146 .gain_set_params[i]
147 .gain_interpolation_type = 1;
148 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
149 .gain_set_params[i]
150 .band_count = 1;
151 }
152 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_sequence_count =
153 4;
154 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
155 .gain_set_params_index_for_gain_sequence[0] = 0;
156 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
157 .gain_set_params_index_for_gain_sequence[1] = 1;
158 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
159 .gain_set_params_index_for_gain_sequence[2] = 2;
160 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
161 .gain_set_params_index_for_gain_sequence[3] = 3;
162 pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count_plus =
163 4;
164 pstr_drc_config->str_drc_instruction_str[0].drc_set_id = 1;
165 pstr_drc_config->str_drc_instruction_str[0].drc_set_complexity_level = 2;
166 pstr_drc_config->str_drc_instruction_str[0].drc_location = 1;
167 pstr_drc_config->str_drc_instruction_str[0].dwnmix_id_count = 1;
168 pstr_drc_config->str_drc_instruction_str[0].drc_set_effect = 1;
169 pstr_drc_config->str_drc_instruction_str[0].gain_set_index[1] = 1;
170 pstr_drc_config->str_drc_instruction_str[0]
171 .drc_set_target_loudness_value_lower = -63;
172 pstr_drc_config->str_drc_instruction_str[0].num_drc_ch_groups = 2;
173 pstr_drc_config->str_drc_instruction_str[0]
174 .gain_set_index_for_channel_group[1] = 1;
175 pstr_drc_config->str_drc_instruction_str[0].band_count_of_ch_group[0] = 1;
176 pstr_drc_config->str_drc_instruction_str[0].band_count_of_ch_group[1] = 1;
177 pstr_drc_config->str_drc_instruction_str[0]
178 .gain_interpolation_type_for_channel_group[0] = 1;
179 pstr_drc_config->str_drc_instruction_str[0]
180 .gain_interpolation_type_for_channel_group[1] = 1;
181 pstr_drc_config->str_drc_instruction_str[0]
182 .time_delta_min_for_channel_group[0] = 32;
183 pstr_drc_config->str_drc_instruction_str[0]
184 .time_delta_min_for_channel_group[1] = 32;
185 pstr_drc_config->str_drc_instruction_str[0].channel_group_of_ch[1] = 1;
186 pstr_drc_config->str_drc_instruction_str[0].gain_element_count = 2;
187
188 pstr_drc_config->str_drc_instruction_str[1].drc_set_id = 2;
189 pstr_drc_config->str_drc_instruction_str[1].drc_set_complexity_level = 2;
190 pstr_drc_config->str_drc_instruction_str[1].drc_location = 1;
191 pstr_drc_config->str_drc_instruction_str[1].dwnmix_id_count = 1;
192 pstr_drc_config->str_drc_instruction_str[1].drc_set_effect = 2;
193 pstr_drc_config->str_drc_instruction_str[1].gain_set_index[0] = 1;
194 pstr_drc_config->str_drc_instruction_str[1].gain_set_index[1] = 2;
195 pstr_drc_config->str_drc_instruction_str[1]
196 .drc_set_target_loudness_value_lower = -63;
197 pstr_drc_config->str_drc_instruction_str[1].num_drc_ch_groups = 2;
198 pstr_drc_config->str_drc_instruction_str[1]
199 .gain_set_index_for_channel_group[0] = 1;
200 pstr_drc_config->str_drc_instruction_str[1]
201 .gain_set_index_for_channel_group[1] = 2;
202 pstr_drc_config->str_drc_instruction_str[1].band_count_of_ch_group[0] = 1;
203 pstr_drc_config->str_drc_instruction_str[1].band_count_of_ch_group[1] = 1;
204 pstr_drc_config->str_drc_instruction_str[1]
205 .gain_interpolation_type_for_channel_group[0] = 1;
206 pstr_drc_config->str_drc_instruction_str[1]
207 .gain_interpolation_type_for_channel_group[1] = 1;
208 pstr_drc_config->str_drc_instruction_str[1]
209 .time_delta_min_for_channel_group[0] = 32;
210 pstr_drc_config->str_drc_instruction_str[1]
211 .time_delta_min_for_channel_group[1] = 32;
212 pstr_drc_config->str_drc_instruction_str[1].channel_group_of_ch[1] = 1;
213 pstr_drc_config->str_drc_instruction_str[1].gain_element_count = 2;
214
215 pstr_drc_config->str_drc_instruction_str[2].drc_set_id = 3;
216 pstr_drc_config->str_drc_instruction_str[2].drc_set_complexity_level = 2;
217 pstr_drc_config->str_drc_instruction_str[2].drc_location = 1;
218 pstr_drc_config->str_drc_instruction_str[2].dwnmix_id_count = 1;
219 pstr_drc_config->str_drc_instruction_str[2].drc_set_effect = 4;
220 pstr_drc_config->str_drc_instruction_str[2].gain_set_index[0] = 2;
221 pstr_drc_config->str_drc_instruction_str[2].gain_set_index[1] = 3;
222 pstr_drc_config->str_drc_instruction_str[2]
223 .drc_set_target_loudness_value_lower = -63;
224 pstr_drc_config->str_drc_instruction_str[2].num_drc_ch_groups = 2;
225 pstr_drc_config->str_drc_instruction_str[2]
226 .gain_set_index_for_channel_group[0] = 2;
227 pstr_drc_config->str_drc_instruction_str[2]
228 .gain_set_index_for_channel_group[1] = 3;
229 pstr_drc_config->str_drc_instruction_str[2].band_count_of_ch_group[0] = 1;
230 pstr_drc_config->str_drc_instruction_str[2].band_count_of_ch_group[1] = 1;
231 pstr_drc_config->str_drc_instruction_str[2]
232 .gain_interpolation_type_for_channel_group[0] = 1;
233 pstr_drc_config->str_drc_instruction_str[2]
234 .gain_interpolation_type_for_channel_group[1] = 1;
235 pstr_drc_config->str_drc_instruction_str[2]
236 .time_delta_min_for_channel_group[0] = 32;
237 pstr_drc_config->str_drc_instruction_str[2]
238 .time_delta_min_for_channel_group[1] = 32;
239 pstr_drc_config->str_drc_instruction_str[2].channel_group_of_ch[1] = 1;
240 pstr_drc_config->str_drc_instruction_str[2].gain_element_count = 2;
241
242 pstr_drc_config->str_drc_instruction_str[3].drc_set_id = 4;
243 pstr_drc_config->str_drc_instruction_str[3].drc_set_complexity_level = 2;
244 pstr_drc_config->str_drc_instruction_str[3].drc_location = 1;
245 pstr_drc_config->str_drc_instruction_str[3].dwnmix_id_count = 1;
246 pstr_drc_config->str_drc_instruction_str[3].drc_set_effect = 32;
247 pstr_drc_config->str_drc_instruction_str[3].gain_set_index[0] = 3;
248 pstr_drc_config->str_drc_instruction_str[3].gain_set_index[1] = 0;
249 pstr_drc_config->str_drc_instruction_str[3]
250 .drc_set_target_loudness_value_lower = -63;
251 pstr_drc_config->str_drc_instruction_str[3].num_drc_ch_groups = 2;
252 pstr_drc_config->str_drc_instruction_str[3]
253 .gain_set_index_for_channel_group[0] = 3;
254 pstr_drc_config->str_drc_instruction_str[3]
255 .gain_set_index_for_channel_group[1] = 0;
256 pstr_drc_config->str_drc_instruction_str[3].band_count_of_ch_group[0] = 1;
257 pstr_drc_config->str_drc_instruction_str[3].band_count_of_ch_group[1] = 1;
258 pstr_drc_config->str_drc_instruction_str[3]
259 .gain_interpolation_type_for_channel_group[0] = 1;
260 pstr_drc_config->str_drc_instruction_str[3]
261 .gain_interpolation_type_for_channel_group[1] = 1;
262 pstr_drc_config->str_drc_instruction_str[3]
263 .time_delta_min_for_channel_group[0] = 32;
264 pstr_drc_config->str_drc_instruction_str[3]
265 .time_delta_min_for_channel_group[1] = 32;
266 pstr_drc_config->str_drc_instruction_str[3].channel_group_of_ch[1] = 1;
267 pstr_drc_config->str_drc_instruction_str[3].gain_element_count = 2;
268
269 pstr_drc_config->str_drc_instruction_str[4].drc_set_id = -1;
270 pstr_drc_config->str_drc_instruction_str[4].dwnmix_id_count = 1;
271 pstr_drc_config->channel_layout.base_channel_count = 2;
272
273 return IA_NO_ERROR;
274 }
275
impd_drc_set_struct_pointer(ia_drc_api_struct * p_obj_drc)276 IA_ERRORCODE impd_drc_set_struct_pointer(ia_drc_api_struct *p_obj_drc) {
277 pUWORD8 persistent_ptr = (pUWORD8)p_obj_drc->p_state->persistent_ptr;
278
279 UWORD64 persistent_size_consumed = 0;
280 p_obj_drc->str_payload.pstr_bitstream_dec =
281 (ia_drc_bits_dec_struct *)persistent_ptr;
282 persistent_ptr += sizeof(ia_drc_bits_dec_struct);
283
284 p_obj_drc->str_payload.pstr_gain_dec[0] =
285 (ia_drc_gain_dec_struct *)persistent_ptr;
286 persistent_ptr += sizeof(ia_drc_gain_dec_struct);
287
288 p_obj_drc->str_payload.pstr_gain_dec[1] =
289 (ia_drc_gain_dec_struct *)persistent_ptr;
290 persistent_ptr += sizeof(ia_drc_gain_dec_struct);
291
292 p_obj_drc->str_payload.pstr_loudness_info =
293 (ia_drc_loudness_info_set_struct *)persistent_ptr;
294 persistent_ptr += sizeof(ia_drc_loudness_info_set_struct);
295
296 p_obj_drc->str_payload.pstr_drc_gain = (ia_drc_gain_struct *)persistent_ptr;
297 persistent_ptr += sizeof(ia_drc_gain_struct);
298
299 p_obj_drc->str_payload.pstr_drc_interface =
300 (ia_drc_interface_struct *)persistent_ptr;
301 persistent_ptr += sizeof(ia_drc_interface_struct);
302
303 p_obj_drc->str_payload.pstr_drc_config = (ia_drc_config *)persistent_ptr;
304 persistent_ptr += sizeof(ia_drc_config);
305
306 p_obj_drc->str_payload.pstr_selection_proc =
307 (ia_drc_sel_pro_struct *)persistent_ptr;
308 persistent_ptr += sizeof(ia_drc_sel_pro_struct);
309
310 p_obj_drc->str_bit_handler.it_bit_buf = (UWORD8 *)persistent_ptr;
311 persistent_ptr += MAX_DRC_BS_BUF_SIZE;
312
313 p_obj_drc->str_payload.pstr_drc_sel_proc_params =
314 (ia_drc_sel_proc_params_struct *)persistent_ptr;
315 persistent_ptr += sizeof(ia_drc_sel_proc_params_struct);
316
317 p_obj_drc->str_payload.pstr_drc_sel_proc_output =
318 (ia_drc_sel_proc_output_struct *)persistent_ptr;
319 persistent_ptr += sizeof(ia_drc_sel_proc_output_struct);
320
321 p_obj_drc->str_bit_handler.bitstream_drc_config = (UWORD8 *)persistent_ptr;
322 persistent_ptr += MAX_BS_BUF_SIZE;
323
324 p_obj_drc->str_bit_handler.bitstream_loudness_info = (UWORD8 *)persistent_ptr;
325 persistent_ptr += MAX_BS_BUF_SIZE;
326
327 p_obj_drc->str_bit_handler.bitstream_unidrc_interface =
328 (UWORD8 *)persistent_ptr;
329 persistent_ptr += MAX_BS_BUF_SIZE;
330
331 p_obj_drc->str_payload.pstr_peak_limiter =
332 (ia_drc_peak_limiter_struct *)persistent_ptr;
333 persistent_ptr += sizeof(ia_drc_peak_limiter_struct);
334
335 p_obj_drc->str_payload.pstr_peak_limiter->buffer = (FLOAT32 *)persistent_ptr;
336 persistent_ptr += PEAK_LIM_BUF_SIZE;
337
338 p_obj_drc->str_payload.pstr_qmf_filter =
339 (ia_drc_qmf_filt_struct *)persistent_ptr;
340 persistent_ptr += sizeof(ia_drc_qmf_filt_struct);
341
342 p_obj_drc->str_payload.pstr_qmf_filter->ana_buff = (FLOAT64 *)persistent_ptr;
343 persistent_ptr += ANALY_BUF_SIZE;
344
345 p_obj_drc->str_payload.pstr_qmf_filter->syn_buff = (FLOAT64 *)persistent_ptr;
346 persistent_ptr += SYNTH_BUF_SIZE;
347
348 persistent_size_consumed =
349 (UWORD64)(persistent_ptr - (pUWORD8)p_obj_drc->p_state->persistent_ptr);
350
351 if ((UWORD64)p_obj_drc->p_mem_info[IA_MEMTYPE_PERSIST].ui_size <
352 persistent_size_consumed)
353 return IA_FATAL_ERROR;
354
355 p_obj_drc->p_state->persistent_ptr = (pVOID)persistent_ptr;
356 return IA_NO_ERROR;
357 }
358
init_qmf_filt_bank(ia_drc_qmf_filt_struct * qmf_filt)359 VOID init_qmf_filt_bank(ia_drc_qmf_filt_struct *qmf_filt) {
360 WORD32 l, k;
361
362 FLOAT64 gain_ana = 64.0 / QMF_FILT_RESOLUTION;
363 FLOAT64 gain_syn = 1.0 / 64.0;
364 for (l = 0; l < 2 * QMF_FILT_RESOLUTION; l++) {
365 for (k = 0; k < QMF_FILT_RESOLUTION; k++) {
366 qmf_filt->syn_tab_real[l][k] =
367 gain_syn * cos((0.0245436926) * (k + 0.5) * (2 * l - 255.0));
368 qmf_filt->syn_tab_imag[l][k] =
369 gain_syn * sin((0.0245436926) * (k + 0.5) * (2 * l - 255.0));
370 qmf_filt->ana_tab_real[k][l] =
371 gain_ana * cos((0.0245436926) * (k + 0.5) * (2 * l - 1.0));
372 qmf_filt->ana_tab_imag[k][l] =
373 gain_ana * sin((0.0245436926) * (k + 0.5) * (2 * l - 1.0));
374 }
375 }
376 }
377
impd_drc_init(ia_drc_api_struct * p_obj_drc)378 IA_ERRORCODE impd_drc_init(ia_drc_api_struct *p_obj_drc) {
379 IA_ERRORCODE err_code = IA_NO_ERROR;
380 WORD32 i, j;
381
382 pVOID persistent_ptr = p_obj_drc->p_state->persistent_ptr;
383
384 WORD32 decDownmixIdList[NUM_GAIN_DEC_INSTANCES] = {0, 4};
385
386 p_obj_drc->p_state->delay_in_output = 0;
387 p_obj_drc->str_payload.pstr_selection_proc->first_frame = 1;
388
389 impd_create_init_bit_buf(&p_obj_drc->str_bit_buf,
390 p_obj_drc->str_bit_handler.it_bit_buf,
391 p_obj_drc->str_bit_handler.num_bytes_bs / 8);
392
393 p_obj_drc->pstr_bit_buf = &p_obj_drc->str_bit_buf;
394
395 err_code = impd_init_drc_bitstream_dec(
396 p_obj_drc->str_payload.pstr_bitstream_dec,
397 p_obj_drc->str_config.sampling_rate, p_obj_drc->str_config.frame_size,
398 p_obj_drc->str_config.delay_mode, -1, 0);
399 if (err_code != IA_NO_ERROR) return err_code;
400
401 for (i = 0; i < NUM_GAIN_DEC_INSTANCES; i++) {
402 err_code = impd_init_drc_decode(p_obj_drc->str_config.frame_size,
403 p_obj_drc->str_config.sampling_rate,
404 p_obj_drc->str_config.gain_delay_samples,
405 p_obj_drc->str_config.delay_mode,
406 p_obj_drc->str_config.sub_band_domain_mode,
407 p_obj_drc->str_payload.pstr_gain_dec[i]);
408 if (err_code != IA_NO_ERROR) return err_code;
409 }
410
411 err_code = impd_drc_dec_interface_add_effect_type(
412 p_obj_drc->str_payload.pstr_drc_interface,
413 p_obj_drc->str_config.effect_type, p_obj_drc->str_config.target_loudness,
414 p_obj_drc->str_config.loud_norm_flag);
415
416 if (err_code != IA_NO_ERROR) return err_code;
417
418 err_code = impd_drc_uni_selction_proc_init(
419 p_obj_drc->str_payload.pstr_selection_proc, 0,
420 p_obj_drc->str_payload.pstr_drc_interface,
421 p_obj_drc->str_config.sub_band_domain_mode);
422 if (err_code != IA_NO_ERROR) return err_code;
423
424 if (p_obj_drc->str_payload.pstr_drc_interface
425 ->loudness_norm_parameter_interface_flag &&
426 p_obj_drc->str_payload.pstr_drc_interface->loudness_norm_param_interface
427 .peak_limiter) {
428 p_obj_drc->str_config.peak_limiter = 1;
429 }
430
431 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_album_count = 0;
432 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_count = 0;
433 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_set_ext_present = 0;
434 p_obj_drc->p_state->ui_exe_done = 0;
435
436 err_code = impd_process_drc_bitstream_dec_config(
437 p_obj_drc->str_payload.pstr_bitstream_dec, p_obj_drc->pstr_bit_buf,
438 p_obj_drc->str_payload.pstr_drc_config,
439 &p_obj_drc->str_bit_handler.bitstream_drc_config[0],
440 p_obj_drc->str_bit_handler.num_bytes_bs_drc_config);
441
442 if (err_code == 1) {
443 memset(p_obj_drc->str_payload.pstr_drc_config, 0, sizeof(ia_drc_config));
444 err_code = impd_drc_set_default_bitstream_config(
445 p_obj_drc->str_payload.pstr_drc_config);
446 p_obj_drc->str_payload.pstr_drc_config->channel_layout.base_channel_count =
447 p_obj_drc->str_config.num_ch_in;
448 }
449
450 if (err_code != IA_NO_ERROR) return err_code;
451 err_code = impd_process_drc_bitstream_dec_loudness_info_set(
452 p_obj_drc->pstr_bit_buf, p_obj_drc->str_payload.pstr_loudness_info,
453 &p_obj_drc->str_bit_handler.bitstream_loudness_info[0],
454 p_obj_drc->str_bit_handler.num_bytes_bs_loudness_info);
455 if (err_code != IA_NO_ERROR) return err_code;
456
457 err_code = impd_drc_uni_sel_proc_process(
458 p_obj_drc->str_payload.pstr_selection_proc,
459 p_obj_drc->str_payload.pstr_drc_config,
460 p_obj_drc->str_payload.pstr_loudness_info,
461 p_obj_drc->str_payload.pstr_drc_sel_proc_output);
462 if (err_code != IA_NO_ERROR) return err_code;
463
464 for (i = 0; i < NUM_GAIN_DEC_INSTANCES; i++) {
465 WORD32 audio_num_chan = 0;
466 WORD32 numMatchingDrcSets = 0;
467 WORD32 matchingDrcSetIds[3], matchingDownmixIds[3];
468 for (j = 0;
469 j < p_obj_drc->str_payload.pstr_drc_sel_proc_output->num_sel_drc_sets;
470 j++) {
471 if (impd_match_downmix(p_obj_drc->str_payload.pstr_drc_sel_proc_output
472 ->sel_downmix_ids[j],
473 decDownmixIdList[i])) {
474 matchingDrcSetIds[numMatchingDrcSets] =
475 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_drc_set_ids[j];
476 matchingDownmixIds[numMatchingDrcSets] =
477 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_downmix_ids[j];
478 numMatchingDrcSets++;
479 }
480 }
481 if (i == 0) {
482 if (p_obj_drc->str_config.num_ch_in !=
483 p_obj_drc->str_payload.pstr_drc_sel_proc_output->base_channel_count)
484
485 return -1;
486 audio_num_chan = p_obj_drc->str_config.num_ch_in;
487 } else if (i == 1) {
488 p_obj_drc->str_config.num_ch_out =
489 p_obj_drc->str_payload.pstr_drc_sel_proc_output->target_channel_count;
490 audio_num_chan = p_obj_drc->str_config.num_ch_out;
491 }
492
493 err_code = impd_init_drc_decode_post_config(
494 audio_num_chan, matchingDrcSetIds, matchingDownmixIds,
495 numMatchingDrcSets,
496 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_eq_set_ids[i]
497
498 ,
499 p_obj_drc->str_payload.pstr_gain_dec[i],
500 p_obj_drc->str_payload.pstr_drc_config,
501 p_obj_drc->str_payload.pstr_loudness_info, &persistent_ptr);
502 if (err_code) return err_code;
503
504 impd_get_parametric_drc_delay(
505 p_obj_drc->str_payload.pstr_gain_dec[i],
506 p_obj_drc->str_payload.pstr_drc_config,
507 &p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance,
508 &p_obj_drc->str_config.parametric_drc_delay_max);
509 impd_get_eq_delay(p_obj_drc->str_payload.pstr_gain_dec[i],
510 p_obj_drc->str_payload.pstr_drc_config,
511 &p_obj_drc->str_config.eq_delay_gain_dec_instance,
512 &p_obj_drc->str_config.eq_delay_max);
513 p_obj_drc->str_config.parametric_drc_delay +=
514 p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance;
515 p_obj_drc->str_config.eq_delay +=
516 p_obj_drc->str_config.eq_delay_gain_dec_instance;
517 }
518
519 {
520 if (p_obj_drc->str_config.parametric_drc_delay_max == -1) {
521 p_obj_drc->str_config.parametric_drc_delay_max =
522 PARAMETRIC_DRC_DELAY_MAX_DEFAULT;
523 }
524 if (p_obj_drc->str_config.eq_delay_max == -1) {
525 p_obj_drc->str_config.eq_delay_max = EQ_DELAY_MAX_DEFAULT;
526 }
527
528 if (!p_obj_drc->str_config.constant_delay_on) {
529 p_obj_drc->p_state->delay_in_output +=
530 p_obj_drc->str_config.parametric_drc_delay +
531 p_obj_drc->str_config.eq_delay +
532 p_obj_drc->str_config.audio_delay_samples;
533 p_obj_drc->str_config.delay_line_samples =
534 p_obj_drc->str_config.audio_delay_samples;
535
536 if (!p_obj_drc->str_config.absorb_delay_on) {
537 p_obj_drc->p_state->delay_in_output = 0;
538 }
539 } else {
540 p_obj_drc->p_state->delay_in_output +=
541 p_obj_drc->str_config.parametric_drc_delay_max +
542 p_obj_drc->str_config.eq_delay_max +
543 p_obj_drc->str_config.audio_delay_samples;
544 p_obj_drc->str_config.delay_line_samples =
545 p_obj_drc->p_state->delay_in_output -
546 p_obj_drc->str_config.parametric_drc_delay +
547 p_obj_drc->str_config.eq_delay;
548
549 if (!p_obj_drc->str_config.absorb_delay_on) {
550 p_obj_drc->p_state->delay_in_output = 0;
551 }
552 }
553 }
554 if (p_obj_drc->str_config.dec_type == 1) {
555 init_qmf_filt_bank(p_obj_drc->str_payload.pstr_qmf_filter);
556 }
557
558 if (p_obj_drc->str_config.peak_limiter) {
559 err_code = impd_peak_limiter_init(
560 p_obj_drc->str_payload.pstr_peak_limiter, DEFAULT_ATTACK_TIME_MS,
561 DEFAULT_RELEASE_TIME_MS, LIM_DEFAULT_THRESHOLD,
562 p_obj_drc->str_config.num_ch_out, p_obj_drc->str_config.sampling_rate,
563 p_obj_drc->str_payload.pstr_peak_limiter->buffer);
564 if (err_code) return (err_code);
565 }
566
567 return IA_NO_ERROR;
568 }
569