Skip to content

linux-alsa: Capture S24_3LE devices at 24 bits - #1104

Merged
zackees merged 4 commits into
obs-rust:masterfrom
vpacher:fix/alsa-24bit-capture
Oct 16, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
vpacher:fix/alsa-24bit-capture

Conversation

@vpacher

@vpacher vpacher commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #1103

What and why

The ALSA capture source opened 24-bit USB audio interfaces at 16 bits. Many of these devices offer only S24_3LE and S16_LE, and hw: and front: PCMs do not convert. _alsa_configure() tried S16_LE first and did not know S24_3LE.

This PR:

  1. Tries the formats with the highest resolution first: S32_LE, FLOAT_LE, S24_3LE, S16_LE, U8.
  2. Widens S24_3LE samples to S32 (the 24 bits go into the high bytes) and gives OBS AUDIO_FORMAT_32BIT. OBS has no packed 24-bit format.
  3. Assigns the return value of snd_pcm_hw_params_set_format() to err. Before, its error check never ran.
  4. Logs the format that was set, next to the rate and channels: alsa-input: PCM 'front:CARD=Module,DEV=0' format set to S24_3LE. The bit depth of an ALSA source is not shown anywhere else.

Effect on other devices: a device that offers S32_LE or FLOAT_LE and S16_LE now opens at the higher resolution, not at 16 bits.

RED → GREEN

  • RED commit: e02eba6 adds test_alsa_capture_format. It runs the real capture code on ALSA's null PCM (no sound card) and wraps snd_pcm_hw_params_test_format (the device offers only S24_3LE and S16_LE), snd_pcm_readi (known samples) and obs_source_output_audio. It fails 1/1: "OBS got audio format 2, expected AUDIO_FORMAT_32BIT (3)".
  • RED commit: 61c738e adds a log check to the same test (log captured with base_set_log_handler). It fails 1/1: no line "alsa-input: PCM 'null' format set to S24_3LE".
  • GREEN: cb71188 (24-bit capture) and 424b7b1 (format log line). test_alsa_capture_format passes 1/1 (5 of 5 runs), against libobs and against libobs-with-rust. It checks full scale, minimum, sign and a mid value. Locally on Debian 13 only; PR CI runs the full suite.
  • Real app: Audinate AVIO USB (Dante), Debian 13, front:CARD=Module,DEV=0. Before: /proc/asound/Module/stream0 capture Altset = 2, hw_params format S16_LE. After: Altset = 1, S24_3LE. A 997 Hz test tone at -15 dBFS through OBS and NDI, received with the NDI SDK: THD+N -85.8 dB before, -96.2 dB after (median; worst second -96.1 dB). Gain 0.0 dB, flat response 20 Hz to 20 kHz, no gaps. A second device that offers only S16_LE (MiraBox capture card) still opens S16_LE. The OBS log on that machine now shows format set to S24_3LE for the AVIO and format set to S16_LE for the MiraBox.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: not a port)

🤖 Generated with Claude Code

vpacher and others added 2 commits October 16, 2026 19:43
A device that offers only S24_3LE and S16_LE (common on USB audio
interfaces, through hw: or front: with no plug layer) must reach OBS
as AUDIO_FORMAT_32BIT with its 24 bits intact. The capture code runs
on ALSA's null PCM; the device's formats and samples are wrapped.

Fails: the capture code does not know S24_3LE and opens S16_LE.

Refs obs-rust#1103

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Try the formats with the highest resolution first: S32_LE, FLOAT_LE,
S24_3LE, S16_LE, U8. OBS has no packed 24-bit format, so S24_3LE
samples are widened to S32 (the 24 bits in the high bytes) and OBS
gets AUDIO_FORMAT_32BIT.

Also assign the return value of snd_pcm_hw_params_set_format() to
err; its error check never ran.

Fixes obs-rust#1103

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner October 16, 2026 17:55
vpacher and others added 2 commits October 16, 2026 20:18
The format is the only place where a user can see the bit depth of
an ALSA source. test_alsa_capture_format now also captures the log
(base_set_log_handler) and expects "PCM 'null' format set to
S24_3LE".

Fails: the capture code logs the rate and channels, not the format.

Refs obs-rust#1103

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Log the format that was set, next to the rate and channels, for
example "PCM 'front:CARD=Module,DEV=0' format set to S24_3LE". The
bit depth of an ALSA source is not shown anywhere else.

Refs obs-rust#1103

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
Merged via the queue into obs-rust:master with commit 16d025d Oct 16, 2026
25 checks passed
@vpacher
vpacher deleted the fix/alsa-24bit-capture branch October 17, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

linux-alsa: 24-bit USB devices are captured at 16 bits

2 participants