Using your USB DAC with Linux

Welcome

This is a small tutorial for using your USB Audio DAC with Linux. I decided to write down all the things I come across when I try to get the best audio quality out of my AUDIOPHONICS Asynchrone USB DAC AK4495SEQ 32bit 384kHz using Linux Mint 18.3. This is a living document.

Device driver

Linux will recognize a class 1 or a class 2 audio device without any configuration. You can check the interface to your DAC by executing the following command in a terminal:

$ cat /proc/asound/x20/stream0

x20 is the card name of your audio device. If your DAC is recognized as a class 2 device you will see:

XMOS xCORE USB Audio 2.0 at usb-0000:00:1d.7-4, high speed : USB Audio

Playback:
Status: Running
Interface = 1
Altset = 1
Packet Size = 72
Momentary freq = 44101 Hz (0x5.8338)
Feedback Format = 16.16
Interface 1
Altset 1
Format: S32_LE
Channels: 2
Endpoint: 1 OUT (ASYNC)
Rates: 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
Data packet interval: 125 us
Interface 1
Altset 2
Format: S16_LE
Channels: 2
Endpoint: 1 OUT (ASYNC)
Rates: 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
Data packet interval: 125 us
Interface 1
Altset 3
Format: SPECIAL DSD_U32_BE
Channels: 2
Endpoint: 1 OUT (ASYNC)
Rates: 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
Data packet interval: 125 us

If Linux recognized your DAC as a class 1 device all the rates higher than 96000 will be missing. Momentary freq should be the same as the frequency shown on your DACs display. If you don't know the name of your device you can execute the following command:

$ aplay -L

This will list all available cards and devices (and that's a long list). For my Audiophonics DAC it wil show (amongst others) the following lines:

hw:CARD=x20,DEV=0
xCORE USB Audio 2.0, USB Audio
Direct hardware device without any conversions
plughw:CARD=x20,DEV=0
xCORE USB Audio 2.0, USB Audio
Hardware device with all software conversions

The CARD attribute is the most important one to rember.

Pulse Audio

Like most distros Linux Mint 18.3 uses Pulse Audio. Unfortunately the default resample-method Pulse Audio uses sounds horrible. You can improve the sound quality a lot by adding the resampling-method option to your Pulse Audio configuration file.

$ echo "resample-method = src-sinc-best-quality" | sudo tee -a /etc/pulse/daemon.conf
$ killall pulseaudio

The killall command is important, otherwise the new settings will not have any effect until you logoff. But if you want the best audio quality I can only advise you to remove Pulse Audio altogether, especially when you are using the Spotify app or other apps that automaticaly select their audio output. After removing Pulse Audio, most apps will automatically use the ALSA sound library. Removing Pulse Audio is simple, but reinstalling also is, so don't be afraid to remove it:

$ sudo apt-get remove pulseaudio pulseaudio-module-x11
$ killall pulseaudio

Reinstalling Pulse Audio is even easier:

$ sudo apt-get install pulseaudio pulseaudio-module-x11

The moment an app notices Pulse Audio is available and tries to use it, the Pulse Audio daemon will be started automatically. You can explore the difference in sound quality between ALSA and Pulse Audio without the need to reboot your computer.

Configuring ALSA

After removing Pulse Adio your USB DAC probably won't play because it's not selected by ALSA as default device. There are two places you can configure ALSA:

Because ALSA is only a library and is not a daemon like Pulse Audio, you don't have to log off or kill a daemon when you're making changes to these files. You only have to close the applications that are using ALSA and restart them. Here are two ways to set your USB-DAC as the default device. The first one:

# Still resampling to 48KHz.

defaults.pcm.type hw
defaults.pcm.!card "x20"
defaults.pcm.device 0

ctl.!default {
  type hw
  card "x20"
}

These settings select x20 as the default output card. In a lot of examples I see people using a card number instead of a name. I had a lot of problems using a number. In my system card 0 was alway the onboard audio device but card 1 and card 2 were never consistently assigned. Sometimes card 1 was the HDMI output of the NVidia graphics card and card 2 was the USB DAC dac but sometimes it was the other way around. By using a the card name this no longer is an issue. But because the type of the card property is a string and not a number you have to use an exclamation mark to override the default integer type.

This configuration has the advantage that ALSA will mix the output of mutliple applications and the ctl.!default option ensures the master-volume control still works. If you leave this option out you only can adjust the volume in your app or by changing the volume of the device (somewhere hidden in a tab within volume-control). The main disadvantage of this configuration is that all input is resampled to 48Khz. When you use Spotify for example, you will see 48Khz on the DACs display instead of the expected 44Khz. The second configuration will prevent ALSA from resampling to 48Khz and use the sample rate of the source stream/file:

# Disable resampling to 48KHz.

pcm.default_device {
  type hw
  card "x20"
  device 0
}

pcm.!default {
  type plug
  slave {
    pcm "default_device"
  }
}

ctl.!default {
  type hw
  card "x20"
}

This improves sound quality but prevents two or more applications from using the same ALSA output device at the same time. The option format S32_LE is worth trying. This option will force ALSA (or the program that uses ALSA, I'm not sure which one) to convert the samples to 32-bit. Normally 16-bit samples will be converted by the DAC and not the software.

DeadBeeF

An unusual name for a music player but for me its the player that does the job for playing music from an URL or my local storage. To my ears it sounds better than VLC. This app can not be found in the standard Linux Mint repository. The easiest way to install it is download it from Sourceforge. DeadBeeF let's your choose the audio output device:

When you open the dropdown box Output devices your will see the same list of ALSA devices as the output from the command aplay -L. In the preference-tab Plugins there are two settings of the ALSA-plugin you might want to change:

You can enable/disable ALSA resampling and hear for yourself what you like best. The Release device while stopped is a handy option if you disabled the ALSA mixer. Now you can keep DeadBeeF open without locking the selected ALSA device.

Audacious

For me this is the best sounding free player with a graphical interface I've tried out (until now), although I don't like its user interface as much as the minimalistic interface of DeaDBeeF. Audacious can be found in the standard repository, but this is an outdated version. If you want the latest version you have to add a PPA:

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 531EE72F4C9D234C
$ sudo apt-get update
$ sudo apt-get install audacious

Like DeaDBeeF, Audacious lets you choose the audio output device:

I had two weird problems using Audacious. The First one was that it wouldn't do gapless playback. The second one was (and still is) that after restarting Audacious the Mixer element is left blank and therefore the volume-control is not working. After selecting a mixer, volume-control is enabled again. The reason for the first problem turned out to be the selection of hw:CARD=x20 (Direct hardware device without any conversions) as PCM output device. Selecting plughw:CARD=x20 (Direct hardware device with all software conversions) will turn on gapless playback. The second problem I haven't been able to solve yet.

For 44.1KHz/16 FLACs I tested both the 16-bit and 32-bit bit-depth output. I prefer the 16-bit output and let the DAC do the conversion to 32-bit. Unfortunately the 'Automatic' bit-depth setting does not output 16-bit samples when playing 16-bit FLACs. So I have to change this option manually when playing 16-bit or 24-bit FLACs.

Clementine

Another great player. It sounds a bit smoother and less direct compared to Audacious. It is available in the Mint repository, but that's not the latest version. The latest version can be downloaded from the Clementine Download Page The disadvantage of this version is that it spits out a lot of debug information to stdout/stderr and I find it less responsive than the version in the Mint repository. I decided to stick to the older Mint-version. For now, this is my favourite player, but .... Clementine does something weird with Hi Res files. I could immediately hear something was wrong and when I examined /proc/asound/x20/stream0, the sample rate was correct, but the sample format was S16_LE instead of S32_LE. Clementine seems to throw away 8 bits of the 24-bit sample. I haven't found a fix yet, so for Hi Res Audacious is still the best option.

Command line: aplay

If you want to use the command line, the best sounding option is probably aplay. Compared to Clementine, aplay sounds a little bit more direct. Unfortunately aplay can't decode FLAC. You need the flac command for decoding and pipe the track as WAVE format into aplay. Personally I only use aplay with classical music or when I want to play a complete album. Here's the command I use for playing all FLACs in the current directory:

$ for f in *.flac; do flac -c -d "$f" | aplay; done

By default the flac command is not installed, but it is available in the standard repository. In terms of ease of use this is of course not a Spotify or iTunes experience, but there is also another disadvantage: this command doesn't do gapless playback. There are ways to do this using mplayer, shntool or ffmpeg. These commands decode the FLACs and strip headers. Search for 'aplay gapless' and you will find a gapless playback solution. I've tested some of the solutions but for some reason they don't sound as good as using the flac command and piping it's output directly into aplay. For gapless playback you are probably better of using DeaDBeeF, Audacious or Clementine.

Signalyst HQPlayer

I've tested this player out of curiosity. It is available on the Signalyst website. You can only try it for 30 minutes and after this shorter than short trial period, you have to buy a license. I tested it and I was both disappointed and relieved. I was disappointed in the audio quality produced by the HQPlayer and relieved that I could save €143,99, beacuse that's how much this player costs. I tried several settings, different filters, frame rates etc., but for me they all had one thing in common: they all sounded artificial. For the test I took an excellent recorded classical CD, ripped it with cdparanoia and played it back with HQPlayer, Clementine, Audacious and my good old Rotel RCD-951 CD Player (playing the original CD), using the coax input of my DAC. For the test I had to use a better PC than my 'Media PC', because HQPlayer demands SSE4.2 support and my 'Media PC' has an Core 2 Duo CPU which only supports SSE3.

The results of this A/B/C/D-test were interesting. The RCD-951 won: more dynamic and cleaner sound. Next came Clementine, but I was surprised how close it came to the CD player. I also noticed that Clementine sounded better compared to my 'Media PC' and I think the main reason is that the PC I used for testing has a better power supply than my 'Media PC'. Third came Audacious and last HQPlayer. I just wasn't able to let HQPlayer shine within 30 minutes. So instead of buying software, I'm going to buy a decent low ripple/noise power supply!

Still ripping CD's?

It's a dying art, but now and then I want to rip a CD using Linux. Years ago when I used a SqueezeBox, I ripped a lot of CDs with Rhythmbox. Fast and convenient, but not exactly bit-perfect. Fortunatly I managed to get Exact Audio Copy working with WineHQ. The version of WineHQ I use is the the standard version (1.6.2) on Mint 18.3. Exact Audio Copy can be downloaded from this download page. After installing and running EAC you will probably notice that it won't recognize your CDROM-drive. I needed to add the drive to fstab:

/dev/sr0   /cdrom   iso9660   noauto  0  0

I also needed to register the drive with winecfg (D: drive)

After that EAC worked just great under WineHQ and I didn't have any issues.

Enjoy the music!

no copyrightLast updated on Sept 3 11:28 2019