📚 Encyclopedia

Audio & Music · updated 2026-10-13

Game audio in Flutter with flutter_soloud

flutterflutter-soloudgame-audioogglatencyweb-audiostutter

flutter_soloud (SoLoud C++ engine over FFI, miniaudio backend, WASM on web) is the audio engine Run uses instead of flame_audio. This covers its tuning, the formats to use, web quirks, and the hardest-won lesson: keep the music architecture simple.

Architecture lesson: one track at a time

Run's music system was rewritten twice. A priority-based event queue with suppression, slot retirement and Future.delayed cleanup caused stutter, leaks and four rounds of fixes, because every screen calling request/end created a distributed state machine that broke on each navigation change. The replacement has no such bugs: - playTrack(path, volume) replaces whatever is playing; stopTrack(); pauseTrack() / resumeTrack() only for game pause. - Each screen plays its own track on entry. Stop gameplay music explicitly before Navigator.pop; do not rely on the game's onRemove() (it may not fire). - Treat any proposal with priorities, queues, suppression or slot systems for music as over-engineering. - Volume: separate music and SFX multipliers from settings. Run's layered-stem "vertical remixing" system (stems started together at volume 0 and faded by a danger level) was eventually deleted as unused, along with ~12 MB of unreferenced music.

Latency and voices

Formats

Web

Mobile lifecycle

Use audio_session for Android audio focus; pause on background, resume on foreground. On iOS AudioSession.setActive(false) can fail with AVAudioSessionErrorCodeIsBusy while SoLoud holds sources (dispose sources first). Dispose the engine on AppLifecycleState.detached.

"Audio stutter" is usually frame time

SoLoud mixes on its own native thread and FFI play/stop calls are cheap. Stutter in Run came from main-thread frame spikes longer than the audio buffer (per-frame collision scans, liquid simulation rasterizing millions of rects). Profile frames before touching the audio code (Flutter / Flame canvas rendering performance facts).

Assets

Run's tracks are CC0 (Juhani Junkala, OpenGameArt, MintoDog, Cleyton Kauffman). Justin keeps audio source files for import in ~/assets/audio/gameplay/; convert to OGG before adding. Flutter's pubspec assets: does not recurse: list every subdirectory.

See also

Linked from

Sources: run memory (research-audio.md, research-collision-audio.md, feedback-audio-architecture.md, sprites-audio.md, speedrun-platformer.md, feedback-audio-assets.md, session-v085.md)