google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.68k stars 560 forks source link

Support earpiece speaker in demos for OpenSL ES #885

Open chrbsg opened 4 years ago

chrbsg commented 4 years ago

According to https://stackoverflow.com/questions/21576739/how-to-configure-opensl-to-work-with-ear-speaker-other-than-main-speaker-or-head and https://groups.google.com/forum/#!topic/android-ndk/O-hufEm20cU

Earpiece speaker can be selected by using option SL_ANDROID_STREAM_VOICE in OpenSL config.

It would be useful to somehow expose this in the audio demos (output device dropdown?) to demonstrate playback with OpenSL through that speaker.

philburk commented 4 years ago

OpenSL ES does not support setting the device menu.

But there are two oboe:Usages that map to that OpenSL stream:

    case Usage::VoiceCommunication:
    case Usage::VoiceCommunicationSignalling:
        openslStream = SL_ANDROID_STREAM_VOICE;

It gets set here: https://github.com/google/oboe/blob/eecaf3e26af7496c6824dcaf83ac270fc4d7fbf5/src/opensles/AudioOutputStreamOpenSLES.cpp#L196

So if we add a Usage menu to the demo then it should work.

dturner commented 4 years ago

When OpenSL ES is being used we should disable the output devices which it isn't possible to select. We can use SL_ANDROID_STREAM_VOICE to select the earpiece speaker.