Repository navigation
linux-alsa: Capture S24_3LE devices at 24 bits - #1104
Merged
Merged
Conversation
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]>
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]>
3 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_3LEandS16_LE, andhw:andfront:PCMs do not convert._alsa_configure()triedS16_LEfirst and did not knowS24_3LE.This PR:
S32_LE,FLOAT_LE,S24_3LE,S16_LE,U8.S24_3LEsamples toS32(the 24 bits go into the high bytes) and gives OBSAUDIO_FORMAT_32BIT. OBS has no packed 24-bit format.snd_pcm_hw_params_set_format()toerr. Before, its error check never ran.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_LEorFLOAT_LEandS16_LEnow opens at the higher resolution, not at 16 bits.RED → GREEN
test_alsa_capture_format. It runs the real capture code on ALSA'snullPCM (no sound card) and wrapssnd_pcm_hw_params_test_format(the device offers onlyS24_3LEandS16_LE),snd_pcm_readi(known samples) andobs_source_output_audio. It fails 1/1: "OBS got audio format 2, expected AUDIO_FORMAT_32BIT (3)".base_set_log_handler). It fails 1/1: no line "alsa-input: PCM 'null' format set to S24_3LE".test_alsa_capture_formatpasses 1/1 (5 of 5 runs), againstlibobsand againstlibobs-with-rust. It checks full scale, minimum, sign and a mid value. Locally on Debian 13 only; PR CI runs the full suite.front:CARD=Module,DEV=0. Before:/proc/asound/Module/stream0captureAltset = 2,hw_paramsformatS16_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 onlyS16_LE(MiraBox capture card) still opensS16_LE. The OBS log on that machine now showsformat set to S24_3LEfor the AVIO andformat set to S16_LEfor the MiraBox.Checklist
master(or the description starts with a Stacked: note)-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)🤖 Generated with Claude Code