wiki:linux/audio

Linux Audio

The Advanced Linux Sound Architecture (ALSA) system is the current audio driver subsystem in Linux.

See also:

ALSA Devices

Audio input and output devices which are registered with the kernel can be shown from the files in /proc/asound directory. Note that the names and order of devices (which represents the card number can change depending on kernel and kernel configuration)

Devices can be specified in different ways depending on the application. This can be either in a hw:x,y notation which specifies the card number (x) and the subdevice number (y) or a device name. Card numbers and device numbers can be obtained from /proc/asound/devices however device 'alias names' depend on the ALSA asound configuration file and can be listed using aplay -L or arecord -L (see alsa-utils below).

Examples:

  • GW54xx
    ~# cat /proc/asound/cards 
     0 [DWHDMI         ]: dw-hdmi-ahb-aud - DW-HDMI
                          DW-HDMI rev 0x0a, irq 22
     1 [sgtl5000audio  ]: sgtl5000-audio - sgtl5000-audio
                          sgtl5000-audio
     2 [tda1997xaudio  ]: tda1997x-audio - tda1997x-audio
                          tda1997x-audio
    ~# cat /proc/asound/devices 
      0: [ 0]   : control
     16: [ 0- 0]: digital audio playback
     32: [ 1]   : control
     33:        : timer
     48: [ 1- 0]: digital audio playback
     56: [ 1- 0]: digital audio capture
     64: [ 2]   : control
     88: [ 2- 0]: digital audio capture
    
    • The first file shows there are 3 audio 'cards' in the system:
      • 0: DWHDMI (HDMI Audio out)
      • 1: sgtl5000audio (Analog Audio in/out)
      • 2: tda1997xaudio (HDMI Audio in)
    • The second file shows the 'devices' in the system:
      • hw0,0: audio output (from card 0, DWHDMI, HDMI audio out)
      • hw1,0: audio output (from card 1, sgtl5000, Analog audio out)
      • hw1,0: audio input (from card 1, sgtl5000, Analog audio in)
      • hw2,0: audio output (from card 2, tda1997x, HDMI audio in)
    • don't be confused by the 'digital audio playback' and 'digital audio capture' above - all devices will be digital from the kernel's perspective because even the analog audio codec as a digital interface to the SoC

ALSA Userapce Utilities (aplay, arecord, amixer)

The alsa-utils package contains simple command-line utilities that use the ALSA kerne API's to show, configure, and use the ALSA audio devices:

  • aplay - list and output to ALSA audio output devices
  • arecord - list and capture from ALSA audio input devices
  • amixer - get and set configuration of ALSA audio devices

Showing Device Alias Names (aplay / arecord)

You can use the aplay and arecord applications from the alsa-utils package to see a list of playback and record devices, their card numbers and subdevice numbers (with the -l argument) and their alias names (with the -L argument).

Note that device alias names are configured via ALSA asound configuration files which is not covered here.

Examples:

  • GW54xx audio output devices:
    ~# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: DWHDMI [DW-HDMI], device 0: DW HDMI [dw-hdmi-ahb-audio]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 1: sgtl5000audio [sgtl5000-audio], device 0: HiFi sgtl5000-0 [HiFi sgtl5000-0]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    ~# aplay -L
    null
        Discard all samples (playback) or generate zero samples (capture)
    default:CARD=DWHDMI
        DW-HDMI, dw-hdmi-ahb-audio
        Default Audio Device
    sysdefault:CARD=DWHDMI
        DW-HDMI, dw-hdmi-ahb-audio
        Default Audio Device
    default:CARD=sgtl5000audio
        sgtl5000-audio, HiFi sgtl5000-0
        Default Audio Device
    default:CARD=sgtl5000audio
        sgtl5000-audio, HiFi sgtl5000-0
        Default Audio Device
    
    • the above shows 2 playback capable devices:
      • card 0, subdevice 0 (HDMI audio output from the IMX6 HDMI output) which can be represented as 'hw:0,0' or 'default:CARD=DWHDMI' or 'sysdefault:CARD=DWHDMI' in this case
      • card 1, subdevice 0 (Analog audio output from the sgtl5000 audio codec device) which can be represented as 'hw:1,0' or 'default:CARD=sgtl5000audio' or 'default:CARD=sgtl5000audio' in this case
  • GW54xx audio input devices:
    ~# arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 1: sgtl5000audio [sgtl5000-audio], device 0: HiFi sgtl5000-0 [HiFi sgtl5000-0]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 2: tda1997xaudio [tda1997x-audio], device 0: 202c000.ssi-tda1997x tda1997x-0 [202c000.ssi-tda1997x tda1997x-0]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    ~# arecord -L
    null
        Discard all samples (playback) or generate zero samples (capture)
    default:CARD=sgtl5000audio
        sgtl5000-audio, HiFi sgtl5000-0
        Default Audio Device
    sysdefault:CARD=sgtl5000audio
        sgtl5000-audio, HiFi sgtl5000-0
        Default Audio Device
    default:CARD=tda1997xaudio
        tda1997x-audio, 202c000.ssi-tda1997x tda1997x-0
        Default Audio Device
    sysdefault:CARD=tda1997xaudio
        tda1997x-audio, 202c000.ssi-tda1997x tda1997x-0
        Default Audio Device
    
    • the above shows 2 capture capable devices:
      • card 1, subdevice 0 (Analog audio input from the sgtl5000 audio codec device) which can be represented as 'hw:1,0' or 'default:CARD=sgtl5000audio' or 'sysdefault:CARD=sgtl5000audio' in this case
      • card 2, subdevice 0 (HDMI audio input from the tda1997x HDMI receiver device) which can be represented as 'hw2,0' or 'default:CARD=tda1997xaudio' or 'sysdefault:CARD=tda1997xaudio' in this case

Configuring ALSA audio devices (amixer)

The ALSA mixer controls the muxing of inputs to outputs, capture gains, and volume levels. The settings vary per card and there are many controls per card. Every conceptual block within an audio codec device is typically represented with an ALSA control. The amixer command-line application will let you set and get these controls for a specific card.

Note that the alsa-utils applications specify 'card' numbers and not alias names or subdevices. The alsa-utils utilities that let you select a device by name are not using alias names but instead are using 'hw:x' where 'x' defines the card number.

Examples:

  • list controls for the various cards in a GW54xx (look at /proc/asound/cards to see a list of cards)
    ~# cat /proc/asound/cards # show cards in system
     0 [DWHDMI         ]: dw-hdmi-ahb-aud - DW-HDMI
                          DW-HDMI rev 0x0a, irq 22
     1 [sgtl5000audio  ]: sgtl5000-audio - sgtl5000-audio
                          sgtl5000-audio
     2 [tda1997xaudio  ]: tda1997x-audio - tda1997x-audio
                          tda1997x-audio
    ~# amixer -c 0 # show controls for card 0 the HDMI output - there are none
    ~# amixer -c 1 # list controls card 1 the analog audio codec
    Simple mixer control 'Headphone',0
      Capabilities: pvolume pswitch pswitch-joined
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 127
      Mono:
      Front Left: Playback 103 [81%] [0.00dB] [off]
      Front Right: Playback 103 [81%] [0.00dB] [off]
    Simple mixer control 'Headphone Mux',0
      Capabilities: enum
      Items: 'DAC' 'LINE_IN'
      Item0: 'DAC'
    Simple mixer control 'Headphone Playback ZC',0
      Capabilities: pswitch pswitch-joined
      Playback channels: Mono
      Mono: Playback [on]
    Simple mixer control 'PCM',0
      Capabilities: pvolume
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 192
      Mono:
      Front Left: Playback 192 [100%]
      Front Right: Playback 192 [100%]
    Simple mixer control 'Lineout',0
      Capabilities: pvolume pswitch pswitch-joined
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 31
      Mono:
      Front Left: Playback 31 [100%] [0.00dB] [off]
      Front Right: Playback 31 [100%] [0.00dB] [off]
    Simple mixer control 'Mic',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 3
      Mono: 0 [0%] [0.00dB]
    Simple mixer control 'Capture',0
      Capabilities: cvolume cswitch cswitch-joined
      Capture channels: Front Left - Front Right
      Limits: Capture 0 - 15
      Front Left: Capture 0 [0%] [off]
      Front Right: Capture 0 [0%] [off]
    Simple mixer control 'Capture Attenuate Switch (-6dB)',0
      Capabilities: pswitch pswitch-joined
      Playback channels: Mono
      Mono: Playback [off]
    Simple mixer control 'Capture Mux',0
      Capabilities: enum
      Items: 'MIC_IN' 'LINE_IN'
      Item0: 'MIC_IN'
    Simple mixer control 'Capture ZC',0
      Capabilities: pswitch pswitch-joined
      Playback channels: Mono
      Mono: Playback [on]
    Simple mixer control 'AVC',0
      Capabilities: pswitch pswitch-joined
      Playback channels: Mono
      Mono: Playback [off]
    Simple mixer control 'AVC Hard Limiter',0
      Capabilities: pswitch pswitch-joined
      Playback channels: Mono
      Mono: Playback [off]
    Simple mixer control 'AVC Integrator Response',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 3
      Mono: 1 [33%]
    Simple mixer control 'AVC Max Gain',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 2
      Mono: 0 [0%] [0.00dB]
    Simple mixer control 'AVC Threshold',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 96
      Mono: 12 [12%] [12.00dB]
    Simple mixer control 'BASS 0',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 95
      Mono: 47 [49%]
    Simple mixer control 'BASS 1',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 95
      Mono: 47 [49%]
    Simple mixer control 'BASS 2',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 95
      Mono: 47 [49%]
    Simple mixer control 'BASS 3',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 95
      Mono: 47 [49%]
    Simple mixer control 'BASS 4',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 95
      Mono: 47 [49%]
    Simple mixer control 'DAP MIX Mux',0
      Capabilities: enum
      Items: 'ADC' 'I2S'
      Item0: 'ADC'
    Simple mixer control 'DAP Main channel',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 65535
      Mono: 32768 [50%]
    Simple mixer control 'DAP Mix channel',0
      Capabilities: volume volume-joined
      Playback channels: Mono
      Capture channels: Mono
      Limits: 0 - 65535
      Mono: 0 [0%]
    Simple mixer control 'DAP Mux',0
      Capabilities: enum
      Items: 'ADC' 'I2S'
      Item0: 'ADC'
    Simple mixer control 'Digital Input Mux',0
      Capabilities: enum
      Items: 'ADC' 'I2S' 'Rsvrd' 'DAP'
      Item0: 'I2S'
    ~# amixer -c 2 # show controls for card 2 the HDMI audio input - there are none
    
    • Note there are a lot of controls for the analog audio codec but no controls for the HDMI audio output or receiver. This is because the analog audio codec is extremely flexible (complicated!) internally but the HDMI output and input devices are very limited as the formats are dictated by the HDMI sink and source devices connected to them.

Note that the output above is rather complicated and it may be more useful to list the ALSA controls names instead:

~# amixer -c 1 scontrols
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone Mux',0
Simple mixer control 'Headphone Playback ZC',0
Simple mixer control 'PCM',0
Simple mixer control 'Lineout',0
Simple mixer control 'Mic',0
Simple mixer control 'Capture',0
Simple mixer control 'Capture Attenuate Switch (-6dB)',0
Simple mixer control 'Capture Mux',0
Simple mixer control 'Capture ZC',0
Simple mixer control 'AVC',0
Simple mixer control 'AVC Hard Limiter',0
Simple mixer control 'AVC Integrator Response',0
Simple mixer control 'AVC Max Gain',0
Simple mixer control 'AVC Threshold',0
Simple mixer control 'BASS 0',0
Simple mixer control 'BASS 1',0
Simple mixer control 'BASS 2',0
Simple mixer control 'BASS 3',0
Simple mixer control 'BASS 4',0
Simple mixer control 'DAP MIX Mux',0
Simple mixer control 'DAP Main channel',0
Simple mixer control 'DAP Mix channel',0
Simple mixer control 'DAP Mux',0
Simple mixer control 'Digital Input Mux',0

And to see what those simple controls can be and are set to currently:

~# amixer -c 1 scontents
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 103 [81%] [0.00dB] [off]
  Front Right: Playback 103 [81%] [0.00dB] [off]
Simple mixer control 'Headphone Mux',0
  Capabilities: enum
  Items: 'DAC' 'LINE_IN'
  Item0: 'DAC'
Simple mixer control 'Headphone Playback ZC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 192
  Mono:
  Front Left: Playback 192 [100%]
  Front Right: Playback 192 [100%]
Simple mixer control 'Lineout',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [0.00dB] [off]
  Front Right: Playback 31 [100%] [0.00dB] [off]
Simple mixer control 'Mic',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 3
  Mono: 0 [0%] [0.00dB]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 15
  Front Left: Capture 0 [0%] [off]
  Front Right: Capture 0 [0%] [off]
Simple mixer control 'Capture Attenuate Switch (-6dB)',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Capture Mux',0
  Capabilities: enum
  Items: 'MIC_IN' 'LINE_IN'
  Item0: 'MIC_IN'
Simple mixer control 'Capture ZC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'AVC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'AVC Hard Limiter',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'AVC Integrator Response',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 3
  Mono: 1 [33%]
Simple mixer control 'AVC Max Gain',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 2
  Mono: 0 [0%] [0.00dB]
Simple mixer control 'AVC Threshold',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 96
  Mono: 12 [12%] [12.00dB]
Simple mixer control 'BASS 0',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 95
  Mono: 47 [49%]
Simple mixer control 'BASS 1',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 95
  Mono: 47 [49%]
Simple mixer control 'BASS 2',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 95
  Mono: 47 [49%]
Simple mixer control 'BASS 3',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 95
  Mono: 47 [49%]
Simple mixer control 'BASS 4',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 95
  Mono: 47 [49%]
Simple mixer control 'DAP MIX Mux',0
  Capabilities: enum
  Items: 'ADC' 'I2S'
  Item0: 'ADC'
Simple mixer control 'DAP Main channel',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 65535
  Mono: 32768 [50%]
Simple mixer control 'DAP Mix channel',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 65535
  Mono: 0 [0%]
Simple mixer control 'DAP Mux',0
  Capabilities: enum
  Items: 'ADC' 'I2S'
  Item0: 'ADC'
Simple mixer control 'Digital Input Mux',0
  Capabilities: enum
  Items: 'ADC' 'I2S' 'Rsvrd' 'DAP'
  Item0: 'I2S'

The get / set usages of amixer use the ID's of the controls which are shown above.

To get a specific simple control use the 'sget' option:

~# amixer -c 1 sget 'PCM'  # get audio output volume
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 192
  Mono:
  Front Left: Playback 192 [100%]
  Front Right: Playback 192 [100%]
~# amixer -c 1 sget 'Capture Mux'  # get audio input line
Simple mixer control 'Capture Mux',0
  Capabilities: enum
  Items: 'MIC_IN' 'LINE_IN'
  Item0: 'MIC_IN'
~# amixer -c 1 sget 'Capture'  # get audio input volume
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 15
  Front Left: Capture 0 [0%] [off]
  Front Right: Capture 0 [0%] [off]
  • Note that the default setting for the Analog input Capture Mux is MIC_IN which is typically unconnected on most boards, so you want to switch this to LINE_IN if capturing audio
  • Note that the default setting for the Analog input Capture gain is off to eliminate unwanted noise, so you will want to set this if capturing audio

To set a specific simple control use the 'sset' option:

~# amixer -c 1 sset 'PCM' 100%  # set output volume to max
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 192
  Mono:
  Front Left: Playback 192 [100%]
  Front Right: Playback 192 [100%]
~# amixer -c 1 sset 'Capture Mux' 'LINE_IN' # select LINE_IN vs MIC_IN
Simple mixer control 'Capture Mux',0
  Capabilities: enum
  Items: 'MIC_IN' 'LINE_IN'
  Item0: 'LINE_IN'
~# amixer -c 1 sset 'Capture' 50% # set capture gain to half
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 15
  Front Left: Capture 8 [53%] [off]
  Front Right: Capture 8 [53%] [off]

Be sure to visit ventana/audio for additional details on audio output connectors and devices

Last modified 5 years ago Last modified on 03/20/2020 11:37:14 PM
Note: See TracWiki for help on using the wiki.