Changes between Initial Version and Version 1 of linux/audio


Ignore:
Timestamp:
03/19/2020 05:12:36 PM (5 years ago)
Author:
Tim Harvey
Comment:

initial page (generalized from ventana/audio)

Legend:

Unmodified
Added
Removed
Modified
  • linux/audio

    v1 v1  
     1[[PageOutline]]
     2
     3= Linux Audio
     4The Advanced Linux Sound Architecture (ALSA) system is the current audio driver subsystem in Linux.
     5
     6See also:
     7 * [wiki:ventana/audio Ventana Audio]
     8 * [wiki:gstreamer Gstreamer]
     9
     10
     11[=#alsa]
     12== ALSA Devices
     13Audio 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)
     14
     15Devices 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 alsa-utils below]).
     16
     17Examples:
     18 * GW54xx
     19{{{#!bash
     20~# cat /proc/asound/cards
     21 0 [DWHDMI         ]: dw-hdmi-ahb-aud - DW-HDMI
     22                      DW-HDMI rev 0x0a, irq 22
     23 1 [sgtl5000audio  ]: sgtl5000-audio - sgtl5000-audio
     24                      sgtl5000-audio
     25 2 [tda1997xaudio  ]: tda1997x-audio - tda1997x-audio
     26                      tda1997x-audio
     27~# cat /proc/asound/devices
     28  0: [ 0]   : control
     29 16: [ 0- 0]: digital audio playback
     30 32: [ 1]   : control
     31 33:        : timer
     32 48: [ 1- 0]: digital audio playback
     33 56: [ 1- 0]: digital audio capture
     34 64: [ 2]   : control
     35 88: [ 2- 0]: digital audio capture
     36}}}
     37  - The first file shows there are 3 audio 'cards' in the system:
     38   * 0: DWHDMI (HDMI Audio out)
     39   * 1: sgtl5000audio (Analog Audio in/out)
     40   * 2: tda1997xaudio (HDMI Audio in)
     41  - The second file shows the 'devices' in the system:
     42   * hw0,0: audio output (from card 0, DWHDMI, HDMI audio out)
     43   * hw1,0: audio output (from card 1, sgtl5000, Analog audio out)
     44   * hw1,0: audio input (from card 1, sgtl5000, Analog audio in)
     45   * hw2,0: audio output (from card 2, tda1997x, HDMI audio in)
     46  - 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
     47
     48
     49[=#alsa-utils]
     50== ALSA Userapce Utilities (aplay, arecord, amixer)
     51The {{{alsa-utils}}} package contains simple command-line utilities that use the ALSA kerne API's to show, configure, and use the ALSA audio devices:
     52 * {{{aplay}}} - list and output to ALSA audio output devices
     53 * {{{arecord}}} - list and capture from ALSA audio input devices
     54 * {{{amixer}}} - get and set configuration of ALSA audio devices
     55
     56
     57=== Showing Device Alias Names (aplay / arecord)
     58You 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).
     59
     60Note that device alias names are configured via ALSA asound configuration files which is not covered here.
     61
     62Examples:
     63 * GW54xx audio output devices:
     64{{{#!bash
     65~# aplay -l
     66**** List of PLAYBACK Hardware Devices ****
     67card 0: DWHDMI [DW-HDMI], device 0: DW HDMI [dw-hdmi-ahb-audio]
     68  Subdevices: 1/1
     69  Subdevice #0: subdevice #0
     70card 1: sgtl5000audio [sgtl5000-audio], device 0: HiFi sgtl5000-0 [HiFi sgtl5000-0]
     71  Subdevices: 1/1
     72  Subdevice #0: subdevice #0
     73~# aplay -L
     74null
     75    Discard all samples (playback) or generate zero samples (capture)
     76default:CARD=DWHDMI
     77    DW-HDMI, dw-hdmi-ahb-audio
     78    Default Audio Device
     79sysdefault:CARD=DWHDMI
     80    DW-HDMI, dw-hdmi-ahb-audio
     81    Default Audio Device
     82default:CARD=sgtl5000audio
     83    sgtl5000-audio, HiFi sgtl5000-0
     84    Default Audio Device
     85default:CARD=sgtl5000audio
     86    sgtl5000-audio, HiFi sgtl5000-0
     87    Default Audio Device
     88}}}
     89  - the above shows 2 playback capable devices:
     90   * 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
     91   * 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
     92 * GW54xx audio input devices:
     93{{{#!bash
     94~# arecord -l
     95**** List of CAPTURE Hardware Devices ****
     96card 1: sgtl5000audio [sgtl5000-audio], device 0: HiFi sgtl5000-0 [HiFi sgtl5000-0]
     97  Subdevices: 1/1
     98  Subdevice #0: subdevice #0
     99card 2: tda1997xaudio [tda1997x-audio], device 0: 202c000.ssi-tda1997x tda1997x-0 [202c000.ssi-tda1997x tda1997x-0]
     100  Subdevices: 1/1
     101  Subdevice #0: subdevice #0
     102~# arecord -L
     103null
     104    Discard all samples (playback) or generate zero samples (capture)
     105default:CARD=sgtl5000audio
     106    sgtl5000-audio, HiFi sgtl5000-0
     107    Default Audio Device
     108sysdefault:CARD=sgtl5000audio
     109    sgtl5000-audio, HiFi sgtl5000-0
     110    Default Audio Device
     111default:CARD=tda1997xaudio
     112    tda1997x-audio, 202c000.ssi-tda1997x tda1997x-0
     113    Default Audio Device
     114sysdefault:CARD=tda1997xaudio
     115    tda1997x-audio, 202c000.ssi-tda1997x tda1997x-0
     116    Default Audio Device
     117}}}
     118  - the above shows 2 capture capable devices:
     119   * 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
     120   * 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
     121
     122
     123[=#amixer]
     124=== Configuring ALSA audio devices (amixer)
     125The 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.
     126
     127**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.**
     128
     129Examples:
     130 * list controls for the various cards in a GW54xx (look at {{{/proc/asound/cards}}} to see a list of cards)
     131{{{#!bash
     132~# cat /proc/asound/cards # show cards in system
     133 0 [DWHDMI         ]: dw-hdmi-ahb-aud - DW-HDMI
     134                      DW-HDMI rev 0x0a, irq 22
     135 1 [sgtl5000audio  ]: sgtl5000-audio - sgtl5000-audio
     136                      sgtl5000-audio
     137 2 [tda1997xaudio  ]: tda1997x-audio - tda1997x-audio
     138                      tda1997x-audio
     139~# amixer -c 0 # show controls for card 0 the HDMI output - there are none
     140~# amixer -c 1 # list controls card 1 the analog audio codec
     141Simple mixer control 'Headphone',0
     142  Capabilities: pvolume pswitch pswitch-joined
     143  Playback channels: Front Left - Front Right
     144  Limits: Playback 0 - 127
     145  Mono:
     146  Front Left: Playback 103 [81%] [0.00dB] [off]
     147  Front Right: Playback 103 [81%] [0.00dB] [off]
     148Simple mixer control 'Headphone Mux',0
     149  Capabilities: enum
     150  Items: 'DAC' 'LINE_IN'
     151  Item0: 'DAC'
     152Simple mixer control 'Headphone Playback ZC',0
     153  Capabilities: pswitch pswitch-joined
     154  Playback channels: Mono
     155  Mono: Playback [on]
     156Simple mixer control 'PCM',0
     157  Capabilities: pvolume
     158  Playback channels: Front Left - Front Right
     159  Limits: Playback 0 - 192
     160  Mono:
     161  Front Left: Playback 192 [100%]
     162  Front Right: Playback 192 [100%]
     163Simple mixer control 'Lineout',0
     164  Capabilities: pvolume pswitch pswitch-joined
     165  Playback channels: Front Left - Front Right
     166  Limits: Playback 0 - 31
     167  Mono:
     168  Front Left: Playback 31 [100%] [0.00dB] [off]
     169  Front Right: Playback 31 [100%] [0.00dB] [off]
     170Simple mixer control 'Mic',0
     171  Capabilities: volume volume-joined
     172  Playback channels: Mono
     173  Capture channels: Mono
     174  Limits: 0 - 3
     175  Mono: 0 [0%] [0.00dB]
     176Simple mixer control 'Capture',0
     177  Capabilities: cvolume cswitch cswitch-joined
     178  Capture channels: Front Left - Front Right
     179  Limits: Capture 0 - 15
     180  Front Left: Capture 0 [0%] [off]
     181  Front Right: Capture 0 [0%] [off]
     182Simple mixer control 'Capture Attenuate Switch (-6dB)',0
     183  Capabilities: pswitch pswitch-joined
     184  Playback channels: Mono
     185  Mono: Playback [off]
     186Simple mixer control 'Capture Mux',0
     187  Capabilities: enum
     188  Items: 'MIC_IN' 'LINE_IN'
     189  Item0: 'MIC_IN'
     190Simple mixer control 'Capture ZC',0
     191  Capabilities: pswitch pswitch-joined
     192  Playback channels: Mono
     193  Mono: Playback [on]
     194Simple mixer control 'AVC',0
     195  Capabilities: pswitch pswitch-joined
     196  Playback channels: Mono
     197  Mono: Playback [off]
     198Simple mixer control 'AVC Hard Limiter',0
     199  Capabilities: pswitch pswitch-joined
     200  Playback channels: Mono
     201  Mono: Playback [off]
     202Simple mixer control 'AVC Integrator Response',0
     203  Capabilities: volume volume-joined
     204  Playback channels: Mono
     205  Capture channels: Mono
     206  Limits: 0 - 3
     207  Mono: 1 [33%]
     208Simple mixer control 'AVC Max Gain',0
     209  Capabilities: volume volume-joined
     210  Playback channels: Mono
     211  Capture channels: Mono
     212  Limits: 0 - 2
     213  Mono: 0 [0%] [0.00dB]
     214Simple mixer control 'AVC Threshold',0
     215  Capabilities: volume volume-joined
     216  Playback channels: Mono
     217  Capture channels: Mono
     218  Limits: 0 - 96
     219  Mono: 12 [12%] [12.00dB]
     220Simple mixer control 'BASS 0',0
     221  Capabilities: volume volume-joined
     222  Playback channels: Mono
     223  Capture channels: Mono
     224  Limits: 0 - 95
     225  Mono: 47 [49%]
     226Simple mixer control 'BASS 1',0
     227  Capabilities: volume volume-joined
     228  Playback channels: Mono
     229  Capture channels: Mono
     230  Limits: 0 - 95
     231  Mono: 47 [49%]
     232Simple mixer control 'BASS 2',0
     233  Capabilities: volume volume-joined
     234  Playback channels: Mono
     235  Capture channels: Mono
     236  Limits: 0 - 95
     237  Mono: 47 [49%]
     238Simple mixer control 'BASS 3',0
     239  Capabilities: volume volume-joined
     240  Playback channels: Mono
     241  Capture channels: Mono
     242  Limits: 0 - 95
     243  Mono: 47 [49%]
     244Simple mixer control 'BASS 4',0
     245  Capabilities: volume volume-joined
     246  Playback channels: Mono
     247  Capture channels: Mono
     248  Limits: 0 - 95
     249  Mono: 47 [49%]
     250Simple mixer control 'DAP MIX Mux',0
     251  Capabilities: enum
     252  Items: 'ADC' 'I2S'
     253  Item0: 'ADC'
     254Simple mixer control 'DAP Main channel',0
     255  Capabilities: volume volume-joined
     256  Playback channels: Mono
     257  Capture channels: Mono
     258  Limits: 0 - 65535
     259  Mono: 32768 [50%]
     260Simple mixer control 'DAP Mix channel',0
     261  Capabilities: volume volume-joined
     262  Playback channels: Mono
     263  Capture channels: Mono
     264  Limits: 0 - 65535
     265  Mono: 0 [0%]
     266Simple mixer control 'DAP Mux',0
     267  Capabilities: enum
     268  Items: 'ADC' 'I2S'
     269  Item0: 'ADC'
     270Simple mixer control 'Digital Input Mux',0
     271  Capabilities: enum
     272  Items: 'ADC' 'I2S' 'Rsvrd' 'DAP'
     273  Item0: 'I2S'
     274~# amixer -c 2 # show controls for card 2 the HDMI audio input - there are none
     275}}}
     276  - 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.
     277
     278Note that the output above is rather complicated and it may be more useful to list the ALSA controls names instead:
     279{{{#!bash
     280~# amixer -c 1 scontrols
     281Simple mixer control 'Headphone',0
     282Simple mixer control 'Headphone Mux',0
     283Simple mixer control 'Headphone Playback ZC',0
     284Simple mixer control 'PCM',0
     285Simple mixer control 'Lineout',0
     286Simple mixer control 'Mic',0
     287Simple mixer control 'Capture',0
     288Simple mixer control 'Capture Attenuate Switch (-6dB)',0
     289Simple mixer control 'Capture Mux',0
     290Simple mixer control 'Capture ZC',0
     291Simple mixer control 'AVC',0
     292Simple mixer control 'AVC Hard Limiter',0
     293Simple mixer control 'AVC Integrator Response',0
     294Simple mixer control 'AVC Max Gain',0
     295Simple mixer control 'AVC Threshold',0
     296Simple mixer control 'BASS 0',0
     297Simple mixer control 'BASS 1',0
     298Simple mixer control 'BASS 2',0
     299Simple mixer control 'BASS 3',0
     300Simple mixer control 'BASS 4',0
     301Simple mixer control 'DAP MIX Mux',0
     302Simple mixer control 'DAP Main channel',0
     303Simple mixer control 'DAP Mix channel',0
     304Simple mixer control 'DAP Mux',0
     305Simple mixer control 'Digital Input Mux',0
     306}}}
     307
     308And to see what those simple controls can be and are set to currently:
     309{{{#!bash
     310~# amixer -c 1 scontents
     311Simple mixer control 'Headphone',0
     312  Capabilities: pvolume pswitch pswitch-joined
     313  Playback channels: Front Left - Front Right
     314  Limits: Playback 0 - 127
     315  Mono:
     316  Front Left: Playback 103 [81%] [0.00dB] [off]
     317  Front Right: Playback 103 [81%] [0.00dB] [off]
     318Simple mixer control 'Headphone Mux',0
     319  Capabilities: enum
     320  Items: 'DAC' 'LINE_IN'
     321  Item0: 'DAC'
     322Simple mixer control 'Headphone Playback ZC',0
     323  Capabilities: pswitch pswitch-joined
     324  Playback channels: Mono
     325  Mono: Playback [on]
     326Simple mixer control 'PCM',0
     327  Capabilities: pvolume
     328  Playback channels: Front Left - Front Right
     329  Limits: Playback 0 - 192
     330  Mono:
     331  Front Left: Playback 192 [100%]
     332  Front Right: Playback 192 [100%]
     333Simple mixer control 'Lineout',0
     334  Capabilities: pvolume pswitch pswitch-joined
     335  Playback channels: Front Left - Front Right
     336  Limits: Playback 0 - 31
     337  Mono:
     338  Front Left: Playback 31 [100%] [0.00dB] [off]
     339  Front Right: Playback 31 [100%] [0.00dB] [off]
     340Simple mixer control 'Mic',0
     341  Capabilities: volume volume-joined
     342  Playback channels: Mono
     343  Capture channels: Mono
     344  Limits: 0 - 3
     345  Mono: 0 [0%] [0.00dB]
     346Simple mixer control 'Capture',0
     347  Capabilities: cvolume cswitch cswitch-joined
     348  Capture channels: Front Left - Front Right
     349  Limits: Capture 0 - 15
     350  Front Left: Capture 0 [0%] [off]
     351  Front Right: Capture 0 [0%] [off]
     352Simple mixer control 'Capture Attenuate Switch (-6dB)',0
     353  Capabilities: pswitch pswitch-joined
     354  Playback channels: Mono
     355  Mono: Playback [off]
     356Simple mixer control 'Capture Mux',0
     357  Capabilities: enum
     358  Items: 'MIC_IN' 'LINE_IN'
     359  Item0: 'MIC_IN'
     360Simple mixer control 'Capture ZC',0
     361  Capabilities: pswitch pswitch-joined
     362  Playback channels: Mono
     363  Mono: Playback [on]
     364Simple mixer control 'AVC',0
     365  Capabilities: pswitch pswitch-joined
     366  Playback channels: Mono
     367  Mono: Playback [off]
     368Simple mixer control 'AVC Hard Limiter',0
     369  Capabilities: pswitch pswitch-joined
     370  Playback channels: Mono
     371  Mono: Playback [off]
     372Simple mixer control 'AVC Integrator Response',0
     373  Capabilities: volume volume-joined
     374  Playback channels: Mono
     375  Capture channels: Mono
     376  Limits: 0 - 3
     377  Mono: 1 [33%]
     378Simple mixer control 'AVC Max Gain',0
     379  Capabilities: volume volume-joined
     380  Playback channels: Mono
     381  Capture channels: Mono
     382  Limits: 0 - 2
     383  Mono: 0 [0%] [0.00dB]
     384Simple mixer control 'AVC Threshold',0
     385  Capabilities: volume volume-joined
     386  Playback channels: Mono
     387  Capture channels: Mono
     388  Limits: 0 - 96
     389  Mono: 12 [12%] [12.00dB]
     390Simple mixer control 'BASS 0',0
     391  Capabilities: volume volume-joined
     392  Playback channels: Mono
     393  Capture channels: Mono
     394  Limits: 0 - 95
     395  Mono: 47 [49%]
     396Simple mixer control 'BASS 1',0
     397  Capabilities: volume volume-joined
     398  Playback channels: Mono
     399  Capture channels: Mono
     400  Limits: 0 - 95
     401  Mono: 47 [49%]
     402Simple mixer control 'BASS 2',0
     403  Capabilities: volume volume-joined
     404  Playback channels: Mono
     405  Capture channels: Mono
     406  Limits: 0 - 95
     407  Mono: 47 [49%]
     408Simple mixer control 'BASS 3',0
     409  Capabilities: volume volume-joined
     410  Playback channels: Mono
     411  Capture channels: Mono
     412  Limits: 0 - 95
     413  Mono: 47 [49%]
     414Simple mixer control 'BASS 4',0
     415  Capabilities: volume volume-joined
     416  Playback channels: Mono
     417  Capture channels: Mono
     418  Limits: 0 - 95
     419  Mono: 47 [49%]
     420Simple mixer control 'DAP MIX Mux',0
     421  Capabilities: enum
     422  Items: 'ADC' 'I2S'
     423  Item0: 'ADC'
     424Simple mixer control 'DAP Main channel',0
     425  Capabilities: volume volume-joined
     426  Playback channels: Mono
     427  Capture channels: Mono
     428  Limits: 0 - 65535
     429  Mono: 32768 [50%]
     430Simple mixer control 'DAP Mix channel',0
     431  Capabilities: volume volume-joined
     432  Playback channels: Mono
     433  Capture channels: Mono
     434  Limits: 0 - 65535
     435  Mono: 0 [0%]
     436Simple mixer control 'DAP Mux',0
     437  Capabilities: enum
     438  Items: 'ADC' 'I2S'
     439  Item0: 'ADC'
     440Simple mixer control 'Digital Input Mux',0
     441  Capabilities: enum
     442  Items: 'ADC' 'I2S' 'Rsvrd' 'DAP'
     443  Item0: 'I2S'
     444}}}
     445
     446The get / set usages of amixer use the ID's of the controls which are shown above.
     447
     448To get a specific simple control use the 'sget' option:
     449{{{#!bash
     450~# amixer -c 1 sget 'PCM'  # get audio output volume
     451Simple mixer control 'PCM',0
     452  Capabilities: pvolume
     453  Playback channels: Front Left - Front Right
     454  Limits: Playback 0 - 192
     455  Mono:
     456  Front Left: Playback 192 [100%]
     457  Front Right: Playback 192 [100%]
     458~# amixer -c 1 sget 'Capture Mux'  # get audio input line
     459Simple mixer control 'Capture Mux',0
     460  Capabilities: enum
     461  Items: 'MIC_IN' 'LINE_IN'
     462  Item0: 'MIC_IN'
     463~# amixer -c 1 sget 'Capture'  # get audio input volume
     464Simple mixer control 'Capture',0
     465  Capabilities: cvolume cswitch cswitch-joined
     466  Capture channels: Front Left - Front Right
     467  Limits: Capture 0 - 15
     468  Front Left: Capture 0 [0%] [off]
     469  Front Right: Capture 0 [0%] [off]
     470}}}
     471 * **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**
     472 * **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**
     473
     474To set a specific simple control use the 'sset' option:
     475{{{#!bash
     476~# amixer -c 1 sset 'PCM' 100%  # set output volume to max
     477Simple mixer control 'PCM',0
     478  Capabilities: pvolume
     479  Playback channels: Front Left - Front Right
     480  Limits: Playback 0 - 192
     481  Mono:
     482  Front Left: Playback 192 [100%]
     483  Front Right: Playback 192 [100%]
     484~# amixer -c 1 sset 'Capture Mux' 'LINE_IN' # select LINE_IN vs MIC_IN
     485Simple mixer control 'Capture Mux',0
     486  Capabilities: enum
     487  Items: 'MIC_IN' 'LINE_IN'
     488  Item0: 'LINE_IN'
     489~# amixer -c 1 sset 'Capture' 50% # set capture gain to half
     490Simple mixer control 'Capture',0
     491  Capabilities: cvolume cswitch cswitch-joined
     492  Capture channels: Front Left - Front Right
     493  Limits: Capture 0 - 15
     494  Front Left: Capture 8 [53%] [off]
     495  Front Right: Capture 8 [53%] [off]
     496}}}
     497