/src/libxaac/encoder/drc_src/impd_drc_api.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2023 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | |
21 | | #include <string.h> |
22 | | #include "ixheaac_type_def.h" |
23 | | #include "ixheaac_error_standards.h" |
24 | | #include "ixheaace_error_codes.h" |
25 | | |
26 | | #include "iusace_bitbuffer.h" |
27 | | #include "iusace_cnst.h" |
28 | | #include "impd_drc_common_enc.h" |
29 | | #include "impd_drc_uni_drc.h" |
30 | | #include "impd_drc_tables.h" |
31 | | #include "impd_drc_api.h" |
32 | | #include "impd_drc_uni_drc_eq.h" |
33 | | #include "impd_drc_uni_drc_filter_bank.h" |
34 | | #include "impd_drc_gain_enc.h" |
35 | | #include "impd_drc_struct_def.h" |
36 | | #include "impd_drc_enc.h" |
37 | | |
38 | | #define IMPD_DRC_BOUND_CHECK(var, lower_bound, upper_bound) \ |
39 | 1.32M | { \ |
40 | 1.32M | var = MIN(var, upper_bound); \ |
41 | 1.32M | var = MAX(var, lower_bound); \ |
42 | 1.32M | } |
43 | | |
44 | 2.14k | IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config) { |
45 | 2.14k | LOOPIDX i, j, k; |
46 | 2.14k | WORD32 curr_start_subband_idx, next_start_subband_idx; |
47 | 2.14k | ia_drc_uni_drc_config_struct *pstr_uni_drc_config = &pstr_inp_config->str_uni_drc_config; |
48 | 2.14k | ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set = |
49 | 2.14k | &pstr_inp_config->str_enc_loudness_info_set; |
50 | | |
51 | 2.14k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->drc_instructions_uni_drc_count, 0, |
52 | 2.14k | MAX_DRC_INSTRUCTIONS_COUNT); |
53 | 12.7k | for (i = 0; i < pstr_uni_drc_config->drc_instructions_uni_drc_count; i++) { |
54 | 10.6k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_id, 0, |
55 | 10.6k | MAX_DRC_SET_ID); |
56 | 10.6k | IMPD_DRC_BOUND_CHECK( |
57 | 10.6k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].additional_downmix_id_count, 0, |
58 | 10.6k | ADDITIONAL_DOWNMIX_ID_COUNT_MAX); |
59 | 10.6k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_location, 0, |
60 | 10.6k | MAX_DRC_LOCATION); |
61 | 10.6k | IMPD_DRC_BOUND_CHECK( |
62 | 10.6k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_target_loudness_value_upper, |
63 | 10.6k | MIN_DRC_TARGET_LOUDNESS, 0); |
64 | 10.6k | IMPD_DRC_BOUND_CHECK( |
65 | 10.6k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_target_loudness_value_lower, |
66 | 10.6k | MIN_DRC_TARGET_LOUDNESS, 0); |
67 | 95.4k | for (j = 0; j < MAX_CHANNEL_COUNT; j++) { |
68 | 84.8k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i].gain_set_index[j], |
69 | 84.8k | 0, GAIN_SET_COUNT_MAX - 1); |
70 | 84.8k | } |
71 | 10.6k | IMPD_DRC_BOUND_CHECK( |
72 | 10.6k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].num_drc_channel_groups, 0, |
73 | 10.6k | MAX_CHANNEL_GROUP_COUNT); |
74 | 41.0k | for (j = 0; j < pstr_uni_drc_config->str_drc_instructions_uni_drc[i].num_drc_channel_groups; |
75 | 30.4k | j++) { |
76 | 30.4k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i] |
77 | 30.4k | .str_gain_modifiers[j] |
78 | 30.4k | .attenuation_scaling[0], |
79 | 30.4k | 0, MAX_ATTENUATION_SCALING); |
80 | 30.4k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i] |
81 | 30.4k | .str_gain_modifiers[j] |
82 | 30.4k | .amplification_scaling[0], |
83 | 30.4k | 0, MAX_AMPLIFICATION_SCALING); |
84 | 30.4k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i] |
85 | 30.4k | .str_gain_modifiers[j] |
86 | 30.4k | .gain_offset[0], |
87 | 30.4k | MIN_DRC_GAIN_OFFSET, MAX_DRC_GAIN_OFFSET); |
88 | 30.4k | } |
89 | 10.6k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i].limiter_peak_target, |
90 | 10.6k | MIN_LIMITER_PEAK_TARGET, 0.0f); |
91 | 10.6k | #ifdef LOUDNESS_LEVELING_SUPPORT |
92 | 10.6k | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_effect & |
93 | 10.6k | EFFECT_BIT_DUCK_SELF) { |
94 | 4.72k | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i].leveling_present != 0 && |
95 | 3.19k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].leveling_present != 1) { |
96 | 0 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].leveling_present = 0; |
97 | 0 | } |
98 | 4.72k | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present != 0 && |
99 | 3.34k | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present != 1) { |
100 | 0 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present = 0; |
101 | 0 | } |
102 | 4.72k | } |
103 | 10.6k | #endif |
104 | 10.6k | } |
105 | | |
106 | 2.14k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->drc_coefficients_uni_drc_count, 0, |
107 | 2.14k | MAX_DRC_COEFF_COUNT); |
108 | 4.29k | for (i = 0; i < pstr_uni_drc_config->drc_coefficients_uni_drc_count; i++) { |
109 | 2.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].drc_location, 0, |
110 | 2.51k | MAX_DRC_LOCATION); |
111 | 2.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].gain_set_count, 0, |
112 | 2.51k | MAX_CHANNEL_GROUP_COUNT); |
113 | 5.66k | for (j = 0; j < pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].gain_set_count; j++) { |
114 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
115 | 3.51k | .str_gain_set_params[j] |
116 | 3.51k | .gain_coding_profile, |
117 | 3.51k | 0, MAX_GAIN_CODING_PROFILE); |
118 | 3.51k | IMPD_DRC_BOUND_CHECK( |
119 | 3.51k | pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count, |
120 | 3.51k | 0, MAX_BAND_COUNT); |
121 | 3.51k | for (k = 0; |
122 | 7.03k | k < |
123 | 7.03k | pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count; |
124 | 3.51k | k++) { |
125 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
126 | 3.51k | .str_gain_set_params[j] |
127 | 3.51k | .gain_params[k] |
128 | 3.51k | .nb_points, |
129 | 3.51k | 0, MAX_GAIN_POINTS); |
130 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
131 | 3.51k | .str_gain_set_params[j] |
132 | 3.51k | .gain_params[k] |
133 | 3.51k | .drc_characteristic, |
134 | 3.51k | 0, MAX_DRC_CHARACTERISTIC_VALUE); |
135 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
136 | 3.51k | .str_gain_set_params[j] |
137 | 3.51k | .gain_params[k] |
138 | 3.51k | .crossover_freq_index, |
139 | 3.51k | 0, MAX_CROSSOVER_FREQ_INDEX); |
140 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
141 | 3.51k | .str_gain_set_params[j] |
142 | 3.51k | .gain_params[k] |
143 | 3.51k | .start_sub_band_index, |
144 | 3.51k | 0, STFT256_HOP_SIZE - 1); |
145 | 3.51k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
146 | 3.51k | .str_gain_set_params[j] |
147 | 3.51k | .gain_params[k] |
148 | 3.51k | .width, |
149 | 3.51k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
150 | 143k | for (WORD32 m = 0; m < pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
151 | 143k | .str_gain_set_params[j] |
152 | 143k | .gain_params[k] |
153 | 143k | .nb_points; |
154 | 139k | m++) { |
155 | 139k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
156 | 139k | .str_gain_set_params[j] |
157 | 139k | .gain_params[k] |
158 | 139k | .gain_points[m] |
159 | 139k | .x, |
160 | 139k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
161 | 139k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
162 | 139k | .str_gain_set_params[j] |
163 | 139k | .gain_params[k] |
164 | 139k | .gain_points[m] |
165 | 139k | .y, |
166 | 139k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
167 | 139k | } |
168 | 3.51k | } |
169 | 3.93k | for (k = 0; k < pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
170 | 3.93k | .str_gain_set_params[j] |
171 | 3.93k | .band_count - |
172 | 3.93k | 1; |
173 | 3.51k | k++) { |
174 | 785 | curr_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
175 | 785 | .str_gain_set_params[j] |
176 | 785 | .gain_params[k] |
177 | 785 | .start_sub_band_index; |
178 | 785 | next_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i] |
179 | 785 | .str_gain_set_params[j] |
180 | 785 | .gain_params[k + 1] |
181 | 785 | .start_sub_band_index; |
182 | | /* It is assumed that the start index of a subband is greater than |
183 | | the start index of its previous subbands for a multiband */ |
184 | 785 | if (next_start_subband_idx <= curr_start_subband_idx) { |
185 | 365 | return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_SUBBAND_INDEX; |
186 | 365 | } |
187 | 785 | } |
188 | 3.51k | } |
189 | 2.51k | } |
190 | 1.78k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->downmix_instructions_count, 0, |
191 | 1.78k | MAX_DOWNMIX_INSTRUCTION_COUNT); |
192 | | |
193 | 1.78k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->loudness_info_count, 0, |
194 | 1.78k | MAX_LOUDNESS_INFO_COUNT); |
195 | 5.43k | for (i = 0; i < pstr_enc_loudness_info_set->loudness_info_count; i++) { |
196 | 3.65k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info[i].sample_peak_level, |
197 | 3.65k | MIN_SAMPLE_PEAK_LEVEL, MAX_SAMPLE_PEAK_LEVEL); |
198 | 3.65k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info[i].true_peak_level, |
199 | 3.65k | MIN_TRUE_PEAK_LEVEL, MAX_TRUE_PEAK_LEVEL); |
200 | 3.65k | IMPD_DRC_BOUND_CHECK( |
201 | 3.65k | pstr_enc_loudness_info_set->str_loudness_info[i].true_peak_level_measurement_system, 0, |
202 | 3.65k | MAX_MEASUREMENT_SYSTEM_TYPE); |
203 | 3.65k | IMPD_DRC_BOUND_CHECK( |
204 | 3.65k | pstr_enc_loudness_info_set->str_loudness_info[i].true_peak_level_reliability, 0, |
205 | 3.65k | MAX_RELIABILITY_TYPE); |
206 | 3.65k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info[i].measurement_count, 0, |
207 | 3.65k | MAX_MEASUREMENT_COUNT); |
208 | 19.7k | for (j = 0; j < pstr_enc_loudness_info_set->str_loudness_info[i].measurement_count; j++) { |
209 | 16.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info[i] |
210 | 16.1k | .str_loudness_measure[j] |
211 | 16.1k | .method_definition, |
212 | 16.1k | 0, MAX_METHOD_DEFINITION_TYPE); |
213 | 16.1k | IMPD_DRC_BOUND_CHECK( |
214 | 16.1k | pstr_enc_loudness_info_set->str_loudness_info[i].str_loudness_measure[j].method_value, |
215 | 16.1k | MIN_METHOD_VALUE, MAX_METHOD_VALUE); |
216 | 16.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info[i] |
217 | 16.1k | .str_loudness_measure[j] |
218 | 16.1k | .measurement_system, |
219 | 16.1k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
220 | 16.1k | IMPD_DRC_BOUND_CHECK( |
221 | 16.1k | pstr_enc_loudness_info_set->str_loudness_info[i].str_loudness_measure[j].reliability, 0, |
222 | 16.1k | MAX_RELIABILITY_TYPE); |
223 | 16.1k | } |
224 | 3.65k | } |
225 | 1.78k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->loudness_info_album_count, 0, |
226 | 1.78k | MAX_LOUDNESS_INFO_COUNT); |
227 | 7.58k | for (i = 0; i < pstr_enc_loudness_info_set->loudness_info_album_count; i++) { |
228 | 5.80k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i].sample_peak_level, |
229 | 5.80k | MIN_SAMPLE_PEAK_LEVEL, MAX_SAMPLE_PEAK_LEVEL); |
230 | 5.80k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i].true_peak_level, |
231 | 5.80k | MIN_TRUE_PEAK_LEVEL, MAX_TRUE_PEAK_LEVEL); |
232 | 5.80k | IMPD_DRC_BOUND_CHECK( |
233 | 5.80k | pstr_enc_loudness_info_set->str_loudness_info_album[i].true_peak_level_measurement_system, |
234 | 5.80k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
235 | 5.80k | IMPD_DRC_BOUND_CHECK( |
236 | 5.80k | pstr_enc_loudness_info_set->str_loudness_info_album[i].true_peak_level_reliability, 0, |
237 | 5.80k | MAX_RELIABILITY_TYPE); |
238 | 5.80k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i].measurement_count, |
239 | 5.80k | 0, MAX_MEASUREMENT_COUNT); |
240 | 29.7k | for (j = 0; j < pstr_enc_loudness_info_set->str_loudness_info_album[i].measurement_count; |
241 | 23.9k | j++) { |
242 | 23.9k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i] |
243 | 23.9k | .str_loudness_measure[j] |
244 | 23.9k | .method_definition, |
245 | 23.9k | 0, MAX_METHOD_DEFINITION_TYPE); |
246 | 23.9k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i] |
247 | 23.9k | .str_loudness_measure[j] |
248 | 23.9k | .method_value, |
249 | 23.9k | MIN_METHOD_VALUE, MAX_METHOD_VALUE); |
250 | 23.9k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i] |
251 | 23.9k | .str_loudness_measure[j] |
252 | 23.9k | .measurement_system, |
253 | 23.9k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
254 | 23.9k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set->str_loudness_info_album[i] |
255 | 23.9k | .str_loudness_measure[j] |
256 | 23.9k | .reliability, |
257 | 23.9k | 0, MAX_RELIABILITY_TYPE); |
258 | 23.9k | } |
259 | 5.80k | } |
260 | | |
261 | 1.78k | if (pstr_uni_drc_config->uni_drc_config_ext_present != 0 && |
262 | 929 | pstr_uni_drc_config->uni_drc_config_ext_present != 1) { |
263 | 0 | pstr_uni_drc_config->uni_drc_config_ext_present = 0; |
264 | 0 | } |
265 | | |
266 | 1.78k | if (pstr_uni_drc_config->uni_drc_config_ext_present && |
267 | 929 | (pstr_uni_drc_config->drc_instructions_uni_drc_count > 0 || |
268 | 864 | pstr_uni_drc_config->drc_coefficients_uni_drc_count > 0)) { |
269 | 175 | memset(pstr_uni_drc_config->str_drc_instructions_uni_drc, 0, |
270 | 175 | sizeof(pstr_uni_drc_config->str_drc_instructions_uni_drc[0]) * |
271 | 175 | pstr_uni_drc_config->drc_instructions_uni_drc_count); |
272 | 175 | memset(pstr_uni_drc_config->str_drc_coefficients_uni_drc, 0, |
273 | 175 | sizeof(pstr_uni_drc_config->str_drc_coefficients_uni_drc[0]) * |
274 | 175 | pstr_uni_drc_config->drc_coefficients_uni_drc_count); |
275 | 175 | pstr_uni_drc_config->drc_instructions_uni_drc_count = 0; |
276 | 175 | pstr_uni_drc_config->drc_coefficients_uni_drc_count = 0; |
277 | 175 | } |
278 | 1.78k | if (pstr_uni_drc_config->uni_drc_config_ext_present) { |
279 | 929 | ia_drc_uni_drc_config_ext_struct *pstr_uni_drc_config_ext = |
280 | 929 | &pstr_uni_drc_config->str_uni_drc_config_ext; |
281 | 929 | if (pstr_uni_drc_config_ext->downmix_instructions_v1_present != 0 && |
282 | 401 | pstr_uni_drc_config_ext->downmix_instructions_v1_present != 1) { |
283 | 0 | pstr_uni_drc_config_ext->downmix_instructions_v1_present = 0; |
284 | 0 | } |
285 | 929 | if (pstr_uni_drc_config_ext->downmix_instructions_v1_present) { |
286 | 401 | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->downmix_instructions_v1_count, 0, |
287 | 401 | DOWNMIX_INSTRUCTIONS_COUNT_MAX); |
288 | 1.80k | for (i = 0; i < pstr_uni_drc_config_ext->downmix_instructions_v1_count; i++) { |
289 | 1.40k | IMPD_DRC_BOUND_CHECK( |
290 | 1.40k | pstr_uni_drc_config_ext->str_downmix_instructions_v1[i].target_layout, 0, |
291 | 1.40k | MAX_TARGET_LAYOUT_COUNT); |
292 | 1.40k | IMPD_DRC_BOUND_CHECK( |
293 | 1.40k | pstr_uni_drc_config_ext->str_downmix_instructions_v1[i].target_ch_count, 0, |
294 | 1.40k | MAX_CHANNEL_COUNT); |
295 | 1.40k | } |
296 | 401 | } |
297 | | |
298 | 929 | if (pstr_uni_drc_config_ext->drc_coeffs_and_instructions_uni_drc_v1_present != 0 && |
299 | 859 | pstr_uni_drc_config_ext->drc_coeffs_and_instructions_uni_drc_v1_present != 1) { |
300 | 0 | pstr_uni_drc_config_ext->drc_coeffs_and_instructions_uni_drc_v1_present = 0; |
301 | 0 | } |
302 | 929 | if (pstr_uni_drc_config_ext->drc_coeffs_and_instructions_uni_drc_v1_present) { |
303 | 859 | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count, 0, |
304 | 859 | DRC_COEFFICIENTS_UNIDRC_V1_COUNT_MAX); |
305 | 1.65k | for (i = 0; i < pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count; i++) { |
306 | 1.14k | IMPD_DRC_BOUND_CHECK( |
307 | 1.14k | pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i].gain_set_count, 0, |
308 | 1.14k | GAIN_SET_COUNT_MAX); |
309 | 1.14k | for (j = 0; |
310 | 3.35k | j < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i].gain_set_count; |
311 | 2.55k | j++) { |
312 | 2.55k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
313 | 2.55k | .str_gain_set_params[j] |
314 | 2.55k | .gain_coding_profile, |
315 | 2.55k | 0, MAX_GAIN_CODING_PROFILE); |
316 | 2.55k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
317 | 2.55k | .str_gain_set_params[j] |
318 | 2.55k | .band_count, |
319 | 2.55k | 0, MAX_BAND_COUNT); |
320 | 6.42k | for (k = 0; k < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
321 | 6.42k | .str_gain_set_params[j] |
322 | 6.42k | .band_count; |
323 | 3.86k | k++) { |
324 | 3.86k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
325 | 3.86k | .str_gain_set_params[j] |
326 | 3.86k | .gain_params[k] |
327 | 3.86k | .nb_points, |
328 | 3.86k | 0, MAX_GAIN_POINTS); |
329 | 3.86k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
330 | 3.86k | .str_gain_set_params[j] |
331 | 3.86k | .gain_params[k] |
332 | 3.86k | .drc_characteristic, |
333 | 3.86k | 0, MAX_DRC_CHARACTERISTIC_VALUE); |
334 | 3.86k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
335 | 3.86k | .str_gain_set_params[j] |
336 | 3.86k | .gain_params[k] |
337 | 3.86k | .crossover_freq_index, |
338 | 3.86k | 0, MAX_CROSSOVER_FREQ_INDEX); |
339 | 3.86k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
340 | 3.86k | .str_gain_set_params[j] |
341 | 3.86k | .gain_params[k] |
342 | 3.86k | .start_sub_band_index, |
343 | 3.86k | 0, STFT256_HOP_SIZE - 1); |
344 | 3.86k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
345 | 3.86k | .str_gain_set_params[j] |
346 | 3.86k | .gain_params[k] |
347 | 3.86k | .width, |
348 | 3.86k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
349 | 144k | for (WORD32 m = 0; m < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
350 | 144k | .str_gain_set_params[j] |
351 | 144k | .gain_params[k] |
352 | 144k | .nb_points; |
353 | 140k | m++) { |
354 | 140k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
355 | 140k | .str_gain_set_params[j] |
356 | 140k | .gain_params[k] |
357 | 140k | .gain_points[m] |
358 | 140k | .x, |
359 | 140k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
360 | 140k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
361 | 140k | .str_gain_set_params[j] |
362 | 140k | .gain_params[k] |
363 | 140k | .gain_points[m] |
364 | 140k | .y, |
365 | 140k | -MAX_FLT_VAL_DB, MAX_FLT_VAL_DB); |
366 | 140k | } |
367 | 3.86k | } |
368 | 3.11k | for (k = 0; k < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
369 | 3.11k | .str_gain_set_params[j] |
370 | 3.11k | .band_count - |
371 | 3.11k | 1; |
372 | 2.55k | k++) { |
373 | 915 | curr_start_subband_idx = pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
374 | 915 | .str_gain_set_params[j] |
375 | 915 | .gain_params[k] |
376 | 915 | .start_sub_band_index; |
377 | 915 | next_start_subband_idx = pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i] |
378 | 915 | .str_gain_set_params[j] |
379 | 915 | .gain_params[k + 1] |
380 | 915 | .start_sub_band_index; |
381 | | /* It is assumed that the start index of a subband is greater than |
382 | | the start index of its previous subbands for a multiband */ |
383 | 915 | if (next_start_subband_idx <= curr_start_subband_idx) { |
384 | 354 | return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_SUBBAND_INDEX; |
385 | 354 | } |
386 | 915 | } |
387 | 2.55k | } |
388 | 1.14k | } |
389 | | |
390 | 505 | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count, 0, |
391 | 505 | DRC_INSTRUCTIONS_UNIDRC_V1_COUNT_MAX); |
392 | 1.94k | for (i = 0; i < pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count; i++) { |
393 | 1.44k | IMPD_DRC_BOUND_CHECK( |
394 | 1.44k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_set_id, 0, |
395 | 1.44k | MAX_DRC_SET_ID); |
396 | 1.44k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
397 | 1.44k | .additional_downmix_id_count, |
398 | 1.44k | 0, MAX_ADDITIONAL_DOWNMIX_ID); |
399 | 1.44k | IMPD_DRC_BOUND_CHECK( |
400 | 1.44k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_location, 0, |
401 | 1.44k | MAX_DRC_LOCATION); |
402 | 1.44k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
403 | 1.44k | .drc_set_target_loudness_value_upper, |
404 | 1.44k | MIN_DRC_TARGET_LOUDNESS, 0); |
405 | 1.44k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
406 | 1.44k | .drc_set_target_loudness_value_lower, |
407 | 1.44k | MIN_DRC_TARGET_LOUDNESS, 0); |
408 | 12.9k | for (j = 0; j < MAX_CHANNEL_COUNT; j++) { |
409 | 11.5k | IMPD_DRC_BOUND_CHECK( |
410 | 11.5k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].gain_set_index[j], 0, |
411 | 11.5k | GAIN_SET_COUNT_MAX - 1); |
412 | 11.5k | } |
413 | 1.44k | IMPD_DRC_BOUND_CHECK( |
414 | 1.44k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].num_drc_channel_groups, 0, |
415 | 1.44k | MAX_CHANNEL_GROUP_COUNT); |
416 | 1.44k | for (j = 0; |
417 | 4.08k | j < |
418 | 4.08k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].num_drc_channel_groups; |
419 | 2.64k | j++) { |
420 | 2.64k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
421 | 2.64k | .str_gain_modifiers[j] |
422 | 2.64k | .attenuation_scaling[0], |
423 | 2.64k | 0, MAX_ATTENUATION_SCALING); |
424 | 2.64k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
425 | 2.64k | .str_gain_modifiers[j] |
426 | 2.64k | .amplification_scaling[0], |
427 | 2.64k | 0, MAX_AMPLIFICATION_SCALING); |
428 | 2.64k | IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
429 | 2.64k | .str_gain_modifiers[j] |
430 | 2.64k | .gain_offset[0], |
431 | 2.64k | MIN_DRC_GAIN_OFFSET, MAX_DRC_GAIN_OFFSET); |
432 | 2.64k | } |
433 | 1.44k | IMPD_DRC_BOUND_CHECK( |
434 | 1.44k | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].limiter_peak_target, |
435 | 1.44k | MIN_LIMITER_PEAK_TARGET, 0.0f); |
436 | 1.44k | #ifdef LOUDNESS_LEVELING_SUPPORT |
437 | 1.44k | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_set_effect & |
438 | 1.44k | EFFECT_BIT_DUCK_SELF) { |
439 | 608 | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].leveling_present != 0 && |
440 | 291 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].leveling_present != 1) { |
441 | 0 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].leveling_present = 0; |
442 | 0 | } |
443 | 608 | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
444 | 608 | .ducking_only_set_present != 0 && |
445 | 262 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
446 | 262 | .ducking_only_set_present != 1) { |
447 | 0 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].ducking_only_set_present = |
448 | 0 | 0; |
449 | 0 | } |
450 | 608 | } |
451 | 1.44k | #endif |
452 | 1.44k | } |
453 | 505 | } |
454 | 929 | } |
455 | | |
456 | 1.42k | if (pstr_enc_loudness_info_set->loudness_info_set_ext_present != 0 && |
457 | 487 | pstr_enc_loudness_info_set->loudness_info_set_ext_present != 1) { |
458 | 0 | pstr_enc_loudness_info_set->loudness_info_set_ext_present = 0; |
459 | 0 | } |
460 | 1.42k | if (pstr_enc_loudness_info_set->loudness_info_set_ext_present) { |
461 | 487 | ia_drc_loudness_info_set_ext_eq_struct *pstr_enc_loudness_info_set_ext = |
462 | 487 | &pstr_enc_loudness_info_set->str_loudness_info_set_extension.str_loudness_info_set_ext_eq; |
463 | 487 | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->loudness_info_v1_count, 0, |
464 | 487 | MAX_LOUDNESS_INFO_COUNT); |
465 | 3.88k | for (i = 0; i < pstr_enc_loudness_info_set_ext->loudness_info_v1_count; i++) { |
466 | 3.39k | IMPD_DRC_BOUND_CHECK( |
467 | 3.39k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i].sample_peak_level, |
468 | 3.39k | MIN_SAMPLE_PEAK_LEVEL, MAX_SAMPLE_PEAK_LEVEL); |
469 | 3.39k | IMPD_DRC_BOUND_CHECK( |
470 | 3.39k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i].true_peak_level, |
471 | 3.39k | MIN_TRUE_PEAK_LEVEL, MAX_TRUE_PEAK_LEVEL); |
472 | 3.39k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i] |
473 | 3.39k | .true_peak_level_measurement_system, |
474 | 3.39k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
475 | 3.39k | IMPD_DRC_BOUND_CHECK( |
476 | 3.39k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i].true_peak_level_reliability, 0, |
477 | 3.39k | MAX_RELIABILITY_TYPE); |
478 | 3.39k | IMPD_DRC_BOUND_CHECK( |
479 | 3.39k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i].measurement_count, 0, |
480 | 3.39k | MAX_MEASUREMENT_COUNT); |
481 | 21.5k | for (j = 0; j < pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i].measurement_count; |
482 | 18.1k | j++) { |
483 | 18.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i] |
484 | 18.1k | .str_loudness_measure[j] |
485 | 18.1k | .method_definition, |
486 | 18.1k | 0, MAX_METHOD_DEFINITION_TYPE); |
487 | 18.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i] |
488 | 18.1k | .str_loudness_measure[j] |
489 | 18.1k | .method_value, |
490 | 18.1k | MIN_METHOD_VALUE, MAX_METHOD_VALUE); |
491 | 18.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i] |
492 | 18.1k | .str_loudness_measure[j] |
493 | 18.1k | .measurement_system, |
494 | 18.1k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
495 | 18.1k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1[i] |
496 | 18.1k | .str_loudness_measure[j] |
497 | 18.1k | .reliability, |
498 | 18.1k | 0, MAX_RELIABILITY_TYPE); |
499 | 18.1k | } |
500 | 3.39k | } |
501 | | |
502 | 487 | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->loudness_info_v1_album_count, 0, |
503 | 487 | MAX_LOUDNESS_INFO_COUNT); |
504 | 5.44k | for (i = 0; i < pstr_enc_loudness_info_set_ext->loudness_info_v1_album_count; i++) { |
505 | 4.95k | IMPD_DRC_BOUND_CHECK( |
506 | 4.95k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i].sample_peak_level, |
507 | 4.95k | MIN_SAMPLE_PEAK_LEVEL, MAX_SAMPLE_PEAK_LEVEL); |
508 | 4.95k | IMPD_DRC_BOUND_CHECK( |
509 | 4.95k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i].true_peak_level, |
510 | 4.95k | MIN_TRUE_PEAK_LEVEL, MAX_TRUE_PEAK_LEVEL); |
511 | 4.95k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
512 | 4.95k | .true_peak_level_measurement_system, |
513 | 4.95k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
514 | 4.95k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
515 | 4.95k | .true_peak_level_reliability, |
516 | 4.95k | 0, MAX_RELIABILITY_TYPE); |
517 | 4.95k | IMPD_DRC_BOUND_CHECK( |
518 | 4.95k | pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i].measurement_count, 0, |
519 | 4.95k | MAX_MEASUREMENT_COUNT); |
520 | 4.95k | for (j = 0; |
521 | 27.8k | j < pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i].measurement_count; |
522 | 22.8k | j++) { |
523 | 22.8k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
524 | 22.8k | .str_loudness_measure[j] |
525 | 22.8k | .method_definition, |
526 | 22.8k | 0, MAX_METHOD_DEFINITION_TYPE); |
527 | 22.8k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
528 | 22.8k | .str_loudness_measure[j] |
529 | 22.8k | .method_value, |
530 | 22.8k | MIN_METHOD_VALUE, MAX_METHOD_VALUE); |
531 | 22.8k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
532 | 22.8k | .str_loudness_measure[j] |
533 | 22.8k | .measurement_system, |
534 | 22.8k | 0, MAX_MEASUREMENT_SYSTEM_TYPE); |
535 | 22.8k | IMPD_DRC_BOUND_CHECK(pstr_enc_loudness_info_set_ext->str_loudness_info_v1_album[i] |
536 | 22.8k | .str_loudness_measure[j] |
537 | 22.8k | .reliability, |
538 | 22.8k | 0, MAX_RELIABILITY_TYPE); |
539 | 22.8k | } |
540 | 4.95k | } |
541 | 487 | } |
542 | | |
543 | 1.42k | return IA_NO_ERROR; |
544 | 1.78k | } |
545 | | |
546 | | static IA_ERRORCODE impd_drc_validate_drc_instructions( |
547 | 1.31k | ia_drc_uni_drc_config_struct *pstr_uni_drc_config) { |
548 | 1.31k | LOOPIDX i, j; |
549 | 1.31k | WORD32 profile_found = FALSE; |
550 | | |
551 | 1.77k | for (j = 0; j < pstr_uni_drc_config->drc_coefficients_uni_drc_count; j++) { |
552 | 925 | if (pstr_uni_drc_config->str_drc_coefficients_uni_drc[j].drc_location == 1) { |
553 | 469 | profile_found = TRUE; |
554 | 469 | break; |
555 | 469 | } |
556 | 925 | } |
557 | 1.31k | if (pstr_uni_drc_config->uni_drc_config_ext_present && |
558 | 527 | pstr_uni_drc_config->str_uni_drc_config_ext.parametric_drc_present && |
559 | 0 | pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_coeff_parametric_drc.drc_location == |
560 | 0 | 1) { |
561 | 0 | profile_found = TRUE; |
562 | 0 | } |
563 | 1.31k | if ((pstr_uni_drc_config->uni_drc_config_ext_present == 0) && profile_found == FALSE) { |
564 | 322 | return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG; |
565 | 322 | } |
566 | 996 | #ifdef LOUDNESS_LEVELING_SUPPORT |
567 | 1.51k | for (i = 0; i < pstr_uni_drc_config->drc_instructions_uni_drc_count; i++) { |
568 | 514 | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_effect & |
569 | 514 | EFFECT_BIT_DUCK_SELF) { |
570 | 302 | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i].leveling_present && |
571 | 120 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present) { |
572 | 97 | if (i < pstr_uni_drc_config->drc_instructions_uni_drc_count - 1) { |
573 | 91 | if (pstr_uni_drc_config->str_drc_instructions_uni_drc[i + 1].drc_set_effect != |
574 | 91 | EFFECT_BIT_DUCK_SELF && |
575 | 91 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i + 1].drc_set_effect != |
576 | 91 | EFFECT_BIT_DUCK_OTHER) { |
577 | 91 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i + 1].drc_set_effect = |
578 | 91 | EFFECT_BIT_DUCK_SELF; |
579 | 91 | } |
580 | 91 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i + 1].leveling_present = 0; |
581 | 91 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i + 1].ducking_only_set_present = 0; |
582 | 91 | } else { |
583 | 6 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present = 0; |
584 | 6 | } |
585 | 205 | } else if (!pstr_uni_drc_config->str_drc_instructions_uni_drc[i].leveling_present && |
586 | 182 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present) { |
587 | 28 | pstr_uni_drc_config->str_drc_instructions_uni_drc[i].ducking_only_set_present = 0; |
588 | 28 | } |
589 | 302 | } |
590 | 514 | } |
591 | 996 | #endif |
592 | | |
593 | 996 | if (pstr_uni_drc_config->uni_drc_config_ext_present) { |
594 | 527 | ia_drc_uni_drc_config_ext_struct *pstr_uni_drc_config_ext = |
595 | 527 | &pstr_uni_drc_config->str_uni_drc_config_ext; |
596 | 527 | profile_found = FALSE; |
597 | 894 | for (j = 0; j < pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count; j++) { |
598 | 642 | if (pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[j].drc_location == 1) { |
599 | 275 | profile_found = TRUE; |
600 | 275 | break; |
601 | 275 | } |
602 | 642 | } |
603 | 527 | if (pstr_uni_drc_config->str_uni_drc_config_ext.parametric_drc_present && |
604 | 0 | pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_coeff_parametric_drc.drc_location == |
605 | 0 | 1) { |
606 | 0 | profile_found = TRUE; |
607 | 0 | } |
608 | 527 | if (profile_found == FALSE) { |
609 | 252 | return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG; |
610 | 252 | } |
611 | 275 | #ifdef LOUDNESS_LEVELING_SUPPORT |
612 | 1.03k | for (i = 0; i < pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count; i++) { |
613 | 764 | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_set_effect & |
614 | 764 | EFFECT_BIT_DUCK_SELF) { |
615 | 455 | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].leveling_present && |
616 | 166 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
617 | 166 | .ducking_only_set_present) { |
618 | 112 | if (i < pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count - 1) { |
619 | 102 | if (pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i + 1].drc_set_effect != |
620 | 102 | EFFECT_BIT_DUCK_SELF && |
621 | 96 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i + 1].drc_set_effect != |
622 | 96 | EFFECT_BIT_DUCK_OTHER) { |
623 | 91 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i + 1].drc_set_effect = |
624 | 91 | EFFECT_BIT_DUCK_SELF; |
625 | 91 | } |
626 | 102 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i + 1].leveling_present = 0; |
627 | 102 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i + 1] |
628 | 102 | .ducking_only_set_present = 0; |
629 | 102 | } else { |
630 | 10 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].ducking_only_set_present = |
631 | 10 | 0; |
632 | 10 | } |
633 | 343 | } else if (!pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
634 | 343 | .leveling_present && |
635 | 289 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i] |
636 | 289 | .ducking_only_set_present) { |
637 | 33 | pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].ducking_only_set_present = |
638 | 33 | 0; |
639 | 33 | } |
640 | 455 | } |
641 | 764 | } |
642 | 275 | #endif |
643 | 275 | } |
644 | | |
645 | 744 | return IA_NO_ERROR; |
646 | 996 | } |
647 | | |
648 | | IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch, |
649 | 1.39k | ia_drc_input_config *pstr_inp_config) { |
650 | 1.39k | IA_ERRORCODE err_code = IA_NO_ERROR; |
651 | 1.39k | WORD32 bit_count = 0; |
652 | 1.39k | ia_drc_enc_state *pstr_drc_state_local = pstr_drc_state; |
653 | | |
654 | 1.39k | pstr_drc_state_local->drc_scratch_mem = ptr_drc_scratch; |
655 | 1.39k | pstr_drc_state_local->drc_scratch_used = 0; |
656 | | |
657 | 1.39k | iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg, |
658 | 1.39k | pstr_drc_state_local->bit_buf_base_cfg, |
659 | 1.39k | sizeof(pstr_drc_state_local->bit_buf_base_cfg), 1); |
660 | | |
661 | 1.39k | iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_ext, |
662 | 1.39k | pstr_drc_state_local->bit_buf_base_cfg_ext, |
663 | 1.39k | sizeof(pstr_drc_state_local->bit_buf_base_cfg_ext), 1); |
664 | | |
665 | 1.39k | iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_tmp, |
666 | 1.39k | pstr_drc_state_local->bit_buf_base_cfg_tmp, |
667 | 1.39k | sizeof(pstr_drc_state_local->bit_buf_base_cfg_tmp), 1); |
668 | | |
669 | 1.39k | iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_out, |
670 | 1.39k | pstr_drc_state_local->bit_buf_base_out, |
671 | 1.39k | sizeof(pstr_drc_state_local->bit_buf_base_out), 1); |
672 | | |
673 | 1.39k | err_code = impd_drc_gain_enc_init( |
674 | 1.39k | &pstr_drc_state_local->str_gain_enc, &pstr_inp_config->str_uni_drc_config, |
675 | 1.39k | &pstr_inp_config->str_enc_loudness_info_set, pstr_inp_config->str_enc_params.frame_size, |
676 | 1.39k | pstr_inp_config->str_enc_params.sample_rate, pstr_inp_config->str_enc_params.delay_mode, |
677 | 1.39k | pstr_inp_config->str_enc_params.domain); |
678 | 1.39k | if (err_code) { |
679 | 80 | return err_code; |
680 | 80 | } |
681 | | |
682 | 1.31k | err_code = impd_drc_validate_drc_instructions(&pstr_inp_config->str_uni_drc_config); |
683 | | |
684 | 1.31k | if (err_code & IA_FATAL_ERROR) { |
685 | 574 | return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG; |
686 | 574 | } |
687 | | |
688 | 744 | pstr_drc_state_local->str_enc_params = pstr_inp_config->str_enc_params; |
689 | 744 | pstr_drc_state_local->str_uni_drc_config = pstr_inp_config->str_uni_drc_config; |
690 | 744 | pstr_drc_state_local->str_enc_gain_extension = pstr_inp_config->str_enc_gain_extension; |
691 | 744 | pstr_drc_state_local->str_gain_enc.str_uni_drc_config = pstr_inp_config->str_uni_drc_config; |
692 | | |
693 | 744 | pstr_drc_state_local->str_enc_params.gain_sequence_present = FALSE; |
694 | 917 | for (WORD16 k = 0; k < pstr_drc_state_local->str_uni_drc_config.drc_coefficients_uni_drc_count; |
695 | 744 | k++) { |
696 | 601 | if ((pstr_drc_state_local->str_uni_drc_config.str_drc_coefficients_uni_drc[k].drc_location == |
697 | 601 | 1) && |
698 | 484 | (pstr_drc_state_local->str_uni_drc_config.str_drc_coefficients_uni_drc[k].gain_set_count > |
699 | 484 | 0)) { |
700 | 428 | pstr_drc_state_local->str_enc_params.gain_sequence_present = TRUE; |
701 | 428 | break; |
702 | 428 | } |
703 | 601 | } |
704 | | |
705 | 744 | if (pstr_drc_state_local->str_enc_params.gain_sequence_present == FALSE) { |
706 | 557 | for (WORD16 k = 0; k < pstr_drc_state_local->str_uni_drc_config.str_uni_drc_config_ext |
707 | 557 | .drc_coefficients_uni_drc_v1_count; |
708 | 492 | k++) { |
709 | 492 | if ((pstr_drc_state_local->str_uni_drc_config.str_uni_drc_config_ext |
710 | 492 | .str_drc_coefficients_uni_drc_v1[k] |
711 | 492 | .drc_location == 1) && |
712 | 276 | (pstr_drc_state_local->str_uni_drc_config.str_uni_drc_config_ext |
713 | 276 | .str_drc_coefficients_uni_drc_v1[k] |
714 | 276 | .gain_set_count > 0)) { |
715 | 251 | pstr_drc_state_local->str_enc_params.gain_sequence_present = TRUE; |
716 | 251 | break; |
717 | 251 | } |
718 | 492 | } |
719 | 316 | } |
720 | | |
721 | 744 | err_code = impd_drc_write_uni_drc_config(pstr_drc_state_local, &bit_count, 1); |
722 | 744 | if (err_code & IA_FATAL_ERROR) { |
723 | 117 | return err_code; |
724 | 117 | } |
725 | 627 | pstr_drc_state_local->drc_config_data_size_bit = bit_count; |
726 | | |
727 | | // Loudness info set |
728 | 627 | if (pstr_drc_state_local->str_gain_enc.str_uni_drc_config.loudness_info_set_present == 1) { |
729 | 474 | bit_count = 0; |
730 | 474 | iusace_reset_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_ext); |
731 | 474 | memset(pstr_drc_state_local->bit_buf_base_cfg_ext, 0, |
732 | 474 | sizeof(MAX_DRC_PAYLOAD_BYTES * sizeof(pstr_drc_state_local->bit_buf_base_cfg_ext[0]))); |
733 | 474 | err_code = impd_drc_write_loudness_info_set( |
734 | 474 | pstr_drc_state, &pstr_drc_state_local->str_bit_buf_cfg_ext, &bit_count, 1); |
735 | 474 | if (err_code & IA_FATAL_ERROR) { |
736 | 6 | return (err_code); |
737 | 6 | } |
738 | 468 | pstr_drc_state_local->drc_config_ext_data_size_bit = bit_count; |
739 | 468 | } |
740 | | |
741 | 621 | return err_code; |
742 | 627 | } |
743 | | |
744 | 2.67k | IA_ERRORCODE impd_loudness_info_init(VOID *pstr_drc_state, ia_drc_input_config *pstr_inp_config) { |
745 | 2.67k | IA_ERRORCODE err_code = IA_NO_ERROR; |
746 | 2.67k | ia_drc_enc_state *pstr_drc_state_local = pstr_drc_state; |
747 | | |
748 | 2.67k | iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_ext, |
749 | 2.67k | pstr_drc_state_local->bit_buf_base_cfg_ext, |
750 | 2.67k | sizeof(pstr_drc_state_local->bit_buf_base_cfg_ext), 1); |
751 | | |
752 | 2.67k | memcpy(&pstr_drc_state_local->str_gain_enc.str_loudness_info_set, |
753 | 2.67k | &pstr_inp_config->str_enc_loudness_info_set, sizeof(ia_drc_loudness_info_set_struct)); |
754 | | |
755 | 2.67k | err_code = impd_drc_write_measured_loudness_info(pstr_drc_state_local); |
756 | 2.67k | return err_code; |
757 | 2.67k | } |
758 | | |
759 | | IA_ERRORCODE impd_drc_enc(VOID *pstr_drc_state, FLOAT32 **pptr_input, UWORD32 inp_offset, |
760 | 73.7k | WORD32 *ptr_bits_written, VOID *pstr_scratch) { |
761 | 73.7k | LOOPIDX i, j, k; |
762 | 73.7k | WORD32 band_count = 0; |
763 | 73.7k | WORD32 stop_sub_band_index; |
764 | 73.7k | WORD32 num_bits_payload = 0; |
765 | 73.7k | UWORD8 is_fft_ready[MAX_NUM_CHANNELS] = {0}; |
766 | 73.7k | ia_drc_enc_state *pstr_drc_state_local = pstr_drc_state; |
767 | 73.7k | ia_drc_gain_enc_struct *pstr_gain_enc = &pstr_drc_state_local->str_gain_enc; |
768 | 73.7k | ia_drc_uni_drc_config_struct *pstr_uni_drc_config = &pstr_drc_state_local->str_uni_drc_config; |
769 | 73.7k | ia_drc_compand_struct *pstr_drc_compand; |
770 | 73.7k | ia_drc_stft_gain_calc_struct *pstr_drc_stft_gain_calc; |
771 | 73.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
772 | 73.7k | ia_drc_coefficients_uni_drc_struct *pstr_drc_coefficients_uni_drc; |
773 | | |
774 | 73.7k | if (pstr_uni_drc_config->str_uni_drc_config_ext.drc_coefficients_uni_drc_v1_count > 0) { |
775 | 19.0k | pstr_drc_coefficients_uni_drc = |
776 | 19.0k | &pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_coefficients_uni_drc_v1[0]; |
777 | 54.6k | } else { |
778 | 54.6k | pstr_drc_coefficients_uni_drc = &pstr_uni_drc_config->str_drc_coefficients_uni_drc[0]; |
779 | 54.6k | } |
780 | | |
781 | 73.7k | if (pstr_drc_state_local->str_enc_params.gain_sequence_present) { |
782 | 577k | for (i = 0; i < MAX_DRC_COEFF_COUNT; i++) { |
783 | 653k | for (j = 0; j < GAIN_SET_COUNT_MAX; j++) { |
784 | 651k | pstr_drc_stft_gain_calc = &pstr_gain_enc->str_drc_stft_gain_handle[i][j][0]; |
785 | 651k | pstr_drc_compand = &pstr_gain_enc->str_drc_compand[i][j]; |
786 | 651k | if ((pstr_drc_compand->is_valid == 0) && (pstr_drc_stft_gain_calc->is_valid == 0)) { |
787 | 503k | break; |
788 | 503k | } |
789 | | |
790 | 148k | if (pstr_drc_compand->is_valid == 0) { |
791 | 21.9k | if (is_fft_ready[pstr_drc_stft_gain_calc->ch_idx] == 0) { |
792 | 19.6k | impd_drc_stft_drc_convert_to_fd( |
793 | 19.6k | pstr_gain_enc, &pptr_input[pstr_drc_stft_gain_calc->ch_idx][inp_offset], |
794 | 19.6k | pstr_drc_stft_gain_calc->ch_idx, pstr_drc_state_local->str_enc_params.frame_size, |
795 | 19.6k | pstr_gain_enc->complex_fft_ptr[pstr_drc_stft_gain_calc->ch_idx], pstr_scratch); |
796 | 19.6k | is_fft_ready[pstr_drc_stft_gain_calc->ch_idx] = 1; |
797 | 19.6k | } |
798 | | |
799 | 66.6k | for (k = 0; k < pstr_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count; |
800 | 44.7k | k++) { |
801 | 44.7k | if (k == pstr_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count - 1) { |
802 | 21.9k | stop_sub_band_index = STFT256_HOP_SIZE - 1; |
803 | 22.7k | } else { |
804 | 22.7k | stop_sub_band_index = pstr_drc_coefficients_uni_drc[i] |
805 | 22.7k | .str_gain_set_params[j] |
806 | 22.7k | .gain_params[k + 1] |
807 | 22.7k | .start_sub_band_index - |
808 | 22.7k | 1; |
809 | 22.7k | } |
810 | | |
811 | 44.7k | impd_drc_stft_drc_gain_calc_process( |
812 | 44.7k | pstr_gain_enc, i, j, k, |
813 | 44.7k | pstr_drc_coefficients_uni_drc[i] |
814 | 44.7k | .str_gain_set_params[j] |
815 | 44.7k | .gain_params[k] |
816 | 44.7k | .start_sub_band_index, |
817 | 44.7k | stop_sub_band_index, pstr_drc_state_local->str_enc_params.frame_size, |
818 | 44.7k | pstr_gain_enc->complex_fft_ptr[pstr_drc_stft_gain_calc->ch_idx], |
819 | 44.7k | pstr_drc_state_local->gain_buffer[band_count + k]); |
820 | 44.7k | } |
821 | 126k | } else { |
822 | 126k | impd_drc_td_drc_gain_calc_process(pstr_gain_enc, i, j, |
823 | 126k | pstr_drc_state_local->str_enc_params.frame_size, |
824 | 126k | &pptr_input[pstr_drc_compand->ch_idx][inp_offset], |
825 | 126k | pstr_drc_state_local->gain_buffer[band_count]); |
826 | 126k | } |
827 | | |
828 | 148k | band_count += pstr_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count; |
829 | 148k | } |
830 | 505k | } |
831 | 72.1k | } |
832 | 73.7k | err_code = impd_drc_encode_uni_drc_gain(pstr_gain_enc, pstr_drc_state_local->gain_buffer[0], |
833 | 73.7k | pstr_scratch); |
834 | 73.7k | if (err_code) { |
835 | 0 | return err_code; |
836 | 0 | } |
837 | | |
838 | 73.7k | if (pstr_drc_state_local->is_first_drc_process_complete == 1) { |
839 | 73.1k | impd_drc_write_uni_drc_gain(pstr_drc_state_local, &num_bits_payload); |
840 | 73.1k | } |
841 | | |
842 | 73.7k | *ptr_bits_written = num_bits_payload; |
843 | 73.7k | return err_code; |
844 | 73.7k | } |