blob: 489c07ef2789517442eeb0bd54dc8a351cbeff7f
1 | #define LOG_TAG "LibAudioCtl" |
2 | |
3 | #include <stdbool.h> |
4 | #include <stdio.h> |
5 | #include <string.h> |
6 | #include <stdlib.h> |
7 | #include <stdint.h> |
8 | #include <signal.h> |
9 | #include <pthread.h> |
10 | #include <unistd.h> |
11 | #include <math.h> |
12 | #include <fcntl.h> |
13 | #include <sys/mman.h> |
14 | #include <sys/ioctl.h> |
15 | #include <sys/stat.h> |
16 | #include <dlfcn.h> |
17 | |
18 | #include <cutils/log.h> |
19 | #include <cutils/properties.h> |
20 | #include <tinyalsa/asoundlib.h> |
21 | #include <hardware/audio.h> |
22 | |
23 | #include "audio_usb_check.h" |
24 | #include "audio_effect_control.h" |
25 | #include "../audio_amaudio.h" |
26 | #include "../../audio_virtual_effect.h" |
27 | |
28 | //#define ENABLE_AUDIO |
29 | int amSetAudioDelay(int delay_ms) { |
30 | #ifdef ENABLE_AUDIO |
31 | return set_audio_delay(delay_ms); |
32 | #else |
33 | return 0; |
34 | #endif |
35 | } |
36 | |
37 | int amGetAudioDelay(void) { |
38 | #ifdef ENABLE_AUDIO |
39 | return get_audio_delay(); |
40 | #else |
41 | return 0; |
42 | #endif |
43 | } |
44 | |
45 | int amAudioOpen(unsigned int sr, int input_device, int output_device) { |
46 | #ifdef ENABLE_AUDIO |
47 | int ret; |
48 | ret = aml_audio_open(sr, input_device, output_device); |
49 | return ret; |
50 | #else |
51 | return 0; |
52 | #endif |
53 | } |
54 | |
55 | int amAudioClose(void) { |
56 | #ifdef ENABLE_AUDIO |
57 | return aml_audio_close(); |
58 | #else |
59 | return 0; |
60 | #endif |
61 | } |
62 | |
63 | int amAudioSetInputSr(unsigned int sr, int input_device, int output_device) { |
64 | #ifdef ENABLE_AUDIO |
65 | int tmpRet = 0; |
66 | |
67 | if (check_input_stream_sr(sr) < 0) { |
68 | ALOGE("%s, The sample rate (%u) is invalid!\n", __FUNCTION__, sr); |
69 | return -1; |
70 | } |
71 | |
72 | tmpRet |= amAudioClose(); |
73 | tmpRet |= amAudioOpen(sr, input_device, output_device); |
74 | |
75 | return tmpRet; |
76 | #else |
77 | return 0; |
78 | #endif |
79 | } |
80 | |
81 | int amAudioSetDumpDataFlag(int tmp_flag) { |
82 | #ifdef ENABLE_AUDIO |
83 | return SetDumpDataFlag(tmp_flag); |
84 | #else |
85 | return 0; |
86 | #endif |
87 | } |
88 | |
89 | int amAudioGetDumpDataFlag() { |
90 | #ifdef ENABLE_AUDIO |
91 | return GetDumpDataFlag(); |
92 | #else |
93 | return 0; |
94 | #endif |
95 | } |
96 | |
97 | int amAudioSetOutputMode(int mode) { |
98 | #ifdef ENABLE_AUDIO |
99 | return set_output_mode(mode); |
100 | #else |
101 | return 0; |
102 | #endif |
103 | } |
104 | |
105 | int amAudioSetMusicGain(int gain) { |
106 | #ifdef ENABLE_AUDIO |
107 | return set_music_gain(gain); |
108 | #else |
109 | return 0; |
110 | #endif |
111 | } |
112 | |
113 | int amAudioSetLeftGain(int gain) { |
114 | #ifdef ENABLE_AUDIO |
115 | return set_left_gain(gain); |
116 | #else |
117 | return 0; |
118 | #endif |
119 | } |
120 | |
121 | int amAudioSetRightGain(int gain) { |
122 | #ifdef ENABLE_AUDIO |
123 | return set_right_gain(gain); |
124 | #else |
125 | return 0; |
126 | #endif |
127 | } |
128 | |
129 | int eq_gain_buf[5] = {0,0,0,0,0}; |
130 | int amAudioSetEQGain(int gain_val_buf[], int buf_item_cnt __unused) { |
131 | #ifdef ENABLE_AUDIO |
132 | int i = 0, ret = 0; |
133 | int tmp_buf[5] = { 0, 0, 0, 0, 0}; |
134 | |
135 | for (i = 0; i < 5; i++) { |
136 | tmp_buf[i] = gain_val_buf[i]; |
137 | eq_gain_buf[i] = gain_val_buf[i]; |
138 | } |
139 | |
140 | HPEQ_setParameter(tmp_buf[0], tmp_buf[1], tmp_buf[2], tmp_buf[3], |
141 | tmp_buf[4]); |
142 | |
143 | char param[15]; |
144 | char parm_key[] = AUDIO_PARAMETER_STREAM_EQ; |
145 | sprintf(param, "%02d%02d%02d%02d%02d", tmp_buf[0]+10, tmp_buf[1]+10, |
146 | tmp_buf[2]+10, tmp_buf[3]+10, tmp_buf[4]+10); |
147 | |
148 | ret = set_parameters(param, parm_key); |
149 | //ALOGE("EQ param : %s\n", param); |
150 | return ret; |
151 | #else |
152 | return 0; |
153 | #endif |
154 | } |
155 | |
156 | int amAudioGetEQGain(int gain_val_buf[], int buf_item_cnt __unused) { |
157 | #ifdef ENABLE_AUDIO |
158 | int i = 0; |
159 | int tmp_buf[5] = { 0, 0, 0, 0, 0}; |
160 | |
161 | HPEQ_getParameter(tmp_buf); |
162 | |
163 | for (i = 0; i < 5; i++) { |
164 | gain_val_buf[i] = tmp_buf[i]; |
165 | } |
166 | return 0; |
167 | #else |
168 | return 0; |
169 | #endif |
170 | } |
171 | |
172 | int amAudioSetEQEnable(int en_val) { |
173 | #ifdef ENABLE_AUDIO |
174 | return HPEQ_enable(en_val); |
175 | #else |
176 | return 0; |
177 | #endif |
178 | } |
179 | |
180 | int amAudioGetEQEnable() { |
181 | return 0; |
182 | } |
183 | |
184 | #define CC_SET_TYPE_TRUBASS_SPEAKERSIZE (0) |
185 | #define CC_SET_TYPE_TRUBASS_GAIN (1) |
186 | #define CC_SET_TYPE_DIALOGCLARITY_GAIN (2) |
187 | #define CC_SET_TYPE_DEFINITION_GAIN (3) |
188 | #define CC_SET_TYPE_SURROUND_GAIN (4) |
189 | #define CC_SET_TYPE_MAX (5) |
190 | |
191 | |
192 | |
193 | int srs_param_buf[5] = { 0, 0, 0, 0, 0}; |
194 | static int amAudioSetSRSParameter(int set_type, int gain_val) { |
195 | #ifdef ENABLE_AUDIO |
196 | int ret = 0; |
197 | |
198 | srs_param_buf[set_type] = gain_val; |
199 | ret = srs_setParameter(srs_param_buf); |
200 | |
201 | char param[20]; |
202 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS; |
203 | |
204 | sprintf(param, "%03d%03d%03d%03d%03d", srs_param_buf[0], |
205 | srs_param_buf[1], srs_param_buf[2], |
206 | srs_param_buf[3], srs_param_buf[4]); |
207 | ret = set_parameters(param, parm_key); |
208 | return ret; |
209 | #else |
210 | return 0; |
211 | #endif |
212 | } |
213 | |
214 | int amAudioSetSRSGain(int input_gain, int output_gain) { |
215 | #ifdef ENABLE_AUDIO |
216 | int ret = 0; |
217 | ret = srs_set_gain(input_gain, output_gain); |
218 | |
219 | char param[10]; |
220 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_GAIN; |
221 | sprintf(param, "%03d%03d", input_gain, output_gain); |
222 | ret = set_parameters(param, parm_key); |
223 | |
224 | return ret; |
225 | #else |
226 | return 0; |
227 | #endif |
228 | } |
229 | |
230 | #define CC_SET_SWITCH_SURROUND (0) |
231 | #define CC_SET_SWITCH_DIALOGCLARITY (1) |
232 | #define CC_SET_SWITCH_TRUBASS (2) |
233 | int srs_switch[3]= {0, 0, 0}; |
234 | |
235 | int amAudioSetSRSSurroundSwitch(int switch_val) { |
236 | #ifdef ENABLE_AUDIO |
237 | int ret = 0; |
238 | ret = srs_surround_enable(switch_val); |
239 | |
240 | srs_switch[CC_SET_SWITCH_SURROUND] = switch_val; |
241 | char param[10]; |
242 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
243 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
244 | ret = set_parameters(param, parm_key); |
245 | |
246 | return ret; |
247 | #else |
248 | return 0; |
249 | #endif |
250 | } |
251 | |
252 | int amAudioSetSRSDialogClaritySwitch(int switch_val) { |
253 | #ifdef ENABLE_AUDIO |
254 | int ret = 0; |
255 | ret = srs_dialogclarity_enable(switch_val); |
256 | |
257 | srs_switch[CC_SET_SWITCH_DIALOGCLARITY] = switch_val; |
258 | char param[10]; |
259 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
260 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
261 | ret = set_parameters(param, parm_key); |
262 | |
263 | return ret; |
264 | #else |
265 | return 0; |
266 | #endif |
267 | } |
268 | |
269 | int amAudioSetSRSTrubassSwitch(int switch_val) { |
270 | #ifdef ENABLE_AUDIO |
271 | int ret = 0; |
272 | ret = srs_truebass_enable(switch_val); |
273 | |
274 | srs_switch[CC_SET_SWITCH_TRUBASS] = switch_val; |
275 | char param[10]; |
276 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
277 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
278 | ret = set_parameters(param, parm_key); |
279 | |
280 | return ret; |
281 | #else |
282 | return 0; |
283 | #endif |
284 | } |
285 | |
286 | int amAudioSetSRSSurroundGain(int gain_val) { |
287 | #ifdef ENABLE_AUDIO |
288 | return amAudioSetSRSParameter(CC_SET_TYPE_SURROUND_GAIN, gain_val); |
289 | #else |
290 | return 0; |
291 | #endif |
292 | } |
293 | |
294 | int amAudioSetSRSTrubassGain(int gain_val) { |
295 | #ifdef ENABLE_AUDIO |
296 | return amAudioSetSRSParameter(CC_SET_TYPE_TRUBASS_GAIN, gain_val); |
297 | #else |
298 | return 0; |
299 | #endif |
300 | } |
301 | |
302 | int amAudioSetSRSDialogClarityGain(int gain_val) { |
303 | #ifdef ENABLE_AUDIO |
304 | return amAudioSetSRSParameter(CC_SET_TYPE_DIALOGCLARITY_GAIN, gain_val); |
305 | #else |
306 | return 0; |
307 | #endif |
308 | } |
309 | |
310 | int amAudioSetSRSDefinitionGain(int gain_val) { |
311 | #ifdef ENABLE_AUDIO |
312 | return amAudioSetSRSParameter(CC_SET_TYPE_DEFINITION_GAIN, gain_val); |
313 | #else |
314 | return 0; |
315 | #endif |
316 | } |
317 | |
318 | int amAudioSetSRSTrubassSpeakerSize(int tmp_val) { |
319 | #ifdef ENABLE_AUDIO |
320 | return amAudioSetSRSParameter(CC_SET_TYPE_TRUBASS_SPEAKERSIZE, tmp_val); |
321 | #else |
322 | return 0; |
323 | #endif |
324 | } |
325 | |
326 | int amAudioSetPreGain(float gain) { |
327 | #ifdef ENABLE_AUDIO |
328 | return aml_audio_set_pregain(gain); |
329 | #else |
330 | return 0; |
331 | #endif |
332 | } |
333 | |
334 | int amAudioGetPreGain(float *gain) { |
335 | #ifdef ENABLE_AUDIO |
336 | return aml_audio_get_pregain(gain); |
337 | #else |
338 | return 0; |
339 | #endif |
340 | } |
341 | |
342 | int amAudioSetPreMute(uint mute) { |
343 | #ifdef ENABLE_AUDIO |
344 | return aml_audio_set_pre_mute(mute); |
345 | #else |
346 | return 0; |
347 | #endif |
348 | } |
349 | |
350 | int amAudioGetPreMute(uint *mute) { |
351 | #ifdef ENABLE_AUDIO |
352 | return aml_audio_get_pre_mute(mute); |
353 | #else |
354 | return 0; |
355 | #endif |
356 | } |
357 | |
358 | int virtual_para_buf[2] = {0,0}; |
359 | int amAudioVirtualizer(int enable, int EffectLevel) { |
360 | #ifdef ENABLE_AUDIO |
361 | int ret = 0; |
362 | char param[10]; |
363 | virtual_para_buf[0] = enable; |
364 | virtual_para_buf[1] = EffectLevel; |
365 | char parm_key[] = "AML_VIRTUALIZER"; |
366 | sprintf(param, "%03d%03d", enable, EffectLevel); |
367 | ret = set_parameters(param, parm_key); |
368 | Virtualizer_control(enable, EffectLevel); |
369 | return ret; |
370 | #else |
371 | return 0; |
372 | #endif |
373 | } |
374 |