-1
  • Device: HUAWEI P smart

  • Android-Version: 8.0.0

  • Generic Application:
    RecDev1 -> PlayDev1
    RecDev2 -> PlayDev2
    "simultaneous streaming"
    where
    RecDev can be built-in mic, USB-mic or headset-mic
    and
    PlayDev can be built-in speaker, USB-speaker or headset-speaker
    any input and output device shall be streamed "SIMULTANEOUSLY" in any combination as shown above.

  • Example Application (all devices with "1" channel):
    Guitar -> wired-mic -> [(processing)] -> built-in-Speaker
    Voice -> built-in mic -> [(processing)] -> wired-speaker
    "simultaneous streaming"

  • Code:
    is just an extended version of the sample "LiveEffect" provided by oboe.
    Up to now I tried:
    . straight forward extension
    . LiveEffectEngine no longer singleton (2 instances with own long mEngineHandle)
    . use of 2 separate threads
    . set a callback for the recording stream(s)

  • Note:
    I get the warning Stream is NOT low latency for all 4 streams but all parameters match:
    SharingMode::Exclusive PerformanceMode::LowLatency (not accepted) mSampleRate 48000 (default of PlaybackDevice) AudioFormat::I16

with OpenSL-ES API: I cannot start the second recordingStream, stream->requestStart() returns "ErrorInternal"

with AAudio API: I cannot open the second recordingStream, builder.openStream() returns "ErrorInvalidState"

In both cases I call builder->setCallback(nullptr) so I thought using separate threads might help, but this didn't solve the problem.

Any ideas?

Marco
  • 13
  • 4
  • Please provide a bit more info including: Which Android device are you using? What are you trying to achieve? Is this using the built-in microphone(s) or an attached USB recording device? Please also post the minimum source code required to reproduce your issue. – donturner Dec 17 '18 at 17:35
  • @donturner I added the information to the comment – Marco Dec 18 '18 at 08:17

2 Answers2

3

Android does not allow you to open input (ie recording) audio streams to more than one audio device at the same time. This use case is not supported.

Perhaps if you explain why you want to record from different built-in microphones at the same time I could suggest a workaround.

Update: The term Audio Device refers to a device capable or receiving or sending audio. An audio device can have multiple microphones and/or speakers attached to it, and these are represented as different channels.

donturner
  • 17,867
  • 8
  • 59
  • 81
  • I don't want to record from different "built-in" microphones at the same time, what I want is e.g.: USB-Audio-In ---> Speaker, and at the same time Mic ----> USB-Audio-Out. I thought this should be a "basic" use case. – Marco Dec 18 '18 at 09:42
  • Sorry, I still don't get it. Why do you want to record from 2 microphones on 2 different audio devices at the same time? – donturner Dec 19 '18 at 14:31
  • is this relevant for answering the question? – Marco Dec 19 '18 at 16:02
  • If you tell me what you're trying to do maybe I can suggest a workaround, or put in a feature request with the Android audio team if it's a reasonable use case. What you've specified so far cannot be done because Android doesn't support recording from different audio devices simultaneously, regardless of whether they're built-in or not. – donturner Dec 19 '18 at 19:24
  • Sorry, I don't want to disclose my idea (thank you for your understanding). Nevertheless, I can think of many use cases based on the same technical approach. E.g. mix an instrument (RecDev1) with voice (RecDev2) and add cool effects. This could be output to an external speaker. Another option could be processing these inputs independently and then output them to two different audio outputs. Even a second instrument could be added in a RecDev3. I am so frustrated, I was really counting with this functionality. Can you provide a link to add a feature request directly? – Marco Dec 20 '18 at 06:00
  • Those use cases could all be handled through a single audio device which has multiple microphones attached. For example you have a 2 channel audio device which has 2 microphones attached, one for instrument, one for voice. You have a *single* audio stream which receives both channels, do your audio processing on each channel separately, then mix the channels back together and send to a different playback device (the speaker). This is fully supported. – donturner Dec 20 '18 at 18:55
  • Thank you for your time. I updated the comment with an Example Application (all devices with "1" channel): Guitar -> wired-mic -> [(processing)] -> Speaker .... Voice -> built-in mic -> [(processing)] -> wired-speaker This is what I need. What do you mean with a device with 2 mics? – Marco Dec 20 '18 at 22:30
  • For future reference it would've been a lot easier to answer your question if you'd included this example in your original question text. As I said, this use case isn't supported, and neither is it supported on any other major operating system (as far as I'm aware). There are hardware limitations which don't allow multiple audio devices to run concurrently. By a 2 channel audio device I mean something like this: https://www.gear4music.com/Recording-and-Computers/ESI-UGM96-Ultra-Mobile-USB-Audio-Interface/1RAP – donturner Dec 21 '18 at 15:12
  • Could you please take a look at my question https://stackoverflow.com/q/61245561/5709159 – Sirop4ik Apr 21 '20 at 19:08
-2

** according to Don Turner's answer: "Android does not allow you to open input (ie recording) audio streams to more than one audio device at the same time. This use case is not supported."

** More clearly:
- Android does NOT support recording from more than ONE input devices at the same time.
- Android does NOT support playback to more than ONE output devices at the same time.
- and for sure, the combination of the 2 points above does NOT work either.

** This can be easily tested e.g. by running 2 instances of this AAudio Sample in parallel and selecting different output devices. This will just NOT work!

** This VERY IMPORTANT CONSTRAINT is not mentioned anywhere in the official documentation!!!

** Therefore, the following "example use case" is NOT supported by Android (oboe, aaudio, opensl es):

USB-Audio-In ---> In-line-speaker
and at the same time
Mic ----> USB-Audio-Out

** I am quite disappointed, I spent time and money to start something based on this, assuming this was "basic" functionality...now I have to give up :-(

** If I find the right place, then I will enter a "request" to support this "feature", e.g. in AAudio.

** Hope this helps other people before they invest too much time in something beyond the current capabilities offered by Android and the corresponding libraries.


** A possible workaround indicated by donturner would be instead using a special USB-soundcard with 2 inputs and 2 outputs which are just separate channels in the same device. Unfortunately, this does not really work for me because I was targeting a low-cost solution without additional hardware (using the headset interface).

Marco
  • 13
  • 4
  • [Here](https://stackoverflow.com/questions/43384037/is-it-possible-to-record-audio-from-two-mic-inputs-independently-at-a-time) you find a similar case where "2 built-in mics" can be used.. – Marco Dec 19 '18 at 16:25
  • The solution there is using a single audio device with 2 microphones (left and right). – donturner Dec 20 '18 at 18:59
  • Please consider accepting my answer since it is more accurate than yours (and you've just quoted part of my answer) – donturner Dec 20 '18 at 19:09