hex/src/audio/hex_microphone
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dax ec97f13945
fix(audio): stop using cpal default devices on Windows (#2622)
* fix(audio): use Windows default endpoints as specific cpal devices

cpal 0.18 registers a default-device monitor for every stream built on a
default input or output handle. Its notification callbacks initialize COM
as STA on the Windows thread-pool threads they run on; those threads stay
STA, and ActivateAudioInterfaceAsync (which only default handles use) then
fails with RPC_E_CHANGED_MODE for the rest of the process. A specific
endpoint activates through IMMDevice::Activate and registers no monitor.

Resolve the default capture and render endpoint ids on one MTA thread and
pick the matching listed cpal device for System default in input opens,
feedback tones, history playback, and Hex Microphone auditions, falling
back to cpal's handles only if resolution fails.

Specific devices no longer report default changes through cpal, so register
an IMMNotificationClient on the same thread: its callbacks do no COM calls
and bump the input or output route generation, which now exists on Windows
too, so dictation switches and feedback reopens follow the OS default.

The direct WASAPI fallback's failure now reaches the surfaced microphone
error instead of only the log, and the feature maps describe the behavior.

* fix(audio): hold the Windows endpoint notification client for the thread

RegisterEndpointNotificationCallback is not documented to keep its client
alive. Return the client from watch_default and keep it beside the
enumerator for as long as the endpoint thread answers requests.

* fix(audio): never open Windows default handles

The resolved default input no longer falls back to cpal's default-input
handle, and destructuring its Option fixes the Windows build. Tones and
other default-output playback try the resolved listed device, then every
listed output, instead of from_default_device/open_default_sink.

The default-name invalidation report is only configured for a stream that
really runs on cpal's default-input handle, which Windows no longer
opens, so a resolved device's own invalidation is reported as a failure.

* docs(audio): correct Windows default-resolution recovery notes

The unresolved Windows default input falls back to a listed stand-in
microphone and re-resolves on the next route change; only an unusable
device list errors. The feedback fatal-error note no longer describes
Windows default-handle invalidation, which Hex no longer opens.
2026-11-23 22:08:04 -05:00
..
audition.rs fix(audio): stop using cpal default devices on Windows (#2622) 2026-11-23 22:08:04 -05:00
macos_hal.rs Extract macos_hal and pipewire_source from audio/hex_microphone.rs 2026-10-31 18:57:51 -07:00
pipewire_source.rs fix(linux): pass pw-cat --raw only where pipewire knows it (#1803) 2026-11-13 16:30:28 -05:00