summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2014-04-30 18:53:46 -0500
committerGerrit Code Review2014-06-03 17:39:33 -0500
commit3da8567243ec8a5d46581f9e5642a1a105471a6c (patch)
tree9fe3af101aea3721f0416d17fbf08434d7cbe0ca /audio/legacy
parentfe4561a100a8a0205d1bfab0bd85da4da03942fa (diff)
downloaddevice-ti-jacinto6evm-3da8567243ec8a5d46581f9e5642a1a105471a6c.tar.gz
device-ti-jacinto6evm-3da8567243ec8a5d46581f9e5642a1a105471a6c.tar.xz
device-ti-jacinto6evm-3da8567243ec8a5d46581f9e5642a1a105471a6c.zip
audio: Legacy: Use audio_route for kcontrol settings
Simplify the kcontrol settings through the audio_route library. The control settings are now moved to a XML audio paths file. Change-Id: I72670523968a6646aea28e1625798b04f7a7799f Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Diffstat (limited to 'audio/legacy')
-rw-r--r--audio/legacy/Android.mk2
-rw-r--r--audio/legacy/audio_hw.c162
2 files changed, 10 insertions, 154 deletions
diff --git a/audio/legacy/Android.mk b/audio/legacy/Android.mk
index c50fb5b..1e6c223 100644
--- a/audio/legacy/Android.mk
+++ b/audio/legacy/Android.mk
@@ -33,6 +33,7 @@ LOCAL_SRC_FILES := audio_hw.c
33 33
34LOCAL_C_INCLUDES += \ 34LOCAL_C_INCLUDES += \
35 external/tinyalsa/include \ 35 external/tinyalsa/include \
36 system/media/audio_route/include \
36 system/media/audio_utils/include \ 37 system/media/audio_utils/include \
37 system/media/audio_effects/include 38 system/media/audio_effects/include
38 39
@@ -40,6 +41,7 @@ LOCAL_SHARED_LIBRARIES := \
40 liblog \ 41 liblog \
41 libcutils \ 42 libcutils \
42 libtinyalsa \ 43 libtinyalsa \
44 libaudioroute \
43 libaudioutils 45 libaudioutils
44 46
45LOCAL_MODULE_TAGS := optional 47LOCAL_MODULE_TAGS := optional
diff --git a/audio/legacy/audio_hw.c b/audio/legacy/audio_hw.c
index 1ce01f5..d25fedf 100644
--- a/audio/legacy/audio_hw.c
+++ b/audio/legacy/audio_hw.c
@@ -33,6 +33,7 @@
33#include <cutils/properties.h> 33#include <cutils/properties.h>
34 34
35#include <audio_utils/resampler.h> 35#include <audio_utils/resampler.h>
36#include <audio_route/audio_route.h>
36#include <system/audio.h> 37#include <system/audio.h>
37#include <hardware/hardware.h> 38#include <hardware/hardware.h>
38#include <hardware/audio.h> 39#include <hardware/audio.h>
@@ -59,7 +60,7 @@ struct j6_audio_device {
59 struct audio_hw_device device; 60 struct audio_hw_device device;
60 struct j6_stream_in *in; 61 struct j6_stream_in *in;
61 struct j6_stream_out *out; 62 struct j6_stream_out *out;
62 struct mixer *mixer; 63 struct audio_route *route;
63 audio_devices_t in_device; 64 audio_devices_t in_device;
64 audio_devices_t out_device; 65 audio_devices_t out_device;
65 pthread_mutex_t lock; 66 pthread_mutex_t lock;
@@ -142,148 +143,6 @@ struct pcm_config pcm_config_playback = {
142 .avail_min = PLAYBACK_PERIOD_SIZE, 143 .avail_min = PLAYBACK_PERIOD_SIZE,
143}; 144};
144 145
145/* Mixer control names */
146
147/* Capture */
148#define MIXER_PGA_CAPTURE_SWITCH "PGA Capture Switch"
149#define MIXER_PGA_CAPTURE_VOLUME "PGA Capture Volume"
150
151/* Capture gain (0dB, 59.5dB) step=0.5 */
152#define CAPTURE_DB_TO_VAL(x) ((int)(2 * (float)(x)))
153
154/* Microphone specific */
155#define MIXER_LEFT_PGA_MIC3L_SWITCH "Left PGA Mixer Mic3L Switch"
156#define MIXER_RIGHT_PGA_MIC3R_SWITCH "Right PGA Mixer Mic3R Switch"
157
158/* Line-In specific */
159#define MIXER_LEFT_PGA_LINE1L_SWITCH "Left PGA Mixer Line1L Switch"
160#define MIXER_RIGHT_PGA_LINE1R_SWITCH "Right PGA Mixer Line1R Switch"
161#define MIXER_LEFT_LINE1L_MUX "Left Line1L Mux"
162#define MIXER_RIGHT_LINE1L_MUX "Right Line1L Mux"
163#define MIXER_LEFT_LINE1R_MUX "Left Line1R Mux"
164#define MIXER_RIGHT_LINE1R_MUX "Right Line1R Mux"
165#define MIXER_LINE_IN_SINGLE_ENDED "single-ended"
166#define MIXER_LINE_IN_DIFFERENTIAL "differential"
167
168/* Playback */
169#define MIXER_LEFT_DAC_MUX "Left DAC Mux"
170#define MIXER_RIGHT_DAC_MUX "Right DAC Mux"
171#define MIXER_MUX_DAC_L1 "DAC_L1"
172#define MIXER_MUX_DAC_R1 "DAC_R1"
173#define MIXER_PCM_PLAYBACK_VOLUME "PCM Playback Volume"
174
175 /* Playback gain (-63.5dB, 0dB) step=0.5dB */
176#define PLAYBACK_DB_TO_VAL(x) ((int)(2 * ((float)(x) + 63.5)))
177
178/* Headphone specific */
179#define MIXER_HP_PLAYBACK_SWITCH "HP Playback Switch"
180#define MIXER_LEFT_HP_DACL1_SWITCH "Left HP Mixer DACL1 Switch"
181#define MIXER_RIGHT_HP_DACR1_SWITCH "Right HP Mixer DACR1 Switch"
182#define HP_PLAYBACK_VOLUME "HP DAC Playback Volume"
183#define HP_DRIVER_POWER_ON_TIME "Output Driver Power-On time"
184#define HP_DRIVER_DELAY "200ms"
185
186/* Line-Out specific */
187#define MIXER_LINE_PLAYBACK_SWITCH "Line Playback Switch"
188#define MIXER_LEFT_LINE_DACL1_SWITCH "Left Line Mixer DACL1 Switch"
189#define MIXER_RIGHT_LINE_DACR1_SWITCH "Right Line Mixer DACR1 Switch"
190#define LINE_PLAYBACK_VOLUME "Line DAC Playback Volume"
191
192 /* Output stage gain (-59.0dB, 0dB) step=0.5dB */
193#define OUTPUT_DB_TO_VAL(x) ((int)(2 * ((float)(x) + 59.0)))
194
195struct route_setting {
196 char *ctl_name;
197 int intval;
198 char *strval;
199};
200
201#define RS_STR(ctrl, str) { .ctl_name = ctrl, .strval = str }
202#define RS_INT(ctrl, val) { .ctl_name = ctrl, .intval = val }
203#define RS_END { .ctl_name = NULL, .strval = NULL }
204
205/* These are values that never change */
206static struct route_setting rs_defaults[] = {
207 /* Capture: Mic */
208 RS_INT(MIXER_LEFT_PGA_MIC3L_SWITCH, 1),
209 RS_INT(MIXER_RIGHT_PGA_MIC3R_SWITCH, 1),
210 RS_INT(MIXER_PGA_CAPTURE_SWITCH, 1),
211 RS_INT(MIXER_PGA_CAPTURE_VOLUME, CAPTURE_DB_TO_VAL(12)), /* 12dB */
212 RS_STR(MIXER_LEFT_LINE1L_MUX, MIXER_LINE_IN_SINGLE_ENDED),
213 RS_STR(MIXER_RIGHT_LINE1L_MUX, MIXER_LINE_IN_SINGLE_ENDED),
214 RS_STR(MIXER_LEFT_LINE1R_MUX, MIXER_LINE_IN_SINGLE_ENDED),
215 RS_STR(MIXER_RIGHT_LINE1R_MUX, MIXER_LINE_IN_SINGLE_ENDED),
216
217 /* Playback: Line-Out and Headphone */
218 RS_STR(MIXER_LEFT_DAC_MUX, MIXER_MUX_DAC_L1),
219 RS_STR(MIXER_RIGHT_DAC_MUX, MIXER_MUX_DAC_R1),
220 RS_INT(MIXER_PCM_PLAYBACK_VOLUME, PLAYBACK_DB_TO_VAL(0)), /* 0dB */
221
222 RS_INT(MIXER_LEFT_HP_DACL1_SWITCH, 1),
223 RS_INT(MIXER_RIGHT_HP_DACR1_SWITCH, 1),
224 RS_INT(MIXER_HP_PLAYBACK_SWITCH, 1),
225 RS_INT(HP_PLAYBACK_VOLUME, OUTPUT_DB_TO_VAL(0)), /* 0 dB */
226 RS_STR(HP_DRIVER_POWER_ON_TIME, HP_DRIVER_DELAY),
227
228 RS_INT(MIXER_LEFT_LINE_DACL1_SWITCH, 1),
229 RS_INT(MIXER_RIGHT_LINE_DACR1_SWITCH, 1),
230 RS_INT(MIXER_LINE_PLAYBACK_SWITCH, 1),
231 RS_INT(LINE_PLAYBACK_VOLUME, OUTPUT_DB_TO_VAL(0)), /* 0 dB */
232};
233
234/* Capture switch used for mic mute */
235static struct route_setting rs_capture[] = {
236 RS_INT(MIXER_PGA_CAPTURE_SWITCH, 1),
237 RS_END
238};
239
240/*
241 * The enable flag when 0 makes the assumption that enums are disabled by
242 * "Off" and integers/booleans by 0
243 */
244static int set_route_by_array(struct mixer *mixer, struct route_setting *route,
245 int enable)
246{
247 struct mixer_ctl *ctl;
248 unsigned int i, j;
249
250 ALOGV("set_route_by_array() route=%p %s", route, enable ? "enable" : "disable");
251
252 /* Go through the route array and set each value */
253 i = 0;
254 while (route[i].ctl_name) {
255 ctl = mixer_get_ctl_by_name(mixer, route[i].ctl_name);
256 if (!ctl) {
257 ALOGE("set_route_by_array() failed to get control '%s'", route[i].ctl_name);
258 return -EINVAL;
259 }
260
261 if (route[i].strval) {
262 ALOGV("set_route_by_array() control='%s' val='%s'",
263 route[i].ctl_name, enable ? route[i].strval: "Off");
264
265 if (enable)
266 mixer_ctl_set_enum_by_string(ctl, route[i].strval);
267 else
268 mixer_ctl_set_enum_by_string(ctl, "Off");
269 } else {
270 ALOGV("set_route_by_array() control='%s' val=%d",
271 route[i].ctl_name, route[i].intval);
272
273 /* This ensures multiple (i.e. stereo) values are set jointly */
274 for (j = 0; j < mixer_ctl_get_num_values(ctl); j++) {
275 if (enable)
276 mixer_ctl_set_value(ctl, j, route[i].intval);
277 else
278 mixer_ctl_set_value(ctl, j, 0);
279 }
280 }
281 i++;
282 }
283
284 return 0;
285}
286
287static int find_supported_card(void) 146static int find_supported_card(void)
288{ 147{
289 char name[256] = ""; 148 char name[256] = "";
@@ -924,6 +783,8 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
924 ALOGE("in_read() failed to read audio data %d", ret); 783 ALOGE("in_read() failed to read audio data %d", ret);
925 usleep(read_usecs); /* limits the rate of error messages */ 784 usleep(read_usecs); /* limits the rate of error messages */
926 memset(buffer, 0, bytes); 785 memset(buffer, 0, bytes);
786 } else if (adev->mic_mute) {
787 memset(buffer, 0, bytes);
927 } 788 }
928 789
929 pthread_mutex_unlock(&in->lock); 790 pthread_mutex_unlock(&in->lock);
@@ -1070,11 +931,7 @@ static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
1070 struct j6_audio_device *adev = (struct j6_audio_device *)dev; 931 struct j6_audio_device *adev = (struct j6_audio_device *)dev;
1071 932
1072 ALOGV("adev_set_mic_mute() state=%s", state ? "mute" : "unmute"); 933 ALOGV("adev_set_mic_mute() state=%s", state ? "mute" : "unmute");
1073
1074 pthread_mutex_lock(&adev->lock);
1075 set_route_by_array(adev->mixer, rs_capture, !state);
1076 adev->mic_mute = state; 934 adev->mic_mute = state;
1077 pthread_mutex_unlock(&adev->lock);
1078 935
1079 return 0; 936 return 0;
1080} 937}
@@ -1248,8 +1105,7 @@ static int adev_close(hw_device_t *device)
1248 1105
1249 ALOGI("adev_close()"); 1106 ALOGI("adev_close()");
1250 1107
1251 mixer_close(adev->mixer); 1108 audio_route_free(adev->route);
1252 adev->mixer = NULL;
1253 free(device); 1109 free(device);
1254 1110
1255 return 0; 1111 return 0;
@@ -1302,17 +1158,15 @@ static int adev_open(const hw_module_t* module, const char* name,
1302 adev->out_port = 0; 1158 adev->out_port = 0;
1303 adev->mic_mute = false; 1159 adev->mic_mute = false;
1304 1160
1305 adev->mixer = mixer_open(adev->card); 1161 adev->route = audio_route_init(adev->card, NULL);
1306 if (!adev->mixer) { 1162 if (!adev->route) {
1163 ALOGE("Unable to initialize audio routes");
1307 free(adev); 1164 free(adev);
1308 ALOGE("Unable to open the mixer, aborting.");
1309 return -EINVAL; 1165 return -EINVAL;
1310 } 1166 }
1311 1167
1312 *device = &adev->device.common; 1168 *device = &adev->device.common;
1313 1169
1314 set_route_by_array(adev->mixer, rs_defaults, 1);
1315
1316 return 0; 1170 return 0;
1317} 1171}
1318 1172