#StackBounty: #android #android-source #alsa #android-kernel #android-rom Modifying in-call voice playback in Android custom ROM

Bounty: 200

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

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

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

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


I’m attempting to create a Java layer app that routes the phone playback to the music stream in real time.
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.

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


        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 = null;

        // Stop playback
        mTrack = null;

I’m running on 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.

Also I’ve been looking at:
The function voice_check_and_set_incall_rec_usecase at hardware/qcom/audio/hal/voice.c
But wasn’t able to make sense out of it or how to make it work.

Get this bounty!!!