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

查看:424
本文介绍了在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.

我已经实现了针对应用音频播放(通过修改 HAL audioflinger )。

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).

UPDATE#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.

我已经成功将其安装为系统应用,并获得了初始化的权限。 AudioRecord AudioSource.VOICE_DOWNLINK 。但是,记录给出了空白样本。

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 c $ c>但是,我无法理解它(如何使其以我想要的方式工作)。

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).

UPDATE# 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);
可以将电话的内置听筒直接路由到录音机的输入。是的,它有点肮脏和hacky,但也许符合目的。

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.

另一件事让我感到困惑的是,您没有尝试使用builder类来配置对象直接通过其构造函数。是否有特定的原因导致您不希望使用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天全站免登陆