Coverage Report

Created: 2026-07-16 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
472
static WORD32 impd_match_downmix(WORD32 downmix_id, WORD32 dec_downmix_id) {
75
472
  WORD32 id_match = 0;
76
77
472
  switch (dec_downmix_id) {
78
236
    case 0:
79
236
      id_match = (downmix_id == 0);
80
236
      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
236
    case 4:
91
236
      id_match = (downmix_id != 0);
92
236
      break;
93
472
  }
94
472
  return id_match;
95
472
}
96
97
18.3k
IA_ERRORCODE impd_drc_set_default_config(ia_drc_api_struct *p_obj_drc) {
98
18.3k
  memset(p_obj_drc, 0, sizeof(*p_obj_drc));
99
18.3k
  p_obj_drc->str_config.bitstream_file_format = 1;
100
18.3k
  p_obj_drc->str_config.dec_type = 0;
101
18.3k
  p_obj_drc->str_config.sub_band_domain_mode = 0;
102
18.3k
  p_obj_drc->str_config.sub_band_count = 0;
103
18.3k
  p_obj_drc->str_config.sub_band_down_sampling_factor = 0;
104
18.3k
  p_obj_drc->str_config.sampling_rate = 0;
105
18.3k
  p_obj_drc->str_config.frame_size = 1024;
106
18.3k
  p_obj_drc->str_config.num_ch_in = -1;
107
18.3k
  p_obj_drc->str_config.num_ch_out = -1;
108
18.3k
  p_obj_drc->str_config.control_parameter_index = -1;
109
18.3k
  p_obj_drc->str_config.peak_limiter = 0;
110
18.3k
  p_obj_drc->str_config.delay_mode = 0;
111
18.3k
  p_obj_drc->str_config.interface_bitstream_present = 1;
112
18.3k
  p_obj_drc->str_config.gain_delay_samples = 0;
113
18.3k
  p_obj_drc->str_config.absorb_delay_on = 1;
114
18.3k
  p_obj_drc->str_config.subband_domain_io_flag = 0;
115
18.3k
  p_obj_drc->str_bit_handler.gain_stream_flag = 1;
116
18.3k
  p_obj_drc->str_config.constant_delay_on = 0;
117
18.3k
  p_obj_drc->str_config.audio_delay_samples = 0;
118
18.3k
  p_obj_drc->str_config.effect_type = 0;
119
18.3k
  p_obj_drc->str_config.target_loudness = -24;
120
18.3k
  p_obj_drc->str_config.loud_norm_flag = 0;
121
18.3k
  p_obj_drc->str_config.album_mode = 0;
122
18.3k
  p_obj_drc->str_config.boost = 1.0f;
123
18.3k
  p_obj_drc->str_config.compress = 1.0f;
124
18.3k
  p_obj_drc->str_config.boost_set = 0;
125
18.3k
  p_obj_drc->str_config.compress_set = 0;
126
18.3k
  memset(&p_obj_drc->str_bit_handler, 0, sizeof(p_obj_drc->str_bit_handler));
127
128
18.3k
  return IA_NO_ERROR;
129
18.3k
}
130
131
IA_ERRORCODE impd_drc_set_default_bitstream_config(
132
1.39k
    ia_drc_config *pstr_drc_config) {
133
1.39k
  WORD32 i;
134
135
1.39k
  pstr_drc_config->sample_rate_present = 0;
136
1.39k
  pstr_drc_config->sampling_rate = 0;
137
1.39k
  pstr_drc_config->dwnmix_instructions_count = 0;
138
1.39k
  pstr_drc_config->drc_coefficients_drc_count = 1;
139
1.39k
  pstr_drc_config->drc_instructions_uni_drc_count = 4;
140
1.39k
  pstr_drc_config->drc_instructions_count_plus = 5;
141
1.39k
  pstr_drc_config->drc_description_basic_present = 0;
142
1.39k
  pstr_drc_config->drc_coefficients_basic_count = 0;
143
1.39k
  pstr_drc_config->drc_instructions_basic_count = 0;
144
1.39k
  pstr_drc_config->drc_config_ext_present = 1;
145
1.39k
  pstr_drc_config->apply_drc = 0;
146
1.39k
  pstr_drc_config->str_drc_config_ext.drc_config_ext_type[0] = 2;
147
1.39k
  pstr_drc_config->str_drc_config_ext.ext_bit_size[0] = 345;
148
1.39k
  pstr_drc_config->str_drc_config_ext.parametric_drc_present = 0;
149
1.39k
  pstr_drc_config->str_drc_config_ext.drc_extension_v1_present = 1;
150
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].version = 1;
151
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].drc_location = 1;
152
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count = 4;
153
1.39k
  for (i = 0;
154
6.97k
       i <
155
6.97k
       pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count;
156
5.57k
       i++) {
157
5.57k
    pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
158
5.57k
        .gain_set_params[i]
159
5.57k
        .gain_interpolation_type = 1;
160
5.57k
    pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
161
5.57k
        .gain_set_params[i]
162
5.57k
        .band_count = 1;
163
5.57k
  }
164
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_sequence_count =
165
1.39k
      4;
166
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
167
1.39k
      .gain_set_params_index_for_gain_sequence[0] = 0;
168
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
169
1.39k
      .gain_set_params_index_for_gain_sequence[1] = 1;
170
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
171
1.39k
      .gain_set_params_index_for_gain_sequence[2] = 2;
172
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0]
173
1.39k
      .gain_set_params_index_for_gain_sequence[3] = 3;
174
1.39k
  pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0].gain_set_count_plus =
175
1.39k
      4;
176
1.39k
  pstr_drc_config->str_drc_instruction_str[0].drc_set_id = 1;
177
1.39k
  pstr_drc_config->str_drc_instruction_str[0].drc_set_complexity_level = 2;
178
1.39k
  pstr_drc_config->str_drc_instruction_str[0].drc_location = 1;
179
1.39k
  pstr_drc_config->str_drc_instruction_str[0].dwnmix_id_count = 1;
180
1.39k
  pstr_drc_config->str_drc_instruction_str[0].drc_set_effect = 1;
181
1.39k
  pstr_drc_config->str_drc_instruction_str[0].gain_set_index[1] = 1;
182
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
183
1.39k
      .drc_set_target_loudness_value_lower = -63;
184
1.39k
  pstr_drc_config->str_drc_instruction_str[0].num_drc_ch_groups = 2;
185
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
186
1.39k
      .gain_set_index_for_channel_group[1] = 1;
187
1.39k
  pstr_drc_config->str_drc_instruction_str[0].band_count_of_ch_group[0] = 1;
188
1.39k
  pstr_drc_config->str_drc_instruction_str[0].band_count_of_ch_group[1] = 1;
189
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
190
1.39k
      .gain_interpolation_type_for_channel_group[0] = 1;
191
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
192
1.39k
      .gain_interpolation_type_for_channel_group[1] = 1;
193
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
194
1.39k
      .time_delta_min_for_channel_group[0] = 32;
195
1.39k
  pstr_drc_config->str_drc_instruction_str[0]
196
1.39k
      .time_delta_min_for_channel_group[1] = 32;
197
1.39k
  pstr_drc_config->str_drc_instruction_str[0].channel_group_of_ch[1] = 1;
198
1.39k
  pstr_drc_config->str_drc_instruction_str[0].gain_element_count = 2;
199
200
1.39k
  pstr_drc_config->str_drc_instruction_str[1].drc_set_id = 2;
201
1.39k
  pstr_drc_config->str_drc_instruction_str[1].drc_set_complexity_level = 2;
202
1.39k
  pstr_drc_config->str_drc_instruction_str[1].drc_location = 1;
203
1.39k
  pstr_drc_config->str_drc_instruction_str[1].dwnmix_id_count = 1;
204
1.39k
  pstr_drc_config->str_drc_instruction_str[1].drc_set_effect = 2;
205
1.39k
  pstr_drc_config->str_drc_instruction_str[1].gain_set_index[0] = 1;
206
1.39k
  pstr_drc_config->str_drc_instruction_str[1].gain_set_index[1] = 2;
207
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
208
1.39k
      .drc_set_target_loudness_value_lower = -63;
209
1.39k
  pstr_drc_config->str_drc_instruction_str[1].num_drc_ch_groups = 2;
210
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
211
1.39k
      .gain_set_index_for_channel_group[0] = 1;
212
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
213
1.39k
      .gain_set_index_for_channel_group[1] = 2;
214
1.39k
  pstr_drc_config->str_drc_instruction_str[1].band_count_of_ch_group[0] = 1;
215
1.39k
  pstr_drc_config->str_drc_instruction_str[1].band_count_of_ch_group[1] = 1;
216
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
217
1.39k
      .gain_interpolation_type_for_channel_group[0] = 1;
218
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
219
1.39k
      .gain_interpolation_type_for_channel_group[1] = 1;
220
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
221
1.39k
      .time_delta_min_for_channel_group[0] = 32;
222
1.39k
  pstr_drc_config->str_drc_instruction_str[1]
223
1.39k
      .time_delta_min_for_channel_group[1] = 32;
224
1.39k
  pstr_drc_config->str_drc_instruction_str[1].channel_group_of_ch[1] = 1;
225
1.39k
  pstr_drc_config->str_drc_instruction_str[1].gain_element_count = 2;
226
227
1.39k
  pstr_drc_config->str_drc_instruction_str[2].drc_set_id = 3;
228
1.39k
  pstr_drc_config->str_drc_instruction_str[2].drc_set_complexity_level = 2;
229
1.39k
  pstr_drc_config->str_drc_instruction_str[2].drc_location = 1;
230
1.39k
  pstr_drc_config->str_drc_instruction_str[2].dwnmix_id_count = 1;
231
1.39k
  pstr_drc_config->str_drc_instruction_str[2].drc_set_effect = 4;
232
1.39k
  pstr_drc_config->str_drc_instruction_str[2].gain_set_index[0] = 2;
233
1.39k
  pstr_drc_config->str_drc_instruction_str[2].gain_set_index[1] = 3;
234
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
235
1.39k
      .drc_set_target_loudness_value_lower = -63;
236
1.39k
  pstr_drc_config->str_drc_instruction_str[2].num_drc_ch_groups = 2;
237
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
238
1.39k
      .gain_set_index_for_channel_group[0] = 2;
239
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
240
1.39k
      .gain_set_index_for_channel_group[1] = 3;
241
1.39k
  pstr_drc_config->str_drc_instruction_str[2].band_count_of_ch_group[0] = 1;
242
1.39k
  pstr_drc_config->str_drc_instruction_str[2].band_count_of_ch_group[1] = 1;
243
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
244
1.39k
      .gain_interpolation_type_for_channel_group[0] = 1;
245
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
246
1.39k
      .gain_interpolation_type_for_channel_group[1] = 1;
247
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
248
1.39k
      .time_delta_min_for_channel_group[0] = 32;
249
1.39k
  pstr_drc_config->str_drc_instruction_str[2]
250
1.39k
      .time_delta_min_for_channel_group[1] = 32;
251
1.39k
  pstr_drc_config->str_drc_instruction_str[2].channel_group_of_ch[1] = 1;
252
1.39k
  pstr_drc_config->str_drc_instruction_str[2].gain_element_count = 2;
253
254
1.39k
  pstr_drc_config->str_drc_instruction_str[3].drc_set_id = 4;
255
1.39k
  pstr_drc_config->str_drc_instruction_str[3].drc_set_complexity_level = 2;
256
1.39k
  pstr_drc_config->str_drc_instruction_str[3].drc_location = 1;
257
1.39k
  pstr_drc_config->str_drc_instruction_str[3].dwnmix_id_count = 1;
258
1.39k
  pstr_drc_config->str_drc_instruction_str[3].drc_set_effect = 32;
259
1.39k
  pstr_drc_config->str_drc_instruction_str[3].gain_set_index[0] = 3;
260
1.39k
  pstr_drc_config->str_drc_instruction_str[3].gain_set_index[1] = 0;
261
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
262
1.39k
      .drc_set_target_loudness_value_lower = -63;
263
1.39k
  pstr_drc_config->str_drc_instruction_str[3].num_drc_ch_groups = 2;
264
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
265
1.39k
      .gain_set_index_for_channel_group[0] = 3;
266
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
267
1.39k
      .gain_set_index_for_channel_group[1] = 0;
268
1.39k
  pstr_drc_config->str_drc_instruction_str[3].band_count_of_ch_group[0] = 1;
269
1.39k
  pstr_drc_config->str_drc_instruction_str[3].band_count_of_ch_group[1] = 1;
270
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
271
1.39k
      .gain_interpolation_type_for_channel_group[0] = 1;
272
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
273
1.39k
      .gain_interpolation_type_for_channel_group[1] = 1;
274
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
275
1.39k
      .time_delta_min_for_channel_group[0] = 32;
276
1.39k
  pstr_drc_config->str_drc_instruction_str[3]
277
1.39k
      .time_delta_min_for_channel_group[1] = 32;
278
1.39k
  pstr_drc_config->str_drc_instruction_str[3].channel_group_of_ch[1] = 1;
279
1.39k
  pstr_drc_config->str_drc_instruction_str[3].gain_element_count = 2;
280
281
1.39k
  pstr_drc_config->str_drc_instruction_str[4].drc_set_id = -1;
282
1.39k
  pstr_drc_config->str_drc_instruction_str[4].dwnmix_id_count = 1;
283
1.39k
  pstr_drc_config->channel_layout.base_channel_count = 2;
284
285
1.39k
  return IA_NO_ERROR;
286
1.39k
}
287
288
16.1k
IA_ERRORCODE impd_drc_set_struct_pointer(ia_drc_api_struct *p_obj_drc) {
289
16.1k
  pUWORD8 persistent_ptr = (pUWORD8)p_obj_drc->p_state->persistent_ptr;
290
291
16.1k
  UWORD64 persistent_size_consumed = 0;
292
16.1k
  p_obj_drc->str_payload.pstr_bitstream_dec = (ia_drc_bits_dec_struct *)persistent_ptr;
293
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_bits_dec_struct), BYTE_ALIGN_8);
294
295
16.1k
  p_obj_drc->str_payload.pstr_gain_dec[0] = (ia_drc_gain_dec_struct *)persistent_ptr;
296
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_gain_dec_struct), BYTE_ALIGN_8);
297
298
16.1k
  p_obj_drc->str_payload.pstr_gain_dec[1] = (ia_drc_gain_dec_struct *)persistent_ptr;
299
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_gain_dec_struct), BYTE_ALIGN_8);
300
301
16.1k
  p_obj_drc->str_payload.pstr_loudness_info = (ia_drc_loudness_info_set_struct *)persistent_ptr;
302
16.1k
  persistent_ptr +=
303
16.1k
      IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_loudness_info_set_struct), BYTE_ALIGN_8);
304
305
16.1k
  p_obj_drc->str_payload.pstr_drc_gain = (ia_drc_gain_struct *)persistent_ptr;
306
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_gain_struct), BYTE_ALIGN_8);
307
308
16.1k
  p_obj_drc->str_payload.pstr_drc_interface = (ia_drc_interface_struct *)persistent_ptr;
309
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_interface_struct), BYTE_ALIGN_8);
310
311
16.1k
  p_obj_drc->str_payload.pstr_drc_config = (ia_drc_config *)persistent_ptr;
312
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_config), BYTE_ALIGN_8);
313
314
16.1k
  p_obj_drc->str_payload.pstr_selection_proc = (ia_drc_sel_pro_struct *)persistent_ptr;
315
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_sel_pro_struct), BYTE_ALIGN_8);
316
317
16.1k
  p_obj_drc->str_bit_handler.it_bit_buf = (UWORD8 *)persistent_ptr;
318
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(MAX_DRC_BS_BUF_SIZE, BYTE_ALIGN_8);
319
320
16.1k
  p_obj_drc->str_payload.pstr_drc_sel_proc_params =
321
16.1k
      (ia_drc_sel_proc_params_struct *)persistent_ptr;
322
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_sel_proc_params_struct), BYTE_ALIGN_8);
323
324
16.1k
  p_obj_drc->str_payload.pstr_drc_sel_proc_output =
325
16.1k
      (ia_drc_sel_proc_output_struct *)persistent_ptr;
326
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_sel_proc_output_struct), BYTE_ALIGN_8);
327
328
16.1k
  p_obj_drc->str_bit_handler.bitstream_drc_config = (UWORD8 *)persistent_ptr;
329
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(MAX_BS_BUF_SIZE, BYTE_ALIGN_8);
330
331
16.1k
  p_obj_drc->str_bit_handler.bitstream_loudness_info = (UWORD8 *)persistent_ptr;
332
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(MAX_BS_BUF_SIZE, BYTE_ALIGN_8);
333
334
16.1k
  p_obj_drc->str_bit_handler.bitstream_unidrc_interface = (UWORD8 *)persistent_ptr;
335
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(MAX_BS_BUF_SIZE, BYTE_ALIGN_8);
336
337
16.1k
  p_obj_drc->str_payload.pstr_peak_limiter = (ia_drc_peak_limiter_struct *)persistent_ptr;
338
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_peak_limiter_struct), BYTE_ALIGN_8);
339
340
16.1k
  p_obj_drc->str_payload.pstr_peak_limiter->buffer = (FLOAT32 *)persistent_ptr;
341
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(PEAK_LIM_BUF_SIZE, BYTE_ALIGN_8);
342
343
16.1k
  p_obj_drc->str_payload.pstr_qmf_filter = (ia_drc_qmf_filt_struct *)persistent_ptr;
344
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_drc_qmf_filt_struct), BYTE_ALIGN_8);
345
346
16.1k
  p_obj_drc->str_payload.pstr_qmf_filter->ana_buff = (FLOAT64 *)persistent_ptr;
347
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(ANALY_BUF_SIZE, BYTE_ALIGN_8);
348
349
16.1k
  p_obj_drc->str_payload.pstr_qmf_filter->syn_buff = (FLOAT64 *)persistent_ptr;
350
16.1k
  persistent_ptr += IXHEAAC_GET_SIZE_ALIGNED(SYNTH_BUF_SIZE, BYTE_ALIGN_8);
351
352
16.1k
  persistent_size_consumed =
353
16.1k
      (UWORD64)(persistent_ptr - (pUWORD8)p_obj_drc->p_state->persistent_ptr);
354
355
16.1k
  if ((UWORD64)p_obj_drc->p_mem_info[IA_MEMTYPE_PERSIST].ui_size <
356
16.1k
      persistent_size_consumed)
357
0
    return IA_FATAL_ERROR;
358
359
16.1k
  p_obj_drc->p_state->persistent_ptr = (pVOID)persistent_ptr;
360
16.1k
  return IA_NO_ERROR;
361
16.1k
}
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
1.77k
IA_ERRORCODE impd_drc_init(ia_drc_api_struct *p_obj_drc) {
383
1.77k
  IA_ERRORCODE err_code = IA_NO_ERROR;
384
1.77k
  WORD32 i, j;
385
386
1.77k
  pVOID persistent_ptr = p_obj_drc->p_state->persistent_ptr;
387
388
1.77k
  WORD32 decDownmixIdList[NUM_GAIN_DEC_INSTANCES] = {0, 4};
389
390
1.77k
  p_obj_drc->p_state->delay_in_output = 0;
391
1.77k
  p_obj_drc->str_payload.pstr_selection_proc->first_frame = 1;
392
393
1.77k
  impd_create_init_bit_buf(&p_obj_drc->str_bit_buf,
394
1.77k
                           p_obj_drc->str_bit_handler.it_bit_buf,
395
1.77k
                           p_obj_drc->str_bit_handler.num_bytes_bs / 8);
396
397
1.77k
  p_obj_drc->pstr_bit_buf = &p_obj_drc->str_bit_buf;
398
399
1.77k
  err_code = impd_init_drc_bitstream_dec(
400
1.77k
      p_obj_drc->str_payload.pstr_bitstream_dec,
401
1.77k
      p_obj_drc->str_config.sampling_rate, p_obj_drc->str_config.frame_size,
402
1.77k
      p_obj_drc->str_config.delay_mode, -1, 0);
403
1.77k
  if (err_code != IA_NO_ERROR) return err_code;
404
405
5.32k
  for (i = 0; i < NUM_GAIN_DEC_INSTANCES; i++) {
406
3.54k
    err_code = impd_init_drc_decode(p_obj_drc->str_config.frame_size,
407
3.54k
                                    p_obj_drc->str_config.sampling_rate,
408
3.54k
                                    p_obj_drc->str_config.gain_delay_samples,
409
3.54k
                                    p_obj_drc->str_config.delay_mode,
410
3.54k
                                    p_obj_drc->str_config.sub_band_domain_mode,
411
3.54k
                                    p_obj_drc->str_payload.pstr_gain_dec[i]);
412
3.54k
    if (err_code != IA_NO_ERROR) return err_code;
413
3.54k
  }
414
415
1.77k
  err_code = impd_drc_dec_interface_add_effect_type(
416
1.77k
      p_obj_drc->str_payload.pstr_drc_interface, p_obj_drc->str_config.effect_type,
417
1.77k
      p_obj_drc->str_config.target_loudness, p_obj_drc->str_config.loud_norm_flag,
418
1.77k
      p_obj_drc->str_config.album_mode, p_obj_drc->str_config.boost,
419
1.77k
      p_obj_drc->str_config.compress
420
1.77k
#ifdef LOUDNESS_LEVELING_SUPPORT
421
1.77k
      ,
422
1.77k
      p_obj_drc->str_config.loudness_leveling_flag
423
1.77k
#endif
424
1.77k
  );
425
426
1.77k
  if (err_code != IA_NO_ERROR) return err_code;
427
428
1.77k
  err_code = impd_drc_uni_selction_proc_init(
429
1.77k
      p_obj_drc->str_payload.pstr_selection_proc, 0,
430
1.77k
      p_obj_drc->str_payload.pstr_drc_interface,
431
1.77k
      p_obj_drc->str_config.sub_band_domain_mode);
432
1.77k
  if (err_code != IA_NO_ERROR) return err_code;
433
434
1.77k
  if (p_obj_drc->str_payload.pstr_drc_interface
435
1.77k
          ->loudness_norm_parameter_interface_flag &&
436
1.77k
      p_obj_drc->str_payload.pstr_drc_interface->loudness_norm_param_interface
437
1.77k
          .peak_limiter) {
438
0
    p_obj_drc->str_config.peak_limiter = 1;
439
0
  }
440
441
1.77k
  p_obj_drc->str_payload.pstr_loudness_info->loudness_info_album_count = 0;
442
1.77k
  p_obj_drc->str_payload.pstr_loudness_info->loudness_info_count = 0;
443
1.77k
  p_obj_drc->str_payload.pstr_loudness_info->loudness_info_set_ext_present = 0;
444
1.77k
  p_obj_drc->p_state->ui_exe_done = 0;
445
446
1.77k
  err_code = impd_process_drc_bitstream_dec_config(
447
1.77k
      p_obj_drc->str_payload.pstr_bitstream_dec, p_obj_drc->pstr_bit_buf,
448
1.77k
      p_obj_drc->str_payload.pstr_drc_config,
449
1.77k
      &p_obj_drc->str_bit_handler.bitstream_drc_config[0],
450
1.77k
      p_obj_drc->str_bit_handler.num_bytes_bs_drc_config);
451
452
1.77k
  if (err_code == 1) {
453
1.39k
    memset(p_obj_drc->str_payload.pstr_drc_config, 0, sizeof(ia_drc_config));
454
1.39k
    err_code = impd_drc_set_default_bitstream_config(
455
1.39k
        p_obj_drc->str_payload.pstr_drc_config);
456
1.39k
    p_obj_drc->str_payload.pstr_drc_config->channel_layout.base_channel_count =
457
1.39k
        p_obj_drc->str_config.num_ch_in;
458
1.39k
  }
459
460
1.77k
  if (err_code != IA_NO_ERROR) return err_code;
461
1.46k
  err_code = impd_process_drc_bitstream_dec_loudness_info_set(
462
1.46k
      p_obj_drc->pstr_bit_buf, p_obj_drc->str_payload.pstr_loudness_info,
463
1.46k
      &p_obj_drc->str_bit_handler.bitstream_loudness_info[0],
464
1.46k
      p_obj_drc->str_bit_handler.num_bytes_bs_loudness_info);
465
1.46k
  if (err_code != IA_NO_ERROR) return err_code;
466
467
711
  if (p_obj_drc->str_payload.pstr_loudness_info->loudness_info
468
711
          ->anchor_loudness_present)
469
40
    p_obj_drc->str_payload.pstr_selection_proc->uni_drc_sel_proc_params
470
40
        .loudness_measurement_method = METHOD_DEFINITION_ANCHOR_LOUDNESS;
471
472
711
  if (p_obj_drc->str_payload.pstr_loudness_info->loudness_info
473
711
          ->expert_loudness_present)
474
3
    p_obj_drc->str_payload.pstr_selection_proc->uni_drc_sel_proc_params
475
3
        .loudness_measurement_system = USER_MEASUREMENT_SYSTEM_EXPERT_PANEL;
476
477
711
  err_code = impd_drc_uni_sel_proc_process(
478
711
      p_obj_drc->str_payload.pstr_selection_proc,
479
711
      p_obj_drc->str_payload.pstr_drc_config,
480
711
      p_obj_drc->str_payload.pstr_loudness_info,
481
711
      p_obj_drc->str_payload.pstr_drc_sel_proc_output);
482
711
  if (err_code != IA_NO_ERROR) return err_code;
483
484
2.08k
  for (i = 0; i < NUM_GAIN_DEC_INSTANCES; i++) {
485
1.39k
    WORD32 audio_num_chan = 0;
486
1.39k
    WORD32 numMatchingDrcSets = 0;
487
1.39k
    WORD32 matchingDrcSetIds[3], matchingDownmixIds[3];
488
1.39k
    for (j = 0;
489
1.86k
         j < p_obj_drc->str_payload.pstr_drc_sel_proc_output->num_sel_drc_sets;
490
1.39k
         j++) {
491
472
      if (impd_match_downmix(p_obj_drc->str_payload.pstr_drc_sel_proc_output
492
472
                                 ->sel_downmix_ids[j],
493
472
                             decDownmixIdList[i])) {
494
236
        matchingDrcSetIds[numMatchingDrcSets] =
495
236
            p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_drc_set_ids[j];
496
236
        matchingDownmixIds[numMatchingDrcSets] =
497
236
            p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_downmix_ids[j];
498
236
        numMatchingDrcSets++;
499
236
      }
500
472
    }
501
1.39k
    if (i == 0) {
502
699
      if (p_obj_drc->str_config.num_ch_in !=
503
699
          p_obj_drc->str_payload.pstr_drc_sel_proc_output->base_channel_count)
504
505
7
        return -1;
506
692
      audio_num_chan = p_obj_drc->str_config.num_ch_in;
507
692
    } else if (i == 1) {
508
692
      p_obj_drc->str_config.num_ch_out =
509
692
          p_obj_drc->str_payload.pstr_drc_sel_proc_output->target_channel_count;
510
692
      audio_num_chan = p_obj_drc->str_config.num_ch_out;
511
692
    }
512
513
1.38k
    err_code = impd_init_drc_decode_post_config(
514
1.38k
        audio_num_chan, matchingDrcSetIds, matchingDownmixIds,
515
1.38k
        numMatchingDrcSets,
516
1.38k
        p_obj_drc->str_payload.pstr_drc_sel_proc_output->sel_eq_set_ids[i]
517
518
1.38k
        ,
519
1.38k
        p_obj_drc->str_payload.pstr_gain_dec[i],
520
1.38k
        p_obj_drc->str_payload.pstr_drc_config,
521
1.38k
        p_obj_drc->str_payload.pstr_loudness_info, &persistent_ptr);
522
1.38k
    if (err_code) return err_code;
523
524
1.38k
    impd_get_parametric_drc_delay(
525
1.38k
        p_obj_drc->str_payload.pstr_gain_dec[i],
526
1.38k
        p_obj_drc->str_payload.pstr_drc_config,
527
1.38k
        &p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance,
528
1.38k
        &p_obj_drc->str_config.parametric_drc_delay_max);
529
1.38k
    impd_get_eq_delay(p_obj_drc->str_payload.pstr_gain_dec[i],
530
1.38k
                      p_obj_drc->str_payload.pstr_drc_config,
531
1.38k
                      &p_obj_drc->str_config.eq_delay_gain_dec_instance,
532
1.38k
                      &p_obj_drc->str_config.eq_delay_max);
533
1.38k
    p_obj_drc->str_config.parametric_drc_delay +=
534
1.38k
        p_obj_drc->str_config.parametric_drc_delay_gain_dec_instance;
535
1.38k
    p_obj_drc->str_config.eq_delay +=
536
1.38k
        p_obj_drc->str_config.eq_delay_gain_dec_instance;
537
1.38k
  }
538
539
692
  {
540
692
    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
692
    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
692
    if (!p_obj_drc->str_config.constant_delay_on) {
549
692
      p_obj_drc->p_state->delay_in_output +=
550
692
          p_obj_drc->str_config.parametric_drc_delay +
551
692
          p_obj_drc->str_config.eq_delay +
552
692
          p_obj_drc->str_config.audio_delay_samples;
553
692
      p_obj_drc->str_config.delay_line_samples =
554
692
          p_obj_drc->str_config.audio_delay_samples;
555
556
692
      if (!p_obj_drc->str_config.absorb_delay_on) {
557
0
        p_obj_drc->p_state->delay_in_output = 0;
558
0
      }
559
692
    } 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
692
  }
574
692
  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
692
  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
692
  return IA_NO_ERROR;
588
692
}