Setting up ALSA for the miniDSP + USBStreamer

 

In hindsight getting ALSA to connect to the USBStreamer and miniDSP wasn't so complicated.   But it wasn't trivial, either.  In the end, the only thing I had to change in the default ALSA setup in LUbuntu was to create the file /etc/asound.conf with the contents:

pcm.!default {
  type plug
  slave.pcm {
    type hw
    card USBStreamer
    device 0
    }
  ttable {
   0.8 1
   1.9 1
  }
}

What's going on is that my sound card, which ALSA sees as "USBStreamer" does not use the default stereo channels 0 and 1.  It took some probing to discover, my left and right stereo signals are on channel 8 and 9 respectively. The ttable object in the pcm remap is telling ALSA to send the signals in channels 0 and 1 to channels 8 and 9 respectively.  The "1" afterwards is an amplitude -- this is if you would like to mix the channels, or if you have 8 or 10 channels being produced by your computer (say for surround sound) but only a 4-channel stereo, it gives you the flexibility to mix the signals appropriately for your setup. 

If you have a different setup, the primary tools you will need to get ALSA working are, in order:

 1) You will need to find your hardware device.  The command "aplay -l" lists the audio output primitives that ALSA can detect.  "aplay -L" lists the 2nd order audio inputs that ALSA automatically creates for those device (or that you might create for it).  For example, here is my "aplay -l" output:

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VB Analog [ALC269VB Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC269VB Digital [ALC269VB Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: USBStreamer [USBStreamer], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

And the "aplay -L" output:

null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
default
sysdefault:CARD=PCH
    HDA Intel PCH, ALC269VB Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    Front speakers
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Digital
    IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=PCH,DEV=0
    HDA Intel PCH, HDMI 0
    HDMI Audio Output
hdmi:CARD=PCH,DEV=1
    HDA Intel PCH, HDMI 1
    HDMI Audio Output
hdmi:CARD=PCH,DEV=2
    HDA Intel PCH, HDMI 2
    HDMI Audio Output
dmix:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    Direct sample mixing device
dmix:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VB Digital
    Direct sample mixing device
dmix:CARD=PCH,DEV=3
    HDA Intel PCH, HDMI 0
    Direct sample mixing device
dmix:CARD=PCH,DEV=7
    HDA Intel PCH, HDMI 1
    Direct sample mixing device
dmix:CARD=PCH,DEV=8
    HDA Intel PCH, HDMI 2
    Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VB Digital
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=3
    HDA Intel PCH, HDMI 0
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=7
    HDA Intel PCH, HDMI 1
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=8
    HDA Intel PCH, HDMI 2
    Direct sample snooping device
hw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VB Digital
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=3
    HDA Intel PCH, HDMI 0
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=7
    HDA Intel PCH, HDMI 1
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=8
    HDA Intel PCH, HDMI 2
    Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VB Analog
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VB Digital
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=3
    HDA Intel PCH, HDMI 0
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=7
    HDA Intel PCH, HDMI 1
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=8
    HDA Intel PCH, HDMI 2
    Hardware device with all software conversions
sysdefault:CARD=USBStreamer
    USBStreamer, USB Audio
    Default Audio Device
front:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    Front speakers
surround21:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    Direct sample mixing device
dsnoop:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    Direct sample snooping device
hw:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    Direct hardware device without any conversions
plughw:CARD=USBStreamer,DEV=0
    USBStreamer, USB Audio
    Hardware device with all software conversions

When you modify the alsa configuration, you have to tell ALSA to reload and read the new configuration file.  The command

sudo alsa reload

typically works.  Good resources for coming to understand ALSA are difficult to come by.  My impression is the people who really understand it are the developers and the people that read the source code closely.  Volker Schatz has the best overview I've been able to find.  His alsacap utility can also be helpful.  The Archlinux distribution also has good documentation for configuring ALSA. The ALSA page also has a configuration file page.

Lastly, once you have alsa running you will need to adjust the volume in alsa's mixer.  Typically you tell the mixer which interface you want to adjust.  For the USBStreamer, this works:

alsamixer -D hw:USBStreamer

Just calling "alsamixer" usually works, but if your /etc/asound.conf file is invalid it could result in alsamixer crashing with bizarre error messages about missing library files -- I problem I fought for hours once.

If you are using a different device than the USBStreamer you can probe the channels with the alsa speaker-test:

speaker-test -c 10 -t sin -D plughw:USBStreamer

This sends a sin wav, one channel at a time for small intervals, telling you which channel it is broadcasting to.  Since my channel remapping is on the default ALSA device, the way to test it would be:

aplay -D default ./blah.wav

If that works, you know your channel remapping (on default) was successful. 

Finally, once this is working you could install something like mplayer and play your music files directly.  Once that works, it's time to set up MPD. 

One problem I've often fought with is ALSA only allows one process to use it at a time.  Sometimes mpd gets "stuck" on ALSA, or perhaps pulseaudio will use ALSA.  The simplest way to find out which process is using ALSA is:

sudo fuser -v /dev/snd/*