From 6be81bf7c5fbf502f0122ca535eaf425eabab7cb Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Wed, 29 Aug 2012 00:27:54 +0200 Subject: Audio: Added Audio RIL Interface, updated TinyALSA configuration Signed-off-by: Paul Kocialkowski --- audio-ril-interface/Android.mk | 27 +++++ audio-ril-interface/audio-ril-interface.cpp | 159 ++++++++++++++++++++++++++++ gta04.mk | 3 +- tinyalsa-audio.xml | 38 ++++++- 4 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 audio-ril-interface/Android.mk create mode 100644 audio-ril-interface/audio-ril-interface.cpp diff --git a/audio-ril-interface/Android.mk b/audio-ril-interface/Android.mk new file mode 100644 index 0000000..2b77bf5 --- /dev/null +++ b/audio-ril-interface/Android.mk @@ -0,0 +1,27 @@ +LOCAL_PATH:= $(call my-dir) + +ifeq ($(TARGET_DEVICE),gta04) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libaudio-ril-interface +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := audio-ril-interface.cpp + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libtinyalsa + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) +LOCAL_C_INCLUDES := $(LOCAL_PATH) +LOCAL_C_INCLUDES += \ + external/tinyalsa/include \ + hardware/tinyalsa-audio/include/ + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +endif diff --git a/audio-ril-interface/audio-ril-interface.cpp b/audio-ril-interface/audio-ril-interface.cpp new file mode 100644 index 0000000..dba1832 --- /dev/null +++ b/audio-ril-interface/audio-ril-interface.cpp @@ -0,0 +1,159 @@ +/** + * Audio RIL Interface for GTA04 + * + * Copyright (C) 2012 Paul Kocialkowski + * + * Audio RIL Interface is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Audio RIL Interface is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Audio RIL Interface. If not, see . + */ + +#include +#include + +#define LOG_TAG "AudioRILInterface" +#include +#include +#include + +#include + +#define DEVICE "Goldelico GTA04" + +/* + * Structures + */ + +struct gta04_pdata { + struct pcm *voice_pcm; + int mode; +}; + +/* + * Functions + */ + +void *gta04_pdata_create(void) +{ + struct gta04_pdata *pdata = NULL; + + pdata = (struct gta04_pdata *) calloc(1, sizeof(struct gta04_pdata)); + return (void *) pdata; +} + +void gta04_pdata_destroy(void *pdata) +{ + if(pdata != NULL) + free(pdata); +} + +int gta04_mode(void *pdata, int mode) +{ + struct pcm_config config; + struct gta04_pdata *gta04_pdata = NULL; + void *buffer = NULL; + int size = 0; + + if(pdata == NULL) + return -1; + + gta04_pdata = (struct gta04_pdata *) pdata; + + if(mode == android::AudioSystem::MODE_IN_CALL && gta04_pdata->mode != android::AudioSystem::MODE_IN_CALL) { + LOGD("Starting call, activating voice!"); + + /* + * It seems that on GTA04 A4, microphone voice routing to + * the modem only works when a capture channel is active. + * Note that Android will close any existing capture channel. + */ + memset(&config, 0, sizeof(config)); + + config.channels = 2; + config.rate = 44100; + config.period_size = 1056; + config.period_count = 2; + config.format = PCM_FORMAT_S16_LE; + + gta04_pdata->voice_pcm = pcm_open(0, 0, PCM_IN, &config); + if(!gta04_pdata->voice_pcm || !pcm_is_ready(gta04_pdata->voice_pcm)) { + LOGE("Failed to open capture channel!"); + } + + size = pcm_get_buffer_size(gta04_pdata->voice_pcm); + buffer = malloc(size); + + LOGD("Reading one sample"); + + pcm_read(gta04_pdata->voice_pcm, buffer, size); + + free(buffer); + } else if(mode != android::AudioSystem::MODE_IN_CALL && gta04_pdata->mode == android::AudioSystem::MODE_IN_CALL) { + LOGD("Ending call, deactivating voice!"); + + if(gta04_pdata->voice_pcm != NULL) + pcm_close(gta04_pdata->voice_pcm); + + gta04_pdata->voice_pcm = NULL; + } + + gta04_pdata->mode = mode; + + return 0; +} + +int gta04_mic_mute(void *pdata, int mute) +{ + return 0; +} + +int gta04_voice_volume(void *pdata, float volume) +{ + return 0; +} + +int gta04_routing(void *pdata, int route) +{ + return 0; +} + +/* + * Interface + */ + +extern "C" { + +struct audio_ril_interface gta04_interface = { + NULL, + gta04_mode, + gta04_mic_mute, + gta04_voice_volume, + gta04_routing +}; + +struct audio_ril_interface *audio_ril_interface_open(void) +{ + LOGE("%s (%s)", __func__, DEVICE); + + gta04_interface.pdata = gta04_pdata_create(); + + return >a04_interface; +} + +void audio_ril_interface_close(struct audio_ril_interface *interface_p) +{ + LOGE("%s (%s)", __func__, DEVICE); + + gta04_pdata_destroy(interface_p->pdata); +} + +} diff --git a/gta04.mk b/gta04.mk index bad70f2..00b9b94 100644 --- a/gta04.mk +++ b/gta04.mk @@ -27,7 +27,8 @@ PRODUCT_COPY_FILES += \ # Audio PRODUCT_PACKAGES += \ libaudio \ - libaudiopolicy + libaudiopolicy \ + libaudio-ril-inteface PRODUCT_COPY_FILES += \ device/goldelico/gta04/tinyalsa-audio.xml:system/etc/tinyalsa-audio.xml diff --git a/tinyalsa-audio.xml b/tinyalsa-audio.xml index 49598c3..7a0bf22 100644 --- a/tinyalsa-audio.xml +++ b/tinyalsa-audio.xml @@ -9,12 +9,45 @@ - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + @@ -26,6 +59,7 @@ + -- cgit v1.1