Skip to content

fix(audio): match output stream sample format to device, never panic#24

Merged
dkmstr merged 1 commit into
masterfrom
master-audio-output-format-fix
Jun 19, 2026
Merged

fix(audio): match output stream sample format to device, never panic#24
dkmstr merged 1 commit into
masterfrom
master-audio-output-format-fix

Conversation

@aschumann-virtualcable

Copy link
Copy Markdown
Contributor

This pull request improves the robustness and compatibility of audio output stream creation in crates/channels/src/audio/output.rs. The main changes ensure that the audio output stream matches the device's supported sample format, preventing runtime errors and improving support for a wider range of audio hardware.

Key improvements to audio output stream handling:

  • Prefer selection of F32 sample format when available, matching the internal buffer and common device defaults, but gracefully fall back to any supported format if necessary. (AudioHandle::get_stream_config logic)
  • Introduced a new helper function build_output_stream_typed<T> to generically build output streams for any sample format, converting the internal f32 buffer to the required device format on the fly.
  • Updated stream creation logic to dynamically select and build the output stream based on the device's reported SampleFormat, supporting F32, I16, U16, U8, I32, and F64 formats, and logging an error if the format is unsupported.
  • Improved error handling so that if stream creation fails, audio is disabled gracefully and an error is logged, rather than panicking or crashing the application.

Dependency and import updates:

  • Added imports for FromSample, SampleFormat, and SizedSample from the cpal crate to support the new generic stream-building logic.

RDP server->client audio crashed the launcher: get_stream_config picked the
first supported config (e.g. U8 on some USB headsets) while the stream was
always built with an f32 callback. In WASAPI shared mode the stream sample
format must match the device mix format, so the mismatch returned
UnsupportedConfig, and the .unwrap() turned it into a panic that killed the
whole launcher.

- get_stream_config now prefers an F32 config (the usual shared-mode mix
  format and what our f32 buffer feeds), falling back to any supported one.
- New build_output_stream_typed::<T> builds a stream typed to the device's
  actual sample format, converting the f32 buffer via FromSample.
- Build failures now disable audio and log instead of panicking.

@dkmstr dkmstr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fine :).

@dkmstr dkmstr merged commit 839a60b into master Jun 19, 2026
3 checks passed
@aschumann-virtualcable aschumann-virtualcable deleted the master-audio-output-format-fix branch June 19, 2026 13:52
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.

2 participants