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 SIZE_T persistent_ptr = (SIZE_T)p_obj_drc->p_state->persistent_ptr;
278
279 SIZE_T persistent_size_consumed = 0;
280 p_obj_drc->str_payload.pstr_bitstream_dec =
281 (ia_drc_bits_dec_struct *)persistent_ptr;
282 persistent_ptr = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = persistent_ptr + MAX_BS_BUF_SIZE;
323
324 p_obj_drc->str_bit_handler.bitstream_loudness_info = (UWORD8 *)persistent_ptr;
325 persistent_ptr = persistent_ptr + MAX_BS_BUF_SIZE;
326
327 p_obj_drc->str_bit_handler.bitstream_unidrc_interface =
328 (UWORD8 *)persistent_ptr;
329 persistent_ptr = 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 = persistent_ptr + sizeof(ia_drc_peak_limiter_struct);
334
335 p_obj_drc->str_payload.pstr_peak_limiter->buffer =
336 (FLOAT32 *)((SIZE_T)p_obj_drc->str_payload.pstr_peak_limiter +
337 sizeof(ia_drc_peak_limiter_struct));
338 persistent_ptr = persistent_ptr + PEAK_LIM_BUF_SIZE;
339
340 p_obj_drc->str_payload.pstr_qmf_filter =
341 (ia_drc_qmf_filt_struct *)persistent_ptr;
342 persistent_ptr = persistent_ptr + sizeof(ia_drc_qmf_filt_struct);
343
344 p_obj_drc->str_payload.pstr_qmf_filter->ana_buff = (FLOAT64 *)persistent_ptr;
345 persistent_ptr = persistent_ptr + ANALY_BUF_SIZE;
346
347 p_obj_drc->str_payload.pstr_qmf_filter->syn_buff = (FLOAT64 *)persistent_ptr;
348 persistent_ptr = persistent_ptr + SYNTH_BUF_SIZE;
349 persistent_size_consumed =
350 (UWORD32)persistent_ptr - (UWORD32)p_obj_drc->p_state->persistent_ptr;
351 if (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 struct ia_bit_buf_struct *it_bit_buff;
385
386 WORD32 decDownmixIdList[NUM_GAIN_DEC_INSTANCES] = {0, 4};
387
388 p_obj_drc->p_state->delay_in_output = 0;
389 p_obj_drc->str_payload.pstr_selection_proc->first_frame = 1;
390
391 p_obj_drc->pstr_bit_buf = impd_create_init_bit_buf(
392 &p_obj_drc->str_bit_buf, p_obj_drc->str_bit_handler.it_bit_buf,
393 p_obj_drc->str_bit_handler.num_bytes_bs / 8);
394 it_bit_buff = p_obj_drc->pstr_bit_buf;
395
396 err_code = impd_init_drc_bitstream_dec(
397 p_obj_drc->str_payload.pstr_bitstream_dec,
398 p_obj_drc->str_config.sampling_rate, p_obj_drc->str_config.frame_size,
399 p_obj_drc->str_config.delay_mode, -1, 0);
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 }
409
410 err_code = impd_drc_dec_interface_add_effect_type(
411 p_obj_drc->str_payload.pstr_drc_interface,
412 p_obj_drc->str_config.effect_type, p_obj_drc->str_config.target_loudness,
413 p_obj_drc->str_config.loud_norm_flag);
414
415 if (err_code != IA_NO_ERROR) return err_code;
416
417 err_code = impd_drc_uni_selction_proc_init(
418 p_obj_drc->str_payload.pstr_selection_proc, 0,
419 p_obj_drc->str_payload.pstr_drc_interface,
420 p_obj_drc->str_config.sub_band_domain_mode);
421 if (err_code != IA_NO_ERROR) return err_code;
422
423 if (p_obj_drc->str_payload.pstr_drc_interface
424 ->loudness_norm_parameter_interface_flag &&
425 p_obj_drc->str_payload.pstr_drc_interface->loudness_norm_param_interface
426 .peak_limiter) {
427 p_obj_drc->str_config.peak_limiter = 1;
428 }
429
430 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_album_count = 0;
431 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_count = 0;
432 p_obj_drc->str_payload.pstr_loudness_info->loudness_info_set_ext_present = 0;
433 p_obj_drc->p_state->ui_exe_done = 0;
434
435 err_code = impd_process_drc_bitstream_dec_config(
436 p_obj_drc->str_payload.pstr_bitstream_dec, p_obj_drc->pstr_bit_buf,
437 p_obj_drc->str_payload.pstr_drc_config,
438 &p_obj_drc->str_bit_handler.bitstream_drc_config[0],
439 p_obj_drc->str_bit_handler.num_bytes_bs_drc_config);
440
441 if (err_code == 1) {
442 memset(p_obj_drc->str_payload.pstr_drc_config, 0, sizeof(ia_drc_config));
443 err_code = impd_drc_set_default_bitstream_config(
444 p_obj_drc->str_payload.pstr_drc_config);
445 p_obj_drc->str_payload.pstr_drc_config->channel_layout.base_channel_count =
446 p_obj_drc->str_config.num_ch_in;
447 }
448
449 if (err_code != IA_NO_ERROR) return err_code;
450 err_code = impd_process_drc_bitstream_dec_loudness_info_set(
451 p_obj_drc->pstr_bit_buf, p_obj_drc->str_payload.pstr_loudness_info,
452 &p_obj_drc->str_bit_handler.bitstream_loudness_info[0],
453 p_obj_drc->str_bit_handler.num_bytes_bs_loudness_info);
454 if (err_code != IA_NO_ERROR) return err_code;
455
456 err_code = impd_drc_uni_sel_proc_process(
457 p_obj_drc->str_payload.pstr_selection_proc,
458 p_obj_drc->str_payload.pstr_drc_config,
459 p_obj_drc->str_payload.pstr_loudness_info,
460 p_obj_drc->str_payload.pstr_drc_sel_proc_output);
461 if (err_code != IA_NO_ERROR) return err_code;
462
463 for (i = 0; i < NUM_GAIN_DEC_INSTANCES; i++) {
464 WORD32 audio_num_chan = 0;
465 WORD32 numMatchingDrcSets = 0;
466 WORD32 matchingDrcSetIds[3], matchingDownmixIds[3];
467 for (j = 0;
468 j < p_obj_drc->str_payload.pstr_drc_sel_proc_output->num_sel_drc_sets;
469 j++) {
470 if (impd_match_downmix(p_obj_drc->str_payload.pstr_drc_sel_proc_output
471 ->sel_downmix_ids[j],
472 decDownmixIdList[i])) {
473 matchingDrcSetIds[numMatchingDrcSets] =
474 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_drc_set_ids[j];
475 matchingDownmixIds[numMatchingDrcSets] =
476 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_downmix_ids[j];
477 numMatchingDrcSets++;
478 }
479 }
480 if (i == 0) {
481 if (p_obj_drc->str_config.num_ch_in !=
482 p_obj_drc->str_payload.pstr_drc_sel_proc_output->base_channel_count)
483
484 return -1;
485 audio_num_chan = p_obj_drc->str_config.num_ch_in;
486 } else if (i == 1) {
487 p_obj_drc->str_config.num_ch_out =
488 p_obj_drc->str_payload.pstr_drc_sel_proc_output->target_channel_count;
489 audio_num_chan = p_obj_drc->str_config.num_ch_out;
490 }
491
492 err_code = impd_init_drc_decode_post_config(
493 audio_num_chan, matchingDrcSetIds, matchingDownmixIds,
494 numMatchingDrcSets,
495 p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_eq_set_ids[i]
496
497 ,
498 p_obj_drc->str_payload.pstr_gain_dec[i],
499 p_obj_drc->str_payload.pstr_drc_config,
500 p_obj_drc->str_payload.pstr_loudness_info, &persistent_ptr);
501
502 impd_get_parametric_drc_delay(
503 p_obj_drc->str_payload.pstr_gain_dec[i],
504 p_obj_drc->str_payload.pstr_drc_config,
505 &p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance,
506 &p_obj_drc->str_config.parametric_drc_delay_max);
507 impd_get_eq_delay(p_obj_drc->str_payload.pstr_gain_dec[i],
508 p_obj_drc->str_payload.pstr_drc_config,
509 &p_obj_drc->str_config.eq_delay_gain_dec_instance,
510 &p_obj_drc->str_config.eq_delay_max);
511 p_obj_drc->str_config.parametric_drc_delay +=
512 p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance;
513 p_obj_drc->str_config.eq_delay +=
514 p_obj_drc->str_config.eq_delay_gain_dec_instance;
515 }
516
517 {
518 if (p_obj_drc->str_config.parametric_drc_delay_max == -1) {
519 p_obj_drc->str_config.parametric_drc_delay_max =
520 PARAMETRIC_DRC_DELAY_MAX_DEFAULT;
521 }
522 if (p_obj_drc->str_config.eq_delay_max == -1) {
523 p_obj_drc->str_config.eq_delay_max = EQ_DELAY_MAX_DEFAULT;
524 }
525
526 if (!p_obj_drc->str_config.constant_delay_on) {
527 p_obj_drc->p_state->delay_in_output +=
528 p_obj_drc->str_config.parametric_drc_delay +
529 p_obj_drc->str_config.eq_delay +
530 p_obj_drc->str_config.audio_delay_samples;
531 p_obj_drc->str_config.delay_line_samples =
532 p_obj_drc->str_config.audio_delay_samples;
533
534 if (!p_obj_drc->str_config.absorb_delay_on) {
535 p_obj_drc->p_state->delay_in_output = 0;
536 }
537 } else {
538 p_obj_drc->p_state->delay_in_output +=
539 p_obj_drc->str_config.parametric_drc_delay_max +
540 p_obj_drc->str_config.eq_delay_max +
541 p_obj_drc->str_config.audio_delay_samples;
542 p_obj_drc->str_config.delay_line_samples =
543 p_obj_drc->p_state->delay_in_output -
544 p_obj_drc->str_config.parametric_drc_delay +
545 p_obj_drc->str_config.eq_delay;
546
547 if (!p_obj_drc->str_config.absorb_delay_on) {
548 p_obj_drc->p_state->delay_in_output = 0;
549 }
550 }
551 }
552 if (p_obj_drc->str_config.dec_type == 1) {
553 init_qmf_filt_bank(p_obj_drc->str_payload.pstr_qmf_filter);
554 }
555
556 if (p_obj_drc->str_config.peak_limiter) {
557 impd_peak_limiter_init(
558 p_obj_drc->str_payload.pstr_peak_limiter, DEFAULT_ATTACK_TIME_MS,
559 DEFAULT_RELEASE_TIME_MS, LIM_DEFAULT_THRESHOLD,
560 p_obj_drc->str_config.num_ch_out, p_obj_drc->str_config.sampling_rate,
561 p_obj_drc->str_payload.pstr_peak_limiter->buffer);
562 }
563
564 return IA_NO_ERROR;
565 }
566