Outils pour utilisateurs

Outils du site


alsa

Linux audio - Comprendre ALSA

PCM audio

  • ALSA procfs : On trouve des informations utiles dans /proc/asound.
    • Information globales :
      # ls -l /proc/asound/
      lrwxrwxrwx    1 root     root             5 Mar 11 16:14 U20F1 -> card0
      dr-xr-xr-x    3 root     root             0 Mar 11 16:01 card0
      -r--r--r--    1 root     root             0 Mar 11 16:01 cards
      -r--r--r--    1 root     root             0 Mar 11 16:14 devices
      -r--r--r--    1 root     root             0 Mar 11 16:14 hwdep
      -r--r--r--    1 root     root             0 Mar 11 16:14 pcm
      -r--r--r--    1 root     root             0 Mar 11 16:14 timers
      -r--r--r--    1 root     root             0 Mar 11 16:14 version
      
      # cat /proc/asound/cards
       0 [U20F1          ]: USB-Audio - USB Audio 2.0(F1)
                            Singxer USB Audio 2.0(F1) at usb-1c1d000.usb-1, high speed
      
      # cat /proc/asound/version  
      Advanced Linux Sound Architecture Driver Version k4.19.25.
    • Fichiers spécifiques concernant card0 :
      # ls /proc/asound/card0/pcm0p/
      info  sub0
      
      # ls /proc/asound/card0/pcm0p/sub0/
      hw_params  info       status     sw_params
      
      === Lire un fichier 24/96 ===
      # cat /proc/asound/card0/pcm0p/sub0/hw_params 
      access: RW_INTERLEAVED
      format: S32_LE
      subformat: STD
      channels: 2
      rate: 96000 (96000/1)
      period_size: 12000
      buffer_size: 48000
      
      === Lire un fichier 16/44 ===
      # cat /proc/asound/card0/pcm0p/sub0/hw_params 
      access: RW_INTERLEAVED
      format: S16_LE
      subformat: STD
      channels: 2
      rate: 44100 (44100/1)
      period_size: 5513
      buffer_size: 22050
  • Paramètres importants : le types d'accès, la taille du buffer, le nombre de canaux, le format d'échantillon, le taux d'échantillonnage, le nombre de périodes
    • Prenons le dernier exemple (un flux audio stéréo, 16-bit, 44.1 kHz) :
      • type d'accès : INTERLEAVED
      • format: S16_LE (Signed 16 bit Little Endian)
      • nombre de canaux = 2 (stéréo)
      • 1 sample (en byte) = 2 bytes (car représenté par 16-bit)
      • 1 frame (en byte) = (nombre_canaux) * (1 sample) = 4 bytes
      • 1 period = entre deux interruptions matérielles
      • buffer_size = periods * period_size où periods = le nombre de periods, period_size = 1 period en byte.

Quelques infos trouvées sur Internet.

  • Application –> alsa-lib –> alsa driver –> hardware. Pour comprendre l'usage de alsa-lib :
    • PCM Devices (PCM Interfaces). Voir aussi /usr/share/alsa/alsa.conf. Exemples :
      • Device hw : il utilise le plugin hw.
      • Device plughw : il utilise les plugins plug et hw.
      • List of PLAYBACK Hardware Devices :
        [root@alarm ~]# aplay -l
        **** List of PLAYBACK Hardware Devices ****
        card 0: M20 [M2Tech USB Audio 2.0], device 0: USB Audio [USB Audio]
          Subdevices: 0/1
          Subdevice #0: subdevice #0
      • List all PCMs defined : ce sont des aliases des devices donne tous les PCM définis dans /usr/share/alsa/alsa.conf.
        [root@alarm ~]# aplay -L
        null
            Discard all samples (playback) or generate zero samples (capture)
        sysdefault:CARD=M20
            M2Tech USB Audio 2.0, USB Audio
            Default Audio Device
        front:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            Front speakers
        surround40:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            4.0 Surround output to Front and Rear speakers
        surround41:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            4.1 Surround output to Front, Rear and Subwoofer speakers
        surround50:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            5.0 Surround output to Front, Center and Rear speakers
        surround51:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            5.1 Surround output to Front, Center, Rear and Subwoofer speakers
        surround71:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
        iec958:CARD=M20,DEV=0
            M2Tech USB Audio 2.0, USB Audio
            IEC958 (S/PDIF) Digital Audio Output
    • PCM Plugins. Exemples :
      • Plugin hw : Ce plugin communique directement avec ALSA kernel driver. Il s'agit d'une communication brute sans aucune conversion. ( PCM HW Plugin Interface)
      • Plugin plug : Ce plugin convertit “channels, rate et format” sur demande. (Automatic conversion plugin).
    • Différence entre hw et plughw : C'est de savoir ce que fait le plugin plug dans ce cas. Il semble que le plugin plug de device plughw est configuré pour ne pas ajouter de conversion si le son peut passer par le plugin hw.
      plughw only does very necessary convertions to allow output to work
      at all and never any extra. Like, for example, if you feed 44100 but
      your audio card supports only 48k samples, it will convert 44.1->48 but
      nothing else; or if you feed 16 bit stream to it but your sound card
      supports only 24-bit sampled audio, it will convert s16 to s24. It can
      upconvert stereo to multichannel (by simply filling other channels with
      silence) for sound cards that accept only multichannel - there are such
      beasts - but it will never do any extra steps, not to introduce
      undesirable effects. Basically plughw is just "compatible" version of hw
      that takes care of most obvious incompatibilities which make playback
      impossible; as long as playback IS possible, plughw does no conversion.

      (http://mplayerhq.hu/pipermail/mplayer-users/2011-July/082989.html).

      with ALSA, devices named "hw:..." can only be configured in ways that match
      the hardware capabilities of the device. no configuration that requires the
      driver or libasound to resample, reformat etc. etc. are allowed. note that
      this includes the number of channels, so if the h/w has N channels you
      cannot configure it for anything other than N channels.
      
      "plughw:..." devices are much more flexible and will use the full
      capabilities (such as they are) of the driver and libasound to provide a
      much broader configuration space.

      (http://linuxaudio.org/mailarchive/lad/2012/10/7/193380) Cela explique peut-être qu'une carte son multichannel (ex. RME HDSP 9632) peut ne pas marcher avec le device hw.

alsa.txt · Dernière modification: 2019/03/11 17:47 par bz31