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 <stdlib.h>
22 #include <math.h>
23 #include <assert.h>
24 #include <string.h>
25 #include "impd_type_def.h"
26 #include "impd_drc_bitbuffer.h"
27 #include "impd_drc_common.h"
28 #include "impd_drc_interface.h"
29 #include "impd_drc_parser_interface.h"
30
31 WORD32
impd_drc_dec_interface_add_effect_type(ia_drc_interface_struct * pstr_drc_interface,WORD32 drc_effect_type,WORD32 target_loudness,WORD32 loud_norm,WORD32 album_mode,FLOAT32 boost,FLOAT32 compress)32 impd_drc_dec_interface_add_effect_type(
33 ia_drc_interface_struct* pstr_drc_interface, WORD32 drc_effect_type,
34 WORD32 target_loudness, WORD32 loud_norm, WORD32 album_mode, FLOAT32 boost,
35 FLOAT32 compress) {
36 WORD32 err = 0;
37 WORD32 i = 0;
38
39 if (pstr_drc_interface != NULL) {
40 pstr_drc_interface->interface_signat_flag = 0;
41 for (i = 0; i < MAX_SIGNATURE_DATA_LENGTH_PLUS_ONE * 8; i++)
42 pstr_drc_interface->drc_uni_interface_signature.interface_signat_data[i] =
43 0;
44
45 pstr_drc_interface->drc_uni_interface_signature.interface_signat_data_len =
46 0;
47
48 pstr_drc_interface->system_interface_flag = 1;
49
50 pstr_drc_interface->system_interface.target_config_request_type = 0;
51 pstr_drc_interface->system_interface.num_downmix_id_requests = 0;
52 for (i = 0; i < MAX_NUM_DOWNMIX_ID_REQUESTS; i++) {
53 pstr_drc_interface->system_interface.requested_dwnmix_id[i] = 0;
54 }
55 pstr_drc_interface->system_interface.requested_target_layout = 0;
56 pstr_drc_interface->system_interface.requested_target_ch_count = 0;
57
58 pstr_drc_interface->loudness_norm_ctrl_interface_flag = 1;
59 if (loud_norm == 1) {
60 pstr_drc_interface->loudness_norm_ctrl_interface
61 .loudness_normalization_on = 1;
62 } else {
63 pstr_drc_interface->loudness_norm_ctrl_interface
64 .loudness_normalization_on = 0;
65 }
66 pstr_drc_interface->loudness_norm_ctrl_interface.target_loudness =
67 (FLOAT32)target_loudness;
68
69 pstr_drc_interface->loudness_norm_parameter_interface_flag = 1;
70 pstr_drc_interface->loudness_norm_param_interface.album_mode = album_mode;
71 pstr_drc_interface->loudness_norm_param_interface.peak_limiter = 0;
72 pstr_drc_interface->loudness_norm_param_interface
73 .change_loudness_deviation_max = 1;
74 pstr_drc_interface->loudness_norm_param_interface.loudness_deviation_max =
75 63;
76 pstr_drc_interface->loudness_norm_param_interface
77 .change_loudness_measur_method = 1;
78 pstr_drc_interface->loudness_norm_param_interface
79 .loudness_measurement_method = 1;
80 pstr_drc_interface->loudness_norm_param_interface
81 .change_loudness_measur_system = 1;
82 pstr_drc_interface->loudness_norm_param_interface
83 .loudness_measurement_system = 1;
84 pstr_drc_interface->loudness_norm_param_interface
85 .change_loudness_measur_pre_proc = 0;
86 pstr_drc_interface->loudness_norm_param_interface
87 .loudness_measurement_pre_proc = 0;
88 pstr_drc_interface->loudness_norm_param_interface
89 .change_device_cut_off_freq = 1;
90 pstr_drc_interface->loudness_norm_param_interface.device_cut_off_frequency =
91 20;
92 pstr_drc_interface->loudness_norm_param_interface
93 .change_loudness_norm_gain_db_max = 1;
94 pstr_drc_interface->loudness_norm_param_interface
95 .loudness_norm_gain_db_max = 1000.0;
96 pstr_drc_interface->loudness_norm_param_interface
97 .change_loudness_norm_gain_modification_db = 1;
98 pstr_drc_interface->loudness_norm_param_interface
99 .loudness_norm_gain_modification_db = 0.0;
100 pstr_drc_interface->loudness_norm_param_interface
101 .change_output_peak_level_max = 1;
102 pstr_drc_interface->loudness_norm_param_interface.output_peak_level_max =
103 0.0;
104
105 pstr_drc_interface->drc_interface_flag = 1;
106 if (drc_effect_type == -1) {
107 pstr_drc_interface->drc_ctrl_interface.dynamic_range_control_on = 0;
108 pstr_drc_interface->drc_ctrl_interface.requested_drc_effect_type[0][0] =
109 0;
110 } else if (drc_effect_type == 0) {
111 pstr_drc_interface->drc_ctrl_interface.dynamic_range_control_on = 1;
112 pstr_drc_interface->drc_ctrl_interface.num_drc_feature_requests = 0;
113 } else {
114 pstr_drc_interface->drc_ctrl_interface.dynamic_range_control_on = 1;
115 pstr_drc_interface->drc_ctrl_interface.requested_drc_effect_type[0][0] =
116 drc_effect_type;
117 pstr_drc_interface->drc_ctrl_interface.num_drc_feature_requests = 3;
118 pstr_drc_interface->drc_ctrl_interface.drc_feature_req_type[0] = 0;
119 pstr_drc_interface->drc_ctrl_interface.drc_feature_req_type[1] = 1;
120 pstr_drc_interface->drc_ctrl_interface.drc_feature_req_type[2] = 2;
121 pstr_drc_interface->drc_ctrl_interface.requested_num_drc_effects[0] = 1;
122 pstr_drc_interface->drc_ctrl_interface
123 .desired_num_drc_effects_of_requested[0] = 1;
124 }
125
126 pstr_drc_interface->drc_ctrl_interface
127 .requested_dyn_rng_measurement_type[0] = 0;
128 pstr_drc_interface->drc_ctrl_interface
129 .requested_dyn_range_is_single_val_flag[0] = 0;
130 pstr_drc_interface->drc_ctrl_interface
131 .requested_dyn_range_is_single_val_flag[1] = 0;
132 pstr_drc_interface->drc_ctrl_interface.requested_dyn_range_min_val[1] =
133 3.0f;
134 pstr_drc_interface->drc_ctrl_interface.requested_dyn_range_max_val[1] =
135 10.0f;
136 pstr_drc_interface->drc_ctrl_interface.requested_drc_characteristic[2] = 3;
137
138 pstr_drc_interface->drc_parameter_interface_flag = 1;
139 pstr_drc_interface->drc_parameter_interface.change_compress = 1;
140 pstr_drc_interface->drc_parameter_interface.change_boost = 1;
141 pstr_drc_interface->drc_parameter_interface.compress = compress;
142 pstr_drc_interface->drc_parameter_interface.boost = boost;
143 pstr_drc_interface->drc_parameter_interface
144 .change_drc_characteristic_target = 1;
145 pstr_drc_interface->drc_parameter_interface.drc_characteristic_target = 0;
146
147 pstr_drc_interface->drc_uni_interface_ext_flag = 0;
148
149 } else {
150 return UNEXPECTED_ERROR;
151 }
152
153 return err;
154 }
155