How do you acquire microphone audio via OPENSL ES from a connected Bluetooth headset's microphone???

1,663 views
Skip to first unread message

Jake

unread,
Oct 22, 2015, 2:56:51 PM10/22/15
to android-ndk
When I connect my Bluetooth headset to an Android 4.4.2 device (Samsung T230NU) and start openSL ES microphone callbacks,
the microphone audio is not coming from the Bluetooth headset but rather the device's own microphone.

1. What are the requirements for streaming microphone audio from a BT headset via openSL ES ?
1a ) How should the openSL "channel" be configured?
1b) Do I need to execute certain Java API calls before I create and start the openSL stuff?


Thanks.

Damien Delépine

unread,
Oct 27, 2015, 10:25:59 AM10/27/15
to android-ndk
Hey Jake,

I'm facing a similar issue with ear speakers. 
Here is what i've found so far :

  1. The ideal solution would be to use the SLAudioIODeviceCapabilitiesItf. You can retrieve this interface on the engine object.
    Then, the GetAvailableAudioInputs method should help use to parse and select which device we want to use, according to the parameters of the SLAudioInputDescriptor structure. (Please see the B.1.2 Recording sample code available here).

    Unfortunately, this does not seem to be available in the android implementation. See this recap (from the doc there). IODeviceDataLocator / Engine cell is not green.

  2. The second solution I tried was to retrieve the SlAndroidConfigurationItf from the recorder himself, before you realize it (I had a weird beahior while doing it after). This interface comes with the OpenSLES_Android.h header.
    Then you can use SetConfiguration and GetConfiguration to play with one of the SL_ANDROID_RECORDING_PRESET.

    While I successfully changed the configuration and then realized my recorder, I was not able to record sound from the ear speaker built-in microphone :/

Have you tried some of these "workarounds" ?

I did not mention it but this behavior only concerns some Sony or Samsung devices I tested. Nexus devices works well. It seems to be a tricky implementation from these OEMs.
 Do you have the same results on a Nexus device ?

If anyone can bring some other stuff to adress this issue, it would be amazing !
Regards.

Glenn Kasten

unread,
Nov 5, 2015, 11:29:25 AM11/5/15
to android-ndk
#1 - as you said, this is documented as missing

#2 - Thank you for reporting this incompatibility
that some devices do not correctly support recording as you have configured.
In order that we can investigate, can you please say which device models you tested
and what the result pass/fail for each?  Thanks

Jake

unread,
Nov 5, 2015, 1:29:50 PM11/5/15
to android-ndk
I managed to get it to work, but the behavior is not consistent.

If you set the AudioManager mode to IN COMMUNICATION and _then_ create your openSL channel
audio starts flowing correctly. However, changing AudioManager mode after you have created your
openSL channel (or while callbacks are active) seems to mess things up. I have found that when you're
routing audio natively via openSL you should refrain from doing anything related to audio routing at the
SDK level.

It's amazing that audio routing has to be *this* complicated on Android when it on other platforms is
easy. And why is an obvious feature like getting available audio endpoints missing in openSL ?

How is it that these manufacturers can just deliver whatever half-ass implementation that they want without there
being some external QA in place? It is so frustrating.

Jake

unread,
Nov 5, 2015, 2:01:56 PM11/5/15
to android-ndk
Hey Glenn,

Since you're looking at this thread anyway and you have tons of experience with Android audio,
can you tell me how to intercept Bluetooth button events?

I have a Parrot B350-XT headset which has 4 buttons:

1. VOL UP
2. VOL DOWN
3. POWER
4. "Parrot" button

The Android device is Samsung ST-230NU (OS: 4.4.2)

When:

1. the BT headset is connected (STATE_CONNECTED)
2. and the SCO audio channel is established (SCO_AUDIO_STATE_CONNECTED)
3. and the headset state changes to STATE_AUDIO_CONNECTED when SCO audio is connected

then I would like to be able to use the Bluetooth buttons to control certain features in my app, but I haven't
been able to find solid documentation on how this is done.

When I look in logcat I see that the only thing that is triggered when pressing the BT buttons is something called
HeadsetStateMachine.





Damien

unread,
Nov 9, 2015, 10:10:23 AM11/9/15
to android-ndk
Hi Glenn,

I get the following results :

I will try Jake's workaround (Thank you Jake for reporting this !!) later in the week as it might solve our issue here.


I'll keep this thread up to date with my results.


Regards


Anh Tuấn Hoàng

unread,
Dec 17, 2016, 2:45:32 PM12/17/16
to android-ndk
Do you solve this issue? Can you share about the solution?
Tks!

Vào 01:56:51 UTC+7 Thứ Sáu, ngày 23 tháng 10 năm 2015, Jake đã viết:
Reply all
Reply to author
Forward
0 new messages