[Android4.4]Audio添加控制MIC左右声道接口
来源:互联网 发布:js设为首页和加入收藏 编辑:程序博客网 时间:2024/05/18 03:16
平台: 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.hindex 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.cindex 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;+ /*Kris, 20160224, add interface to set mic channel. }*/ adev->hw_device.set_master_volume = adev_set_master_volume; adev->hw_device.set_mode = adev_set_mode; adev->hw_device.set_mic_mute = adev_set_mic_mute;
hardware/libhardware目录:
diff --git a/include/hardware/audio.h b/include/hardware/audio.hindex 3ae3b42..e76b866 100644--- a/include/hardware/audio.h+++ b/include/hardware/audio.h@@ -465,6 +465,10 @@ struct audio_hw_device { int (*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. {*/+ int (*set_mic_channel)(struct audio_hw_device *dev, int channel);+ /*Kris, 20160224, add interface to set mic channel. }*/+ /** * set the audio volume for all audio activities other than voice call. * Range between 0.0 and 1.0. If any value other than 0 is returned,
AudioFlinger/AudioSystem/AudioRecord
frameworks/av目录:
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.hindex d25c404..fbfb72b 100644--- a/include/media/AudioRecord.h+++ b/include/media/AudioRecord.h@@ -196,6 +196,10 @@ public: status_t setVolume(int volume); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ status_t setMicChannel(int channel);+ /*Kris, 20160224, add interface to set mic channel. }*/+ /* Result of constructing the AudioRecord. This must be checked * before using any AudioRecord API (except for set()), because using * an uninitialized AudioRecord produces undefined results.diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.hindex 260c9ca..5318572 100644--- a/include/media/AudioSystem.h+++ b/include/media/AudioSystem.h@@ -125,6 +125,10 @@ public: static status_t setMicVolume(int value); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ static status_t setMicChannel(int channel);+ /*Kris, 20160224, add interface to set mic channel. }*/+ // return the number of audio frames written by AudioFlinger to audio HAL and // audio dsp to DAC since the output on which the specified stream is playing // has exited standby.diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.hindex 1674264..685981b 100644--- a/include/media/IAudioFlinger.h+++ b/include/media/IAudioFlinger.h@@ -171,6 +171,11 @@ public: virtual status_t setMicVolume(int volume) = 0; /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ virtual status_t setMicChannel(int channel) = 0;+ /*Kris, 20160224, add interface to set mic channel. }*/+ + virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const = 0; diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cppindex 9128e50..0cd366c 100644--- a/media/libmedia/AudioRecord.cpp+++ b/media/libmedia/AudioRecord.cpp@@ -128,6 +128,15 @@ status_t AudioRecord::setVolume(int volume) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/+status_t AudioRecord::setMicChannel(int channel)+{+ ALOGV("AudioRecord::setMicChannel:%d", channel);+ AudioSystem::setMicChannel(channel);+ return NO_ERROR;+}+/*Kris, 20160224, add interface to set mic channel. }*/+ status_t AudioRecord::set( audio_source_t inputSource,diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cppindex 39889a5..191f9ea 100644--- a/media/libmedia/AudioSystem.cpp+++ b/media/libmedia/AudioSystem.cpp@@ -400,6 +400,15 @@ status_t AudioSystem::setMicVolume(int value) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/+status_t AudioSystem::setMicChannel(int channel)+{+ const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();+ ALOGV("AudioSystem::setMicChannel:%d", channel);+ if (af == 0) return PERMISSION_DENIED;+ return af->setMicChannel(channel);+}+/*Kris, 20160224, add interface to set mic channel. }*/ status_t AudioSystem::getRenderPosition(audio_io_handle_t output, size_t *halFrames, size_t *dspFrames, audio_stream_type_t stream)diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cppindex 821d1d8..6e8a64a 100644--- a/media/libmedia/IAudioFlinger.cpp+++ b/media/libmedia/IAudioFlinger.cpp@@ -63,6 +63,9 @@ enum { /*Kris, 20150702, add interface to set mic volume. {*/ SET_MIC_VOLUME, /*Kris, 20150702, add interface to set mic volume. }*/+ /*Kris, 20160224, add interface to set mic channel. {*/+ SET_MIC_CHANNEL,+ /*Kris, 20160224, add interface to set mic channel. }*/ GET_RENDER_POSITION, GET_INPUT_FRAMES_LOST, NEW_AUDIO_SESSION_ID,@@ -539,6 +542,18 @@ public: } /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ virtual status_t setMicChannel(int channel)+ {+ Parcel data, reply;+ data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());+ data.writeInt32(channel);+ remote()->transact(SET_MIC_CHANNEL, data, &reply);+ return reply.readInt32();+ }+ /*Kris, 20160224, add interface to set mic channel. }*/++ virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const {@@ -1032,6 +1047,14 @@ status_t BnAudioFlinger::onTransact( return NO_ERROR; } break; /*Kris, 20150702, add interface to set mic volume. }*/+ /*Kris, 20160224, add interface to set mic channel. {*/+ case SET_MIC_CHANNEL: {+ CHECK_INTERFACE(IAudioFlinger, data, reply);+ uint32_t channel = data.readInt32();+ reply->writeInt32( setMicChannel(channel) );+ return NO_ERROR;+ } break;+ /*Kris, 20150702, add interface to set mic volume. }*/ case GET_RENDER_POSITION: { CHECK_INTERFACE(IAudioFlinger, data, reply); audio_io_handle_t output = (audio_io_handle_t) data.readInt32();diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cppindex 7ca2ccf..4a03af1 100644--- a/services/audioflinger/AudioFlinger.cpp+++ b/services/audioflinger/AudioFlinger.cpp@@ -1059,6 +1059,25 @@ status_t AudioFlinger::setMicVolume(int value) } /*Kris, 20150702, add interface to set mic volume. }*/ ++/*Kris, 20160224, add interface to set mic channel. {*/+status_t AudioFlinger::setMicChannel(int channel)+{+ status_t ret = initCheck();+ if (ret != NO_ERROR) {+ return ret;+ }+ ALOGV("AudioFlinger::setMicChannel: %d", value);+ AutoMutex lock(mHardwareLock);+ audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();+ ret = dev->set_mic_channel(dev, channel);++ return ret;+}+/*Kris, 20160224, add interface to set mic channel. }*/+++ status_t AudioFlinger::getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const {diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.hindex 0f159be..06cbe4d 100644--- a/services/audioflinger/AudioFlinger.h+++ b/services/audioflinger/AudioFlinger.h@@ -190,6 +190,10 @@ public: virtual status_t setMicVolume(int value); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ virtual status_t setMicChannel(int channel);+ /*Kris, 20160224, add interface to set mic channel. }*/+ virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const;
JNI
frameworks/base目录:
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cppindex 2449d21..27acc26 100644--- a/core/jni/android_media_AudioRecord.cpp+++ b/core/jni/android_media_AudioRecord.cpp@@ -541,6 +541,21 @@ android_media_AudioRecord_set_volume(JNIEnv *env, jobject thiz, jint vol )diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cppindex 2449d21..27acc26 100644--- a/core/jni/android_media_AudioRecord.cpp+++ b/core/jni/android_media_AudioRecord.cpp@@ -541,6 +541,21 @@ android_media_AudioRecord_set_volume(JNIEnv *env, jobject thiz, jint vol ) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/+static void+android_media_AudioRecord_set_mic_channel(JNIEnv *env, jobject thiz, jint channel )+{+ sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);+ if (lpRecorder == NULL) {+ jniThrowException(env, "java/lang/IllegalStateException",+ "Unable to retrieve AudioRecorder pointer for setVolume()");+ return;+ }++ lpRecorder->setMicChannel(channel);+}+/*Kris, 20160224, add interface to set mic channel. }*/+ // ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------@@ -569,6 +584,10 @@ static JNINativeMethod gMethods[] = { /*Kris, 20150702, add interface to set mic volume. {*/ {"native_setVolume", "(I)V", (void *)android_media_AudioRecord_set_volume}, /*Kris, 20150702, add interface to set mic volume. }*/++ /*Kris, 20160224, add interface to set mic channel. {*/+ {"native_setMicChannel", "(I)V", (void *)android_media_AudioRecord_set_mic_channel},+ /*Kris, 20160224, add interface to set mic channel. }*/ };
Framework
frameworks/base目录:
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.javaindex b31097a..5288aa1 100644--- a/media/java/android/media/AudioRecord.java+++ b/media/java/android/media/AudioRecord.java@@ -430,10 +430,16 @@ public class AudioRecord public int setVolume(int volume) { native_setVolume(volume); return SUCCESS;- } /*Kris, 20150702, add interface to set mic volume. {*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ public int setMicChannel(int channel) {+ native_setMicChannel(channel);+ return SUCCESS;+ }+ /*Kris, 20160224, add interface to set mic channel. {*/+ /** * Returns the minimum buffer size required for the successful creation of an AudioRecord * object, in byte units.@@ -840,6 +846,10 @@ public class AudioRecord private native final void native_setVolume(int volume); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/+ private native final void native_setMicChannel(int channel);+ /*Kris, 20160224, add interface to set mic channel. }*/+
2 0
- [Android4.4]Audio添加控制MIC左右声道接口
- MCI接口实现音频左右声道控制
- 控制左右声道
- 控制电脑的左右声道
- Android左右声道的控制
- Flash中音量和左右声道平衡的控制(1)
- Flash中音量和左右声道平衡的控制(2)
- Flash中音量和左右声道平衡的控制(3)
- VC++之多媒体编程之左右声道控制
- VC++之多媒体编程之左右声道控制
- 声道控制
- kmplayer 调左右声道
- 左右声道混合方案
- 5.1声道转化为左右声道
- audio 声道路由策略分析
- 使用AudioTrack播放MP3 左右声道控制 之移植Libmad到android平台
- VB设置左右声道音量
- 多媒体之合并左右声道
- Navicat+V10.0.11+各版本注册码
- markdown编辑器使用二
- Java Thread join() 的用法
- 安卓计算应用程序缓存大小以及清除缓存
- canvas绘图 -实现图片围绕中心点旋转
- [Android4.4]Audio添加控制MIC左右声道接口
- 39.Evaluate the following command:CREATE TABLE employees(employee_id NUMBER(2) PRIMARY KEY
- C# using 三种使用方式
- 【BZOJ1087】【codevs2451】互不侵犯,状压DP
- linux svn使用总结
- Android6.0权限问题导致下载没效果
- iOS开发-block 简单使用
- markdown编辑器使用一
- 用Android网络通信技术,在网络上直接传输对象