feat: respect AudioContextOptions.latencyHint when opening the Android output stream - #1232
Open
DanielOrmeno wants to merge 1 commit into
Open
Conversation
…d output stream AudioContext now accepts the Web Audio latencyHint category and the Android backend maps it to Oboe performance modes: interactive -> LowLatency (unchanged default), balanced -> None, playback -> PowerSaving. On web the hint is forwarded to the browser AudioContext; on iOS it is accepted but does not change the stream yet. Numeric hints are not supported yet. Motivation: the hard-coded LowLatency stream is granted a very small buffer (192 frames / 4 ms on an entry-level Samsung) and misses ~220 render deadlines per second when a multi-source graph renders, heard as continuous crackle. The same graph on a PerformanceMode::None stream plays clean. Measured via AudioStream::getXRunCount on device.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
AudioContextOptions.latencyHint(category form) and maps it to Oboe performance modes on Android, so playback-heavy apps can opt out of the underrun-prone low-latency stream on low-end devices.Closes #1231 — full measurements there: on an entry-level Samsung, the hard-coded
LowLatencystream is granted 192 frames (4 ms) of buffer and misses ~210–230 render deadlines per second while an 11-source graph plays (continuous audible crackle); the same graph on aPerformanceMode::Nonestream plays clean.What changed
latencyHintPerformanceMode)'interactive'(default)LowLatency— current behaviour, unchanged'balanced'None'playback'PowerSavingAudioContextLatencyHintenum (common/cpp/audioapi/core/types/), carried byAudioContextand consumed by the AndroidAudioPlayerwhen opening the stream.createAudioContextgains an optional second string argument; unknown/omitted values fall back toINTERACTIVE, matching how browsers treat an unrecognizedlatencyHint.AudioContextOptions.latencyHint?: AudioContextLatencyCategory; web passthrough hands it to the browser'sAudioContext.audio-context.mdxconstructor table.Non-breaking: the new constructor parameters are defaulted (existing callers, including the WPT harness, compile unchanged) and the default mode is exactly today's behaviour.
Out of scope (follow-ups noted in #1231): numeric hints (would map to
setBufferSizeInFrameson Android), iOS stream wiring (preferredIOBufferDuration).Test plan
yarn workspace react-native-audio-api run typecheck/lint:js/format:check— cleanyarn workspace react-native-audio-api run test:js— 79/79interactivereproduces the underruns,balancedplays the same 11-source session clean (verified withAudioStream::getXRunCount()logging)🤖 Generated with Claude Code