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