Skip to content

Repository files navigation

ALSA Capabilities

A command-line tool for querying Linux audio hardware capabilities and managing HDA codec jack retasking.

Features

  • Hardware Discovery: Enumerate all ALSA sound cards and their PCM devices
  • Capability Detection: Query sample rates, bit depths, and channel counts supported by each device
  • HDA Codec Information: Display pin configurations including jack colors, locations, and connector types
  • Retasking Detection: Identify pins that have been retasked from their original BIOS configuration
  • Boot Override Generation: Create firmware patch files for persistent jack retasking

Quick Start

Using Docker (Recommended)

# Basic usage - show all cards and capabilities
docker run -it --rm \
  --device /dev/snd \
  -v /proc/asound:/host/asound:ro \
  -v /sys/class/sound:/host/sys/class/sound:ro \
  ghcr.io/scyto/alsa-capabilities

Example Output

Card 0: HDA Intel PCH
    ID: PCH
    Driver: snd_hda_intel
    Path: /devices/pci0000:00/0000:00:1f.3

    HDA Codec: Realtek ALC892

    Pin Configuration:
    +--------+----------------+----------+-----------+-------------+
    | Node   | Function       | Location | Color     | Connector   |
    +--------+----------------+----------+-----------+-------------+
    | 0x14   | Line Out       | Rear     | Green     | 1/8"        |
    | 0x15   | HP Out         | Front    | Green     | 1/8"        |
    | 0x18   | Mic In         | Rear     | Pink      | 1/8"        |
    | 0x1a   | Line In        | Rear     | Blue      | 1/8"        |
    | 0x1b   | Line Out       | Rear     | Orange    | 1/8"        |
    +--------+----------------+----------+-----------+-------------+

    Playback Devices:
      hw:0,0 - ALC892 Analog
        Rates: 44100, 48000, 96000, 192000
        Formats: S16_LE, S32_LE
        Channels: 2, 4, 6, 8

Jack Retasking

HDA codecs allow changing the function of audio jacks. For example, you can convert a "Line In" jack to a "Line Out" for additional speaker outputs.

Preview a Change (Dry Run)

docker run -it --rm \
  --device /dev/snd \
  -v /proc/asound:/host/asound:ro \
  -v /sys/class/sound:/host/sys/class/sound:ro \
  ghcr.io/scyto/alsa-capabilities \
  --generate-boot-override=0:0 --pin=blue:line-out --dry-run

Generate Boot Override Files

docker run -it --rm \
  --device /dev/snd \
  -v /proc/asound:/host/asound:ro \
  -v /sys/class/sound:/host/sys/class/sound:ro \
  -v $(pwd):/output \
  ghcr.io/scyto/alsa-capabilities \
  --generate-boot-override=0:0 --pin=blue:line-out --output=/output

Pin Selectors

You can reference pins by:

  • Color: --pin=blue:line-out (physical jack color)
  • Current role: --pin=line-in:line-out (current function)
  • Node ID: --pin=0x1a:line-out (hex address)

Available Roles

Role Description
line-out Stereo line-level output
hp-out Headphone output (with amplification)
line-in Stereo line-level input
mic Microphone input (with preamp)
speaker Internal speaker output
spdif-out Digital optical/coaxial output
disabled Disable the jack

See docs/pin-retasking.md for a complete step-by-step guide.

CLI Reference

Usage: AlsaCapabilities.Console [options]

Options:
  -v, --verbose              Show detailed output including raw formats
  --retask-info              Show HDA jack retasking information
  --generate-boot-override=CARD:CODEC
                             Generate boot override files for persistent retasking
  --pin=SELECTOR:ROLE        Set pin configuration (use with --generate-boot-override)
  --dry-run                  Show what would be generated without writing files
  --output=DIR               Output directory for boot override files (default: /tmp)
  -h, --help                 Show this help message

Building from Source

Prerequisites

  • .NET 8.0 SDK
  • Linux with ALSA (for runtime)

Build

dotnet build AlsaCapabilities.sln

Run Locally

dotnet run --project AlsaCapabilities.Console

Build Docker Image

docker build -t alsa-capabilities .

Architecture

alsa-capabilities/
├── AlsaNative/                 # Core library
│   ├── AlsaInterop.cs         # P/Invoke bindings to libasound
│   ├── HdaCodecReader.cs      # /proc/asound codec parsing
│   ├── HdaRetasker.cs         # Boot override generation
│   ├── SysfsReader.cs         # /sys/class/sound parsing
│   ├── PinConfigBuilder.cs    # HDA pin config construction
│   └── Models/                # Data models
├── AlsaCapabilities.Console/   # CLI application
│   └── Program.cs
├── docs/
│   └── pin-retasking.md       # Retasking guide
└── Dockerfile

How It Works

ALSA Capabilities

The tool uses direct P/Invoke calls to libasound.so.2 to query hardware parameters, avoiding dependencies on command-line tools like aplay or arecord.

HDA Codec Information

Pin configurations are read from /proc/asound/cardN/codec#M which contains the 32-bit pin default values encoding:

  • Device type (Line Out, HP Out, Mic In, etc.)
  • Location (Rear, Front, Internal)
  • Color (Green, Pink, Blue, Orange, etc.)
  • Connector type (1/8", RCA, Optical)

Retasking Detection

The tool compares current pin configs (from /proc/asound) with original BIOS configs (from /sys/class/sound/hwCxDy/init_pin_configs) to identify retasked pins.

Boot Override

Persistent retasking uses the kernel's snd-hda-intel patch= mechanism:

  1. hda-jack-retask.conf - modprobe configuration
  2. hda-jack-retask.fw - firmware patch with new pin configs

Container Mounts

Mount Purpose
--device /dev/snd Access to ALSA devices
-v /proc/asound:/host/asound:ro HDA codec information
-v /sys/class/sound:/host/sys/class/sound:ro Sysfs device info, original pin configs
-v $(pwd):/output Output directory for generated files

License

MIT License - See LICENSE file for details.

About

CLI tool for querying Linux audio hardware capabilities and HDA codec jack retasking

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages