Skip to content

fix(FxController): prevent sleep during playback and re-init audio on system resume#533

Open
akai07 wants to merge 2 commits into
fxsound2:mainfrom
akai07:fix/sleep-prevention-power-events
Open

fix(FxController): prevent sleep during playback and re-init audio on system resume#533
akai07 wants to merge 2 commits into
fxsound2:mainfrom
akai07:fix/sleep-prevention-power-events

Conversation

@akai07

@akai07 akai07 commented May 27, 2026

Copy link
Copy Markdown

Summary

Prevents the system from sleeping while FxSound is actively processing audio. Also handles system resume from sleep and RDP session changes to ensure audio processing continues correctly.

Changes

SetThreadExecutionState — Sleep prevention

  • When audio processing is detected (timerCallback detects 5 consecutive active frames), calls SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED) to prevent system sleep and display off.
  • When audio processing stops, reverts to SetThreadExecutionState(ES_CONTINUOUS) to allow normal power management.
  • Execution state is also cleared in the destructor.

PBT_APMRESUMEAUTOMATIC — System resume handler

Added WM_POWERBROADCAST case in the message window callback. When PBT_APMRESUMEAUTOMATIC fires after resume from sleep:

  • Calls audio_passthru_->checkDeviceChanges() to refresh device state (devices may have changed during sleep)
  • Calls setPowerState() to re-activate audio processing with the stored power state

Files Changed

  • fxsound/Source/GUI/FxController.cpp — Sleep prevention, power event handling, execution state cleanup

Related Issues

  • Fixes system sleeping while audio is processing
  • Fixes audio processing not resuming after system wakes from sleep

akai07 added 2 commits May 28, 2026 02:50
… in OnDeviceStateChanged

- Filter capture (eRender) device events in OnDeviceStateChanged via IMMEndpoint.GetDataFlow
  to prevent unnecessary playback reinit when input devices change state
- Track reconnected device GUID when state transitions to ACTIVE
- Add reconnection detection in sndDevicesImplementDeviceRules to auto-select
  reconnected playback devices (fixes BT headset reconnect after UNPLUGGED)
- Clear reconnection state on reinit
… system resume

- Call SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)
  when audio processing starts to prevent system sleep during playback
- Revert to SetThreadExecutionState(ES_CONTINUOUS) when processing stops
- Handle PBT_APMRESUMEAUTOMATIC power event: check device changes and
  restore power state after system resume from sleep
- Clear execution state on controller destruction
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.

1 participant