修改Android自定义ROM中的通话语音播放 [英] Modifying in-call voice playback in Android custom ROM

查看:46
本文介绍了修改Android自定义ROM中的通话语音播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改 Android OS(AOSP 官方图片),为普通电话播放声音添加预处理.

I would like to modify Android OS (official image from AOSP) to add preprocessing to a normal phone call playback sound.

我已经为应用音频播放实现了这种过滤(通过修改 HALaudioflinger).

I've already achieved this filtering for app audio playback (by modifying HAL and audioflinger).

我可以只针对特定设备(Nexus 5X).另外,我只需要过滤播放 - 我不关心录音(上行).

I'm OK with targeting only a specific device (Nexus 5X). Also, I only need to filter playback - I don't care about recording (uplink).

更新 #1:

澄清一下 - 我可以修改 Qualcomm 特定的驱动程序,或者它在 Nexus 5X 上运行的任何部分,可以帮助我修改通话中的播放.

To make it clear - I'm OK with modifying Qualcomm-specific drivers, or whatever part that it is that runs on Nexus 5X and can help me modify in-call playback.

更新 #2:

我正在尝试创建一个 Java 层应用程序,将手机播放实时路由到音乐流.

I'm attempting to create a Java layer app that routes the phone playback to the music stream in real time.

我已经成功地将它安装为系统应用,获得了使用 AudioSource.VOICE_DOWNLINK 初始化 AudioRecord 的权限.然而,记录给出了空白样本;它不会记录语音通话.

I've already succeeded in installing it as a system app, getting permissions for initializing AudioRecord with AudioSource.VOICE_DOWNLINK. However, the recording gives blank samples; it doesn't record the voice call.

这是我的工作线程中的代码:

This is the code inside my worker thread:

// Start recording
int recBufferSize = AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
mRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_DOWNLINK, 44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, recBufferSize);

// Start playback
int playBufferSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
mTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, playBufferSize, AudioTrack.MODE_STREAM);

mRecord.startRecording();;
mTrack.play();

int bufSize = 1024;
short[] buffer = new short[bufSize];
int res;
while (!interrupted())
{
    // Pull recording buffers and play back
    res = mRecord.read(buffer, 0, bufSize, AudioRecord.READ_NON_BLOCKING);
    mTrack.write(buffer, 0, res, AudioTrack.WRITE_BLOCKING);
}

// Stop recording
mRecord.stop();
mRecord.release();
mRecord = null;

// Stop playback
mTrack.stop();
mTrack.release();;
mTrack = null;

我在 Nexus 5X、我自己的 AOSP 自定义 ROM、Android 7.1.1 上运行.我需要找到允许通话录音工作的地方 - 可能在平台代码中的 hardware/qcom/audio/hal 某处.

I'm running on a Nexus 5X, my own AOSP custom ROM, Android 7.1.1. I need to find the place which will allow call recording to work - probably somewhere in hardware/qcom/audio/hal in platform code.

此外,我一直在查看 hardware/qcom/audio/hal/voice.c 中的 voice_check_and_set_incall_rec_usecase 函数,但是,我无法理解它(如何让它按照我想要的方式工作).

Also I've been looking at the function voice_check_and_set_incall_rec_usecase at hardware/qcom/audio/hal/voice.c However, I wasn't able to make sense of it (how to make it work the way I want it to).

更新 #3:

我打开了一个关于使用AudioSource.VOICE_DOWNLINK的更具体的问题,这可能会引起正确的注意并最终帮助我解决这个问题的问题.

I've opened a more-specific question about using AudioSource.VOICE_DOWNLINK, which might draw the right attention and will eventually help me solve this question's problem as well.

推荐答案

我想到了几个可能的问题.空白缓冲区可能表示您选择了错误的源.另外根据 https://developer.android.com/reference/android/media/AudioRecord.html#AudioRecord(int,%20int,%20int,%20int,%20int) 你可能并不总是得到例外即使配置有问题,您也可能想确认您的对象是否已正确初始化.如果一切都失败了,你也可以做一个"mRecord.setPreferredDevice(AudioDeviceInfo.TYPE_BUILTIN_EARPIECE);"将手机的内置听筒直接连接到录音机的输入端.是的,它有点肮脏和笨拙,但也许适合这个目的.

There are several possible issues that come to my mind. The blank buffer might indicate that you have the wrong source selected. Also since according to https://developer.android.com/reference/android/media/AudioRecord.html#AudioRecord(int,%20int,%20int,%20int,%20int) you might not always get an exception even if something's wrong with the configuration, you might want to confirm whether your object has been initialized properly. If all else fails, you could also do an "mRecord.setPreferredDevice(AudioDeviceInfo.TYPE_BUILTIN_EARPIECE);" to route the phone's built-in earpiece directly to the input of your recorder. Yeah, it's kinda dirty and hacky, but perhaps suits the purpose.

让我感到困惑的另一件事是,您没有使用构建器类,而是尝试通过其构造函数直接配置对象.您不想使用 AudioRecord.Builder 是否有特定原因(在 https://developer.android.com/reference/android/media/AudioRecord.Builder.html )代替?

The other thing what was puzzling me that instead of using the builder class you've tried to configure the object directly via its constructor. Is there a specific reason why you don't want to use AudioRecord.Builder (there's even a nice example at https://developer.android.com/reference/android/media/AudioRecord.Builder.html ) instead?

这篇关于修改Android自定义ROM中的通话语音播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆