Coverage Report

Created: 2025-10-10 06:12

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