Repository navigation
fix(audio): close the idle system-sound engine - #243
Merged
dianjixz merged 1 commit intoNov 13, 2026
Merged
Conversation
- The system-sound engine stayed open after its first sound, keeping a PulseAudio/PipeWire playback stream running: the ES8389 codec, the sound server and the launcher kept processing silence while idle. - The lock screen made it permanent: entering it suspends the engine and then plays lock.mp3, which reopens it for as long as the device sleeps. - The worker now closes the engine after 10 s with no queued command and no sound playing; the next sound reopens it (with the existing 300 ms warm-up). - Measured on a CardputerZero (0.6.105 + this change, screen locked, on battery): 268 mA -> 215/217 mA, context switches 4600/s -> ~800/s, and the ES8389 playback PCM goes from RUNNING to closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0135vUaG2FpgpGRJfB9LEPvZ
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
The system-sound engine (
Cp0SystemSoundPlayer) never closes once it has played a sound, so a PulseAudio/PipeWire playback stream stays open for the whole session. While the device idles, the ES8389 codec, PipeWire and the launcher keep processing silence. This PR closes the engine after 10 s with nothing queued and nothing playing.Why it stays open today
enter_lockscreen()callssuspend_system_sound()(→close_engine()). But it then callsplay_lockscreen_sound("lock.mp3")right away, which reopens the engine. So the stream runs for as long as the device sleeps.Change
worker_loop()waits with a 10 s timeout while the engine is open. When it times out with no queued command and no sound playing (ma_sound_is_playingon every initialised sound), it callsclose_engine(). The next sound reopens the engine through the existing path, with the existing 300 ms warm-up. ExplicitSuspend/Prepare/Reloadhandling is unchanged.Measurements
These were taken on a CardputerZero running launcher 0.6.105 with this patch applied (the file differs between 0.6.105 and
masteronly by the removal of an unusedkDefaultSoundCountconstant). Conditions: screen locked, backlight off, no app running, on battery. I sampledcurrent_nowfrom bq27220 every 2 s for 60 s.That is about 50 mA, roughly 19 % of the idle draw. The CPU also stopped sitting at 1 GHz while idle.
Testing
sh ext_components/cp0_lvgl/tests/run_tests.shpasses.test_audio_system_sound_playercannot exercise the idle close, because the engine never opens without an audio device and assets. I verified it on the device by checking/proc/asound/card1/pcm0p/sub0/statusandwpctl statusbefore and after.Note
I prepared this with AI assistance (Claude) and tested it on my own device. I'm happy to adjust the timeout or the approach.