google / oboe

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

Stereo audio speakers orientation #1368

Closed tristanjl closed 3 years ago

tristanjl commented 3 years ago

Android version(s): 10 Android device(s): Pixel 3 Oboe version: 1.6.0 App name used for testing: Hello Oboe (modified to encounter issue)

Short description On the pixel 3 (would expect the same on any handset with stereo speakers) while outputting stereo audio, the audio will not change orientation to match the screen orientation

Steps to reproduce Open the samples project in Android studio Remove android:screenOrientation="portrait" from the AndroidManifest.xml In SoundGenerator.cpp, change renderAudio for statement to for (int i = 0; i < 1; ++i) Run the hello oboe app, holding the device in landscape. Flip the device 180 degrees to change screen orientation

Expected behavior Audio comes out of different speakers in both configurations

Actual behavior Audio comes out of only one speaker regardless of orientation

Device Pixel 3 was tested

Any additional context I was unable to find any documentation relating to handling of this. If this needs to be handled by the developer, this should be indicated somewhere, stating where the responsibility lies.

philburk commented 3 years ago

Very interesting question. It is tricky because the left and right speakers are often not symmetric. So YouTube, for example, mixes to mono to avoid being affected by the difference in speakers. Speaker placement and management is generally left to the manufacturers. I think it is unlikely that they will implement the channel flipping. So app developers may need to do this themselves for landscape mode.

tristanjl commented 3 years ago

Hmm, this does seem to leave us without a good solution, as if there is a handset that does channel flip, if we try to channel flip preemptively, the channels will be double flipped into an incorrect configuration.

As a follow up, we have noticed on some devices (tested on Pixel 3), when using AudioTrack for audio output, the speakers will swap output when the orientation is flipped, but not with AAudio. On another device (Nokia 2.1), it does not flip with any output mode. We have a customer wondering if they should be outputting to AudioTrack, and at this stage, this might be what we have to recommend.