• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IMPD_DRC_COMMON_H
21 #define IMPD_DRC_COMMON_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define EQ_IS_SUPPORTED 1
28 
29 #define MEASURE_AVERAGE_BITRATE 0
30 
31 #define ENABLE_ADDITIONAL_TESTS 1
32 
33 #define SPEAKER_POS_COUNT_MAX (8)  // 128
34 #define DOWNMIX_COEFF_COUNT_MAX 32 * 32
35 #define MAX_CHANNEL_COUNT (8)  // 128
36 #define MAX_SUBBAND_CHANNEL_COUNT (128)
37 #define BAND_COUNT_MAX 8
38 #define SEQUENCE_COUNT_MAX 24
39 #define GAIN_SET_COUNT_MAX SEQUENCE_COUNT_MAX
40 #define MEASUREMENT_COUNT_MAX 16
41 #define DOWNMIX_INSTRUCTION_COUNT_MAX 16
42 #define DRC_COEFF_COUNT_MAX 8
43 #define DRC_INSTRUCTIONS_COUNT_MAX (DOWNMIX_INSTRUCTION_COUNT_MAX + 20)
44 #define LOUDNESS_INFO_COUNT_MAX (DOWNMIX_INSTRUCTION_COUNT_MAX + 20)
45 #define AUDIO_CODEC_FRAME_SIZE_MAX 4096
46 #define DRC_CODEC_FRAME_SIZE_MAX (AUDIO_CODEC_FRAME_SIZE_MAX / 8)
47 #define NODE_COUNT_MAX DRC_CODEC_FRAME_SIZE_MAX
48 #define CHANNEL_GROUP_COUNT_MAX SEQUENCE_COUNT_MAX
49 #define SUB_DRC_COUNT 4
50 #define SEL_DRC_COUNT 3
51 #define DOWNMIX_ID_COUNT_MAX 8
52 #define MAX_SIGNAL_DELAY 4500
53 
54 #define NUM_ELE_IN_CPLX_NUM 2
55 #define MAX_BS_BUF_SIZE 768
56 #define MAX_DRC_CONFG_BUF_SIZE MAX_BS_BUF_SIZE
57 #define MAX_LOUD_INFO_BUF_SIZE MAX_BS_BUF_SIZE
58 #define MAX_INTERFACE_BUF_SIZE MAX_BS_BUF_SIZE
59 #define MAX_GAIN_ELE_COUNT 15 /*MAX 4-bit Value*/
60 
61 #define NUM_GAIN_DEC_INSTANCES 2
62 
63 #define MAX_DRC_FRAME_SIZE AUDIO_CODEC_FRAME_SIZE_MAX
64 #define ANALY_BUF_SIZE                                                \
65   (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \
66    NUM_ELE_IN_CPLX_NUM)
67 #define SYNTH_BUF_SIZE                                                \
68   (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \
69    NUM_ELE_IN_CPLX_NUM)
70 #define PEAK_LIM_BUF_SIZE                                             \
71   (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \
72    NUM_ELE_IN_CPLX_NUM)
73 
74 /*7 bits read from the bitstream*/
75 #define MAX_PARAM_DRC_LOOK_AHEAD_VAL 127
76 
77 #define MAX_PARAM_DRC_LIM_ATTACK_VAL MAX_PARAM_DRC_LOOK_AHEAD_VAL
78 #define MAX_SAMP_FREQ_IN_KHZ 96
79 #define MAX_ATTACK_VAL (MAX_PARAM_DRC_LOOK_AHEAD_VAL * MAX_SAMP_FREQ_IN_KHZ)
80 
81 /*int(sqrt(MAX_ATTACK_VAL + 1))*/
82 #define MAX_SEC_LEN 110
83 #define MAX_NUMBUF_SEC_VAL (MAX_ATTACK_VAL / MAX_SEC_LEN)
84 
85 /*(MAX_NUMBUF_SEC_VAL * MAX_SEC_LEN)*/
86 #define PARAM_DRC_MAX_BUF_SZ 110
87 
88 #define MAX_SUBBAND_DELAY (MAX_SIGNAL_DELAY / AUDIO_CODEC_SUBBAND_COUNT_QMF64)
89 
90 #define DRC_BAND_COUNT_MAX BAND_COUNT_MAX
91 #define SPLIT_CHARACTERISTIC_COUNT_MAX 8
92 #define GAIN_SET_COUNT_MAX SEQUENCE_COUNT_MAX
93 #define SHAPE_FILTER_COUNT_MAX 8
94 #define DRC_SET_ID_COUNT_MAX 16
95 #define EQ_SET_ID_COUNT_MAX 8
96 #define LOUD_EQ_GAIN_SEQUENCE_COUNT_MAX 4
97 #define FILTER_ELEMENT_COUNT_MAX 16
98 #define REAL_ZERO_RADIUS_ONE_COUNT_MAX 14
99 #define REAL_ZERO_COUNT_MAX 64
100 #define COMPLEX_ZERO_COUNT_MAX 64
101 #define REAL_POLE_COUNT_MAX 16
102 #define COMPLEX_POLE_COUNT_MAX 16
103 #define FIR_ORDER_MAX 128
104 #define EQ_NODE_COUNT_MAX 33
105 #define EQ_SUBBAND_GAIN_COUNT_MAX 135
106 #define UNIQUE_SUBBAND_GAIN_COUNT_MAX 16
107 #define FILTER_BLOCK_COUNT_MAX 16
108 #define FILTER_ELEMENT_COUNT_MAX 16
109 
110 #define EQ_CHANNEL_GROUP_COUNT_MAX 4
111 #define EQ_FILTER_BLOCK_COUNT_MAX 4
112 #define LOUD_EQ_INSTRUCTIONS_COUNT_MAX 8
113 #define EQ_INSTRUCTIONS_COUNT_MAX 8
114 #define SELECTED_EQ_SET_COUNT_MAX 2
115 #define SUB_EQ_COUNT 2
116 
117 #define DELAY_MODE_REGULAR_DELAY 0
118 #define DELAY_MODE_LOW_DELAY 1
119 #define DELAY_MODE_DEFAULT DELAY_MODE_REGULAR_DELAY
120 
121 #define FEATURE_REQUEST_COUNT_MAX 10
122 #define EFFECT_TYPE_REQUEST_COUNT_MAX 10
123 
124 #define SELECTION_CANDIDATE_COUNT_MAX 32
125 
126 #define MAX_NUM_COMPRESSION_EQ (16)
127 
128 #define PROC_COMPLETE 1
129 #define UNEXPECTED_ERROR 2
130 #define PARAM_ERROR 3
131 #define EXTERNAL_ERROR 4
132 #define ERRORHANDLING 5
133 #define BITSTREAM_ERROR 6
134 
135 #define UNDEFINED_LOUDNESS_VALUE 1000.0f
136 #define ID_FOR_BASE_LAYOUT 0x0
137 #define ID_FOR_ANY_DOWNMIX 0x7F
138 #define ID_FOR_NO_DRC 0x0
139 #define ID_FOR_ANY_DRC 0x3F
140 #define ID_FOR_ANY_EQ 0x3F
141 
142 #define LOCATION_MP4_INSTREAM_UNIDRC 0x1
143 #define LOCATION_MP4_DYN_RANGE_INFO 0x2
144 #define LOCATION_MP4_COMPRESSION_VALUE 0x3
145 #define LOCATION_SELECTED LOCATION_MP4_INSTREAM_UNIDRC
146 
147 #define AUDIO_CODEC_SUBBAND_COUNT_MAX 256
148 
149 #define SUBBAND_DOMAIN_MODE_OFF 0
150 #define SUBBAND_DOMAIN_MODE_QMF64 1
151 #define SUBBAND_DOMAIN_MODE_QMF71 2
152 #define SUBBAND_DOMAIN_MODE_STFT256 3
153 
154 #define AUDIO_CODEC_SUBBAND_COUNT_QMF64 64
155 #define AUDIO_CODEC_SUBBAND_DOWNSAMPLING_FACTOR_QMF64 64
156 #define AUDIO_CODEC_SUBBAND_ANALYSE_DELAY_QMF64 320
157 
158 #define AUDIO_CODEC_SUBBAND_COUNT_QMF71 71
159 #define AUDIO_CODEC_SUBBAND_DOWNSAMPLING_FACTOR_QMF71 64
160 #define AUDIO_CODEC_SUBBAND_ANALYSE_DELAY_QMF71 320 + 384
161 
162 #define AUDIO_CODEC_SUBBAND_COUNT_STFT256 256
163 #define AUDIO_CODEC_SUBBAND_DOWNSAMPLING_FACTOR_STFT256 256
164 #define AUDIO_CODEC_SUBBAND_ANALYSE_DELAY_STFT256 256
165 
166 #define MAX_NUM_DOWNMIX_ID_REQUESTS 15
167 #define MAX_NUM_DRC_FEATURE_REQUESTS 7
168 #define MAX_NUM_DRC_EFFECT_TYPE_REQUESTS 15
169 #define MAX_SIGNATURE_DATA_LENGTH_PLUS_ONE 256
170 
171 #define EXT_COUNT_MAX 2
172 #define UNIDRCGAINEXT_TERM 0x0
173 #define UNIDRCLOUDEXT_TERM 0x0
174 #define UNIDRCCONFEXT_TERM 0x0
175 #define UNIDRCINTERFACEEXT_TERM 0x0
176 
177 #define UNIDRCCONFEXT_PARAM_DRC 0x1
178 
179 #define PARAM_DRC_INSTRUCTIONS_COUNT_MAX 8
180 #define PARAM_DRC_INSTANCE_COUNT_MAX 8
181 
182 #define PARAM_DRC_TYPE_FF 0x0
183 #define PARAM_DRC_TYPE_FF_NODE_COUNT_MAX 9
184 #define PARAM_DRC_TYPE_FF_LEVEL_ESTIM_FRAME_COUNT_MAX 64
185 
186 #define PARAM_DRC_TYPE_LIM 0x1
187 #define PARAM_DRC_TYPE_LIM_THRESHOLD_DEFAULT (-1.f)
188 #define PARAM_DRC_TYPE_LIM_ATTACK_DEFAULT 5
189 #define PARAM_DRC_TYPE_LIM_RELEASE_DEFAULT 50
190 #define MAX_LOUDNESS_INFO_COUNT (16)
191 
192 #define MAX_LOUDNESS_INFO_COUNT (16)
193 
194 #define UNIDRCCONFEXT_V1 0x2
195 #define UNIDRCLOUDEXT_EQ 0x1
196 #define UNIDRCINTERFACEEXT_EQ 0x1
197 
198 #define LOUD_EQ_REQUEST_OFF 0x0
199 #define LOUD_EQ_REQUEST_LIGHT 0x1
200 #define LOUD_EQ_REQUEST_REGULAR 0x2
201 #define LOUD_EQ_REQUEST_HEAVY 0x3
202 
203 #define EQ_PURPOSE_EQ_OFF 0
204 #define EQ_PURPOSE_DEFAULT (1 << 0)
205 #define EQ_PURPOSE_LARGE_ROOM (1 << 1)
206 #define EQ_PURPOSE_SMALL_SPACE (1 << 2)
207 #define EQ_PURPOSE_AVERAGE_ROOM (1 << 3)
208 #define EQ_PURPOSE_CAR_CABIN (1 << 4)
209 #define EQ_PURPOSE_HEADPHONES (1 << 5)
210 #define EQ_PURPOSE_LATE_NIGHT (1 << 6)
211 
212 #define MAXPACKETLOSSTIME 2.5f
213 
214 #define SLOPE_FACTOR_DB_TO_LINEAR 0.1151f
215 
216 #ifndef min
217 #define min(a, b) ((a) < (b) ? (a) : (b))
218 #endif
219 #ifndef max
220 #define max(a, b) ((a) > (b) ? (a) : (b))
221 #endif
222 
223 #ifndef bool
224 #define bool WORD32
225 #endif
226 
227 typedef struct ia_drc_sel_proc_output_struct {
228   FLOAT32 output_peak_level_db;
229   FLOAT32 loudness_normalization_gain_db;
230   FLOAT32 output_loudness;
231 
232   WORD32 sel_drc_set_ids[SUB_DRC_COUNT];
233   WORD32 sel_downmix_ids[SUB_DRC_COUNT];
234   WORD32 num_sel_drc_sets;
235 
236   WORD32 active_downmix_id;
237   WORD32 base_channel_count;
238   WORD32 target_channel_count;
239   WORD32 target_layout;
240   WORD32 downmix_matrix_present;
241   FLOAT32 downmix_matrix[MAX_SUBBAND_CHANNEL_COUNT][MAX_SUBBAND_CHANNEL_COUNT];
242 
243   FLOAT32 boost;
244   FLOAT32 compress;
245   WORD32 drc_characteristic_target;
246 
247   FLOAT32 mixing_level;
248   WORD32 sel_eq_set_ids[SELECTED_EQ_SET_COUNT_MAX];
249   WORD32 sel_loud_eq_id;
250 } ia_drc_sel_proc_output_struct;
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif
256