blob: b46cc87a3f696f14004086f7ab29cbd29c2b0b50
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 | |
27 | int amSetAudioDelay(int delay_ms) { |
28 | return set_audio_delay(delay_ms); |
29 | } |
30 | |
31 | int amGetAudioDelay(void) { |
32 | return get_audio_delay(); |
33 | } |
34 | |
35 | int amAudioOpen(unsigned int sr, int input_device, int output_device) { |
36 | int ret; |
37 | ret = aml_audio_open(sr, input_device, output_device); |
38 | return ret; |
39 | } |
40 | |
41 | int amAudioClose(void) { |
42 | return aml_audio_close(); |
43 | } |
44 | |
45 | int amAudioSetInputSr(unsigned int sr, int input_device, int output_device) { |
46 | int tmpRet = 0; |
47 | |
48 | if (check_input_stream_sr(sr) < 0) { |
49 | ALOGE("%s, The sample rate (%u) is invalid!\n", __FUNCTION__, sr); |
50 | return -1; |
51 | } |
52 | |
53 | tmpRet |= amAudioClose(); |
54 | tmpRet |= amAudioOpen(sr, input_device, output_device); |
55 | |
56 | return tmpRet; |
57 | } |
58 | |
59 | int amAudioSetDumpDataFlag(int tmp_flag) { |
60 | return SetDumpDataFlag(tmp_flag); |
61 | } |
62 | |
63 | int amAudioGetDumpDataFlag() { |
64 | return GetDumpDataFlag(); |
65 | } |
66 | |
67 | int amAudioSetOutputMode(int mode) { |
68 | return set_output_mode(mode); |
69 | } |
70 | |
71 | int amAudioSetMusicGain(int gain) { |
72 | return set_music_gain(gain); |
73 | } |
74 | |
75 | int amAudioSetLeftGain(int gain) { |
76 | return set_left_gain(gain); |
77 | } |
78 | |
79 | int amAudioSetRightGain(int gain) { |
80 | return set_right_gain(gain); |
81 | } |
82 | |
83 | int amAudioSetEQGain(int gain_val_buf[], int buf_item_cnt __unused) { |
84 | int i = 0, ret = 0; |
85 | int tmp_buf[5] = { 0, 0, 0, 0, 0}; |
86 | |
87 | for (i = 0; i < 5; i++) { |
88 | tmp_buf[i] = gain_val_buf[i]; |
89 | } |
90 | |
91 | HPEQ_setParameter(tmp_buf[0], tmp_buf[1], tmp_buf[2], tmp_buf[3], |
92 | tmp_buf[4]); |
93 | |
94 | char param[15]; |
95 | char parm_key[] = AUDIO_PARAMETER_STREAM_EQ; |
96 | sprintf(param, "%02d%02d%02d%02d%02d", tmp_buf[0]+10, tmp_buf[1]+10, |
97 | tmp_buf[2]+10, tmp_buf[3]+10, tmp_buf[4]+10); |
98 | |
99 | ret = set_parameters(param, parm_key); |
100 | //ALOGE("EQ param : %s\n", param); |
101 | return ret; |
102 | } |
103 | |
104 | int amAudioGetEQGain(int gain_val_buf[], int buf_item_cnt __unused) { |
105 | int i = 0; |
106 | int tmp_buf[5] = { 0, 0, 0, 0, 0}; |
107 | |
108 | HPEQ_getParameter(tmp_buf); |
109 | |
110 | for (i = 0; i < 5; i++) { |
111 | gain_val_buf[i] = tmp_buf[i]; |
112 | } |
113 | return 0; |
114 | } |
115 | |
116 | int amAudioSetEQEnable(int en_val) { |
117 | return HPEQ_enable(en_val); |
118 | } |
119 | |
120 | int amAudioGetEQEnable() { |
121 | return 0; |
122 | } |
123 | |
124 | #define CC_SET_TYPE_TRUBASS_SPEAKERSIZE (0) |
125 | #define CC_SET_TYPE_TRUBASS_GAIN (1) |
126 | #define CC_SET_TYPE_DIALOGCLARITY_GAIN (2) |
127 | #define CC_SET_TYPE_DEFINITION_GAIN (3) |
128 | #define CC_SET_TYPE_SURROUND_GAIN (4) |
129 | #define CC_SET_TYPE_MAX (5) |
130 | |
131 | |
132 | |
133 | int srs_param_buf[5] = { 0, 0, 0, 0, 0}; |
134 | static int amAudioSetSRSParameter(int set_type, int gain_val) { |
135 | int ret = 0; |
136 | |
137 | srs_param_buf[set_type] = gain_val; |
138 | ret = srs_setParameter(srs_param_buf); |
139 | |
140 | char param[20]; |
141 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS; |
142 | |
143 | sprintf(param, "%03d%03d%03d%03d%03d", srs_param_buf[0], |
144 | srs_param_buf[1], srs_param_buf[2], |
145 | srs_param_buf[3], srs_param_buf[4]); |
146 | ret = set_parameters(param, parm_key); |
147 | return ret; |
148 | } |
149 | |
150 | int amAudioSetSRSGain(int input_gain, int output_gain) { |
151 | int ret = 0; |
152 | ret = srs_set_gain(input_gain, output_gain); |
153 | |
154 | char param[10]; |
155 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_GAIN; |
156 | sprintf(param, "%03d%03d", input_gain, output_gain); |
157 | ret = set_parameters(param, parm_key); |
158 | |
159 | return ret; |
160 | } |
161 | |
162 | #define CC_SET_SWITCH_SURROUND (0) |
163 | #define CC_SET_SWITCH_DIALOGCLARITY (1) |
164 | #define CC_SET_SWITCH_TRUBASS (2) |
165 | int srs_switch[3]= {0, 0, 0}; |
166 | |
167 | int amAudioSetSRSSurroundSwitch(int switch_val) { |
168 | int ret = 0; |
169 | ret = srs_surround_enable(switch_val); |
170 | |
171 | srs_switch[CC_SET_SWITCH_SURROUND] = switch_val; |
172 | char param[10]; |
173 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
174 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
175 | ret = set_parameters(param, parm_key); |
176 | |
177 | return ret; |
178 | } |
179 | |
180 | int amAudioSetSRSDialogClaritySwitch(int switch_val) { |
181 | int ret = 0; |
182 | ret = srs_dialogclarity_enable(switch_val); |
183 | |
184 | srs_switch[CC_SET_SWITCH_DIALOGCLARITY] = switch_val; |
185 | char param[10]; |
186 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
187 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
188 | ret = set_parameters(param, parm_key); |
189 | |
190 | return ret; |
191 | } |
192 | |
193 | int amAudioSetSRSTrubassSwitch(int switch_val) { |
194 | int ret = 0; |
195 | ret = srs_truebass_enable(switch_val); |
196 | |
197 | srs_switch[CC_SET_SWITCH_TRUBASS] = switch_val; |
198 | char param[10]; |
199 | char parm_key[] = AUDIO_PARAMETER_STREAM_SRS_SWITCH; |
200 | sprintf(param, "%02d%02d%02d", srs_switch[0], srs_switch[1], srs_switch[2]); |
201 | ret = set_parameters(param, parm_key); |
202 | |
203 | return ret; |
204 | } |
205 | |
206 | int amAudioSetSRSSurroundGain(int gain_val) { |
207 | return amAudioSetSRSParameter(CC_SET_TYPE_SURROUND_GAIN, gain_val); |
208 | } |
209 | |
210 | int amAudioSetSRSTrubassGain(int gain_val) { |
211 | return amAudioSetSRSParameter(CC_SET_TYPE_TRUBASS_GAIN, gain_val); |
212 | } |
213 | |
214 | int amAudioSetSRSDialogClarityGain(int gain_val) { |
215 | return amAudioSetSRSParameter(CC_SET_TYPE_DIALOGCLARITY_GAIN, gain_val); |
216 | } |
217 | |
218 | int amAudioSetSRSDefinitionGain(int gain_val) { |
219 | return amAudioSetSRSParameter(CC_SET_TYPE_DEFINITION_GAIN, gain_val); |
220 | } |
221 | |
222 | int amAudioSetSRSTrubassSpeakerSize(int tmp_val) { |
223 | return amAudioSetSRSParameter(CC_SET_TYPE_TRUBASS_SPEAKERSIZE, tmp_val); |
224 | } |
225 | |
226 | int amAudioSetPreGain(float gain) |
227 | { |
228 | return aml_audio_set_pregain(gain); |
229 | } |
230 | |
231 | int amAudioGetPreGain(float *gain) |
232 | { |
233 | return aml_audio_get_pregain(gain); |
234 | } |
235 | int amAudioSetPreMute(uint mute) |
236 | { |
237 | return aml_audio_set_pre_mute(mute); |
238 | } |
239 | |
240 | int amAudioGetPreMute(uint *mute) |
241 | { |
242 | return aml_audio_get_pre_mute(mute); |
243 | } |
244 | int amAudioVirtualizer(int enable, int EffectLevel) { |
245 | int ret = 0; |
246 | char param[10]; |
247 | char parm_key[] = "AML_VIRTUALIZER"; |
248 | sprintf(param, "%03d%03d", enable, EffectLevel); |
249 | ret = set_parameters(param, parm_key); |
250 | //Virtualizer_control(enable, EffectLevel); |
251 | return ret; |
252 | } |
253 |