Elevate audio thread priority on Android#396
Merged
Merged
Conversation
Owner
|
Thank you @djkingCanada! This is a great improvement! I would merge this into the I will test again in the next few days before merging into Thanks again. |
Owner
|
I have published |
alnitak
added a commit
that referenced
this pull request
Apr 3, 2026
#### 4.0.0 (3 Apr 2026) - fix: some OGG audio files don't trigger `SoundEventType.handleIsNoMoreValid` - fix: setBufferStream fails to decode small MP3 files under 32 KB #434. Thanks to @chaudharydeepanshu - fix web: `createVoiceGroup` return was interpred as a signed int instead of unsigned because it has always the sign bit flag - fixed switching output devices on macOS and maybe on others platforms, didn't initialize correctly the new one - added some more tests - removed deprecated `equalizerFilter` in favor of `parametricEqFilter` #### 4.0.0-pre.3 (29 Mar 2026) - fix: FFI symbol stripping causing "symbol not found" errors in iOS/macOS when uploading to App Store #431 - fix decreasing volume when adding a bus to another #### 4.0.0-pre.2 (28 Mar 2026) - macOS/iOS fix: check for cmake in path while building - iOS simulator: fix libs linking #### 4.0.0-pre.1 (26 Mar 2026) - macOS fix: build error #### 4.0.0-pre.0 (24 Mar 2026) - added Mixing Bus feature and example https://docs.page/alnitak/flutter_soloud_docs/advanced/mixing_bus - added `getApproximateVolume` to get the approximate volume of a channel of the player - added `autoDispose` parameter to `load*` methods to automatically dispose the sound when it is finished. This eliminates the need to manually call disposeSource - added `playSource` to play a source from assets, URLs, or file and automatically dispose its `AudioSource` when it is finished - added `filters/parametric_eq.dart` example - added parametric equalizer with 1 to 64 bands and FFT window size from 32 to 4096 for quality and performance - added Swift Package Manager support - improved quality and performance of the pitchshift filter #313 - CocoaPods now uses cmake to compile the plugin always in release mode for macOS and iOS - conditional import of `js` and `wasm` only on web (no more included on other platforms) - win fix: UTF8 file name conversion was causing crash or file not found #427 - fixed a possible crash during app shutdown - possible fix for #333 which caused an ANR on Android when stopping/deinit or closing the app - Linux feat: choose to link ogg, opus, vorbis, and flac libraries from the system with `TRY_SYSTEM_LIBS_FIRST=1` environment variable #421. Useful for Rasperry Pi because the precompiled libs are available only for x86_64. - Android fix: elevate audio thread priority on Android #396. Thanks to @djkingCanada - Android: build optimizations --- ***breaking changes*** - bump Flutter version to 3.41.0 and Dart to 3.11.0 - play, play3d, speechText, are now sync - renamed `NO_OPUS_OGG_LIBS` environment variable to `NO_XIPH_LIBS` - renamed `SoLoudOpusOggVorbisLibsNotAvailableException` to `SoLoudXiphLibsNotAvailableException` - renamed `areOpusOggLibsAvailable` to `areXiphLibsAvailable`
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.
Problem
On many Android devices, the audio thread spawned by MiniAudio is categorized as a background or batch process (SCHED_BATCH). This leads to significant scheduling delays (50ms+), causing audible static and "stuttering" even when CPU usage is low. This is especially prevalent when the app is under load or when targeting older API levels.
Solution
This PR implements a manual priority elevation within the MiniAudio backend. On the first invocation of the audio callback (which runs on the dedicated audio thread):
Escapes SCHED_BATCH: If the thread is found to be in the Batch policy, it is moved to SCHED_NORMAL (Policy 0).
Elevates Priority: Attempts to set the thread to Realtime (SCHED_FIFO) or Round-Robin (SCHED_RR).
Niceness Adjustment: Falls back to setting the highest possible niceness (-20) using setpriority if Realtime access is denied by the OS.
These changes are wrapped in #ifdef ANDROID guards to ensure zero impact on other platforms.
Impact
Stability: Prevents the OS from preempting the audio thread.
Latency: Reduces "jitter" and audio underruns.
Quality: Eliminates persistent "static" noise on problematic Android hardware.
Testing
Verified on Android devices where previous versions experienced consistent static. Jitter monitoring showed the thread meeting its deadlines (e.g., 2048 samples @ 48kHz) consistently after the fix.
Type of Change