Skip to content

Default SpatializationBehavior to Auto and make Never opt-in - #2421

Merged
robertwu1 merged 1 commit into
mainfrom
spatialization-auto-default
Sep 16, 2026
Merged

robertwu1 merged 1 commit into
mainfrom
spatialization-auto-default

Conversation

@robertwu1

@robertwu1 robertwu1 commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Previously, Oboe explicitly overrode SpatializationBehavior::Unspecified to SpatializationBehavior::Never by default (added in commit 9e24a77022d20cf89c4a444873e8a82b72781b6d, PR #1776) with a comment // Override Unspecified as Never to reduce latency, and also defaulted mSpatializationBehavior to Never on API <= 31 and OpenSL ES.

However, overriding Unspecified to Never prevents Android XR from spatializing 2D panel app audio for apps using Oboe. When AAudioStreamBuilder_setSpatializationBehavior is not called (or set to AAUDIO_UNSPECIFIED), AAudio's native default on API 32+ is AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO (and on API <= 31 / OpenSL ES, the system uses its default automatic behavior).

Therefore, SpatializationBehavior::Auto should be the default everywhere (mirroring the system's default behavior), and SpatializationBehavior::Never should be opt-in (supported on AAudio API 32+).

Empirical Latency & MMAP Verification

We ran an empirical stream-open matrix on an attached Pixel 10 (frankel, Android 17 / API 37) comparing SpatializationBehavior::Auto vs SpatializationBehavior::Never across PerformanceMode (LowLatency and None), SharingMode (Shared and Exclusive), and channel counts (2 Stereo and 6 5.1 Surround):

PerformanceMode SharingMode Channels SpatializationBehavior Actual Perf Actual Sharing MMAP Used Frames / Burst Buffer Capacity
LowLatency Shared 2 (Stereo) Auto LowLatency Shared Yes 96 (2ms) 1536
LowLatency Shared 2 (Stereo) Never LowLatency Shared Yes 96 (2ms) 1536
LowLatency Exclusive 2 (Stereo) Auto LowLatency Exclusive Yes 96 (2ms) 1920
LowLatency Exclusive 2 (Stereo) Never LowLatency Exclusive Yes 96 (2ms) 1920
LowLatency Shared / Exclusive 6 (5.1) Auto None Shared No 962 1924
LowLatency Shared / Exclusive 6 (5.1) Never None Shared No 962 1924
None Shared / Exclusive 2 or 6 Auto None Shared No 962 2886 / 1924
None Shared / Exclusive 2 or 6 Never None Shared No 962 2886 / 1924
  • Findings: On Android phones, setting SpatializationBehavior::Auto has zero impact on low-latency stereo streams (AUDIO_OUTPUT_FLAG_MMAP_NOIRQ / AUDIO_OUTPUT_FLAG_FAST are preserved with identical 96-frame bursts and MMAP paths), while enabling Android XR to spatialize 2D panel app audio automatically.

Changes

  • src/aaudio/AudioStreamAAudio.cpp: Default SpatializationBehavior::Unspecified to SpatializationBehavior::Auto (and set mSpatializationBehavior = SpatializationBehavior::Auto when builder_setSpatializationBehavior == nullptr on API <= 31).
  • src/opensles/AudioStreamOpenSLES.cpp: Set mSpatializationBehavior = SpatializationBehavior::Auto since OpenSL ES does not support opting out via Never and always uses the system's default behavior.
  • include/oboe/AudioStreamBuilder.h: Update documentation comment for setSpatializationBehavior to state that SpatializationBehavior::Auto is the default and SpatializationBehavior::Never is only supported on API 32 and above for AAudio.
  • tests/testStreamOpen.cpp: Update spatialization unit tests (AAudioInputSetSpatializationBehavior, AAudioOutputSetSpatializationBehavior, OpenSLESOutputSetSpatializationBehavior, AAudioInputSetSpatializationBehaviorUnspecified, and AAudioOutputSetSpatializationBehaviorUnspecified) to test that Auto is the default everywhere and Never is opt-in on API 32+ AAudio.

Testing

  • Verified all 5 spatialization tests in testStreamOpen.cpp and the full 242-test GoogleTest suite on Pixel 10 (frankel, Android 17 / API 37).

@robertwu1
robertwu1 force-pushed the spatialization-auto-default branch from 07772b1 to 41ef541 Compare September 15, 2026 20:31
@robertwu1
robertwu1 requested a review from flamme September 15, 2026 20:34
@robertwu1
robertwu1 force-pushed the spatialization-auto-default branch 3 times, most recently from 4a0f6d3 to 78a18d1 Compare September 15, 2026 21:27
Comment thread src/aaudio/AudioStreamAAudio.cpp Outdated
@robertwu1
robertwu1 force-pushed the spatialization-auto-default branch from 78a18d1 to dc717d3 Compare September 15, 2026 22:44
Comment thread src/aaudio/AudioStreamAAudio.cpp Outdated
@robertwu1
robertwu1 force-pushed the spatialization-auto-default branch from dc717d3 to 14a882f Compare September 15, 2026 23:14
@robertwu1 robertwu1 changed the title Default SpatializationBehavior::Unspecified to Auto on API 32+ Default SpatializationBehavior to Auto and make Never opt-in Sep 15, 2026
@robertwu1
robertwu1 merged commit 7a40679 into main Sep 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants