Fix ALSA hardware volume detection for CARD=<name> and bare sysdefault devices - #279
Open
OnFreund wants to merge 1 commit into
Open
Fix ALSA hardware volume detection for CARD=<name> and bare sysdefault devices#279OnFreund wants to merge 1 commit into
OnFreund wants to merge 1 commit into
Conversation
parse_alsa_card() only matched PortAudio's hw:N,M numeric card form, so devices selected via --audio-device using the plughw:/dmix: CARD=<name> convention (needed to reach ALSA's plug/dmix conversion layer, since raw hw:N,M often fails to open for playback) silently fell back to software volume even when a real hardware mixer existed. Also handle PortAudio's bare "sysdefault"/"default" enumeration, which carries no card info at all: cross-reference aplay -L's fully-qualified hints (e.g. sysdefault:CARD=vc4hdmi) to recover the card, backing off to software volume only when the match is ambiguous (multiple cards each exposing their own default hint) rather than guessing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
parse_alsa_card()insendspin/alsa_volume.pyonly recognized PortAudio's numerichw:N,Mcard annotation. Devices selected via--audio-deviceusing theplughw:CARD=<name>,DEV=<n>/dmix:CARD=<name>,DEV=<n>convention — often needed because rawhw:N,Mbypasses ALSA'splug/dmixconversion layer and fails to open for playback at all — weren't recognized, so hardware volume control silently fell back to software volume even when a real mixer element existed.parse_alsa_card()now also extracts the card's string name from aCARD=<name>pattern, andfind_mixer_element()/AlsaVolumeController/async_check_alsa_available()were generalized to acceptint | strcard identifiers. Confirmed via theamixersource that-cresolves either a numeric index or a card name throughsnd_card_get_index()internally, so passing the name straight through works.sysdefault/defaultdevice enumeration (no card info at all in the name), which turned up in real-world testing on an ODROID-N2. Since the string carries no card identity, this cross-referencesaplay -L's fully-qualified hints (e.g.sysdefault:CARD=ODROIDN2) to recover the card, and only resolves when exactly one hint matches — on a system with multiple cards each exposing their own default hint, it backs off to software volume rather than guessing which one is meant.Test plan
uv run ruff check --fix .uv run ruff format .uv run mypy sendspin— no issuesuv run pytest tests/ -q— 150 passed (11 new tests coveringCARD=<name>parsing, the plughw/dmix discovery flow, and the bare-sysdefault resolution including the ambiguous multi-card and no-hint cases)🤖 Generated with Claude Code