From 6a2edf8f42c9fe4533d583938362f5c183fcd887 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 13 Oct 2012 17:16:33 +0200 Subject: Bindings for Yamaha-MC1N2-Audio library Signed-off-by: Paul Kocialkowski --- Android.mk | 12 +++++++++++- audio_hw.c | 34 +++++++++++++++++++++++++++++++++- audio_hw.h | 8 ++++++++ audio_out.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/Android.mk b/Android.mk index 59f0605..a510621 100644 --- a/Android.mk +++ b/Android.mk @@ -15,7 +15,7 @@ LOCAL_PATH := $(call my-dir) -ifeq ($(strip $(BOARD_USES_TINYALSA_LIBAUDIO)),true) +ifeq ($(strip $(BOARD_USE_TINYALSA_AUDIO)),true) include $(CLEAR_VARS) @@ -41,6 +41,16 @@ LOCAL_SHARED_LIBRARIES := \ libaudioutils \ libdl +ifeq ($(strip $(BOARD_USE_YAMAHA_MC1N2_AUDIO)),true) + LOCAL_CFLAGS += -DYAMAHA_MC1N2_AUDIO + LOCAL_C_INCLUDES += hardware/yamaha-mc1n2-audio/include + LOCAL_SHARED_LIBRARIES += libyamaha-mc1n2-audio + + ifeq ($(TARGET_DEVICE),galaxys2) + LOCAL_CFLAGS += -DYAMAHA_MC1N2_AUDIO_DEVICE=\"galaxys2\" + endif +endif + LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := optional diff --git a/audio_hw.c b/audio_hw.c index e2cb1c3..144706d 100644 --- a/audio_hw.c +++ b/audio_hw.c @@ -27,6 +27,10 @@ #include +#ifdef YAMAHA_MC1N2_AUDIO +#include +#endif + #include "audio_hw.h" #include "mixer.h" @@ -214,11 +218,18 @@ int audio_hw_close(hw_device_t *device) if(device != NULL) { tinyalsa_audio_device = (struct tinyalsa_audio_device *) device; - if(tinyalsa_audio_device != NULL && tinyalsa_audio_device->mixer != NULL) { + if(tinyalsa_audio_device->mixer != NULL) { tinyalsa_mixer_close(tinyalsa_audio_device->mixer); tinyalsa_audio_device->mixer = NULL; } +#ifdef YAMAHA_MC1N2_AUDIO + if(tinyalsa_audio_device->mc1n2_pdata != NULL) { + yamaha_mc1n2_audio_stop(tinyalsa_audio_device->mc1n2_pdata); + tinyalsa_audio_device->mc1n2_pdata = NULL; + } +#endif + free(device); } @@ -268,6 +279,20 @@ int audio_hw_open(const hw_module_t *module, const char *name, dev->dump = audio_hw_dump; +#ifdef YAMAHA_MC1N2_AUDIO + rc = yamaha_mc1n2_audio_start(&tinyalsa_audio_device->mc1n2_pdata, + YAMAHA_MC1N2_AUDIO_DEVICE); + if(rc < 0) { + LOGE("Failed to open Yamaha-MC1N2-Audio"); + goto error_device; + } + + rc = yamaha_mc1n2_audio_routine_init(tinyalsa_audio_device->mc1n2_pdata); + if(rc < 0) { + LOGE("Failed to init Yamaha-MC1N2-Audio"); + } +#endif + rc = tinyalsa_mixer_open(&tinyalsa_mixer, TINYALSA_MIXER_CONFIG_FILE); if(rc < 0 || tinyalsa_mixer == NULL) { LOGE("Failed to open mixer!"); @@ -279,6 +304,13 @@ int audio_hw_open(const hw_module_t *module, const char *name, LOGE("Failed to set default mixer route"); } +#ifdef YAMAHA_MC1N2_AUDIO + rc = yamaha_mc1n2_audio_routine_route_init(tinyalsa_audio_device->mc1n2_pdata); + if(rc < 0) { + LOGE("Failed to init Yamaha-MC1N2-Audio route"); + } +#endif + tinyalsa_audio_device->mixer = tinyalsa_mixer; *device = &(dev->common); diff --git a/audio_hw.h b/audio_hw.h index 555ee0b..84750b5 100644 --- a/audio_hw.h +++ b/audio_hw.h @@ -22,6 +22,10 @@ #include #include +#ifdef YAMAHA_MC1N2_AUDIO +#include +#endif + struct tinyalsa_audio_stream_out { struct audio_stream_out stream; struct tinyalsa_audio_device *device; @@ -60,6 +64,10 @@ struct tinyalsa_audio_device { struct tinyalsa_audio_stream_out *stream_out; struct tinyalsa_audio_stream_in *stream_in; +#ifdef YAMAHA_MC1N2_AUDIO + struct yamaha_mc1n2_audio_pdata *mc1n2_pdata; +#endif + struct tinyalsa_mixer *mixer; audio_mode_t mode; int mic_mute; diff --git a/audio_out.c b/audio_out.c index 69394c8..47f4dfa 100644 --- a/audio_out.c +++ b/audio_out.c @@ -28,6 +28,10 @@ #include #include +#ifdef YAMAHA_MC1N2_AUDIO +#include +#endif + #define EFFECT_UUID_NULL EFFECT_UUID_NULL_OUT #define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_OUT #include "audio_hw.h" @@ -188,6 +192,7 @@ static int audio_out_set_format(struct audio_stream *stream, int format) static int audio_out_standby(struct audio_stream *stream) { struct tinyalsa_audio_stream_out *stream_out; + int rc; LOGD("%s(%p)", __func__, stream); @@ -199,6 +204,15 @@ static int audio_out_standby(struct audio_stream *stream) if(stream_out->pcm != NULL) audio_out_pcm_close(stream_out); +#ifdef YAMAHA_MC1N2_AUDIO + if(!stream_out->standby) { + rc = yamaha_mc1n2_audio_routine_route_stop(stream_out->device->mc1n2_pdata); + if(rc < 0) { + LOGE("Failed to set Yamaha-MC1N2-Audio route"); + } + } +#endif + stream_out->standby = 1; return 0; @@ -302,6 +316,13 @@ static ssize_t audio_out_write(struct audio_stream_out *stream, stream_out = (struct tinyalsa_audio_stream_out *) stream; if(stream_out->standby) { +#ifdef YAMAHA_MC1N2_AUDIO + rc = yamaha_mc1n2_audio_routine_route_start(stream_out->device->mc1n2_pdata); + if(rc < 0) { + LOGE("Failed to set Yamaha-MC1N2-Audio route"); + } +#endif + rc = audio_out_pcm_open(stream_out); if(rc < 0) { LOGE("Unable to open pcm device"); @@ -429,6 +450,13 @@ int audio_hw_open_output_stream(struct audio_hw_device *dev, goto error_stream; } +#ifdef YAMAHA_MC1N2_AUDIO + rc = yamaha_mc1n2_audio_routine_postopen(tinyalsa_audio_device->mc1n2_pdata); + if(rc < 0) { + LOGE("Failed to init Yamaha-MC1N2-Audio route"); + } +#endif + audio_out_pcm_close(tinyalsa_audio_stream_out); tinyalsa_audio_stream_out->standby = 1; -- cgit v1.1