Audio commands

Tutorials on Linux commands can be found everywhere on the internet.
http://www.linuxcommand.org/
http://tldp.org/LDP/intro-linux/html/index.html

 

Sound cards

ALSA numbers the sound cards starting with 0.

A card can have more then one device, again numbering starts at 0.

You refer to a soundcard with (card, device)

hw:0,0 refers to the first card and the first device of this card.

 

You can use hw or plughw

If you use the "plughw" interface, you need not care much about the sound hardware. If your soundcard does not support the sample rate or sample format you specify, your data will be automatically converted. This also applies to the access type and the number of channels. With the "hw" interface, you have to check whether your hardware supports the configuration you would like to use.

Commands

The following commands works in Ubuntu, a Debian distro.

asoundconf

Utility to read and change the user's ALSA library configuration

 

asoundconf set-default-card B10

 

Makes B10 (USB DAC) the default sound card, see cat to get the name of the soundcard.

aplay

A native ALSA wav player.

Can be used for some testing as well.

More ALSA utils

cat

Concatenates files, an easy way to list your audio devices in the terminal


cat /proc/asound/cards

 

 0 [Intel          ]: HDA-Intel - HDA Intel

                      HDA Intel at 0xb0000000 irq 16

 1 [B10            ]: USB-Audio - Benchmark 1.0

                      Texas Instruments Benchmark 1.0 at usb-0000:00:1d.0-1, full speed

 

cat /proc/asound/devices

 

  2:        : timer

  3:        : sequencer

  4: [ 0- 0]: digital audio playback

  5: [ 0- 0]: digital audio capture

  6: [ 0]   : control

  7: [ 1- 0]: digital audio playback

  8: [ 1]   : control

 

cat /proc/asound/hwdep

 

cat /proc/asound/modules

 

 0 snd_hda_intel

 1 snd_usb_audio

vincent@vincent-ubuntu:~$ cat /proc/asound/pcm

00-00: ALC260 Analog : ALC260 Analog : playback 1 : capture 1

01-00: USB Audio : USB Audio : playback 1

 

cat /proc/asound/timers

 

G0: system timer : 4000.000us (10000000 ticks)

P0-0-0: PCM playback 0-0-0 : SLAVE

P0-0-1: PCM capture 0-0-1 : SLAVE

P1-0-0: PCM playback 1-0-0 : SLAVE

 

cat /proc/asound/version

 

Advanced Linux Sound Architecture Driver Version 1.0.17.

 

cat /proc/asound/card1/stream0

 

Shows you the properties of the audio stream.

Momentary freq tells you what Alsa is sending to the device.

This allows you to check if resampling is applied.

 

Texas Instruments Benchmark 1.0 at usb-0000:00:1d.0-1, full speed : USB Audio

 

Playback:

  Status: Running

    Interface = 1

    Altset = 1

    URBs = 2 [ 3 3 ]

    Packet Size = 576

    Momentary freq = 44100 Hz (0x2c.199a)

  Interface 1

    Altset 1

    Format: 0x20

    Channels: 2

    Endpoint: 1 OUT (ADAPTIVE)

    Rates: 44100, 48000, 88200, 96000

lspci

shows you all the PCI devices.

A very useful one is GREP, it filters the output.


lspci | grep –i audio

 

shows devices with audio in their name only, use  –i to ignore upper/lower case

 

00:1b.0 Audio device: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller (rev 03)

lsusb

list all USB devices.

lsusb -2 002 -v list all properties of the USB-DAC

 

Bus 002 Device 002: ID 04d8:feea Microchip Technology, Inc.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x04d8 Microchip Technology, Inc.
  idProduct          0xfeea
  bcdDevice            1.00
  iManufacturer           1 Texas Instruments
  iProduct                2 Benchmark 1.0
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          109
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0
      iInterface              0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength           30
        bInCollection           1
        baInterfaceNr( 0)       1
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             5
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             8
        wTerminalType      0x0301 Speaker
        bAssocTerminal          0
        bSourceID               5
        iTerminal               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           5
        bDelay                  1 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                20
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           3
        bBitResolution         24
        bSamFreqType            4 Discrete
        tSamFreq[ 0]        44100
        tSamFreq[ 1]        48000
        tSamFreq[ 2]        88200
        tSamFreq[ 3]        96000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            9
          Transfer Type            Isochronous
          Synch Type               Adaptive
          Usage Type               Data
        wMaxPacketSize     0x0240  1x 576 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         0 Undefined
          wLockDelay              0 Undefined
Device Status:     0x0000
  (Bus Powered)

ps

List processes.

 

ps -edalf | grep -i dsp

 

List processes using dsp

Specifying an audio device

hw:0,0
This means go directly to the hardware, card0, device 0. (the left number is the card, the right number is the device). If the device has a name you can use that as well.

hw talks directly to the hardware, no conversions whatsoever are performed.
If the DAC is 24 bits and you are playing a 16 bits file it won't play.
In this case, use the "plug" interface. Plug will do simple conversions such as bit differences and sample rate conversions as necessary.
You talk to the plug interface the same way as to hw.