1 /*
2  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 and
6  * only version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 
14 #ifndef _AUDIO_EFFECTS_H
15 #define _AUDIO_EFFECTS_H
16 
17 /** AUDIO EFFECTS **/
18 
19 
20 /* CONFIG GET/SET */
21 #define CONFIG_CACHE			0
22 #define CONFIG_SET			1
23 #define CONFIG_GET			2
24 
25 /* CONFIG HEADER */
26 /*
27 
28 	MODULE_ID,
29 	DEVICE,
30 	NUM_COMMANDS,
31 	COMMAND_ID_1,
32 	CONFIG_CACHE/SET/GET,
33 	OFFSET_1,
34 	LENGTH_1,
35 	VALUES_1,
36 	...,
37 	...,
38 	COMMAND_ID_2,
39 	CONFIG_CACHE/SET/GET,
40 	OFFSET_2,
41 	LENGTH_2,
42 	VALUES_2,
43 	...,
44 	...,
45 	COMMAND_ID_3,
46 	...
47 */
48 
49 
50 /* CONFIG PARAM IDs */
51 #define VIRTUALIZER_MODULE		0x00001000
52 #define VIRTUALIZER_ENABLE		0x00001001
53 #define VIRTUALIZER_STRENGTH		0x00001002
54 #define VIRTUALIZER_OUT_TYPE		0x00001003
55 #define VIRTUALIZER_GAIN_ADJUST		0x00001004
56 #define VIRTUALIZER_ENABLE_PARAM_LEN		1
57 #define VIRTUALIZER_STRENGTH_PARAM_LEN		1
58 #define VIRTUALIZER_OUT_TYPE_PARAM_LEN		1
59 #define VIRTUALIZER_GAIN_ADJUST_PARAM_LEN	1
60 
61 #define REVERB_MODULE			0x00002000
62 #define REVERB_ENABLE			0x00002001
63 #define REVERB_MODE			0x00002002
64 #define REVERB_PRESET			0x00002003
65 #define REVERB_WET_MIX			0x00002004
66 #define REVERB_GAIN_ADJUST		0x00002005
67 #define REVERB_ROOM_LEVEL		0x00002006
68 #define REVERB_ROOM_HF_LEVEL		0x00002007
69 #define REVERB_DECAY_TIME		0x00002008
70 #define REVERB_DECAY_HF_RATIO		0x00002009
71 #define REVERB_REFLECTIONS_LEVEL	0x0000200a
72 #define REVERB_REFLECTIONS_DELAY	0x0000200b
73 #define REVERB_LEVEL			0x0000200c
74 #define REVERB_DELAY			0x0000200d
75 #define REVERB_DIFFUSION		0x0000200e
76 #define REVERB_DENSITY			0x0000200f
77 #define REVERB_ENABLE_PARAM_LEN			1
78 #define REVERB_MODE_PARAM_LEN			1
79 #define REVERB_PRESET_PARAM_LEN			1
80 #define REVERB_WET_MIX_PARAM_LEN		1
81 #define REVERB_GAIN_ADJUST_PARAM_LEN		1
82 #define REVERB_ROOM_LEVEL_PARAM_LEN		1
83 #define REVERB_ROOM_HF_LEVEL_PARAM_LEN		1
84 #define REVERB_DECAY_TIME_PARAM_LEN		1
85 #define REVERB_DECAY_HF_RATIO_PARAM_LEN		1
86 #define REVERB_REFLECTIONS_LEVEL_PARAM_LEN	1
87 #define REVERB_REFLECTIONS_DELAY_PARAM_LEN	1
88 #define REVERB_LEVEL_PARAM_LEN			1
89 #define REVERB_DELAY_PARAM_LEN			1
90 #define REVERB_DIFFUSION_PARAM_LEN		1
91 #define REVERB_DENSITY_PARAM_LEN		1
92 
93 #define BASS_BOOST_MODULE		0x00003000
94 #define BASS_BOOST_ENABLE		0x00003001
95 #define BASS_BOOST_MODE			0x00003002
96 #define BASS_BOOST_STRENGTH		0x00003003
97 #define BASS_BOOST_ENABLE_PARAM_LEN		1
98 #define BASS_BOOST_MODE_PARAM_LEN		1
99 #define BASS_BOOST_STRENGTH_PARAM_LEN		1
100 
101 #define EQ_MODULE			0x00004000
102 #define EQ_ENABLE			0x00004001
103 #define EQ_CONFIG			0x00004002
104 #define EQ_NUM_BANDS			0x00004003
105 #define EQ_BAND_LEVELS			0x00004004
106 #define EQ_BAND_LEVEL_RANGE		0x00004005
107 #define EQ_BAND_FREQS			0x00004006
108 #define EQ_SINGLE_BAND_FREQ_RANGE	0x00004007
109 #define EQ_SINGLE_BAND_FREQ		0x00004008
110 #define EQ_BAND_INDEX			0x00004009
111 #define EQ_PRESET_ID			0x0000400a
112 #define EQ_NUM_PRESETS			0x0000400b
113 #define EQ_PRESET_NAME			0x0000400c
114 #define EQ_ENABLE_PARAM_LEN			1
115 #define EQ_CONFIG_PARAM_LEN			3
116 #define EQ_CONFIG_PER_BAND_PARAM_LEN		5
117 #define EQ_NUM_BANDS_PARAM_LEN			1
118 #define EQ_BAND_LEVELS_PARAM_LEN		13
119 #define EQ_BAND_LEVEL_RANGE_PARAM_LEN		2
120 #define EQ_BAND_FREQS_PARAM_LEN			13
121 #define EQ_SINGLE_BAND_FREQ_RANGE_PARAM_LEN	2
122 #define EQ_SINGLE_BAND_FREQ_PARAM_LEN		1
123 #define EQ_BAND_INDEX_PARAM_LEN			1
124 #define EQ_PRESET_ID_PARAM_LEN			1
125 #define EQ_NUM_PRESETS_PARAM_LEN		1
126 #define EQ_PRESET_NAME_PARAM_LEN		32
127 
128 #define EQ_TYPE_NONE	0
129 #define EQ_BASS_BOOST	1
130 #define EQ_BASS_CUT	2
131 #define EQ_TREBLE_BOOST	3
132 #define EQ_TREBLE_CUT	4
133 #define EQ_BAND_BOOST	5
134 #define EQ_BAND_CUT	6
135 
136 #define SOFT_VOLUME_MODULE		0x00006000
137 #define SOFT_VOLUME_ENABLE		0x00006001
138 #define SOFT_VOLUME_GAIN_2CH		0x00006002
139 #define SOFT_VOLUME_GAIN_MASTER		0x00006003
140 #define SOFT_VOLUME_ENABLE_PARAM_LEN		1
141 #define SOFT_VOLUME_GAIN_2CH_PARAM_LEN		2
142 #define SOFT_VOLUME_GAIN_MASTER_PARAM_LEN	1
143 
144 #define SOFT_VOLUME2_MODULE		0x00007000
145 #define SOFT_VOLUME2_ENABLE		0x00007001
146 #define SOFT_VOLUME2_GAIN_2CH		0x00007002
147 #define SOFT_VOLUME2_GAIN_MASTER	0x00007003
148 #define SOFT_VOLUME2_ENABLE_PARAM_LEN		SOFT_VOLUME_ENABLE_PARAM_LEN
149 #define SOFT_VOLUME2_GAIN_2CH_PARAM_LEN		SOFT_VOLUME_GAIN_2CH_PARAM_LEN
150 #define SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN	\
151 					SOFT_VOLUME_GAIN_MASTER_PARAM_LEN
152 
153 #define PBE_CONF_MODULE_ID	0x00010C2A
154 #define PBE_CONF_PARAM_ID	0x00010C49
155 
156 #define PBE_MODULE		0x00008000
157 #define PBE_ENABLE		0x00008001
158 #define PBE_CONFIG		0x00008002
159 #define PBE_ENABLE_PARAM_LEN		1
160 #define PBE_CONFIG_PARAM_LEN		28
161 
162 #define COMMAND_PAYLOAD_LEN	3
163 #define COMMAND_PAYLOAD_SZ	(COMMAND_PAYLOAD_LEN * sizeof(uint32_t))
164 #define MAX_INBAND_PARAM_SZ	4096
165 #define Q27_UNITY		(1 << 27)
166 #define Q8_UNITY		(1 << 8)
167 #define CUSTOM_OPENSL_PRESET	18
168 
169 #define VIRTUALIZER_ENABLE_PARAM_SZ	\
170 			(VIRTUALIZER_ENABLE_PARAM_LEN*sizeof(uint32_t))
171 #define VIRTUALIZER_STRENGTH_PARAM_SZ	\
172 			(VIRTUALIZER_STRENGTH_PARAM_LEN*sizeof(uint32_t))
173 #define VIRTUALIZER_OUT_TYPE_PARAM_SZ	\
174 			(VIRTUALIZER_OUT_TYPE_PARAM_LEN*sizeof(uint32_t))
175 #define VIRTUALIZER_GAIN_ADJUST_PARAM_SZ	\
176 			(VIRTUALIZER_GAIN_ADJUST_PARAM_LEN*sizeof(uint32_t))
177 struct virtualizer_params {
178 	uint32_t device;
179 	uint32_t enable_flag;
180 	uint32_t strength;
181 	uint32_t out_type;
182 	int32_t gain_adjust;
183 };
184 
185 #define NUM_OSL_REVERB_PRESETS_SUPPORTED	6
186 #define REVERB_ENABLE_PARAM_SZ		\
187 			(REVERB_ENABLE_PARAM_LEN*sizeof(uint32_t))
188 #define REVERB_MODE_PARAM_SZ		\
189 			(REVERB_MODE_PARAM_LEN*sizeof(uint32_t))
190 #define REVERB_PRESET_PARAM_SZ		\
191 			(REVERB_PRESET_PARAM_LEN*sizeof(uint32_t))
192 #define REVERB_WET_MIX_PARAM_SZ		\
193 			(REVERB_WET_MIX_PARAM_LEN*sizeof(uint32_t))
194 #define REVERB_GAIN_ADJUST_PARAM_SZ	\
195 			(REVERB_GAIN_ADJUST_PARAM_LEN*sizeof(uint32_t))
196 #define REVERB_ROOM_LEVEL_PARAM_SZ	\
197 			(REVERB_ROOM_LEVEL_PARAM_LEN*sizeof(uint32_t))
198 #define REVERB_ROOM_HF_LEVEL_PARAM_SZ	\
199 			(REVERB_ROOM_HF_LEVEL_PARAM_LEN*sizeof(uint32_t))
200 #define REVERB_DECAY_TIME_PARAM_SZ	\
201 			(REVERB_DECAY_TIME_PARAM_LEN*sizeof(uint32_t))
202 #define REVERB_DECAY_HF_RATIO_PARAM_SZ	\
203 			(REVERB_DECAY_HF_RATIO_PARAM_LEN*sizeof(uint32_t))
204 #define REVERB_REFLECTIONS_LEVEL_PARAM_SZ	\
205 			(REVERB_REFLECTIONS_LEVEL_PARAM_LEN*sizeof(uint32_t))
206 #define REVERB_REFLECTIONS_DELAY_PARAM_SZ	\
207 			(REVERB_REFLECTIONS_DELAY_PARAM_LEN*sizeof(uint32_t))
208 #define REVERB_LEVEL_PARAM_SZ		\
209 			(REVERB_LEVEL_PARAM_LEN*sizeof(uint32_t))
210 #define REVERB_DELAY_PARAM_SZ		\
211 			(REVERB_DELAY_PARAM_LEN*sizeof(uint32_t))
212 #define REVERB_DIFFUSION_PARAM_SZ	\
213 			(REVERB_DIFFUSION_PARAM_LEN*sizeof(uint32_t))
214 #define REVERB_DENSITY_PARAM_SZ		\
215 			(REVERB_DENSITY_PARAM_LEN*sizeof(uint32_t))
216 struct reverb_params {
217 	uint32_t device;
218 	uint32_t enable_flag;
219 	uint32_t mode;
220 	uint32_t preset;
221 	uint32_t wet_mix;
222 	int32_t  gain_adjust;
223 	int32_t  room_level;
224 	int32_t  room_hf_level;
225 	uint32_t decay_time;
226 	uint32_t decay_hf_ratio;
227 	int32_t  reflections_level;
228 	uint32_t reflections_delay;
229 	int32_t  level;
230 	uint32_t delay;
231 	uint32_t diffusion;
232 	uint32_t density;
233 };
234 
235 #define BASS_BOOST_ENABLE_PARAM_SZ	\
236 			(BASS_BOOST_ENABLE_PARAM_LEN*sizeof(uint32_t))
237 #define BASS_BOOST_MODE_PARAM_SZ	\
238 			(BASS_BOOST_MODE_PARAM_LEN*sizeof(uint32_t))
239 #define BASS_BOOST_STRENGTH_PARAM_SZ	\
240 			(BASS_BOOST_STRENGTH_PARAM_LEN*sizeof(uint32_t))
241 struct bass_boost_params {
242 	uint32_t device;
243 	uint32_t enable_flag;
244 	uint32_t mode;
245 	uint32_t strength;
246 };
247 
248 
249 #define MAX_EQ_BANDS 12
250 #define MAX_OSL_EQ_BANDS 5
251 #define EQ_ENABLE_PARAM_SZ			\
252 			(EQ_ENABLE_PARAM_LEN*sizeof(uint32_t))
253 #define EQ_CONFIG_PARAM_SZ			\
254 			(EQ_CONFIG_PARAM_LEN*sizeof(uint32_t))
255 #define EQ_CONFIG_PER_BAND_PARAM_SZ		\
256 			(EQ_CONFIG_PER_BAND_PARAM_LEN*sizeof(uint32_t))
257 #define EQ_CONFIG_PARAM_MAX_LEN			(EQ_CONFIG_PARAM_LEN+\
258 			MAX_EQ_BANDS*EQ_CONFIG_PER_BAND_PARAM_LEN)
259 #define EQ_CONFIG_PARAM_MAX_SZ			\
260 			(EQ_CONFIG_PARAM_MAX_LEN*sizeof(uint32_t))
261 #define EQ_NUM_BANDS_PARAM_SZ			\
262 			(EQ_NUM_BANDS_PARAM_LEN*sizeof(uint32_t))
263 #define EQ_BAND_LEVELS_PARAM_SZ			\
264 			(EQ_BAND_LEVELS_PARAM_LEN*sizeof(uint32_t))
265 #define EQ_BAND_LEVEL_RANGE_PARAM_SZ		\
266 			(EQ_BAND_LEVEL_RANGE_PARAM_LEN*sizeof(uint32_t))
267 #define EQ_BAND_FREQS_PARAM_SZ			\
268 			(EQ_BAND_FREQS_PARAM_LEN*sizeof(uint32_t))
269 #define EQ_SINGLE_BAND_FREQ_RANGE_PARAM_SZ	\
270 			(EQ_SINGLE_BAND_FREQ_RANGE_PARAM_LEN*sizeof(uint32_t))
271 #define EQ_SINGLE_BAND_FREQ_PARAM_SZ		\
272 			(EQ_SINGLE_BAND_FREQ_PARAM_LEN*sizeof(uint32_t))
273 #define EQ_BAND_INDEX_PARAM_SZ			\
274 			(EQ_BAND_INDEX_PARAM_LEN*sizeof(uint32_t))
275 #define EQ_PRESET_ID_PARAM_SZ			\
276 			(EQ_PRESET_ID_PARAM_LEN*sizeof(uint32_t))
277 #define EQ_NUM_PRESETS_PARAM_SZ			\
278 			(EQ_NUM_PRESETS_PARAM_LEN*sizeof(uint8_t))
279 struct eq_config_t {
280 	int32_t eq_pregain;
281 	int32_t preset_id;
282 	uint32_t num_bands;
283 };
284 struct eq_per_band_config_t {
285 	int32_t band_idx;
286 	uint32_t filter_type;
287 	uint32_t freq_millihertz;
288 	int32_t  gain_millibels;
289 	uint32_t quality_factor;
290 };
291 struct eq_per_band_freq_range_t {
292 	uint32_t band_index;
293 	uint32_t min_freq_millihertz;
294 	uint32_t max_freq_millihertz;
295 };
296 
297 struct eq_params {
298 	uint32_t device;
299 	uint32_t enable_flag;
300 	struct eq_config_t config;
301 	struct eq_per_band_config_t per_band_cfg[MAX_EQ_BANDS];
302 	struct eq_per_band_freq_range_t per_band_freq_range[MAX_EQ_BANDS];
303 	uint32_t band_index;
304 	uint32_t freq_millihertz;
305 };
306 
307 #define PBE_ENABLE_PARAM_SZ	\
308 			(PBE_ENABLE_PARAM_LEN*sizeof(uint32_t))
309 #define PBE_CONFIG_PARAM_SZ	\
310 			(PBE_CONFIG_PARAM_LEN*sizeof(uint16_t))
311 struct pbe_config_t {
312 	int16_t  real_bass_mix;
313 	int16_t  bass_color_control;
314 	uint16_t main_chain_delay;
315 	uint16_t xover_filter_order;
316 	uint16_t bandpass_filter_order;
317 	int16_t  drc_delay;
318 	uint16_t rms_tav;
319 	int16_t exp_threshold;
320 	uint16_t exp_slope;
321 	int16_t comp_threshold;
322 	uint16_t comp_slope;
323 	uint16_t makeup_gain;
324 	uint32_t comp_attack;
325 	uint32_t comp_release;
326 	uint32_t exp_attack;
327 	uint32_t exp_release;
328 	int16_t limiter_bass_threshold;
329 	int16_t limiter_high_threshold;
330 	int16_t limiter_bass_makeup_gain;
331 	int16_t limiter_high_makeup_gain;
332 	int16_t limiter_bass_gc;
333 	int16_t limiter_high_gc;
334 	int16_t  limiter_delay;
335 	uint16_t reserved;
336 	/* place holder for filter coeffs to be followed */
337 	int32_t p1LowPassCoeffs[5*2];
338 	int32_t p1HighPassCoeffs[5*2];
339 	int32_t p1BandPassCoeffs[5*3];
340 	int32_t p1BassShelfCoeffs[5];
341 	int32_t p1TrebleShelfCoeffs[5];
342 } __packed;
343 
344 struct pbe_params {
345 	uint32_t device;
346 	uint32_t enable_flag;
347 	uint32_t cfg_len;
348 	struct pbe_config_t config;
349 };
350 
351 #define SOFT_VOLUME_ENABLE_PARAM_SZ		\
352 			(SOFT_VOLUME_ENABLE_PARAM_LEN*sizeof(uint32_t))
353 #define SOFT_VOLUME_GAIN_MASTER_PARAM_SZ	\
354 			(SOFT_VOLUME_GAIN_MASTER_PARAM_LEN*sizeof(uint32_t))
355 #define SOFT_VOLUME_GAIN_2CH_PARAM_SZ		\
356 			(SOFT_VOLUME_GAIN_2CH_PARAM_LEN*sizeof(uint16_t))
357 struct soft_volume_params {
358 	uint32_t device;
359 	uint32_t enable_flag;
360 	uint32_t master_gain;
361 	uint32_t left_gain;
362 	uint32_t right_gain;
363 };
364 
365 struct msm_nt_eff_all_config {
366 	struct bass_boost_params bass_boost;
367 	struct pbe_params pbe;
368 	struct virtualizer_params virtualizer;
369 	struct reverb_params reverb;
370 	struct eq_params equalizer;
371 	struct soft_volume_params saplus_vol;
372 	struct soft_volume_params topo_switch_vol;
373 };
374 
375 #endif /*_MSM_AUDIO_EFFECTS_H*/
376