Does SDL3 reliably fire SDL_AudioDeviceEvent for USB headset connect/disconnect across platforms?
0 reputation · 27 Jan 2024, 13:38 UTC
0 reputation · 27 Jan 2024, 13:38 UTC
Determine whether SDL3's SDL_AudioDeviceEvent reliably reports USB headset connect and disconnect across the major OS backends.
SDL3 exposes SDL_EVENT_AUDIO_DEVICE_ADDED and SDL_EVENT_AUDIO_DEVICE_REMOVED, but each backend (PipeWire, PulseAudio, WASAPI, CoreAudio) implements the notification differently. Event ordering, duplicate delivery, and device ID persistence vary, and SDL_GetAudioDeviceList may return transient IDs after a hot‑plug cycle.
No. SDL3 does not guarantee perfectly reliable, single-instance audio device events for USB headset hot-plug across all major platforms. SDL_EVENT_AUDIO_DEVICE_ADDED and SDL_EVENT_AUDIO_DEVICE_REMOVED are dispatched when the native backend detects a change, but the exact timing, duplication, and device identity are backend-dependent.
Confirmed: SDL3 defines these events and exposes SDL_GetAudioDeviceList and SDL_GetAudioDeviceInfo. Each backend—PulseAudio, PipeWire, WASAPI, and CoreAudio—translates native notifications into SDL events differently. Device IDs returned by SDL_GetAudioDeviceList are logical identifiers that may change after a hot-plug cycle.
Likely explanation: The symptoms you describe—missing events, duplicates, transient IDs, and premature readiness—are consistent with the underlying audio server pipelines rather than an SDL3 bug alone. PulseAudio may signal before the sink/source is fully registered. PipeWire can coalesce node and link changes, producing duplicate or delayed removals. WASAPI is generally deterministic for endpoint changes, but format or sample-rate renegotiation can generate additional events. CoreAudio may report aggregate devices or system reconfigurations that are indistinguishable from a physical plug without extra validation.
SDL_EVENT_AUDIO_DEVICE_ADDED, call SDL_Delay(200) before enumerating. This gives the backend time to stabilize.SDL_GetAudioDeviceList, then SDL_GetAudioDeviceInfo. Match on the device name and unique ID string; do not cache indices.SDL_OpenAudioDeviceStream returns an error or the stream produces no data, discard it and retry after another delay.SDL_EVENT_AUDIO_DEVICE_REMOVED arrives, immediately mark the old ID as unusable. Do not assume the same numeric ID will refer to the same hardware after replug.Do you need to distinguish the physical USB headset from OS-level aggregate or virtual devices on macOS, or is any output matching the headset name acceptable? This determines whether step 3 requires additional transport/UID filtering.
This guidance assumes SDL3 3.x with current stable backends; exact event timing may vary by OS version and audio server configuration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.