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 <stdio.h>
21 #include "impd_type_def.h"
22 #include "impd_drc_extr_delta_coded_info.h"
23 #include "impd_drc_common.h"
24 #include "impd_drc_struct.h"
25 #include "impd_drc_interface.h"
26 #include "impd_drc_selection_process.h"
27 #include "impd_drc_filter_bank.h"
28 #include "impd_drc_rom.h"
29
impd_set_default_params_selection_process(ia_drc_sel_proc_params_struct * pstr_drc_sel_proc_params)30 WORD32 impd_set_default_params_selection_process(
31 ia_drc_sel_proc_params_struct* pstr_drc_sel_proc_params) {
32 pstr_drc_sel_proc_params->base_channel_count = -1;
33 pstr_drc_sel_proc_params->base_layout = -1;
34 pstr_drc_sel_proc_params->target_config_request_type = 0;
35 pstr_drc_sel_proc_params->num_downmix_id_requests = 0;
36
37 pstr_drc_sel_proc_params->album_mode = 0;
38
39 pstr_drc_sel_proc_params->peak_limiter = 1;
40
41 pstr_drc_sel_proc_params->loudness_normalization_on = 0;
42 pstr_drc_sel_proc_params->target_loudness = -24.0f;
43
44 pstr_drc_sel_proc_params->loudness_deviation_max =
45 LOUDNESS_DEVIATION_MAX_DEFAULT;
46
47 pstr_drc_sel_proc_params->loudness_measurement_method =
48 USER_METHOD_DEFINITION_DEFAULT;
49 pstr_drc_sel_proc_params->loudness_measurement_system =
50 USER_MEASUREMENT_SYSTEM_DEFAULT;
51 pstr_drc_sel_proc_params->loudness_measurement_pre_proc =
52 USER_LOUDNESS_PREPROCESSING_DEFAULT;
53 pstr_drc_sel_proc_params->device_cut_off_frequency = 500;
54 pstr_drc_sel_proc_params->loudness_norm_gain_db_max =
55 LOUDNESS_NORMALIZATION_GAIN_MAX_DEFAULT;
56 pstr_drc_sel_proc_params->loudness_norm_gain_modification_db = 0.0f;
57 pstr_drc_sel_proc_params->output_peak_level_max = 0.0f;
58 if (pstr_drc_sel_proc_params->peak_limiter == 1) {
59 pstr_drc_sel_proc_params->output_peak_level_max = 6.0f;
60 }
61
62 pstr_drc_sel_proc_params->dynamic_range_control_on = 1;
63 pstr_drc_sel_proc_params->num_bands_supported = 4;
64 pstr_drc_sel_proc_params->num_drc_feature_requests = 0;
65
66 pstr_drc_sel_proc_params->boost = 1.f;
67 pstr_drc_sel_proc_params->compress = 1.f;
68 pstr_drc_sel_proc_params->drc_characteristic_target = 0;
69
70 return 0;
71 }
impd_set_custom_params(const WORD32 param_set_idx,ia_drc_sel_proc_params_struct * pstr_drc_sel_proc_params)72 WORD32 impd_set_custom_params(
73 const WORD32 param_set_idx,
74 ia_drc_sel_proc_params_struct* pstr_drc_sel_proc_params) {
75 WORD32 i, k;
76
77 const ia_loc_sys_interface_struct* system_interface =
78 &(loc_sys_interface[param_set_idx - 1]);
79
80 const ia_loc_loudness_norm_ctrl_interface_struct*
81 loudness_norm_ctrl_interface =
82 &(loc_loudness_norm_ctrl_interface[param_set_idx - 1]);
83 const ia_loc_loudness_norm_param_interface_struct*
84 loudness_norm_param_interface =
85 &(loc_loudness_norm_param_interface[param_set_idx - 1]);
86
87 const ia_loc_drc_interface_struct* drc_ctrl_interface =
88 &(loc_dyn_range_ctrl_interface[param_set_idx - 1]);
89 const ia_loc_requested_drc_effect_struct* requested_drc_effect_type =
90 &(loc_requested_drc_effect_type_str[param_set_idx - 1]);
91 const ia_loc_drc_parameter_interface_struct* drc_parameter_interface =
92 &(loc_drc_parameter_interface[param_set_idx - 1]);
93
94 pstr_drc_sel_proc_params->target_config_request_type =
95 system_interface->target_config_request_type;
96 switch (system_interface->target_config_request_type) {
97 case 1:
98 pstr_drc_sel_proc_params->requested_target_layout =
99 system_interface->requested_target_layout;
100 break;
101 case 2:
102 pstr_drc_sel_proc_params->requested_target_ch_count =
103 system_interface->requested_target_ch_count;
104 break;
105 case 0:
106 default:
107 pstr_drc_sel_proc_params->num_downmix_id_requests =
108 system_interface->num_downmix_id_requests;
109 for (i = 0; i < system_interface->num_downmix_id_requests; i++) {
110 pstr_drc_sel_proc_params->requested_dwnmix_id[i] =
111 system_interface->requested_dwnmix_id[i];
112 }
113 break;
114 }
115
116 pstr_drc_sel_proc_params->loudness_normalization_on =
117 loudness_norm_ctrl_interface->loudness_normalization_on;
118 pstr_drc_sel_proc_params->target_loudness =
119 loudness_norm_ctrl_interface->target_loudness;
120
121 pstr_drc_sel_proc_params->album_mode =
122 loudness_norm_param_interface->album_mode;
123 pstr_drc_sel_proc_params->peak_limiter =
124 loudness_norm_param_interface->peak_limiter;
125 pstr_drc_sel_proc_params->loudness_deviation_max =
126 loudness_norm_param_interface->loudness_deviation_max;
127 pstr_drc_sel_proc_params->loudness_measurement_method =
128 loudness_norm_param_interface->loudness_measurement_method;
129 pstr_drc_sel_proc_params->loudness_measurement_system =
130 loudness_norm_param_interface->loudness_measurement_system;
131 pstr_drc_sel_proc_params->loudness_measurement_pre_proc =
132 loudness_norm_param_interface->loudness_measurement_pre_proc;
133 pstr_drc_sel_proc_params->device_cut_off_frequency =
134 loudness_norm_param_interface->device_cut_off_frequency;
135 pstr_drc_sel_proc_params->loudness_norm_gain_db_max =
136 loudness_norm_param_interface->loudness_norm_gain_db_max;
137 pstr_drc_sel_proc_params->loudness_norm_gain_modification_db =
138 loudness_norm_param_interface->loudness_norm_gain_modification_db;
139 pstr_drc_sel_proc_params->output_peak_level_max =
140 loudness_norm_param_interface->output_peak_level_max;
141
142 pstr_drc_sel_proc_params->dynamic_range_control_on =
143 drc_ctrl_interface->dynamic_range_control_on;
144 pstr_drc_sel_proc_params->num_drc_feature_requests =
145 drc_ctrl_interface->num_drc_feature_requests;
146 for (i = 0; i < drc_ctrl_interface->num_drc_feature_requests; i++) {
147 pstr_drc_sel_proc_params->drc_feature_req_type[i] =
148 drc_ctrl_interface->drc_feature_req_type[i];
149 switch (drc_ctrl_interface->drc_feature_req_type[i]) {
150 case MATCH_EFFECT_TYPE:
151 pstr_drc_sel_proc_params->requested_num_drc_effects[i] =
152 requested_drc_effect_type->requested_num_drc_effects;
153 pstr_drc_sel_proc_params->desired_num_drc_effects_of_requested[i] =
154 requested_drc_effect_type->desired_num_drc_effects_of_requested;
155 for (k = 0; k < requested_drc_effect_type->requested_num_drc_effects;
156 k++) {
157 pstr_drc_sel_proc_params->requested_drc_effect_type[i][k] =
158 requested_drc_effect_type->requested_drc_effect_type[k];
159 }
160 break;
161 case MATCH_DYNAMIC_RANGE:
162 pstr_drc_sel_proc_params->requested_dyn_range_measur_type[i] =
163 drc_ctrl_interface->requested_dyn_rng_measurement_type;
164 pstr_drc_sel_proc_params->requested_dyn_range_range_flag[i] =
165 drc_ctrl_interface->requested_dyn_range_is_single_val_flag;
166 pstr_drc_sel_proc_params->requested_dyn_range_value[i] =
167 drc_ctrl_interface->requested_dyn_range_value;
168 pstr_drc_sel_proc_params->requested_dyn_range_min_val[i] =
169 drc_ctrl_interface->requested_dyn_range_min_val;
170 pstr_drc_sel_proc_params->requested_dyn_range_max_val[i] =
171 drc_ctrl_interface->requested_dyn_range_max_val;
172 break;
173 case MATCH_DRC_CHARACTERISTIC:
174 pstr_drc_sel_proc_params->requested_drc_characteristic[i] =
175 drc_ctrl_interface->requested_drc_characteristic;
176 break;
177 default:
178 return (UNEXPECTED_ERROR);
179 }
180 }
181
182 pstr_drc_sel_proc_params->boost = drc_parameter_interface->boost;
183 pstr_drc_sel_proc_params->compress = drc_parameter_interface->compress;
184 pstr_drc_sel_proc_params->drc_characteristic_target =
185 drc_parameter_interface->drc_characteristic_target;
186
187 return (0);
188 }
impd_eval_custom_params_selection_process(ia_drc_sel_proc_params_struct * pstr_drc_sel_proc_params)189 WORD32 impd_eval_custom_params_selection_process(
190 ia_drc_sel_proc_params_struct* pstr_drc_sel_proc_params) {
191 pstr_drc_sel_proc_params->loudness_norm_gain_db_max =
192 max(0.0f, pstr_drc_sel_proc_params->loudness_norm_gain_db_max);
193 pstr_drc_sel_proc_params->loudness_deviation_max =
194 max(0, pstr_drc_sel_proc_params->loudness_deviation_max);
195
196 return (0);
197 }
198