Skip to content

fix(sndDevices): suppress unnecessary re-init when default device changes to same device#535

Open
akai07 wants to merge 4 commits into
fxsound2:mainfrom
akai07:fix/format-change-suppress-reinit
Open

fix(sndDevices): suppress unnecessary re-init when default device changes to same device#535
akai07 wants to merge 4 commits into
fxsound2:mainfrom
akai07:fix/format-change-suppress-reinit

Conversation

@akai07

@akai07 akai07 commented May 27, 2026

Copy link
Copy Markdown

Summary

Prevents unnecessary audio processing thread restarts when a video application (Plex, etc.) switches between audio tracks with different formats but uses the same device.

Problem

When playing video content (Plex, MPC-HC, etc.), Windows fires OnDefaultDeviceChanged whenever the audio stream format changes between tracks — even if the audio endpoint device itself hasn't changed. FxSound's callback handler was treating this as a full device change, setting stopAudioCaptureAndPlaybackLoop = 1 and causing the processing thread to restart. This results in audible audio pauses or glitches during normal video playback.

Fix

Added a check in OnDefaultDeviceChanged: before setting the re-init flag, compare the new default device ID against the ID of our current targeted playback device (cast_handle->pwszID[cast_handle->playbackDeviceNum]). If they match, it's a format-only change — skip the re-init and let the processing thread continue uninterrupted.

Files Changed

  • audiopassthru/src/sndDevices/sndDevicesDeviceCallbacks.cpp — Added device ID comparison guard in OnDefaultDeviceChanged

Notes

  • The existing DFX-device check (pwszID[dfxDeviceNum]) is preserved above the new check
  • Bounds checking ensures playbackDeviceNum is valid before accessing the array
  • This is a read-only comparison — no side effects on device state

akai07 added 4 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
…sizing and alpha

Replaced LoadIcon with LoadImage using explicit SM_CXSMICON/SM_CYSMICON
dimensions so tray icons are rendered at the correct size for the
notification area. LoadIcon uses default icon size which can cause
scaling artifacts and improper alpha blending on Windows 10/11,
especially in dark theme mode where transparency is critical.
…nges to same device

When video applications (Plex, etc.) switch between audio tracks with
different formats, Windows fires OnDefaultDeviceChanged even if the
device itself hasn't changed — only the format/role has. This was
causing the audio processing thread to restart unnecessarily, resulting
in audible pauses during video playback.

Fix: compare the new default device ID against our current playback
device. If they match, skip the re-init since it's a format change
on the same device, not an actual device switch.
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