How to read data from multiple microphones using Android's Oboe/AAudio

1.5k Views Asked by At

I'm interesting in accessing both microphone on a phone using the Android Oboe library. Most phones have a dual-mic configuration and I'd like to read data from both at the same time. I've extended the "LiveAffect" sample from Oboe, and tried the following:

  1. Having two oboe::AudioStream, one for each microphone on my phone (Note 9 and Pixel 1). Running only one of the streams works fine, I'm able to read the data and play it back/save to file. But starting both streams doesn't work (I get the following error when attempting to start the second stream via stream->requestStart(): E/AUDIO-APP: Error starting stream. ErrorInvalidState). Apparently starting two input streams is an Android limitation as discussed in this SO question: Android Oboe Library: 2 streams recording from 2 recording devices possible?

  2. Having one stream but with 2 channels. The two mics on my Note 9 are part of the same group, yet when I open a stream with either of them with 2 channels (->setChannelCount(oboe::ChannelCount::Stereo);), I get duplicate data in both channels for only one microphone. I've tried playing around with AudioStreamBuilder settings, for example setting ->setInputPreset(oboe::InputPreset::Camcorder). None of the InputPresets settings fixed it, still mirrored data in both channels.

Both attempts did not work using OpenSL backend either.

2

There are 2 best solutions below

0
donturner On BEST ANSWER

I'm fairly sure this is a problem with that particular device. A user reported an identical issue on the JUCE forum here. I have filed a bug internally (id: 133143785) and will attempt to route this to Samsung for further investigation.

1
jeanC On

The only way I could get a stereo input of both microphones (either AAUDIO or SLES ) on a Samsung S8 was to set:

builder->setDeviceId(0) // mandatory ! if set to the microphone id you get only one mic!
builder->setDirection(oboe::Direction::Input) // obvious
builder->setChannelCount(2) // obvious
builder->setFormat(oboe::AudioFormat::I16) // with oboe converter float should work to
builder->setInputPreset(oboe::InputPreset::Generic) // or oboe::InputPreset::Camcorder
builder->setUsage(oboe::Usage::Media) // unsure if this is ness.

Odd thing I noticed, androids AudioManager.getDevices (AudioManager.GET_DEVICES_ALL) on this device returns a different list after you used the audio in mono ( 2 x TYPE_BUILTIN_MIC ) or stereo ( 1x TYPE_BUILTIN_MIC ) all having AudioDeviceInfo.getChannelCounts() list = [1,2] !