Microphone input

When capturing audio, the Audio HAL receives an openInputStream call that includes an AudioSource argument to indicate how microphone input should be processed.

The VOICE_RECOGNITION source expects a stereo microphone stream that has an echo cancellation effect (if available) but no other processing applied to it.

Multi-channel microphone input

To capture audio from a device with more than two channels (stereo), use a channel index mask instead of positional index mask (such as CHANNEL_IN_LEFT). For example:

final AudioFormat audioFormat = new AudioFormat.Builder()
    .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
    .setSampleRate(44100)
    .setChannelIndexMask(0xf /* 4 channels, 0..3 */)
    .build();
final AudioRecord audioRecord = new AudioRecord.Builder()
    .setAudioFormat(audioFormat)
    .build();
audioRecord.setPreferredDevice(someAudioDeviceInfo);

When both setChannelMask and setChannelIndexMask are set, AudioRecord uses only the value set by setChannelMask (maximum of two channels).

Concurrent capture

As of Android 10, the Android framework supports Concurrent capture of inputs, but with restrictions to protect the user’s privacy. As part of these restrictions, virtual sources such as AUDIO_SOURCE_FM_TUNER are ignored, and are allowed to be captured concurrently along with a regular input (such as the microphone). HwAudioSource is not considered part of the concurrent capture restrictions.

Apps designed to work with AUDIO_DEVICE_IN_BUS devices or with secondary AUDIO_DEVICE_IN_FM_TUNER devices must rely on explicitly identifying those devices and using AudioRecord.setPreferredDevice() to bypass the Android default source selection logic.