[IMX6Q][Android4.4] Audio添加控制MIC左右声道接口

该博客详细介绍了如何在Freescale i.MX6Q平台上,针对Android 4.4系统,从硬件抽象层(HAL)到应用程序框架层,逐步实现AudioRecord接口,以控制MIC的左右声道。主要步骤涉及HAL修改、AudioFlinger、AudioSystem、AudioRecord、JNI及Framework的更新,确保应用能够成功调用并使用这一功能。
摘要由CSDN通过智能技术生成

平台: freescale imx6q

系统: Android4.4


主要关注的是自下而上添加的方法,添加的顺序是:

HAL -> AudioFlinger -> AudioSystem -> AudioRecord -> JNI -> Framework

这样Application申请了AudioRecord之后就可以使用了。


HAL:

hardware/imx 目录:

diff --git a/alsa/config_aic3254.h b/alsa/config_aic3254.h
index 48465d3..ae0fff5 100644
--- a/alsa/config_aic3254.h
+++ b/alsa/config_aic3254.h
@@ -23,6 +23,10 @@
 #define MIXER_AIC3254_PGA_CAP_VOLUME                  "PGA Capture Volume"
 /*Kris, 20150702, add interface to set mic volume. }*/
 
+/*Kris, 20160224, add interface to set mic channel. {*/
+#define MIXER_AIC3254_LEFT_INPUT_SWITCH 		"Left Input Mixer IN1_L switch"
+#define MIXER_AIC3254_RIGHT_INPUT_SWITCH 		"Right Input Mixer IN1_R switch"
+/*Kris, 20160224, add interface to set mic channel. }*/
 
 /* ALSA cards for IMX, these must be defined according different board / kernel config*/
 static struct audio_card  aic3254_card = {
diff --git a/alsa/tinyalsa_hal.c b/alsa/tinyalsa_hal.c
index 58ab54c..bb2ddaf 100644
--- a/alsa/tinyalsa_hal.c
+++ b/alsa/tinyalsa_hal.c
@@ -2867,6 +2867,31 @@ static int adev_set_mic_volume(struct audio_hw_device *dev, int volume)
 }
 /*Kris, 20150702, add interface to set mic volume. }*/
 
+/*Kris, 20160224, add interface to set mic channel. {*/
+static int adev_set_mic_channel(struct audio_hw_device *dev, int channel)
+{
+    struct imx_audio_device *adev = (struct imx_audio_device *)dev;
+    struct mixer_ctl *ctl;
+
+    ALOGV("adev_set_input_channel channel:%d", channel);
+
+    if (!channel) {
+        /*left input channel open.*/
+        ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_LEFT_INPUT_SWITCH);
+        mixer_ctl_set_value(ctl, 0, 1);
+        ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_RIGHT_INPUT_SWITCH);
+        mixer_ctl_set_value(ctl, 0, 0);
+    } else {
+       /*right input channel open.*/
+        ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_LEFT_INPUT_SWITCH);
+        mixer_ctl_set_value(ctl, 0, 0);
+        ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_RIGHT_INPUT_SWITCH);
+        mixer_ctl_set_value(ctl, 0, 1);
+    }
+
+    return 0;
+}
+/*Kris, 20160224, add interface to set mic channel. }*/
 
 static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
 {
@@ -3222,6 +3247,9 @@ static int adev_open(const hw_module_t* module, const char* name,
     /*Kris, 20150702, add interface to set mic volume. {*/
     adev->hw_device.set_mic_volume        =  adev_set_mic_volume;
     /*Kris, 20150702, add interface to set mic volume. }*/
+    /*Kris, 20160224, add interface to set mic channel. {*/
+    adev->hw_device.set_mic_channel       =  adev_set_mic_channel;
+    /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值