Ubuntu – Setting the default ALSA device for Pulseaudio

alsapulseaudiosound

I recently got an external soundcard/DAC (Fiio E17) and am currently trying to properly configure it on my Ubuntu 12.04 installation. When plugging it in via USB, it's immediately recognized and shows up as a new device in the audio settings. Playback works mostly fine as well (except for some minor volume-related issues, which are beyond the scope of this question).

However, when trying to test the 24 bit/96 kHz playback by playing such an audio file with mplayer, I encountered a small issue:

Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 96000 Hz, 2 ch, s24le, 4608.0 kbit/100.00% (ratio: 576000->576000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [pulse] 96000Hz 2ch s16le (2 bytes per sample)

As can be seen from the output, even though the played file does contain 24 bit/96 kHz audio, it's resampled to 16 bit before playback. Playing the same file with aplay shows the reason:

Playing WAVE 'sr003-02-2496.wav' : Signed 24 bit Little Endian in 3bytes, Rate 96000 Hz, Stereo
aplay: set_params:1081: Sample format non available
Available formats:
- U8
- S16_LE
- S16_BE
- S32_LE
- S32_BE
- FLOAT_LE
- FLOAT_BE
- MU_LAW
- A_LAW

However, /proc/asound/card1/stream0 confirms that the hardware does support 24 bit:

FiiO FiiO USB DAC-E17 at usb-0000:00:1a.0-1.1, full speed : USB Audio

Playback:
  Status: Running
    Interface = 3
    Altset = 1
    Packet Size = 388
    Momentary freq = 44100 Hz (0x2c.199a)
  Interface 3
    Altset 1
    Format: S16_LE
    Channels: 2
    Endpoint: 3 OUT (ADAPTIVE)
    Rates: 32000, 44100, 48000, 96000
  Interface 3
    Altset 2
    Format: S24_3LE
    Channels: 2
    Endpoint: 3 OUT (ADAPTIVE)
    Rates: 32000, 44100, 48000, 96000

At this point I noticed that in the hardware tab of the sound settings, I can select two different profiles for the sound card: Digital Stereo (IEC958) and Analog Stereo. Switching between these two doesn't result in any changes though, as far as I can tell.

Specifying the ALSA device does help though (that is, aplay -Dhw:1,0 sr003-02-2496.wav works just fine and plays the file without resampling). But since Pulseaudio only shows one Fiio device/sink in the sound settings, I'm not sure how I'd tell Pulseaudio to use ALSA device hw:1,0. Adding load-module module-alsa-source device=hw:1,0 to /etc/pulse/default.pa results in Pulseaudio aborting with module.c: Failed to load module "module-alsa-source" (argument: "device=hw:1,0"): initialization failed. during startup.

So, that's the introduction, here's my actual questions:

  • How do I figure out which ALSA device Pulseaudio actually uses when I select the Fiio E17 in the sound settings?
  • How do I tell Pulseaudio to use ALSA device hw:1,0 when selecting the Fiio E17 in my sound settings?

Some more (hopefully helpful) debug information:

Best Answer

Answering the two questions:

You can select the default device in PulseAudio with a GUI like the GNOME volume control, pavucontrol, or from the command line using pacmd set-default-sink.

By default, PulseAudio opens devices for 44.1 kHz or 48 kHz, whichever leads to lower resampling effort (so 96 kHz audio would usually lead to the device being opened at 48 kHz. Also, we open the devices for S16LE by default.

Now, you have two options. If you just want to play a few files at their native format, paplay --passthrough <file> should do the job for you. You can even specify which device to use.

The other option is to globally make PA use 96/24. You can change that in /etc/pulse/default.conf (alternate-sample-rate = 96000, default-sample-format=s24-32le). This will lead to greater CPU usage, though. This is a bit of a silly situation, having to apply global configuration for all devices. We're planning to add per-device configuration at some point.

Note, after this, you should just use mplayer's PulseAudio backend rather than have mplayer talk to ALSA and then ALSA to PulseAudio. You can do that with mplayer -ao pulse ... and if you want to set it up permanently, add ao=pulse to ~/.mplayer/config.