From e72995d4ac7fe80fb608599ceb35ecb13367f903 Mon Sep 17 00:00:00 2001 From: Joshua Lang Date: Wed, 2 Nov 2016 14:29:21 -0700 Subject: Enable audio channels and set default volume This fixes the audio device being muted by default. Test: Boot emulator and check audio is not muted Change-Id: Ied6b02910dcb23fdebd3b8a1e3f8ec23d2d78ff1 --- audio/audio_hw.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'audio') diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 393494b8..4efd67b4 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -47,6 +47,7 @@ struct generic_audio_device { struct audio_hw_device device; // Constant after init pthread_mutex_t lock; bool mic_mute; // Proteced by this->lock + struct mixer* mixer; // Proteced by this->lock }; /* If not NULL, this is a pointer to the fallback module. @@ -977,6 +978,9 @@ static int adev_close(hw_device_t *dev) } if ((--audio_device_ref_count) == 0) { + if (adev->mixer) { + mixer_close(adev->mixer); + } free(adev); } @@ -1035,6 +1039,32 @@ static int adev_open(const hw_module_t* module, const char* name, *device = &adev->device.common; + adev->mixer = mixer_open(PCM_CARD); + struct mixer_ctl *ctl; + + // Set default mixer ctls + // Enable channels and set volume + for (int i = 0; i < (int)mixer_get_num_ctls(adev->mixer); i++) { + ctl = mixer_get_ctl(adev->mixer, i); + ALOGD("mixer %d name %s", i, mixer_ctl_get_name(ctl)); + if (!strcmp(mixer_ctl_get_name(ctl), "Master Playback Volume") || + !strcmp(mixer_ctl_get_name(ctl), "Capture Volume")) { + for (int z = 0; z < (int)mixer_ctl_get_num_values(ctl); z++) { + ALOGD("set ctl %d to %d", z, 100); + mixer_ctl_set_percent(ctl, z, 100); + } + continue; + } + if (!strcmp(mixer_ctl_get_name(ctl), "Master Playback Switch") || + !strcmp(mixer_ctl_get_name(ctl), "Capture Switch")) { + for (int z = 0; z < (int)mixer_ctl_get_num_values(ctl); z++) { + ALOGD("set ctl %d to %d", z, 1); + mixer_ctl_set_value(ctl, z, 1); + } + continue; + } + } + audio_device_ref_count++; unlock: -- cgit v1.2.3